:root {
    --ink: #0f172a;
    --muted: #64748b;
    --line: #e2e8f0;
    --panel: #ffffff;
    --paper: #f6f7fb;
    --field: #ffffff;
    --brand: #4f46e5;
    --brand-dark: #4338ca;
    --brand-soft: #eef2ff;
    --sidebar: #111827;
    --sidebar-soft: #1f2937;
    --green: #16a34a;
    --amber: #d97706;
    --red: #dc2626;
    --blue: #2563eb;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
    --shadow: 0 8px 24px rgba(15, 23, 42, .08);
    --shadow-lg: 0 20px 45px rgba(15, 23, 42, .12);
    --radius: 12px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    color: var(--ink);
    background: var(--paper);
    font-family: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
}

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

a:hover {
    color: var(--brand-dark);
}

.link-button {
    border: 0;
    background: transparent;
    color: var(--brand);
    padding: 0;
    cursor: pointer;
    text-align: left;
    font-weight: 700;
}

.link-button:hover {
    color: var(--brand-dark);
    text-decoration: underline;
}

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

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

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

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 24px 16px;
    background: var(--sidebar);
    color: #e5e7eb;
    display: flex;
    flex-direction: column;
    gap: 28px;
}

.brand {
    display: flex;
    gap: 12px;
    align-items: center;
    color: inherit;
    padding: 0 8px;
}

.brand.compact {
    color: var(--ink);
}

.brand-mark {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    display: grid;
    place-items: center;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--brand), #818cf8);
    color: #fff;
    font-weight: 700;
    font-size: 14px;
    letter-spacing: .02em;
}

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

.brand strong {
    font-size: 14px;
    font-weight: 700;
}

.brand small {
    color: #9ca3af;
    margin-top: 2px;
    font-size: 12px;
}

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

.nav a,
.logout {
    color: #cbd5e1;
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    transition: background-color .15s ease, color .15s ease;
}

.nav a:hover {
    background: var(--sidebar-soft);
    color: #fff;
}

.nav a.active {
    background: var(--brand);
    color: #fff;
    font-weight: 600;
}

.logout {
    margin-top: auto;
    color: #fca5a5;
}

.logout:hover {
    background: rgba(248, 113, 113, .12);
    color: #fecaca;
}

.content {
    padding: 32px 40px;
    max-width: 1280px;
    width: 100%;
}

.content.narrow {
    max-width: 920px;
}

.page-head,
.section-head {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    align-items: center;
    margin-bottom: 26px;
}

.eyebrow {
    margin: 0 0 4px;
    color: var(--brand);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
}

h1,
h2 {
    margin: 0;
    line-height: 1.2;
    font-family: inherit;
    letter-spacing: -.01em;
    color: var(--ink);
}

h1 {
    font-size: clamp(26px, 3vw, 32px);
    font-weight: 700;
}

h2 {
    font-size: 18px;
    font-weight: 700;
}

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

.metric,
.panel,
.login-panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.metric {
    padding: 20px 22px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: box-shadow .2s ease, transform .2s ease;
}

.metric:hover {
    box-shadow: var(--shadow);
    transform: translateY(-2px);
}

.metric::before {
    content: "";
    width: 36px;
    height: 4px;
    border-radius: 4px;
    background: var(--brand);
}

.metric.alert-metric::before {
    background: var(--amber);
}

.metric span {
    display: block;
    font-size: 32px;
    font-weight: 800;
    letter-spacing: -.02em;
}

.metric small,
small,
.hint {
    color: var(--muted);
    font-size: 13px;
}

.panel {
    padding: 22px;
    margin-bottom: 22px;
}

.filter-panel {
    padding: 14px;
}

.filters {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) 190px 190px 160px auto;
    gap: 10px;
}

.table-wrap {
    overflow-x: auto;
    margin: -22px;
    padding: 22px;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 780px;
}

th,
td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: middle;
}

th {
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
}

tbody tr {
    transition: background-color .12s ease;
}

tbody tr:hover {
    background: var(--paper);
}

tbody tr:last-child td {
    border-bottom: none;
}

.actions {
    text-align: right;
    white-space: nowrap;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.badge.ok {
    background: #dcfce7;
    color: #15803d;
}

.badge.warning {
    background: #fef3c7;
    color: #b45309;
}

.badge.danger,
.alert.danger {
    background: #fee2e2;
    color: var(--red);
}

.badge.muted,
.badge.neutral {
    background: #f1f5f9;
    color: var(--muted);
}

.form {
    display: grid;
    gap: 16px;
}

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

label {
    display: grid;
    gap: 6px;
    color: #334155;
    font-weight: 600;
    font-size: 14px;
}

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

input,
select,
textarea {
    width: 100%;
    min-height: 42px;
    border: 1px solid var(--line);
    background: var(--field);
    color: var(--ink);
    border-radius: 8px;
    padding: 10px 12px;
    transition: border-color .15s ease, box-shadow .15s ease;
}

textarea {
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-soft);
}

.btn {
    min-height: 40px;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 9px 16px;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: background-color .15s ease, border-color .15s ease, box-shadow .15s ease;
}

.btn.primary {
    background: var(--brand);
    color: #fff;
    box-shadow: var(--shadow-sm);
}

.btn.primary:hover {
    background: var(--brand-dark);
}

.btn.ghost {
    background: var(--panel);
    color: var(--ink);
    border-color: var(--line);
}

.btn.ghost:hover {
    background: var(--paper);
    border-color: #cbd5e1;
}

.btn.danger {
    background: #fef2f2;
    color: var(--red);
    border-color: #fecaca;
}

.btn.danger:hover {
    background: #fee2e2;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    flex-wrap: wrap;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: grid;
    place-items: center;
    padding: 24px;
    background: rgba(15, 23, 42, .55);
}

.modal-backdrop[hidden] {
    display: none;
}

.modal {
    width: min(780px, 100%);
    max-height: min(760px, calc(100vh - 48px));
    overflow: auto;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
}

.modal-head {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    align-items: flex-start;
    padding: 22px 24px;
    border-bottom: 1px solid var(--line);
}

.modal-close {
    width: 36px;
    height: 36px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    color: var(--muted);
    cursor: pointer;
    font-size: 18px;
}

.modal-close:hover {
    background: var(--paper);
    color: var(--ink);
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    padding: 22px 24px;
}

.detail-grid div {
    min-width: 0;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--paper);
}

.detail-grid span {
    display: block;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
}

.detail-grid strong {
    display: block;
    color: var(--ink);
    font-size: 14px;
    font-weight: 600;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    padding: 16px 24px 22px;
    border-top: 1px solid var(--line);
}

.alert {
    padding: 12px 14px;
    border-radius: 8px;
    margin-bottom: 14px;
    font-weight: 600;
    font-size: 14px;
}

.alert.success {
    background: #dcfce7;
    color: #15803d;
}

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

.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        radial-gradient(circle at 15% 0%, rgba(79, 70, 229, .12), transparent 45%),
        radial-gradient(circle at 85% 100%, rgba(79, 70, 229, .08), transparent 45%),
        var(--paper);
}

.login-panel {
    width: min(420px, 100%);
    padding: 32px;
    box-shadow: var(--shadow-lg);
}

.login-panel h1 {
    font-size: 24px;
    margin: 22px 0 18px;
}

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

    .sidebar {
        position: static;
        height: auto;
    }

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

    .logout {
        margin-top: 0;
    }

    .content {
        padding: 20px;
    }

    .metric-grid,
    .filters,
    .grid-form,
    .detail-grid {
        grid-template-columns: 1fr;
    }

    .page-head {
        align-items: flex-start;
        flex-direction: column;
    }
}
