:root {
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --accent-soft: #cde2fb;
  --danger: #d03b3b;
  --good: #006300;
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --accent: #3987e5;
    --accent-soft: #184f95;
    --danger: #e66767;
    --good: #0ca30c;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--page);
  color: var(--ink);
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.container { max-width: 1080px; margin: 0 auto; padding: 0 20px; }

/* ---------- header ---------- */
.site-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.site-header .inner {
  max-width: 1080px; margin: 0 auto; padding: 0 20px;
  display: flex; align-items: center; justify-content: space-between; width: 100%;
}
.logo { font-weight: 700; font-size: 20px; color: var(--ink); letter-spacing: -0.02em; }
.logo:hover { text-decoration: none; }
.logo .dot { color: var(--accent); }
.nav { display: flex; gap: 16px; align-items: center; }
.nav .user-email { color: var(--ink-2); font-size: 14px; }

/* ---------- buttons & forms ---------- */
.btn {
  display: inline-block; border: 1px solid var(--border);
  background: var(--surface); color: var(--ink);
  padding: 8px 16px; border-radius: 8px; font-size: 14px; font-family: var(--font);
  cursor: pointer; text-decoration: none;
}
.btn:hover { border-color: var(--baseline); text-decoration: none; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-danger { color: var(--danger); }
.btn-sm { padding: 4px 10px; font-size: 13px; }

input, select {
  font-family: var(--font); font-size: 14px;
  padding: 9px 12px; border-radius: 8px;
  border: 1px solid var(--baseline);
  background: var(--surface); color: var(--ink);
  width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
label { display: block; font-size: 13px; color: var(--ink-2); margin: 12px 0 4px; }

.form-error {
  color: var(--danger); font-size: 14px; margin-top: 12px; min-height: 20px;
}

/* ---------- auth card ---------- */
.auth-wrap { display: flex; justify-content: center; padding: 64px 20px; }
.auth-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 32px; width: 100%; max-width: 400px;
}
.auth-card h1 { margin: 0 0 4px; font-size: 22px; }
.auth-card .sub { color: var(--ink-2); font-size: 14px; margin: 0 0 12px; }
.auth-card .btn { width: 100%; margin-top: 20px; padding: 10px; }
.auth-card .alt { text-align: center; font-size: 14px; color: var(--ink-2); margin-top: 16px; }

/* ---------- landing ---------- */
.hero { text-align: center; padding: 80px 20px 48px; }
.hero h1 { font-size: 44px; letter-spacing: -0.03em; margin: 0 0 12px; }
.hero p { color: var(--ink-2); font-size: 18px; max-width: 560px; margin: 0 auto 28px; }
.hero .cta { display: flex; gap: 12px; justify-content: center; }
.features {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px; padding: 24px 0 80px;
}
.feature {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
}
.feature h3 { margin: 0 0 6px; font-size: 16px; }
.feature p { margin: 0; color: var(--ink-2); font-size: 14px; }

/* ---------- dashboard layout ---------- */
.dash { padding: 24px 0 64px; }
.dash h2 { font-size: 18px; margin: 28px 0 12px; }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
}

.stat-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; }
.stat-tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 20px; }
.stat-tile .label { font-size: 13px; color: var(--ink-2); }
.stat-tile .value { font-size: 30px; font-weight: 650; letter-spacing: -0.02em; }

.shorten-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.shorten-form .field { flex: 1 1 260px; }
.shorten-form .field.small { flex: 0 1 160px; }
.shorten-form label { margin-top: 0; }

/* ---------- links table ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--muted); font-weight: 600; padding: 8px 12px; border-bottom: 1px solid var(--grid);
}
td { padding: 10px 12px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr.row-link { cursor: pointer; }
tr.row-link:hover td { background: color-mix(in srgb, var(--accent) 6%, transparent); }
td.num { font-variant-numeric: tabular-nums; text-align: right; }
th.num { text-align: right; }
.code-pill {
  font-weight: 600; color: var(--accent); white-space: nowrap;
}
.target-cell { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.inactive-badge {
  font-size: 11px; border: 1px solid var(--baseline); color: var(--muted);
  border-radius: 999px; padding: 1px 8px; margin-left: 6px; vertical-align: middle;
}

/* ---------- charts ---------- */
.chart-card { position: relative; }
.chart-card h3 { margin: 0 0 4px; font-size: 15px; }
.chart-card .chart-sub { color: var(--muted); font-size: 12px; margin: 0 0 12px; }
.chart-svg { display: block; width: 100%; height: auto; }
.viz-tooltip {
  position: absolute; pointer-events: none; z-index: 10;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 10px; font-size: 12px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
  white-space: nowrap; display: none;
}
.viz-tooltip .t-label { color: var(--ink-2); }
.viz-tooltip .t-value { font-weight: 650; font-variant-numeric: tabular-nums; }

.breakdowns { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 16px; }
.hbar-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; font-size: 13px; margin: 6px 0; }
.hbar-label { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { grid-column: 1 / -1; height: 6px; border-radius: 4px; background: var(--grid); overflow: hidden; }
.hbar-fill { height: 100%; border-radius: 4px; background: var(--accent); }
.hbar-count { font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 600; }
.empty-note { color: var(--muted); font-size: 13px; }

/* ---------- detail header ---------- */
.detail-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; }
.detail-head .title { font-size: 16px; font-weight: 650; }
.range-picker { display: flex; gap: 4px; }
.range-picker button {
  border: 1px solid var(--border); background: transparent; color: var(--ink-2);
  border-radius: 6px; padding: 4px 10px; font-size: 13px; cursor: pointer; font-family: var(--font);
}
.range-picker button.active { background: var(--accent); color: var(--accent-ink); border-color: transparent; }

/* ---------- api keys ---------- */
.key-reveal {
  background: color-mix(in srgb, var(--accent) 10%, var(--surface));
  border: 1px solid var(--accent);
  border-radius: 8px; padding: 12px; margin-top: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px;
  word-break: break-all;
}
.key-reveal .note { font-family: var(--font); color: var(--ink-2); font-size: 12px; display: block; margin-top: 6px; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--page); padding: 10px 18px;
  border-radius: 999px; font-size: 14px; opacity: 0; transition: opacity 0.2s;
  pointer-events: none; z-index: 100;
}
.toast.show { opacity: 1; }

.muted { color: var(--muted); font-size: 13px; }
.hidden { display: none; }
