:root {
    color-scheme: light;
    --bg: #eef2f6;
    --surface: #ffffff;
    --surface-muted: #f6f8fb;
    --surface-strong: #e7edf5;
    --sidebar: #111827;
    --sidebar-2: #182235;
    --sidebar-text: #f8fafc;
    --sidebar-muted: #94a3b8;
    --text: #142033;
    --muted: #687386;
    --border: #d6dee9;
    --border-strong: #b9c5d4;
    --primary: #2f6fed;
    --primary-soft: #e8f0ff;
    --primary-hover: #255bd0;
    --accent: #0f9f8f;
    --accent-soft: #e2f7f4;
    --success: #17875d;
    --success-soft: #e4f6ef;
    --warning: #b7791f;
    --warning-soft: #fff3d8;
    --danger: #c93d3d;
    --danger-soft: #fde8e8;
    --violet: #7357d8;
    --violet-soft: #eeeafe;
    --shadow: none;
    --radius: 8px;
    --control-height: 40px;
}

[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0b111a;
    --surface: #121b29;
    --surface-muted: #182435;
    --surface-strong: #203047;
    --sidebar: #090f18;
    --sidebar-2: #101827;
    --sidebar-text: #f8fafc;
    --sidebar-muted: #8ca0bb;
    --text: #e8eef7;
    --muted: #98a8bd;
    --border: #29384d;
    --border-strong: #3a4b63;
    --primary: #72a7ff;
    --primary-soft: #162a49;
    --primary-hover: #8db8ff;
    --accent: #3cc7bb;
    --accent-soft: #153a38;
    --success: #57d59f;
    --success-soft: #17382b;
    --warning: #f2bf5f;
    --warning-soft: #3b2c13;
    --danger: #ff7474;
    --danger-soft: #401c22;
    --violet: #a99aff;
    --violet-soft: #2d2750;
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 15px;
    letter-spacing: 0;
}

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

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

button {
    color: inherit;
}

h1,
h2,
h3,
p {
    margin-top: 0;
}

.app-shell {
    display: grid;
    grid-template-columns: 292px minmax(0, 1fr);
    min-height: 100vh;
}

.sidebar {
    background: var(--sidebar);
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--sidebar-text);
    padding: 22px 16px;
}

.brand {
    align-items: center;
    display: flex;
    gap: 12px;
    min-height: 42px;
    padding: 0 8px;
}

.brand-mark {
    background: var(--primary);
    border-radius: var(--radius);
    color: #ffffff;
    display: grid;
    font-weight: 800;
    height: 40px;
    place-items: center;
    width: 40px;
}

.brand strong,
.brand small {
    display: block;
}

.brand small {
    color: var(--sidebar-muted);
    margin-top: 2px;
}

.nav {
    display: grid;
    gap: 20px;
    margin-top: 30px;
}

.nav-group h2 {
    color: var(--sidebar-muted);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.08em;
    margin: 0 0 7px;
    padding: 0 10px;
    text-transform: uppercase;
}

.nav-group a {
    align-items: center;
    border-radius: var(--radius);
    color: #cbd5e1;
    display: flex;
    min-height: 38px;
    padding: 9px 10px;
}

.nav-group a:hover,
.nav-group a.active {
    background: var(--sidebar-2);
    color: #ffffff;
}

.nav-group a.active {
    box-shadow: inset 3px 0 0 var(--primary);
}

.workspace {
    min-width: 0;
}

.topbar {
    align-items: center;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    min-height: 78px;
    padding: 16px 28px;
}

.eyebrow {
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.08em;
    margin: 0;
    text-transform: uppercase;
}

.topbar h1 {
    font-size: 24px;
    line-height: 1.15;
    margin: 4px 0 0;
}

.topbar-actions,
.button-row,
.inline-actions {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.topbar-actions form {
    margin: 0;
}

.content {
    padding: 28px;
}

.grid,
.section-grid,
.stack {
    display: grid;
    gap: 16px;
}

.metrics-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    margin-bottom: 16px;
}

.two-metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin-bottom: 0;
}

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

.mt-16 {
    margin-top: 16px;
}

.panel,
.metric-card,
.auth-panel,
.empty-state {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.panel {
    padding: 20px;
}

.panel-tight {
    padding: 14px;
}

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

.panel-header,
.section-title {
    align-items: flex-start;
    display: flex;
    gap: 14px;
    justify-content: space-between;
    margin-bottom: 16px;
}

.panel-header h2,
.section-title h2 {
    font-size: 18px;
    line-height: 1.2;
    margin: 0 0 5px;
}

.panel-header p,
.section-title p,
.muted {
    color: var(--muted);
    margin-bottom: 0;
}

.metric-card {
    border-left: 4px solid var(--border-strong);
    padding: 17px;
}

.metric-card span {
    color: var(--muted);
    display: block;
    font-size: 13px;
    font-weight: 700;
}

.metric-card strong {
    display: block;
    font-size: 26px;
    line-height: 1.1;
    margin-top: 10px;
}

.metric-card small {
    color: var(--muted);
    display: block;
    margin-top: 8px;
}

.metric-card.success {
    border-left-color: var(--success);
}

.metric-card.neutral {
    border-left-color: var(--primary);
}

.metric-card.warning {
    border-left-color: var(--warning);
}

.metric-card.danger {
    border-left-color: var(--danger);
}

.button {
    align-items: center;
    border: 1px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
    display: inline-flex;
    font-weight: 800;
    justify-content: center;
    min-height: var(--control-height);
    padding: 9px 13px;
}

.button:focus-visible,
.theme-switch:focus-visible,
.logout-button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--primary), transparent 72%);
    outline-offset: 1px;
}

.button-primary {
    background: var(--primary);
    color: #ffffff;
}

.button-primary:hover {
    background: var(--primary-hover);
}

.button-secondary {
    background: var(--surface-muted);
    border-color: var(--border);
    color: var(--text);
}

.button-secondary:hover {
    border-color: var(--border-strong);
}

.button-danger {
    background: var(--danger);
    color: #ffffff;
}

.button-ghost {
    background: transparent;
    border-color: var(--border);
    color: var(--text);
}

.button-sm {
    font-size: 13px;
    min-height: 32px;
    padding: 6px 10px;
}

.user-chip {
    align-items: center;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: inline-flex;
    gap: 9px;
    min-height: var(--control-height);
    padding: 6px 11px 6px 8px;
}

.chip-icon {
    align-items: center;
    background: var(--primary-soft);
    border-radius: 7px;
    color: var(--primary);
    display: inline-flex;
    height: 28px;
    justify-content: center;
    width: 28px;
}

.chip-text strong,
.chip-text small {
    display: block;
}

.chip-text strong {
    font-weight: 800;
    line-height: 1.1;
}

.chip-text small {
    color: var(--muted);
    font-size: 12px;
    line-height: 1.1;
    margin-top: 3px;
}

.theme-switch {
    align-items: center;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--muted);
    cursor: pointer;
    display: inline-flex;
    gap: 8px;
    min-height: var(--control-height);
    padding: 6px 8px;
}

.theme-switch:hover,
.logout-button:hover {
    border-color: var(--border-strong);
}

.theme-icon {
    align-items: center;
    display: inline-flex;
    height: 24px;
    justify-content: center;
    opacity: 0.55;
    width: 24px;
}

.theme-sun {
    color: var(--warning);
    opacity: 1;
}

.theme-moon {
    color: var(--primary);
}

.theme-track {
    background: var(--surface-strong);
    border: 1px solid var(--border);
    border-radius: 999px;
    display: inline-flex;
    height: 22px;
    padding: 2px;
    width: 42px;
}

.theme-thumb {
    background: var(--warning);
    border-radius: 50%;
    display: block;
    height: 16px;
    transform: translateX(0);
    transition: transform 160ms ease, background 160ms ease;
    width: 16px;
}

[data-theme="dark"] .theme-thumb {
    background: var(--primary);
    transform: translateX(18px);
}

[data-theme="dark"] .theme-sun {
    opacity: 0.45;
}

[data-theme="dark"] .theme-moon {
    opacity: 1;
}

.logout-button {
    align-items: center;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    cursor: pointer;
    display: inline-flex;
    gap: 8px;
    min-height: var(--control-height);
    padding: 8px 12px;
}

.logout-button span {
    align-items: center;
    color: var(--danger);
    display: inline-flex;
}

.logout-button strong {
    font-weight: 800;
}

.form-stack,
.field-grid {
    display: grid;
    gap: 14px;
}

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

label span,
.field-label {
    color: var(--muted);
    display: block;
    font-size: 13px;
    font-weight: 800;
    margin-bottom: 6px;
}

input,
select,
textarea {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    min-height: var(--control-height);
    padding: 10px 12px;
    width: 100%;
}

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

input::placeholder,
textarea::placeholder {
    color: var(--muted);
}

.checkbox-row {
    align-items: center;
    display: flex;
    gap: 10px;
}

.checkbox-row input {
    height: 18px;
    min-height: 18px;
    width: 18px;
}

.toggle-row {
    align-items: center;
    display: flex;
    justify-content: space-between;
}

.toggle {
    background: var(--surface-strong);
    border: 1px solid var(--border);
    border-radius: 999px;
    display: inline-flex;
    height: 24px;
    padding: 2px;
    width: 44px;
}

.toggle::before {
    background: var(--primary);
    border-radius: 50%;
    content: "";
    display: block;
    height: 18px;
    transform: translateX(18px);
    width: 18px;
}

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

.data-table th,
.data-table td {
    border-bottom: 1px solid var(--border);
    padding: 12px;
    text-align: left;
    vertical-align: top;
}

.data-table th {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.data-table tbody tr:hover {
    background: var(--surface-muted);
}

.tag-list,
.badge-row,
.tab-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.tag-list span,
.badge,
.tab {
    align-items: center;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    display: inline-flex;
    font-size: 13px;
    font-weight: 800;
    min-height: 30px;
    padding: 6px 9px;
}

.badge-success {
    background: var(--success-soft);
    border-color: transparent;
    color: var(--success);
}

.badge-warning {
    background: var(--warning-soft);
    border-color: transparent;
    color: var(--warning);
}

.badge-danger {
    background: var(--danger-soft);
    border-color: transparent;
    color: var(--danger);
}

.badge-primary,
.tab.active {
    background: var(--primary-soft);
    border-color: transparent;
    color: var(--primary);
}

.badge-accent {
    background: var(--accent-soft);
    border-color: transparent;
    color: var(--accent);
}

.alert {
    border: 1px solid transparent;
    border-radius: var(--radius);
    padding: 12px 13px;
}

.alert-danger {
    background: var(--danger-soft);
    color: var(--danger);
}

.alert-success {
    background: var(--success-soft);
    color: var(--success);
}

.alert-warning {
    background: var(--warning-soft);
    color: var(--warning);
}

.alert-info {
    background: var(--primary-soft);
    color: var(--primary);
}

.toolbar {
    align-items: end;
    display: grid;
    gap: 12px;
    grid-template-columns: 1.2fr repeat(3, minmax(140px, 0.6fr)) auto;
}

.stat-list {
    display: grid;
    gap: 10px;
}

.stat-row {
    align-items: center;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex;
    justify-content: space-between;
    min-height: 42px;
    padding: 9px 11px;
}

.stat-row span {
    color: var(--muted);
    font-weight: 700;
}

.stat-row strong {
    font-size: 18px;
}

.progress {
    background: var(--surface-strong);
    border-radius: 999px;
    height: 8px;
    overflow: hidden;
}

.progress span {
    background: var(--primary);
    display: block;
    height: 100%;
}

.w-38 {
    width: 38%;
}

.swatch-grid {
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(6, minmax(0, 1fr));
}

.swatch {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.swatch i {
    display: block;
    height: 48px;
}

.swatch span {
    display: block;
    font-size: 12px;
    font-weight: 800;
    padding: 8px;
}

.swatch-primary i {
    background: var(--primary);
}

.swatch-accent i {
    background: var(--accent);
}

.swatch-success i {
    background: var(--success);
}

.swatch-warning i {
    background: var(--warning);
}

.swatch-danger i {
    background: var(--danger);
}

.swatch-violet i {
    background: var(--violet);
}

.empty-state {
    display: grid;
    gap: 12px;
    justify-items: start;
    padding: 22px;
}

.empty-state strong {
    font-size: 18px;
}

.auth-body {
    display: grid;
    min-height: 100vh;
    padding: 24px;
    place-items: center;
}

.auth-panel {
    max-width: 380px;
    padding: 24px;
    width: 100%;
}

@media (max-width: 1120px) {
    .metrics-grid,
    .swatch-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

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

@media (max-width: 920px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        border-bottom: 1px solid rgba(255, 255, 255, 0.08);
        border-right: 0;
    }

    .section-grid,
    .field-grid,
    .toolbar {
        grid-template-columns: 1fr;
    }

    .topbar {
        align-items: flex-start;
        flex-direction: column;
        gap: 14px;
    }
}

@media (max-width: 620px) {
    .content {
        padding: 18px;
    }

    .metrics-grid,
    .swatch-grid {
        grid-template-columns: 1fr;
    }

    .panel-header,
    .section-title {
        display: block;
    }
}
