:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0efec;
  --text: #0b0b0b;
  --text-2: #52514e;
  --muted: #7d7c77;
  --rule: #e4e3de;
  --grid: #ecebe7;
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --accent-soft: #e6f0fc;
  --good: #1b7f3b;
  --bad: #b3261e;
  --warn: #8a5a00;
  --radius: 10px;
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #111110;
    --surface: #1a1a19;
    --surface-2: #242422;
    --text: #ffffff;
    --text-2: #c3c2b7;
    --muted: #8f8e86;
    --rule: #2e2d2a;
    --grid: #2a2927;
    --accent: #3987e5;
    --accent-ink: #86b6ef;
    --accent-soft: #16263b;
    --good: #5cc27f;
    --bad: #f28b82;
    --warn: #e0b04a;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 600; }
.muted { color: var(--muted); }
.pad { padding: 24px 16px; }
.num { font-variant-numeric: tabular-nums; }

.top {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--rule);
}
.brand { font-weight: 700; color: var(--text); font-size: 16px; }
.brand span { color: var(--muted); font-weight: 500; }
.top nav { display: flex; gap: 4px; }
.top nav a { color: var(--text-2); padding: 6px 10px; border-radius: 8px; }
.top nav a.on { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.top nav a:hover { text-decoration: none; background: var(--surface-2); }
.range { margin-left: auto; display: flex; border: 1px solid var(--rule); border-radius: 8px; overflow: hidden; }
.range button { border: 0; background: transparent; color: var(--text-2); padding: 5px 10px; font: inherit; cursor: pointer; }
.range button + button { border-left: 1px solid var(--rule); }
.range button.on { background: var(--accent); color: #fff; }
.logout { color: var(--muted); font-size: 14px; }

main { max-width: 1180px; margin: 0 auto; padding: 24px 24px 64px; }
.bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.bar .grow { flex: 1; }
.card { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; min-width: 0; }
.card .sub { color: var(--muted); font-size: 13px; margin: 8px 0 0; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.grid2 > .card, .grid3 > .card { margin-bottom: 0; }
.stack { display: grid; gap: 16px; margin-bottom: 16px; }

.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.tile { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 14px 16px; }
.tile .label { color: var(--text-2); font-size: 13px; }
.tile .value { font-size: 28px; font-weight: 600; line-height: 1.2; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile .value.small { font-size: 17px; margin-top: 8px; }
.tile .hint { color: var(--muted); font-size: 12px; margin-top: 2px; }

form.create { display: grid; grid-template-columns: 2fr 1.2fr 1fr; gap: 10px 12px; align-items: end; }
form.create .wide { grid-column: 1 / -1; }
label { display: grid; gap: 4px; font-size: 13px; color: var(--text-2); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--rule);
  border-radius: 8px; padding: 8px 10px; width: 100%; min-width: 0;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.prefix { display: flex; align-items: stretch; }
.prefix span { display: flex; align-items: center; padding: 0 8px; background: var(--surface-2); border: 1px solid var(--rule); border-right: 0; border-radius: 8px 0 0 8px; color: var(--text-2); white-space: nowrap; }
.prefix input { border-radius: 0 8px 8px 0; }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: auto; }
button.btn, a.btn {
  font: inherit; font-weight: 600; border: 1px solid var(--accent); background: var(--accent); color: #fff;
  border-radius: 8px; padding: 8px 14px; cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px;
}
a.btn:hover { text-decoration: none; }
.btn.ghost { background: transparent; color: var(--accent-ink); border-color: var(--rule); }
.btn.small { padding: 4px 9px; font-size: 13px; font-weight: 500; }
.btn:disabled { opacity: .6; cursor: default; }
.err { color: var(--bad); font-size: 14px; }

.result { display: flex; gap: 16px; align-items: center; margin-top: 14px; padding: 12px; border-radius: 8px; background: var(--accent-soft); flex-wrap: wrap; }
.result img { width: 88px; height: 88px; border-radius: 6px; background: #fff; }
.result .url { font-size: 18px; font-weight: 600; word-break: break-all; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-weight: 600; color: var(--text-2); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; padding: 8px 10px; border-bottom: 1px solid var(--rule); white-space: nowrap; }
td { padding: 9px 10px; border-bottom: 1px solid var(--grid); vertical-align: top; }
td.r, th.r { text-align: right; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--surface-2); }
.clip { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-url { font-weight: 600; }
.pill { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); }
.pill.good { color: var(--good); }
.pill.bad { color: var(--bad); }
.pill.warn { color: var(--warn); }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 12px; }

.chart { position: relative; }
.chart svg { display: block; overflow: visible; }
.chart .grid line { stroke: var(--grid); stroke-width: 1; }
.chart .axis text { fill: var(--muted); font-size: 11px; }
.chart .col { fill: var(--accent); }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover + .col, .chart .col.on { fill: var(--accent-ink); }
.tip {
  position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--rule); border-radius: 8px;
  padding: 6px 10px; font-size: 13px; box-shadow: 0 4px 16px rgba(0,0,0,.12); white-space: nowrap; display: none; z-index: 3;
}
.tip b { display: block; }
details.data summary { cursor: pointer; color: var(--muted); font-size: 13px; margin-top: 8px; }
details.data table { margin-top: 8px; }

.blist { display: grid; gap: 10px; }
.brow { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 2px 12px; font-size: 14px; }
.brow .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brow .val { color: var(--text-2); font-variant-numeric: tabular-nums; }
.brow svg { grid-column: 1 / -1; width: 100%; height: 8px; display: block; }
.brow .track { fill: var(--surface-2); }
.brow .fill { fill: var(--accent); }

.detail-head { display: flex; gap: 20px; align-items: flex-start; flex-wrap: wrap; }
.detail-head .qr { width: 132px; height: 132px; background: #fff; border-radius: 8px; border: 1px solid var(--rule); }
.detail-head .info { flex: 1; min-width: 260px; }
.detail-head .big { font-size: 24px; font-weight: 700; word-break: break-all; }
.detail-head .dest { color: var(--text-2); word-break: break-all; margin: 4px 0 10px; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
form.edit { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 10px 12px; align-items: end; }
form.edit .wide { grid-column: 1 / -1; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 8px; font-size: 14px; opacity: 0; transition: opacity .2s; pointer-events: none; }
#toast.on { opacity: 1; }

body.login { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 28px; width: min(360px, 100%); display: grid; gap: 14px; }
.login-card h1 { font-size: 20px; }
.login-card button { font: inherit; font-weight: 600; border: 0; background: var(--accent); color: #fff; border-radius: 8px; padding: 10px; cursor: pointer; }
.login-card .muted { font-size: 13px; margin: 0; }

@media (max-width: 900px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  form.create, form.edit { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 640px) {
  .top { padding: 10px 16px; gap: 10px; }
  .range { margin-left: 0; }
  main { padding: 16px 16px 48px; }
  .grid2, .grid3 { grid-template-columns: minmax(0, 1fr); }
  form.create, form.edit { grid-template-columns: minmax(0, 1fr); }
  .tile .value { font-size: 24px; }
  .clip { max-width: 180px; }
}

/* UTM builder, bulk page, QR designer */
details.utm summary { cursor: pointer; color: var(--accent-ink); font-size: 14px; }
details.utm[open] summary { margin-bottom: 10px; }
.utm-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px 12px; margin-bottom: 10px; }
.utm-preview { word-break: break-all; }
label.paste { margin-top: 12px; }
textarea { font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; resize: vertical; }
input[type="file"] { border: 0; padding: 4px 0; background: transparent; width: auto; }
input[type="color"] { padding: 2px; height: 38px; cursor: pointer; }
.qr-designer { display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 24px; align-items: start; }
.qr-preview { background: var(--surface-2); border-radius: 10px; padding: 14px; }
.qr-preview img { display: block; width: 100%; height: auto; border-radius: 6px; }
.qr-controls { display: grid; gap: 12px; }
.qr-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 640px) {
  .qr-designer { grid-template-columns: minmax(0, 1fr); }
  .qr-preview { max-width: 260px; }
}

[hidden] { display: none !important; }
.err:empty { display: none; }
