/* Web Stats dashboard. Two themes, no external assets, no web fonts: the
   dashboard should load as fast as the script it serves. */

:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --faint: #94a3b8;
  --accent: #4f46e5;
  --accent-soft: #eef2ff;
  --bar: #e0e7ff;
  --positive: #059669;
  --negative: #dc2626;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .04);
  --radius: 10px;
}

:root[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #1e293b;
  --border: #334155;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --faint: #64748b;
  --accent: #818cf8;
  --accent-soft: #312e81;
  --bar: #312e81;
  --positive: #34d399;
  --negative: #f87171;
  --shadow: none;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f172a;
    --surface: #1e293b;
    --border: #334155;
    --text: #f1f5f9;
    --muted: #94a3b8;
    --faint: #64748b;
    --accent: #818cf8;
    --accent-soft: #312e81;
    --bar: #312e81;
    --positive: #34d399;
    --negative: #f87171;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; }

.wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px 64px; }

/* ---- top bar ------------------------------------------------------- */

.topbar {
  position: sticky; top: 0; z-index: 30;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1100px; margin: 0 auto; padding: 12px 16px;
  display: flex; align-items: center; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; letter-spacing: -.01em; }
.brand svg { width: 22px; height: 22px; color: var(--accent); }
.spacer { flex: 1; }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  box-shadow: var(--shadow);
}
.btn:hover { border-color: var(--faint); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); border-color: var(--accent); }
.btn-danger { color: var(--negative); }
.btn-plain { border: 0; background: none; box-shadow: none; padding: 6px; color: var(--muted); }
.btn-plain:hover { color: var(--text); }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

/* ---- menus --------------------------------------------------------- */

.menu { position: relative; }
.menu-panel {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 40;
  min-width: 220px; max-height: 60vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 10px 30px rgba(15, 23, 42, .12);
  padding: 6px;
}
.menu-panel[hidden] { display: none; }
.menu-item {
  display: flex; justify-content: space-between; gap: 12px; width: 100%;
  padding: 8px 10px; border: 0; background: none; border-radius: 7px;
  color: var(--text); text-align: left;
}
.menu-item:hover { background: var(--accent-soft); }
.menu-item.is-active { color: var(--accent); font-weight: 600; }
.menu-sep { height: 1px; background: var(--border); margin: 6px 2px; }
.menu-label { padding: 8px 10px 4px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .06em; color: var(--faint); }

/* ---- cards --------------------------------------------------------- */

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); margin-top: 16px;
}
.card-head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px 0;
}
.card-title { font-weight: 600; }
.card-body { padding: 12px 16px 16px; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid > .card { margin-top: 0; }

.tabs { display: flex; gap: 2px; margin-left: auto; flex-wrap: wrap; }
.tab {
  padding: 4px 9px; border-radius: 6px; border: 0; background: none;
  color: var(--muted); font-size: 12px;
}
.tab:hover { background: var(--accent-soft); color: var(--text); }
.tab.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* ---- headline metrics ---------------------------------------------- */

.metrics { display: flex; flex-wrap: wrap; gap: 8px; padding: 14px 16px 0; }
.metric {
  flex: 1 1 130px; text-align: left; padding: 8px 10px; border-radius: 8px;
  border: 1px solid transparent; background: none; color: inherit;
}
.metric:hover { background: var(--accent-soft); }
.metric.is-active { border-color: var(--accent); background: var(--accent-soft); }
.metric-label { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.metric-value { font-size: 22px; font-weight: 600; letter-spacing: -.02em; margin-top: 2px; }
.metric-change { font-size: 12px; margin-top: 2px; }
.up { color: var(--positive); }
.down { color: var(--negative); }

.live { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.live-dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--positive);
  box-shadow: 0 0 0 0 rgba(5, 150, 105, .6); animation: pulse 2.4s infinite;
}
@keyframes pulse {
  70% { box-shadow: 0 0 0 7px rgba(5, 150, 105, 0); }
  100% { box-shadow: 0 0 0 0 rgba(5, 150, 105, 0); }
}

/* ---- graph ---------------------------------------------------------- */

.chart { position: relative; padding: 8px 4px 0; }
.chart svg { display: block; width: 100%; height: 260px; overflow: visible; }
.chart-line { fill: none; stroke: var(--accent); stroke-width: 2.5;
  stroke-linejoin: round; stroke-linecap: round; }
.chart-compare { fill: none; stroke: var(--faint); stroke-width: 1.5; stroke-dasharray: 4 4; }
.chart-grid { stroke: var(--border); stroke-width: 1; }
.chart-axis { fill: var(--faint); font-size: 11px; }
.chart-dot { fill: var(--surface); stroke: var(--accent); stroke-width: 2.5; }
.chart-cursor { stroke: var(--faint); stroke-width: 1; stroke-dasharray: 3 3; }
.tooltip {
  position: absolute; pointer-events: none; z-index: 10;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, .16); padding: 8px 10px;
  font-size: 12px; white-space: nowrap; transform: translate(-50%, -100%);
}
.tooltip[hidden] { display: none; }
.tooltip b { font-size: 13px; }

/* ---- report lists ---------------------------------------------------- */

.list { list-style: none; margin: 0; padding: 0; }
.row {
  position: relative; display: flex; align-items: center; gap: 10px;
  padding: 7px 8px; border-radius: 6px; min-height: 34px;
}
.row + .row { margin-top: 1px; }
.row-bar {
  position: absolute; inset: 0 auto 0 0; background: var(--bar);
  border-radius: 6px; z-index: 0; transition: width .25s ease;
}
.row-name {
  position: relative; z-index: 1; flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  display: flex; align-items: center; gap: 8px;
}
.row-name button { border: 0; background: none; padding: 0; color: inherit; text-align: left;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-name button:hover { color: var(--accent); text-decoration: underline; }
.row-value { position: relative; z-index: 1; font-variant-numeric: tabular-nums; color: var(--muted); }
.row-value b { color: var(--text); font-weight: 600; }
.row-head {
  display: flex; gap: 10px; padding: 4px 8px 6px; font-size: 11px;
  text-transform: uppercase; letter-spacing: .05em; color: var(--faint);
}
.row-head span:first-child { flex: 1; }
.favicon, .flag { width: 16px; height: 16px; flex: none; border-radius: 3px; }
.flag { width: 20px; text-align: center; font-size: 14px; line-height: 16px; }

.empty { padding: 28px 8px; text-align: center; color: var(--muted); }
.card-foot { padding: 8px 16px 14px; }
.link { color: var(--accent); background: none; border: 0; padding: 0; font-size: 12px; }
.link:hover { text-decoration: underline; }

/* ---- filters --------------------------------------------------------- */

.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 16px; }
.pill {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 999px; padding: 5px 10px 5px 12px; font-size: 12px; box-shadow: var(--shadow);
}
.pill b { font-weight: 600; }
.pill button { border: 0; background: none; color: var(--muted); padding: 0 2px; line-height: 1; }
.pill button:hover { color: var(--negative); }

/* ---- modal ----------------------------------------------------------- */

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 50;
  display: flex; align-items: flex-start; justify-content: center; padding: 48px 16px;
  overflow-y: auto;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--surface); border-radius: 14px; width: 100%; max-width: 620px;
  box-shadow: 0 20px 60px rgba(15, 23, 42, .3); border: 1px solid var(--border);
}
.modal-head { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 16px; }
.modal-body { padding: 18px 20px; }
.modal-body > section + section { margin-top: 26px; padding-top: 22px; border-top: 1px solid var(--border); }
.modal-body h3 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase;
  letter-spacing: .05em; color: var(--muted); }

/* ---- forms ----------------------------------------------------------- */

label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=email], input[type=password], select {
  width: 100%; padding: 8px 10px; border-radius: 8px; font: inherit;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.field + .field { margin-top: 12px; }
.row-inline { display: flex; gap: 8px; align-items: flex-end; }
.row-inline .field { flex: 1; margin-top: 0; }
.checkbox { display: flex; gap: 8px; align-items: flex-start; }
.checkbox input { width: auto; margin-top: 3px; }
.checkbox span { font-size: 13px; color: var(--text); }
.hint { font-size: 12px; color: var(--muted); margin-top: 6px; }
.error { color: var(--negative); font-size: 13px; margin-top: 10px; min-height: 18px; }

code, pre {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px;
}
pre {
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px; overflow-x: auto; margin: 0;
}

/* ---- auth and empty states -------------------------------------------- */

.center { max-width: 380px; margin: 12vh auto; }
.center .card { padding: 26px; }
.center h1 { margin: 0 0 6px; font-size: 20px; }
.center p { margin: 0 0 18px; color: var(--muted); }

.site-row {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.site-row:last-child { border-bottom: 0; }
.site-row .domain { font-weight: 600; flex: 1; }
.site-row .count { color: var(--muted); font-variant-numeric: tabular-nums; }

.badge {
  font-size: 11px; padding: 2px 7px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); font-weight: 600;
}

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); font-size: 13px; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--faint); }

@media (max-width: 760px) {
  .grid { grid-template-columns: 1fr; }
  .metric { flex-basis: 45%; }
  .topbar-inner { flex-wrap: wrap; }
}
