/* ============================================================
   Tzana Pharma Companion — Design System
   Aesthetic: calm, refined, medical. Deep teal + warm sand + amber.
   Display: Fraunces (serif). Body/UI: Geist (grotesk).
   ============================================================ */

/* ---------- Tokens ---------- */
:root {
  /* Brand */
  --teal-900: #0a2a2c;
  --teal-800: #0e3a3d;
  --teal-700: #125054;
  --teal-600: #1a6a6f;
  --teal-500: #248489;
  --teal-400: #3ba0a4;
  --teal-300: #6cc2c5;
  --teal-200: #a8dde0;
  --teal-100: #d3eeef;
  --teal-050: #eaf6f7;

  /* Warm sand neutrals (light mode base) */
  --sand-000: #fdfbf7;
  --sand-050: #f7f3ea;
  --sand-100: #efe9da;
  --sand-200: #e0d8c4;
  --sand-300: #c9bfa3;
  --sand-400: #a89e85;
  --sand-500: #7d7560;
  --sand-600: #5d5645;
  --sand-700: #443f33;
  --sand-800: #2c2920;
  --sand-900: #1a1814;

  /* Accents */
  --amber-600: #b8741a;
  --amber-500: #d68a23;
  --amber-400: #e8a53a;
  --amber-300: #f0c066;
  --amber-200: #f5d795;
  --amber-100: #faeac0;
  --amber-050: #fdf6e3;

  --green-600: #1f7a3d;
  --green-500: #2a9c4d;
  --green-400: #4bc16a;
  --green-200: #b8e6c2;

  --red-600: #a32a1f;
  --red-500: #c2382a;
  --red-400: #e0543d;
  --red-200: #f3c2b8;

  /* Semantic (light) */
  --bg:            var(--sand-000);
  --bg-subtle:     var(--sand-050);
  --bg-elevated:   #ffffff;
  --bg-inset:      var(--sand-100);
  --surface:       #ffffff;
  --surface-2:     var(--sand-050);
  --border:        var(--sand-200);
  --border-strong: var(--sand-300);
  --text:          var(--sand-900);
  --text-2:        var(--sand-700);
  --text-muted:    var(--sand-500);
  --text-inverse:  #ffffff;

  --primary:       var(--teal-700);
  --primary-ink:   var(--teal-900);
  --primary-soft:  var(--teal-100);
  --primary-bg:    var(--teal-050);
  --on-primary:    #ffffff;

  --accent:        var(--amber-500);
  --accent-soft:   var(--amber-100);

  --success:       var(--green-500);
  --danger:        var(--red-500);
  --warning:       var(--amber-500);

  /* Type */
  --font-display: 'Fraunces', Georgia, 'Times New Roman', serif;
  --font-ui:      'Geist', -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  --font-mono:    'Geist Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  --text-xs:   0.75rem;   /* 12 */
  --text-sm:   0.8125rem; /* 13 */
  --text-base: 0.9375rem; /* 15 */
  --text-md:   1.0625rem; /* 17 */
  --text-lg:   1.25rem;   /* 20 */
  --text-xl:   1.5rem;    /* 24 */
  --text-2xl:  1.875rem;  /* 30 */
  --text-3xl:  2.25rem;   /* 36 */

  --leading-tight:  1.15;
  --leading-snug:   1.3;
  --leading-normal: 1.5;
  --leading-relaxed: 1.65;

  --tracking-tight:  -0.015em;
  --tracking-normal: 0;
  --tracking-wide:   0.02em;

  /* Spacing scale (4pt base) */
  --space-1:  4px;
  --space-2:  8px;
  --space-3:  12px;
  --space-4:  16px;
  --space-5:  20px;
  --space-6:  24px;
  --space-8:  32px;
  --space-10: 40px;
  --space-12: 48px;
  --space-16: 64px;
  --space-20: 80px;

  /* Radii */
  --r-xs: 4px;
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-xl: 20px;
  --r-2xl: 28px;
  --r-pill: 999px;

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(28, 24, 18, 0.04);
  --shadow-sm: 0 1px 3px rgba(28, 24, 18, 0.06), 0 1px 2px rgba(28, 24, 18, 0.04);
  --shadow-md: 0 4px 12px rgba(28, 24, 18, 0.08), 0 2px 4px rgba(28, 24, 18, 0.04);
  --shadow-lg: 0 12px 28px rgba(28, 24, 18, 0.10), 0 4px 8px rgba(28, 24, 18, 0.06);
  --shadow-xl: 0 24px 56px rgba(28, 24, 18, 0.14), 0 8px 16px rgba(28, 24, 18, 0.08);
  --shadow-glow: 0 0 0 4px var(--teal-100);

  /* Layout */
  --app-max: 1280px;
  --appbar-h: 60px;
  --tabbar-h: 64px;
  --rail-w: 76px;
  --rail-w-open: 240px;

  /* Motion */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --dur-fast: 140ms;
  --dur: 220ms;
  --dur-slow: 360ms;
}

/* ---------- Dark theme ---------- */
:root[data-theme="dark"] {
  --bg:            #0d1517;
  --bg-subtle:     #121d1f;
  --bg-elevated:   #182527;
  --bg-inset:      #1f2d2f;
  --surface:       #182527;
  --surface-2:     #1f2d2f;
  --border:        #2a3a3c;
  --border-strong: #3a4d50;
  --text:          #f1ece1;
  --text-2:        #c8c2b3;
  --text-muted:    #8a8579;
  --text-inverse:  var(--teal-900);

  --primary:       var(--teal-400);
  --primary-ink:   var(--teal-300);
  --primary-soft:  rgba(58, 160, 164, 0.16);
  --primary-bg:    rgba(58, 160, 164, 0.08);
  --on-primary:    var(--teal-900);

  --accent:        var(--amber-400);
  --accent-soft:   rgba(232, 165, 58, 0.18);

  --success:       var(--green-400);
  --danger:        var(--red-400);

  --shadow-xs: 0 1px 2px rgba(0,0,0,0.3);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.45), 0 2px 4px rgba(0,0,0,0.3);
  --shadow-lg: 0 16px 36px rgba(0,0,0,0.55), 0 6px 12px rgba(0,0,0,0.35);
  --shadow-xl: 0 28px 64px rgba(0,0,0,0.6), 0 12px 24px rgba(0,0,0,0.4);
  --shadow-glow: 0 0 0 4px var(--primary-soft);
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--text);
  background-color: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  font-feature-settings: "ss01", "cv01";
}
h1, h2, h3, h4, h5, h6 { margin: 0; font-weight: 600; color: var(--text); }
h1, h2, h3 { font-family: var(--font-display); font-weight: 500; letter-spacing: var(--tracking-tight); line-height: var(--leading-tight); }
h1 { font-size: var(--text-3xl); }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-xl); }
h4 { font-size: var(--text-lg); }
h5 { font-size: var(--text-md); }
h6 { font-size: var(--text-base); font-weight: 600; }
p { margin: 0 0 var(--space-3); }
a { color: var(--primary); text-decoration: none; transition: color var(--dur-fast) var(--ease-out); }
a:hover { color: var(--primary-ink); }
img { max-width: 100%; display: block; }
button { font-family: inherit; cursor: pointer; }
small { font-size: var(--text-sm); color: var(--text-muted); }
hr { border: 0; border-top: 1px solid var(--border); margin: var(--space-6) 0; }
::selection { background: var(--accent-soft); color: var(--text); }

/* ---------- Background texture (subtle grain) ---------- */
body::before {
  content: '';
  position: fixed; inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.08 0 0 0 0 0.06 0 0 0 0 0.04 0 0 0 0.5 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)' opacity='0.4'/></svg>");
  opacity: 0.035;
  mix-blend-mode: multiply;
}
:root[data-theme="dark"] body::before { mix-blend-mode: screen; opacity: 0.05; }

/* ---------- Layout primitives ---------- */
.stack > * + * { margin-top: var(--space-3); }
.stack-2 > * + * { margin-top: var(--space-2); }
.stack-4 > * + * { margin-top: var(--space-4); }
.stack-6 > * + * { margin-top: var(--space-6); }

.row { display: flex; gap: var(--space-4); flex-wrap: wrap; align-items: center; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); }
.row-gap-2 { gap: var(--space-2); }
.row-gap-3 { gap: var(--space-3); }
.row-gap-6 { gap: var(--space-6); }

.grid { display: grid; gap: var(--space-4); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
@media (max-width: 720px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .grid-auto { grid-template-columns: 1fr; }
}

.spread { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--space-4); }
.wrap { flex-wrap: wrap; }
.grow { flex: 1 1 auto; min-width: 0; }
.shrink-0 { flex-shrink: 0; }

.container { max-width: var(--app-max); margin: 0 auto; padding: 0 var(--space-5); width: 100%; }
.container-narrow { max-width: 640px; margin: 0 auto; padding: 0 var(--space-5); }
@media (max-width: 720px) { .container, .container-narrow { padding: 0 var(--space-4); } }

/* ---------- App shell ---------- */
.app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--rail-w) 1fr;
  position: relative;
  z-index: 1;
}
.app.rail-open { grid-template-columns: var(--rail-w-open) 1fr; }

/* Icon rail (desktop) */
.rail {
  background: var(--primary-ink);
  color: #e6efef;
  height: 100vh;
  position: sticky; top: 0;
  display: flex; flex-direction: column;
  padding: var(--space-4) 0;
  overflow: hidden;
}
.rail-brand {
  display: flex; align-items: center; gap: var(--space-3);
  padding: 0 var(--space-4) var(--space-6);
  border-bottom: 1px solid rgba(255,255,255,0.12);
  margin-bottom: var(--space-4);
  min-height: var(--appbar-h);
}
.rail-brand-mark {
  width: 36px; height: 36px;
  border-radius: var(--r-md);
  display: grid; place-items: center;
  flex-shrink: 0;
  overflow: hidden;
}
.rail-brand-mark img { width: 100%; height: 100%; object-fit: cover; }
.rail-brand-text { display: none; }
.app.rail-open .rail-brand-text { display: flex; align-items: center; gap: var(--space-2); }
.app.rail-open .rail-brand-text .wordmark { height: 22px; width: auto; display: block; }

.rail-nav { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; padding: 0 var(--space-2); flex: 1; overflow-y: auto; }
.rail-nav li { width: 100%; }
.rail-link {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-3);
  border-radius: var(--r-md);
  color: #cfe5e6;
  font-size: var(--text-sm);
  font-weight: 500;
  transition: background var(--dur-fast) var(--ease-out), color var(--dur-fast);
  white-space: nowrap;
}
.rail-link .rail-icon { width: 22px; height: 22px; flex-shrink: 0; color: #ffffff; opacity: 0.92; }
.rail-link-text { display: none; }
.app.rail-open .rail-link-text { display: inline; }
.rail-link:hover { background: rgba(255,255,255,0.10); color: #ffffff; }
.rail-link:hover .rail-icon { opacity: 1; }
.rail-link.active { background: rgba(108, 194, 197, 0.22); color: #ffffff; box-shadow: inset 2px 0 0 var(--teal-300); }
.rail-link.active .rail-icon { color: #a8dde0; opacity: 1; }

.rail-foot { padding: var(--space-3) var(--space-2); border-top: 1px solid rgba(255,255,255,0.12); }
.rail-link--logout { color: #b9d4d6; }
.rail-link--logout .rail-icon { color: #6cc2c5; opacity: 1; }

/* Main column */
.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Top app bar (mobile + desktop) */
.appbar {
  height: var(--appbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  gap: var(--space-4);
  padding: 0 var(--space-5);
  position: sticky; top: 0;
  z-index: 20;
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
}
.appbar-title { font-family: var(--font-display); font-weight: 500; font-size: var(--text-lg); letter-spacing: var(--tracking-tight); color: var(--text); }
.appbar-sub { font-size: var(--text-xs); color: var(--text-muted); margin-top: 1px; }
.appbar-back { display: none; }
.appbar-actions { margin-left: auto; display: flex; align-items: center; gap: var(--space-2); }

@media (max-width: 1024px) {
  .app, .app.rail-open { grid-template-columns: 1fr; }
  .rail { display: none; }
  .appbar-back { display: inline-flex; }
}

/* Role badge */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  border-radius: var(--r-pill);
  font-size: var(--text-xs); font-weight: 600;
  letter-spacing: var(--tracking-wide);
  background: var(--primary-bg); color: var(--primary);
  border: 1px solid var(--primary-soft);
}
.badge-amber { background: var(--amber-050); color: var(--amber-600); border-color: var(--amber-200); }
.badge-green { background: var(--green-200); color: var(--green-600); border-color: rgba(31,122,61,0.18); }
.badge-red   { background: var(--red-200); color: var(--red-600); border-color: rgba(163,42,31,0.18); }
.badge-muted { background: var(--bg-inset); color: var(--text-muted); border-color: var(--border); }
.badge-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* Avatar */
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--primary-soft); color: var(--primary);
  display: grid; place-items: center;
  font-weight: 600; font-size: var(--text-sm);
  overflow: hidden; flex-shrink: 0;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-lg { width: 56px; height: 56px; font-size: var(--text-lg); }
.avatar-xl { width: 88px; height: 88px; font-size: var(--text-2xl); border-radius: var(--r-xl); }

/* Content area */
.content { flex: 1; padding: var(--space-6) var(--space-5) calc(var(--space-12) + var(--tabbar-h)); }
@media (min-width: 1025px) { .content { padding-bottom: var(--space-12); } }
.content-narrow { max-width: 720px; margin: 0 auto; }

/* Page header */
.page-head { margin-bottom: var(--space-6); }
.page-head h1, .page-head h2 { margin-bottom: var(--space-1); }
.page-head small { color: var(--text-muted); }
.page-head-row { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4); flex-wrap: wrap; }
.breadcrumb { list-style: none; padding: 0; margin: 0 0 var(--space-2); display: flex; gap: var(--space-2); font-size: var(--text-xs); color: var(--text-muted); flex-wrap: wrap; }
.breadcrumb li + li::before { content: '›'; margin-right: var(--space-2); color: var(--border-strong); }
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--primary); }
.breadcrumb .active { color: var(--text-2); font-weight: 500; }

/* ---------- Bottom tab bar (mobile/PWA) ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  height: var(--tabbar-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex; justify-content: space-around; align-items: stretch;
  padding: 0 env(safe-area-inset-bottom) 0;
  z-index: 30;
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
}
.tab {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px;
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: 500;
  padding: 6px 4px;
  text-decoration: none;
  position: relative;
  transition: color var(--dur-fast);
}
.tab .tab-icon { width: 24px; height: 24px; }
.tab .tab-label { letter-spacing: var(--tracking-wide); }
.tab.active { color: var(--primary); }
.tab.active::before {
  content: ''; position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 28px; height: 3px; border-radius: 0 0 var(--r-pill) var(--r-pill);
  background: var(--accent);
}
.tab.has-more .tab-icon { color: var(--accent); }
@media (min-width: 1025px) { .tabbar { display: none; } }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.card-head { padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); background: var(--surface); }
.card-head h3, .card-head h4 { margin: 0; font-family: var(--font-display); font-weight: 500; }
.card-body { padding: var(--space-5); }
.card-foot { padding: var(--space-3) var(--space-5); border-top: 1px solid var(--border); background: var(--surface-2); }

/* Pagination */
.pagination { display: inline-flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.pagination.pagination-center { justify-content: center; display: flex; }
.pg-btn {
  min-width: 32px; height: 32px; padding: 0 8px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); border-radius: var(--r-md);
  background: var(--surface); color: var(--text);
  font-size: 13px; font-family: var(--font-mono); cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.pg-btn:hover:not(:disabled):not(.active) { background: var(--surface-2); border-color: var(--primary); }
.pg-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pg-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.pg-ellipsis { padding: 0 4px; color: var(--text-muted); }
.card-pad-tight .card-body { padding: var(--space-4); }
.card-pad-none .card-body { padding: 0; }
.card-flush { box-shadow: none; border-color: var(--border); }

/* Stat tile */
.stat {
  display: flex; flex-direction: column; gap: var(--space-1);
  padding: var(--space-4) var(--space-5);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  position: relative;
  overflow: hidden;
}
.stat-label { font-size: var(--text-xs); color: var(--text-muted); letter-spacing: var(--tracking-wide); text-transform: uppercase; font-weight: 600; }
.stat-value { font-family: var(--font-display); font-weight: 600; font-size: var(--text-2xl); letter-spacing: var(--tracking-tight); color: var(--text); line-height: 1.1; }
.stat-trend { font-size: var(--text-xs); display: inline-flex; align-items: center; gap: 4px; }
.stat-trend.up { color: var(--success); }
.stat-trend.down { color: var(--danger); }
.stat-spark { position: absolute; right: var(--space-3); bottom: var(--space-3); opacity: 0.5; }

/* ---------- List items ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list-row { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-5); border-bottom: 1px solid var(--border); }
.list-row:last-child { border-bottom: 0; }
.list-row:hover { background: var(--surface-2); }
.list-row--tight { padding: var(--space-3); }
.list-row .grow { flex: 1 1 auto; min-width: 0; }
.list-title { font-weight: 600; color: var(--text); }
.list-sub { font-size: var(--text-sm); color: var(--text-muted); margin-top: 2px; }
.list-trailing { color: var(--text-muted); font-size: var(--text-sm); text-align: right; flex-shrink: 0; }

/* Doctor row */
.doctor-row { display: flex; align-items: center; gap: var(--space-4); padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border); }
.doctor-row:last-child { border-bottom: 0; }
.doctor-row:hover { background: var(--surface-2); }
.doctor-avatar { width: 44px; height: 44px; border-radius: var(--r-md); background: var(--primary-bg); color: var(--primary); display: grid; place-items: center; font-weight: 600; flex-shrink: 0; }
.doctor-name { font-weight: 600; color: var(--text); }
.doctor-meta { font-size: var(--text-sm); color: var(--text-muted); margin-top: 2px; display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; }
.doctor-meta .sep { color: var(--border-strong); }
.doctor-actions { margin-left: auto; display: flex; gap: var(--space-2); flex-shrink: 0; }

/* Call/visit button */
.btn-call {
  display: inline-flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  background: var(--teal-700); color: #fff;
  border: none; border-radius: var(--r-pill);
  font-weight: 600; font-size: var(--text-sm);
  transition: transform var(--dur-fast), background var(--dur-fast);
  box-shadow: var(--shadow-sm);
}
.btn-call:hover { background: var(--teal-800); transform: translateY(-1px); }
.btn-call:active { transform: translateY(0); }
.btn-call.done { background: var(--green-500); }
.btn-call.done::before { content: '✓'; margin-right: 2px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  padding: var(--space-3) var(--space-5);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--r-md);
  font-size: var(--text-sm);
  font-weight: 600;
  letter-spacing: var(--tracking-wide);
  transition: all var(--dur-fast) var(--ease-out);
  white-space: nowrap;
  text-decoration: none;
}
.btn:hover { border-color: var(--text-muted); color: var(--text); background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn .btn-icon { width: 18px; height: 18px; }
.btn-primary {
  background: var(--primary); color: var(--on-primary); border-color: var(--primary);
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { background: var(--primary-ink); border-color: var(--primary-ink); color: var(--on-primary); }
.btn-accent { background: var(--accent); color: var(--teal-900); border-color: var(--accent); }
.btn-accent:hover { background: var(--amber-600); color: #fff; border-color: var(--amber-600); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: var(--red-600); border-color: var(--red-600); color: #fff; }
.btn-sm { padding: 6px var(--space-3); font-size: var(--text-xs); }
.btn-lg { padding: var(--space-4) var(--space-6); font-size: var(--text-md); }
.btn-block { width: 100%; }
.btn-pill { border-radius: var(--r-pill); }
.btn-icon-only { padding: var(--space-2); }
.btn-icon-only.btn-sm { padding: 6px; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--space-4); }
.field-label { font-size: var(--text-sm); font-weight: 600; color: var(--text-2); }
.field-hint { font-size: var(--text-xs); color: var(--text-muted); }
.field-error { font-size: var(--text-xs); color: var(--danger); }
.input, .select, .textarea {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  font-family: var(--font-ui); font-size: var(--text-base);
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--r-md);
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
  appearance: none;
}
.input::placeholder, .textarea::placeholder { color: var(--text-muted); }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: var(--shadow-glow);
}
.textarea { min-height: 96px; resize: vertical; line-height: var(--leading-normal); }
.select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path fill='%237d7560' d='M2 4l4 4 4-4z'/></svg>");
  background-repeat: no-repeat; background-position: right 12px center;
  padding-right: 36px;
}
input[type="checkbox"], input[type="radio"] { accent-color: var(--primary); width: 18px; height: 18px; }
.input-group { display: flex; align-items: stretch; }
.input-group .input { border-radius: var(--r-md) 0 0 var(--r-md); }
.input-group .btn { border-radius: 0 var(--r-md) var(--r-md) 0; border-left: 0; }

/* Search */
.search { position: relative; display: flex; align-items: center; gap: var(--space-2); }
.search .search-icon { position: absolute; left: var(--space-3); color: var(--text-muted); width: 18px; height: 18px; }
.search .input { padding-left: 40px; }

/* ---------- Tables ---------- */
.table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.table th, .table td { padding: var(--space-3) var(--space-4); text-align: left; border-bottom: 1px solid var(--border); }
.table th { font-weight: 600; color: var(--text-2); background: var(--surface-2); font-size: var(--text-xs); letter-spacing: var(--tracking-wide); text-transform: uppercase; position: sticky; top: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table-flush { border-collapse: collapse; }
.table-flush th, .table-flush td { padding-left: 0; padding-right: 0; }
.table-wrap { overflow-x: auto; border-radius: var(--r-lg); border: 1px solid var(--border); background: var(--surface); }
.table-wrap .table { border-radius: 0; }

/* ---------- Attendance grid ---------- */
.muster { display: grid; grid-template-columns: 220px repeat(31, minmax(34px, 1fr)); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--r-lg); overflow: auto; }
.muster > .muster-cell { background: var(--surface); padding: 6px; display: grid; place-items: center; font-size: var(--text-xs); }
.muster .muster-head { background: var(--surface-2); font-weight: 600; color: var(--text-2); }
.muster .muster-name { text-align: left; padding-left: var(--space-3); }
.muster .muster-holiday { color: var(--danger); }
.muster input[type="checkbox"] { margin: 0; }
@media (max-width: 1280px) { .muster { grid-template-columns: 180px repeat(31, minmax(30px, 1fr)); } }

/* Mobile attendance (per-day cards) */
.day-card { display: flex; align-items: center; gap: var(--space-4); padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border); }
.day-card:last-child { border-bottom: 0; }
.day-card .day-num { font-family: var(--font-display); font-weight: 600; font-size: var(--text-xl); color: var(--text); width: 44px; text-align: center; }
.day-card .day-dow { font-size: var(--text-xs); color: var(--text-muted); text-transform: uppercase; letter-spacing: var(--tracking-wide); }
.day-card.holiday { background: var(--surface-2); }
.day-card.holiday .day-num { color: var(--danger); }
.day-card .day-action { margin-left: auto; }

/* ---------- Chips / tags ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: var(--r-pill);
  font-size: var(--text-xs); font-weight: 600;
  background: var(--bg-inset); color: var(--text-2); border: 1px solid var(--border);
}
.chip-teal { background: var(--primary-bg); color: var(--primary); border-color: var(--primary-soft); }
.chip-amber { background: var(--amber-050); color: var(--amber-600); border-color: var(--amber-200); }
.chip-green { background: var(--green-200); color: var(--green-600); border-color: rgba(31,122,61,0.18); }
.chip-red { background: var(--red-200); color: var(--red-600); border-color: rgba(163,42,31,0.18); }
.chip-outline { background: transparent; }

/* ---------- Icons (inline SVG class) ---------- */
.icon { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
.icon-sm { width: 16px; height: 16px; }
.icon-lg { width: 22px; height: 22px; }
.icon-xl { width: 28px; height: 28px; }
.icon-block { display: block; }

/* ---------- Alerts ---------- */
.alert { display: flex; align-items: flex-start; gap: var(--space-3); padding: var(--space-4) var(--space-5); border-radius: var(--r-md); border: 1px solid; font-size: var(--text-sm); }
.alert-info { background: var(--primary-bg); border-color: var(--primary-soft); color: var(--primary-ink); }
.alert-warning { background: var(--amber-050); border-color: var(--amber-200); color: var(--amber-600); }
.alert-danger { background: var(--red-200); border-color: rgba(163,42,31,0.18); color: var(--red-600); }
.alert-success { background: var(--green-200); border-color: rgba(31,122,61,0.18); color: var(--green-600); }
.alert .icon { margin-top: 2px; }

/* ---------- Sheet / modal ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(10, 20, 22, 0.5); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); z-index: 40; opacity: 0; transition: opacity var(--dur); }
.sheet-backdrop.open { opacity: 1; }
.sheet {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%);
  background: var(--surface); border-radius: var(--r-2xl);
  box-shadow: var(--shadow-xl); width: min(640px, calc(100vw - 32px));
  max-height: calc(100vh - 32px); overflow: auto;
  z-index: 41; padding: var(--space-6);
}
@media (max-width: 720px) {
  .sheet { left: 0; right: 0; bottom: 0; top: auto; transform: translateY(100%); border-radius: var(--r-2xl) var(--r-2xl) 0 0; width: 100%; max-height: 88vh; transition: transform var(--dur-slow) var(--ease-out); }
  .sheet.open { transform: translateY(0); }
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-5); }
.sheet-close { background: transparent; border: 0; padding: 6px; color: var(--text-muted); border-radius: var(--r-pill); display: grid; place-items: center; }
.sheet-close:hover { background: var(--surface-2); color: var(--text); }

/* ---------- Sparkline / charts ---------- */
.chart-canvas { width: 100%; height: 100px; }
.bar-chart { display: flex; align-items: flex-end; gap: 6px; height: 120px; }
.bar-chart .bar { flex: 1; background: linear-gradient(180deg, var(--teal-400), var(--teal-700)); border-radius: 4px 4px 0 0; min-height: 4px; position: relative; }
.bar-chart .bar:hover { filter: brightness(1.1); }
.bar-chart .bar-label { position: absolute; bottom: -20px; left: 50%; transform: translateX(-50%); font-size: var(--text-xs); color: var(--text-muted); }

/* ---------- Progress ---------- */
.progress { height: 8px; background: var(--bg-inset); border-radius: var(--r-pill); overflow: hidden; }
.progress .progress-bar { height: 100%; background: linear-gradient(90deg, var(--teal-400), var(--teal-600)); border-radius: var(--r-pill); transition: width var(--dur-slow) var(--ease-out); }
.progress-amber .progress-bar { background: linear-gradient(90deg, var(--amber-300), var(--amber-500)); }

/* ---------- Empty state ---------- */
.empty { text-align: center; padding: var(--space-12) var(--space-5); color: var(--text-muted); }
.empty .empty-icon { width: 56px; height: 56px; margin: 0 auto var(--space-4); color: var(--border-strong); }
.empty h3 { color: var(--text-2); margin-bottom: var(--space-2); }

/* ---------- Skeleton ---------- */
.skeleton { background: linear-gradient(90deg, var(--bg-inset) 25%, var(--surface-2) 50%, var(--bg-inset) 75%); background-size: 200% 100%; animation: shimmer 1.5s infinite; border-radius: var(--r-md); }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ---------- Animations ---------- */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeInUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
@keyframes scaleIn { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: scale(1); } }
.fade-in { animation: fadeIn var(--dur-slow) var(--ease-out); }
.fade-in-up { animation: fadeInUp var(--dur-slow) var(--ease-out); }
.scale-in { animation: scaleIn var(--dur) var(--ease-out); }
.stagger > * { opacity: 0; animation: fadeInUp var(--dur-slow) var(--ease-out) forwards; }
.stagger > *:nth-child(1) { animation-delay: 40ms; }
.stagger > *:nth-child(2) { animation-delay: 80ms; }
.stagger > *:nth-child(3) { animation-delay: 120ms; }
.stagger > *:nth-child(4) { animation-delay: 160ms; }
.stagger > *:nth-child(5) { animation-delay: 200ms; }
.stagger > *:nth-child(6) { animation-delay: 240ms; }
.stagger > *:nth-child(7) { animation-delay: 280ms; }
.stagger > *:nth-child(8) { animation-delay: 320ms; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

/* ---------- Utilities ---------- */
.text-muted { color: var(--text-muted) !important; }
.text-2 { color: var(--text-2) !important; }
.text-primary { color: var(--primary) !important; }
.text-accent { color: var(--accent) !important; }
.text-danger { color: var(--danger) !important; }
.text-success { color: var(--success) !important; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-sm { font-size: var(--text-sm); }
.text-xs { font-size: var(--text-xs); }
.text-lg { font-size: var(--text-lg); }
.text-xl { font-size: var(--text-xl); }
.font-mono { font-family: var(--font-mono); }
.font-display { font-family: var(--font-display); }
.uppercase { text-transform: uppercase; letter-spacing: var(--tracking-wide); }
.tracking-wide { letter-spacing: var(--tracking-wide); }
.bold { font-weight: 700; }
.semibold { font-weight: 600; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: var(--space-1); } .mt-2 { margin-top: var(--space-2); } .mt-3 { margin-top: var(--space-3); } .mt-4 { margin-top: var(--space-4); } .mt-5 { margin-top: var(--space-5); } .mt-6 { margin-top: var(--space-6); } .mt-8 { margin-top: var(--space-8); }
.mb-0 { margin-bottom: 0; } .mb-2 { margin-bottom: var(--space-2); } .mb-3 { margin-bottom: var(--space-3); } .mb-4 { margin-bottom: var(--space-4); } .mb-6 { margin-bottom: var(--space-6); }
.hidden { display: none !important; }
.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; }
.divider { height: 1px; background: var(--border); margin: var(--space-4) 0; }
@media (max-width: 1024px) { .hide-mobile { display: none !important; } }
@media (min-width: 1025px) { .hide-desktop { display: none !important; } }

/* Desktop-only: hide tabbar-specific padding etc. */
@media (min-width: 1025px) {
  .content { padding-bottom: var(--space-12); }

/* ---------- Toast ---------- */
.tz-toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 16px); transform: translateX(-50%) translateY(20px);
  z-index: 50; opacity: 0; pointer-events: none;
  transition: opacity var(--dur), transform var(--dur);
  max-width: min(420px, calc(100vw - 32px));
}
.tz-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.tz-toast .alert { box-shadow: var(--shadow-lg); }
@media (min-width: 1025px) { .tz-toast { bottom: 24px; } }
}