/* Apple-style: system font, iOS system colours, light + dark, mobile first. */
:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --card-2: #f2f2f7;
  --text: #000000;
  --text-2: rgba(60, 60, 67, 0.6);
  --sep: rgba(60, 60, 67, 0.18);
  --fill: rgba(120, 120, 128, 0.12);
  --blue: #007aff;
  --green: #34c759;
  --orange: #ff9500;
  --red: #ff3b30;
  --purple: #af52de;
  --gray: #8e8e93;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.04);
  --radius: 14px;
  --bar: rgba(249, 249, 249, 0.86);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --card-2: #2c2c2e;
    --text: #ffffff;
    --text-2: rgba(235, 235, 245, 0.6);
    --sep: rgba(84, 84, 88, 0.6);
    --fill: rgba(120, 120, 128, 0.24);
    --blue: #0a84ff;
    --green: #30d158;
    --orange: #ff9f0a;
    --red: #ff453a;
    --purple: #bf5af2;
    --gray: #98989d;
    --shadow: none;
    --bar: rgba(22, 22, 23, 0.86);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2 { margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 17px; font-weight: 600; }
a { color: var(--blue); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13px; }
.muted { color: var(--text-2); }
.small { font-size: 13px; }
.c-blue { color: var(--blue); } .c-green { color: var(--green); } .c-orange { color: var(--orange); }
.c-red { color: var(--red); } .c-purple { color: var(--purple); }
.boot { padding: 40vh 0; text-align: center; color: var(--text-2); }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--blue) 50%, transparent); outline-offset: 2px; border-radius: 8px; }

/* ---------- shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 24px;
  padding: 10px max(20px, env(safe-area-inset-left));
  background: var(--bar);
  backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--sep);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; color: var(--text); white-space: nowrap; }
.logo { width: 56px; height: 56px; border-radius: 14px; background: var(--blue); color: #fff; display: grid; place-items: center; font-size: 28px; margin: 0 auto 12px; }
.logo.small { width: 26px; height: 26px; border-radius: 7px; font-size: 14px; margin: 0; }
.tabs { display: flex; gap: 4px; }
.tabs a { padding: 6px 12px; border-radius: 8px; color: var(--text); font-weight: 500; }
.tabs a:hover { background: var(--fill); }
.tabs a.active { background: var(--fill); color: var(--blue); }
.tabs .nav-icon { display: none; }
.who { margin-left: auto; display: flex; gap: 14px; align-items: center; font-size: 13px; }
.bottom-tabs { display: none; }
.content { max-width: 1100px; margin: 0 auto; padding: 24px 20px 64px; outline: none; }
.page-title { font-size: 30px; font-weight: 700; margin-bottom: 8px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 4px; }
.page-head .page-title { margin: 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.intro { margin: 4px 0 18px; max-width: 70ch; }
.back { display: inline-block; margin-bottom: 8px; }

@media (max-width: 760px) {
  .tabs, .who-email { display: none; }
  .topbar { gap: 12px; }
  .content { padding: 16px 16px calc(96px + env(safe-area-inset-bottom)); }
  .page-title { font-size: 28px; }
  .bottom-tabs {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
    background: var(--bar); backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-top: 0.5px solid var(--sep); padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .bottom-tabs a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 10px; color: var(--gray); padding: 2px 0; }
  .bottom-tabs a.active { color: var(--blue); }
  .bottom-tabs .nav-icon { font-size: 20px; line-height: 24px; }
}

/* ---------- cards ---------- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 16px; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.error-card { color: var(--red); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.cards .card { margin: 0; display: flex; flex-direction: column; gap: 10px; }
.cards .card .btn { align-self: flex-start; margin-top: auto; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-2 .card { margin: 0; }
.grid-2 + * { margin-top: 16px; }
@media (max-width: 760px) { .grid-2, .cards { grid-template-columns: 1fr; } .card { padding: 16px; } }

.hero { display: flex; flex-direction: column; gap: 18px; }
.hero-times { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.big-text { font-size: 24px; font-weight: 600; letter-spacing: -0.01em; }
.health { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; font-size: 17px; }
.health .dot { width: 12px; height: 12px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 4px color-mix(in srgb, currentColor 20%, transparent); }
.health-green { color: var(--green); } .health-orange { color: var(--orange); } .health-red { color: var(--red); }
.health-blue { color: var(--blue); } .health-gray { color: var(--gray); }
.health-blue .dot { animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 10px; margin: 4px 0 14px; }
.stat { background: var(--card-2); border-radius: 12px; padding: 12px; }
.stat-value { font-size: 24px; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 12px; color: var(--text-2); }
.stat-link { color: inherit; display: block; }
.stat-link .stat:hover { outline: 1px solid var(--sep); }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; margin: 0 0 12px; }
.facts dt { color: var(--text-2); }
.facts dd { margin: 0; }
.facts.compact { font-size: 14px; gap: 4px 14px; }

.banner { border-radius: 10px; padding: 10px 14px; margin-bottom: 14px; font-size: 14px; }
.banner-orange { background: color-mix(in srgb, var(--orange) 16%, transparent); }
.banner-red { background: color-mix(in srgb, var(--red) 14%, transparent); }
.banner-gray { background: var(--fill); }

.progress-wrap { display: grid; gap: 6px; }
.progress { height: 6px; background: var(--fill); border-radius: 3px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--blue); border-radius: 3px; transition: width 0.4s ease; }

/* ---------- pills ---------- */
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill-blue { color: var(--blue); background: color-mix(in srgb, var(--blue) 14%, transparent); }
.pill-green { color: var(--green); background: color-mix(in srgb, var(--green) 16%, transparent); }
.pill-orange { color: var(--orange); background: color-mix(in srgb, var(--orange) 16%, transparent); }
.pill-red { color: var(--red); background: color-mix(in srgb, var(--red) 14%, transparent); }
.pill-purple { color: var(--purple); background: color-mix(in srgb, var(--purple) 14%, transparent); }
.pill-gray { color: var(--text-2); background: var(--fill); }
.summary-chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 12px 0; }

/* ---------- buttons & inputs ---------- */
.btn {
  border: 0; border-radius: 10px; padding: 8px 16px; font-weight: 500; cursor: pointer;
  background: var(--fill); color: var(--blue); transition: opacity 0.15s, transform 0.05s;
}
.btn:hover { opacity: 0.85; }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.45; cursor: default; transform: none; }
.btn.primary { background: var(--blue); color: #fff; }
.btn.primary.danger { background: var(--red); }
.btn.danger-text { color: var(--red); }
.btn.big { font-size: 17px; font-weight: 600; padding: 14px 20px; border-radius: 12px; width: 100%; }
.btn.block { width: 100%; padding: 12px; font-size: 16px; }
.btn.small { padding: 5px 12px; font-size: 13px; }
.btn.loading { opacity: 0.6; }
.link { background: none; border: 0; padding: 0; color: var(--blue); cursor: pointer; font-size: inherit; }
.icon-btn { background: var(--fill); border: 0; width: 30px; height: 30px; border-radius: 50%; cursor: pointer; color: var(--text-2); flex: none; }

input:not([type="checkbox"]), select, textarea {
  width: 100%; border: 0; border-radius: 10px; padding: 10px 12px; background: var(--fill);
  font-size: 16px; /* stops iOS zooming */
}
textarea { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13px; resize: vertical; }
select { width: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue); outline-offset: 0; }
.form { display: grid; gap: 14px; }
.stack { display: grid; gap: 10px; }
.field { display: grid; gap: 5px; }
.field-label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.field-hint { font-size: 12px; color: var(--text-2); }
.field-msg { font-size: 13px; }
.field-msg:empty { display: none; }
.check { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; }
.check input { width: 20px; height: 20px; margin: 1px 0 0; accent-color: var(--blue); flex: none; }
.inline-form { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.inline-form input { flex: 1 1 200px; width: auto; }
.kv { display: flex; gap: 12px; }

/* iOS switch */
.switch { position: relative; display: inline-block; width: 51px; height: 31px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; background: var(--fill); border-radius: 31px; transition: 0.2s; cursor: pointer; }
.slider::before { content: ""; position: absolute; width: 27px; height: 27px; left: 2px; top: 2px; background: #fff; border-radius: 50%; transition: 0.2s; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2); }
.switch input:checked + .slider { background: var(--green); }
.switch input:checked + .slider::before { transform: translateX(20px); }
.switch input:focus-visible + .slider { outline: 3px solid color-mix(in srgb, var(--blue) 50%, transparent); }

.segmented { display: inline-flex; background: var(--fill); border-radius: 9px; padding: 2px; }
.segmented button { border: 0; background: none; padding: 5px 12px; border-radius: 7px; cursor: pointer; font-size: 13px; font-weight: 500; white-space: nowrap; }
.segmented button.on { background: var(--card); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
@media (prefers-color-scheme: dark) { .segmented button.on { background: #636366; } }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input[type="search"] { flex: 1 1 240px; width: auto; }

/* ---------- tables (become cards on phones) ---------- */
.table-wrap { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: auto; }
.table-wrap.short { max-height: 45vh; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--text-2); padding: 10px 14px; border-bottom: 0.5px solid var(--sep); position: sticky; top: 0; background: var(--card); }
.table td { padding: 10px 14px; border-bottom: 0.5px solid var(--sep); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table.products tbody tr, .table.clickable tbody tr { cursor: pointer; }
.table tbody tr:hover td { background: color-mix(in srgb, var(--fill) 50%, transparent); }
.table tr.inactive td { opacity: 0.5; }
.title-cell { min-width: 220px; }
.strike { text-decoration: line-through; }
.clamp { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 760px) {
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { padding: 10px 14px; border-bottom: 0.5px solid var(--sep); }
  .table td { border: 0; padding: 2px 0; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  .table td::before { content: attr(data-label); color: var(--text-2); font-size: 13px; text-align: left; flex: none; }
  .table .num { text-align: right; }
  .title-cell { min-width: 0; }
  .table-wrap.short { max-height: none; }
  .clamp { max-width: 60vw; }
}

/* ---------- lists ---------- */
.list { display: grid; }
.list-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 0.5px solid var(--sep); }
.list-row:last-child { border-bottom: 0; }
.grow { flex: 1; min-width: 0; overflow-wrap: anywhere; }

/* ---------- Rosetti lookup ---------- */
.preview { background: var(--card-2); border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.preview-title { font-weight: 600; }
.preview-facts { display: flex; gap: 14px; color: var(--text-2); flex-wrap: wrap; }
.suggest { margin-top: 6px; }
.rosetti-search { display: grid; gap: 8px; margin-top: 6px; }
.search-results { max-height: 280px; overflow: auto; display: grid; gap: 4px; }
.result { text-align: left; border: 0; background: var(--card-2); border-radius: 10px; padding: 8px 12px; cursor: pointer; display: grid; gap: 2px; }
.result:hover { outline: 2px solid var(--blue); }
.result-main { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.pad { padding: 8px 4px; }

.item-title { font-weight: 600; }
.reason { font-size: 14px; }
.empty { text-align: center; color: var(--text-2); padding: 48px 16px; background: var(--card); border-radius: var(--radius); }

/* ---------- sheet & toast ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, 0.35); display: grid; place-items: center; padding: 16px; animation: fade 0.2s; }
.overlay.out { opacity: 0; transition: opacity 0.2s; }
.sheet { background: var(--card); border-radius: 16px; width: min(560px, 100%); max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3); animation: rise 0.25s cubic-bezier(0.2, 0.9, 0.3, 1); }
.sheet.wide { width: min(960px, 100%); }
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px 8px; }
.sheet-body { padding: 8px 20px; overflow: auto; }
.sheet-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 18px; border-top: 0.5px solid var(--sep); flex-wrap: wrap; }
@media (max-width: 760px) {
  .overlay { place-items: end stretch; padding: 0; }
  .sheet, .sheet.wide { width: 100%; border-radius: 16px 16px 0 0; max-height: 92vh; padding-bottom: env(safe-area-inset-bottom); }
}
@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }
#toasts { position: fixed; z-index: 60; left: 50%; transform: translateX(-50%); bottom: calc(24px + env(safe-area-inset-bottom)); display: grid; gap: 8px; width: min(420px, calc(100% - 32px)); }
@media (max-width: 760px) { #toasts { bottom: calc(84px + env(safe-area-inset-bottom)); } }
.toast { background: rgba(28, 28, 30, 0.94); color: #fff; padding: 12px 16px; border-radius: 12px; font-size: 14px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25); animation: rise 0.25s; transition: opacity 0.4s; }
.toast-error { background: var(--red); }
.toast.out { opacity: 0; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); text-align: center; padding: 32px 24px; }
.login-card h1 { font-size: 24px; margin-bottom: 8px; }
.login-msg { color: var(--text-2); margin: 0 0 18px; }

/* ---------- help ---------- */
.help ol, .help ul { padding-left: 20px; margin: 8px 0; }
.help li { margin: 6px 0; }
.help p { margin: 8px 0; }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
