:root {
    color-scheme: light;
    --bg: #f6f7f2;
    --surface: #ffffff;
    --surface-strong: #f0f3ef;
    --ink: #17212b;
    --muted: #64707d;
    --line: #d9dfd6;
    --focus: #1d5fd0;
    --blue: #215db8;
    --blue-soft: #e8f0ff;
    --green: #14735f;
    --green-soft: #e4f4ee;
    --amber: #8a5a00;
    --amber-soft: #fff2cf;
    --red: #b42318;
    --red-soft: #ffe8e5;
    --slate: #4e5c6d;
    --slate-soft: #edf0f4;
    --shadow: 0 14px 40px rgba(23, 33, 43, 0.08);
    --shadow-soft: 0 8px 26px rgba(23, 33, 43, 0.05);
    --radius: 8px;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
}

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

a {
    color: var(--blue);
}

a:hover {
    color: #123f86;
}

button,
input,
select {
    font: inherit;
}

button,
a,
input,
select,
.ts-control {
    outline-offset: 3px;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
.ts-control:focus-within {
    outline: 3px solid rgba(29, 95, 208, 0.45);
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.skip-link {
    position: absolute;
    left: 1rem;
    top: 1rem;
    z-index: 30;
    transform: translateY(-140%);
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    background: var(--ink);
    color: #fff;
}

.skip-link:focus {
    transform: translateY(0);
}

.auth-page {
    background:
        linear-gradient(90deg, rgba(20, 115, 95, 0.08), transparent 45%),
        var(--bg);
}

.auth-frame {
    width: min(100%, 1120px);
    min-height: 100vh;
    margin: 0 auto;
    padding: 2rem;
    display: grid;
    place-items: center;
}

.auth-panel {
    width: min(100%, 920px);
    display: grid;
    grid-template-columns: 1fr minmax(320px, 420px);
    gap: 2rem;
    padding: 2rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.auth-panel--compact {
    display: block;
    max-width: 620px;
}

.auth-copy {
    align-self: center;
    padding-right: 1rem;
}

.auth-form {
    align-self: center;
    display: grid;
    gap: 1rem;
}

.auth-note {
    margin: 0;
    text-align: center;
}

.eyebrow {
    margin: 0 0 0.35rem;
    color: var(--green);
    font-size: 0.76rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0;
}

h1,
h2,
h3,
p {
    overflow-wrap: anywhere;
}

h1,
h2 {
    margin: 0;
    line-height: 1.15;
    letter-spacing: 0;
}

h1 {
    font-size: 2rem;
}

h2 {
    font-size: 1.2rem;
}

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

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    min-height: 72px;
    padding: 0.8rem 1.25rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(10px);
}

.brand {
    color: var(--ink);
    font-size: 1.2rem;
    font-weight: 800;
    text-decoration: none;
}

.layout {
    display: grid;
    grid-template-columns: 240px minmax(0, 1fr);
    min-height: calc(100vh - 72px);
}

.sidebar {
    position: sticky;
    top: 72px;
    align-self: start;
    min-height: calc(100vh - 72px);
    padding: 1rem;
    border-right: 1px solid var(--line);
    background: var(--surface);
}

.nav-link {
    min-height: 44px;
    display: flex;
    align-items: center;
    gap: 0.65rem;
    width: 100%;
    padding: 0.75rem 0.85rem;
    border-radius: var(--radius);
    color: var(--ink);
    text-decoration: none;
    font-weight: 700;
}

.nav-link:hover,
.nav-link.is-active {
    background: var(--surface-strong);
    color: var(--ink);
}

.nav-link .bi,
.button .bi {
    flex: 0 0 auto;
    font-size: 1rem;
    line-height: 1;
}

.nav-button {
    border: 0;
    background: transparent;
    cursor: pointer;
}

.nav-form {
    margin: 0.35rem 0 0;
}

.user-chip {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    min-width: 0;
    color: var(--muted);
    font-size: 0.86rem;
}

.user-chip span,
.user-chip strong {
    max-width: 260px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-chip strong {
    color: var(--ink);
}

.menu-toggle {
    display: none;
}

.content {
    width: min(100%, 1180px);
    margin: 0 auto;
    padding: 1.5rem;
}

.content.narrow {
    width: min(100%, 860px);
}

.hero-band {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(220px, 320px);
    gap: 1.25rem;
    align-items: end;
    margin-bottom: 1rem;
    padding: 1.5rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #eef5f1;
}

.hero-band p:last-child {
    margin-bottom: 0;
}

.hero-meta {
    display: grid;
    gap: 0.2rem;
    padding: 1rem;
    border: 1px solid rgba(20, 115, 95, 0.25);
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.58);
}

.hero-meta span {
    color: var(--muted);
    font-size: 0.9rem;
}

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

.stat-card,
.panel {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-soft);
}

.stat-card {
    min-height: 118px;
    padding: 1rem;
    display: grid;
    align-content: space-between;
}

.stat-card span {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    color: var(--muted);
    font-weight: 700;
}

.stat-card strong {
    font-size: 2rem;
    line-height: 1;
}

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

.panel {
    padding: 1rem;
}

.panel-table {
    padding: 0;
    overflow: hidden;
}

.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.section-heading-compact {
    padding: 1rem 1rem 0;
}

.role-list,
.meter-list,
.actions,
.form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: center;
}

.meter-list {
    display: grid;
}

.meter-row {
    display: grid;
    grid-template-columns: minmax(120px, 1fr) auto;
    gap: 1rem;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--line);
}

.meter-row meter {
    grid-column: 1 / -1;
    width: 100%;
}

.meter-row:last-child {
    border-bottom: 0;
}

.form-stack,
.form-grid {
    display: grid;
    gap: 1rem;
}

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

.field,
.field-wide {
    display: grid;
    gap: 0.35rem;
}

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

label {
    font-weight: 750;
}

input,
select,
.ts-control {
    width: 100%;
    min-height: 44px;
    border: 1px solid #c6cec3;
    border-radius: var(--radius);
    padding: 0.7rem 0.75rem;
    color: var(--ink);
    background: #fff;
}

input[aria-invalid="true"],
select[aria-invalid="true"],
.ts-wrapper.is-invalid .ts-control {
    border-color: var(--red);
    box-shadow: 0 0 0 3px rgba(180, 35, 24, 0.12);
}

.ts-wrapper.single .ts-control,
.ts-wrapper.multi .ts-control {
    box-shadow: none;
}

.ts-wrapper.is-invalid .ts-control {
    border-color: var(--red);
    box-shadow: 0 0 0 3px rgba(180, 35, 24, 0.12);
}

.ts-dropdown {
    border-color: #c6cec3;
    border-radius: var(--radius);
}

.ts-dropdown .active {
    background: var(--surface-strong);
    color: var(--ink);
}

input:disabled {
    color: var(--muted);
    background: var(--surface-strong);
}

.password-control {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.5rem;
}

.filter-bar {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) minmax(180px, 260px) auto;
    gap: 1rem;
    align-items: end;
}

.button {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.68rem 0.95rem;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-weight: 800;
    text-decoration: none;
    cursor: pointer;
}

.button[disabled],
.button.is-loading {
    cursor: progress;
    opacity: 0.72;
}

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

.button-primary:hover {
    color: #fff;
    background: #0a1118;
}

.button-secondary {
    border-color: var(--line);
    background: var(--surface);
    color: var(--ink);
}

.button-secondary:hover {
    color: var(--ink);
    background: var(--surface-strong);
}

.button-ghost {
    border-color: transparent;
    background: var(--surface-strong);
    color: var(--ink);
}

.button-small {
    min-height: 38px;
    padding: 0.45rem 0.65rem;
    font-size: 0.9rem;
}

.button-full {
    width: 100%;
}

.alert {
    margin-bottom: 1rem;
    padding: 0.85rem 1rem;
    border-radius: var(--radius);
    border: 1px solid var(--line);
    font-weight: 700;
}

.alert-success {
    border-color: #b9ded1;
    background: var(--green-soft);
    color: #0f4d41;
}

.alert-warning {
    border-color: #f2d789;
    background: var(--amber-soft);
    color: #5f3e00;
}

.alert-danger {
    border-color: #f0b7b1;
    background: var(--red-soft);
    color: #7c1a12;
}

.error-summary {
    margin: 1rem 0;
    padding: 1rem;
    border: 1px solid #f0b7b1;
    border-radius: var(--radius);
    background: var(--red-soft);
    color: #7c1a12;
}

.error-summary strong {
    display: block;
    margin-bottom: 0.5rem;
}

.error-summary ul {
    margin: 0;
    padding-left: 1.2rem;
}

.error-summary a {
    color: #7c1a12;
    font-weight: 800;
}

.confirm-dialog {
    width: min(92vw, 460px);
    padding: 0;
    border: 0;
    border-radius: var(--radius);
    background: transparent;
}

.confirm-dialog::backdrop {
    background: rgba(23, 33, 43, 0.48);
}

.confirm-dialog-panel {
    display: grid;
    gap: 0.8rem;
    margin: 0;
    padding: 1.25rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.field-error {
    margin: 0;
    color: var(--red);
    font-size: 0.92rem;
    font-weight: 700;
}

.field-hint {
    margin: 0;
    color: var(--muted);
    font-size: 0.9rem;
}

.password-meter {
    width: 100%;
    height: 0.5rem;
}

.empty-state {
    display: grid;
    justify-items: center;
    gap: 0.75rem;
    padding: 2rem 1rem;
    color: var(--muted);
    text-align: center;
}

.empty-state .bi {
    display: grid;
    place-items: center;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--surface-strong);
    color: var(--green);
    font-size: 1.35rem;
}

.empty-state h3,
.empty-state p {
    margin: 0;
}

.empty-state h3 {
    color: var(--ink);
    font-size: 1.05rem;
}

.badge {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    font-size: 0.84rem;
    font-weight: 800;
    white-space: nowrap;
}

.badge-ink {
    background: #e8e9e7;
    color: var(--ink);
}

.badge-blue {
    background: var(--blue-soft);
    color: var(--blue);
}

.badge-green {
    background: var(--green-soft);
    color: var(--green);
}

.badge-amber {
    background: var(--amber-soft);
    color: var(--amber);
}

.badge-red {
    background: var(--red-soft);
    color: var(--red);
}

.badge-slate {
    background: var(--slate-soft);
    color: var(--slate);
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
}

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

th,
td {
    padding: 0.9rem 1rem;
    border-top: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}

tbody tr:hover {
    background: #fbfcfa;
}

th {
    color: var(--muted);
    font-size: 0.86rem;
    text-transform: uppercase;
    letter-spacing: 0;
    background: #fbfcfa;
}

.cell-subtitle {
    display: block;
    margin-top: 0.15rem;
    color: var(--muted);
    font-size: 0.9rem;
}

.pagination {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem;
    border-top: 1px solid var(--line);
}

.form-actions {
    grid-column: 1 / -1;
    padding-top: 0.25rem;
}

@media (prefers-reduced-motion: no-preference) {
    .nav-link,
    .button {
        transition: background-color 140ms ease, color 140ms ease, border-color 140ms ease;
    }
}

@media (max-width: 900px) {
    .auth-panel,
    .hero-band,
    .split-grid,
    .form-grid {
        grid-template-columns: 1fr;
    }

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

    .layout {
        grid-template-columns: 1fr;
    }

    .sidebar {
        display: none;
        position: static;
        min-height: auto;
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

    .sidebar.is-open {
        display: block;
    }

    .menu-toggle {
        min-height: 42px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        padding: 0.55rem 0.75rem;
        border: 1px solid var(--line);
        border-radius: var(--radius);
        background: var(--surface);
        font-weight: 800;
    }

    .user-chip {
        display: none;
    }

    .content {
        padding: 1rem;
    }
}

@media (max-width: 620px) {
    .auth-frame {
        padding: 1rem;
    }

    .auth-panel {
        padding: 1rem;
    }

    .stats-grid,
    .filter-bar,
    .password-control,
    .pagination {
        grid-template-columns: 1fr;
    }

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

    .section-heading {
        align-items: stretch;
        flex-direction: column;
    }

    .section-heading .button {
        width: 100%;
    }

    .topbar {
        align-items: flex-start;
        flex-wrap: wrap;
    }

    .pagination {
        display: grid;
        justify-items: stretch;
    }

    th,
    td {
        padding: 0.8rem;
    }
}
