:root {
    --bg: #0b0d12;
    --panel: #14171f;
    --panel-2: #1b1f29;
    --border: #252a36;
    --text: #e9ecf1;
    --text-dim: #9ba3b4;
    --accent: #ff3366;
    --accent-2: #ff5b87;
    --success: #29c46f;
    --warn: #f0b429;
    --danger: #ef4444;
    --radius: 12px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
}

[data-theme="light"] {
    --bg: #f5f6fa;
    --panel: #ffffff;
    --panel-2: #f0f2f7;
    --border: #e1e4ec;
    --text: #1a1d24;
    --text-dim: #5c6478;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-2); }

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
}

.center-card {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 28px;
}

.card.narrow { width: 100%; max-width: 420px; }

h1, h2, h3 { margin: 0 0 12px; font-weight: 700; letter-spacing: -0.01em; }
h1 { font-size: 28px; }
h2 { font-size: 22px; }
h3 { font-size: 17px; }

.muted { color: var(--text-dim); font-size: 14px; }

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.02em;
    margin-bottom: 18px;
}
.brand .dot {
    width: 12px; height: 12px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    box-shadow: 0 0 12px var(--accent);
}

label {
    display: block;
    font-size: 13px;
    color: var(--text-dim);
    margin-bottom: 6px;
    font-weight: 500;
}

input[type="text"], input[type="email"], input[type="password"], input[type="tel"], input[type="number"], input[type="datetime-local"], input[type="search"], textarea, select {
    width: 100%;
    padding: 11px 14px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 15px;
    font-family: inherit;
    transition: border-color 0.15s, background 0.15s;
}

input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--accent);
    background: var(--panel);
}

/* Override Chrome autofill so it doesn't paint dark text on dark bg in dark mode. */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:active,
textarea:-webkit-autofill,
select:-webkit-autofill {
    -webkit-text-fill-color: var(--text) !important;
    -webkit-box-shadow: 0 0 0 1000px var(--panel-2) inset !important;
    caret-color: var(--text);
    transition: background-color 5000s ease-in-out 0s;
}
input:-webkit-autofill:focus,
textarea:-webkit-autofill:focus,
select:-webkit-autofill:focus {
    -webkit-box-shadow: 0 0 0 1000px var(--panel) inset !important;
}

textarea { resize: vertical; min-height: 80px; }

.field { margin-bottom: 16px; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 11px 18px;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: transform 0.05s, opacity 0.15s;
    font-family: inherit;
}
.btn:hover { color: white; opacity: 0.95; }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn.full { width: 100%; }

.btn.ghost {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
}
.btn.ghost:hover { background: var(--panel-2); color: var(--text); }

.btn.danger {
    background: var(--danger);
}

.btn.small { padding: 6px 12px; font-size: 13px; }

.row { display: flex; gap: 12px; align-items: center; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }

.stack { display: flex; flex-direction: column; gap: 10px; }

.alert {
    padding: 11px 14px;
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 14px;
    border: 1px solid;
}
.alert.error { background: rgba(239, 68, 68, 0.12); border-color: rgba(239, 68, 68, 0.4); color: #ffb4b4; }
.alert.success { background: rgba(41, 196, 111, 0.12); border-color: rgba(41, 196, 111, 0.4); color: #8be3b6; }
.alert.warn { background: rgba(240, 180, 41, 0.12); border-color: rgba(240, 180, 41, 0.4); color: #ffd97a; }
.alert.info { background: rgba(99, 130, 255, 0.12); border-color: rgba(99, 130, 255, 0.4); color: #b9c6ff; }

.hidden { display: none !important; }

/* Dashboard layout */
.layout { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
    background: var(--panel);
    border-right: 1px solid var(--border);
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    /* Keep the nav reachable on long pages: the sidebar pins to the
       viewport and scrolls its own content if it overflows. */
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}
.sidebar .nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: 8px;
    color: var(--text-dim);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.sidebar .nav-link svg { width: 16px; height: 16px; flex: none; opacity: 0.75; }
.sidebar .nav-link:hover { background: var(--panel-2); color: var(--text); }
.sidebar .nav-link:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
/* Active ≠ hover : ember-tinted background + brighter text + accent icon,
   on top of the existing 3px accent bar. */
.sidebar .nav-link.active {
    background: rgba(255, 51, 102, 0.12);
    color: var(--text);
    font-weight: 600;
}
.sidebar .nav-link.active svg { opacity: 1; color: var(--accent); }
.sidebar .nav-link.active::before {
    content: ""; width: 3px; height: 16px; flex: none;
    background: var(--accent); border-radius: 2px; margin-right: 4px; margin-left: -7px;
}
.sidebar .nav-section { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-dim); margin: 14px 12px 4px; font-weight: 600; }
.sidebar .footer { margin-top: auto; padding-top: 16px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.sidebar .footer .footer-id { font-size: 12px; padding: 0 12px; margin-bottom: 4px; }
.sidebar .footer .footer-id strong { color: var(--text); }
.sidebar .footer .footer-btn { width: 100%; justify-content: flex-start; }
.sidebar .footer .footer-btn svg { width: 15px; height: 15px; flex: none; }

/* `.main` no longer scrolls horizontally — only `.table-wrap` does.
   Two nested horizontal scroll containers fight each other on iOS
   (the wrong one captures the gesture about half the time). */
.main { padding: 32px; min-width: 0; }

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 24px;
    gap: 16px;
    flex-wrap: wrap;
}

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px;
}
.stat-card .label { font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 6px; }
.stat-card .value { font-size: 26px; font-weight: 700; }

/* Coins-by-reason breakdown table — used on the user-profile Coins tab
   so the operator can see at a glance "X earned from referrals" instead
   of having to scan the raw transaction list. */
.coin-breakdown { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-bottom: 24px; }
.coin-breakdown-row { display: grid; grid-template-columns: 1fr 110px 110px 70px; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--border); align-items: center; font-size: 13px; }
.coin-breakdown-row:last-child { border-bottom: none; }
.coin-breakdown-row.coin-breakdown-head { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; background: var(--panel-2); }
.coin-breakdown-row .bd-name { color: var(--text); }
.coin-breakdown-row .bd-in   { font-weight: 600; color: #8be3b6; text-align: right; font-variant-numeric: tabular-nums; }
.coin-breakdown-row .bd-out  { font-weight: 600; color: #ffb4b4; text-align: right; font-variant-numeric: tabular-nums; }
.coin-breakdown-row .bd-count { color: var(--text-dim); text-align: right; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
table th, table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
table th { color: var(--text-dim); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; cursor: pointer; user-select: none; }
table tbody tr:hover { background: var(--panel-2); }
table .actions { display: flex; gap: 6px; flex-wrap: wrap; }

.table-wrap {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    /* Was `overflow: hidden`, which clipped wide tables on small
       screens — the user couldn't reach the right-most columns at
       all on mobile. Letting the wrapper scroll horizontally is the
       responsive default; vertical stays clipped so tall tables
       don't expand the card outline. `-webkit-overflow-scrolling`
       gives iOS the inertial flick. */
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
}
/* Force a sensible minimum table width so columns don't squish into
   illegibility before the wrapper kicks in horizontal scroll. Pages
   with very dense tables (users, drops) still fit comfortably on a
   12" tablet without scroll, but a 390pt phone gets a clean swipe. */
.table-wrap table { min-width: 640px; }

.toolbar {
    display: flex;
    gap: 10px;
    margin-bottom: 14px;
    flex-wrap: wrap;
    align-items: center;
}
.toolbar input[type="search"] { width: 280px; }

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    background: var(--panel-2);
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.badge.super { background: rgba(255, 51, 102, 0.18); color: #ff89a8; }
.badge.admin { background: rgba(99, 130, 255, 0.18); color: #b9c6ff; }
.badge.success { background: rgba(41, 196, 111, 0.18); color: #8be3b6; }
.badge.warn { background: rgba(240, 180, 41, 0.18); color: #ffd97a; }
.badge.danger { background: rgba(239, 68, 68, 0.18); color: #ffb4b4; }

.empty {
    padding: 40px;
    text-align: center;
    color: var(--text-dim);
}

.spinner {
    display: inline-block;
    width: 18px; height: 18px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.modal-backdrop {
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex; align-items: center; justify-content: center;
    z-index: 100;
    padding: 20px;
}
.modal {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    width: 100%; max-width: 520px;
    max-height: 90vh; overflow-y: auto;
    padding: 24px;
    box-shadow: var(--shadow);
}
.modal-large { max-width: 880px; }

/* Lang tabs (changelog editor) */
.lang-tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 12px; }
.lang-tab {
    padding: 6px 12px;
    border-radius: 6px;
    background: var(--panel-2);
    border: 1px solid var(--border);
    font-size: 13px;
    cursor: pointer;
}
.lang-tab.active { background: var(--accent); border-color: var(--accent); color: white; }
.lang-tab.filled::after { content: "•"; color: var(--success); margin-left: 4px; }
.lang-pane { display: none; }
.lang-pane.active { display: block; }

@media (max-width: 720px) {
    .layout { grid-template-columns: 1fr; }
    .sidebar {
        position: sticky; top: 0; z-index: 10;
        flex-direction: row; overflow-x: auto;
        padding: 12px;
        /* Cancel the desktop pinned-column sizing — the mobile sidebar is a
           horizontally scrollable row. */
        height: auto; overflow-y: hidden;
        border-right: none; border-bottom: 1px solid var(--border);
        -webkit-overflow-scrolling: touch;
    }
    .sidebar .nav-section { display: none; }
    .sidebar .nav-link { white-space: nowrap; }
    /* Footer stays reachable on mobile (it used to be display:none, which
       hid theme AND logout entirely): theme + logout collapse to icon-only
       buttons at the end of the row; the email/role block stays desktop-only. */
    .sidebar .footer {
        flex-direction: row; align-items: center; gap: 6px;
        margin: 0 0 0 auto; padding: 0 0 0 8px;
        border-top: none; border-left: 1px solid var(--border);
        flex: none;
    }
    .sidebar .footer .footer-id { display: none; }
    .sidebar .footer .footer-btn { width: auto; padding: 8px; }
    .sidebar .footer .footer-btn .footer-btn-label { display: none; }
    .main {
        padding: 16px;
        /* The outer .main no longer scrolls — only `.table-wrap`
           does. Otherwise the page stutters between two competing
           horizontal scroll containers on iOS. */
        overflow-x: visible;
    }

    /* Page header stacks vertically so the right-side action button
       (e.g. "New", "Refresh") doesn't get cropped on the right edge. */
    .page-header { flex-direction: column; align-items: stretch; }
    .page-header > div:last-child { display: flex; gap: 8px; flex-wrap: wrap; }

    /* Toolbar (search + filters): fill the row, drop the fixed 280px
       width on the search input so the user can actually see what
       they're typing. */
    .toolbar input[type="search"],
    .toolbar input[type="text"],
    .toolbar select { width: 100%; max-width: 100%; }
    .toolbar { gap: 8px; }

    /* Compact tables — slightly smaller padding + font so a row stays
       readable inside a phone-width scroll wrapper. */
    table { font-size: 13px; }
    table th, table td { padding: 8px 10px; }

    /* Stat grid: phones get 2 columns max so each card stays legible
       without forcing the value to truncate. */
    .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .stat-card { padding: 12px; }
    .stat-card .value { font-size: 20px; }

    /* Modals: hug the screen on mobile, smaller backdrop padding so
       the modal isn't forced through a tiny porthole. */
    .modal-backdrop { padding: 8px; }
    .modal,
    .modal-large {
        max-width: 100%;
        max-height: 95vh;
        padding: 18px;
    }

    /* Cards too — full-width with tighter padding. The default 28px
       eats nearly half a phone screen on either side. */
    .card { padding: 18px; }
}

/* Very narrow phones (≤ 380pt — older iPhone SE, some Android compacts).
   One stat card per row keeps the value readable. */
@media (max-width: 380px) {
    .stat-grid { grid-template-columns: 1fr; }
}
