:root {
    --bg: #f4f7fb;
    --surface: #ffffff;
    --surface-2: #eef3f8;
    --ink: #172033;
    --muted: #667085;
    --line: #d9e2ec;
    --primary: #1f7a8c;
    --primary-dark: #155f70;
    --danger: #c83e4d;
    --warn: #d69e2e;
    --good: #2f855a;
    --shadow: 0 10px 28px rgba(22, 34, 51, .08);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--ink);
    font-family: 'Poppins', Arial, Helvetica, sans-serif;
}

.auth-page {
    display: grid;
    place-items: center;
    padding: 24px;
}

.auth-card {
    width: min(440px, 100%);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 28px;
}

.auth-brand {
    color: var(--ink);
    margin-bottom: 22px;
}

.auth-brand small {
    color: var(--muted);
}

.login-form,
.auth-actions {
    display: grid;
    gap: 14px;
    margin-top: 20px;
}

.alert {
    padding: 12px 14px;
    border-radius: 8px;
    margin: 16px 0;
    font-weight: 700;
}

.alert.error {
    background: #fde7ea;
    color: var(--danger);
}

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

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

.app-shell.menu-collapsed {
    grid-template-columns: 78px minmax(0, 1fr);
}

.sidebar {
    position: relative;
    background: #11202f;
    color: #fff;
    padding: 24px 18px;
    overflow: hidden;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 28px;
}

.brand-icon {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 8px;
    background: var(--primary);
}

.brand strong, .brand small { display: block; }
.brand small { color: #b8c6d6; margin-top: 3px; }

.menu-toggle {
    display: grid;
    place-items: center;
    width: 36px;
    min-width: 36px;
    height: 36px;
    margin-left: auto;
    border: 0;
    border-radius: 8px;
    background: rgba(255, 255, 255, .1);
    color: #d8e2ed;
    cursor: pointer;
}

.menu-toggle:hover {
    background: rgba(255, 255, 255, .16);
    color: #fff;
}

.app-shell.menu-collapsed .sidebar {
    padding-inline: 18px;
}

.app-shell.menu-collapsed .brand {
    justify-content: center;
}

.app-shell.menu-collapsed .brand > div,
.app-shell.menu-collapsed .nav-group-title {
    display: none;
}

.app-shell.menu-collapsed .menu-toggle {
    position: absolute;
    top: 70px;
    left: 21px;
    margin-left: 0;
}

.app-shell.menu-collapsed .menu-toggle i {
    transform: rotate(180deg);
}

.app-shell.menu-collapsed .main-nav {
    margin-top: 62px;
    gap: 12px;
}

.app-shell.menu-collapsed .nav-group {
    gap: 8px;
}

.app-shell.menu-collapsed .nav-group + .nav-group {
    padding-top: 12px;
}

.app-shell.menu-collapsed .nav-link {
    justify-content: center;
    gap: 0;
    min-height: 42px;
    padding: 10px;
    font-size: 0;
}

.app-shell.menu-collapsed .nav-link i {
    width: 18px;
    font-size: 16px;
    text-align: center;
}

.main-nav {
    display: grid;
    gap: 18px;
}

.nav-group {
    display: grid;
    gap: 7px;
}

.nav-group + .nav-group {
    padding-top: 14px;
    border-top: 1px solid rgba(255, 255, 255, .1);
}

.nav-group-title {
    padding: 0 12px;
    color: #8fa2b7;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: #d8e2ed;
    text-decoration: none;
    text-align: left;
    cursor: pointer;
}

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

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

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 18px;
    margin-bottom: 24px;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 6px; font-size: clamp(24px, 3vw, 34px); }
h2 { margin-bottom: 0; font-size: 20px; }
p { color: var(--muted); }

.view { display: none; }
.view.active { display: block; }

.toolbar {
    display: flex;
    gap: 16px;
    align-items: end;
    margin-bottom: 18px;
}

.toolbar.split > div { flex: 1; }

label {
    display: grid;
    gap: 7px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 42px;
    color: var(--ink);
}

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

input, select, textarea {
    width: 100%;
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 9px 10px;
    background: #fff;
    color: var(--ink);
}

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

.grid {
    display: grid;
    gap: 18px;
    margin-bottom: 18px;
}

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

.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 20px;
    min-width: 0;
}

.panel.narrow { max-width: 860px; }

.panel-heading {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-start;
    margin-bottom: 18px;
}

.panel-heading.compact { align-items: center; }
.panel-heading p { margin-bottom: 0; }

.chart-stack {
    display: grid;
    gap: 18px;
}

.chart-stack h3 {
    margin: 0 0 10px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
    text-transform: uppercase;
}

.eyebrow {
    display: block;
    color: var(--primary);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    margin-bottom: 6px;
}

.score-badge {
    display: grid;
    place-items: center;
    min-width: 68px;
    height: 54px;
    border-radius: 8px;
    background: var(--surface-2);
    color: var(--ink);
    font-size: 24px;
    font-weight: 800;
}

.score-low { background: #fde7ea; color: var(--danger); }
.score-mid { background: #fff4d6; color: #92610f; }
.score-high { background: #dff4e8; color: var(--good); }

.criteria-list, .score-grid {
    display: grid;
    gap: 10px;
    margin-top: 18px;
}

.criteria-item, .score-item {
    display: grid;
    grid-template-columns: minmax(120px, 1fr) 110px;
    gap: 12px;
    align-items: center;
    padding: 11px 12px;
    background: var(--surface-2);
    border-radius: 8px;
}

.bar {
    height: 8px;
    border-radius: 999px;
    background: #d3dce6;
    overflow: hidden;
}

.bar span { display: block; height: 100%; border-radius: inherit; }

.highlight-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-top: 18px;
}

.history-insights {
    grid-template-columns: 1fr;
    margin-top: 0;
}

.highlight-row div {
    padding: 12px;
    border-radius: 8px;
    background: var(--surface-2);
}

.highlight-row small, .highlight-row strong { display: block; }
.highlight-row small { color: var(--muted); margin-bottom: 4px; }

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

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

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

th {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
}

.primary-btn, .secondary-btn, .danger-btn, .icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 42px;
    border: 0;
    border-radius: 8px;
    padding: 9px 14px;
    cursor: pointer;
    font-weight: 700;
}

.primary-btn { background: var(--primary); color: #fff; }
.primary-btn:hover { background: var(--primary-dark); }
.secondary-btn { background: var(--surface-2); color: var(--ink); }
.danger-btn { background: #fde7ea; color: var(--danger); }
.icon-btn { width: 40px; padding: 0; background: var(--surface-2); color: var(--ink); }

.crud-head {
    display: flex;
    justify-content: space-between;
    align-items: end;
    gap: 14px;
    margin-bottom: 16px;
}

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

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

.form-grid .full, .score-grid, .form-actions { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; }

.credentials-section {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    margin: 2px 0 4px;
    padding: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-2);
}

.credentials-section[hidden] {
    display: none;
}

.credentials-section legend {
    padding: 0 8px;
    color: var(--primary);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.employee-access-panel {
    display: grid;
    gap: 12px;
    margin-top: 4px;
}

.access-panel-head {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
}

.access-panel-head strong,
.access-panel-head small {
    display: block;
}

.access-panel-head small {
    color: var(--muted);
    margin-top: 3px;
}

.permissions-table.compact th,
.permissions-table.compact td {
    padding: 9px 8px;
}

.permissions-toolbar {
    display: grid;
    grid-template-columns: minmax(220px, 420px) auto;
    gap: 12px;
    align-items: end;
    margin-bottom: 18px;
}

.permissions-table td,
.permissions-table th {
    text-align: center;
}

.permissions-table td:first-child,
.permissions-table th:first-child {
    text-align: left;
}

.permissions-table input[type="checkbox"] {
    width: 18px;
    min-height: 18px;
}

.toast {
    position: fixed;
    right: 20px;
    bottom: 20px;
    max-width: min(420px, calc(100vw - 40px));
    padding: 13px 16px;
    border-radius: 8px;
    background: #11202f;
    color: #fff;
    box-shadow: var(--shadow);
    opacity: 0;
    transform: translateY(10px);
    pointer-events: none;
    transition: .2s ease;
}

.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--danger); }

.error-state {
    max-width: 760px;
    background: #fff;
    border-left: 5px solid var(--danger);
    padding: 22px;
    border-radius: 8px;
}

@media (max-width: 960px) {
    .app-shell,
    .app-shell.menu-collapsed {
        grid-template-columns: 1fr;
    }
    .sidebar { position: static; padding: 16px; }
    .app-shell.menu-collapsed .brand {
        justify-content: flex-start;
    }
    .app-shell.menu-collapsed .brand > div,
    .app-shell.menu-collapsed .nav-group-title {
        display: block;
    }
    .app-shell.menu-collapsed .menu-toggle {
        position: static;
        margin-left: auto;
    }
    .app-shell.menu-collapsed .main-nav {
        margin-top: 0;
        gap: 14px;
    }
    .app-shell.menu-collapsed .nav-link {
        justify-content: flex-start;
        gap: 10px;
        padding: 10px 12px;
        font-size: inherit;
    }
    .main-nav { gap: 14px; }
    .nav-group {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        align-items: start;
    }
    .nav-group-title { grid-column: 1 / -1; }
    .main { padding: 18px; }
    .topbar, .toolbar, .crud-head { flex-direction: column; align-items: stretch; }
    .grid.two, .form-grid, .permissions-toolbar, .credentials-section { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
    .nav-group { grid-template-columns: 1fr; }
    .criteria-item, .score-item, .highlight-row { grid-template-columns: 1fr; }
    th, td { padding: 10px 8px; }
}
