/* ── Reset ────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Variables ───────────────────────────────────────────────────────────── */
:root {
  --bg:        #1b1e27;
  --surface:   #22263a;
  --surface2:  #2a2f40;
  --surface3:  #323750;
  --border:    #353a52;
  --text:      #d4d8e8;
  --muted:     #7a80a0;
  --primary:   #4a90e2;
  --primary-h: #5fa0ed;
  --success:   #3cb878;
  --warning:   #e8a838;
  --danger:    #d95f5f;
  --cal-blue:  #5fc2e0;
  --radius:    10px;
  --shadow:    0 2px 8px rgba(0,0,0,0.35);
  --font:      system-ui, -apple-system, 'Segoe UI', sans-serif;
}

/* ── Base ────────────────────────────────────────────────────────────────── */
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }

/* ── Header ──────────────────────────────────────────────────────────────── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 200;
  box-shadow: var(--shadow);
}
.header-inner {
  max-width: 800px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 54px;
}
.site-title {
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
  color: var(--text);
}
nav { display: flex; gap: 4px; flex-wrap: wrap; }

.nav-btn {
  background: none;
  border: none;
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: var(--font);
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.nav-btn:hover { background: var(--surface2); color: var(--text); }
.nav-btn.active { background: var(--primary); color: #fff; }
.nav-logout { color: var(--danger); }
.nav-logout:hover { background: rgba(217,95,95,0.12); color: var(--danger); }

/* ── Main view ───────────────────────────────────────────────────────────── */
#view {
  max-width: 800px;
  margin: 0 auto;
  padding: 20px 16px 80px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.card-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.card-title .confirmed-badge,
.confirmed-badge {
  font-size: 11px;
  color: var(--success);
  font-weight: 600;
  text-transform: none;
  letter-spacing: 0;
  white-space: nowrap;
}

/* ── Collapsible card header ────────────────────────────────────────────── */
.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px 14px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.card.collapsed .card-header { margin-bottom: 0; }
.card-header-left {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  min-width: 0;
}
.card-header-click {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  min-width: 0;
}
.card-collapse-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
  padding: 2px;
  flex-shrink: 0;
  line-height: 1;
}
.card-title-text {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
}
.card-header-extra {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.card.collapsed .card-body { display: none; }

/* Food stats — always visible in header, even collapsed */
.food-stat-cal, .food-stat-left { font-size: 17px; font-weight: 800; white-space: nowrap; }
.food-stat-cal small, .food-stat-left small { font-size: 11px; font-weight: 500; color: var(--muted); }
.food-stat-limit { font-size: 11px; color: var(--muted); font-weight: 500; white-space: nowrap; }

/* WASH toggle */
.wash-toggle {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 0 0 12px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
}
.wash-toggle input { flex-shrink: 0; width: auto; margin-top: 2px; }
.wash-toggle small { color: var(--muted); }

/* ── Date nav ────────────────────────────────────────────────────────────── */
.date-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.date-nav .date-label {
  font-size: 20px;
  font-weight: 700;
  text-align: center;
  flex: 1;
}
.date-nav .date-label em {
  font-style: normal;
  font-size: 13px;
  color: var(--primary);
  margin-left: 8px;
  font-weight: 500;
}
.icon-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  width: 34px; height: 34px;
  border-radius: 8px;
  font-size: 18px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: border-color 0.15s, background 0.15s;
  flex-shrink: 0;
}
.icon-btn:hover:not(:disabled) { border-color: var(--primary); background: var(--surface3); }
.icon-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* ── Weight section ──────────────────────────────────────────────────────── */
.weight-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.weight-input-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}
.weight-input-wrap input {
  width: 90px;
  font-size: 22px;
  font-weight: 700;
  text-align: center;
  padding: 6px 8px;
}
.weight-unit { font-size: 15px; color: var(--muted); }
.weight-display {
  font-size: 28px;
  font-weight: 800;
  min-width: 80px;
}
.weight-display.green { color: var(--success); }
.weight-display.black { color: var(--text); }
.weight-goal {
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
}
.weight-goal .goal-val { font-weight: 700; font-size: 15px; }
.weight-goal .goal-val.green { color: var(--success); }
.weight-goal .goal-val.red   { color: var(--danger); }

/* ── Blood Pressure ──────────────────────────────────────────────────────── */
.bp-entry-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.bp-fields { display: flex; align-items: center; gap: 6px; }
.bp-fields input { width: 72px; text-align: center; font-size: 18px; font-weight: 700; }
.bp-slash { font-size: 24px; color: var(--muted); font-weight: 300; }
.bp-log {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}
.bp-log-entry {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  padding: 6px 10px;
  background: var(--surface2);
  border-radius: 6px;
  gap: 8px;
}
.bp-reading { font-weight: 700; font-size: 15px; }
.bp-meta { color: var(--muted); font-size: 12px; }

/* ── Supplements ─────────────────────────────────────────────────────────── */
.supp-list-combined {
  columns: 2;
  column-gap: 16px;
}
.supp-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  margin-bottom: 5px;
  border-radius: 7px;
  border: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  transition: background 0.12s, border-color 0.12s;
  font-size: 14px;
  break-inside: avoid;
}
.supp-rx-badge {
  margin-left: auto;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .05em;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  flex-shrink: 0;
}
.supp-item:hover { background: var(--surface2); }
.supp-item.pending { border-color: var(--border); }
.supp-item.confirmed.taken { border-color: var(--success); background: rgba(60,184,120,0.07); }
.supp-item.confirmed.not-taken { border-color: var(--border); opacity: 0.5; }

.supp-checkbox {
  width: 18px; height: 18px;
  border-radius: 4px;
  border: 2px solid var(--border);
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px;
  transition: background 0.12s, border-color 0.12s;
}
.supp-item.taken .supp-checkbox,
.supp-item.pending-checked .supp-checkbox {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}
.supp-item.pending-checked .supp-checkbox {
  opacity: 0.5;
}
.supp-confirm-row {
  margin-top: 12px;
  display: flex;
  justify-content: flex-end;
}

/* ── Exercise ────────────────────────────────────────────────────────────── */
.exercise-list { display: flex; flex-direction: column; gap: 10px; }
.exercise-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--surface2);
  border-radius: 8px;
  flex-wrap: wrap;
}
.exercise-label {
  font-size: 14px;
  font-weight: 600;
  min-width: 150px;
  flex-shrink: 0;
}
.exercise-inputs { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.exercise-inputs input { width: 70px; text-align: center; }
.exercise-inputs .unit-label { font-size: 12px; color: var(--muted); }
.exercise-prev {
  font-size: 12px;
  color: var(--muted);
  margin-left: auto;
  white-space: nowrap;
}
.exercise-prev.show-mwf { color: var(--warning); }
.ex-checkbox {
  width: 22px; height: 22px;
  border-radius: 5px;
  border: 2px solid var(--border);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  transition: all 0.12s;
}
.ex-checkbox.checked { background: var(--success); border-color: var(--success); color: #fff; }
.time-input { width: 80px; font-family: 'Consolas', monospace; text-align: center; }

/* ── Food ────────────────────────────────────────────────────────────────── */
.food-add-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 14px;
}
.food-add-row select, .food-add-row input { flex-shrink: 0; }
.food-select { flex: 1; min-width: 140px; }
.food-qty { width: 80px; text-align: center; }
.food-unit { width: 80px; }
.food-log { display: flex; flex-direction: column; gap: 5px; }
.food-log-entry {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  padding: 6px 10px;
  background: var(--surface2);
  border-radius: 6px;
  gap: 8px;
}
.food-log-name { flex: 1; }
.food-log-cal { font-weight: 700; color: var(--warning); }

/* ── Music ───────────────────────────────────────────────────────────────── */
.music-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 7px;
}
.music-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  transition: border-color 0.12s;
}
.music-row.scheduled { border-color: var(--warning); background: rgba(232,168,56,0.05); }
.music-row.practiced { border-color: var(--success); background: rgba(60,184,120,0.06); }
.music-label { flex: 1; min-width: 0; font-size: 14px; font-weight: 500; white-space: nowrap; }
.music-row.scheduled .music-label { color: var(--warning); }
.music-row .music-minutes { width: 62px; flex: 0 0 62px; text-align: center; }

/* ── Daily Habits ────────────────────────────────────────────────────────── */
.habits-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 8px;
}
.time-entries {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 8px;
  margin-bottom: 4px;
}
.time-entry-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.time-entry-label { flex: 1; min-width: 0; font-size: 14px; font-weight: 500; }
.time-entry-label small { display: block; font-size: 11px; font-weight: 400; color: var(--muted); }
.time-entry-row input[type="time"] { width: 110px; flex: 0 0 110px; text-align: center; }
.habit-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
  transition: all 0.12s;
  font-size: 14px;
  font-weight: 500;
}
.habit-row:hover { border-color: var(--primary); background: var(--surface2); }
.habit-row.done { border-color: var(--success); background: rgba(60,184,120,0.07); }
.habit-check {
  width: 20px; height: 20px;
  border-radius: 50%;
  border: 2px solid var(--border);
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px;
  transition: all 0.12s;
}
.habit-row.done .habit-check { background: var(--success); border-color: var(--success); color: #fff; }
.habit-row.done .habit-check::after { content: '✓'; }

/* Dev & reading multi-entry */
.dev-log-form {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
  align-items: center;
}
.dev-minutes { width: 70px; text-align: center; }
.dev-desc { flex: 1; min-width: 140px; }
.dev-log { display: flex; flex-direction: column; gap: 5px; }
.dev-log-entry {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  padding: 6px 10px;
  background: var(--surface2);
  border-radius: 6px;
  gap: 8px;
}
.dev-log-desc { flex: 1; }
.dev-log-time { color: var(--muted); white-space: nowrap; }

/* ── Forms ───────────────────────────────────────────────────────────────── */
input:where([type="text"], [type="number"], [type="password"], [type="time"], [type="date"]),
select,
textarea {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
  font-family: var(--font);
  padding: 7px 10px;
  width: 100%;
  transition: border-color 0.15s;
  outline: none;
  -webkit-appearance: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
input[type="time"]::-webkit-calendar-picker-indicator,
input[type="date"]::-webkit-calendar-picker-indicator { filter: invert(0.7); cursor: pointer; }
textarea { resize: vertical; min-height: 60px; }
select { cursor: pointer; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  border: none;
  border-radius: 7px;
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  transition: background 0.15s, opacity 0.15s;
  white-space: nowrap;
  display: inline-flex; align-items: center; gap: 5px;
}
.btn-primary  { background: var(--primary); color: #fff; }
.btn-primary:hover  { background: var(--primary-h); }
.btn-success  { background: var(--success); color: #fff; }
.btn-success:hover  { opacity: 0.88; }
.btn-ghost    { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover    { background: var(--surface3); }
.btn-danger   { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.btn-danger:hover   { background: var(--danger); color: #fff; }
.btn-sm       { padding: 5px 10px; font-size: 12px; border-radius: 5px; }
.btn-full     { width: 100%; justify-content: center; }

/* ── Graphs ──────────────────────────────────────────────────────────────── */
.graph-section { display: flex; flex-direction: column; gap: 20px; }
.graph-block { }
.graph-block h3 {
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.chart-svg { display: block; overflow: visible; }
.chart-label { font-size: 10px; fill: var(--muted); font-family: var(--font); }
.chart-grid  { stroke: var(--border); stroke-width: 0.5; }
.chart-empty { color: var(--muted); font-size: 13px; padding: 20px 0; text-align: center; }
.note { font-size: 11px; color: var(--muted); margin-top: 6px; }

/* Compliance heatmap */
.heatmap-wrap { overflow-x: auto; padding-bottom: 4px; }
.heatmap-table { border-collapse: collapse; font-size: 11px; }
.heatmap-table th {
  color: var(--muted);
  font-weight: 500;
  padding: 2px 6px 6px 0;
  text-align: right;
  white-space: nowrap;
  font-size: 11px;
}
.heatmap-table td {
  width: 14px; height: 14px;
  border-radius: 3px;
  margin: 1px;
  cursor: default;
}
.hm-done   { background: var(--success); }
.hm-miss   { background: var(--surface3); }
.hm-empty  { background: transparent; }

/* BP chart legend */
.bp-legend { display: flex; gap: 16px; margin-bottom: 8px; flex-wrap: wrap; }
.bp-legend-item { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted); }
.bp-legend-dot { width: 10px; height: 10px; border-radius: 50%; }

/* Graph selector pills */
.graph-selector { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.selector-pill {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--muted);
  cursor: pointer;
  transition: all 0.12s;
  user-select: none;
}
.selector-pill.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* ── History ─────────────────────────────────────────────────────────────── */
.history-day {
  border-bottom: 1px solid var(--border);
  padding-bottom: 16px;
}
.history-day-header {
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 8px;
}
.history-entry {
  font-size: 13px;
  color: var(--text);
  padding: 2px 0;
}
.history-entry .ts { color: var(--muted); font-size: 11px; margin-left: 6px; }

/* ── Manage page ─────────────────────────────────────────────────────────── */
.manage-section { display: flex; flex-direction: column; gap: 16px; }
.manage-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.manage-list-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}
.manage-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 12px;
  background: var(--surface2);
  border-radius: 7px;
  font-size: 14px;
  gap: 10px;
}
.manage-item-name { flex: 1; }
.manage-item-meta { font-size: 12px; color: var(--muted); }
.add-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.add-form input, .add-form select { flex: 1; min-width: 100px; }
.schedule-grid {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 10px;
  align-items: center;
  font-size: 13px;
}
.day-pills { display: flex; gap: 4px; flex-wrap: wrap; }
.day-pill {
  font-size: 11px;
  font-weight: 600;
  width: 30px; height: 28px;
  border-radius: 5px;
  display: flex; align-items: center; justify-content: center;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  transition: all 0.12s;
}
.day-pill.active { background: var(--warning); border-color: var(--warning); color: #1b1e27; }

/* ── Login ───────────────────────────────────────────────────────────────── */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 32px;
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow);
}
.login-title { font-size: 20px; font-weight: 800; margin-bottom: 4px; }
.login-sub { color: var(--muted); font-size: 13px; margin-bottom: 24px; }
.login-card .field { margin-bottom: 14px; }
.login-card label { display: block; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; margin-bottom: 5px; }
.login-error { color: var(--danger); font-size: 13px; margin-bottom: 12px; }
.login-card .btn-full { margin-top: 8px; padding: 10px; font-size: 15px; }

/* ── Toast ───────────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 13px;
  box-shadow: var(--shadow);
  transform: translateX(120%);
  transition: transform 0.25s ease;
  max-width: 260px;
  word-break: break-word;
}
.toast.show { transform: translateX(0); }
.toast-success { border-left: 3px solid var(--success); }
.toast-error   { border-left: 3px solid var(--danger); }
.toast-info    { border-left: 3px solid var(--primary); }

/* ── Misc ────────────────────────────────────────────────────────────────── */
.loading { text-align: center; color: var(--muted); padding: 60px 0; font-size: 15px; }
.empty   { color: var(--muted); font-size: 13px; padding: 10px 0; }
.divider { height: 1px; background: var(--border); margin: 14px 0; }
.sep-label {
  display: flex; align-items: center; gap: 10px;
  color: var(--muted); font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .07em;
  margin: 14px 0 8px;
}
.sep-label::before, .sep-label::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 520px) {
  .header-inner { height: auto; padding: 8px 12px; flex-direction: column; align-items: flex-start; }
  nav { gap: 3px; }
  .nav-btn { padding: 5px 9px; font-size: 12px; }
  .site-title { font-size: 14px; }
  #view { padding: 14px 12px 80px; gap: 12px; }
  .card { padding: 14px 14px; }
  .supp-list-combined { columns: 1; }
  .schedule-grid { grid-template-columns: 1fr; }
  .music-list { grid-template-columns: 1fr; }
  .food-stat-cal, .food-stat-left { font-size: 15px; }
  .card-header-extra { gap: 8px; }
}
