/* Warm Amber - light theme defaults */
:root {
    --primary: #F59E0B;
    --primaryDark: #D97706;
    --primaryLight: #FBBF24;
    --primarySubtle: rgba(245, 158, 11, 0.10);
    --primaryFg: #fff;
    --bg: #FFFBF0;
    --mainBg: #FFFBF0;
    --mainBgAlt: #FEF3C7;
    --secondaryBg: #FFFFFF;
    --surface: #FFFFFF;
    --surfaceAlt: #FEF3C7;
    --surfaceRaised: #FFFDF7;
    --textPrimary: #1C1410;
    --textSecondary: #6B5E4E;
    --textMuted: #9C8E80;
    --border: #EDE0CC;
    --borderStrong: #D4B896;
    --success: #059669;
    --successBg: #ecfdf5;
    --successText: #065f46;
    --warning: #EA580C;
    --warningBg: #fff7ed;
    --warningText: #9a3412;
    --danger: #DC2626;
    --dangerBg: #fef2f2;
    --dangerText: #991b1b;
    --info: #0891B2;
    --accentGlow: #FDE68A;
    --alertRoseBg: #fef2f2;
    --alertRoseBorder: #FECDD3;
    --alertRoseText: #991b1b;
    --alertAmberBg: #fff7ed;
    --alertAmberBorder: #FDE68A;
    --alertAmberText: #9a3412;
    --alertGreenBg: #ecfdf5;
    --alertGreenBorder: #BBF7D0;
    --alertGreenText: #065f46;
    --chartBarHigh: #F43F5E;
    --chartBarLow: #F59E0B;
    --inputBg: #FFFFFF;
    --inputBorder: #EDE0CC;
    --inputFocus: #F59E0B;
    --shadow: 0 1px 2px rgba(28, 20, 16, 0.05);
    --shadowMd: 0 2px 8px rgba(28, 20, 16, 0.07);
    --shadowLg: 0 8px 24px rgba(28, 20, 16, 0.1);
    --radiusXl: 20px;
    --radiusLg: 16px;
    --radiusMd: 12px;
    --radiusSm: 8px;

    /* Font families */
    --font-heading: 'Plus Jakarta Sans', system-ui, sans-serif;
    --font-body: 'DM Sans', system-ui, sans-serif;
    --font-mono: 'DM Mono', monospace;
}

html.theme-dark {
    --primary: #FCD34D;
    --primaryDark: #F59E0B;
    --primaryLight: #FDE68A;
    --primarySubtle: rgba(252, 211, 77, 0.14);
    --primaryFg: #1C1410;
    --bg: #0C0A04;
    --mainBg: #0C0A04;
    --mainBgAlt: #1E180C;
    --secondaryBg: #151108;
    --surface: #151108;
    --surfaceAlt: #1E180C;
    --surfaceRaised: #282010;
    --textPrimary: #FEF9EC;
    --textSecondary: #B5A898;
    --textMuted: #6B5E52;
    --border: #2E2416;
    --borderStrong: #3D3018;
    --success: #34D399;
    --successBg: #052e16;
    --successText: #6ee7b7;
    --warning: #FB923C;
    --warningBg: #431407;
    --warningText: #fdba74;
    --danger: #F87171;
    --dangerBg: #450a0a;
    --dangerText: #fca5a5;
    --info: #22D3EE;
    --accentGlow: #92400E;
    --alertRoseBg: rgba(248, 113, 113, 0.12);
    --alertRoseBorder: rgba(248, 113, 113, 0.25);
    --alertRoseText: #fca5a5;
    --alertAmberBg: rgba(252, 211, 77, 0.10);
    --alertAmberBorder: rgba(252, 211, 77, 0.25);
    --alertAmberText: #FDE68A;
    --alertGreenBg: rgba(52, 211, 153, 0.10);
    --alertGreenBorder: rgba(52, 211, 153, 0.25);
    --alertGreenText: #6ee7b7;
    --chartBarHigh: #FB7185;
    --chartBarLow: #FCD34D;
    --inputBg: #1E180C;
    --inputBorder: #2E2416;
    --inputFocus: #FCD34D;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadowMd: 0 2px 8px rgba(0, 0, 0, 0.4);
    --shadowLg: 0 8px 24px rgba(0, 0, 0, 0.5);
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    font-family: var(--font-body);
    color: var(--textPrimary);
    -webkit-font-smoothing: antialiased;
    background-color: var(--bg);
}

html, body, #app {
    height: 100vh;
    height: 100dvh;
}

@supports (height: 100dvh) {
    html, body, #app {
        height: 100dvh;
    }
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-heading);
}

h1:focus {
    outline: none;
}

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

.card h3,
.page-card h3 {
    margin: 0 0 4px;
    font-size: 16px;
    font-weight: 700;
    color: var(--textPrimary);
}

button, input, textarea, select {
    font: inherit;
}

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

/* Input component */
.in-input {
    font-size: 0.875rem;
    font-weight: 400;
    color: var(--textPrimary);
    height: 100%;
    width: 100%;
    outline: none;
    border: none;
    background: transparent;
    border-radius: var(--in-radius);
    padding: 0 0 0 var(--in-pad-x);
    font-family: var(--font-body);
}

.in-input::placeholder {
    color: var(--textMuted);
}

.form-login_register {
    width: 100%;
}

.valid.modified:not([type=checkbox]) {
    outline: 1px solid var(--success);
}

.validation-message {
    color: var(--danger);
    font-size: 0.8rem;
    font-weight: 400;
}

.in-input-checkbox {
    width: 14px;
    height: 14px;
    padding: 0;
    accent-color: var(--primary);
    border-radius: 4px;
    justify-self: start;
    cursor: pointer;
}

.in-input-checkbox:hover {
    border-color: var(--in-accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--in-accent) 18%, transparent),
    var(--in-shadow-focus);
}

.in-input-checkbox:focus-within {
    border-color: var(--in-accent);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--in-accent) 18%, transparent),
    var(--in-shadow-focus);
}

/* Sidebar link */
.sb-link {
    display: flex;
    gap: 0.8rem;
    align-items: center;
    color: var(--textSecondary);
    padding: 9px 12px;
    font-size: 13px;
    font-family: var(--font-body);
    border-radius: 10px;
    border-left: 3px solid transparent;
    transition: background 150ms ease, color 150ms ease;
    margin-bottom: 2px;
    white-space: nowrap;
}

.sb-link:hover {
    background: var(--surfaceAlt);
    color: var(--textPrimary);
}

.sb-link.active {
    background: var(--primarySubtle);
    color: var(--primaryDark);
    font-weight: 600;
    border-left-color: var(--primary);
}

.sb-link.active .sb-link-icon {
    font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}

/* Cards & surfaces */
.page-card,
.card,
.oauth-card,
.admin-tile,
.permission-group-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow);
    padding: 20px;
}

.page-card {
    display: grid;
    gap: 1rem;
}

/* Grid layouts */
.dashboard-grid,
.two-col-grid,
.metric-grid,
.admin-home-grid,
.admin-action-grid,
.oauth-grid,
.permission-group-grid,
.form-grid {
    display: grid;
    gap: 20px;
}

.dashboard-grid,
.two-col-grid {
    grid-template-columns: 1.2fr .8fr;
}

.metric-grid {
    grid-template-columns: repeat(4, 1fr);
}

.metric-grid-two,
.oauth-grid,
.permission-group-grid,
.admin-home-grid,
.admin-action-grid {
    grid-template-columns: repeat(2, 1fr);
}

.panel-wide {
    grid-column: 1 / -1;
}

.field-span-2 {
    grid-column: span 2;
}

/* Hero card */
.hero-card {
    background: linear-gradient(135deg, var(--primaryDark) 0%, var(--primary) 100%);
    color: #FFFFFF;
    border-radius: var(--radiusLg);
    padding: 28px;
    box-shadow: var(--shadowLg);
    position: relative;
    overflow: hidden;
}

.hero-card::before {
    content: '';
    position: absolute;
    inset: 0;
    opacity: 0.06;
    background-image: radial-gradient(circle at 80% 20%, #fff 1px, transparent 1px),
    radial-gradient(circle at 30% 70%, #fff 1px, transparent 1px);
    background-size: 30px 30px, 40px 40px;
    pointer-events: none;
}

.eyebrow {
    font-size: 11px;
    font-weight: 500;
    opacity: .8;
    letter-spacing: .04em;
    text-transform: uppercase;
    font-family: var(--font-heading);
}

.hero-reading-row {
    display: flex;
    align-items: baseline;
    gap: 6px;
    margin-top: 8px;
}

.hero-reading {
    font-size: 56px;
    font-weight: 700;
    line-height: 1;
    font-family: var(--font-mono);
    letter-spacing: -0.03em;
}

.hero-unit {
    margin-bottom: 6px;
    font-size: 16px;
    font-weight: 500;
    opacity: .8;
}

/* Badges & pills */
.status-pill,
.badge,
.summary-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 3px 10px;
    border-radius: 20px;
    background: var(--surfaceAlt);
    color: var(--textPrimary);
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
    gap: 4px;
}

.metric-label {
    color: var(--textMuted);
    font-size: 11px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: .04em;
    font-family: var(--font-heading);
}

.metric-value {
    margin-top: 4px;
    font-size: 24px;
    font-weight: 700;
    font-family: var(--font-mono);
}

.muted-text {
    color: var(--textMuted);
    font-size: 13px;
}

.card-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.card-title-row h1,
.card-title-row h3,
.page-card h1 {
    margin: 0 0 4px;
}

.page-card p {
    margin: 0;
    color: var(--textMuted);
    font-size: 13px;
}

/* Bar chart */
.bar-chart {
    height: 240px;
    padding: 16px;
    border-radius: var(--radiusLg);
    background: linear-gradient(180deg, var(--surfaceAlt) 0%, var(--surfaceRaised) 100%);
    display: flex;
    align-items: end;
    gap: 8px;
}

.bar {
    flex: 1;
    border-radius: 6px 6px 0 0;
    background: linear-gradient(180deg, var(--primary) 0%, var(--primaryDark) 100%);
    opacity: .8;
    transition: opacity 150ms ease;
}

.bar:hover {
    opacity: 1;
}

/* Form elements */
.app-input {
    width: 100%;
    min-height: 42px;
    padding: 0 12px;
    border-radius: 10px;
    border: 1.5px solid var(--inputBorder);
    background: var(--inputBg);
    color: var(--textPrimary);
    font-size: 14px;
    font-family: var(--font-body);
    transition: border-color 200ms ease, box-shadow 200ms ease;
}

.app-input:focus {
    outline: none;
    border-color: var(--inputFocus);
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.13);
}

.app-textarea {
    min-height: 120px;
    padding-top: 12px;
    padding-bottom: 12px;
    resize: vertical;
}

label {
    display: block;
    margin-bottom: 5px;
    color: var(--textSecondary);
    font-size: 12px;
    font-weight: 500;
    font-family: var(--font-heading);
}

/* Buttons */
.app-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 42px;
    padding: 0 18px;
    border-radius: 10px;
    border: 1.5px solid transparent;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    font-family: var(--font-heading);
    transition: background 150ms ease, box-shadow 150ms ease, transform 100ms ease;
}

.app-btn:active {
    transform: scale(.98);
}

.app-btn-primary {
    background: var(--primary);
    color: var(--primaryFg);
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.25);
}

.app-btn-primary:hover {
    background: var(--primaryDark);
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.35);
}

.app-btn-secondary {
    background: var(--surface);
    color: var(--textPrimary);
    border-color: var(--border);
}

.app-btn-secondary:hover {
    border-color: var(--borderStrong);
    background: var(--surfaceAlt);
}

.app-btn-outline {
    background: var(--surface);
    color: var(--textPrimary);
    border-color: var(--border);
}

.app-btn-outline:hover {
    border-color: var(--borderStrong);
    background: var(--surfaceAlt);
}

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

.app-btn-danger:hover {
    opacity: .88;
}

.btn-sm {
    min-height: 34px;
    padding: 0 14px;
    border-radius: 10px;
    font-size: 12px;
}

/* Scroll lock - applied by dialog-lock.js when any modal is open */
body.dialog-open {
    overflow: hidden;
}

/* Tables */
.table-wrap {
    overflow-x: auto;
}

.app-table {
    width: 100%;
    border-collapse: collapse;
}

.app-table th,
.app-table td {
    text-align: left;
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

.app-table th {
    padding: 12px 20px;
    color: var(--textMuted);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    background: var(--surfaceAlt);
    font-family: var(--font-heading);
    position: sticky;
    top: 0;
    z-index: 1;
}

.app-table tr:last-child td {
    border-bottom: none;
}

.app-table tbody tr:hover {
    background: var(--surfaceRaised);
}

/* Settings rows */
.settings-list,
.stack-list {
    display: grid;
    gap: 10px;
}

.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 14px 16px;
    border-radius: var(--radiusMd);
    background: var(--surfaceAlt);
    border: 1px solid var(--border);
}

.row-actions,
.toolbar-actions,
.switch-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.input-inline {
    width: 260px;
}

.admin-tile-title,
.permission-group-title,
.row-title {
    font-weight: 700;
    font-size: 15px;
    font-family: var(--font-heading);
}

.admin-tile-text {
    color: var(--textSecondary);
    margin-top: 6px;
    font-size: 14px;
}

.permission-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

.permission-item:last-child {
    border-bottom: none;
}

/* Custom scrollbar */
*::-webkit-scrollbar {
    width: 6px;
}

*::-webkit-scrollbar-track {
    background: transparent;
}

*::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

/* Responsive */
@media (max-width: 960px) {
    .dashboard-grid,
    .two-col-grid,
    .metric-grid-two,
    .oauth-grid,
    .permission-group-grid,
    .admin-home-grid,
    .admin-action-grid,
    .form-grid {
        grid-template-columns: 1fr;
    }

    .metric-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .field-span-2 {
        grid-column: span 1;
    }

    .input-inline {
        width: 100%;
    }
}

@media (max-width: 600px) {
    .metric-grid {
        grid-template-columns: 1fr;
    }

    .card, .page-card, .oauth-card, .admin-tile, .permission-group-card {
        padding: 16px;
    }

    .hero-reading {
        font-size: 42px;
    }

    .hero-unit {
        font-size: 14px;
    }

    .metric-value {
        font-size: 20px;
    }

    .app-table th,
    .app-table td {
        padding: 10px 12px;
        font-size: 13px;
    }

    .settings-row {
        flex-wrap: wrap;
    }

    .bar-chart {
        height: 180px;
        padding: 12px;
    }

    .card-title-row {
        flex-wrap: wrap;
    }
}

/* ── Mobile bottom navigation ── */
.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 68px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    align-items: center;
    justify-content: space-around;
    z-index: 30;
    padding-bottom: 8px;
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.06);
}

@media (max-width: 639px) {
    .bottom-nav {
        display: flex;
    }
}

.bnav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    border: none;
    background: transparent;
    cursor: pointer;
    padding: 4px 8px;
    text-decoration: none;
    color: var(--textMuted);
    transition: color 0.15s;
}

.bnav-item .material-symbols-outlined {
    font-size: 22px;
}

.bnav-active {
    color: var(--primary);
}

.bnav-active .bnav-label {
    font-weight: 600;
}

.bnav-label {
    font-size: 10px;
    font-weight: 400;
    line-height: 1.2;
}

.bnav-log {
    color: #F59E0B;
}

.bnav-log-icon {
    width: 48px;
    height: 48px;
    border-radius: 16px;
    background: linear-gradient(135deg, #D97706, #F59E0B);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: -20px;
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.35);
}

.bnav-log-icon .material-symbols-outlined {
    font-size: 22px;
    color: #fff;
}

.bnav-label-log {
    color: #F59E0B;
}
