:root {
  color-scheme: light dark; /* native controls & scrollbars follow the theme */
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #16181d;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #e8336d;
  --accent-soft: #fde7ef;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --bad: #b91c1c;
  --bad-soft: #fee2e2;
  --info: #1d4ed8;
  --info-soft: #dbeafe;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.05);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115; --panel: #171a21; --text: #e8eaf0; --muted: #9aa1ae; --border: #262b35;
    --accent-soft: #3a1422; --ok-soft: #0f2e1b; --warn-soft: #33250a; --bad-soft: #3a1414; --info-soft: #11244a;
    --ok: #4ade80; --warn: #fbbf24; --bad: #f87171; --info: #93b4ff;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 Inter, system-ui, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--bad); }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 16px 0 8px; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

.brand { font-weight: 700; font-size: 18px; letter-spacing: -.02em; }
.brand span { color: var(--accent); }
.brand small { font-weight: 500; color: var(--muted); font-size: 12px; margin-left: 4px; }
.brand.big { font-size: 32px; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 40px; text-align: center; box-shadow: var(--shadow); max-width: 380px; width: 100%; }
.login-card form { text-align: left; margin-top: 24px; }

.topbar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 24px; padding: 10px 24px; background: var(--panel); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.topbar nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.topbar nav a { padding: 6px 12px; border-radius: 8px; color: var(--muted); font-weight: 500; }
.topbar nav a:hover { background: var(--bg); text-decoration: none; color: var(--text); }
.topbar nav a.active { background: var(--accent-soft); color: var(--accent); }
.user { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.user img { width: 26px; height: 26px; border-radius: 50%; }

main { padding: 24px; max-width: 1400px; margin: 0 auto; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); min-width: 0; }

.btn { border: 1px solid var(--border); background: var(--panel); color: var(--text); padding: 7px 14px; border-radius: 8px; font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn:disabled, .btn.primary:disabled { opacity: 1; cursor: not-allowed; background: var(--bg); border-color: var(--border); color: var(--muted); filter: none; }

input, select, textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { resize: vertical; }
label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin: 10px 0 4px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.form-grid .full { grid-column: 1 / -1; }

/* funnel */
.funnel { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stage { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; position: relative; overflow: hidden; }
.stage .v { font-size: 28px; font-weight: 700; letter-spacing: -.02em; }
.stage .l { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.stage .p { font-size: 12px; color: var(--muted); }
.stage .bar { position: absolute; left: 0; bottom: 0; height: 4px; background: var(--accent); }
.issues { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; white-space: nowrap; cursor: default; }
th.sortable { cursor: pointer; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover { background: var(--bg); }
td .sub { color: var(--muted); font-size: 12px; }
td.num, th.num { text-align: right; white-space: nowrap; }
.url { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; vertical-align: bottom; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--bg); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.badge.info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.badge.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.dots { display: inline-flex; gap: 3px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border); }
.dot.on { background: var(--accent); }
.dot.bad { background: var(--bad); }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filters input { max-width: 280px; }
.filters select { max-width: 200px; }

/* drawer & modal */
.drawer, .modal { position: fixed; inset: 0; background: rgba(10,12,16,.45); z-index: 20; }
.drawer-panel { position: absolute; right: 0; top: 0; bottom: 0; width: min(640px, 100%); background: var(--panel); overflow-y: auto; padding: 24px; box-shadow: -8px 0 30px rgba(0,0,0,.15); }
.modal { display: grid; place-items: center; padding: 16px; }
.modal-panel { background: var(--panel); border-radius: 14px; padding: 24px; width: min(560px, 100%); max-height: 90vh; overflow-y: auto; overflow-x: hidden; border: 1px solid var(--border); }
.modal-panel h2 { margin-bottom: 16px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips code { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 2px 7px; }
.dropzone { display: flex; align-items: center; justify-content: center; gap: 10px; margin: 0; padding: 22px 16px;
  border: 1.5px dashed var(--border); border-radius: 10px; color: var(--muted); font-size: 14px; font-weight: 400;
  cursor: pointer; text-align: center; transition: border-color .15s, background .15s; }
.dropzone b { color: var(--text); font-weight: 600; }
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dropzone.has-file { border-style: solid; border-color: var(--accent); }
.dz-icon { font-size: 20px; color: var(--accent); }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { display: grid; grid-template-columns: 110px 1fr; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.timeline .when { color: var(--muted); font-size: 12px; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; }
.kv div:nth-child(odd) { color: var(--muted); font-size: 12px; }
.copy { display: flex; gap: 6px; }
.copy input { font-family: ui-monospace, monospace; font-size: 12px; }

/* campaign editor */
.editor { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.editor textarea.html { min-height: 420px; font-family: ui-monospace, monospace; font-size: 12px; }
.preview { width: 100%; height: 560px; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.picker { max-height: 340px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; }
.picker label { display: flex; gap: 8px; align-items: center; margin: 0; padding: 6px 10px; border-bottom: 1px solid var(--border); font-weight: 400; color: var(--text); font-size: 13px; cursor: pointer; }
.picker input { width: auto; }
.steps { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.alert { padding: 10px 14px; margin-top: 8px; overflow-wrap: anywhere; border-radius: 8px; background: var(--warn-soft); color: var(--warn); margin-bottom: 12px; }
.alert.info { background: var(--info-soft); color: var(--info); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 10px; z-index: 40; max-width: 90vw; }
.toast.err { background: var(--bad); color: #fff; }

.bars .b { display: grid; grid-template-columns: 160px 1fr 50px; gap: 8px; align-items: center; margin: 6px 0; font-size: 13px; }
.bars .track { background: var(--bg); border-radius: 4px; height: 10px; overflow: hidden; }
.bars .fill { background: var(--accent); height: 100%; }
.empty { text-align: center; padding: 40px; color: var(--muted); }

@media (max-width: 900px) {
  .editor, .grid.two { grid-template-columns: 1fr; }
  main { padding: 16px; }
  .topbar { padding: 10px 16px; }
  .form-grid { grid-template-columns: 1fr; }
}
