:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef2f0;
  --text: #15201c;
  --muted: #5d6b66;
  --border: #dde4e1;
  --brand: #0f5c4d;
  --brand-soft: #e3f0ec;
  --accent: #b8892b;
  --bar: #2f8f78;
  --line: #c9862a;
  --danger: #b3261e;
  --ok: #1f7a4d;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 32, 28, .06), 0 2px 8px rgba(16, 32, 28, .04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1412; --surface: #161e1b; --surface-2: #1d2724; --text: #e6ece9; --muted: #98a6a0;
    --border: #2a3632; --brand: #5cc3a6; --brand-soft: #1b2f29; --accent: #e0b55a;
    --bar: #3fa98c; --line: #e3a54c; --danger: #f08b84; --ok: #6fd19c;
    --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1412; --surface: #161e1b; --surface-2: #1d2724; --text: #e6ece9; --muted: #98a6a0;
  --border: #2a3632; --brand: #5cc3a6; --brand-soft: #1b2f29; --accent: #e0b55a;
  --bar: #3fa98c; --line: #e3a54c; --danger: #f08b84; --ok: #6fd19c;
  --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
}
button, input, select { font: inherit; color: inherit; }
.loading { padding: 40px 16px; text-align: center; color: var(--muted); }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login {
  width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; padding: 28px 22px; box-shadow: var(--shadow);
}
.login h1 { margin: 12px 0 4px; font-size: 22px; }
.login p { margin: 0 0 20px; color: var(--muted); }
.login label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 6px; }
.login input {
  width: 100%; padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2); font-size: 16px;
}
.login input:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
.login .err { color: var(--danger); min-height: 20px; margin-top: 10px; font-size: 14px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); border-radius: 10px;
  padding: 8px 12px; cursor: pointer; min-height: 38px;
}
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; width: 100%; padding: 12px; margin-top: 16px; font-weight: 600; }
:root[data-theme="dark"] .btn-primary { color: #08221b; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn-primary { color: #08221b; } }
.btn:disabled { opacity: .6; cursor: default; }
.logo { width: 44px; height: 44px; }

/* ---------- shell ---------- */
.top {
  position: sticky; top: 0; z-index: 10; background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
}
.top-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; max-width: 1200px; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; min-width: 0; }
.brand img { width: 30px; height: 30px; }
.brand small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-actions { display: flex; gap: 8px; align-items: center; }

.tabs, .chips {
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch;
  max-width: 1200px; margin: 10px auto 0;
}
.tabs::-webkit-scrollbar, .chips::-webkit-scrollbar { display: none; }
.tab, .chip {
  flex: 0 0 auto; border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  border-radius: 999px; padding: 7px 14px; cursor: pointer; font-size: 14px; white-space: nowrap;
}
.tab[aria-pressed="true"], .chip[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: #fff; }
:root[data-theme="dark"] .tab[aria-pressed="true"], :root[data-theme="dark"] .chip[aria-pressed="true"] { color: #08221b; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .tab[aria-pressed="true"], :root:not([data-theme="light"]) .chip[aria-pressed="true"] { color: #08221b; }
}

main { max-width: 1200px; margin: 0 auto; padding: 14px 16px 40px; }
.range-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 10px 0 0; }
.range-row input[type=date] {
  border: 1px solid var(--border); border-radius: 10px; padding: 7px 10px; background: var(--surface); min-height: 38px;
}
.range-label { color: var(--muted); font-size: 13px; margin-top: 8px; }

section.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; margin-top: 14px; box-shadow: var(--shadow); min-width: 0;
}
section.card > h2 { margin: 0 0 12px; font-size: 17px; display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
section.card > h2 small { font-weight: 400; color: var(--muted); font-size: 13px; }

.kpis { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 640px) { .kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 980px) { .kpis { grid-template-columns: repeat(5, minmax(0, 1fr)); } }
.kpi { background: var(--surface-2); border-radius: 12px; padding: 12px; min-width: 0; }
.kpi .label { color: var(--muted); font-size: 12.5px; }
.kpi .value { font-size: 22px; font-weight: 700; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi.main .value { color: var(--brand); }

.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; padding: 0 4px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 9px 8px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-weight: 500; font-size: 12.5px; }
tbody tr:last-child td { border-bottom: 0; }
tfoot td { font-weight: 700; border-top: 2px solid var(--border); border-bottom: 0; }
.muted { color: var(--muted); }
.empty { padding: 22px 8px; text-align: center; color: var(--muted); }

/* ---------- chart ---------- */
.chart-wrap { position: relative; }
.chart { width: 100%; height: 220px; display: block; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .axis { fill: var(--muted); font-size: 10.5px; }
.chart .bar { fill: var(--bar); }
.chart .bar.sel { fill: var(--accent); }
.chart .hit { fill: transparent; cursor: pointer; }
.chart .ln { fill: none; stroke: var(--line); stroke-width: 2.25; }
.chart .dot { fill: var(--surface); stroke: var(--line); stroke-width: 2; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); margin: 4px 0 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.chart-detail { min-height: 22px; font-size: 13.5px; margin-top: 6px; color: var(--text); }
details.daily { margin-top: 10px; }
details.daily summary { cursor: pointer; color: var(--brand); font-size: 14px; padding: 6px 0; }

/* ---------- creatives ---------- */
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.toolbar select { border: 1px solid var(--border); border-radius: 10px; padding: 7px 10px; background: var(--surface); min-height: 38px; max-width: 100%; }
.cr-table th { cursor: pointer; user-select: none; }
.cr-table th.sorted { color: var(--brand); }
.cr-name { display: flex; gap: 10px; align-items: center; min-width: 220px; max-width: 340px; white-space: normal; }
.thumb { width: 52px; height: 52px; border-radius: 8px; object-fit: cover; background: var(--surface-2); flex: 0 0 52px; }
.thumb.ph { display: grid; place-items: center; color: var(--muted); font-size: 11px; }
.cr-title { font-weight: 600; font-size: 13.5px; line-height: 1.3; word-break: break-word; }
.cr-sub { color: var(--muted); font-size: 12px; line-height: 1.3; word-break: break-word; }
.badge { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 999px; background: var(--surface-2); color: var(--muted); margin-top: 3px; }
.badge.on { background: var(--brand-soft); color: var(--brand); }

@media (max-width: 720px) {
  .cr-table thead { display: none; }
  .cr-table, .cr-table tbody, .cr-table tr, .cr-table td { display: block; width: 100%; }
  .cr-table tr { border: 1px solid var(--border); border-radius: 12px; padding: 10px; margin-bottom: 10px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px 10px; }
  .cr-table td { border: 0; padding: 0; text-align: left; white-space: normal; }
  .cr-table td:first-child { grid-column: 1 / -1; margin-bottom: 4px; }
  .cr-table td[data-l]::before { content: attr(data-l); display: block; color: var(--muted); font-size: 11.5px; }
  .cr-name { max-width: none; min-width: 0; }
}

/* ---------- CRM ---------- */
.placeholder {
  border: 1.5px dashed var(--border); border-radius: 12px; padding: 22px 16px; text-align: center; background: var(--surface-2);
}
.placeholder strong { display: block; font-size: 16px; margin-bottom: 6px; }
.placeholder p { margin: 0 auto; color: var(--muted); max-width: 520px; font-size: 14px; }
.stages { display: grid; gap: 8px; margin-top: 12px; }
.stage { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 10px; align-items: center; font-size: 14px; }
.stage .track { grid-column: 1 / -1; height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.stage .fill { height: 100%; background: var(--bar); border-radius: 99px; }
.stage.success .fill { background: var(--ok); }
.stage.failure .fill { background: var(--danger); opacity: .6; }

.foot { color: var(--muted); font-size: 12.5px; margin-top: 18px; text-align: center; }
.warn { color: var(--danger); }
.err-box { background: var(--surface); border: 1px solid var(--danger); color: var(--danger); border-radius: 12px; padding: 12px; margin-top: 14px; }
