:root {
    --bg: #f1f5f9;
    --panel: #ffffff;
    --ink: #0f172a;
    --muted: #64748b;
    --line: #e2e8f0;
    --brand: #4f46e5;
    --brand-dark: #4338ca;
    --sidebar: #0f172a;
    --sidebar-ink: #cbd5e1;
    --green: #16a34a;
    --green-bg: #dcfce7;
    --amber: #b45309;
    --amber-bg: #fef3c7;
    --red: #dc2626;
    --red-bg: #fee2e2;
    --blue: #2563eb;
    --blue-bg: #dbeafe;
    --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .06);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 14px;
    line-height: 1.45;
}

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

a:hover {
    text-decoration: underline;
}

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

.login-panel {
    width: min(100%, 420px);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 28px;
    box-shadow: var(--shadow);
}

.login-panel h1 {
    margin: 0 0 8px;
    font-size: 26px;
}

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

.sidebar {
    background: var(--sidebar);
    color: var(--sidebar-ink);
    padding: 14px 8px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.brand {
    display: block !important;
    padding: 10px 12px 18px;
    border-bottom: 1px solid #1e293b;
    margin-bottom: 10px;
}

.brand strong {
    display: block;
    color: #fff;
    font-size: 20px;
    letter-spacing: .04em;
}

.brand span {
    display: block;
    color: #94a3b8;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .08em;
    margin-top: 2px;
}

.nav-section {
    color: #64748b;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .08em;
    padding: 14px 12px 6px;
}

.sidebar .nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--sidebar-ink);
    padding: 10px 12px;
    border-radius: 9px;
    font-weight: 500;
    margin-bottom: 2px;
    white-space: nowrap;
}

.sidebar .nav-link:hover,
.sidebar .nav-link.active {
    background: var(--brand);
    color: #fff;
    text-decoration: none;
}

.nav-count {
    margin-left: auto;
    flex: 0 0 auto;
    background: #1e293b;
    color: #94a3b8;
    border-radius: 999px;
    padding: 1px 8px;
    font-size: 11px;
}

.nav-link.active .nav-count {
    background: rgba(255, 255, 255, .24);
    color: #fff;
}

.material-icons-outlined {
    font-size: 20px;
}

.main {
    min-width: 0;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    background: var(--panel);
    border-bottom: 1px solid var(--line);
    padding: 14px 26px;
    display: flex;
    align-items: center;
    gap: 14px;
    justify-content: space-between;
}

.topbar h1 {
    margin: 0;
    font-size: 19px;
}

.topbar p {
    margin: 2px 0 0;
    color: var(--muted);
    font-size: 12.5px;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.main > .alert,
.main > section {
    margin-left: 26px;
    margin-right: 26px;
}

.main > .alert {
    margin-top: 18px;
}

.eios-kpi-grid,
.kpis {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 14px;
    margin-top: 24px;
    margin-bottom: 22px;
}

.eios-kpi-card,
.kpi,
.panel,
.tablewrap,
.template-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: var(--shadow);
}

.eios-kpi-card,
.kpi {
    padding: 16px 18px;
}

.eios-kpi-card span,
.kpi span {
    display: block;
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .04em;
}

.eios-kpi-card strong,
.kpi strong {
    display: block;
    font-size: 28px;
    margin-top: 6px;
}

.eios-kpi-card small,
.kpi small {
    display: block;
    color: var(--muted);
}

.eios-kpi-card div,
.kpi div {
    height: 6px;
    background: #e2e8f0;
    border-radius: 999px;
    overflow: hidden;
    margin-top: 12px;
}

.eios-kpi-card div i,
.kpi div i {
    display: block;
    height: 100%;
    background: var(--brand);
}

.content-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
    margin-bottom: 18px;
}

.content-grid.two-col {
    grid-template-columns: minmax(0, 1.5fr) minmax(320px, .8fr);
}

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

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

.panel-heading h2 {
    margin: 0;
    font-size: 15px;
}

.module-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-top: 24px;
    margin-bottom: 14px;
}

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

.search {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 12px;
    width: 280px;
}

.tablewrap {
    overflow: auto;
    margin-bottom: 18px;
}

.tablewrap.inner {
    box-shadow: none;
    margin: 0;
}

table {
    width: 100%;
    border-collapse: collapse;
    white-space: nowrap;
}

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

th {
    background: #f8fafc;
    color: var(--muted);
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: .04em;
    text-align: left;
}

tr:last-child td {
    border-bottom: 0;
}

tr:hover td {
    background: #fafbff;
}

.status-pill {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 700;
}

.status-pill.ok {
    background: var(--green-bg);
    color: var(--green);
}

.status-pill.warn {
    background: var(--amber-bg);
    color: var(--amber);
}

.status-pill.bad {
    background: var(--red-bg);
    color: var(--red);
}

.status-pill.info {
    background: var(--blue-bg);
    color: var(--blue);
}

.row-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

.row-actions form {
    margin: 0;
}

.record-form {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.record-form label {
    display: grid;
    gap: 6px;
}

.record-form label span {
    color: var(--muted);
    font-weight: 700;
    font-size: 12px;
}

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

.checkline {
    display: flex !important;
    align-items: center;
    gap: 8px;
    color: var(--ink) !important;
    font-weight: 500 !important;
}

.template-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
    gap: 16px;
    margin-bottom: 18px;
}

.template-card {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.template-head {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: center;
}

.template-card h2 {
    font-size: 16px;
    margin: 0;
}

.template-card pre {
    white-space: pre-wrap;
    background: #f8fafc;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    max-height: 240px;
    overflow: auto;
    font-family: inherit;
    font-size: 13px;
}

.template-subject,
.template-note,
.muted {
    color: var(--muted);
}

.distrow {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 9px 0;
    border-bottom: 1px solid var(--line);
}

.distrow:last-child {
    border-bottom: 0;
}

.alert-row,
.list-item,
.notification-card {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 12px;
    margin-bottom: 10px;
    background: #fff;
}

.notification-card,
.list-item {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
}

.alert-row span,
.list-item span {
    display: block;
    color: var(--muted);
    font-size: 12px;
}

.severity-danger {
    border-left: 4px solid var(--red);
}

.severity-warning {
    border-left: 4px solid var(--amber);
}

.severity-info {
    border-left: 4px solid var(--blue);
}

.filter-bar,
.stack-form {
    display: grid;
    gap: 12px;
}

.filter-bar {
    grid-template-columns: repeat(3, minmax(0, 260px));
    align-items: end;
    margin-bottom: 16px;
}

.stack-form label {
    display: grid;
    gap: 6px;
    font-weight: 700;
    color: var(--muted);
    font-size: 12px;
}

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

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

.btn-primary {
    background: var(--brand);
    border-color: var(--brand);
}

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

#toast {
    position: fixed;
    left: 50%;
    bottom: 26px;
    transform: translateX(-50%) translateY(20px);
    background: #0f172a;
    color: #fff;
    padding: 11px 22px;
    border-radius: 10px;
    opacity: 0;
    pointer-events: none;
    transition: .2s;
    z-index: 200;
}

#toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

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

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

    .content-grid,
    .content-grid.two-col,
    .record-form,
    .filter-bar {
        grid-template-columns: 1fr;
    }

    .topbar,
    .module-actions,
    .notification-card,
    .list-item {
        align-items: stretch;
        flex-direction: column;
    }

    .search,
    .search-form {
        width: 100%;
    }

    .main > .alert,
    .main > section {
        margin-left: 14px;
        margin-right: 14px;
    }
}
