:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --text: #1d2330;
    --muted: #6b7385;
    --border: #e2e5eb;
    --accent: #3b5bdb;
    --accent-text: #ffffff;
    --danger: #c92a2a;
    --ok-bg: #e6f6ec;
    --ok-text: #1e6b3a;
    --err-bg: #fdecec;
    --err-text: #9b1c1c;
    --radius: 10px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #12151b;
        --surface: #1b1f27;
        --text: #e6e8ee;
        --muted: #9098a9;
        --border: #2c323d;
        --accent: #6f8cff;
        --accent-text: #0d1020;
        --danger: #ff6b6b;
        --ok-bg: #173323;
        --ok-text: #8fe0aa;
        --err-bg: #3a1a1a;
        --err-text: #ffaaaa;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2 { margin: 0 0 1rem; line-height: 1.2; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.1rem; }

.wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px; }
main.wrap { padding-top: 24px; padding-bottom: 48px; }

.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar .wrap { display: flex; align-items: center; justify-content: space-between; height: 56px; gap: 16px; }
.brand { font-weight: 700; font-size: 1.15rem; color: var(--text); }
.topbar nav { display: flex; align-items: center; gap: 18px; }
.topbar nav form { margin: 0; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 20px;
}
.narrow { max-width: 420px; margin-left: auto; margin-right: auto; }
.center { text-align: center; }
.muted { color: var(--muted); font-weight: normal; }
.nowrap { white-space: nowrap; }
.empty { padding: 40px 0; }

label { display: block; margin-bottom: 14px; font-weight: 500; }
label > input, label > select, label > .prefix-input { margin-top: 4px; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: normal; }

input, select, button { font: inherit; color: inherit; }
input:not([type=checkbox]):not([type=color]), select {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=color] { width: 44px; height: 34px; padding: 2px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); vertical-align: middle; }

.prefix-input { display: flex; align-items: stretch; }
.prefix-input span {
    display: flex; align-items: center; padding: 0 10px;
    background: var(--border); color: var(--muted);
    border-radius: 8px 0 0 8px; white-space: nowrap; font-weight: normal;
}
.prefix-input input { border-radius: 0 8px 8px 0 !important; min-width: 0; }

.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 8px 16px; border: 1px solid var(--accent); border-radius: 8px;
    background: var(--accent); color: var(--accent-text);
    font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover { text-decoration: none; filter: brightness(1.08); }
.btn-ghost { background: transparent; color: var(--accent); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-small { padding: 3px 10px; font-size: 0.85rem; }
.btn-block { width: 100%; }
.linklike { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; }
.icon-btn { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 0 4px; }
.icon-btn:hover { color: var(--accent); }

.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.row label { margin-bottom: 0; }

.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; word-break: break-word; }
.alert-ok { background: var(--ok-bg); color: var(--ok-text); }
.alert-error { background: var(--err-bg); color: var(--err-text); }

.quick { display: flex; gap: 10px; flex-wrap: wrap; }
.quick .grow { flex: 2 1 300px; }
.quick .prefix-input { flex: 1 1 240px; }

.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar h1 { margin: 0; margin-right: auto; }
.search { display: flex; gap: 12px; align-items: center; }
.search input { width: 220px; }
.search label { margin: 0; white-space: nowrap; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; }
tbody tr:last-child td { border-bottom: 0; }
tr.inactive td { opacity: 0.55; }
.num { text-align: right; }
.code { font-family: ui-monospace, Consolas, monospace; font-weight: 600; }
.dest { max-width: 420px; }
.dest a { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
.dest .title { font-weight: 500; }
.actions { display: flex; gap: 6px; justify-content: flex-end; }
.actions form { margin: 0; }

.badge { display: inline-block; padding: 0 6px; border-radius: 4px; background: var(--border); color: var(--muted); font-size: 0.75rem; }
.badge-accent { background: var(--accent); color: var(--accent-text); }

.pager { display: flex; gap: 6px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }
.pager a { padding: 4px 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); }
.pager a.current { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
.grid-2 .card { margin-bottom: 0; }
@media (max-width: 760px) { .grid-2 { grid-template-columns: 1fr; } }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 20px 0; }
.stats div { background: var(--bg); border-radius: 8px; padding: 8px 12px; }
.stats dt { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; }
.stats dd { margin: 0; font-weight: 600; }

.share { display: flex; gap: 8px; margin-bottom: 16px; }

.qr-panel { display: flex; flex-direction: column; gap: 14px; }
.qr-preview { background: #fff; border-radius: 8px; border: 1px solid var(--border); padding: 0; aspect-ratio: 1; max-width: 320px; width: 100%; margin: 0 auto; overflow: hidden; }
.qr-preview svg { display: block; width: 100%; height: 100%; }
.qr-controls label { margin-bottom: 10px; }

dialog {
    border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--surface); color: var(--text);
    padding: 20px; width: min(420px, calc(100vw - 32px));
}
dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
.dialog-head { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 14px; word-break: break-all; }

/* ---------------------------------------------------------------- stats */

.subtitle { font-size: 0.85rem; margin-top: 4px; max-width: 640px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.small { font-size: 0.85rem; }

.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.segmented a { padding: 5px 12px; color: var(--muted); font-size: 0.875rem; }
.segmented a + a { border-left: 1px solid var(--border); }
.segmented a.current { background: var(--accent); color: var(--accent-text); }
.segmented a:hover { text-decoration: none; }

.tiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.tile-label { font-size: 0.8rem; color: var(--muted); }
.tile-value { font-size: 1.7rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
@media (max-width: 700px) { .tiles { grid-template-columns: repeat(2, 1fr); } }

.chart { display: grid; grid-template-columns: auto 1fr; grid-template-rows: 200px auto; column-gap: 8px; }
.chart-y { position: relative; width: 2.5em; font-size: 0.75rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.chart-y span { position: absolute; right: 0; transform: translateY(50%); line-height: 1; }
.chart-plot { position: relative; border-bottom: 1px solid var(--border); }
.chart-grid { position: absolute; left: 0; right: 0; border-top: 1px dashed var(--border); }
.chart-bars { position: absolute; inset: 0; display: flex; align-items: flex-end; }
.chart-slot { flex: 1 1 0; height: 100%; display: flex; align-items: flex-end; justify-content: center; padding: 0 1px; outline: none; }
.chart-bar { width: 100%; max-width: 28px; min-height: 2px; background: var(--accent); border-radius: 4px 4px 0 0; }
.chart-slot:hover, .chart-slot:focus-visible { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.chart-x { display: flex; font-size: 0.75rem; color: var(--muted); padding-top: 6px; }
.chart-x span { flex: 1 1 0; white-space: nowrap; overflow: visible; width: 0; }

.as-table { margin-top: 14px; font-size: 0.9rem; }
.as-table summary { cursor: pointer; color: var(--muted); }
.as-table table { margin-top: 8px; max-width: 360px; }
.as-table td, .as-table th { padding: 4px 8px; }

.breakdowns { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px; margin-bottom: 20px; }
.breakdowns .card { margin-bottom: 0; }
.hbars { list-style: none; margin: 0; padding: 0; }
.hbars li { position: relative; display: flex; justify-content: space-between; gap: 12px; padding: 5px 8px; margin-bottom: 2px; border-radius: 6px; }
.hbars li:hover { background: var(--bg); }
.hbar-fill { position: absolute; left: 0; top: 0; bottom: 0; background: color-mix(in srgb, var(--accent) 18%, transparent); border-radius: 6px; z-index: 0; }
.hbar-label, .hbar-value { position: relative; z-index: 1; }
.hbar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-value { font-variant-numeric: tabular-nums; font-weight: 600; }

.tooltip {
    position: fixed; z-index: 100; pointer-events: none;
    background: var(--text); color: var(--surface);
    padding: 5px 9px; border-radius: 6px; font-size: 0.8rem; white-space: nowrap;
    transform: translate(-50%, calc(-100% - 10px));
}

@media (max-width: 600px) {
    .topbar nav { gap: 12px; font-size: 0.9rem; }
    .search input { width: 100%; }
    .search { width: 100%; }
    .dest { max-width: 200px; }
}
