:root {
    color-scheme: light;
    --bg: #f4f7fb;
    --surface: #ffffff;
    --surface-raised: #ffffff;
    --surface-muted: #eef2f8;
    --text: #102139;
    --text-muted: #5a6b80;
    --border: #d8e0eb;
    --success: #087f5b;
    --warning: #9a6700;
    --danger: #c0392b;
    --info: #2563a6;
    --shadow: 0 10px 28px rgba(7, 27, 58, .08);
    --radius: 8px;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0b111a;
    --surface: #131c28;
    --surface-raised: #182331;
    --surface-muted: #202c3b;
    --text: #f5f8fc;
    --text-muted: #b8c5d6;
    --border: #334155;
    --success: #55d6a9;
    --warning: #f4c45e;
    --danger: #ff7b7b;
    --info: #86c5ff;
    --shadow: 0 14px 34px rgba(0, 0, 0, .28);
}

@media (prefers-color-scheme: dark) {
    [data-theme="system"] {
        color-scheme: dark;
        --bg: #0b111a;
        --surface: #131c28;
        --surface-raised: #182331;
        --surface-muted: #202c3b;
        --text: #f5f8fc;
        --text-muted: #b8c5d6;
        --border: #334155;
        --success: #55d6a9;
        --warning: #f4c45e;
        --danger: #ff7b7b;
        --info: #86c5ff;
        --shadow: 0 14px 34px rgba(0, 0, 0, .28);
    }
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; letter-spacing: 0; }
a { color: inherit; }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 248px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 18px 14px; background: var(--brand-primary); color: #f4f8ff; }
.brand { display: flex; align-items: center; gap: 11px; min-height: 48px; padding: 4px 8px 18px; color: #fff; text-decoration: none; font-size: 15px; font-weight: 750; }
.brand img { width: 34px; height: 34px; object-fit: contain; border-radius: 6px; background: #fff; padding: 3px; }
.nav { display: flex; flex-direction: column; gap: 3px; overflow-y: auto; }
.nav a { min-height: 40px; display: flex; align-items: center; padding: 0 12px; border-radius: 6px; color: #dce9f8; text-decoration: none; font-weight: 560; }
.nav a:hover, .nav a:focus-visible { background: rgba(255,255,255,.12); color: #fff; outline: none; }
.nav-section { margin: 20px 12px 7px; color: #9fb8d8; font-size: 11px; font-weight: 800; text-transform: uppercase; }
.sidebar-footer { margin-top: auto; display: grid; gap: 12px; }
.theme-control { display: grid; grid-template-columns: repeat(3, 1fr); padding: 3px; border: 1px solid rgba(255,255,255,.2); border-radius: 7px; }
.theme-control button { min-height: 30px; border: 0; border-radius: 5px; background: transparent; color: inherit; cursor: pointer; font-size: 12px; }
.theme-control button[aria-pressed="true"] { background: rgba(255,255,255,.18); color: #fff; }
.main-column { min-width: 0; }
.topbar { height: 70px; display: flex; align-items: center; gap: 14px; padding: 0 28px; border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--surface) 94%, transparent); position: sticky; top: 0; z-index: 10; backdrop-filter: blur(10px); }
.topbar div { display: grid; gap: 2px; }
.topbar strong { font-size: 15px; }
.topbar span { color: var(--text-muted); font-size: 12px; }
.topbar .environment { margin-left: auto; padding: 5px 9px; border-radius: 999px; background: var(--surface-muted); color: var(--text-muted); font-weight: 700; }
.menu-toggle { display: none; border: 0; background: transparent; color: var(--text); font-size: 21px; }
.content { width: min(1500px, 100%); margin: 0 auto; padding: 28px; }

.page-heading { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; margin-bottom: 22px; }
.page-heading h1 { margin: 0 0 5px; font-size: 24px; line-height: 1.2; }
.page-heading p { margin: 0; color: var(--text-muted); }
.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 24px; }
.metric { padding: 18px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.metric span { display: block; color: var(--text-muted); font-size: 12px; font-weight: 700; }
.metric strong { display: block; margin-top: 8px; font-size: 28px; line-height: 1; }
.metric small { display: block; margin-top: 9px; color: var(--text-muted); }

.panel { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); overflow: hidden; }
.panel + .panel { margin-top: 18px; }
.panel-header { display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 17px 18px; border-bottom: 1px solid var(--border); }
.panel-header h2 { margin: 0; font-size: 15px; }
.panel-header p { margin: 4px 0 0; color: var(--text-muted); font-size: 12px; }
.panel-body { padding: 18px; }
.grid-two { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, .46fr); gap: 18px; align-items: start; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 11px 14px; background: var(--surface-muted); color: var(--text-muted); text-align: left; font-size: 11px; text-transform: uppercase; white-space: nowrap; }
td { padding: 13px 14px; border-top: 1px solid var(--border); vertical-align: middle; }
tbody tr:hover { background: color-mix(in srgb, var(--surface-muted) 48%, transparent); }
.device-name { display: grid; gap: 3px; min-width: 150px; }
.device-name strong { font-size: 13px; }
.device-name span, .muted { color: var(--text-muted); font-size: 12px; }
.status { display: inline-flex; align-items: center; gap: 6px; padding: 4px 8px; border-radius: 999px; background: var(--surface-muted); font-size: 11px; font-weight: 800; white-space: nowrap; }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status-pending { color: var(--warning); }
.status-approved, .status-online { color: var(--success); }
.status-blocked, .status-rejected, .status-revoked { color: var(--danger); }
.status-offline { color: var(--text-muted); }

.filters { display: flex; flex-wrap: wrap; gap: 9px; padding: 14px 16px; border-bottom: 1px solid var(--border); background: var(--surface-muted); }
.filters select, .filters input { width: auto; min-width: 170px; }
.field { display: grid; gap: 7px; margin-bottom: 15px; }
.field label { font-size: 12px; font-weight: 750; }
.field-help { color: var(--text-muted); font-size: 11px; line-height: 1.5; }
input, select, textarea { width: 100%; min-height: 40px; padding: 9px 11px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-raised); color: var(--text); outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--brand-accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-accent) 20%, transparent); }
input[type="color"] { min-height: 46px; padding: 4px; }
input[type="checkbox"] { width: 17px; min-height: 17px; accent-color: var(--brand-accent); }
textarea { min-height: 92px; resize: vertical; }
.checkbox { display: flex; align-items: flex-start; gap: 9px; margin: 12px 0; }
.checkbox label { line-height: 1.45; }
.validation-summary-errors, .field-validation-error { color: var(--danger); font-size: 12px; }
.validation-summary-errors ul { margin: 0 0 14px; padding-left: 18px; }

.button { display: inline-flex; justify-content: center; align-items: center; min-height: 38px; padding: 0 14px; border: 1px solid transparent; border-radius: 6px; background: var(--brand-accent); color: #fff; text-decoration: none; font-weight: 750; cursor: pointer; }
.button:hover { filter: brightness(1.08); }
.button-secondary { border-color: var(--border); background: var(--surface-raised); color: var(--text); }
.button-danger { background: var(--danger); }
.button-ghost { border-color: rgba(255,255,255,.25); background: transparent; color: #fff; }
.button-small { min-height: 31px; padding: 0 10px; font-size: 12px; }
.button-full { width: 100%; }
.actions { display: flex; flex-wrap: wrap; gap: 7px; }
.form-actions { justify-content: flex-end; margin-top: 18px; }
.form-panel { max-width: 760px; }
.alert { margin-bottom: 18px; padding: 12px 14px; border-radius: 7px; border: 1px solid var(--border); }
.alert-success { border-color: color-mix(in srgb, var(--success) 42%, var(--border)); background: color-mix(in srgb, var(--success) 9%, var(--surface)); color: var(--success); }
.alert-error { border-color: color-mix(in srgb, var(--danger) 42%, var(--border)); background: color-mix(in srgb, var(--danger) 9%, var(--surface)); color: var(--danger); }
.empty { padding: 44px 20px; color: var(--text-muted); text-align: center; }

dialog { width: min(520px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); box-shadow: 0 28px 70px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(2, 8, 18, .66); backdrop-filter: blur(2px); }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.modal-header h2 { margin: 0; font-size: 16px; }
.modal-close { width: 34px; height: 34px; border: 0; border-radius: 6px; background: var(--surface-muted); color: var(--text); cursor: pointer; }
.modal-body { padding: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; padding: 14px 18px; border-top: 1px solid var(--border); }

.auth-body { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--bg); }
.auth-shell { width: min(900px, 100%); min-height: 520px; display: grid; grid-template-columns: .9fr 1.1fr; overflow: hidden; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: 0 24px 70px rgba(7,27,58,.18); }
.auth-brand { display: flex; flex-direction: column; justify-content: flex-end; padding: 38px; background: var(--brand-primary); color: #fff; }
.auth-brand img { width: min(230px, 100%); max-height: 82px; margin-bottom: auto; object-fit: contain; object-position: left center; filter: brightness(0) invert(1); }
.auth-brand p { max-width: 320px; margin: 0 0 22px; color: #d5e4f6; font-size: 17px; line-height: 1.55; }
.auth-status { display: flex; align-items: center; gap: 8px; color: #bad0e9; font-size: 12px; font-weight: 700; }
.auth-status span { width: 8px; height: 8px; border-radius: 50%; background: #55d6a9; box-shadow: 0 0 0 4px rgba(85,214,169,.16); }
.auth-panel { display: grid; align-content: center; padding: 48px; }
.auth-panel h1 { margin: 0 0 7px; font-size: 25px; }
.auth-panel > p { margin: 0 0 26px; color: var(--text-muted); line-height: 1.5; }
.auth-theme { position: fixed; top: 18px; right: 18px; width: 190px; color: var(--text); border-color: var(--border); background: var(--surface); }
.auth-theme button[aria-pressed="true"] { background: var(--surface-muted); color: var(--text); }
.qr-code { width: 190px; height: 190px; display: block; margin: 0 auto 18px; border-radius: 6px; background: #fff; padding: 10px; }
.recovery-codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 18px 0; }
.recovery-codes code { padding: 10px; border-radius: 5px; background: var(--surface-muted); text-align: center; }

.brand-preview { min-height: 210px; display: grid; place-items: center; padding: 30px; border-radius: var(--radius); background: var(--brand-primary); }
.brand-preview img { max-width: 280px; max-height: 100px; object-fit: contain; filter: brightness(0) invert(1); }
.logo-guidance { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.guidance { padding: 12px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface-muted); }
.guidance strong { display: block; margin-bottom: 5px; }
.guidance span { color: var(--text-muted); font-size: 12px; }

@media (max-width: 980px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { position: fixed; left: -260px; z-index: 30; width: 248px; transition: left .2s ease; box-shadow: 18px 0 40px rgba(0,0,0,.25); }
    .menu-open .sidebar { left: 0; }
    .menu-toggle { display: block; }
    .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-two { grid-template-columns: 1fr; }
}

@media (max-width: 680px) {
    .content { padding: 18px 14px; }
    .topbar { padding: 0 14px; }
    .topbar .environment { display: none; }
    .page-heading { align-items: flex-start; flex-direction: column; }
    .page-heading h1 { font-size: 21px; }
    .metrics { grid-template-columns: 1fr 1fr; gap: 9px; }
    .metric { padding: 14px; }
    .metric strong { font-size: 23px; }
    .auth-body { padding: 0; }
    .auth-shell { min-height: 100vh; grid-template-columns: 1fr; border: 0; border-radius: 0; }
    .auth-brand { min-height: 190px; padding: 26px; }
    .auth-brand img { width: 190px; max-height: 60px; }
    .auth-brand p { margin-top: 26px; font-size: 15px; }
    .auth-panel { padding: 30px 24px; }
    .auth-theme { top: 10px; right: 10px; width: 170px; }
    .logo-guidance { grid-template-columns: 1fr; }
}
