:root {
    color-scheme: light;
    --bg: #f6f7f9;
    --panel: #ffffff;
    --text: #17202a;
    --muted: #657281;
    --line: #d9dee5;
    --primary: #14532d;
    --primary-hover: #0f3f22;
    --danger: #b42318;
    --sidebar-width: 240px;
}

* {
    box-sizing: border-box;
}

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

a {
    color: inherit;
    text-decoration: none;
}

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

.sidebar {
    background: #111827;
    color: #f9fafb;
    height: 100vh;
    inset: 0 auto 0 0;
    overflow-y: auto;
    padding: 24px 18px;
    position: fixed;
    width: var(--sidebar-width);
    z-index: 100;
}

.brand {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 28px;
}

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

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

.nav a:hover,
.nav button:hover,
.nav .active {
    background: #1f2937;
    color: #ffffff;
}

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

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

h1 {
    font-size: 24px;
    line-height: 1.2;
    margin: 0;
}

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

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.button,
button.button {
    align-items: center;
    background: var(--primary);
    border: 1px solid var(--primary);
    border-radius: 6px;
    color: #ffffff;
    cursor: pointer;
    display: inline-flex;
    font: inherit;
    min-height: 38px;
    padding: 8px 14px;
}

.button:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

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

.button.secondary {
    background: #ffffff;
    border-color: var(--line);
    color: var(--text);
}

.button.danger {
    background: var(--danger);
    border-color: var(--danger);
}

.icon-button {
    align-items: center;
    background: #ffffff;
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--muted);
    cursor: pointer;
    display: inline-flex;
    font-size: 24px;
    height: 38px;
    justify-content: center;
    line-height: 1;
    width: 38px;
}

.icon-button:hover {
    color: var(--text);
}

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

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

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

.stat {
    padding: 18px;
}

.stat strong {
    display: block;
    font-size: 28px;
    line-height: 1.1;
    margin-top: 8px;
}

.panel {
    overflow: hidden;
}

.panel-header {
    align-items: center;
    border-bottom: 1px solid var(--line);
    display: flex;
    justify-content: space-between;
    padding: 16px 18px;
}

.panel-title {
    font-size: 16px;
    font-weight: 700;
    margin: 0;
}

.panel-body {
    padding: 18px;
}

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

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

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

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

.status {
    border-radius: 999px;
    display: inline-flex;
    font-size: 12px;
    font-weight: 700;
    padding: 4px 9px;
}

.status.active {
    background: #dcfce7;
    color: #166534;
}

.status.inactive {
    background: #fee2e2;
    color: #991b1b;
}

.form-grid {
    display: grid;
    gap: 16px;
    max-width: 720px;
}

.form-field {
    min-width: 0;
}

label {
    display: block;
    font-weight: 700;
    margin-bottom: 6px;
}

input,
textarea,
select {
    border: 1px solid var(--line);
    border-radius: 6px;
    font: inherit;
    min-height: 40px;
    padding: 9px 11px;
    width: 100%;
}

input[type="checkbox"] {
    min-height: auto;
    width: auto;
}

[data-uppercase] {
    text-transform: uppercase;
}

.checkbox-panel {
    border: 1px solid var(--line);
    border-radius: 6px;
    margin: 0;
    padding: 10px 12px 12px;
}

.checkbox-panel legend {
    font-weight: 700;
    padding: 0 6px;
}

.checkbox-panel ul,
.checkbox-panel > div {
    display: grid;
    gap: 8px;
    grid-template-columns: repeat(6, minmax(58px, 1fr));
    list-style: none;
    margin: 0;
    padding: 0;
}

.checkbox-panel label {
    align-items: center;
    background: #f8fafc;
    border: 1px solid var(--line);
    border-radius: 6px;
    display: flex;
    gap: 6px;
    margin: 0;
    min-height: 30px;
    padding: 5px 8px;
}

.checkbox-panel input[type="checkbox"] {
    height: 14px;
    margin: 0;
    width: 14px;
}

.span-2 {
    grid-column: 1 / -1;
}

.field-error,
.errorlist {
    color: var(--danger);
    margin: 6px 0 0;
}

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

.message {
    background: #ecfdf5;
    border: 1px solid #bbf7d0;
    border-radius: 6px;
    color: #166534;
    padding: 10px 12px;
}

.search-row {
    display: grid;
    gap: 10px;
    grid-template-columns: minmax(0, 1fr) auto;
    margin-bottom: 18px;
}

.filter-combo {
    min-width: 0;
    position: relative;
}

.filter-combo input[type="search"] {
    padding-right: 38px;
}

.filter-combo > button {
    align-items: center;
    background: transparent;
    border: 0;
    border-left: 1px solid var(--line);
    color: var(--muted);
    cursor: pointer;
    display: inline-flex;
    height: 28px;
    justify-content: center;
    line-height: 1;
    position: absolute;
    right: 6px;
    top: 6px;
    width: 28px;
}

.filter-menu {
    background: #ffffff;
    border: 1px solid var(--line);
    border-radius: 6px;
    box-shadow: 0 18px 42px rgba(15, 23, 42, 0.16);
    display: none;
    left: 0;
    max-height: 280px;
    overflow-y: auto;
    padding: 5px;
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    z-index: 30;
}

.filter-combo.is-open .filter-menu {
    display: grid;
    gap: 2px;
}

.filter-option {
    background: transparent;
    border: 0;
    border-radius: 5px;
    color: var(--text);
    cursor: pointer;
    font: inherit;
    padding: 7px 9px;
    text-align: left;
    width: 100%;
}

.filter-option:hover,
.filter-option.is-selected {
    background: #eef2f7;
}

.filter-option.is-empty {
    color: var(--muted);
}

.login-page {
    align-items: center;
    display: grid;
    min-height: 100vh;
    padding: 20px;
    place-items: center;
}

.login-panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    max-width: 420px;
    padding: 28px;
    width: 100%;
}

body.modal-open {
    overflow: hidden;
}

.modal-backdrop {
    align-items: center;
    background: rgba(15, 23, 42, 0.48);
    display: none;
    inset: 0;
    justify-content: center;
    padding: 18px 18px 18px calc(var(--sidebar-width) + 18px);
    position: fixed;
    z-index: 200;
}

.modal-backdrop.is-open {
    display: flex;
}

.modal-panel {
    background: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.8);
    border-radius: 8px;
    box-shadow: 0 24px 70px rgba(15, 23, 42, 0.28);
    max-height: min(82vh, 680px);
    overflow: hidden;
    width: min(780px, 100%);
}

.modal-header {
    align-items: center;
    border-bottom: 1px solid var(--line);
    display: flex;
    justify-content: space-between;
    padding: 12px 16px;
}

.modal-header h2 {
    font-size: 18px;
    line-height: 1.2;
    margin: 2px 0 0;
}

.modal-kicker {
    color: var(--primary);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0;
    margin: 0;
    text-transform: uppercase;
}

.compact-form {
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    min-height: 0;
}

.modal-body {
    display: grid;
    gap: 10px 12px;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    max-height: calc(82vh - 122px);
    overflow-y: auto;
    padding: 12px 16px;
}

.modal-body .half-field {
    grid-column: span 2;
}

.modal-body .compact-field {
    grid-column: span 1;
    max-width: none;
}

.modal-body input,
.modal-body select,
.modal-body textarea {
    min-height: 34px;
    padding: 7px 9px;
}

.modal-body label {
    font-size: 13px;
    margin-bottom: 4px;
}

.modal-body .errorlist {
    font-size: 13px;
}

.empty-state {
    color: var(--muted);
    padding: 14px;
}

.compact-field {
    max-width: 220px;
}

.modal-footer {
    align-items: center;
    background: #f8fafc;
    border-top: 1px solid var(--line);
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    padding: 10px 16px;
}

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

    .sidebar {
        height: auto;
        inset: auto;
        position: static;
        padding: 16px;
        width: auto;
    }

    .main {
        grid-column: auto;
        padding: 20px 16px;
    }

    .modal-backdrop {
        padding: 18px;
    }

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

    .topbar,
    .panel-header {
        align-items: flex-start;
        flex-direction: column;
    }

    .search-row {
        grid-template-columns: 1fr;
    }

    table {
        min-width: 680px;
    }

    .checkbox-panel ul,
    .checkbox-panel > div {
        grid-template-columns: repeat(3, minmax(64px, 1fr));
    }

    .modal-backdrop {
        align-items: stretch;
        padding: 10px;
    }

    .modal-panel {
        max-height: calc(100vh - 20px);
        width: 100%;
    }

    .modal-body {
        grid-template-columns: 1fr;
        max-height: calc(100vh - 158px);
    }

    .modal-body .half-field,
    .modal-body .compact-field {
        grid-column: auto;
    }

    .compact-field {
        max-width: none;
    }

    .panel {
        overflow-x: auto;
    }
}
