:root {
  --bg: #090c12;
  --bg-2: #0e141d;
  --elev: #121925;
  --card: #161e2b;
  --line: #253044;
  --line-2: #314058;
  --text: #e8eef7;
  --muted: #8b9bb4;
  --accent: #3ce6a8;
  --accent-2: #6b8cff;
  --warn: #f0a05a;
  --down: #ff6b7d;
  --up: #3ce6a8;
  --shadow: 0 18px 50px rgba(0, 0, 0, .35);
  --radius: 18px;
  --font: "Outfit", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --tabbar: calc(64px + var(--safe-b));
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(108, 140, 255, .16), transparent 50%),
    radial-gradient(900px 400px at 110% 0%, rgba(60, 230, 168, .1), transparent 45%),
    var(--bg);
  color: var(--text);
  line-height: 1.45;
}
a { color: var(--accent); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
.sr, .skip { position: absolute; left: -999px; }
.skip:focus { left: 12px; top: 12px; background: #000; padding: 8px 12px; z-index: 9; }

.brand {
  display: flex; align-items: center; gap: 10px;
  color: var(--text); font-weight: 600; letter-spacing: .01em;
}
.brand strong, .brand-name { color: var(--text); font-weight: 700; }
.brand-lg { font-size: 1.25rem; margin-bottom: 8px; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px;
  background:
    linear-gradient(180deg, #1a2433, #10151e);
  box-shadow: inset 0 0 0 1px #2a3a52;
  position: relative;
}
.brand-mark::after {
  content: "";
  position: absolute; inset: 7px 6px 8px 6px;
  background: no-repeat center / contain;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 12'><path d='M1 10 L6 4 L11 7 L17 1 L23 4' fill='none' stroke='%233ce6a8' stroke-width='2' stroke-linecap='round'/></svg>");
}

.app { min-height: 100dvh; display: flex; }
.sidebar {
  width: 248px; flex: none;
  background: rgba(10, 14, 20, .86);
  border-right: 1px solid var(--line);
  padding: 18px 14px 16px;
  display: none; flex-direction: column; gap: 18px;
  position: sticky; top: 0; height: 100dvh;
}
@media (min-width: 960px) {
  .sidebar { display: flex; }
}
.side-nav { display: flex; flex-direction: column; gap: 4px; }
.side-nav a, .side-site {
  display: flex; align-items: center; gap: 10px;
  color: var(--muted); padding: 10px 10px; border-radius: 12px;
}
.side-nav a svg { width: 18px; height: 18px; fill: currentColor; flex: none; }
.side-nav a.is-active, .side-nav a:hover, .side-site.is-active, .side-site:hover {
  background: var(--card); color: var(--text);
}
.side-sites p { margin: 0 10px 6px; font-size: .72rem; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.side-site i { width: 8px; height: 8px; border-radius: 99px; flex: none; }
.side-site span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-foot { margin-top: auto; display: flex; justify-content: space-between; font-size: .85rem; padding: 8px 10px; }
.side-foot a { color: var(--muted); }
.maincol { flex: 1; min-width: 0; padding-bottom: var(--tabbar); }
@media (min-width: 960px) { .maincol { padding-bottom: 24px; } }

.topbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 14px 16px 8px;
  position: sticky; top: 0; z-index: 5;
  background: linear-gradient(var(--bg) 70%, transparent);
}
.topbar-title { flex: 1; min-width: 140px; }
.topbar-title h1 { margin: 0; font-size: 1.25rem; letter-spacing: -.02em; }
.topbar-title p { margin: 2px 0 0; color: var(--muted); font-size: .88rem; }
.menu-btn {
  width: 42px; height: 42px; border: 1px solid var(--line); background: var(--card);
  border-radius: 12px; display: flex; flex-direction: column; justify-content: center; gap: 5px; padding: 0 12px;
}
.menu-btn span { display: block; height: 2px; background: var(--text); border-radius: 2px; }
@media (min-width: 960px) { .menu-btn { display: none; } }

.icon-btn { cursor: pointer; }
.period {
  display: flex; gap: 4px; overflow: auto; max-width: 100%;
  padding: 4px; background: var(--elev); border: 1px solid var(--line); border-radius: 999px;
  -webkit-overflow-scrolling: touch;
}
.period button, .pills a {
  border: 0; background: transparent; color: var(--muted); padding: 8px 12px;
  border-radius: 999px; white-space: nowrap; cursor: pointer; font-size: .86rem;
}
.period button.is-active, .pills a.is-active { background: var(--card); color: var(--text); box-shadow: 0 0 0 1px var(--line-2); }
.site-switch select {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; min-height: 42px;
}
.content { padding: 8px 16px 24px; display: grid; gap: 22px; }
[data-site-panels] { display: grid; gap: 22px; }
.scrim {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 20;
}
@media (max-width: 959px) {
  .sidebar {
    display: flex; position: fixed; left: 0; top: 0; z-index: 30;
    transform: translateX(-105%); transition: transform .2s ease;
  }
  .sidebar.open { transform: none; }
}

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: rgba(12, 16, 24, .94);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
  backdrop-filter: blur(12px);
}
.tabbar a {
  color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 4px 8px; font-size: .7rem;
}
.tabbar svg { width: 22px; height: 22px; fill: currentColor; }
.tabbar a.is-active { color: var(--accent); }
@media (min-width: 960px) { .tabbar { display: none; } }

.kpi-grid {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px;
}
@media (min-width: 800px) { .kpi-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1200px) { .kpi-grid { grid-template-columns: repeat(6, 1fr); } }
[data-home-kpis] { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 800px) { [data-home-kpis] { grid-template-columns: repeat(4, 1fr); } }

.kpi-card, .card, .list-card, .site-card {
  background: linear-gradient(180deg, rgba(255,255,255,.02), transparent 40%), var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.kpi-card span { display: block; color: var(--muted); font-size: .78rem; }
.kpi-card strong {
  display: block; margin-top: 6px; font-family: var(--mono); font-size: 1.35rem; font-weight: 600; letter-spacing: -.03em;
}
.kpi-card small { display: inline-flex; gap: 4px; margin-top: 6px; font-size: .75rem; }
.kpi-card .up { color: var(--up); }
.kpi-card .down { color: var(--down); }
.kpi-card .flat { color: var(--muted); }
.kpi-card.skeleton strong { opacity: .3; }
.live-num { color: var(--accent); }

.toolbar { display: flex; justify-content: space-between; gap: 12px; align-items: center; flex-wrap: wrap; }
.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: .82rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--elev); color: var(--text); cursor: pointer;
}
.btn-primary { background: var(--accent); color: #062016; border-color: transparent; font-weight: 600; }
.btn-ghost { background: transparent; }
.btn-danger { background: #2a1216; color: #ff8a97; border-color: #5a2430; }
.btn-block { width: 100%; }
.btn:active { transform: translateY(1px); }

.site-board {
  display: grid; gap: 12px;
  grid-template-columns: 1fr;
}
@media (min-width: 700px) { .site-board { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1100px) { .site-board { grid-template-columns: repeat(3, 1fr); } }

.site-card {
  display: grid; gap: 10px; cursor: pointer;
  position: relative; overflow: hidden;
}
.site-card:hover { border-color: var(--line-2); transform: translateY(-1px); }
.site-card:active { transform: none; }
.site-card.dragging { opacity: .55; }
.site-card .card-head { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.site-card h3 { margin: 0; font-size: 1.05rem; }
.site-card h3 a { color: inherit; }
.site-card .live-pill {
  font-size: .72rem; color: #062016; background: var(--accent); border-radius: 999px; padding: 3px 8px; font-weight: 600;
}
.drag-handle {
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line);
  display: grid; place-items: center; color: var(--muted); background: var(--elev); cursor: grab;
}
.drag-handle:active { cursor: grabbing; }
.site-card .nums { display: flex; gap: 14px; font-family: var(--mono); font-size: .85rem; }
.site-card .nums span { color: var(--muted); display: block; font-family: var(--font); font-size: .7rem; }
.site-card .nums b { font-weight: 600; }
.card-live { display: flex; gap: 8px; align-items: center; }
.bump { animation: bump .35s ease; color: var(--accent); }
@keyframes bump {
  0% { transform: scale(1.12); }
  100% { transform: scale(1); }
}
.site-card .stripe { position: absolute; left: 0; top: 0; bottom: 0; width: 4px; }

.pills { display: flex; gap: 6px; overflow: auto; }
.split { display: grid; gap: 22px; }
@media (min-width: 900px) { .split { grid-template-columns: 1fr 1fr; } }
.split-3 { display: grid; gap: 22px; }
@media (min-width: 900px) { .split-3 { grid-template-columns: repeat(3, 1fr); } }

.card h2 { margin: 0 0 12px; font-size: .95rem; }
.card-head-row { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; flex-wrap: wrap; margin-bottom: 12px; }
.card-head-row h2 { margin: 0; }
.kpi-link { cursor: pointer; }
.kpi-link:hover { border-color: var(--accent); }
.rank-list { display: grid; gap: 8px; }
.rank-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; font-size: .9rem; }
.rank-row .bar {
  grid-column: 1 / -1; height: 6px; background: var(--elev); border-radius: 99px; overflow: hidden;
}
.rank-row .bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent-2), var(--accent)); border-radius: 99px; }
.rank-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-row .val { font-family: var(--mono); font-size: .8rem; color: var(--muted); }

.chart-wrap { position: relative; height: 220px; }
.chart-wrap canvas { width: 100%; height: 100%; display: block; }
.chart-tip {
  position: absolute; pointer-events: none; background: #0b1018; border: 1px solid var(--line);
  padding: 6px 8px; border-radius: 8px; font-size: .78rem; display: none;
}

.heat {
  display: grid; grid-template-columns: 28px repeat(24, 1fr); gap: 3px; font-size: .65rem; color: var(--muted);
}
.heat b { display: block; aspect-ratio: 1; border-radius: 3px; background: #1a2433; }
.heat .lab { display: flex; align-items: center; }

.feed { display: grid; gap: 8px; max-height: 480px; overflow: auto; }
.feed-item {
  display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: start;
  padding: 8px 0; border-bottom: 1px solid var(--line); font-size: .86rem;
}
.feed-item i { width: 8px; height: 8px; border-radius: 99px; background: var(--accent); margin-top: 6px; }
.visit-log { max-height: 560px; }
.visit-table { font-size: .82rem; }
.visit-table .mono { font-family: var(--mono); font-size: .78rem; white-space: nowrap; }
.visit-table td:nth-child(3) { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.live-stamp { display: block; font-size: .72rem; }

.live-hero { display: grid; gap: 22px; }
@media (min-width: 900px) { .live-hero { grid-template-columns: 220px 1fr; align-items: stretch; } }
.live-count {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 22px; display: grid; place-items: center; text-align: center; gap: 6px;
}
.live-count strong { font-family: var(--mono); font-size: 3rem; color: var(--accent); }
.pulse {
  width: 10px; height: 10px; background: var(--accent); border-radius: 99px;
  box-shadow: 0 0 0 0 rgba(60,230,168,.6); animation: pulse 1.6s infinite;
}
@keyframes pulse {
  70% { box-shadow: 0 0 0 12px rgba(60,230,168,0); }
  100% { box-shadow: 0 0 0 0 rgba(60,230,168,0); }
}

.list-cards { display: grid; gap: 10px; }
.list-card { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.list-card .dot { width: 10px; height: 10px; border-radius: 99px; }
.list-card h3 { margin: 0; }
.list-card .row-actions, .row-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-left: auto; }
.table-wrap { overflow: auto; }
table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data th { color: var(--muted); font-weight: 500; font-size: .78rem; }

.form-card { max-width: 640px; }
.stack { display: grid; gap: 12px; }
.stack label, fieldset { display: grid; gap: 6px; font-size: .9rem; }
input[type="text"], input[type="email"], input[type="password"], input[type="url"], select, textarea {
  width: 100%; background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px; min-height: 44px;
}
input:focus, select:focus { outline: 2px solid rgba(60,230,168,.35); border-color: var(--accent); }
.check { display: flex !important; flex-direction: row; align-items: center; gap: 10px; }
.check input { width: 18px; height: 18px; }
.color-picks { display: flex; flex-wrap: wrap; gap: 8px; border: 0; padding: 0; }
.color-picks legend { margin-bottom: 6px; }
.swatch { position: relative; }
.swatch input { position: absolute; opacity: 0; }
.swatch span { display: block; width: 32px; height: 32px; border-radius: 99px; border: 2px solid transparent; }
.swatch input:checked + span { border-color: #fff; }
.site-checks { border: 1px solid var(--line); border-radius: 14px; padding: 12px; display: grid; gap: 8px; }
.code-block {
  background: #0b1018; border: 1px solid var(--line); border-radius: 12px; padding: 12px;
  overflow: auto; font-family: var(--mono); font-size: .8rem; white-space: pre-wrap;
}
.danger-zone { max-width: 640px; }

.flash { padding: 10px 14px; border-radius: 12px; margin: 0 16px; }
.flash-error { background: #2a1216; color: #ffb3bc; }
.flash-ok { background: #10261d; color: #9ff3d0; }
.content > .flash { margin: 0; }

.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty h2 { color: var(--text); }

.auth-body { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.auth-wrap { width: min(420px, 100%); display: grid; }
.auth-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 24px; padding: 28px 24px;
  box-shadow: var(--shadow);
}
.auth-card h1 { margin: 8px 0 6px; font-size: 1.7rem; letter-spacing: -.03em; }
.lead { color: var(--muted); margin-top: 0; }
.auth-card .flash { margin: 0 0 8px; }

.donut-row { display: flex; gap: 16px; align-items: center; }
.donut-row svg { width: 88px; height: 88px; flex: none; }

@media (max-width: 959px) {
  .content { padding-bottom: 12px; }
  .kpi-card strong { font-size: 1.18rem; }
}
