:root, [data-theme="light"] {
  --bg: #f5f5f7;
  --sidebar: #f5f5f7;
  --card: #ffffff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: #d2d2d7;
  --brand: #0071e3;
  --brand-dark: #0077ed;
  --brand-soft: rgba(0, 113, 227, 0.1);
  --ok: #248a3d;
  --ok-bg: #e4f6e8;
  --danger: #d70015;
  --danger-bg: #ffe5e5;
  --warn: #b25000;
  --shadow: none;
  --radius: 12px;
  --sidebar-w: 200px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Inter, system-ui, sans-serif;
}
[data-theme="dark"] {
  --bg: #000;
  --sidebar: #1d1d1f;
  --card: #1d1d1f;
  --text: #f5f5f7;
  --muted: #a1a1a6;
  --line: #424245;
  --brand: #2997ff;
  --brand-dark: #64b5ff;
  --brand-soft: rgba(41, 151, 255, .18);
  --ok-bg: rgba(36,138,61,.25);
  --danger-bg: rgba(215,0,21,.2);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 13px;
}
a { color: var(--brand); }
.muted { color: var(--muted); }
.muted.sm { font-size: 12px; margin: .15rem 0 0; }
.error { color: var(--danger); }
code { font-size: .85em; background: var(--bg); border: 1px solid var(--line); padding: .1rem .35rem; border-radius: 4px; }

.login-shell {
  min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; background: var(--bg);
}
.login-card {
  width: min(380px, 100%); background: var(--card); border: 1px solid var(--line);
  border-radius: 16px; padding: 1.75rem;
}
.login-card h1 { margin: .7rem 0 .25rem; font-size: 1.35rem; letter-spacing: -.02em; }
.login-card label { display: grid; gap: .3rem; margin: .75rem 0; font-size: 13px; font-weight: 500; }
.login-card input, .url-box input, .custom-range input, .asc-form input, .asc-form textarea {
  border: 1px solid var(--line); border-radius: 8px; padding: .65rem .75rem;
  background: var(--card); color: var(--text); width: 100%; font: inherit;
}
.asc-form textarea { min-height: 110px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; }
.btn-primary {
  width: 100%; margin-top: .35rem; border: 0; border-radius: 980px; padding: .7rem 1rem;
  background: var(--brand); color: #fff; font-weight: 600; cursor: pointer; font-size: 13px;
}
.btn-primary:hover { background: var(--brand-dark); }
.btn-primary.narrow { width: auto; white-space: nowrap; margin: 0; }
.btn-mini {
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 980px; padding: .35rem .7rem; cursor: pointer; font-weight: 600; font-size: 12px;
}
.logo-mark {
  width: 36px; height: 36px; border-radius: 9px; display: grid; place-items: center;
  font-weight: 700; color: #fff; background: var(--brand); font-size: 12px;
}
.logo-mark.sm { width: 28px; height: 28px; font-size: 11px; border-radius: 7px; }

.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; background: var(--sidebar);
  border-right: 1px solid var(--line); display: flex; flex-direction: column;
  padding: .75rem .55rem; position: sticky; top: 0; height: 100vh;
}
.sidebar-brand { display: flex; align-items: center; gap: .5rem; padding: .35rem .45rem .85rem; }
.sidebar-brand strong { display: block; font-size: 13px; font-weight: 600; }
.sidebar-brand small { color: var(--muted); font-size: 11px; }
.side-nav { display: grid; gap: 1px; flex: 1; align-content: start; }
.side-nav button {
  display: flex; align-items: center; gap: .55rem; width: 100%; text-align: left;
  border: 0; background: transparent; color: var(--muted); border-radius: 8px;
  padding: .38rem .55rem; cursor: pointer; font-weight: 500; font-size: 13px; line-height: 1.2;
}
.side-nav button:hover { background: rgba(0,0,0,.04); color: var(--text); }
[data-theme="dark"] .side-nav button:hover { background: rgba(255,255,255,.06); }
.side-nav button.active {
  background: rgba(0,0,0,.06); color: var(--text); font-weight: 600;
  box-shadow: none;
}
[data-theme="dark"] .side-nav button.active { background: rgba(255,255,255,.1); }
.side-nav .ico { width: 1rem; text-align: center; opacity: .75; font-size: 12px; }
.sidebar-foot { display: grid; gap: .25rem; padding-top: .65rem; border-top: 1px solid var(--line); }
.ghost-btn {
  border: 0; background: transparent; color: var(--muted);
  border-radius: 8px; padding: .4rem .55rem; cursor: pointer; text-align: left; font-weight: 500; font-size: 12px;
}
.ghost-btn.danger { color: var(--danger); }
.ghost-btn:hover { background: rgba(0,0,0,.04); color: var(--text); }

.main-col { flex: 1; min-width: 0; padding: 1rem 1.35rem 2rem; background: #fff; }
[data-theme="dark"] .main-col { background: #000; }
.topbar {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 1rem; margin-bottom: .85rem; flex-wrap: wrap;
}
.greeting { margin: 0; color: var(--muted); font-size: 12px; font-weight: 500; }
.topbar h1 { margin: .1rem 0 0; font-size: 22px; letter-spacing: -.02em; font-weight: 700; }
.topbar-right { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; justify-content: flex-end; }
.range-bar {
  display: inline-flex; gap: 0; background: transparent; border: 1px solid var(--line);
  border-radius: 980px; padding: 2px;
}
.range-bar button {
  border: 0; background: transparent; color: var(--muted); border-radius: 980px;
  padding: .3rem .65rem; cursor: pointer; font-size: 12px; font-weight: 600;
}
.range-bar button.active { background: var(--brand); color: #fff; }
.custom-range { display: flex; align-items: center; gap: .35rem; }
.custom-range input { width: auto; padding: .3rem .45rem; }
.icon-btn {
  width: 32px; height: 32px; border-radius: 980px; border: 1px solid var(--line);
  background: var(--card); cursor: pointer; color: var(--text);
}
.profile {
  display: flex; align-items: center; gap: .5rem; background: transparent;
  border: 1px solid var(--line); border-radius: 980px; padding: .2rem .65rem .2rem .2rem;
}
.profile strong { display: block; font-size: 12px; }
.profile small { font-size: 10px; }
.avatar {
  width: 26px; height: 26px; border-radius: 50%; background: var(--brand-soft);
  color: var(--brand); display: grid; place-items: center; font-weight: 700; font-size: 10px;
}

.banner {
  margin: 0 0 .85rem; padding: .65rem .85rem; border-radius: 10px;
  background: #f5f5f7; border: 1px solid var(--line);
  color: var(--muted); font-size: 12.5px; line-height: 1.45;
}
.banner.info { background: #f0f6ff; border-color: #c7ddff; color: #3a3a3c; }
.banner a { font-weight: 600; color: var(--brand); text-decoration: none; }
.banner a:hover { text-decoration: underline; }
[data-theme="dark"] .banner.info { background: rgba(41,151,255,.12); border-color: #424245; color: var(--text); }

.section-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: .75rem;
  margin: 1.15rem 0 .55rem; padding-top: .35rem;
}
.section-head:first-child { margin-top: 0; }
.section-head h2 {
  margin: 0; font-size: 11px; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--muted);
}
.section-head .hint { font-size: 12px; color: var(--muted); }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .9rem 1rem 1rem; box-shadow: none;
}
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: .75rem; margin-bottom: .65rem; }
.card-head h2, .card-head h3 { margin: 0; font-size: 14px; font-weight: 600; letter-spacing: -.01em; }
.pill {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); background: #f5f5f7; border: 1px solid var(--line);
  border-radius: 980px; padding: .2rem .5rem;
}
.pill.alt { color: var(--brand); background: var(--brand-soft); border-color: transparent; }
.pill.ok { color: var(--ok); background: var(--ok-bg); border-color: transparent; }
.pill.warn { color: var(--warn); background: #fff4e5; border-color: transparent; }
[data-theme="dark"] .pill { background: #2c2c2e; }
[data-theme="dark"] .pill.alt { color: #64b5ff; }
[data-theme="dark"] .pill.ok { color: #86efac; }

.kpi-row {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .65rem; margin-bottom: .75rem;
}
.kpi-row.compact { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.kpi-row.asc { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
@media (max-width: 1100px) { .kpi-row { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.kpi {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .85rem .9rem .7rem; box-shadow: none;
  display: grid; grid-template-columns: 1fr 70px; gap: .2rem .4rem; align-items: end;
  position: relative; overflow: hidden;
}
/* No decorative circles */
.kpi::before { content: none; display: none; }
.kpi .label {
  grid-column: 1 / -1; color: var(--muted); font-size: 10px; font-weight: 700;
  letter-spacing: .05em; text-transform: uppercase;
}
.kpi .value { font-size: 26px; font-weight: 700; letter-spacing: -.03em; line-height: 1.05; }
.kpi .sub { grid-column: 1 / -1; font-size: 11px; color: var(--muted); }
.kpi .trend { font-size: 11px; font-weight: 600; }
.kpi .trend.up { color: var(--ok); }
.kpi .trend.down { color: var(--danger); }
.kpi .trend.flat { color: var(--muted); }
.kpi canvas { width: 70px !important; height: 34px !important; }
.kpi.locked .value { font-size: 15px; font-weight: 600; color: var(--muted); }
.kpi.locked { background: #fafafa; }
[data-theme="dark"] .kpi.locked { background: #141416; }

.grid-12 {
  display: grid; grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: .65rem; margin-bottom: .65rem;
}
.col-8 { grid-column: span 8; }
.col-6 { grid-column: span 6; }
.col-4 { grid-column: span 4; }
@media (max-width: 1100px) {
  .col-8, .col-6, .col-4 { grid-column: 1 / -1; }
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: relative; }
  .side-nav { grid-auto-flow: column; overflow-x: auto; }
  .main-col { background: var(--bg); }
}

.chart-xl { height: 280px; position: relative; }
.chart-lg { height: 230px; position: relative; }
.chart-md { height: 170px; position: relative; }
.chart-sm { height: 130px; position: relative; }

.bar-list, .rank-list, .feed { list-style: none; margin: .35rem 0 0; padding: 0; }
.bar-list { display: grid; gap: .45rem; }
.bar-list li {
  display: grid; grid-template-columns: 60px 1fr 32px; gap: .4rem; align-items: center; font-size: 12px; font-weight: 600;
}
.bar-list .track {
  height: 6px; border-radius: 999px; background: #f5f5f7; overflow: hidden; border: 1px solid var(--line);
}
.bar-list .fill { height: 100%; border-radius: 999px; background: var(--brand); }
.bar-list .n { color: var(--muted); text-align: right; }

.rank-list li {
  display: flex; justify-content: space-between; gap: .75rem;
  padding: .5rem 0; border-bottom: 1px solid var(--line); font-size: 13px;
}
.rank-list li:last-child { border-bottom: 0; }
.rank-list .n { font-weight: 700; color: var(--text); }

.feed { max-height: 280px; overflow: auto; }
.feed li {
  display: grid; grid-template-columns: 32px 1fr auto; gap: .55rem; align-items: start;
  padding: .55rem 0; border-bottom: 1px solid var(--line); font-size: 12.5px;
}
.feed .dot {
  width: 32px; height: 32px; border-radius: 8px; background: var(--brand-soft);
  color: var(--brand); display: grid; place-items: center; font-size: 9px; font-weight: 700;
}
.feed .meta { color: var(--muted); font-size: 11px; margin-top: .1rem; }
.feed .when { color: var(--muted); font-size: 11px; white-space: nowrap; }

.sub-mini { display: grid; grid-template-columns: repeat(3, 1fr); gap: .4rem; margin-bottom: .55rem; }
.sub-mini .cell {
  background: #fafafa; border: 1px solid var(--line); border-radius: 8px; padding: .45rem .55rem;
}
[data-theme="dark"] .sub-mini .cell { background: #141416; }
.sub-mini .n { font-size: 1.05rem; font-weight: 700; }
.sub-mini .l { font-size: 10px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.setup-link { margin: .45rem 0 0; font-size: 12px; font-weight: 600; }
.setup-link a { text-decoration: none; }

.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th, td { text-align: left; padding: .55rem .4rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th {
  color: var(--muted); font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
}
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; }
.badge {
  display: inline-block; border-radius: 980px; padding: .15rem .45rem; font-size: 10px; font-weight: 700;
}
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.off { background: #f5f5f7; color: var(--muted); border: 1px solid var(--line); }
.empty-state { color: var(--muted); font-style: italic; padding: 1rem .4rem !important; }

.setup-card .url-box { margin: .5rem 0 1rem; }
.setup-card .url-box label, .asc-form label { display: block; font-weight: 600; margin-bottom: .35rem; font-size: 12px; }
.url-row { display: flex; gap: .5rem; align-items: center; }
.asc-form { display: grid; gap: .75rem; margin: .75rem 0 1rem; }
.asc-form .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: .65rem; }
@media (max-width: 700px) { .asc-form .row2 { grid-template-columns: 1fr; } }
.setup-steps {
  margin: 0 0 1rem; padding-left: 1.15rem; display: grid; gap: .5rem;
  color: var(--text); line-height: 1.45; font-size: 13px;
}
.setup-steps em { color: var(--muted); font-style: normal; display: block; font-size: 12px; margin-top: .1rem; }
.callout {
  background: #f0f6ff; border: 1px solid #c7ddff; border-radius: 10px;
  padding: .85rem .95rem; margin-bottom: .75rem; line-height: 1.45;
}
.callout.soft { background: #f5f5f7; border-color: var(--line); }
.callout strong { display: block; margin-bottom: .25rem; font-size: 13px; }
.callout p { margin: 0; color: var(--muted); font-size: 12.5px; }
[data-theme="dark"] .callout { background: rgba(41,151,255,.12); border-color: #424245; }

.asc-status {
  display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
  margin: 0 0 .65rem; font-size: 12px; color: var(--muted);
}
