/* =====================================================================
   ORTHOSMAT — Demo design system
   Apple Human Interface–inspired tokens & components.
   Light / dark / auto via html[data-theme].
   ===================================================================== */

:root {
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", "Segoe UI Variable Display", "Segoe UI", system-ui, sans-serif;
  --font-rounded: ui-rounded, "SF Pro Rounded", -apple-system, "Inter", system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  /* System colours (light) */
  --blue: #007AFF; --green: #34C759; --indigo: #5856D6; --orange: #FF9500;
  --pink: #FF2D55; --purple: #AF52DE; --red: #FF3B30; --teal: #30B0C7;
  --yellow: #FFCC00; --mint: #00C7BE; --cyan: #32ADE6; --brown: #A2845E; --gray: #8E8E93;
  --gray-2: #AEAEB2; --gray-3: #C7C7CC; --gray-4: #D1D1D6; --gray-5: #E5E5EA; --gray-6: #F2F2F7;

  --accent: var(--blue);
  --accent-contrast: #fff;

  --bg: #F2F2F7;          /* systemGroupedBackground */
  --bg-2: #FFFFFF;        /* secondarySystemGroupedBackground */
  --bg-3: #F2F2F7;        /* tertiary */
  --bg-elevated: #FFFFFF;

  --label: #000000;
  --label-2: rgba(60, 60, 67, .60);
  --label-3: rgba(60, 60, 67, .30);
  --label-4: rgba(60, 60, 67, .18);

  --fill: rgba(120, 120, 128, .20);
  --fill-2: rgba(120, 120, 128, .16);
  --fill-3: rgba(118, 118, 128, .12);
  --fill-4: rgba(116, 116, 128, .08);

  --sep: rgba(60, 60, 67, .22);
  --sep-opaque: #C6C6C8;

  --material: rgba(246, 246, 248, .72);
  --material-thick: rgba(252, 252, 253, .86);
  --material-chrome: rgba(249, 249, 251, .80);

  --shadow-1: 0 1px 1px rgba(0,0,0,.03), 0 1px 3px rgba(0,0,0,.04);
  --shadow-card: 0 1px 2px rgba(0,0,0,.04), 0 6px 20px rgba(0,0,0,.05);
  --shadow-pop: 0 24px 64px rgba(0,0,0,.18), 0 2px 8px rgba(0,0,0,.06);

  --r-xs: 8px; --r-sm: 10px; --r: 14px; --r-lg: 20px; --r-xl: 28px; --r-pill: 999px;

  --ease: cubic-bezier(.32, .72, 0, 1);
  --ease-out: cubic-bezier(.22, 1, .36, 1);
  --spring: cubic-bezier(.34, 1.36, .64, 1);

  --sidebar-w: 272px;
  --content-max: 1040px;
  --navbar-h: 52px;
  --tabbar-h: 58px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);

  color-scheme: light;
}

html[data-theme="dark"] {
  --blue: #0A84FF; --green: #30D158; --indigo: #5E5CE6; --orange: #FF9F0A;
  --pink: #FF375F; --purple: #BF5AF2; --red: #FF453A; --teal: #40C8E0;
  --yellow: #FFD60A; --mint: #63E6E2; --cyan: #64D2FF; --brown: #AC8E68; --gray: #8E8E93;
  --gray-2: #636366; --gray-3: #48484A; --gray-4: #3A3A3C; --gray-5: #2C2C2E; --gray-6: #1C1C1E;
  --bg: #000000; --bg-2: #1C1C1E; --bg-3: #2C2C2E; --bg-elevated: #1C1C1E;
  --label: #FFFFFF; --label-2: rgba(235,235,245,.60); --label-3: rgba(235,235,245,.30); --label-4: rgba(235,235,245,.16);
  --fill: rgba(120,120,128,.36); --fill-2: rgba(120,120,128,.32); --fill-3: rgba(118,118,128,.24); --fill-4: rgba(118,118,128,.18);
  --sep: rgba(84,84,88,.6); --sep-opaque: #38383A;
  --material: rgba(28,28,30,.72); --material-thick: rgba(28,28,30,.88); --material-chrome: rgba(22,22,24,.80);
  --shadow-1: none; --shadow-card: 0 0 0 .5px rgba(255,255,255,.06);
  --shadow-pop: 0 24px 64px rgba(0,0,0,.6), 0 0 0 .5px rgba(255,255,255,.08);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] {
    --blue: #0A84FF; --green: #30D158; --indigo: #5E5CE6; --orange: #FF9F0A;
    --pink: #FF375F; --purple: #BF5AF2; --red: #FF453A; --teal: #40C8E0;
    --yellow: #FFD60A; --mint: #63E6E2; --cyan: #64D2FF; --brown: #AC8E68; --gray: #8E8E93;
    --gray-2: #636366; --gray-3: #48484A; --gray-4: #3A3A3C; --gray-5: #2C2C2E; --gray-6: #1C1C1E;
    --bg: #000000; --bg-2: #1C1C1E; --bg-3: #2C2C2E; --bg-elevated: #1C1C1E;
    --label: #FFFFFF; --label-2: rgba(235,235,245,.60); --label-3: rgba(235,235,245,.30); --label-4: rgba(235,235,245,.16);
    --fill: rgba(120,120,128,.36); --fill-2: rgba(120,120,128,.32); --fill-3: rgba(118,118,128,.24); --fill-4: rgba(118,118,128,.18);
    --sep: rgba(84,84,88,.6); --sep-opaque: #38383A;
    --material: rgba(28,28,30,.72); --material-thick: rgba(28,28,30,.88); --material-chrome: rgba(22,22,24,.80);
    --shadow-1: none; --shadow-card: 0 0 0 .5px rgba(255,255,255,.06);
    --shadow-pop: 0 24px 64px rgba(0,0,0,.6), 0 0 0 .5px rgba(255,255,255,.08);
    color-scheme: dark;
  }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; min-height: 100dvh;
  font-family: var(--font); font-size: 16px; line-height: 1.4; letter-spacing: -.011em;
  color: var(--label); background: var(--bg);
  -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); text-decoration: none; }
button { font: inherit; color: inherit; }
img, svg { display: block; }
h1, h2, h3, h4, p { margin: 0; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; border-radius: 8px; }
::selection { background: color-mix(in srgb, var(--accent) 28%, transparent); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.icon { width: 1.25em; height: 1.25em; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon.fill { fill: currentColor; }

/* Typography scale (iOS Dynamic Type, large) */
.t-large { font: 700 34px/1.18 var(--font-display); letter-spacing: -.022em; }
.t-title1 { font: 700 28px/1.2 var(--font-display); letter-spacing: -.02em; }
.t-title2 { font: 700 22px/1.25 var(--font-display); letter-spacing: -.017em; }
.t-title3 { font: 600 20px/1.25 var(--font-display); letter-spacing: -.015em; }
.t-headline { font-weight: 600; font-size: 17px; letter-spacing: -.02em; }
.t-body { font-size: 17px; }
.t-callout { font-size: 16px; }
.t-sub { font-size: 15px; }
.t-foot { font-size: 13px; letter-spacing: -.004em; }
.t-cap { font-size: 12px; letter-spacing: 0; }
.t-cap2 { font-size: 11px; letter-spacing: .006em; }
.t-mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.tabular { font-variant-numeric: tabular-nums; }
.secondary { color: var(--label-2); }
.tertiary { color: var(--label-3); }
.accent { color: var(--accent); }
.danger { color: var(--red); }
.success { color: var(--green); }
.warning { color: var(--orange); }
.bold { font-weight: 600; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.clamp-2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.clamp-3 { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* Layout utilities */
.stack { display: flex; flex-direction: column; gap: var(--gap, 12px); }
.hstack { display: flex; align-items: center; gap: var(--gap, 10px); min-width: 0; }
.hstack.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.gap-4 { --gap: 4px; } .gap-6 { --gap: 6px; } .gap-8 { --gap: 8px; } .gap-16 { --gap: 16px; } .gap-20 { --gap: 20px; } .gap-24 { --gap: 24px; }
.mt-4 { margin-top: 4px; } .mt-8 { margin-top: 8px; } .mt-12 { margin-top: 12px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; } .mt-32 { margin-top: 32px; }
.mb-8 { margin-bottom: 8px; } .mb-16 { margin-bottom: 16px; }
.grid { display: grid; gap: var(--gap, 14px); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(var(--min, 240px), 1fr)); }
@media (max-width: 720px) {
  .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2.collapse, .grid-3.collapse, .grid-4.collapse { grid-template-columns: 1fr; }
}
.hscroll {
  display: flex; gap: 12px; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none;
  margin: 0 calc(var(--pad) * -1); padding: 2px var(--pad) 6px; scroll-padding: 0 var(--pad);
}
.hscroll::-webkit-scrollbar { display: none; }
.hscroll > * { scroll-snap-align: start; flex: none; }

/* ---------- App shell ---------- */
#app { min-height: 100vh; }
.shell { display: flex; min-height: 100vh; }
.main { flex: 1; min-width: 0; position: relative; }
.view { --pad: 20px; padding-bottom: calc(var(--tabbar-h) + var(--safe-b) + 40px); animation: viewIn .42s var(--ease-out) both; }
.view.no-anim { animation: none; }
@keyframes viewIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.content { max-width: var(--content-max); margin: 0 auto; padding: 0 var(--pad); }
.content.wide { max-width: 1280px; }
.content.narrow { max-width: 720px; }

@media (min-width: 900px) {
  .view { --pad: 36px; padding-bottom: 64px; }
}

/* Sidebar (iPadOS / macOS style) */
.sidebar {
  display: none; position: sticky; top: 0; height: 100vh; width: var(--sidebar-w); flex: none;
  background: var(--material-chrome); -webkit-backdrop-filter: saturate(180%) blur(30px); backdrop-filter: saturate(180%) blur(30px);
  border-right: .5px solid var(--sep); padding: 18px 12px 12px; overflow-y: auto; scrollbar-width: thin;
  flex-direction: column; gap: 4px; z-index: 30;
}
@media (min-width: 900px) { .sidebar { display: flex; } }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 14px; }
.brand-mark { width: 34px; height: 34px; border-radius: 9px; box-shadow: 0 1px 3px rgba(0,0,0,.15); }
.brand-name { font: 700 17px/1 var(--font-display); letter-spacing: .04em; }
.brand-sub { font-size: 11px; color: var(--label-2); margin-top: 3px; letter-spacing: .01em; }
.side-search { margin: 0 4px 10px; }
.side-group-title { font-size: 12px; font-weight: 600; color: var(--label-2); padding: 14px 12px 6px; letter-spacing: .01em; }
.side-item {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 9px;
  color: var(--label); font-size: 15px; font-weight: 450; transition: background .15s;
}
.side-item:hover { background: var(--fill-4); }
.side-item.active { background: var(--fill-3); font-weight: 590; }
.side-item .tile { width: 26px; height: 26px; border-radius: 7px; font-size: 14px; }
.side-item .count { margin-left: auto; font-size: 13px; color: var(--label-2); font-variant-numeric: tabular-nums; }
.side-footer { margin-top: auto; padding-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.user-chip {
  display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 14px; background: var(--bg-2);
  box-shadow: var(--shadow-card); cursor: pointer; border: 0; text-align: left; width: 100%;
  transition: transform .2s var(--ease);
}
.user-chip:active { transform: scale(.98); }
.status-line { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--label-2); padding: 0 10px; }

/* Tab bar (iOS) */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  height: calc(var(--tabbar-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  display: flex; background: var(--material-chrome);
  -webkit-backdrop-filter: saturate(180%) blur(24px); backdrop-filter: saturate(180%) blur(24px);
  border-top: .5px solid var(--sep);
}
@media (min-width: 900px) { .tabbar { display: none; } }
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--gray); font-size: 10.5px; font-weight: 500; letter-spacing: .01em; padding-top: 4px;
  transition: color .2s;
}
.tab .icon { width: 25px; height: 25px; stroke-width: 1.7; transition: transform .3s var(--spring); }
.tab.active { color: var(--accent); }
.tab.active .icon { stroke-width: 2.1; }
.tab:active .icon { transform: scale(.86); }

/* Navigation bar with collapsing large title */
.navbar {
  position: sticky; top: 0; z-index: 20; height: calc(var(--navbar-h) + var(--safe-t)); padding-top: var(--safe-t);
  transition: background .25s, border-color .25s, -webkit-backdrop-filter .25s, backdrop-filter .25s;
  border-bottom: .5px solid transparent;
}
.navbar.is-scrolled {
  background: var(--material-chrome); border-bottom-color: var(--sep);
  -webkit-backdrop-filter: saturate(180%) blur(24px); backdrop-filter: saturate(180%) blur(24px);
}
.navbar-inner {
  height: var(--navbar-h); max-width: var(--content-max); margin: 0 auto; padding: 0 calc(var(--pad) - 8px);
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 8px;
}
.content.wide ~ .navbar .navbar-inner, .view.wide .navbar-inner { max-width: 1280px; }
.nav-leading { display: flex; align-items: center; min-width: 0; }
.nav-title {
  font-weight: 600; font-size: 17px; letter-spacing: -.02em; opacity: 0; transform: translateY(4px);
  transition: opacity .2s, transform .25s var(--ease); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 52vw;
}
.navbar.is-scrolled .nav-title, .navbar.always .nav-title { opacity: 1; transform: none; }
.nav-actions { display: flex; align-items: center; justify-content: flex-end; gap: 4px; }
.nav-back {
  display: inline-flex; align-items: center; gap: 1px; color: var(--accent); font-size: 17px; padding: 8px 8px 8px 2px;
  border-radius: 10px; min-width: 0; letter-spacing: -.02em;
}
.nav-back .icon { width: 24px; height: 24px; stroke-width: 2.3; }
.nav-back span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-back:active { opacity: .45; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%; border: 0; background: transparent; color: var(--accent);
  display: inline-grid; place-items: center; cursor: pointer; transition: background .15s, transform .15s;
}
.icon-btn .icon { width: 22px; height: 22px; }
.icon-btn:hover { background: var(--fill-4); }
.icon-btn:active { transform: scale(.9); opacity: .6; }
.icon-btn.filled { background: var(--fill-3); color: var(--label); }

.large-title-wrap { max-width: var(--content-max); margin: 0 auto; padding: 2px var(--pad) 18px; }
.view.wide .large-title-wrap { max-width: 1280px; }
.eyebrow { font-size: 13px; font-weight: 600; color: var(--label-2); letter-spacing: .02em; text-transform: uppercase; margin-bottom: 4px; display: flex; align-items: center; gap: 6px; }
.large-title { font: 700 34px/1.15 var(--font-display); letter-spacing: -.024em; }
.subtitle { color: var(--label-2); font-size: 17px; margin-top: 6px; max-width: 62ch; }
@media (min-width: 900px) { .large-title { font-size: 38px; } }

/* ---------- Grouped sections & list rows ---------- */
.section { margin-top: 28px; }
.section:first-child { margin-top: 0; }
.section-header {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 0 4px 8px;
}
.section-header h2 { font: 700 22px/1.2 var(--font-display); letter-spacing: -.018em; }
.section-header .caps { font-size: 13px; font-weight: 400; text-transform: uppercase; color: var(--label-2); letter-spacing: .01em; padding-left: 12px; }
.section-header a, .section-header .link { font-size: 15px; font-weight: 400; color: var(--accent); background: none; border: 0; cursor: pointer; padding: 0; }
.section-footer { font-size: 13px; color: var(--label-2); padding: 8px 16px 0; line-height: 1.38; }

.group {
  background: var(--bg-2); border-radius: var(--r-sm); overflow: hidden; box-shadow: var(--shadow-1);
}
.group.lg { border-radius: var(--r); }
.row {
  position: relative; display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 10px 16px;
  color: var(--label); background: transparent; border: 0; width: 100%; text-align: left; cursor: default;
  transition: background .12s;
}
a.row, button.row, .row[data-href], .row.tap { cursor: pointer; }
a.row:active, button.row:active, .row.tap:active, .row[data-href]:active { background: var(--fill-3); }
@media (hover: hover) { a.row:hover, button.row:hover, .row.tap:hover { background: var(--fill-4); } }
.row + .row::before {
  content: ""; position: absolute; top: 0; right: 0; left: var(--inset, 16px); height: .5px; background: var(--sep);
}
.row.has-icon { --inset: 60px; }
.row.has-thumb { --inset: 84px; }
.row-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row-title { font-size: 16px; color: var(--label); letter-spacing: -.015em; }
.row-sub { font-size: 14px; color: var(--label-2); line-height: 1.3; }
.row-detail { color: var(--label-2); font-size: 15px; white-space: nowrap; display: flex; align-items: center; gap: 6px; }
.row-chevron { color: var(--label-3); width: 14px; height: 14px; stroke-width: 2.6; }
.row.destructive .row-title { color: var(--red); }
.row.accent .row-title { color: var(--accent); }
.row-thumb { width: 56px; height: 56px; border-radius: 10px; overflow: hidden; flex: none; background: var(--fill-3); }

.tile {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; flex: none;
  color: #fff; background: var(--tint, var(--accent)); font-size: 16px;
  box-shadow: inset 0 0 0 .5px rgba(0,0,0,.06);
  background-image: linear-gradient(180deg, rgba(255,255,255,.18), rgba(255,255,255,0) 60%);
}
.tile .icon { width: 18px; height: 18px; stroke-width: 2; }
.tile.lg { width: 44px; height: 44px; border-radius: 11px; }
.tile.lg .icon { width: 24px; height: 24px; }
.tile.xl { width: 64px; height: 64px; border-radius: 16px; }
.tile.xl .icon { width: 34px; height: 34px; }
.tile.soft { background: color-mix(in srgb, var(--tint, var(--accent)) 14%, transparent); color: var(--tint, var(--accent)); box-shadow: none; background-image: none; }

/* ---------- Cards ---------- */
.card {
  background: var(--bg-2); border-radius: var(--r-lg); padding: 18px; box-shadow: var(--shadow-card);
  position: relative; overflow: hidden; color: var(--label);
}
.card.flat { box-shadow: var(--shadow-1); }
.card.pad-lg { padding: 24px; }
.card.tap, a.card { cursor: pointer; transition: transform .35s var(--ease), box-shadow .3s; display: block; }
.card.tap:active, a.card:active { transform: scale(.975); }
@media (hover: hover) { .card.tap:hover, a.card:hover { box-shadow: var(--shadow-card), 0 10px 30px rgba(0,0,0,.06); } }
.card-title { font: 600 17px/1.3 var(--font); letter-spacing: -.02em; }
.card-sub { color: var(--label-2); font-size: 14px; margin-top: 3px; }
.card-hero {
  color: #fff; background: radial-gradient(120% 140% at 0% 0%, var(--c1, #3D7BFF) 0%, var(--c2, #5B3DF5) 55%, var(--c3, #2A1A8F) 100%);
  box-shadow: 0 12px 32px color-mix(in srgb, var(--c2, #5B3DF5) 28%, transparent);
}
.card-hero .card-sub, .card-hero .secondary { color: rgba(255,255,255,.78); }
.card-hero::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(60% 80% at 100% 0%, rgba(255,255,255,.22), transparent 60%);
}
.card-hero > * { position: relative; z-index: 1; }
.card.glass {
  background: var(--material); -webkit-backdrop-filter: saturate(180%) blur(24px); backdrop-filter: saturate(180%) blur(24px);
}
.media {
  border-radius: var(--r); overflow: hidden; background: #0b0d12; position: relative; aspect-ratio: 4/3;
}
.media > svg, .media > img { width: 100%; height: 100%; object-fit: cover; }
.media .media-label {
  position: absolute; left: 10px; bottom: 10px; font-size: 11px; font-weight: 600; letter-spacing: .04em; color: rgba(255,255,255,.85);
  background: rgba(0,0,0,.45); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px); padding: 4px 8px; border-radius: 6px;
}

/* ---------- Buttons ---------- */
.btn {
  --b-bg: var(--accent); --b-fg: var(--accent-contrast);
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 44px; padding: 0 20px; border-radius: var(--r-pill); border: 0; cursor: pointer;
  font-size: 16px; font-weight: 600; letter-spacing: -.016em; white-space: nowrap;
  background: var(--b-bg); color: var(--b-fg);
  transition: transform .22s var(--ease), opacity .15s, background .2s, box-shadow .2s, filter .15s;
  user-select: none; -webkit-user-select: none; text-decoration: none;
}
.btn .icon { width: 19px; height: 19px; stroke-width: 2.1; }
.btn:hover { filter: brightness(1.06); }
.btn:active { transform: scale(.965); opacity: .82; }
.btn[disabled], .btn.disabled { opacity: .38; pointer-events: none; }
.btn-filled { box-shadow: 0 1px 2px rgba(0,0,0,.08), 0 6px 16px color-mix(in srgb, var(--b-bg) 26%, transparent); }
.btn-tinted { --b-bg: color-mix(in srgb, var(--accent) 15%, transparent); --b-fg: var(--accent); }
.btn-gray { --b-bg: var(--fill-3); --b-fg: var(--accent); }
.btn-gray.label { --b-fg: var(--label); }
.btn-plain { --b-bg: transparent; --b-fg: var(--accent); padding: 0 10px; font-weight: 400; }
.btn-plain:hover { filter: none; background: var(--fill-4); }
.btn-destructive { --b-bg: var(--red); --b-fg: #fff; }
.btn-destructive.btn-tinted { --b-bg: color-mix(in srgb, var(--red) 14%, transparent); --b-fg: var(--red); }
.btn-success { --b-bg: var(--green); --b-fg: #fff; }
.btn-dark { --b-bg: var(--label); --b-fg: var(--bg-2); }
.btn-white { --b-bg: #fff; --b-fg: #111; }
.btn-glass { --b-bg: rgba(255,255,255,.2); --b-fg: #fff; -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); }
.btn-sm { height: 32px; padding: 0 14px; font-size: 14px; gap: 5px; }
.btn-sm .icon { width: 16px; height: 16px; }
.btn-xs { height: 26px; padding: 0 11px; font-size: 13px; gap: 4px; }
.btn-xs .icon { width: 14px; height: 14px; }
.btn-lg { height: 52px; padding: 0 28px; font-size: 17px; border-radius: 16px; }
.btn-block { width: 100%; }
.btn-square { border-radius: 12px; }
.btn-icon { width: 44px; padding: 0; }
.btn-icon.btn-sm { width: 32px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.btn-row.end { justify-content: flex-end; }
.btn .spinner { width: 16px; height: 16px; }

/* ---------- Segmented control ---------- */
.seg {
  position: relative; display: inline-grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  padding: 2px; border-radius: 9px; background: var(--fill-3); isolation: isolate; max-width: 100%;
}
.seg.block { display: grid; width: 100%; }
.seg button {
  position: relative; z-index: 1; border: 0; background: transparent; height: 30px; padding: 0 14px;
  font-size: 13.5px; font-weight: 500; color: var(--label); border-radius: 7px; cursor: pointer; white-space: nowrap;
  transition: opacity .15s;
}
.seg button:active { opacity: .55; }
.seg button.on { font-weight: 600; }
.seg .thumb {
  position: absolute; z-index: 0; top: 2px; bottom: 2px; left: 2px; border-radius: 7px;
  background: var(--bg-elevated); box-shadow: 0 3px 8px rgba(0,0,0,.12), 0 3px 1px rgba(0,0,0,.04), 0 0 0 .5px rgba(0,0,0,.04);
  transition: transform .32s var(--ease), width .32s var(--ease);
}
html[data-theme="dark"] .seg .thumb { background: #636366; }
@media (prefers-color-scheme: dark) { html[data-theme="auto"] .seg .thumb { background: #636366; } }

/* ---------- Switch ---------- */
.switch { position: relative; width: 51px; height: 31px; flex: none; display: inline-block; cursor: pointer; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; z-index: 2; }
.switch .track { position: absolute; inset: 0; border-radius: 99px; background: var(--fill); transition: background .25s; }
.switch .knob {
  position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff;
  box-shadow: 0 3px 8px rgba(0,0,0,.15), 0 3px 1px rgba(0,0,0,.06); transition: transform .3s var(--spring), width .2s var(--ease);
}
.switch input:checked ~ .track { background: var(--green); }
.switch input:checked ~ .knob { transform: translateX(20px); }
.switch input:active ~ .knob { width: 32px; }
.switch input:checked:active ~ .knob { transform: translateX(15px); }
.switch input:focus-visible ~ .track { outline: 3px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 2px; }

/* ---------- Badges / chips ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 6px;
  font-size: 12px; font-weight: 600; letter-spacing: .005em; white-space: nowrap;
  color: var(--tone, var(--label-2)); background: color-mix(in srgb, var(--tone, var(--gray)) 14%, transparent);
}
.badge .icon { width: 12px; height: 12px; stroke-width: 2.4; }
.badge.solid { background: var(--tone, var(--gray)); color: #fff; }
.badge.pill { border-radius: 99px; }
.badge.lg { height: 26px; font-size: 13px; padding: 0 10px; }
.tone-blue { --tone: var(--blue); } .tone-green { --tone: var(--green); } .tone-orange { --tone: var(--orange); }
.tone-red { --tone: var(--red); } .tone-purple { --tone: var(--purple); } .tone-indigo { --tone: var(--indigo); }
.tone-pink { --tone: var(--pink); } .tone-teal { --tone: var(--teal); } .tone-gray { --tone: var(--gray); }
.tone-yellow { --tone: #C9A000; } .tone-mint { --tone: var(--mint); } .tone-brown { --tone: var(--brown); }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px; border-radius: 99px;
  background: var(--bg-2); border: .5px solid var(--sep); font-size: 14px; font-weight: 500; color: var(--label);
  cursor: pointer; white-space: nowrap; transition: background .15s, transform .2s var(--ease), color .15s;
  box-shadow: var(--shadow-1);
}
.chip .icon { width: 16px; height: 16px; }
.chip:active { transform: scale(.95); }
.chip.on { background: var(--label); color: var(--bg-2); border-color: transparent; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 calc(var(--pad) * -1); padding: 2px var(--pad) 4px; }
.chips.scroll::-webkit-scrollbar { display: none; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--tone, var(--green)); flex: none; }
.dot.pulse { box-shadow: 0 0 0 0 color-mix(in srgb, var(--tone, var(--green)) 60%, transparent); animation: pulse 2s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 7px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }

/* ---------- Form fields ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .field-label { font-size: 13px; font-weight: 500; color: var(--label-2); padding-left: 4px; }
.input, .textarea, .select {
  width: 100%; font: inherit; font-size: 16px; color: var(--label); background: var(--bg-2);
  border: .5px solid var(--sep); border-radius: 11px; padding: 0 14px; height: 46px; outline: none;
  transition: border-color .15s, box-shadow .15s; -webkit-appearance: none; appearance: none;
}
.textarea { padding: 12px 14px; height: auto; min-height: 110px; resize: vertical; line-height: 1.45; }
.select {
  padding-right: 36px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238E8E93' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m7 10 5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 18px;
}
.input:focus, .textarea:focus, .select:focus { border-color: var(--accent); box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 18%, transparent); }
.input::placeholder, .textarea::placeholder { color: var(--label-3); }
.group .input, .group .select { border: 0; border-radius: 0; background: transparent; box-shadow: none; }
.search {
  display: flex; align-items: center; gap: 6px; height: 38px; padding: 0 10px; border-radius: 11px; background: var(--fill-3); color: var(--label-2);
}
.search .icon { width: 17px; height: 17px; stroke-width: 2.2; }
.search input { flex: 1; min-width: 0; border: 0; outline: none; background: transparent; font: inherit; font-size: 16px; color: var(--label); }
.search input::placeholder { color: var(--label-2); }
.form-row { display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 4px 16px; position: relative; }
.form-row + .form-row::before { content: ""; position: absolute; top: 0; right: 0; left: 16px; height: .5px; background: var(--sep); }
.form-row > label { width: 120px; flex: none; font-size: 16px; }
.form-row .input, .form-row .select { padding: 0; height: 44px; text-align: right; }
.check {
  width: 22px; height: 22px; border-radius: 50%; border: 1.5px solid var(--label-3); display: grid; place-items: center; flex: none;
  transition: background .2s, border-color .2s; color: #fff;
}
.check .icon { width: 14px; height: 14px; stroke-width: 3; opacity: 0; transform: scale(.5); transition: all .25s var(--spring); }
.checked .check, .check.on { background: var(--accent); border-color: var(--accent); }
.checked .check .icon, .check.on .icon { opacity: 1; transform: none; }
input[type="range"] { width: 100%; accent-color: var(--accent); }

/* ---------- Progress ---------- */
.progress { height: 6px; border-radius: 99px; background: var(--fill-3); overflow: hidden; }
.progress > i { display: block; height: 100%; border-radius: inherit; background: var(--tone, var(--accent)); width: var(--v, 0%); transition: width .8s var(--ease-out); }
.progress.thin { height: 4px; }
.progress.thick { height: 10px; }
.ring { --size: 64px; --stroke: 7; position: relative; width: var(--size); height: var(--size); flex: none; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring circle { fill: none; stroke-width: var(--stroke); stroke-linecap: round; }
.ring .track { stroke: var(--fill-3); }
.ring .val { stroke: var(--tone, var(--accent)); transition: stroke-dashoffset 1s var(--ease-out); }
.ring .ring-label { position: absolute; inset: 0; display: grid; place-items: center; font-weight: 700; font-size: calc(var(--size) * .24); font-variant-numeric: tabular-nums; letter-spacing: -.02em; }

/* Stats */
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat-label { font-size: 13px; color: var(--label-2); font-weight: 500; display: flex; align-items: center; gap: 6px; }
.stat-value { font: 700 28px/1.15 var(--font-display); letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat-value small { font-size: 15px; font-weight: 600; color: var(--label-2); letter-spacing: 0; margin-left: 2px; }
.stat-delta { font-size: 13px; font-weight: 600; }
.stat-delta.up { color: var(--green); } .stat-delta.down { color: var(--red); }

/* Bars (simple chart) */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 120px; }
.bars > div { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bars i { display: block; width: 100%; max-width: 28px; border-radius: 6px 6px 3px 3px; background: var(--tone, var(--accent)); min-height: 3px; transition: height .8s var(--ease-out); }
.bars i.muted { background: var(--fill-2); }
.bars span { font-size: 11px; color: var(--label-2); }

/* ---------- Notices ---------- */
.notice {
  display: flex; gap: 12px; align-items: flex-start; padding: 14px 16px; border-radius: var(--r);
  background: color-mix(in srgb, var(--tone, var(--blue)) 10%, var(--bg-2)); color: var(--label); font-size: 14px; line-height: 1.42;
  border: .5px solid color-mix(in srgb, var(--tone, var(--blue)) 22%, transparent);
}
.notice > .icon { color: var(--tone, var(--blue)); width: 20px; height: 20px; margin-top: 1px; }
.notice strong { font-weight: 600; }
.disclaimer { --tone: var(--orange); }
.demo-source {
  display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 500; color: var(--label-2);
  padding: 3px 8px; border-radius: 6px; background: var(--fill-4); border: .5px dashed var(--label-3);
}
.demo-source .icon { width: 12px; height: 12px; }

.lock-card { text-align: center; padding: 28px 22px; }
.lock-card .tile { margin: 0 auto 14px; }
.lock-card p { color: var(--label-2); font-size: 15px; max-width: 40ch; margin: 6px auto 18px; }

.empty { text-align: center; padding: 48px 20px; color: var(--label-2); }
.empty .icon { width: 44px; height: 44px; margin: 0 auto 12px; color: var(--label-3); stroke-width: 1.4; }
.empty h3 { color: var(--label); font-size: 20px; font-weight: 600; margin-bottom: 4px; }

.skeleton { background: linear-gradient(90deg, var(--fill-4) 25%, var(--fill-3) 50%, var(--fill-4) 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: 8px; }
@keyframes shimmer { to { background-position: -200% 0; } }
.spinner { width: 20px; height: 20px; border-radius: 50%; border: 2.5px solid var(--fill); border-top-color: var(--label-2); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.divider { height: .5px; background: var(--sep); margin: 16px 0; border: 0; }
.kbd { font-family: var(--font-mono); font-size: 12px; padding: 1px 6px; border-radius: 5px; background: var(--fill-3); }
.avatar {
  width: var(--s, 36px); height: var(--s, 36px); border-radius: 50%; flex: none; display: grid; place-items: center;
  font-weight: 600; font-size: calc(var(--s, 36px) * .4); color: #fff; letter-spacing: .01em;
  background: linear-gradient(180deg, var(--a1, #A5B4FC), var(--a2, #6366F1));
}
.table-wrap { overflow-x: auto; border-radius: var(--r-sm); background: var(--bg-2); box-shadow: var(--shadow-1); }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-weight: 600; font-size: 12px; color: var(--label-2); padding: 10px 14px; border-bottom: .5px solid var(--sep); white-space: nowrap; text-transform: uppercase; letter-spacing: .02em; }
.table td { padding: 11px 14px; border-bottom: .5px solid var(--sep); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background .12s; }
.table tbody tr:hover { background: var(--fill-4); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Sheet / Alert / Toast ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.32);
  opacity: 0; transition: opacity .35s var(--ease); display: flex; align-items: flex-end; justify-content: center;
}
.overlay.open { opacity: 1; }
.sheet {
  width: 100%; max-width: 640px; max-height: 92vh; max-height: 92dvh; background: var(--bg); color: var(--label);
  border-radius: 14px 14px 0 0; box-shadow: var(--shadow-pop); display: flex; flex-direction: column;
  transform: translateY(100%); transition: transform .5s var(--ease); padding-bottom: var(--safe-b);
}
.sheet.plain { background: var(--bg-2); }
.overlay.open .sheet { transform: none; }
.sheet-grabber { width: 36px; height: 5px; border-radius: 3px; background: var(--label-3); margin: 6px auto 0; flex: none; }
.sheet-head { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 8px 10px 6px; flex: none; }
.sheet-head .sheet-title { font-weight: 600; font-size: 17px; letter-spacing: -.02em; text-align: center; }
.sheet-head .end { justify-self: end; }
.sheet-body { overflow-y: auto; padding: 8px 20px 24px; --pad: 20px; overscroll-behavior: contain; }
@media (min-width: 720px) {
  .overlay { align-items: center; padding: 24px; }
  .sheet { border-radius: 18px; transform: translateY(24px) scale(.97); opacity: 0; transition: transform .45s var(--ease), opacity .3s; max-height: 86vh; }
  .sheet.wide { max-width: 860px; }
  .overlay.open .sheet { transform: none; opacity: 1; }
  .sheet-grabber { display: none; }
  .sheet-head { padding: 14px 14px 6px; }
}
.alert-overlay { align-items: center; padding: 24px; }
.alert {
  width: 270px; border-radius: 14px; background: var(--material-thick);
  -webkit-backdrop-filter: saturate(180%) blur(40px); backdrop-filter: saturate(180%) blur(40px);
  box-shadow: var(--shadow-pop); text-align: center; transform: scale(1.12); opacity: 0;
  transition: transform .35s var(--spring), opacity .2s; overflow: hidden;
}
.overlay.open .alert { transform: none; opacity: 1; }
.alert-body { padding: 19px 16px 17px; }
.alert-title { font-weight: 600; font-size: 17px; letter-spacing: -.02em; }
.alert-msg { font-size: 13px; margin-top: 4px; line-height: 1.35; color: var(--label); }
.alert-actions { display: flex; border-top: .5px solid var(--sep); }
.alert-actions.stacked { flex-direction: column; }
.alert-actions button {
  flex: 1; height: 44px; border: 0; background: transparent; color: var(--accent); font-size: 17px; cursor: pointer;
}
.alert-actions button + button { border-left: .5px solid var(--sep); }
.alert-actions.stacked button + button { border-left: 0; border-top: .5px solid var(--sep); }
.alert-actions button.primary { font-weight: 600; }
.alert-actions button.destructive { color: var(--red); }
.alert-actions button:active { background: var(--fill-3); }

.toast-wrap { position: fixed; z-index: 200; left: 0; right: 0; top: calc(12px + var(--safe-t)); display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast {
  display: flex; align-items: center; gap: 10px; padding: 10px 18px 10px 12px; border-radius: 99px; min-height: 48px;
  background: var(--material-thick); -webkit-backdrop-filter: saturate(180%) blur(30px); backdrop-filter: saturate(180%) blur(30px);
  box-shadow: 0 10px 30px rgba(0,0,0,.14), 0 0 0 .5px var(--sep); font-size: 15px; font-weight: 500;
  transform: translateY(-140%); opacity: 0; transition: transform .5s var(--spring), opacity .3s; pointer-events: auto; max-width: calc(100vw - 32px);
}
.toast.show { transform: none; opacity: 1; }
.toast .tile { width: 26px; height: 26px; border-radius: 50%; }
.toast .tile .icon { width: 15px; height: 15px; stroke-width: 2.6; }

/* Connectivity banner */
.conn-banner {
  position: sticky; top: 0; z-index: 35; display: flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 13px; font-weight: 600; color: #fff; background: #3A3A3C; padding: 7px 12px; padding-top: calc(7px + var(--safe-t));
}
.conn-banner .icon { width: 16px; height: 16px; }
.conn-banner.syncing { background: var(--blue); }

/* Utility surfaces */
.surface { background: var(--bg-2); border-radius: var(--r); box-shadow: var(--shadow-1); }
.inset-pad { padding: 16px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 14px; }
.kv dt { color: var(--label-2); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.prose { font-size: 16px; line-height: 1.55; }
.prose p + p { margin-top: 10px; }
.prose ul, .prose ol { padding-left: 20px; margin: 8px 0; }
.prose li + li { margin-top: 4px; }
.prose h3 { font-size: 17px; font-weight: 600; margin: 16px 0 6px; }

/* Flip card (for flashcards) */
.flip { perspective: 1400px; }
.flip-inner { position: relative; transform-style: preserve-3d; transition: transform .7s var(--ease); min-height: 320px; }
.flip.flipped .flip-inner { transform: rotateY(180deg); }
.flip-face {
  position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden;
  border-radius: var(--r-xl); background: var(--bg-2); box-shadow: var(--shadow-card), 0 20px 50px rgba(0,0,0,.06);
  padding: 28px; display: flex; flex-direction: column;
}
.flip-back { transform: rotateY(180deg); }

/* Vertical snap feed (for OrthoTok) */
.snap-feed { height: calc(100vh - var(--tabbar-h) - var(--safe-b)); height: calc(100dvh - var(--tabbar-h) - var(--safe-b)); overflow-y: auto; scroll-snap-type: y mandatory; scrollbar-width: none; }
.snap-feed::-webkit-scrollbar { display: none; }
.snap-feed > * { scroll-snap-align: start; scroll-snap-stop: always; height: 100%; }
@media (min-width: 900px) { .snap-feed { height: 100vh; } }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* Mobile adjustments */
@media (max-width: 899px) {
  body { font-size: 17px; }
  .row-title { font-size: 17px; }
  .hide-mobile { display: none !important; }
}
@media (min-width: 900px) {
  .hide-desktop { display: none !important; }
}
