:root {
    --bg: #f5f7fb;
    --panel: #ffffff;
    --text: #172033;
    --muted: #647087;
    --line: #d9e0ec;
    --primary: #1769e0;
    --primary-dark: #0e4ea8;
    --success: #0f7b43;
    --warning: #9a5b00;
    --danger: #b42318;
}

[data-theme="dark"] {
    --bg: #0f172a;
    --panel: #1e293b;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --line: #334155;
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Arial, Helvetica, sans-serif;
    font-size: 15px;
    transition: background .2s, color .2s;
}

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

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

.sidebar {
    position: sticky;
    top: 0;
    width: 250px;
    height: 100vh;
    background: #101827;
    color: #fff;
    padding: 20px;
    display: flex;
    flex-direction: column;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    margin-bottom: 28px;
}

.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 6px;
    background: var(--primary);
}

.sidebar nav {
    display: grid;
    gap: 4px;
}

.sidebar-footer {
    margin-top: auto;
}

.sidebar a,
.logout-form button {
    display: block;
    width: 100%;
    color: #d9e3f4;
    background: transparent;
    border: 0;
    border-radius: 6px;
    padding: 10px 12px;
    text-align: left;
    font: inherit;
    cursor: pointer;
}

.sidebar a:hover,
.logout-form button:hover {
    background: #1c2a42;
}

.sidebar-footer {
    border-top: 1px solid #1e3a5f;
    padding-top: 12px;
}

.theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 8px;
    background: transparent;
    border: 1px solid #1e3a5f;
    border-radius: 6px;
    color: #d9e3f4;
    cursor: pointer;
    font-size: 18px;
    margin-bottom: 8px;
}

.theme-toggle:hover {
    background: #1c2a42;
}

.logout-form {
    margin-top: 0;
}

.main {
    flex: 1;
    min-width: 0;
    padding: 28px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 22px;
}

h1, h2, h3 {
    margin: 0;
}

h1 { font-size: 26px; }
h2 { font-size: 18px; }
h3 { font-size: 16px; margin-bottom: 10px; }

.user-chip, .badge {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    border-radius: 6px;
    padding: 4px 9px;
    background: #edf2f8;
    color: var(--muted);
}

[data-theme="dark"] .user-chip,
[data-theme="dark"] .badge:not(.info):not(.warning):not(.error):not(.critical) {
    background: #334155;
    color: #94a3b8;
}

.notice {
    border-radius: 6px;
    padding: 12px 14px;
    margin-bottom: 16px;
    border: 1px solid;
}

.notice.success {
    color: var(--success);
    background: #ecfdf3;
    border-color: #b7e4ca;
}

.notice.error {
    color: var(--danger);
    background: #fff1f0;
    border-color: #f7c7c2;
}

[data-theme="dark"] .notice.success {
    background: #064e3b;
    border-color: #166534;
}

[data-theme="dark"] .notice.error {
    background: #450a0a;
    border-color: #991b1b;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.stat, .panel, .login-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.stat {
    padding: 18px;
}

.stat span {
    display: block;
    color: var(--muted);
    margin-bottom: 8px;
}

.stat strong {
    font-size: 28px;
}

.panel {
    padding: 18px;
    margin-bottom: 18px;
    transition: background .2s, border-color .2s;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 14px;
}

.charts-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}

.chart-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px;
}

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

.table-wrap {
    overflow-x: auto;
}

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

th, td {
    border-bottom: 1px solid var(--line);
    padding: 11px 10px;
    text-align: left;
    vertical-align: middle;
    white-space: nowrap;
}

th {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.empty {
    color: var(--muted);
    text-align: center;
}

.badge.info {
    background: #eaf2ff;
    color: #175cd3;
}

.badge.warning {
    background: #fff7e6;
    color: var(--warning);
}

.badge.error,
.badge.critical {
    background: #fff1f0;
    color: var(--danger);
}

[data-theme="dark"] .badge.info {
    background: #1e3a5f;
    color: #93c5fd;
}

[data-theme="dark"] .badge.warning {
    background: #451a03;
    color: #fcd34d;
}

[data-theme="dark"] .badge.error,
[data-theme="dark"] .badge.critical {
    background: #450a0a;
    color: #fca5a5;
}

.tag-badge {
    display: inline-flex;
    align-items: center;
    min-height: 22px;
    border-radius: 4px;
    padding: 2px 7px;
    background: #e0e7ff;
    color: #3730a3;
    font-size: 12px;
    margin: 1px 2px;
}

[data-theme="dark"] .tag-badge {
    background: #312e81;
    color: #c7d2fe;
}

.bulk-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-top: 12px;
    padding: 12px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.bulk-actions select {
    width: auto;
    min-height: 36px;
}

.button, button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--text);
    padding: 7px 12px;
    font: inherit;
    cursor: pointer;
    transition: background .15s, border-color .15s;
}

[data-theme="dark"] .button,
[data-theme="dark"] button {
    background: #334155;
    border-color: #475569;
    color: #e2e8f0;
}

.button.primary, button.primary {
    border-color: var(--primary);
    background: var(--primary);
    color: #fff;
}

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

[data-theme="dark"] .button.primary,
[data-theme="dark"] button.primary {
    color: #fff;
}

.button.disabled {
    pointer-events: none;
    opacity: .5;
}

.button.danger, button.danger {
    border-color: #f7c7c2;
    background: #fff1f0;
    color: var(--danger);
}

.button.danger:hover, button.danger:hover {
    background: var(--danger);
    border-color: var(--danger);
    color: #fff;
}

[data-theme="dark"] .button.danger,
[data-theme="dark"] button.danger {
    background: #450a0a;
    border-color: #991b1b;
    color: #fca5a5;
}

[data-theme="dark"] .button.danger:hover,
[data-theme="dark"] button.danger:hover {
    background: #991b1b;
    color: #fff;
}

.actions {
    display: flex;
    gap: 8px;
}

.form-panel {
    max-width: 760px;
}

label {
    display: grid;
    gap: 7px;
    color: var(--muted);
    font-weight: 700;
    margin-bottom: 14px;
}

input, select, textarea {
    width: 100%;
    min-height: 40px;
    border: 1px solid #b9c3d3;
    border-radius: 6px;
    padding: 8px 10px;
    color: var(--text);
    font: inherit;
    background: #fff;
}

[data-theme="dark"] input,
[data-theme="dark"] select,
[data-theme="dark"] textarea {
    border-color: #475569;
    background: #1e293b;
    color: #e2e8f0;
}

textarea {
    resize: vertical;
}

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

.checkbox input {
    width: auto;
    min-height: auto;
}

.form-actions, .pagination {
    display: flex;
    gap: 10px;
    align-items: center;
}

.filters {
    display: grid;
    grid-template-columns: repeat(4, minmax(160px, 1fr));
    gap: 12px;
    align-items: end;
}

.filters label {
    margin: 0;
}

.detail-grid {
    display: grid;
    grid-template-columns: minmax(260px, 420px) minmax(0, 1fr);
    gap: 22px;
}

dl {
    display: grid;
    grid-template-columns: 130px 1fr;
    gap: 10px;
}

dt {
    color: var(--muted);
    font-weight: 700;
}

dd {
    margin: 0;
}

pre {
    overflow: auto;
    max-height: 620px;
    background: #0f172a;
    color: #e5edf8;
    padding: 16px;
    border-radius: 8px;
}

.login-panel {
    display: grid;
    place-items: center;
    width: 100%;
    min-height: 100vh;
    padding: 24px;
}

.login-card {
    width: min(420px, 100%);
    padding: 28px;
}

.login-card h1 {
    margin-bottom: 8px;
}

.login-card p, .help {
    color: var(--muted);
}

.credentials textarea {
    font-family: Consolas, Monaco, monospace;
}

.muted {
    color: var(--muted);
}

@media (max-width: 900px) {
    .app-shell, .detail-grid {
        display: block;
    }

    .sidebar {
        position: static;
        width: 100%;
        height: auto;
    }

    .sidebar-footer {
        margin-top: 12px;
    }

    .stats-grid, .filters {
        grid-template-columns: 1fr;
    }

    .main {
        padding: 18px;
    }
}
