/* =========================================================
   health-for design system
   ========================================================= */

/* --- Design tokens --------------------------------------- */
:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --text: #111827;
  --text-secondary: #374151;
  --muted: #6b7280;
  --border: #e5e7eb;
  --border-subtle: #f3f4f6;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-text: #ffffff;
  --accent-subtle: #eff6ff;
  --badge-bg: #eef2ff;
  --badge-text: #3730a3;
  --shadow-sm: 0 1px 2px 0 rgba(0,0,0,0.05);
  --shadow: 0 1px 3px 0 rgba(0,0,0,0.1), 0 1px 2px -1px rgba(0,0,0,0.1);
  --radius: 12px;
  --radius-sm: 8px;
}

[data-theme="dark"] {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-raised: #1c2128;
  --text: #e6edf3;
  --text-secondary: #c9d1d9;
  --muted: #8b949e;
  --border: #30363d;
  --border-subtle: #21262d;
  --accent: #4493f8;
  --accent-hover: #6eb0fb;
  --accent-text: #0d1117;
  --accent-subtle: #1f3459;
  --badge-bg: #1e293b;
  --badge-text: #93c5fd;
  --shadow-sm: 0 1px 2px 0 rgba(0,0,0,0.3);
  --shadow: 0 1px 3px 0 rgba(0,0,0,0.4);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { line-height: 1.3; color: var(--text); }
h1 { font-size: 1.5rem; font-weight: 700; }
h2 { font-size: 1rem; font-weight: 600; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- Top navigation -------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0 1.25rem;
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}

.brand {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.02em;
  padding-right: 1rem;
  border-right: 1px solid var(--border);
  margin-right: 0.5rem;
}
.brand:hover { text-decoration: none; }

.topbar nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex: 1;
}
.topbar nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 0.35rem 0.65rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  transition: color 0.15s, background 0.15s;
}
.topbar nav a:hover {
  color: var(--text);
  background: var(--border-subtle);
  text-decoration: none;
}
.topbar nav a.active {
  color: var(--accent);
  background: var(--accent-subtle);
}

.theme-toggle {
  margin-left: auto;
  flex-shrink: 0;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.3rem 0.55rem;
  cursor: pointer;
  font-size: 0.95rem;
  color: var(--muted);
  transition: border-color 0.15s;
}
.theme-toggle:hover { border-color: var(--accent); }

.nav-hamburger {
  display: none;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.25rem 0.55rem;
  cursor: pointer;
  font-size: 1rem;
  color: var(--muted);
  flex-shrink: 0;
}

/* --- Page layout ----------------------------------------- */
.container {
  max-width: 1040px;
  margin: 0 auto;
  padding: 1.75rem 1.25rem;
}

/* --- Page header ----------------------------------------- */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  gap: 1rem;
}
.page-header h1 { margin: 0; }

/* --- Stat summary row ------------------------------------ */
.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow-sm);
}
.stat-card__label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.25rem;
}
.stat-card__value {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1;
  color: var(--text);
}
.stat-card__unit {
  font-size: 0.85rem;
  color: var(--muted);
  margin-left: 0.2rem;
}
.stat-card__sub {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.2rem;
}

/* --- Cards ----------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
  box-shadow: var(--shadow-sm);
}
.card h2 {
  margin-bottom: 0.9rem;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.card-empty {
  border-style: dashed;
  text-align: center;
  padding: 2.5rem;
  color: var(--muted);
}

/* --- Chart card ------------------------------------------ */
.chart-card__header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.chart-card__header h2 { margin: 0; }
.chart-card__stat { display: flex; align-items: baseline; gap: 0.3rem; }
.stat-value { font-size: 1.75rem; font-weight: 700; }
.stat-unit  { font-size: 1rem; color: var(--muted); }
.stat-sub   { font-size: 0.8rem; color: var(--muted); }

/* --- Dashboard grid -------------------------------------- */
.dashboard-section { margin-bottom: 1.25rem; }
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
}

/* --- Banners --------------------------------------------- */
.banner {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-size: 0.875rem;
  font-weight: 500;
}
.banner-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.banner-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
[data-theme="dark"] .banner-success { background: #14532d; color: #86efac; border-color: #166534; }
[data-theme="dark"] .banner-error   { background: #450a0a; color: #fca5a5; border-color: #991b1b; }

/* --- Accounts bar ---------------------------------------- */
.accounts-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  align-items: center;
}
.account-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.75rem;
  border-radius: 999px;
  background: var(--badge-bg);
  color: var(--badge-text);
  font-size: 0.78rem;
  font-weight: 500;
  border: 1px solid var(--border);
}
.account-chip__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}
.account-chip--connected .account-chip__dot { background: #22c55e; }
.account-chip--error     .account-chip__dot { background: #ef4444; }
.account-chip__sync { color: var(--muted); font-weight: 400; }

/* --- List ------------------------------------------------ */
.list { list-style: none; }
.list li {
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.list li:last-child { border-bottom: none; padding-bottom: 0; }
.list li:first-child { padding-top: 0; }
.muted { color: var(--muted); font-size: 0.85rem; }
.more {
  display: inline-block;
  margin-top: 0.85rem;
  color: var(--accent);
  font-size: 0.85rem;
  font-weight: 500;
}
.more:hover { text-decoration: underline; }

/* --- Filter bar ------------------------------------------ */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}
.filter-bar .btn-ghost, .filter-bar .btn-sm {
  font-size: 0.8rem;
  padding: 0.28rem 0.65rem;
  text-decoration: none;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  color: var(--text-muted);
  background: transparent;
  cursor: pointer;
  white-space: nowrap;
}
.filter-bar .active-btn,
.filter-bar .btn-ghost.active-btn {
  background: var(--accent-subtle);
  color: var(--accent);
  border-color: var(--accent);
}

/* --- Activity type pill ---------------------------------- */
.activity-type {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: 5px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: var(--badge-bg);
  color: var(--badge-text);
}

/* --- Table ----------------------------------------------- */
.table, .data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
.table th, .data-table th {
  text-align: left;
  padding: 0.5rem 0.75rem;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
}
.table td, .data-table td {
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}
.table tr:last-child td, .data-table tr:last-child td { border-bottom: none; }
.table tbody tr:hover td, .data-table tbody tr:hover td { background: var(--border-subtle); }
.table tbody tr.row--error td, .data-table tbody tr.row--error td {
  background: rgba(220, 38, 38, 0.04);
}
.table-scroll { overflow-x: auto; }

/* --- Badge ----------------------------------------------- */
.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: var(--badge-bg);
  color: var(--badge-text);
  font-size: 0.72rem;
  font-weight: 600;
}
.badge-cancelled, .badge--red,       .badge--cancelled { background: #fee2e2; color: #991b1b; }
.badge-attended,  .badge--green,     .badge--attended  { background: #dcfce7; color: #166534; }
.badge-booked,    .badge--booked                       { background: #dbeafe; color: #1d4ed8; }
.badge-waitlist,  .badge--waitlist                     { background: #fef9c3; color: #854d0e; }
.badge-pending,   .badge--pending                      { background: #f3e8ff; color: #7e22ce; }
.badge--gray                                           { background: #f1f5f9; color: #475569; }
[data-theme="dark"] .badge-cancelled,
[data-theme="dark"] .badge--red,
[data-theme="dark"] .badge--cancelled  { background: #450a0a; color: #fca5a5; }
[data-theme="dark"] .badge-attended,
[data-theme="dark"] .badge--green,
[data-theme="dark"] .badge--attended   { background: #14532d; color: #86efac; }
[data-theme="dark"] .badge-booked,
[data-theme="dark"] .badge--booked     { background: #1e3a5f; color: #93c5fd; }
[data-theme="dark"] .badge-waitlist,
[data-theme="dark"] .badge--waitlist   { background: #451a03; color: #fde68a; }
[data-theme="dark"] .badge-pending,
[data-theme="dark"] .badge--pending    { background: #2e1065; color: #d8b4fe; }
[data-theme="dark"] .badge--gray       { background: #1e293b; color: #94a3b8; }

/* --- Buttons --------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.45rem 0.9rem;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  text-decoration: none;
}
.btn:hover { background: var(--accent-hover); text-decoration: none; }

.btn-sm {
  display: inline-flex;
  align-items: center;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
}
.btn-sm:hover { background: var(--accent-subtle); text-decoration: none; }
.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.25rem 0.6rem;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
}
.btn-ghost:hover, .btn-ghost.active-btn { background: var(--accent-subtle); color: var(--accent); border-color: var(--accent); }

/* --- Booking cards --------------------------------------- */
.booking-day { margin-bottom: 1.5rem; }
.booking-day--past { opacity: 0.75; }
.booking-day__header {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.booking-day__weekday {
  font-weight: 700;
  font-size: 1rem;
  color: var(--text);
}
.booking-day__date {
  font-size: 0.85rem;
}
.booking-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  margin-bottom: 0.5rem;
  box-shadow: var(--shadow-sm);
}
.booking-card__time {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--accent);
  min-width: 3.2rem;
  text-align: right;
}
.booking-card__body { flex: 1; }
.booking-card__name { font-weight: 600; font-size: 0.95rem; }
.booking-card__meta { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.15rem; }
.booking-card__status { flex-shrink: 0; }

/* --- Note cards ------------------------------------------ */
.note-card__header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.note-card__date { font-size: 0.9rem; }
.note-meta { font-size: 0.82rem; color: var(--muted); }

/* --- Form inputs ----------------------------------------- */
.form-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
}
.form-input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card-bg);
  color: var(--text);
  font-size: 0.9rem;
  box-sizing: border-box;
}
.form-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-subtle);
}

/* --- Form layout ----------------------------------------- */
.form-row {
  margin-bottom: 1.25rem;
}
.form-hint {
  display: block;
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.25rem;
}
.settings-form { max-width: 500px; }

/* --- Progress bars --------------------------------------- */
.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 0.6rem;
}
.progress-bar__fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.4s ease;
}
.progress-bar__fill--green { background: #22c55e; }

/* --- Goal cards ------------------------------------------ */
.goal-card { padding: 1rem 1.25rem; }
.goal-card__header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.4rem;
}
.goal-card__label { font-weight: 600; font-size: 0.95rem; }
.goal-card__target { font-size: 0.8rem; color: var(--text-muted); }
.goal-card__value {
  font-size: 1.15rem;
  font-weight: 700;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
}
.goal-card__delta { font-size: 0.82rem; font-weight: 500; }
.goal-card__delta--good { color: #22c55e; }
.goal-card__delta--bad  { color: #ef4444; }

/* --- Alerts ---------------------------------------------- */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  margin-bottom: 1.25rem;
}
.alert--success {
  background: #dcfce7;
  color: #166534;
  border: 1px solid #bbf7d0;
}
[data-theme="dark"] .alert--success {
  background: #14532d;
  color: #86efac;
  border-color: #166534;
}

/* --- Misc ------------------------------------------------ */
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
code {
  background: var(--badge-bg);
  color: var(--badge-text);
  padding: 0.1rem 0.35rem;
  border-radius: 5px;
  font-size: 0.85em;
}

.sync-banner {
  position: sticky;
  top: 52px;
  z-index: 90;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 1.25rem;
  background: var(--accent);
  color: #fff;
  font-size: 0.85rem;
  font-weight: 500;
}
.sync-banner[hidden] { display: none; }
.sync-banner__spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

.footer {
  max-width: 1040px;
  margin: 2rem auto;
  padding: 1rem 1.25rem;
  color: var(--muted);
  font-size: 0.8rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* --- Responsive ------------------------------------------ */
@media (max-width: 768px) {
  .nav-hamburger { display: block; }
  .topbar nav {
    display: none;
    position: absolute;
    top: 52px;
    left: 0;
    right: 0;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: 0.5rem 0;
    z-index: 99;
  }
  .topbar nav.open { display: flex; }
  .topbar nav a { border-radius: 0; padding: 0.65rem 1.25rem; font-size: 0.9rem; }
}
@media (max-width: 600px) {
  .stat-row { grid-template-columns: repeat(2, 1fr); }
  .container { padding: 1rem 0.75rem; }
}
@media (min-width: 769px) {
  .topbar nav { overflow-x: auto; scrollbar-width: none; }
  .topbar nav::-webkit-scrollbar { display: none; }
}
