/* =====================================================================
   Tokens — Apple-style: system type, neutral surfaces, one blue accent
   ===================================================================== */
:root {
  --bg: #F5F5F7;
  --surface: #FFFFFF;
  --surface-2: #F2F2F4;
  --ink: #1D1D1F;
  --ink-2: #6E6E73;
  --ink-3: #A1A1A6;
  --line: rgba(0, 0, 0, 0.08);
  --accent: #0071E3;
  --accent-ink: #FFFFFF;
  --green: #34C759;
  --orange: #FF9F0A;
  --red: #FF3B30;
  --blue: #0A84FF;
  --glass: rgba(255, 255, 255, 0.72);
  --shadow-1: 0 1px 2px rgba(0,0,0,.04), 0 2px 12px rgba(0,0,0,.05);
  --shadow-2: 0 12px 40px rgba(0,0,0,.14);
  --r-card: 22px;
  --r-ctl: 12px;
  --r-pill: 980px;
  --spring: cubic-bezier(.32, .72, 0, 1);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", "Inter", Helvetica, Arial, sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1C1C1E;
    --surface-2: #2C2C2E;
    --ink: #F5F5F7;
    --ink-2: #98989D;
    --ink-3: #636366;
    --line: rgba(255, 255, 255, 0.10);
    --accent: #2997FF;
    --glass: rgba(20, 20, 22, 0.72);
    --shadow-1: 0 1px 2px rgba(0,0,0,.4);
    --shadow-2: 0 16px 48px rgba(0,0,0,.6);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); color: var(--ink); background: var(--bg);
  font-size: 16px; line-height: 1.45; -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
body.sheet-open { overflow: hidden; }
img { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
a { color: var(--accent); text-decoration: none; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 2px; border-radius: 8px; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.hidden { display: none !important; }
.row { display: flex; align-items: center; }
.row.gap { gap: 10px; }
.grow { flex: 1; }
.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 10px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 20px; border-radius: var(--r-pill); font-weight: 600; font-size: 15px;
  background: var(--surface-2); color: var(--ink); transition: transform .18s var(--spring), background .18s, opacity .18s;
  white-space: nowrap; min-height: 44px; user-select: none;
}
.btn:active { transform: scale(.96); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; box-shadow: inset 0 0 0 1.5px var(--line); }
.btn.danger { background: var(--red); color: #fff; }
.btn.subtle { background: transparent; color: var(--accent); padding-inline: 10px; }
.btn.sm { padding: 8px 14px; min-height: 36px; font-size: 14px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 50%; display: inline-grid; place-items: center;
  background: var(--surface-2); color: var(--ink-2); font-size: 14px; font-weight: 700;
  transition: transform .18s var(--spring), background .18s;
}
.icon-btn:active { transform: scale(.9); }
.icon-btn.plain { background: transparent; }

/* ---------- inputs ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > label, .label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.input, .select, .textarea {
  width: 100%; padding: 12px 14px; border-radius: var(--r-ctl); background: var(--surface-2);
  border: 1.5px solid transparent; outline: none; min-height: 46px; font-size: 16px;
  transition: border-color .15s, background .15s;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); background: var(--surface); }
.textarea { min-height: 96px; resize: vertical; }
.select { appearance: none; -webkit-appearance: none; padding-right: 38px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'><path d='M4 6l4 4 4-4' fill='none' stroke='%236E6E73' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat; background-position: right 12px center; }
.input.sm { min-height: 38px; padding: 8px 12px; font-size: 15px; }
.hint { font-size: 12.5px; color: var(--ink-3); }
.error { color: var(--red); font-size: 13.5px; }

/* switch */
.switch { position: relative; width: 51px; height: 31px; border-radius: 31px; background: var(--ink-3); transition: background .2s; flex: none; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.25); transition: transform .25s var(--spring); }
.switch[aria-checked="true"] { background: var(--green); }
.switch[aria-checked="true"]::after { transform: translateX(20px); }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; }

/* segmented control */
.seg { position: relative; display: inline-flex; padding: 3px; border-radius: 10px; background: var(--surface-2); gap: 2px; }
.seg button { position: relative; z-index: 1; padding: 7px 12px; border-radius: 8px; font-size: 13.5px; font-weight: 600; color: var(--ink-2); transition: color .2s; flex: 1; white-space: nowrap; }
.seg button.on { color: var(--ink); }
.seg .thumb { position: absolute; top: 3px; bottom: 3px; left: 0; width: 0; border-radius: 8px; background: var(--surface); box-shadow: var(--shadow-1); transition: left .28s var(--spring), width .28s var(--spring); }
.seg.block { display: flex; width: 100%; }

/* chips */
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: var(--r-pill); background: var(--surface-2); font-size: 13.5px; font-weight: 500; color: var(--ink); transition: background .15s, color .15s, transform .18s var(--spring); }
.chip.on { background: var(--ink); color: var(--bg); }
.chip:active { transform: scale(.95); }

/* badges */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: var(--r-pill); font-size: 11.5px; font-weight: 600; letter-spacing: .01em; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.green { background: color-mix(in srgb, var(--green) 16%, transparent); color: #1E8A3C; }
.badge.orange { background: color-mix(in srgb, var(--orange) 18%, transparent); color: #B26A00; }
.badge.red { background: color-mix(in srgb, var(--red) 14%, transparent); color: #C8261B; }
.badge.blue { background: color-mix(in srgb, var(--blue) 14%, transparent); color: var(--accent); }
.badge.gray { background: var(--surface-2); color: var(--ink-2); }
.badge.ink { background: var(--ink); color: var(--bg); }
.badge.purple { background: color-mix(in srgb, #AF52DE 18%, transparent); color: #8E44C9; }
@media (prefers-color-scheme: dark) {
  .badge.green { color: #4CD964; } .badge.orange { color: #FFB340; } .badge.red { color: #FF6961; }
}

/* cards & lists */
.card { background: var(--surface); border-radius: var(--r-card); box-shadow: var(--shadow-1); }
.list { background: var(--surface); border-radius: 16px; overflow: hidden; box-shadow: var(--shadow-1); }
.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); min-height: 56px; }
.list-item:last-child { border-bottom: 0; }
.list-item.tap { cursor: pointer; transition: background .12s; }
.list-item.tap:active { background: var(--surface-2); }
.list-item .title { font-weight: 600; font-size: 15px; }
.list-item .sub { font-size: 13px; color: var(--ink-2); margin-top: 1px; }
.list-item .chev { color: var(--ink-3); font-size: 18px; }
.list-empty { padding: 28px 16px; text-align: center; color: var(--ink-2); font-size: 14.5px; }
.section-h { font-size: 13px; font-weight: 600; color: var(--ink-2); margin: 22px 4px 8px; }
.section-h:first-child { margin-top: 4px; }

/* ---------- sheet ---------- */
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,0); backdrop-filter: blur(0px); -webkit-backdrop-filter: blur(0px);
  display: flex; align-items: flex-end; justify-content: center; transition: background .32s, backdrop-filter .32s;
}
.sheet-backdrop.in { background: rgba(0,0,0,.42); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.sheet {
  width: 100%; max-height: 92dvh; background: var(--surface); border-radius: 26px 26px 0 0;
  display: flex; flex-direction: column; transform: translateY(100%); transition: transform .42s var(--spring);
  box-shadow: var(--shadow-2); padding-bottom: var(--safe-b); touch-action: pan-y;
}
.sheet-backdrop.in .sheet { transform: translateY(0); }
.sheet.full { height: 96dvh; max-height: 96dvh; }
.sheet-grab, .sheet-head { touch-action: none; }
.sheet-grab { width: 36px; height: 5px; border-radius: 5px; background: var(--ink-3); opacity: .55; margin: 8px auto 0; flex: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px 6px 20px; flex: none; }
.sheet-title { font-size: 19px; font-weight: 700; letter-spacing: -.01em; }
.sheet-body { padding: 6px 20px 24px; overflow: auto; -webkit-overflow-scrolling: touch; flex: 1; overscroll-behavior: contain; }
@media (min-width: 720px) {
  .sheet-backdrop { align-items: center; padding: 24px; }
  .sheet { max-width: 560px; border-radius: 26px; max-height: 88vh; transform: translateY(24px) scale(.96); opacity: 0; transition: transform .36s var(--spring), opacity .25s; }
  .sheet.full { max-width: 720px; height: auto; max-height: 90vh; }
  .sheet-backdrop.in .sheet { transform: none; opacity: 1; }
  .sheet-grab { display: none; }
  .sheet-head { padding-top: 18px; }
}

/* ---------- toast ---------- */
.toast-host { position: fixed; left: 0; right: 0; top: calc(12px + var(--safe-t)); z-index: 200; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast { background: var(--ink); color: var(--bg); padding: 11px 18px; border-radius: var(--r-pill); font-size: 14px; font-weight: 600; box-shadow: var(--shadow-2); transform: translateY(-16px) scale(.94); opacity: 0; transition: transform .35s var(--spring), opacity .25s; }
.toast.in { transform: none; opacity: 1; }
.toast.error { background: var(--red); color: #fff; }
.toast.success { background: var(--green); color: #fff; }

/* ---------- skeleton ---------- */
.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, color-mix(in srgb, var(--surface-2) 60%, var(--surface)) 50%, var(--surface-2) 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: 12px; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

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