/* ===========================================================
   Tokens. Light is the base; the dark block below overrides it.
   `data-theme` is set on <html> before first paint (see index.html)
   from localStorage, falling back to prefers-color-scheme.
   =========================================================== */
:root {
    color-scheme: light;

    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-2: #f1f3f7;
    --line: #e3e6ec;
    --line-strong: #cfd4de;

    --text: #10141c;
    --text-dim: #5c6779;

    --accent: #4a58ea;
    --accent-hover: #3a47d4;
    --accent-soft: rgba(74, 88, 234, 0.09);
    --on-accent: #ffffff;

    --ok: #0f9d58;
    --ok-soft: rgba(15, 157, 88, 0.1);
    --warn: #b45309;
    --err: #d92d20;
    --err-soft: rgba(217, 45, 32, 0.09);

    --chart-grid: rgba(16, 20, 28, 0.08);
    --chart-1: #4a58ea;
    --chart-2: #0f9d58;
    --chart-3: #d9791f;
    --chart-4: #8b5cf6;
    --chart-5: #0e9ab5;

    --shadow-sm: 0 1px 2px rgba(16, 20, 28, 0.06);
    --shadow-md: 0 6px 20px rgba(16, 20, 28, 0.08);
    --shadow-lg: 0 18px 45px rgba(16, 20, 28, 0.16);

    --r-sm: 6px;
    --r-md: 10px;
    --r-lg: 14px;
    --r-full: 999px;

    --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

:root[data-theme="dark"] {
    color-scheme: dark;

    --bg: #0b0e14;
    --surface: #141922;
    --surface-2: #1b212c;
    --line: #232a36;
    --line-strong: #333c4d;

    --text: #e7ebf2;
    --text-dim: #98a3b5;

    --accent: #6b84ff;
    --accent-hover: #849aff;
    --accent-soft: rgba(107, 132, 255, 0.14);
    --on-accent: #0b0e14;

    --ok: #34d399;
    --ok-soft: rgba(52, 211, 153, 0.12);
    --warn: #fbbf24;
    --err: #f87171;
    --err-soft: rgba(248, 113, 113, 0.12);

    --chart-grid: rgba(231, 235, 242, 0.08);
    --chart-1: #6b84ff;
    --chart-2: #34d399;
    --chart-3: #fbbf24;
    --chart-4: #c084fc;
    --chart-5: #38bdf8;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 18px 45px rgba(0, 0, 0, 0.55);
}

/* ============================= Base ============================= */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: var(--sans);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { line-height: 1.25; letter-spacing: -0.015em; }

a { color: inherit; }
.link { color: var(--accent); text-decoration: none; font-weight: 500; }
.link:hover { text-decoration: underline; }

.hidden { display: none !important; }
.muted { color: var(--text-dim); }
.num { text-align: right; font-variant-numeric: tabular-nums; }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

::selection { background: var(--accent-soft); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb {
    background: var(--line-strong);
    border: 3px solid var(--bg);
    border-radius: var(--r-full);
}

/* ============================ Topbar ============================ */
.topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.75rem clamp(1rem, 4vw, 2.5rem);
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    text-decoration: none;
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: -0.02em;
}
.brand-mark {
    width: 22px;
    height: 22px;
    border-radius: 6px;
    background: var(--accent);
    position: relative;
}
.brand-mark::after {
    content: '';
    position: absolute;
    inset: 6px 4px;
    border-radius: 2px;
    background: var(--surface);
}

.topbar-actions { display: flex; align-items: center; gap: 0.5rem; }
.nav-group { display: flex; align-items: center; gap: 0.5rem; }

.user-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.25rem 0.35rem 0.25rem 0.7rem;
    border: 1px solid var(--line);
    border-radius: var(--r-full);
    background: var(--surface-2);
    max-width: 42vw;
}
.user-email {
    font-size: 0.85rem;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.plan-badge {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    padding: 0.15rem 0.45rem;
    border-radius: var(--r-full);
    background: var(--line);
    color: var(--text-dim);
}
.plan-badge.premium { background: var(--accent); color: var(--on-accent); }

/* ============================ Buttons =========================== */
button { font: inherit; cursor: pointer; border: none; background: none; color: inherit; }

.btn-primary, .btn-secondary, .btn-ghost {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    position: relative;
    padding: 0.55rem 1rem;
    border-radius: var(--r-md);
    font-size: 0.9rem;
    font-weight: 600;
    border: 1px solid transparent;
    transition: background-color .15s, border-color .15s, color .15s;
}
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface-2); border-color: var(--line-strong); }
.btn-secondary:hover { background: var(--line); }
.btn-ghost { color: var(--text-dim); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-block { width: 100%; padding: 0.7rem 1rem; }
.btn-icon-only { padding: 0.5rem; border-radius: var(--r-md); }

button:disabled { cursor: not-allowed; opacity: 0.75; }
button:disabled .btn-text { visibility: hidden; }

.btn-loader {
    position: absolute;
    width: 16px;
    height: 16px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin .7s linear infinite;
}

/* Theme toggle shows the icon of the theme it switches TO. */
.icon-moon { display: none; }
:root[data-theme="dark"] .icon-sun { display: none; }
:root[data-theme="dark"] .icon-moon { display: block; }

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: var(--r-sm);
    color: var(--text-dim);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.danger:hover { background: var(--err-soft); color: var(--err); }
.icon-btn.locked { opacity: 0.45; }
.icon-btn.locked:hover { background: var(--accent-soft); color: var(--accent); opacity: 1; }

/* ============================= Layout ========================== */
.page {
    max-width: 1180px;
    margin: 0 auto;
    padding: clamp(1.25rem, 3vw, 2.25rem) clamp(1rem, 4vw, 2.5rem) 4rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.hero { padding: 1.5rem 0 0.5rem; max-width: 34rem; }
.hero h1 { font-size: clamp(1.8rem, 4.5vw, 2.5rem); }
.hero p { color: var(--text-dim); margin-top: 0.6rem; font-size: 1.02rem; }

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    padding: 1.25rem;
}
.card-title { font-size: 1rem; font-weight: 650; }
.card-sub { font-size: 0.83rem; color: var(--text-dim); }
.card-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.content-grid { display: grid; gap: 1.5rem; }
@media (min-width: 900px) {
    .content-grid { grid-template-columns: 340px minmax(0, 1fr); align-items: start; }
}
/* Visitors get the tool alone — no links card, so no second column. */
.page.anon .content-grid {
    grid-template-columns: minmax(0, 1fr);
    max-width: 34rem;
    margin: 0 auto;
}

.stats-row {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}
.stat-card { padding: 1rem 1.25rem; }
.stat-label {
    font-size: 0.76rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-dim);
}
.stat-value {
    font-size: 1.85rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
    margin-top: 0.2rem;
}

/* ============================== Forms ========================== */
.field { margin-bottom: 1rem; }
.field label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-dim);
    margin-bottom: 0.35rem;
}
.field-hint { font-size: 0.78rem; color: var(--text-dim); margin-top: 0.35rem; }

.input {
    width: 100%;
    background: var(--surface-2);
    border: 1px solid var(--line-strong);
    border-radius: var(--r-md);
    padding: 0.6rem 0.75rem;
    color: var(--text);
    font: inherit;
    font-size: 0.92rem;
    transition: border-color .15s, box-shadow .15s;
}
.input::placeholder { color: var(--text-dim); opacity: 0.75; }
.input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
.input:disabled { opacity: 0.6; cursor: not-allowed; }
.input-sm { padding: 0.4rem 0.6rem 0.4rem 1.9rem; font-size: 0.85rem; }

.input-group { display: flex; align-items: stretch; }
.input-prefix {
    display: inline-flex;
    align-items: center;
    padding: 0 0.6rem;
    font-size: 0.85rem;
    color: var(--text-dim);
    background: var(--line);
    border: 1px solid var(--line-strong);
    border-right: none;
    border-radius: var(--r-md) 0 0 var(--r-md);
    white-space: nowrap;
}
.input-group .input { border-radius: 0 var(--r-md) var(--r-md) 0; }

.pill {
    font-size: 0.65rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    padding: 0.1rem 0.4rem;
    border-radius: var(--r-full);
    background: var(--accent-soft);
    color: var(--accent);
}

.disclosure {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.83rem;
    font-weight: 600;
    color: var(--text-dim);
    padding: 0.2rem 0;
    margin-bottom: 0.75rem;
}
.disclosure:hover { color: var(--text); }
.chevron { transition: transform .2s; }
.disclosure[aria-expanded="true"] .chevron { transform: rotate(90deg); }
.disclosure-body { display: none; }
.disclosure-body.open { display: block; }

.search { position: relative; display: flex; align-items: center; }
.search svg {
    position: absolute;
    left: 0.6rem;
    color: var(--text-dim);
    pointer-events: none;
}

.result {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-top: 1rem;
    padding: 0.6rem 0.75rem;
    background: var(--accent-soft);
    border: 1px solid var(--accent);
    border-radius: var(--r-md);
    font-size: 0.9rem;
}
.result .code { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result-note { font-size: 0.78rem; color: var(--text-dim); white-space: nowrap; }

/* ============================== Table ========================== */
.table-wrap { position: relative; overflow-x: auto; min-height: 8rem; }
.table { width: 100%; border-collapse: collapse; }
.table th {
    text-align: left;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-dim);
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}
.table td {
    padding: 0.7rem 0.75rem;
    font-size: 0.88rem;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--surface-2); }

.cell-link { display: flex; align-items: center; gap: 0.35rem; }
.code {
    font-weight: 600;
    color: var(--accent);
    text-decoration: none;
    white-space: nowrap;
}
.code:hover { text-decoration: underline; }
.dest {
    display: block;
    max-width: 22rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-dim);
    text-decoration: none;
}
.dest:hover { color: var(--text); }
.row-actions { display: flex; gap: 0.15rem; justify-content: flex-end; }

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.15rem 0.5rem;
    border-radius: var(--r-full);
    font-size: 0.72rem;
    font-weight: 600;
    background: var(--surface-2);
    color: var(--text-dim);
    border: 1px solid var(--line);
}
.badge.expired { background: var(--err-soft); color: var(--err); border-color: transparent; }

.empty { padding: 2.5rem 1rem; text-align: center; color: var(--text-dim); font-size: 0.9rem; }

/* ====================== Loaders & spinners ===================== */
.loading-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: color-mix(in srgb, var(--surface) 70%, transparent);
    border-radius: var(--r-md);
    z-index: 5;
}
.spinner {
    width: 24px;
    height: 24px;
    border: 2px solid var(--line-strong);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================= Charts ========================== */
.charts-grid { display: grid; gap: 1rem; }
@media (min-width: 760px) {
    .charts-grid { grid-template-columns: 1fr 1fr; }
}
.chart {
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    padding: 0.9rem;
}
.chart h3 {
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-dim);
    margin-bottom: 0.75rem;
}
.chart-box { position: relative; width: 100%; height: 170px; }
.chart-box.tall { height: 210px; }

/* Free tier sees this instead of the charts — no blurred fake data behind a lock. */
.upsell {
    text-align: center;
    padding: 2rem 1rem;
    border: 1px dashed var(--line-strong);
    border-radius: var(--r-md);
    background: var(--surface-2);
}
.upsell-title { font-weight: 650; font-size: 1.02rem; }
.upsell-text {
    color: var(--text-dim);
    font-size: 0.88rem;
    max-width: 30rem;
    margin: 0.4rem auto 1rem;
}

/* ============================= Pricing ========================= */
.pricing { padding-top: 1.5rem; border-top: 1px solid var(--line); }
.pricing h2 { font-size: 1.25rem; margin-bottom: 1rem; }
.plan-grid { display: grid; gap: 1rem; }
@media (min-width: 720px) {
    .plan-grid { grid-template-columns: 1fr 1fr; max-width: 46rem; }
}
.plan { display: flex; flex-direction: column; gap: 0.6rem; }
.plan.featured { border-color: var(--accent); box-shadow: var(--shadow-sm); }
.plan h3 { font-size: 0.95rem; }
.plan-price { font-size: 1.7rem; font-weight: 700; letter-spacing: -0.02em; }
.plan-list { list-style: none; display: grid; gap: 0.4rem; margin-bottom: 0.4rem; }
.plan-list li {
    font-size: 0.88rem;
    color: var(--text-dim);
    padding-left: 1.2rem;
    position: relative;
}
.plan-list li::before {
    content: '';
    position: absolute;
    left: 0.15rem;
    top: 0.52em;
    width: 0.45rem;
    height: 0.25rem;
    border-left: 2px solid var(--accent);
    border-bottom: 2px solid var(--accent);
    transform: rotate(-45deg);
}
.plan-state { font-size: 0.82rem; color: var(--text-dim); }
.pricing-note { font-size: 0.83rem; color: var(--text-dim); margin-top: 1rem; }

/* ============================= Billing ========================= */
.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.87rem;
    font-weight: 600;
    color: var(--text-dim);
    align-self: flex-start;
}
.back-link:hover { color: var(--text); }
.billing-head h1 { font-size: clamp(1.5rem, 3.5vw, 2rem); }
.billing-head p { margin-top: 0.4rem; }
.billing-note {
    font-size: 0.83rem;
    color: var(--text-dim);
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    padding: 0.75rem 0.9rem;
    max-width: 46rem;
}

/* ============================= Modals ========================== */
.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: rgba(8, 11, 16, 0.55);
    opacity: 0;
    pointer-events: none;
    transition: opacity .18s;
}
.modal-backdrop.show { opacity: 1; pointer-events: auto; }
.modal {
    position: relative;
    width: 100%;
    max-width: 25rem;
    max-height: 90vh;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-lg);
    padding: 1.4rem;
    transform: translateY(6px);
    transition: transform .18s;
}
.modal-backdrop.show .modal { transform: translateY(0); }
.modal.wide { max-width: 46rem; }
.modal-title { font-size: 1.05rem; margin-bottom: 0.2rem; padding-right: 2rem; }
.modal-close {
    position: absolute;
    top: 0.7rem;
    right: 0.7rem;
    width: 28px;
    height: 28px;
    border-radius: var(--r-sm);
    font-size: 1.35rem;
    line-height: 1;
    color: var(--text-dim);
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }
.modal-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin: 0.5rem 0 1rem;
    font-size: 0.88rem;
}
.modal-body { position: relative; min-height: 6rem; display: grid; gap: 1rem; }
.modal-body > div { display: grid; gap: 1rem; }
.modal-foot { margin-top: 1rem; font-size: 0.85rem; color: var(--text-dim); text-align: center; }
.modal form { margin-top: 1rem; }

.qr-frame {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    max-width: 15rem;
    margin: 1rem auto;
    background: #ffffff;
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    padding: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
}
.qr-img { width: 100%; height: 100%; object-fit: contain; display: none; }
.qr-img.loaded { display: block; }

/* ============================= Toasts ========================== */
.toast-container {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}
.toast {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-width: 15rem;
    max-width: 22rem;
    padding: 0.7rem 0.9rem;
    font-size: 0.88rem;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--line);
    border-left: 3px solid var(--accent);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-md);
    animation: toast-in .2s ease-out;
}
.toast.success { border-left-color: var(--ok); }
.toast.success svg { color: var(--ok); }
.toast.warning { border-left-color: var(--warn); }
.toast.warning svg { color: var(--warn); }
.toast.error { border-left-color: var(--err); }
.toast.error svg { color: var(--err); }
.toast.hiding { animation: toast-out .2s ease-in forwards; }

@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }

@media (prefers-reduced-motion: reduce) {
    * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

@media (max-width: 640px) {
    .topbar { padding: 0.6rem 1rem; }
    .brand-name { display: none; }
    .dest { max-width: 9rem; }
    .table th, .table td { padding: 0.6rem 0.5rem; }
    .search { width: 100%; }
}
