:root {
  --bg: #f4f5f8;
  --panel: #ffffff;
  --sidebar: #141b2d;
  --sidebar-text: #aeb6c9;
  --sidebar-active: #1f2a44;
  --text: #1b2130;
  --muted: #6b7385;
  --line: #e3e6ee;
  --accent: #2458e6;
  --accent-ink: #ffffff;
  --up: #1a9d5b;
  --up-bg: #e6f6ee;
  --down: #d9372f;
  --down-bg: #fdecea;
  --warn-bg: #fff6df;
  --info-bg: #eaf0ff;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 27, 45, .06), 0 1px 8px rgba(20, 27, 45, .04);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: ui-monospace, "Cascadia Code", Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--font); font-size: 14px; color: var(--text); background: var(--bg); line-height: 1.45; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; font-weight: 700; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 15px; font-weight: 600; margin: 0 0 12px; }
h3 { font-size: 13px; font-weight: 600; margin: 18px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
p { margin: 0 0 10px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }
code { font-family: var(--mono); font-size: 12px; background: var(--bg); padding: 1px 5px; border-radius: 4px; }
code.block { display: block; padding: 10px 12px; margin: 8px 0 12px; word-break: break-all; }
pre { font-family: var(--mono); font-size: 12px; white-space: pre-wrap; background: var(--bg); padding: 10px; border-radius: 6px; max-height: 240px; overflow: auto; }
.mono { font-family: var(--mono); font-size: 12px; }
.muted { color: var(--muted); }
.ok { color: var(--up); font-weight: 600; }
.bad { color: var(--down); font-weight: 600; }
.up { color: var(--up); font-weight: 600; white-space: nowrap; }
.down { color: var(--down); font-weight: 600; white-space: nowrap; }
.inline { display: inline; }

/* ---- shell ---- */
.shell { display: flex; min-height: 100vh; }
.sidebar { width: 236px; flex: 0 0 236px; background: var(--sidebar); color: var(--sidebar-text); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; color: #fff; font-weight: 700; font-size: 15px; }
.brand:hover { text-decoration: none; }
.brand-mark { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 7px; background: var(--accent); color: #fff; font-size: 14px; }
.brand-lg { padding: 0; margin-bottom: 18px; color: var(--text); }
.sidebar nav { flex: 1; overflow-y: auto; padding: 4px 10px; }
.nav-section { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #6f7892; padding: 14px 8px 6px; }
.nav-link { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border-radius: 7px; color: var(--sidebar-text); font-weight: 500; }
.nav-link:hover { background: var(--sidebar-active); color: #fff; text-decoration: none; }
.nav-link.active { background: var(--sidebar-active); color: #fff; }
.nav-add { color: #8c96b3; font-size: 13px; }
.nav-count { font-size: 11px; background: rgba(255,255,255,.08); padding: 1px 7px; border-radius: 10px; }
.sidebar-foot { padding: 14px 18px; border-top: 1px solid rgba(255,255,255,.08); font-size: 12px; }
.sidebar-foot strong { color: #fff; }
.main { flex: 1; min-width: 0; padding: 26px 32px 60px; }

/* ---- page ---- */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.page-actions { display: flex; gap: 8px; flex-shrink: 0; }
.crumb { font-size: 12px; color: var(--muted); margin: 0 0 2px; }
.card { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 18px; }
.card-narrow { max-width: 620px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; }
.card-head h2 { margin: 0; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty h2 { color: var(--text); font-size: 18px; }

/* ---- alerts ---- */
.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid transparent; }
.alert-ok { background: var(--up-bg); border-color: #bfe8d1; color: #135f3a; }
.alert-error { background: var(--down-bg); border-color: #f4c3bf; color: #8a1f19; }
.alert-warn { background: var(--warn-bg); border-color: #f1dca0; color: #6b4d00; }
.alert-info { background: var(--info-bg); border-color: #c9d6fb; color: #1d3a8f; }

/* ---- stats ---- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
.stat-label { font-size: 12px; color: var(--muted); font-weight: 500; }
.stat-value { font-size: 24px; font-weight: 700; margin-top: 4px; letter-spacing: -.01em; }
.stat-sub { font-size: 13px; color: var(--muted); font-weight: 500; margin-left: 4px; }

/* ---- toolbar / segmented controls ---- */
.toolbar { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 3px; align-items: center; }
.seg a { padding: 6px 12px; border-radius: 6px; color: var(--muted); font-weight: 500; }
.seg a:hover { text-decoration: none; color: var(--text); }
.seg a.on { background: var(--accent); color: var(--accent-ink); }
.seg-sm a { padding: 4px 9px; font-size: 12px; }
.seg-label { font-size: 12px; color: var(--muted); padding: 0 8px 0 6px; }

/* ---- site cards (dashboard) ---- */
.site-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(420px, 1fr)); gap: 18px; }
.site-card { display: block; background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; color: var(--text); border: 1px solid transparent; }
.site-card:hover { text-decoration: none; border-color: var(--accent); }
.site-card-head h2 { font-size: 16px; margin: 0; }
.site-card-meta { font-size: 12px; color: var(--muted); margin: 6px 0 12px; }
.mini-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.mini-table th { text-align: right; font-weight: 500; color: var(--muted); font-size: 11px; padding: 4px 6px; border-bottom: 1px solid var(--line); }
.mini-table th:first-child { text-align: left; }
.mini-table td { padding: 6px; text-align: right; }
.mini-table td.dev { text-align: left; font-weight: 500; }

/* ---- data tables ---- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; }
table.data th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data th[data-sort] { cursor: pointer; user-select: none; }
table.data th[data-sort]:hover { color: var(--text); }
table.data th.sorted::after { content: " ▾"; }
table.data th.sorted.asc::after { content: " ▴"; }
table.data td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover td { background: #fafbfd; }
table.compact td, table.compact th { padding: 6px 10px; }
.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
th.hl, td.hl { background: var(--info-bg); }
.kw { color: var(--text); font-weight: 500; }
.prev { color: var(--muted); font-size: 11px; margin-left: 6px; }
.url { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.dev { font-weight: 500; white-space: nowrap; }
.actions { width: 1%; }
.pill { display: inline-block; min-width: 44px; text-align: center; padding: 2px 8px; border-radius: 12px; font-weight: 600; font-size: 13px; }
.p3 { background: #d8f3e4; color: #0f6b3d; }
.p10 { background: #e4edff; color: #1f47b8; }
.p20 { background: #fff1cc; color: #7a5300; }
.p100 { background: #eceef3; color: #4b5366; }
.pnone { background: #f3f4f7; color: #a0a7b8; }
.filter { padding: 6px 10px; border: 1px solid var(--line); border-radius: 7px; font: inherit; width: 220px; }
.chart-wrap { position: relative; height: 300px; }

/* ---- forms ---- */
label { display: block; font-weight: 500; margin-bottom: 12px; }
label input, label textarea, textarea, input[type=text], input[type=password], input[type=number], input[type=search] { display: block; width: 100%; margin-top: 5px; padding: 8px 10px; border: 1px solid #cfd4e0; border-radius: 7px; font: inherit; font-size: 14px; background: #fff; }
label input:focus, textarea:focus { outline: 2px solid rgba(36, 88, 230, .25); border-color: var(--accent); }
label small { display: block; font-weight: 400; margin-top: 4px; }
textarea { font-family: var(--font); margin-top: 0; }
.form-actions { display: flex; gap: 8px; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 13px; border-radius: 7px; border: 1px solid #cfd4e0; background: #fff; color: var(--text); font: inherit; font-weight: 500; cursor: pointer; }
.btn:hover { border-color: #aab2c4; text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: #1c49c4; border-color: #1c49c4; }
.btn-danger { background: var(--down); border-color: var(--down); color: #fff; }
.btn-block { width: 100%; justify-content: center; padding: 10px; }
.btn-icon { border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 13px; padding: 2px 6px; border-radius: 4px; }
.btn-icon:hover { background: var(--down-bg); color: var(--down); }
ul.plain { list-style: none; padding: 0; margin: 0; }
ul.plain li { padding: 4px 0; }
details summary { cursor: pointer; }

/* ---- auth ---- */
.auth-body { display: grid; place-items: center; min-height: 100vh; }
.auth-card { background: var(--panel); border-radius: 14px; box-shadow: var(--shadow); padding: 32px; width: 380px; }
.auth-card h1 { margin-bottom: 14px; }

@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .sidebar { width: auto; flex: none; height: auto; position: static; }
  .sidebar nav { padding-bottom: 10px; }
  .main { padding: 18px 16px 40px; }
  .two-col { grid-template-columns: 1fr; }
  .site-grid { grid-template-columns: 1fr; }
  .page-head { flex-direction: column; }
}

/* ---- CSV import ---- */
.import-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 6px; }
.import-row input[type=file] { font: inherit; font-size: 13px; }

/* ---- quarterly report ---- */
.report-form { display: grid; grid-template-columns: 2fr 1fr 1fr 1.6fr; gap: 14px; align-items: end; }
.report-form label { margin-bottom: 0; }
.report-form select { display: block; width: 100%; margin-top: 5px; padding: 8px 10px; border: 1px solid #cfd4e0; border-radius: 7px; font: inherit; background: #fff; }
.report-form .form-actions { grid-column: 1 / -1; margin-top: 4px; }
.preview-wrap { background: #444; border-radius: var(--radius); padding: 10px; }
.preview { width: 100%; height: 900px; border: 0; background: #444; }
@media (max-width: 900px) { .report-form { grid-template-columns: 1fr 1fr; } }

.preview-tall { height: 1100px; }
.tag-pill { display: inline-block; font-size: 11px; background: #eceef3; color: #4b5366; padding: 1px 7px; border-radius: 10px; margin-left: 6px; }
.bulk-bar { display: flex; gap: 8px; align-items: center; margin: 10px 0 0; }
.bulk-bar input[type=text] { width: 200px; margin: 0; }

/* busy buttons / spinner */
.btn:disabled { opacity: .65; cursor: default; }
.btn.is-busy { opacity: 1; }
.spinner { display: inline-block; width: 13px; height: 13px; border: 2px solid rgba(255,255,255,.35); border-top-color: currentColor; border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; }
.btn:not(.btn-primary) .spinner, .spinner-dark { border-color: #cfd4e0; border-top-color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }
.busy-banner { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; padding: 12px 18px; background: #fff; border: 1px solid #cfd4e0; border-radius: 10px; box-shadow: 0 8px 28px rgba(16,24,40,.18); font-size: 14px; z-index: 1000; }
.busy-banner span:last-child { color: var(--muted); }
a.btn.is-busy { pointer-events: none; }
.busy-banner.busy-error { border-color: var(--down); background: var(--down-bg); }
