:root {
  --bg: #f4f4f1;
  --surface: #ffffff;
  --surface-2: #fafaf8;
  --line: #e6e5df;
  --line-2: #efeee9;
  --ink: #0f1115;
  --ink-2: #4b4a46;
  --ink-3: #85837c;
  --brand: #0f6b5c;
  --brand-ink: #ffffff;
  --brand-soft: #e3f1ed;
  --side: #121418;
  --side-ink: #c9cbd1;
  --google: #2a78d6;
  --meta: #eb6834;
  --other: #1baf7a;
  --good: #0c7a43;  --good-bg: #e2f4ea;
  --warn: #9a6200;  --warn-bg: #fcf0d4;
  --serious: #b4361b; --serious-bg: #fbe5df;
  --neutral-bg: #efeee9;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15,17,21,.04), 0 4px 16px rgba(15,17,21,.04);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 14px/1.5 Manrope, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-feature-settings: "tnum" 1; -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
h2 { font-size: 16px; font-weight: 700; }
h3 { font-size: 14px; font-weight: 700; }
.muted { color: var(--ink-3); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.sidebar { background: var(--side); color: var(--side-ink); padding: 20px 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.brand { display: flex; gap: 10px; align-items: center; color: #fff; padding: 4px 8px 18px; text-decoration: none !important; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; background: linear-gradient(140deg, #1baf7a, #0f6b5c); display: grid; place-items: center; font-weight: 800; font-size: 18px; color: #fff; }
.brand strong { display: block; font-size: 15px; }
.brand small { display: block; color: #8b8e97; font-size: 11.5px; }
.nav-group { font-size: 10.5px; letter-spacing: .09em; text-transform: uppercase; color: #6c707a; margin: 14px 10px 6px; font-weight: 700; }
.sidebar nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 9px; color: var(--side-ink); font-weight: 500; text-decoration: none; }
.sidebar nav a svg { width: 17px; height: 17px; opacity: .75; flex: none; }
.sidebar nav a:hover { background: #1d2026; color: #fff; }
.sidebar nav a.active { background: #232730; color: #fff; }
.sidebar nav a.active svg { opacity: 1; color: #3fd6a0; }
.sidebar-foot { margin-top: auto; padding: 14px 10px 0; border-top: 1px solid #23262d; }
.sidebar-foot a { color: #8b8e97; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 16px; padding: 18px 28px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar-title h1 { font-size: 20px; font-weight: 800; }
.topbar-title .muted { font-size: 12.5px; }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.menu-btn { display: none; background: none; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 16px; cursor: pointer; }
.content { padding: 24px 28px 40px; display: grid; gap: 20px; }
.foot { padding: 0 28px 24px; color: var(--ink-3); font-size: 12px; }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; gap: 6px; background: var(--brand); color: var(--brand-ink); border: 1px solid var(--brand); padding: 8px 14px; border-radius: 9px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none !important; white-space: nowrap; }
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: var(--serious); border-color: var(--serious); }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
select, input[type=text], input[type=number], input[type=date], input[type=password], textarea {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; min-width: 0;
}
select:focus, input:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
label { font-weight: 600; font-size: 12.5px; color: var(--ink-2); }
.field { display: grid; gap: 5px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }

.flash { margin: 16px 28px 0; padding: 11px 14px; border-radius: 10px; font-weight: 500; }
.flash.ok { background: var(--good-bg); color: var(--good); }
.flash.err { background: var(--serious-bg); color: var(--serious); }
.flash.warn { background: var(--warn-bg); color: var(--warn); }

/* ---------- cards & grid ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: baseline; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head .muted { font-size: 12.5px; }
.card-head .right { margin-left: auto; display: flex; gap: 8px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 20px; }
.span-2 { grid-column: span 2; }
.empty { text-align: center; padding: 48px 20px; }
.empty p { color: var(--ink-3); }

.hero { display: grid; grid-template-columns: 1.1fr 1fr; gap: 20px; }
.hero-main { background: var(--side); color: #fff; border-radius: var(--radius); padding: 24px; position: relative; overflow: hidden; }
.hero-main::after { content: ""; position: absolute; right: -60px; top: -60px; width: 220px; height: 220px; border-radius: 50%; background: radial-gradient(circle, rgba(27,175,122,.35), transparent 70%); }
.hero-main .eyebrow { color: #8b8e97; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; font-weight: 700; }
.hero-main .big { font-size: 40px; font-weight: 800; letter-spacing: -.02em; margin: 6px 0 2px; }
.hero-main .sub { color: #b6b9c1; }
.hero-split { display: flex; gap: 22px; margin-top: 18px; flex-wrap: wrap; position: relative; z-index: 1; }
.hero-split div { display: grid; }
.hero-split span { color: #8b8e97; font-size: 12px; }
.hero-split strong { font-size: 18px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 6px; vertical-align: 0; }
.dot.google { background: var(--google); } .dot.meta { background: var(--meta); } .dot.other { background: var(--other); }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; display: grid; gap: 2px; box-shadow: var(--shadow); }
.kpi-label { font-size: 12px; color: var(--ink-3); font-weight: 600; }
.kpi-value { font-size: 22px; font-weight: 800; letter-spacing: -.01em; }
.kpi-sub { font-size: 12px; color: var(--ink-2); }
.kpi.good .kpi-sub { color: var(--good); } .kpi.bad .kpi-sub { color: var(--serious); }

/* budget pacing */
.pace { display: grid; gap: 16px; }
.pace-row { display: grid; gap: 6px; }
.pace-top { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; }
.pace-top strong { font-weight: 700; }
.track { height: 10px; background: var(--line-2); border-radius: 6px; overflow: hidden; }
.track span { display: block; height: 100%; border-radius: 6px; }
.track .google { background: var(--google); } .track .meta { background: var(--meta); } .track .total { background: var(--brand); }

/* insights */
.insights { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.insights li { display: grid; grid-template-columns: 22px 1fr; gap: 10px; padding: 11px 12px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line-2); }
.insights .ic { width: 22px; height: 22px; border-radius: 6px; display: grid; place-items: center; font-size: 12px; font-weight: 800; }
.ic.good { background: var(--good-bg); color: var(--good); }
.ic.warn { background: var(--warn-bg); color: var(--warn); }
.ic.serious { background: var(--serious-bg); color: var(--serious); }
.ic.info { background: #e4eefb; color: #1c5cab; }

/* tables */
.table-wrap { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
table.t th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); font-weight: 700; padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: normal; vertical-align: bottom; line-height: 1.3; background: var(--surface); }
table.t td { padding: 10px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
table.t td.num, table.t th.num { text-align: right; white-space: nowrap; }
table.t tr:hover td { background: var(--surface-2); }
table.t tfoot td { font-weight: 800; border-top: 2px solid var(--line); border-bottom: none; background: var(--surface-2); }
table.t tr.sub td { font-size: 12px; color: var(--ink-3); font-weight: 600; background: none; }
table.t .name { font-weight: 600; min-width: 200px; max-width: 340px; }
table.t .name small { display: block; color: var(--ink-3); font-weight: 500; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable::after { content: " ↕"; opacity: .35; }
table.t input { width: 100%; min-width: 70px; padding: 6px 8px; }
table.t input.wide { min-width: 160px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11.5px; font-weight: 700; white-space: nowrap; text-transform: capitalize; }
.badge.good { background: var(--good-bg); color: var(--good); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.serious { background: var(--serious-bg); color: var(--serious); }
.badge.neutral { background: var(--neutral-bg); color: var(--ink-2); }
.pill { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 11.5px; font-weight: 700; background: var(--neutral-bg); color: var(--ink-2); }

.barcell { position: relative; min-width: 110px; height: 22px; display: flex; align-items: center; }
.barcell-bar { position: absolute; left: 0; top: 4px; bottom: 4px; border-radius: 0 4px 4px 0; opacity: .22; }
.barcell-bar.b1 { background: var(--google); } .barcell-bar.b2 { background: var(--meta); } .barcell-bar.b3 { background: var(--other); }
.barcell-val { position: relative; padding-left: 6px; font-weight: 600; }

.chart-box { position: relative; height: 280px; }
.chart-box.sm { height: 220px; }
.chart-box.lg { height: 340px; }
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12.5px; color: var(--ink-2); margin-bottom: 10px; }

/* funnel */
.funnel { display: grid; gap: 8px; }
.funnel-row { display: grid; grid-template-columns: 150px 1fr 90px; gap: 12px; align-items: center; }
.funnel-row .lbl { font-weight: 600; font-size: 13px; }
.funnel-row .bar { height: 30px; border-radius: 0 6px 6px 0; display: flex; align-items: center; padding-left: 10px; color: #fff; font-weight: 700; font-size: 13px; min-width: 34px; }
.funnel-row .rate { font-size: 12px; color: var(--ink-3); text-align: right; }

/* upload */
.drop { border: 2px dashed #c9c7bd; border-radius: var(--radius); padding: 36px 20px; text-align: center; background: var(--surface-2); cursor: pointer; transition: .15s; }
.drop.over { border-color: var(--brand); background: var(--brand-soft); }
.drop strong { font-size: 16px; display: block; margin-bottom: 4px; }
.drop input { display: none; }
.file-list { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 6px; text-align: left; }
.file-list li { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; font-size: 13px; }
.sources { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.source { border: 1px solid var(--line); border-radius: 12px; padding: 14px; display: grid; gap: 4px; background: var(--surface); }
.source .st { font-size: 12px; font-weight: 700; }
.source .st.ok { color: var(--good); } .source .st.miss { color: var(--ink-3); }
.source small { color: var(--ink-3); }

.note { font-size: 12.5px; color: var(--ink-3); }
details summary { cursor: pointer; font-weight: 700; color: var(--ink-2); padding: 6px 0; }

/* login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: radial-gradient(1000px 500px at 20% 0%, #dff0ea, transparent), var(--bg); }
.login { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 30px; box-shadow: 0 20px 60px rgba(15,17,21,.08); display: grid; gap: 16px; }
.login .brand { color: var(--ink); padding: 0; }
.login .brand small { color: var(--ink-3); }

/* ---------- responsive ---------- */
@media (max-width: 1100px) { .grid-3 { grid-template-columns: 1fr 1fr; } .hero { grid-template-columns: 1fr; } }
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 20; width: 250px; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .menu-btn { display: inline-block; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .topbar { padding: 12px 16px; flex-wrap: wrap; }
  .content { padding: 16px; }
  .flash { margin: 12px 16px 0; }
  .funnel-row { grid-template-columns: 110px 1fr 70px; }
  .hero-main .big { font-size: 32px; }
}

/* ---------- print / PDF ---------- */
@media print {
  @page { size: A4 landscape; margin: 10mm; }
  body { background: #fff; font-size: 11px; }
  .shell { display: block; }
  .sidebar, .topbar-actions, .menu-btn, .no-print, .flash { display: none !important; }
  .topbar { position: static; border: none; padding: 0 0 10px; }
  .content { padding: 0; gap: 12px; }
  .card, .kpi { box-shadow: none; break-inside: avoid; }
  .hero-main { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
