/* iCalorie Admin Dashboard — Linear/Vercel-style dark UI */
:root {
    /* Legacy aliases for sub-pages */
    --bg-primary: #0f1117;
    --bg-secondary: #1a1d27;
    --bg-tertiary: #252840;
    --accent-primary: #7c6af7;
    --success: #22c55e;
    --warning: #f59e0b;
    --error: #ef4444;
    --info: #3b82f6;
    --border-light: #323649;

    --bg-base: #0f1117;
    --bg-surface: #1a1d27;
    --bg-card: #1e2130;
    --bg-hover: #252840;
    --border: #323649;
    --text-primary: #e2e8f0;
    --text-secondary: #8892a4;
    --text-muted: #4a5568;
    --accent-purple: #7c6af7;
    --accent-green: #22c55e;
    --accent-orange: #f59e0b;
    --accent-red: #ef4444;
    --accent-blue: #3b82f6;
    --sidebar-width: 220px;
    --topbar-height: 48px;
    --radius-card: 20px;
    --radius-btn: 8px;
    --card-gap: 16px;

    /* Elevation + motion tokens (additive — used by refreshed card/nav treatments) */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.24), 0 1px 1px rgba(0, 0, 0, 0.12);
    --shadow-md: 0 8px 20px rgba(0, 0, 0, 0.28), 0 2px 6px rgba(0, 0, 0, 0.16);
    --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.38), 0 4px 10px rgba(0, 0, 0, 0.2);
    --shadow-glow-purple: 0 0 0 1px rgba(124, 106, 247, 0.16), 0 10px 28px rgba(124, 106, 247, 0.14);
    --ease-smooth: cubic-bezier(0.16, 1, 0.3, 1);
}

/* Keyframes for entrance/attention animations (opt-in via utility classes below) */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(14px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes scaleIn {
    from { opacity: 0; transform: scale(0.96); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes livePulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.45; }
}

@keyframes countUpGlow {
    0% { text-shadow: 0 0 0 rgba(124, 106, 247, 0); }
    40% { text-shadow: 0 0 18px rgba(124, 106, 247, 0.35); }
    100% { text-shadow: 0 0 0 rgba(124, 106, 247, 0); }
}

.animate-in {
    animation: fadeInUp 0.55s var(--ease-smooth) both;
}

.animate-in-scale {
    animation: scaleIn 0.45s var(--ease-smooth) both;
}

.live-pulse {
    animation: livePulse 2.2s ease-in-out infinite;
}

.count-glow {
    animation: countUpGlow 0.9s ease-out;
}

@media (prefers-reduced-motion: reduce) {
    .animate-in, .animate-in-scale, .live-pulse, .count-glow {
        animation: none !important;
        opacity: 1 !important;
        transform: none !important;
        text-shadow: none !important;
    }
}

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

body {
    font-family: 'Mitr', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-base);
    color: var(--text-primary);
    line-height: 1.5;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }

.app-layout { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    position: fixed;
    left: 0; top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    z-index: 100;
    overflow-y: auto;
}

.sidebar-logo {
    padding: 20px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-logo-img {
    display: block;
    height: 44px;
    width: auto;
    max-width: 100%;
    object-fit: contain;
}

.sidebar-logo h1 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.sidebar-nav { flex: 1; padding: 12px 8px; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    margin-bottom: 2px;
    border-radius: var(--radius-btn);
    border-left: 2px solid transparent;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.nav-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.nav-item.active {
    background: rgba(124, 106, 247, 0.12);
    border-left-color: var(--accent-purple);
    color: var(--text-primary);
    box-shadow: inset 0 0 0 1px rgba(124, 106, 247, 0.08);
}

.nav-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.nav-icon svg { width: 18px; height: 18px; stroke: currentColor; }

.sidebar-footer {
    padding: 12px 8px;
    border-top: 1px solid var(--border);
}

/* Main */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-width: 0;
    min-height: 100vh;
    background: var(--bg-base);
}

.topbar {
    min-height: var(--topbar-height);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow-sm);
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
    flex: 1;
}

.topbar-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-shrink: 0;
}

.badge-admin {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-secondary);
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-btn);
    background: var(--bg-card);
}

.btn-logout {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-btn);
    background: var(--bg-card);
    transition: background 0.15s, color 0.15s;
}

.btn-logout:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.topbar-menu-btn {
    display: none;
    width: 40px;
    height: 40px;
    min-width: 40px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-primary);
    border-radius: var(--radius-btn);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.content-area {
    padding: 24px;
    max-width: 1600px;
    width: 100%;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.35s var(--ease-smooth), transform 0.35s var(--ease-smooth);
}

.content-area.page-enter { opacity: 1; transform: translateY(0); }

/* Cards */
.card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    padding: 24px;
    margin-bottom: var(--card-gap);
    box-shadow: var(--shadow-sm);
    transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
    gap: 12px;
    flex-wrap: wrap;
}

.card-title {
    font-size: 14.5px;
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--text-primary);
}

/* Metrics grid 2x4 */
/* Outer "surface" container that nests stat cards, matching the reference
   design: a darker rounded panel holding subtly-bordered inner cards. Used
   around .grid-metrics-2x4 (dashboard) and .stats-grid (every other page). */
.metrics-surface {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    padding: 24px;
    margin-bottom: var(--card-gap);
}
.metrics-surface .grid-metrics-2x4,
.metrics-surface .stats-grid {
    margin-bottom: 0;
}

.grid-metrics-2x4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--card-gap);
    margin-bottom: 24px;
}

.metric-card, .stat-card {
    background: rgba(255, 255, 255, 0.025);
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 14px;
    padding: 20px;
    transition: background 0.15s, transform 0.2s var(--ease-smooth), border-color 0.2s ease;
}

.metric-card.clickable, .stat-card.clickable { cursor: pointer; }
.metric-card.clickable:hover, .stat-card.clickable:hover {
    background: rgba(255, 255, 255, 0.05);
    transform: translateY(-2px);
    border-color: rgba(255, 255, 255, 0.14);
}

.metric-label, .stat-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.07em;
    margin-bottom: 10px;
}

.metric-value, .stat-value {
    font-size: 32px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text-primary);
    line-height: 1.15;
}

.metric-sub, .stat-change {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12.5px;
    color: var(--text-secondary);
    margin-top: 10px;
}
.metric-sub::before, .stat-change::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
    flex-shrink: 0;
}

.delta-positive { color: var(--accent-green); }
.delta-positive::before { background: var(--accent-green); }
.delta-negative { color: var(--accent-red); }
.delta-negative::before { background: var(--accent-red); }
.metric-sub-live::before { animation: livePulse 1.8s ease-in-out infinite; }

/* Decorative progress bar under each stat card -- purely visual texture,
   not tied to a specific numeric target (most of these metrics, like
   Total Users or Revenue, have no natural "100%" to measure against). */
.metric-bar, .stat-bar {
    margin-top: 14px;
    height: 3px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.08);
    overflow: hidden;
}
.metric-bar-fill, .stat-bar-fill {
    display: block;
    height: 100%;
    width: 58%;
    transition: width 1s var(--ease-smooth);
    background: rgba(255, 255, 255, 0.85);
    border-radius: 2px;
}

.link-orange {
    color: var(--accent-orange);
    font-weight: 500;
}

.link-orange:hover { text-decoration: underline; }

/* Voice stats row */
.voice-stats-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
}

.voice-stat {
    text-align: center;
    padding: 16px 12px;
    background: rgba(255, 255, 255, 0.025);
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 14px;
    transition: background 0.15s, border-color 0.2s ease;
}
.voice-stat:hover { background: rgba(255, 255, 255, 0.045); border-color: rgba(255, 255, 255, 0.12); }

.voice-stat-value {
    font-size: 24px;
    font-weight: 600;
    color: var(--accent-purple);
}

.voice-stat-label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* Two-column */
.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 20px;
}

/* Feed rows */
.feed-list { display: flex; flex-direction: column; }

.feed-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
    flex-wrap: wrap;
}

.feed-row-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
    flex-shrink: 0;
}

.feed-row:last-child { border-bottom: none; }
.feed-row.clickable { cursor: pointer; }
.feed-row.clickable:hover { background: var(--bg-hover); margin: 0 -8px; padding: 10px 8px; border-radius: var(--radius-btn); }

.avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    color: #fff;
    flex-shrink: 0;
}

.feed-body { flex: 1; min-width: 0; font-size: 13px; }
.feed-name { color: var(--text-primary); font-weight: 500; }
.feed-muted { color: var(--text-muted); }
.feed-food { color: var(--text-primary); }

.kcal-badge {
    font-size: 11px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: var(--radius-btn);
}

.kcal-low { background: rgba(34, 197, 94, 0.15); color: var(--accent-green); }
.kcal-mid { background: rgba(245, 158, 11, 0.15); color: var(--accent-orange); }
.kcal-high { background: rgba(239, 68, 68, 0.15); color: var(--accent-red); }

.feed-time {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
}

.count-badge {
    font-size: 12px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: var(--radius-btn);
    background: rgba(124, 106, 247, 0.15);
    color: var(--accent-purple);
}

.flag-prefix { margin-right: 6px; }

/* Notification stats */
.notif-stats-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
}

.notif-stat {
    text-align: center;
    padding: 16px 12px;
    background: rgba(255, 255, 255, 0.025);
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 14px;
    transition: background 0.15s, border-color 0.2s ease;
}
.notif-stat-value { font-size: 28px; font-weight: 600; }
.notif-stat-label { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }
.notif-stat.clickable { cursor: pointer; }
.notif-stat.clickable:hover { background: rgba(255, 255, 255, 0.045); border-color: rgba(255, 255, 255, 0.12); }

/* Generic "mini stat box" for label:value grids inside a .card (user_detail
   streaks/profile fields, and similar spots elsewhere) -- same subtle
   nested-card treatment as .metric-card/.voice-stat for full consistency. */
.mini-stat-box {
    text-align: center;
    padding: 16px 12px;
    background: rgba(255, 255, 255, 0.025);
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 14px;
    transition: background 0.15s, border-color 0.2s ease;
}
.mini-stat-box:hover { background: rgba(255, 255, 255, 0.045); border-color: rgba(255, 255, 255, 0.12); }
.mini-stat-box-value { font-size: 22px; font-weight: 700; }
.mini-stat-box-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* Top foods */
.food-rank-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 8px;
    margin: 0 -8px;
    border-radius: 8px;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s ease, transform 0.15s var(--ease-smooth);
}
.food-rank-row:hover { background: rgba(255, 255, 255, 0.03); transform: translateX(2px); }

.food-rank-row:last-child { border-bottom: none; }
.food-rank-num { font-size: 12px; color: var(--text-muted); width: 24px; font-weight: 600; }
.food-rank-name { flex: 1; font-size: 13px; color: var(--text-primary); }
.food-rank-count { font-size: 13px; font-weight: 600; color: var(--accent-purple); margin-right: 8px; }
.food-sparkline { width: 80px; height: 28px; }

.lang-chart-wrap { height: 160px; }
.chart-wrap { height: 240px; position: relative; }

/* Segmented control */
.segmented {
    display: flex;
    gap: 4px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-btn);
    padding: 3px;
}

.segmented button {
    font-size: 12px;
    font-weight: 500;
    padding: 5px 12px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.segmented button.active {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.segmented button:hover:not(.active) { color: var(--text-primary); }

/* Table */
.table-container {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    overflow: hidden;
    margin-bottom: var(--card-gap);
}

@media (max-width: 768px) {
    .table-container:not(:has(.table-scroll)):not(:has(.table-responsive-cards)) {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .table-container:not(:has(.table-scroll)):not(:has(.table-responsive-cards)) table {
        min-width: 560px;
    }
}

.table-container .card-title { padding: 20px 20px 0; }

.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
}

.table-scroll table { min-width: 560px; }

/* Responsive-cards tables: below 767px, rows become stacked label:value
   cards instead of scrolling horizontally. Add class="table-responsive-cards"
   plus data-label="Column Name" on every <td> to opt a table in. Pure CSS —
   the underlying <table>/<tr>/<td> DOM is untouched, so row-click navigation
   (admin-tables.js initClickableRows) and column-index-based sorting
   (dashboard-forms.js initTableSort) both keep working unmodified. */
@media (max-width: 767px) {
    table.table-responsive-cards { min-width: 0; }
    table.table-responsive-cards thead { display: none; }
    table.table-responsive-cards,
    table.table-responsive-cards tbody,
    table.table-responsive-cards tr,
    table.table-responsive-cards td {
        display: block;
        width: 100%;
    }
    table.table-responsive-cards tbody tr {
        margin: 12px;
        border: 1px solid var(--border);
        border-radius: var(--radius-card);
        padding: 4px 14px;
    }
    table.table-responsive-cards tbody tr:first-child { margin-top: 12px; }
    table.table-responsive-cards td {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        gap: 16px;
        padding: 9px 0;
        border-bottom: 1px solid var(--border);
        text-align: right;
    }
    table.table-responsive-cards tr td:last-child { border-bottom: none; }
    table.table-responsive-cards td::before {
        content: attr(data-label);
        font-size: 11px;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        color: var(--text-secondary);
        text-align: left;
        flex-shrink: 0;
    }
    table.table-responsive-cards td[data-label=""]::before,
    table.table-responsive-cards td:not([data-label])::before { content: none; }

    /* Rich cells (name + username + badge + id + last-active, etc.) don't
       fit the label:value side-by-side layout above -- stack the label
       above the content instead so multi-line content has room to breathe. */
    table.table-responsive-cards td.cell-stack {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }
    table.table-responsive-cards td.cell-stack > * { text-align: left; }
}

table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead { background: var(--bg-surface); }
th {
    text-align: left;
    padding: 12px 16px;
    font-size: 11px;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border);
}
td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    color: var(--text-primary);
}
tbody tr { transition: background 0.15s; }
tbody tr:hover { background: var(--bg-hover); }
tbody tr.clickable { cursor: pointer; }

.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.03em;
    white-space: nowrap;
}
.badge-uz { background: rgba(124,106,247,0.15); color: var(--accent-purple); border: 1px solid rgba(124,106,247,0.25); }
.badge-ru { background: rgba(59,130,246,0.15); color: var(--accent-blue); border: 1px solid rgba(59,130,246,0.25); }
.badge-en { background: rgba(34,197,94,0.15); color: var(--accent-green); border: 1px solid rgba(34,197,94,0.25); }
.badge-green  { background: #14532d33; color: #4ade80; border: 1px solid #16a34a44; }
.badge-orange { background: #78350f33; color: #fb923c; border: 1px solid #c2410c44; }
.badge-purple { background: #3b0764aa; color: #a78bfa; border: 1px solid #7c3aed44; }
.badge-red    { background: #450a0a33; color: #f87171; border: 1px solid #b91c1c44; }
.badge-gray   { background: #1e293b;   color: #94a3b8; border: 1px solid #334155; }

/* Admin table helpers */
tbody tr.clickable-row { cursor: pointer; }
.cell-name-bold {
    font-weight: 600;
    font-size: 14px;
}
.cell-username-muted { color: #8892a4; font-size: 13px; }
.col-requests-accent { color: var(--accent-purple); font-weight: 600; }
.cell-name-stack { line-height: 1.3; }
.cell-name-stack .cell-id { font-size: 11px; color: #4a5568; }
.cell-date-compact { width: 90px; font-size: 12px; white-space: nowrap; }
.days-green { color: #4ade80; font-weight: 600; }
.days-orange { color: #fb923c; font-weight: 600; }
.days-red { color: #f87171; font-weight: 600; }
.stacked-dates { font-size: 12px; line-height: 1.4; }
.stacked-dates .date-label { color: var(--text-muted); font-size: 10px; }

.btn-primary {
    background: #7c6af7;
    color: #fff;
    border: 1px solid #7c6af7;
    transition: background 0.15s, transform 0.15s var(--ease-smooth), box-shadow 0.15s ease;
}
.btn-primary:hover { background: #6b5ae6; transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn-primary:active { transform: translateY(0); }
.btn-secondary {
    background: #1e2130;
    color: #8892a4;
    border: 1px solid #2a2d3e;
}
.btn-secondary:hover { background: #252840; color: var(--text-primary); }
.btn-ghost-sm {
    font-size: 12px;
    color: #7c6af7;
    border: 1px solid #7c6af740;
    padding: 3px 10px;
    border-radius: 6px;
    text-decoration: none;
    display: inline-block;
    white-space: nowrap;
}
.btn-ghost-sm:hover { background: #7c6af715; }
.btn-confirm {
    background: #14532d33;
    color: #4ade80;
    border: 1px solid #16a34a44;
    padding: 3px 10px;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
}
.btn-confirm:hover { background: #14532d55; }
.btn-cancel {
    background: #450a0a33;
    color: #f87171;
    border: 1px solid #b91c1c44;
    padding: 3px 10px;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    margin-left: 4px;
}
.btn-cancel:hover { background: #450a0a55; }

.filter-tabs {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 24px;
}
.filter-tab {
    flex: 1 1 0;
    min-width: 120px;
    text-align: center;
    text-decoration: none;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    background: #1e2130;
    color: #8892a4;
    border: 1px solid #2a2d3e;
    transition: background 0.15s, color 0.15s;
}
.filter-tab:hover { color: var(--text-primary); }
.filter-tab.active {
    background: #7c6af7;
    color: #fff;
    border-color: #7c6af7;
}

.filter-pills {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border);
    padding-bottom: 0;
}
.filter-pill {
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 500;
    color: #8892a4;
    text-decoration: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.filter-pill:hover { color: var(--text-primary); }
.filter-pill.active {
    color: #a78bfa;
    font-weight: 600;
    border-bottom-color: #7c6af7;
    background: #7c6af720;
    border-radius: 8px 8px 0 0;
}

.pending-invoices-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}
.pending-scroll-hint {
    font-size: 11px;
    color: #4a5568;
}
.pending-invoices-scroll {
    max-height: 380px;
    overflow-y: auto;
    overflow-x: auto;
}
.pending-invoices-scroll::-webkit-scrollbar { width: 4px; }
.pending-invoices-scroll::-webkit-scrollbar-track { background: transparent; }
.pending-invoices-scroll::-webkit-scrollbar-thumb { background: #2a2d3e; border-radius: 4px; }

.pending-table { width: 100%; font-size: 12px; }
.pending-table th {
    font-size: 10px;
    padding: 8px 12px;
}
.pending-table td {
    padding: 8px 12px;
    vertical-align: middle;
}
.pending-table-head {
    position: sticky;
    top: 0;
    background: #1e2130;
    z-index: 1;
}
.pending-table-head th {
    background: #1e2130;
}
.pending-amount {
    font-size: 12px;
    white-space: nowrap;
}
.pending-actions { white-space: nowrap; }

.premium-search-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    align-items: center;
}
.premium-search-bar input[type="text"] {
    flex: 1;
    min-width: 0;
    width: 100%;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 10px 12px;
    border-radius: 6px;
    font-size: 14px;
}
.premium-search-bar input[type="text"]:focus {
    outline: none;
    border-color: var(--accent-purple);
}
.premium-users-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
#premiumUserTable {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    min-width: 0;
}
/* Column widths are set per-cell via .col-* classes (see premium.html) rather
   than nth-child position, so they don't silently break if columns are
   reordered or the count changes between the 'all' and 'non_premium' views. */
.col-name { width: 26%; }
.col-requests { width: 90px; }
.premium-cell-name-text {
    font-weight: 600;
    font-size: 13px;
}
.premium-cell-sub {
    font-size: 11px;
    color: #4a5568;
}
.premium-cell-dates {
    padding: 10px 12px;
    white-space: nowrap;
    font-size: 12px;
}
.premium-dates-since {
    color: #8892a4;
}
.premium-cell-actions {
    padding: 8px 10px;
    white-space: nowrap;
}

.stat-value-purple { color: #a78bfa; }
.stat-value-red { color: #f87171; }
.stat-value-gray { color: #8892a4; }
.stat-value-orange { color: #fb923c; }


/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.modal-overlay.open { display: flex; }

.modal {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-card);
    width: 100%;
    max-width: 720px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-title { font-size: 14px; font-weight: 600; }

.modal-close {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-secondary);
    width: 32px; height: 32px;
    border-radius: var(--radius-btn);
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
}

.modal-close:hover { background: var(--bg-hover); color: var(--text-primary); }

.modal-body { padding: 16px 20px; overflow-y: auto; flex: 1; }

.reason-badge {
    font-size: 11px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: var(--radius-btn);
}
.reason-bot_blocked { background: rgba(239,68,68,0.15); color: var(--accent-red); }
.reason-deleted { background: rgba(74,85,104,0.3); color: var(--text-secondary); }
.reason-timeout { background: rgba(245,158,11,0.15); color: var(--accent-orange); }
.reason-other { background: rgba(74,85,104,0.2); color: var(--text-muted); }

/* Flash messages */
.flash-messages { margin-bottom: 16px; }
.flash-message {
    padding: 12px 16px;
    border-radius: var(--radius-btn);
    font-size: 13px;
    margin-bottom: 8px;
    border: 1px solid var(--border);
}
.flash-success { background: rgba(34,197,94,0.1); color: var(--accent-green); }
.flash-error { background: rgba(239,68,68,0.1); color: var(--accent-red); }
.flash-info { background: rgba(59,130,246,0.1); color: var(--accent-blue); }

.empty-state {
    text-align: center;
    padding: 32px;
    color: var(--text-muted);
    font-size: 13px;
}

/* Legacy compat for sub-pages */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.grid-4 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 16px;
}

.premium-income-card {
    margin-bottom: 20px;
}

.premium-income-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px 16px;
    margin-bottom: 16px;
}

.premium-income-filters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 14px;
}

.premium-income-presets {
    margin: 0;
}

.premium-income-custom {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 8px;
}

.premium-income-date-label {
    font-size: 12px;
    color: var(--text-secondary);
}

.premium-income-date-input {
    padding: 6px 8px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-btn);
    color: var(--text-primary);
    font-size: 12px;
}

.premium-income-value {
    font-size: 28px;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.2;
}

.premium-income-meta {
    margin-top: 8px;
    font-size: 12px;
    color: var(--text-secondary);
}


.btn {
    padding: 8px 14px;
    border-radius: var(--radius-btn);
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 13px;
    cursor: pointer;
    transition: background 0.15s, transform 0.15s var(--ease-smooth), box-shadow 0.15s ease;
}
.btn:hover { background: var(--bg-hover); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn:active { transform: translateY(0); }

/* Sub-page helpers */
.search-box {
    flex-wrap: wrap;
}

body.sidebar-open {
    overflow: hidden;
}

/* Mobile overlay + FAB */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    z-index: 90;
}
.sidebar-overlay.active { display: block; }

.mobile-menu-toggle {
    display: none;
}

#langLegend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 12px;
    font-size: 11px;
    color: var(--text-secondary);
}

/* ── Responsive breakpoints ── */

/* Large tablet / small laptop */
@media (max-width: 1280px) {
    .grid-metrics-2x4 { grid-template-columns: repeat(4, 1fr); }
}

@media (max-width: 1200px) {
    .grid-metrics-2x4 { grid-template-columns: repeat(2, 1fr); }
    .voice-stats-row,
    .notif-stats-row { grid-template-columns: repeat(2, 1fr); }
}

/* Tablet: icon-only sidebar */
@media (min-width: 768px) and (max-width: 1024px) {
    :root { --sidebar-width: 40px; }
    .sidebar-logo h1 { display: none; }
    .sidebar-logo-img { height: 32px; }
    .sidebar-logo { padding: 16px 8px; justify-content: center; }
    .nav-item {
        justify-content: center;
        padding: 10px 8px;
    }
    .nav-item > span:not(.nav-icon) { display: none; }
    .sidebar-nav { padding: 12px 4px; }
    .main-content { margin-left: var(--sidebar-width); }
}

@media (max-width: 1024px) {
    .grid-2 { grid-template-columns: 1fr; }
    .card-header {
        flex-direction: column;
        align-items: flex-start;
    }
    .segmented { width: 100%; justify-content: stretch; }
    .segmented button { flex: 1; text-align: center; }
}

/* Mobile: drawer sidebar */
@media (max-width: 767px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        z-index: 110;
        box-shadow: none;
    }
    .sidebar.active {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.35);
    }
    .main-content { margin-left: 0; }
    .topbar-menu-btn { display: inline-flex; }
}

/* Large phone / small tablet */
@media (max-width: 768px) {
    .content-area { padding: 16px; }
    .topbar { padding: 0 16px; }
    .grid-metrics-2x4 { grid-template-columns: repeat(2, 1fr); }
    .metric-value { font-size: 24px; }
    .chart-wrap { height: 200px; }
    .lang-chart-wrap { height: 140px; }
    .card { padding: 16px; }
    .food-rank-row { flex-wrap: wrap; }
    .food-sparkline { width: 100%; max-width: 120px; height: 32px; }
    .modal-overlay { padding: 12px; align-items: flex-end; }
    .modal {
        max-height: 90vh;
        border-bottom-left-radius: 0;
        border-bottom-right-radius: 0;
    }
}

/* Phone */
@media (max-width: 640px) {
    .grid-metrics-2x4 { grid-template-columns: 1fr; }
    .voice-stats-row,
    .notif-stats-row { grid-template-columns: 1fr 1fr; }
    .notif-stat-value,
    .voice-stat-value { font-size: 22px; }
    .feed-row {
        align-items: flex-start;
    }
    .feed-body {
        flex: 1 1 calc(100% - 48px);
        order: 2;
    }
    .feed-row .avatar { order: 0; }
    .feed-row .flag-prefix { order: 0; }
    .feed-row-meta {
        width: 100%;
        margin-left: 0;
        justify-content: space-between;
        order: 3;
        margin-top: 4px;
    }
    .stats-grid,
    .grid-4 { grid-template-columns: 1fr; }
}

/* Narrow phone */
@media (max-width: 480px) {
    .topbar-title { font-size: 14px; max-width: 140px; }
    .badge-admin { display: none; }
    .btn-logout {
        padding: 8px 10px;
        font-size: 11px;
    }
    .metric-value { font-size: 22px; }
    .metric-card { padding: 14px; }
    .card-title { font-size: 13px; }
    .segmented button { padding: 8px 10px; font-size: 11px; }
    .voice-stats-row,
    .notif-stats-row { grid-template-columns: 1fr; }
    th, td { padding: 10px 12px; font-size: 12px; }
    .table-scroll table { min-width: 480px; }
    .modal-overlay {
        padding: 0;
        align-items: stretch;
    }
    .modal {
        max-width: none;
        max-height: 100vh;
        height: 100%;
        border-radius: 0;
    }
}

/* Very small (iPhone SE, etc.) */
@media (max-width: 360px) {
    .content-area { padding: 12px; }
    .topbar { padding: 0 12px; gap: 8px; }
    .topbar-title { max-width: 110px; font-size: 13px; }
    .metric-value { font-size: 20px; }
}

/* Large desktop */
@media (min-width: 1440px) {
    .content-area {
        padding: 28px 32px;
    }
    .grid-metrics-2x4 {
        gap: 16px;
    }
}

/* Safe areas (notched devices) */
@supports (padding: max(0px)) {
    .topbar {
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
    }
    .content-area {
        padding-bottom: max(24px, env(safe-area-inset-bottom));
    }
    .sidebar {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* Touch-friendly targets */
@media (hover: none) and (pointer: coarse) {
    .nav-item { min-height: 44px; }
    .btn-logout,
    .topbar-menu-btn,
    .segmented button,
    .notif-stat.clickable { min-height: 44px; }
    .feed-row.clickable,
    .metric-card.clickable { min-height: 48px; }
}

[x-cloak] { display: none !important; }

/* ── Form controls ── */
.form-label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 14px;
}

.form-input,
.form-textarea,
.form-select,
select.form-select {
    width: 100%;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    color: var(--text-primary);
    padding: 10px 12px;
    border-radius: var(--radius-btn);
    font-size: 14px;
    font-family: inherit;
    line-height: 1.4;
}

.form-input-sm {
    width: auto;
    min-width: 48px;
    padding: 3px 5px;
    font-size: 11px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text-primary);
}

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

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
    outline: none;
    border-color: var(--accent-purple);
    box-shadow: 0 0 0 2px rgba(124, 106, 247, 0.2);
}

.form-row { margin-bottom: 16px; }

.form-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-search,
.search-box {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 16px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.form-search .form-input,
.search-box .form-input,
.search-box input[type="text"],
.premium-search-bar .form-input,
.premium-search-bar input[type="text"] {
    flex: 1;
    min-width: 0;
    margin-bottom: 0;
}

.form-search-icon {
    color: var(--text-muted);
    flex-shrink: 0;
    width: 18px;
    height: 18px;
}

.premium-search-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    align-items: center;
    flex-wrap: wrap;
    background: transparent;
    border: none;
    padding: 0;
}

.premium-income-date-input.form-date,
input.form-date {
    width: auto;
    min-width: 140px;
}

.results-count {
    color: var(--text-muted);
    font-size: 13px;
    padding: 0 0 12px;
}

.table-sort-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.table-sortable th[data-sort] {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.table-sortable th[data-sort]:hover {
    color: var(--accent-purple);
}

.table-sortable th[data-sort].sort-asc::after,
.table-sortable th[data-sort].sort-desc::after {
    display: inline-block;
    margin-left: 4px;
    font-size: 10px;
    opacity: 0.8;
}

.table-sortable th[data-sort].sort-asc::after { content: '▲'; }
.table-sortable th[data-sort].sort-desc::after { content: '▼'; }

/* Tom Select — dark theme */
.ts-wrapper.form-select-ts,
.ts-wrapper.single {
    width: 100%;
}

.ts-wrapper .ts-control {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-btn);
    color: var(--text-primary);
    padding: 8px 10px;
    font-size: 14px;
    min-height: 40px;
}

.ts-wrapper .ts-control input {
    color: var(--text-primary);
}

.ts-wrapper.focus .ts-control {
    border-color: var(--accent-purple);
    box-shadow: 0 0 0 2px rgba(124, 106, 247, 0.2);
}

.ts-dropdown {
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text-primary);
    border-radius: var(--radius-btn);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.ts-dropdown .option {
    color: var(--text-primary);
}

.ts-dropdown .active {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.ts-dropdown .option:hover,
.ts-dropdown .option.active:hover {
    background: rgba(124, 106, 247, 0.15);
}

.ts-wrapper .item {
    background: rgba(124, 106, 247, 0.2);
    color: var(--accent-purple);
    border-radius: 4px;
}

/* Flatpickr — dark theme */
.flatpickr-calendar {
    background: var(--bg-card);
    border: 1px solid var(--border);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.flatpickr-calendar.arrowTop::before,
.flatpickr-calendar.arrowTop::after {
    border-bottom-color: var(--border);
}

.flatpickr-months .flatpickr-month,
.flatpickr-current-month .flatpickr-monthDropdown-months,
.flatpickr-weekdays,
span.flatpickr-weekday {
    background: var(--bg-card);
    color: var(--text-primary);
    fill: var(--text-primary);
}

.flatpickr-day {
    color: var(--text-primary);
}

.flatpickr-day:hover,
.flatpickr-day:focus {
    background: var(--bg-hover);
    border-color: var(--bg-hover);
}

.flatpickr-day.selected,
.flatpickr-day.startRange,
.flatpickr-day.endRange {
    background: var(--accent-purple);
    border-color: var(--accent-purple);
}

.flatpickr-time input {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.flatpickr-time .flatpickr-am-pm {
    color: var(--text-primary);
}

/* Broadcasts form helpers */
.broadcast-form-grid {
    display: grid;
    gap: 20px;
}

.broadcast-type-toggle {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.broadcast-type-toggle label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
}

.broadcast-type-toggle input:checked + span {
    color: var(--accent-primary);
}

.gif-fields-panel {
    display: grid;
    gap: 16px;
    padding: 16px;
    border: 1px dashed var(--border);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.02);
}

.caption-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

.user-picker-wrap { display: grid; gap: 8px; }

.selected-user-confirm {
    display: grid;
    gap: 12px;
    padding: 14px 16px;
    border: 1px solid rgba(124, 106, 247, 0.45);
    border-radius: var(--radius-card);
    background: rgba(124, 106, 247, 0.1);
}

.selected-user-confirm-header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--accent-purple);
}

.selected-user-confirm-header svg {
    width: 16px;
    height: 16px;
}

.selected-user-confirm-body {
    display: grid;
    gap: 4px;
}

.selected-user-confirm-name {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
}

.selected-user-confirm-meta {
    font-size: 13px;
    color: var(--text-secondary);
}

.selected-user-confirm-id {
    font-size: 14px;
    color: var(--text-primary);
    margin-top: 4px;
}

.selected-user-confirm-id strong {
    color: var(--accent-purple);
    font-size: 16px;
}

.selected-user-confirm-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

.selected-user-confirm-blocked {
    font-size: 12px;
    color: var(--accent-orange);
    font-weight: 600;
}

@media (max-width: 768px) {
    .form-grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
    .broadcast-form-actions .btn { width: 100%; justify-content: center; }
}
