/* Reset & Base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    /* Aurora — dark (default). Indigo / teal / magenta. */
    --bg: #0F1117;
    --bg-card: #161A24;
    --bg-input: #1E293B;
    --border: #2E3548;
    --text: #F8FAFC;
    --text-muted: #94A3B8;
    --primary: #8B8BFF;
    --primary-hover: #A5A5FF;
    --accent: #2DD4BF;
    --tertiary: #E879F9;
    --danger: #F87171;
    --danger-hover: #EF4444;
    --success: #34D399;
    --warning: #FBBF24;
    --blue: #60A5FA;
    --sidebar-w: 240px;
    --radius: 8px;
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;

    /* Gradients — theme-aware where possible. Premium is constant
       (warm gold → sunset) so the badge reads consistently regardless of
       which base palette the operator is on. */
    --gradient-hero: linear-gradient(135deg, var(--primary) 0%, var(--tertiary) 100%);
    --gradient-premium: linear-gradient(135deg, #FBBF24 0%, #F97316 100%);
    --gradient-accent: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
}

[data-theme="light"] {
    /* Aurora — light. */
    --bg: #FAFAFC;
    --bg-card: #FFFFFF;
    --bg-input: #FFFFFF;
    --border: #E2E8F0;
    --text: #0F172A;
    --text-muted: #64748B;
    --primary: #5B5BD6;
    --primary-hover: #4F4FBC;
    --accent: #14B8A6;
    --tertiary: #C026D3;
    --danger: #EF4444;
    --danger-hover: #DC2626;
    --success: #059669;
    --warning: #D97706;
    --blue: #2563EB;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

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

/* Login */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.login-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 40px;
    width: 100%;
    max-width: 400px;
}

.login-box h1 { font-size: 24px; margin-bottom: 4px; }
.login-box .subtitle { color: var(--text-muted); margin-bottom: 24px; }
.login-docs-link { margin-top: 18px; text-align: center; font-size: 13px; }
.login-docs-link a { color: var(--text-muted); text-decoration: none; }
.login-docs-link a:hover { color: var(--text); text-decoration: underline; }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; color: var(--text-muted); margin-bottom: 6px; }

.input, input[type="text"], input[type="password"], input[type="email"], input[type="number"], select, textarea {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
    font-family: var(--font);
    outline: none;
    transition: border-color 0.2s;
}
.input:focus, input:focus, select:focus { border-color: var(--primary); }

/* Inline add form (e.g. manual waitlist add) */
.inline-form {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin: 0 0 16px;
}
.inline-form input[type="email"] { width: 280px; }
.inline-form .form-hint { color: var(--text-muted, #999); font-size: 12px; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-input);
    color: var(--text);
    font-size: 13px;
    font-family: var(--font);
    cursor: pointer;
    transition: all 0.15s;
    gap: 6px;
}
.btn:hover { background: var(--border); }
.btn-primary {
    background: var(--gradient-hero);
    background-size: 140% 140%;
    background-position: 0% 50%;
    border-color: transparent;
    color: white;
    box-shadow: 0 1px 2px rgba(15, 17, 23, 0.25), 0 0 0 1px rgba(255, 255, 255, 0.06) inset;
    transition: background-position 0.25s ease, transform 0.05s ease, box-shadow 0.15s ease;
}
.btn-primary:hover {
    background-position: 100% 50%;
    box-shadow: 0 2px 6px rgba(91, 91, 214, 0.35), 0 0 0 1px rgba(255, 255, 255, 0.1) inset;
}
.btn-primary:active { transform: translateY(1px); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: white; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-warning { background: var(--warning); border-color: var(--warning); color: #111; }
.btn-success { background: var(--success); border-color: var(--success); color: white; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-full { width: 100%; }

.error-text { color: var(--danger); font-size: 13px; margin-top: 12px; text-align: center; }

/* Fixed-OTP toggle — checkbox inline with its label (overrides the
   block-level .form-group label default). */
.fixed-otp-toggle { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 14px; cursor: pointer; }
.fixed-otp-toggle input[type="checkbox"] { width: auto; margin: 0; }

/* Layout */
#main-app {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-w);
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 10;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
    position: relative;
}
.sidebar-header::after {
    content: "";
    position: absolute;
    left: 20px;
    right: 20px;
    bottom: -1px;
    height: 1px;
    background: var(--gradient-hero);
    opacity: 0.5;
    pointer-events: none;
}
.sidebar-header h2 {
    font-size: 18px;
    background: var(--gradient-hero);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    color: transparent;
}

.badge {
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 10px;
    background: var(--gradient-hero);
    color: white;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.06) inset;
}
.badge-premium {
    background: var(--gradient-premium);
    color: #1F2937;
    box-shadow: 0 1px 2px rgba(249, 115, 22, 0.3), 0 0 0 1px rgba(255, 255, 255, 0.2) inset;
}

/* Subscription-tier badges — used by the orbits list column and any
 * future per-orbit tier surfacing. Colours follow the architect spec:
 * Free=grey, Low=blue (admin primary), Medium=purple, High=gold (matches
 * the existing premium gradient). The cells in the orbits list pair each
 * badge with an inline <select> so admins can both eyeball and mutate
 * the tier without leaving the row. */
.badge-tier {
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
    color: white;
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.06) inset;
}
.badge-tier-free   { background: rgba(148,163,184,0.30); color: var(--text-muted); }
.badge-tier-low    { background: #3B82F6; color: white; }
.badge-tier-medium { background: #8B5CF6; color: white; }
.badge-tier-high   { background: var(--gradient-premium); color: #1F2937; box-shadow: 0 1px 2px rgba(249, 115, 22, 0.3), 0 0 0 1px rgba(255, 255, 255, 0.2) inset; }

.tier-cell { display: inline-flex; align-items: center; gap: 8px; }
.tier-select {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 2px 6px;
    color: var(--text);
    font-size: 11px;
    cursor: pointer;
}
.tier-select:focus { border-color: var(--primary); outline: none; }

.nav-links {
    list-style: none;
    flex: 1;
    padding: 12px 0;
    overflow-y: auto;
}

.nav-link {
    display: block;
    padding: 10px 20px;
    color: var(--text-muted);
    font-size: 14px;
    transition: all 0.15s;
    border-left: 3px solid transparent;
}
.nav-link:hover { color: var(--text); background: rgba(255,255,255,0.03); }
.nav-link.active {
    color: var(--primary);
    background: linear-gradient(90deg, rgba(91,91,214,0.18) 0%, rgba(91,91,214,0.04) 100%);
    border-left-color: var(--primary);
    box-shadow: inset 3px 0 0 var(--primary);
}

.nav-divider { height: 1px; background: var(--border); margin: 8px 20px; }

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13px;
    color: var(--text-muted);
    gap: 8px;
}
.sidebar-footer-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}
.btn-icon {
    padding: 4px 8px;
    font-size: 14px;
    line-height: 1;
}

.content {
    flex: 1;
    margin-left: var(--sidebar-w);
    padding: 32px;
    max-width: 1200px;
}

/* Pages */
.page { display: none; }
.page.active { display: block; }

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}
.page-header h1 { margin: 0; }

h1 { font-size: 22px; margin-bottom: 20px; }

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}
.stat-card .stat-value {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 4px;
}
.stat-card .stat-label {
    font-size: 13px;
    color: var(--text-muted);
}

/* Panels */
.dashboard-panels {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}
.panel h3 { font-size: 15px; margin-bottom: 16px; color: var(--text-muted); }

/* Chart */
.chart-container {
    height: 200px;
    display: flex;
    align-items: flex-end;
    gap: 4px;
    padding-top: 10px;
}
.chart-bar-group {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}
.chart-bar {
    width: 100%;
    max-width: 40px;
    background: var(--primary);
    border-radius: 4px 4px 0 0;
    min-height: 2px;
    transition: height 0.3s;
}
.chart-label { font-size: 10px; color: var(--text-muted); }
.chart-value { font-size: 10px; color: var(--text-muted); }

/* Tables */
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.table th {
    text-align: left;
    padding: 10px 12px;
    color: var(--text-muted);
    font-weight: 500;
    border-bottom: 1px solid var(--border);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.table td {
    padding: 10px 12px;
    border-bottom: 1px solid rgba(46,49,64,0.5);
    vertical-align: middle;
}
.table tr:hover td { background: rgba(255,255,255,0.02); }

.table .deleted { opacity: 0.4; text-decoration: line-through; }

/* Sortable column headers */
.table th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
.table th.sortable:hover { color: var(--text); }
.table th.sortable.sorted { color: var(--primary); }
.table th.sortable .sort-arrow { font-weight: 700; }

/* Filters */
.filters {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    align-items: center;
    flex-wrap: wrap;
}
.filters .input, .filters input, .filters select { width: auto; min-width: 180px; }

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-muted);
    cursor: pointer;
}

/* Pagination */
.pagination {
    display: flex;
    gap: 8px;
    margin-top: 16px;
    justify-content: center;
}

/* Badges / Tags */
.role-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}
.role-child { background: rgba(96,165,250,0.15); color: var(--blue); }
.role-parent { background: rgba(20,184,166,0.18); color: var(--accent); }
.role-admin { background: rgba(91,91,214,0.18); color: var(--primary); }

.status-linked { color: var(--success); }
.status-pending { color: var(--warning); }
.status-expired { color: var(--danger); }

.platform-badge {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 11px;
    background: var(--bg-input);
    border: 1px solid var(--border);
}

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

.modal {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 28px;
    width: 100%;
    max-width: 480px;
    max-height: 80vh;
    overflow-y: auto;
}
.modal h2 { font-size: 18px; margin-bottom: 20px; }
.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 24px;
}

/* Debug logs */
.modal-wide { max-width: 900px; }
.debug-tabs {
    display: flex;
    gap: 4px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 16px;
}
.debug-tab {
    padding: 8px 14px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 13px;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
}
.debug-tab.active { color: var(--text); border-bottom-color: var(--primary); }
.debug-tab:hover { color: var(--text); }
.debug-filters {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 12px;
    align-items: center;
}
.debug-filters .input { max-width: 200px; }
.debug-log-list {
    max-height: 50vh;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-input);
}
.debug-log-row {
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    font-family: ui-monospace, 'SF Mono', Menlo, monospace;
    font-size: 12px;
    display: grid;
    grid-template-columns: 60px 140px 100px 1fr;
    gap: 8px;
    align-items: center;
}
.debug-log-row:hover { background: rgba(255,255,255,0.03); }
.debug-log-row:last-child { border-bottom: none; }
.debug-log-expanded {
    padding: 10px;
    background: rgba(0,0,0,0.2);
    border-bottom: 1px solid var(--border);
    font-family: ui-monospace, 'SF Mono', Menlo, monospace;
    font-size: 11px;
    white-space: pre-wrap;
    word-break: break-word;
}
.debug-level-pill {
    display: inline-block;
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    text-align: center;
}
.debug-level-0 { background: rgba(127,127,127,0.2); color: #aaa; }
.debug-level-1 { background: rgba(52,152,219,0.18); color: var(--blue); }
.debug-level-2 { background: rgba(241,196,15,0.2); color: var(--warning); }
.debug-level-3 { background: rgba(231,76,60,0.2); color: var(--danger); }
.debug-log-tag { color: var(--text-muted); }
.debug-log-msg { color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.debug-empty { padding: 24px; text-align: center; color: var(--text-muted); font-size: 13px; }

/* Orbit detail + user detail */
.back-link {
    display: inline-block;
    margin-bottom: 12px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 13px;
}
.back-link:hover { color: var(--primary); }

.row-link { cursor: pointer; }
.row-link:hover { background: var(--bg-hover, rgba(255,255,255,0.03)); }

.orbit-section { margin-top: 28px; }
.orbit-section h3 {
    font-size: 14px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin: 0 0 12px;
}
.section-count {
    display: inline-block;
    background: var(--bg-hover, rgba(255,255,255,0.06));
    color: var(--text-muted);
    padding: 1px 8px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    margin-left: 6px;
}

.user-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 12px;
}
.user-card {
    display: flex;
    gap: 12px;
    padding: 12px;
    background: var(--panel, rgba(255,255,255,0.02));
    border: 1px solid var(--border, rgba(255,255,255,0.06));
    border-radius: 10px;
    cursor: pointer;
    transition: border-color 0.12s ease, transform 0.12s ease;
}
.user-card:hover {
    border-color: var(--primary);
    transform: translateY(-1px);
}
.user-card-deleted {
    opacity: 0.55;
}
.user-card-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), #7c5cff);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 16px;
    flex-shrink: 0;
}
.user-card-body { flex: 1; min-width: 0; }
.user-card-name {
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.user-card-sub {
    color: var(--text-muted);
    font-size: 12px;
    margin-top: 2px;
}
.user-card-meta {
    margin-top: 6px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.pill {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 10px;
    background: var(--bg-hover, rgba(255,255,255,0.06));
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
}
.pill-danger { background: rgba(231,76,60,0.18); color: var(--danger); }
.pill-muted { background: rgba(148,163,184,0.18); color: var(--text-muted); }
.pill-warning { background: rgba(251,191,36,0.18); color: var(--warning); }
.pill-success { background: rgba(52,211,153,0.18); color: var(--success); }

/* Toggles a form field out of the layout without clobbering its own inline
   `display` (several moderation-form labels are inline `display:flex`, so
   flipping style.display directly would not survive being shown again). */
.field-hidden { display: none !important; }

/* Ban banner — sits above the user-detail header when the account is suspended. */
.ban-banner {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    border-radius: 10px;
    background: rgba(231,76,60,0.14);
    border: 1px solid rgba(231,76,60,0.45);
    color: var(--danger);
    font-size: 13px;
    margin-bottom: 14px;
}
.ban-banner strong { color: var(--danger); }
/* Amber variant — a caution ("this comparison proves nothing"), not an
   incident. Used by the cross-region diff when digests were not computed. */
.ban-banner-warn {
    background: rgba(251,191,36,0.14);
    border-color: rgba(251,191,36,0.45);
    color: var(--warning);
}
.ban-banner-warn strong { color: var(--warning); }
.ban-banner-icon { font-size: 16px; line-height: 1.2; }
.ban-banner-body { flex: 1; color: var(--text); }
.ban-banner-body small { display: block; color: var(--text-muted); margin-top: 4px; }

/* Ban modal radio list */
.ban-radio-list { display: flex; flex-direction: column; gap: 6px; }
.ban-radio-list label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
}
.ban-radio-list label:hover { background: rgba(148,163,184,0.08); }
.ban-radio-list input[type="radio"] { margin: 0; }

.empty-grid {
    padding: 16px;
    color: var(--text-muted);
    font-size: 13px;
    text-align: center;
    border: 1px dashed var(--border, rgba(255,255,255,0.08));
    border-radius: 10px;
}

.user-detail-tabs {
    display: flex;
    gap: 8px;
    margin: 16px 0 12px;
    border-bottom: 1px solid var(--border, rgba(255,255,255,0.08));
    padding-bottom: 6px;
    flex-wrap: wrap;
}
.user-tab-panel { margin-top: 8px; }
.user-detail-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* Tier limits — admin editor table. The four cap columns each render a
 * narrow numeric input with the unlimited "-1" chip stacked beneath, and
 * a per-cap inline error slot for BE-side 400s. The actions column packs
 * the reason input, Save button, status pill and history disclosure. */
.tier-limits-table input.tier-limit-input {
    width: 96px;
    padding: 6px 8px;
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}
.tier-limits-table .tier-limit-input.tier-limit-dirty {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(91,91,214,0.18);
}
.tier-limits-table .tier-limit-input.tier-limit-input-error {
    border-color: var(--danger);
    box-shadow: 0 0 0 2px rgba(231,76,60,0.18);
}
.tier-limits-table .tier-limit-field-error {
    margin-top: 4px;
    font-size: 11px;
    color: var(--danger);
}
.tier-limits-table .tier-limits-unlimited {
    margin-left: 4px;
    font-size: 10px;
}
.tier-limits-table .tier-limit-cap {
    vertical-align: top;
}
.tier-limits-table .tier-limit-updated {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
}
.tier-limit-action-stack {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 260px;
}
.tier-limit-action-stack input.tier-limit-reason {
    font-size: 13px;
    padding: 6px 8px;
}
.tier-limit-buttons {
    display: flex;
    align-items: center;
    gap: 8px;
}
.tier-limit-status {
    font-size: 12px;
    color: var(--text-muted);
}
.tier-limit-status-pending { color: var(--text-muted); }
.tier-limit-status-ok {
    background: rgba(52,211,153,0.18);
    color: var(--success);
    padding: 2px 10px;
    border-radius: 10px;
    font-weight: 600;
}
.tier-limit-row-error {
    font-size: 12px;
    color: var(--danger);
    background: rgba(231,76,60,0.10);
    padding: 6px 8px;
    border-radius: 6px;
}
.tier-limit-history > summary {
    cursor: pointer;
    font-size: 12px;
    color: var(--text-muted);
    user-select: none;
    padding: 2px 0;
}
.tier-limit-history[open] > summary { color: var(--text); }
.tier-limit-history-body {
    margin-top: 6px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 360px;
    overflow-y: auto;
    padding-right: 4px;
}
.tier-limit-history-row {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 12px;
    background: rgba(255,255,255,0.02);
}
.tier-limit-history-meta {
    display: flex;
    gap: 8px;
    align-items: baseline;
    color: var(--text-muted);
    margin-bottom: 4px;
}
.tier-limit-history-when { color: var(--text); font-weight: 500; }
.tier-limit-history-by { font-size: 11px; }
.tier-limit-history-caps {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 4px;
}
.tier-limit-history-cap {
    font-variant-numeric: tabular-nums;
    background: rgba(148,163,184,0.10);
    padding: 1px 8px;
    border-radius: 8px;
}
.tier-limit-history-cap-label { color: var(--text-muted); margin-right: 2px; }
.tier-limit-history-reason { color: var(--text); white-space: pre-wrap; word-break: break-word; }
.tier-limit-history-more { text-align: center; margin-top: 4px; }

/* Support case console */
.support-transcript {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    max-height: 52vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 16px;
}
.support-bubble-row { display: flex; }
.support-row-user { justify-content: flex-start; }
.support-row-agent { justify-content: flex-end; }
.support-bubble {
    max-width: 70%;
    padding: 8px 12px;
    border-radius: 12px;
    border: 1px solid var(--border);
}
.support-bubble-user { background: var(--bg); }
.support-bubble-agent {
    background: rgba(139,139,255,0.16);
    border-color: var(--primary);
}
.support-bubble-meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 4px;
}
.support-bubble-body { white-space: pre-wrap; word-break: break-word; }
.support-reply textarea { width: 100%; resize: vertical; }

/* Inline image attachments on support messages (ORB-497, images only) */
.support-bubble-image {
    margin-top: 6px;
    display: block;
}
.support-bubble-image img {
    max-width: 240px;
    max-height: 240px;
    width: auto;
    height: auto;
    border-radius: 8px;
    border: 1px solid var(--border);
    display: block;
    cursor: zoom-in;
    background: var(--bg);
}
.support-bubble-image .support-image-loading,
.support-bubble-image .support-image-error {
    font-size: 11px;
    color: var(--text-muted);
    padding: 4px 0;
}
.support-bubble-image .support-image-error { color: var(--danger, #e05555); }

/* Reply box attach control */
.support-reply-controls {
    margin-top: 8px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
.support-reply-controls .btn-primary { margin-left: auto; }
.support-attach-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}
.support-attach-label input[type="file"] {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    overflow: hidden;
    clip: rect(0 0 0 0);
}
.support-attach-name {
    font-size: 12px;
    color: var(--text-muted);
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.support-attach-clear {
    border: none;
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    padding: 0 2px;
}
.support-attach-clear:hover { color: var(--danger, #e05555); }
.support-reply-status { margin-top: 6px; }

/* Mobile top bar + drawer backdrop — hidden on desktop, shown < 700px. */
.mobile-topbar { display: none; }
.sidebar-backdrop { display: none; }

.menu-toggle {
    display: inline-flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 40px;
    height: 40px;
    padding: 8px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
}
.menu-toggle span {
    display: block;
    height: 2px;
    width: 100%;
    background: var(--text);
    border-radius: 2px;
}

/* Responsive */
@media (max-width: 900px) {
    .dashboard-panels { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 700px) {
    /* Fixed top bar with the hamburger + wordmark. */
    .mobile-topbar {
        display: flex;
        align-items: center;
        gap: 10px;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: 56px;
        padding: 0 16px;
        background: var(--bg-card);
        border-bottom: 1px solid var(--border);
        z-index: 20;
    }
    .mobile-topbar h2 {
        font-size: 18px;
        background: var(--gradient-hero);
        -webkit-background-clip: text;
        background-clip: text;
        -webkit-text-fill-color: transparent;
        color: transparent;
    }

    /* Sidebar slides in as an off-canvas drawer instead of vanishing. */
    .sidebar {
        display: flex;
        width: 260px;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        z-index: 40;
    }
    #main-app.sidebar-open .sidebar { transform: translateX(0); }

    .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 30;
    }
    .sidebar-backdrop[hidden] { display: none; }

    /* Content clears the fixed top bar and spans full width. */
    .content {
        margin-left: 0;
        padding: 16px;
        padding-top: 72px;
        max-width: 100%;
    }

    .page-header { flex-wrap: wrap; gap: 12px; }
    .stats-grid { grid-template-columns: 1fr 1fr; }

    /* Wide data tables scroll horizontally rather than overflow the page. */
    .table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
    }

    /* Modals get breathing room from the screen edges. */
    .modal { margin: 16px; max-height: 88vh; }
    .modal-wide { max-width: 100%; }
}

/* --- Lifecycle Emails config panel --- */
.lifecycle-emails-panel {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding: 20px;
    background: var(--surface, var(--bg));
    border: 1px solid var(--border);
    border-radius: 10px;
}
.lifecycle-emails-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.lifecycle-emails-field > label {
    font-weight: 600;
    color: var(--text);
}
.lifecycle-emails-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    cursor: pointer;
}
.lifecycle-emails-toggle input { width: 16px; height: 16px; }
.lifecycle-emails-hint { font-size: 13px; color: var(--text-muted); }
.lifecycle-emails-buttons {
    display: flex;
    align-items: center;
    gap: 12px;
}
.lifecycle-emails-buttons #lifecycle-emails-save-status { color: var(--success); font-size: 14px; }
.lifecycle-emails-error {
    color: var(--danger);
    font-size: 14px;
    padding: 10px 12px;
    border: 1px solid var(--danger);
    border-radius: 8px;
}

/* Lifecycle Emails — per-email timing table */
.lifecycle-emails-table { margin: 4px 0; }
.lifecycle-emails-table td { vertical-align: top; }
.lifecycle-emails-immediate {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--border);
}
.lifecycle-emails-daycell input { width: 90px; }
.lifecycle-emails-dayunit { margin-left: 8px; font-size: 13px; color: var(--text-muted); }

/* --- Config console (ORB-1357) ---
   Shared by the Remote Config page and the user-detail Config tab: a
   toolbar'd list card with expandable rows + a right-docked editor panel. */

.cfg-breadcrumb { font-size: 13px; color: var(--text-muted); margin-bottom: 6px; }
.cfg-breadcrumb-sep { margin: 0 6px; opacity: 0.6; }
.cfg-breadcrumb-current { color: var(--text); }

.cfg-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}
.cfg-header h1 { margin: 0; font-size: 28px; letter-spacing: -0.02em; }
.cfg-header-inline h2 { margin: 0; font-size: 16px; }

.cfg-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.cfg-select {
    width: auto;
    padding: 8px 12px;
    border-radius: 999px;
    background: var(--bg-card);
    font-size: 13px;
}
.cfg-search { position: relative; display: flex; align-items: center; }
.cfg-search-icon {
    position: absolute;
    left: 12px;
    font-size: 15px;
    color: var(--text-muted);
    pointer-events: none;
}
.cfg-search-input {
    width: 240px;
    padding: 8px 14px 8px 32px;
    border-radius: 999px;
    background: var(--bg-card);
    font-size: 13px;
}

.cfg-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-top: 14px;
}
.cfg-table th:first-child, .cfg-table td:first-child { padding-left: 16px; }
.cfg-table th:last-child, .cfg-table td:last-child { padding-right: 16px; }
.cfg-table td { vertical-align: top; padding-top: 14px; padding-bottom: 14px; }
.cfg-table tbody tr:last-child td { border-bottom: none; }
.cfg-col-expand { width: 34px; }
.cfg-col-menu { width: 48px; }

.cfg-key { font-weight: 600; font-size: 13.5px; }
.cfg-muted { color: var(--text-muted); }
.cfg-desc { color: var(--text-muted); max-width: 340px; }

.cfg-chip {
    display: inline-block;
    max-width: 240px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: bottom;
    padding: 3px 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-input);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12px;
}
.cfg-chip-variants { border-style: dashed; color: var(--primary); }

.cfg-expand-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 13px;
    line-height: 1;
    padding: 2px 4px;
    cursor: pointer;
    transition: transform 0.15s, color 0.15s;
}
.cfg-expand-btn:hover { color: var(--text); }
.cfg-expand-btn.open { transform: rotate(90deg); color: var(--text); }

.cfg-detail-row > td { background: rgba(148,163,184,0.06); padding-top: 0; }
.cfg-detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    padding: 4px 0 10px;
}
.cfg-detail-col h4 {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 6px;
}
.cfg-detail-line { display: flex; gap: 10px; font-size: 12px; padding: 2px 0; }
.cfg-detail-line > span:first-child { color: var(--text-muted); min-width: 78px; }
.cfg-detail-line code { word-break: break-all; }

.cfg-row-menu { position: relative; text-align: right; }
.cfg-menu-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 13px;
    line-height: 1;
    padding: 4px 6px;
    border-radius: 6px;
    cursor: pointer;
}
.cfg-menu-btn:hover { background: var(--border); color: var(--text); }
.cfg-menu {
    display: none;
    position: absolute;
    right: 8px;
    top: 28px;
    z-index: 30;
    min-width: 150px;
    padding: 4px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.28);
    text-align: left;
}
.cfg-menu.open { display: block; }
.cfg-menu button {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    color: var(--text);
    font-family: var(--font);
    font-size: 13px;
    padding: 7px 10px;
    border-radius: 6px;
    cursor: pointer;
}
.cfg-menu button:hover { background: var(--bg-input); }
.cfg-menu button.danger { color: var(--danger); }

/* Right-docked editor panel (replaces the centred modal for config edits). */
.modal.cfg-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    margin: 0;
    width: 100%;
    max-width: 560px;
    max-height: 100vh;
    padding: 0;
    border-radius: 0;
    border-top: none;
    border-right: none;
    border-bottom: none;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}
.cfg-panel form { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.cfg-panel-head { position: relative; padding: 24px 28px 16px; }
.cfg-panel-head h2 { font-size: 24px; margin: 0 0 4px; }
.cfg-panel-sub { color: var(--text-muted); font-size: 13px; }
.cfg-panel-close {
    position: absolute;
    top: 18px;
    right: 20px;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
}
.cfg-panel-close:hover { color: var(--text); }
.cfg-panel-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 0 28px 24px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}
.cfg-panel-foot {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 28px;
    border-top: 1px solid var(--border);
    background: var(--bg-card);
}
.cfg-req { color: var(--danger); }
.cfg-hint { display: block; margin-top: 4px; font-size: 11px; color: var(--text-muted); }
.cfg-section { border: 1px solid var(--border); border-radius: 10px; padding: 16px; }
.cfg-section h3 {
    margin: 0 0 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}
.cfg-textarea { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; resize: vertical; }
.cfg-field-error { text-align: left; font-size: 12px; margin-top: 6px; }

@media (max-width: 700px) {
    .cfg-header h1 { font-size: 22px; }
    .cfg-toolbar { width: 100%; }
    .cfg-search, .cfg-search-input { flex: 1; width: auto; min-width: 0; }
    .modal.cfg-panel { max-width: 100%; }
}
