/* Corrective — design system (vanilla CSS, no build step) */

:root {
  --paper: #f7f4ee;
  --surface: #ffffff;
  --surface-2: #f1ede4;
  --surface-3: #e9e3d6;
  --border: #e2dccf;
  --border-strong: #d3cabb;
  --text: #23201b;
  --text-muted: #6f685c;
  --text-faint: #9a9284;

  --teal: #0f766e;
  --teal-strong: #0b5c55;
  --teal-soft: #d5ece9;
  --coral: #e26d5c;
  --coral-soft: #f7ded8;
  --amber: #c98a1a;
  --amber-soft: #f6e8cc;
  --danger: #c0453b;
  --danger-soft: #f6dcd9;

  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 20px;
  --shadow-sm: 0 1px 2px rgba(35, 32, 27, 0.06), 0 1px 3px rgba(35, 32, 27, 0.05);
  --shadow: 0 4px 14px rgba(35, 32, 27, 0.08);
  --shadow-lg: 0 18px 48px rgba(35, 32, 27, 0.18);

  --sidebar-w: 250px;
  --font: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
}

[data-theme="dark"] {
  --paper: #16130f;
  --surface: #201c17;
  --surface-2: #272219;
  --surface-3: #322b20;
  --border: #342e24;
  --border-strong: #453d30;
  --text: #f2ece0;
  --text-muted: #b3a894;
  --text-faint: #7f7563;

  --teal: #2dd4bf;
  --teal-strong: #14b8a6;
  --teal-soft: #123f3a;
  --coral: #f0836f;
  --coral-soft: #3d251f;
  --amber: #e6b04a;
  --amber-soft: #3a2f18;
  --danger: #f27469;
  --danger-soft: #3d201d;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 20px 52px rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--paper);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

h1, h2, h3, h4 { margin: 0; line-height: 1.2; letter-spacing: -0.01em; }
p { margin: 0; }
button { font-family: inherit; }
a { color: inherit; text-decoration: none; }

/* Layout ------------------------------------------------------------ */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: 1fr;
  min-height: 100vh;
}

.sidebar {
  grid-column: 1;
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 24px 16px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.topbar { display: none; }

.content {
  grid-column: 2;
  padding: 32px 40px 64px;
  max-width: 1120px;
  width: 100%;
  margin: 0 auto;
  outline: none;
}

.bottom-nav { display: none; }

/* Brand ------------------------------------------------------------- */
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 16px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--teal), var(--teal-strong));
  color: #fff;
  flex: none;
  box-shadow: var(--shadow-sm);
}
.brand-mark svg { width: 20px; height: 20px; }
.brand-text { display: flex; flex-direction: column; }
.brand-text strong { font-size: 1.05rem; font-weight: 800; }
.brand-text span { font-size: 0.75rem; color: var(--text-muted); }

/* Nav --------------------------------------------------------------- */
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.92rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.nav-link svg { width: 19px; height: 19px; flex: none; }
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: var(--teal-soft); color: var(--teal-strong); }
[data-theme="dark"] .nav-link.active { color: var(--teal); }

.theme-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
}
.theme-toggle:hover { color: var(--text); border-color: var(--border-strong); }
.theme-toggle.compact { padding: 8px; }
.theme-toggle-icon {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--amber);
  box-shadow: inset -4px -4px 0 0 var(--surface-2);
}
[data-theme="dark"] .theme-toggle-icon { background: var(--teal); box-shadow: none; }

/* Page header ------------------------------------------------------- */
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}
.page-head h1 { font-size: 1.7rem; font-weight: 800; }
.page-head p { color: var(--text-muted); margin-top: 4px; font-size: 0.95rem; }

/* Cards ------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card-pad { padding: 20px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 18px 20px; border-bottom: 1px solid var(--border);
}
.card-head h3 { font-size: 1.02rem; font-weight: 700; }
.card-head .sub { color: var(--text-muted); font-size: 0.82rem; margin-top: 2px; }

.grid { display: grid; gap: 18px; }
.grid-stats { grid-template-columns: repeat(4, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}
.stat-label { color: var(--text-muted); font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }
.stat-value { font-size: 1.9rem; font-weight: 800; margin-top: 6px; }
.stat-hint { color: var(--text-faint); font-size: 0.82rem; margin-top: 2px; }
.stat-icon {
  float: right; width: 38px; height: 38px; border-radius: 10px;
  display: grid; place-items: center; background: var(--teal-soft); color: var(--teal-strong);
}
[data-theme="dark"] .stat-icon { color: var(--teal); }
.stat-icon svg { width: 19px; height: 19px; }

/* Banner ------------------------------------------------------------ */
.banner {
  display: flex; align-items: center; gap: 16px;
  padding: 20px 22px;
  border-radius: var(--radius);
  background: linear-gradient(120deg, var(--teal), var(--teal-strong));
  color: #fff;
  box-shadow: var(--shadow);
}
.banner .big { font-size: 2rem; font-weight: 800; line-height: 1; }
.banner .banner-text strong { font-size: 1.05rem; }
.banner .banner-text p { color: rgba(255,255,255,0.85); font-size: 0.88rem; }

/* Buttons ----------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 600; font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
  white-space: nowrap;
}
.btn svg { width: 17px; height: 17px; }
.btn-primary { background: var(--teal); color: #fff; }
.btn-primary:hover { background: var(--teal-strong); }
.btn-ghost { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.btn-ghost:hover { border-color: var(--border-strong); }
.btn-danger { background: transparent; color: var(--danger); border-color: transparent; }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { padding: 6px 10px; font-size: 0.82rem; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.icon-btn {
  display: grid; place-items: center; width: 34px; height: 34px;
  border-radius: 9px; border: 1px solid transparent; background: transparent;
  color: var(--text-faint); cursor: pointer;
}
.icon-btn:hover { background: var(--danger-soft); color: var(--danger); }
.icon-btn svg { width: 17px; height: 17px; }

/* Badges ------------------------------------------------------------ */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px;
  font-size: 0.74rem; font-weight: 700;
  background: var(--surface-2); color: var(--text-muted);
  text-transform: capitalize;
}
.badge.teal { background: var(--teal-soft); color: var(--teal-strong); }
[data-theme="dark"] .badge.teal { color: var(--teal); }
.badge.coral { background: var(--coral-soft); color: var(--coral); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }

/* Lists / rows ------------------------------------------------------ */
.row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 20px; border-bottom: 1px solid var(--border);
}
.row:last-child { border-bottom: none; }
.row-title { font-weight: 600; }
.row-sub { color: var(--text-muted); font-size: 0.82rem; margin-top: 2px; }
.row-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.row-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--teal); flex: none; }

.stack { display: flex; flex-direction: column; gap: 18px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

/* Forms ------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 0.83rem; font-weight: 600; color: var(--text-muted); }
.input, .select, .textarea {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font-family: inherit; font-size: 0.92rem;
}
.textarea { resize: vertical; min-height: 72px; }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px var(--teal-soft);
}
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.field-error { color: var(--danger); font-size: 0.78rem; }

input[type="range"] { width: 100%; accent-color: var(--teal); }

/* Dialog ------------------------------------------------------------ */
.dialog-root {
  position: fixed; inset: 0; z-index: 60;
  display: none; align-items: flex-start; justify-content: center;
  padding: 40px 16px; overflow-y: auto;
  background: rgba(20, 17, 13, 0.5);
  backdrop-filter: blur(2px);
}
.dialog-root.open { display: flex; }
.dialog {
  width: 100%; max-width: 560px; margin: auto 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  animation: pop 0.16s ease;
}
@keyframes pop { from { transform: translateY(8px) scale(0.98); opacity: 0; } to { transform: none; opacity: 1; } }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 20px 22px 6px; }
.dialog-head h3 { font-size: 1.15rem; font-weight: 800; }
.dialog-head p { color: var(--text-muted); font-size: 0.86rem; margin-top: 3px; }
.dialog-body { padding: 14px 22px; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 8px 22px 22px; }

/* States ------------------------------------------------------------ */
.empty {
  text-align: center; padding: 44px 20px; color: var(--text-muted);
  border: 1px dashed var(--border-strong); border-radius: var(--radius);
  background: var(--surface);
}
.empty svg { width: 34px; height: 34px; color: var(--text-faint); margin-bottom: 10px; }
.empty h3 { font-weight: 700; color: var(--text); margin-bottom: 4px; }
.empty p { font-size: 0.9rem; }

.skeleton { position: relative; overflow: hidden; background: var(--surface-2); border-radius: var(--radius); }
.skeleton::after {
  content: ""; position: absolute; inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.25), transparent);
  animation: shimmer 1.2s infinite;
}
[data-theme="dark"] .skeleton::after { background: linear-gradient(90deg, transparent, rgba(255,255,255,0.06), transparent); }
@keyframes shimmer { 100% { transform: translateX(100%); } }
.sk-line { height: 92px; }

.error-note {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 18px; border-radius: var(--radius);
  background: var(--danger-soft); color: var(--danger);
  border: 1px solid var(--danger);
}
.error-note button { margin-left: auto; }

/* Chart ------------------------------------------------------------- */
.chart { width: 100%; height: auto; }
.chart .grid-line { stroke: var(--border); stroke-width: 1; }
.chart .area { fill: var(--teal-soft); opacity: 0.7; }
.chart .line { fill: none; stroke: var(--teal); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart .dot { fill: var(--teal); }
.chart .lbl { fill: var(--text-faint); font-size: 10px; }

/* Pain slider descriptor ------------------------------------------- */
.pain-value { display: flex; align-items: baseline; gap: 10px; }
.pain-value .num { font-size: 2.6rem; font-weight: 800; }
.pain-scale { display: flex; justify-content: space-between; color: var(--text-faint); font-size: 0.74rem; margin-top: 2px; }

/* Schedule grid ----------------------------------------------------- */
.week { display: grid; grid-template-columns: repeat(7, 1fr); gap: 12px; }
.day-col { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); min-height: 140px; padding: 12px; }
.day-col h4 { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: 10px; text-align: center; }
.day-col.today { border-color: var(--teal); box-shadow: 0 0 0 2px var(--teal-soft); }
.sched-item { background: var(--teal-soft); color: var(--teal-strong); border-radius: 9px; padding: 8px 10px; font-size: 0.8rem; font-weight: 600; margin-bottom: 8px; }
[data-theme="dark"] .sched-item { color: var(--teal); }
.sched-item .t { display: block; font-weight: 700; font-size: 0.72rem; opacity: 0.8; }

/* Toast ------------------------------------------------------------- */
.toast-stack { position: fixed; bottom: 20px; right: 20px; z-index: 80; display: flex; flex-direction: column; gap: 10px; }
.toast {
  min-width: 240px; max-width: 340px;
  padding: 12px 16px; border-radius: var(--radius-sm);
  background: var(--text); color: var(--paper);
  box-shadow: var(--shadow-lg); font-size: 0.88rem; font-weight: 600;
  animation: pop 0.16s ease;
}
.toast.success { background: var(--teal-strong); color: #fff; }
.toast.error { background: var(--danger); color: #fff; }

/* helpers ----------------------------------------------------------- */
.muted { color: var(--text-muted); }
.mt-8 { margin-top: 8px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }
.flex { display: flex; } .flex-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.gap-8 { gap: 8px; } .gap-12 { gap: 12px; }
.wrap { flex-wrap: wrap; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Responsive -------------------------------------------------------- */
@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .topbar {
    display: flex; align-items: center; justify-content: space-between;
    position: sticky; top: 0; z-index: 40;
    padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
  }
  .topbar .brand { padding: 0; }
  .content { grid-column: 1; padding: 20px 16px 96px; }
  .bottom-nav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 40;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 6px 4px; padding-bottom: max(6px, env(safe-area-inset-bottom));
  }
  .bottom-nav .nav-link {
    flex: 1; flex-direction: column; gap: 3px; padding: 6px 2px;
    font-size: 0.64rem; border-radius: 10px; text-align: center;
  }
  .bottom-nav .nav-link svg { width: 20px; height: 20px; }
  .bottom-nav .nav-link span { line-height: 1; }
  .grid-stats { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .week { grid-template-columns: 1fr; }
  .day-col { min-height: auto; }
  .page-head h1 { font-size: 1.4rem; }
}

@media (max-width: 520px) {
  .field-row, .field-row-3 { grid-template-columns: 1fr; }
}
