/* ============ Tokens (from design/Main.dc.html) ============ */
:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1f2733;
  --muted: #5a616c;
  --muted-2: #4a515c;
  --border: #d9dce2;
  --border-soft: #e3e5ea;
  --chip: #f0f1f3;
  --tab-active: #e6e8ec;
  --blue: #2563d9;
  --blue-dark: #1b4fb3;
  --blue-btn: #2f5fd8;
  --green: #6cb554;
  --red: #d93a3a;
  --red-text: #c62828;
  --red-dark: #b3261e;
  --red-bg: #fff4f3;
  --red-border: #f2c4c0;
  --amber-bg: #fff8e6;
  --amber-border: #f1dba3;
  --amber-text: #8a5a00;
  --green-bg: #eef8ea;
  --green-border: #c6e3ba;
  --green-text: #2f6b1e;
  --ring-track: #eceef1;
  --radius: 18px;
  --font: 'Figtree', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --dock-h: 150px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--blue); }
[hidden] { display: none !important; }

/* ============ Top bar ============ */
.topbar {
  position: sticky; top: 0; z-index: 5;
  padding-top: var(--safe-top);
  height: calc(58px + var(--safe-top));
  display: flex; align-items: center; justify-content: center;
  background: var(--bg);
}
.topbar h1 { margin: 0; font-size: 20px; font-weight: 600; }
.profile-btn {
  position: absolute; right: 16px; top: calc(7px + var(--safe-top));
  width: 44px; height: 44px; border-radius: 22px; border: none;
  background: var(--card); box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  display: flex; align-items: center; justify-content: center;
}
.profile-dot { position: absolute; top: 2px; right: 2px; width: 12px; height: 12px; border-radius: 6px; background: var(--red); border: 2px solid var(--card); }
.back-btn { position: absolute; left: 8px; top: calc(7px + var(--safe-top)); width: 44px; height: 44px; border: none; background: none; font-size: 34px; line-height: 1; color: var(--blue); font-weight: 500; }

/* ============ Main view ============ */
.view { padding: 0 0 calc(var(--dock-h) + var(--safe-bottom)); }
.view > * { animation: fade-up .22s ease both; }
@keyframes fade-up { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.card { margin: 14px 16px 0; background: var(--card); border-radius: var(--radius); padding: 18px 16px; }
.card.first { margin-top: 8px; }
.card-head { display: flex; align-items: center; justify-content: space-between; }
.card-title { font-size: 21px; font-weight: 600; }
.help-btn {
  width: 28px; height: 28px; border-radius: 14px; border: 1.5px solid var(--blue);
  background: none; color: var(--blue); font-size: 15px; font-weight: 600; padding: 0; flex-shrink: 0;
}
.section-title { margin: 18px 20px 0; font-size: 26px; font-weight: 700; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

/* Score card */
.score-card { padding: 18px 14px 20px; display: flex; flex-direction: column; gap: 14px; }
.wordmark { display: flex; align-items: baseline; gap: 7px; color: var(--blue); }
.brand { font-size: 24px; font-weight: 800; letter-spacing: -0.5px; font-style: italic; }
.brand-light { font-size: 24px; font-weight: 300; letter-spacing: -0.5px; }
.bureaus { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; }
.bureau { display: flex; flex-direction: column; align-items: center; gap: 4px; position: relative; border: none; background: none; padding: 0; }
.bureau .delta {
  position: absolute; left: 4px; top: 0; background: var(--card); border: 1.5px solid var(--border);
  border-radius: 6px; padding: 1px 5px; font-size: 13px; font-weight: 700; color: var(--red-text); z-index: 1;
}
.bureau .delta.up { color: var(--green-text); }
.bureau svg { width: 112px; height: 112px; }
.bureau .name { font-size: 17px; font-weight: 500; }
.bureau .date { font-size: 14px; color: var(--muted); display: flex; align-items: center; gap: 3px; }
.chev { color: var(--blue); font-weight: 700; }
.ring-fg { transition: stroke-dasharray .6s cubic-bezier(.2,.7,.2,1); }

/* Alert banner */
.banner {
  margin: 14px 16px 0; border-radius: 16px; padding: 14px 16px;
  display: flex; gap: 12px; align-items: flex-start; border: 1.5px solid;
}
.banner.neg { background: var(--red-bg); border-color: var(--red-border); }
.banner.info { background: #eef3ff; border-color: #c9d8fb; }
.banner.ok { background: var(--green-bg); border-color: var(--green-border); }
.banner.warn { background: var(--amber-bg); border-color: var(--amber-border); }
.banner-icon { width: 36px; height: 36px; flex-shrink: 0; border-radius: 18px; display: flex; align-items: center; justify-content: center; background: var(--red); }
.banner.info .banner-icon { background: var(--blue); }
.banner.ok .banner-icon { background: var(--green); }
.banner.warn .banner-icon { background: #e0a100; }
.banner-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.banner-kicker { font-size: 12px; font-weight: 700; letter-spacing: 0.6px; color: var(--red-dark); text-transform: uppercase; }
.banner.info .banner-kicker { color: var(--blue-dark); }
.banner.ok .banner-kicker { color: var(--green-text); }
.banner.warn .banner-kicker { color: var(--amber-text); }
.banner-title { font-size: 17px; font-weight: 700; }
.banner-text { font-size: 14px; color: var(--muted-2); line-height: 1.35; }

/* List rows */
.list { display: flex; flex-direction: column; }
.row {
  display: flex; align-items: center; gap: 14px; padding: 12px 0;
  text-decoration: none; color: var(--text); border-bottom: 1px solid var(--border);
  background: none; border-left: none; border-right: none; border-top: none; text-align: left; width: 100%;
}
.row:last-child { border-bottom: none; }
.row-icon { width: 50px; height: 50px; flex-shrink: 0; border-radius: 25px; background: var(--chip); display: flex; align-items: center; justify-content: center; }
.row-icon svg { width: 24px; height: 24px; fill: none; stroke: var(--muted-2); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.row-icon.neg { background: var(--red-bg); } .row-icon.neg svg { stroke: var(--red); }
.row-icon.ok { background: var(--green-bg); } .row-icon.ok svg { stroke: var(--green-text); }
.row-icon.info { background: #eef3ff; } .row-icon.info svg { stroke: var(--blue); }
.row-main { flex-grow: 1; min-width: 0; }
.row-title { font-size: 17px; }
.row-sub { font-size: 14px; color: var(--muted); margin-top: 2px; }
.row-end { color: var(--blue); font-size: 22px; font-weight: 600; }
.row-val { font-size: 17px; font-weight: 700; }
.row-val.neg { color: var(--red-text); } .row-val.pos { color: var(--green-text); }
.unread { width: 10px; height: 10px; border-radius: 5px; background: var(--blue); flex-shrink: 0; }
.card.list-card { padding: 18px 16px 6px; }

/* Insights */
.insight { display: flex; gap: 12px; align-items: flex-start; }
.insight-emoji { font-size: 28px; line-height: 1; }
.insight-title { font-size: 17px; font-weight: 600; }
.insight-text { font-size: 14px; color: var(--muted-2); margin-top: 3px; line-height: 1.35; }

/* Buttons */
.btn-primary {
  height: 48px; padding: 0 20px; border: none; border-radius: 24px; background: var(--blue-btn); color: #fff;
  font-size: 17px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  box-shadow: 0 4px 14px rgba(47,95,216,0.35);
}
.btn-primary:disabled { opacity: .5; box-shadow: none; }
.btn-secondary {
  height: 44px; padding: 0 18px; border: 1.5px solid var(--blue); border-radius: 22px; background: none; color: var(--blue);
  font-size: 16px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn-secondary:disabled { opacity: .45; }
.btn-ghost { height: 44px; padding: 0 12px; border: none; background: none; color: var(--muted); font-size: 16px; font-weight: 500; }
.btn-danger { height: 44px; padding: 0 18px; border: 1.5px solid var(--red); border-radius: 22px; background: none; color: var(--red-text); font-size: 16px; font-weight: 600; }
.btn-block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }

/* Status pills */
.status { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 700; }
.status::before { content: ''; width: 8px; height: 8px; border-radius: 4px; background: currentColor; }
.status.on { background: var(--green-bg); color: var(--green-text); }
.status.off { background: var(--chip); color: var(--muted); }
.status.warn { background: var(--amber-bg); color: var(--amber-text); }
.status.err { background: var(--red-bg); color: var(--red-text); }
.kv { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border); font-size: 15px; }
.kv:last-child { border-bottom: none; }
.kv .k { color: var(--muted); } .kv .v { font-weight: 600; text-align: right; }

/* Simulator */
.sim-score { display: flex; align-items: center; gap: 18px; }
.sim-score svg { width: 124px; height: 124px; flex-shrink: 0; }
.sim-score .big { font-size: 38px; font-weight: 800; letter-spacing: -1px; line-height: 1; }
.sim-score .diff { font-size: 17px; font-weight: 700; margin-top: 4px; }
.sim-score .diff.neg { color: var(--red-text); } .sim-score .diff.pos { color: var(--green-text); }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); font-size: 16px; cursor: pointer; }
.toggle-row:last-child { border-bottom: none; }
.toggle-row input { position: absolute; opacity: 0; width: 0; height: 0; }
.toggle { width: 50px; height: 30px; border-radius: 15px; background: #d0d4db; position: relative; flex-shrink: 0; transition: background .2s; }
.toggle::after { content: ''; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 12px; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s; }
input:checked + .toggle { background: var(--green); }
input:checked + .toggle::after { transform: translateX(20px); }
.toggle-label { display: flex; flex-direction: column; }
.toggle-label small { color: var(--muted); font-size: 13px; }

/* Plugs */
.plug { display: flex; flex-direction: column; gap: 6px; }
.plug-tag { font-size: 12px; font-weight: 700; letter-spacing: .6px; color: var(--blue-dark); text-transform: uppercase; }
.plug-title { font-size: 19px; font-weight: 700; }
.plug-text { font-size: 14px; color: var(--muted-2); line-height: 1.35; }
.plug-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 6px; }
.plug-apr { font-size: 13px; color: var(--muted); }

/* ============ Dock: FAB + tab bar ============ */
.dock {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  padding: 0 14px calc(18px + var(--safe-bottom));
  display: flex; flex-direction: column; gap: 10px;
  background: linear-gradient(to bottom, rgba(244,245,247,0) 0%, var(--bg) 28%);
  pointer-events: none;
}
.dock > * { pointer-events: auto; }
.dock-fab-row { display: flex; justify-content: flex-end; padding-top: 24px; }
.fab { height: 48px; padding: 0 20px; border: none; border-radius: 24px; background: var(--blue-btn); color: #fff; font-size: 17px; font-weight: 600; display: flex; align-items: center; gap: 8px; box-shadow: 0 4px 14px rgba(47,95,216,0.35); }
.tabbar {
  height: 72px; border-radius: 36px; background: var(--card); border: 1px solid var(--border-soft);
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); align-items: center; padding: 0 6px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.06);
}
.tabbar a {
  height: 60px; border-radius: 30px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  text-decoration: none; color: var(--text); font-size: 12px; position: relative;
}
.tabbar a svg { width: 22px; height: 22px; fill: none; stroke: var(--text); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a.active { background: var(--tab-active); color: var(--blue); font-weight: 600; }
.tabbar a.active svg { stroke: var(--blue); stroke-width: 2.4; }
.badge {
  position: absolute; top: 4px; right: 10px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px;
  background: #d32f2f; color: #fff; font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center;
}

/* ============ Sheet ============ */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(20,24,32,0.4); z-index: 20; opacity: 0; transition: opacity .25s; }
.sheet-backdrop.open { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  background: var(--card); border-radius: 24px 24px 0 0;
  padding: 10px 20px calc(20px + var(--safe-bottom));
  max-height: 88dvh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  transform: translateY(100%); transition: transform .3s cubic-bezier(.2,.8,.2,1);
  box-shadow: 0 -8px 40px rgba(0,0,0,0.18);
}
.sheet.open { transform: translateY(0); }
.sheet-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--border); margin: 0 auto 14px; }
.sheet h2 { margin: 6px 0 8px; font-size: 22px; font-weight: 700; }
.sheet p { margin: 8px 0; font-size: 15px; line-height: 1.45; color: var(--muted-2); }
.sheet-actions { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.sheet-actions .btn-primary, .sheet-actions .btn-secondary { flex: 1 1 auto; }
.install-hero { display: flex; align-items: center; gap: 14px; margin-bottom: 8px; }
.install-hero img { width: 64px; height: 64px; border-radius: 15px; box-shadow: 0 4px 14px rgba(37,99,217,.3); }
.install-hero .t { font-size: 20px; font-weight: 700; } .install-hero .s { font-size: 14px; color: var(--muted); }
.steps { margin: 10px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 10px; }
.steps li { display: flex; align-items: center; gap: 12px; font-size: 16px; }
.steps .n { width: 28px; height: 28px; border-radius: 14px; background: var(--blue); color: #fff; font-weight: 700; display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 14px; }
.steps svg { width: 22px; height: 22px; stroke: var(--blue); fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: -5px; margin: 0 2px; }
.steps b { font-weight: 700; color: var(--text); }
.share-ios { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: 7px; background: #eef3ff; vertical-align: -9px; }

/* Chat */
.chat { display: flex; flex-direction: column; gap: 8px; min-height: 200px; max-height: 50dvh; overflow-y: auto; padding: 4px 0; }
.msg { max-width: 82%; padding: 10px 14px; border-radius: 18px; font-size: 15px; line-height: 1.4; }
.msg.me { align-self: flex-end; background: var(--blue-btn); color: #fff; border-bottom-right-radius: 6px; }
.msg.ai { align-self: flex-start; background: var(--chip); color: var(--text); border-bottom-left-radius: 6px; }
.msg.typing { color: var(--muted); font-style: italic; }
.chat-form { display: flex; gap: 8px; margin-top: 12px; }
.chat-form input { flex: 1; height: 46px; border-radius: 23px; border: 1.5px solid var(--border); padding: 0 16px; font-size: 16px; background: var(--bg); }
.chat-form button { width: 46px; height: 46px; border-radius: 23px; border: none; background: var(--blue-btn); color: #fff; font-size: 20px; }

/* ============ Sign-in ============ */
.signin { display: flex; align-items: center; justify-content: center; padding: calc(24px + var(--safe-top)) 24px calc(24px + var(--safe-bottom)); }
.signin-inner { width: 100%; max-width: 360px; display: flex; flex-direction: column; align-items: center; text-align: center; }
.signin-logo { border-radius: 20px; box-shadow: 0 8px 24px rgba(37,99,217,.3); margin-bottom: 18px; }
.signin .wordmark { flex-direction: column; align-items: center; gap: 0; }
.signin .brand { font-size: 32px; } .signin .brand-light { font-size: 18px; letter-spacing: 3px; }
.signin-tag { color: var(--muted); font-size: 15px; margin: 12px 0 22px; }
.signin-form { width: 100%; display: flex; flex-direction: column; gap: 12px; text-align: left; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.field input { height: 50px; border-radius: 14px; border: 1.5px solid var(--border); background: var(--card); padding: 0 16px; font-size: 17px; font-weight: 500; color: var(--text); letter-spacing: 0; text-transform: none; }
.field input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(37,99,217,.15); }
.signin .toggle-row { border: none; padding: 6px 2px; font-weight: 500; }
.fineprint { font-size: 12px; color: var(--muted); text-align: center; margin: 6px 0 0; }

/* ============ Toast ============ */
.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(var(--dock-h) + var(--safe-bottom) + 8px); z-index: 30;
  background: var(--text); color: #fff; padding: 12px 16px; border-radius: 14px; font-size: 15px; font-weight: 500;
  box-shadow: 0 8px 24px rgba(0,0,0,.25); animation: fade-up .2s ease both; text-align: center;
}
@media (min-width: 560px) { .toast { width: 398px; } }

/* Code-ish text used in profile/debug rows */
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; word-break: break-all; }

/* Phone frame on wide screens so the demo still looks like a phone on desktop */
.screen { min-height: 100dvh; }
@media (min-width: 560px) {
  body { background: #dfe2e8; }
  .screen {
    max-width: 430px; min-height: 100dvh; margin: 0 auto; background: var(--bg);
    box-shadow: 0 0 0 1px rgba(0,0,0,0.06), 0 20px 60px rgba(0,0,0,0.18);
  }
  .dock, .sheet, .toast { width: 430px; max-width: 100%; left: 50% !important; right: auto !important; transform: translateX(-50%); }
  .sheet { transform: translate(-50%, 100%); }
  .sheet.open { transform: translate(-50%, 0); }
}

/* ============ Turf / map ============ */
.map { height: 280px; background: #e9ecef; position: relative; z-index: 0; }
.map-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 20px; color: var(--muted); font-size: 15px; }
.leaflet-container { font-family: var(--font); }
.leaflet-control-attribution { font-size: 10px; }
.pin { font-size: 22px; line-height: 30px; text-align: center; filter: drop-shadow(0 1px 2px rgba(0,0,0,.35)); background: none; border: none; }
