:root {
    --bg: #f5f6fa;
    --panel: #ffffff;
    --text: #111827;
    --muted: #6b7280;
    --border: #e5e7eb;
    --accent: #4f46e5;
    --accent-hover: #4338ca;
    --danger: #dc2626;
    --radius: 12px;
    --shadow: 0 1px 2px rgba(0,0,0,.04), 0 8px 24px rgba(17,24,39,.06);
    --checker: #d1d5db;
    color-scheme: light;
}
/* Light is the default; dark only when chosen with the toggle. */
:root[data-theme="dark"] {
    --bg: #0f1117;
    --panel: #171a23;
    --text: #e5e7eb;
    --muted: #9ca3af;
    --border: #2a2f3b;
    --accent: #818cf8;
    --accent-hover: #6366f1;
    --shadow: 0 8px 24px rgba(0,0,0,.35);
    --checker: #4b5563;
    color-scheme: dark;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh; display: flex; flex-direction: column;
}
a { color: var(--accent); }
h1 { font-size: 1.35rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 0 0 .5rem; }
h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 1rem 0 .25rem; }
code, .mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.center { text-align: center; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.break { word-break: break-all; }
[hidden] { display: none !important; }

.topbar {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
    padding: .9rem 1.5rem; background: var(--panel); border-bottom: 1px solid var(--border);
}
.brand-wrap { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; min-width: 0; }
.brand { font-weight: 700; display: flex; align-items: center; gap: .5rem; }

.controls { display: flex; align-items: center; gap: .5rem; }
.lang-switch { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.lang-switch a {
    padding: .35rem .6rem; font-size: .8rem; font-weight: 600; text-decoration: none; color: var(--muted);
}
.lang-switch a + a { border-left: 1px solid var(--border); }
.lang-switch a:hover { color: var(--text); }
.lang-switch a.active { background: var(--accent); color: #fff; }
.theme-toggle {
    width: 36px; height: 36px; display: grid; place-items: center; padding: 0;
    border: 1px solid var(--border); border-radius: 8px; background: transparent; cursor: pointer;
    transition: border-color .15s;
}
.theme-toggle:hover { border-color: var(--accent); }
.theme-toggle svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.theme-toggle .icon-moon path { fill: currentColor; stroke: none; }
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }

/* Credit footer (always dark, both themes) */
.credit-strip {
    background: #09090b;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    padding: 1.5rem 0;
    display: flex;
    justify-content: center;
    position: relative;
    z-index: 20;
}
.credit-strip a {
    color: #e4e4e7; font-size: .8rem; font-weight: 600; letter-spacing: .2em;
    text-decoration: none; transition: color .15s;
}
.credit-strip a:hover { color: #fff; }
.logo-mark {
    width: 20px; height: 20px; border-radius: 5px;
    background: conic-gradient(var(--accent) 0 25%, transparent 0 50%, var(--accent) 0 75%, transparent 0);
    border: 2px solid var(--accent);
}
.row { display: flex; gap: .5rem; align-items: center; }

.layout {
    display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 1.5rem;
    max-width: 1100px; width: 100%; margin: 1.5rem auto; padding: 0 1rem; flex: 1 0 auto;
}
@media (max-width: 820px) { .layout { grid-template-columns: 1fr; } }

.panel {
    background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 1.5rem;
}
fieldset { border: 1px solid var(--border); border-radius: 10px; padding: .75rem 1rem 1rem; margin: 0 0 1rem; }
legend { font-weight: 600; padding: 0 .35rem; font-size: .9rem; }

.field { display: flex; flex-direction: column; gap: .3rem; margin-bottom: .75rem; font-size: .88rem; }
.field > span { color: var(--muted); }
.field.end { justify-content: flex-end; }
.check { display: flex; align-items: center; gap: .5rem; font-size: .88rem; }
.grid-2, .grid-3 { display: grid; gap: .75rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 480px) { .grid-3 { grid-template-columns: 1fr 1fr; } }

input, select, button { font: inherit; color: inherit; }
input[type=url], input[type=text], input[type=search], input[type=password], input[type=number], input:not([type]), select {
    width: 100%; padding: .55rem .7rem; border: 1px solid var(--border); border-radius: 8px;
    background: var(--bg);
}
input:focus-visible, select:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type=color] {
    width: 100%; height: 40px; padding: 2px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); cursor: pointer;
}
input[type=range] { width: 100%; accent-color: var(--accent); }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
    padding: .55rem 1rem; border-radius: 8px; border: 1px solid var(--border);
    background: var(--panel); cursor: pointer; text-decoration: none; color: var(--text);
    transition: background .15s, border-color .15s, transform .1s;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:active:not(:disabled) { transform: scale(.98); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }
.btn.wide { width: 100%; padding: .75rem; font-weight: 600; }
.small-btn { padding: .3rem .6rem; font-size: .8rem; }

.error {
    color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent);
    border-radius: 8px; padding: .5rem .75rem; font-size: .88rem; margin: 0 0 .75rem;
}

.preview { display: flex; flex-direction: column; align-items: center; gap: 1rem; align-self: start; position: sticky; top: 1rem; }
.qr-box {
    width: 100%; max-width: 380px; aspect-ratio: 1; border-radius: 10px;
    border: 1px dashed var(--border); display: grid; place-items: center; overflow: hidden;
}
.qr-box:empty::after { content: attr(data-empty); color: var(--muted); }
.qr-box svg, .qr-box canvas { width: 100%; height: auto; display: block; }
.qr-box.checker {
    background: repeating-conic-gradient(var(--checker) 0 25%, var(--panel) 0 50%) 0 0 / 16px 16px;
}
.small-box { max-width: 280px; flex-shrink: 0; }
.encoded { word-break: break-all; text-align: center; margin: 0; max-width: 100%; }
.encoded.stale { text-decoration: line-through; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; justify-content: center; }

/* ---- admin ---- */
.center-page { align-items: center; }
.center-page .credit-strip { align-self: stretch; }
.login-top { position: absolute; top: 1rem; right: 1rem; }
.login { width: calc(100% - 2rem); max-width: 360px; margin: auto 1rem; }
.admin { max-width: 1300px; width: 100%; margin: 1.5rem auto; padding: 0 1rem; flex: 1 0 auto; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
@media (max-width: 760px) { .stats { grid-template-columns: 1fr 1fr; } }
.stat {
    background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 1rem 1.25rem; display: flex; flex-direction: column; gap: .25rem; box-shadow: var(--shadow);
}
.stat .num { font-size: 1.75rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.devices { display: flex; flex-wrap: wrap; gap: .35rem; min-height: 2.6rem; align-items: center; }

.filters { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.filters input { flex: 1 1 260px; width: auto; }
.filters select { width: auto; }

.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { padding: .65rem .8rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--bg); }
tbody tr:hover { background: color-mix(in srgb, var(--accent) 5%, transparent); }
tbody tr:last-child td { border-bottom: 0; }
td.url { max-width: 360px; word-break: break-all; }
form.inline { display: inline; }

.tag { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .75rem; background: var(--bg); border: 1px solid var(--border); }
.tag-mobile { color: #059669; }
.tag-tablet { color: #d97706; }
.tag-desktop { color: var(--accent); }
.tag-bot { color: var(--danger); }

.pager { display: flex; justify-content: center; align-items: center; gap: 1rem; margin: 1rem 0; }

dialog {
    border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); color: var(--text);
    padding: 1.5rem; width: min(760px, calc(100vw - 2rem)); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0,0,0,.45); }
.dialog-body { display: flex; gap: 1.5rem; flex-wrap: wrap; }
.detail-info { flex: 1 1 280px; min-width: 0; }
.detail-info .encoded { text-align: left; }
pre { background: var(--bg); padding: .75rem; border-radius: 8px; overflow: auto; max-height: 220px; margin: 0; }
