:root {
    color-scheme: light;
    --bg: #f6f7f9;
    --panel: #ffffff;
    --text: #17202a;
    --muted: #657281;
    --line: #d9dee5;
    --primary: #14532d;
    --primary-hover: #0f3f22;
    --danger: #b42318;
    --sidebar-width: 216px;
    --sidebar-bg-top: #111c2e;
    --sidebar-bg-bottom: #0b1420;
    --sidebar-accent: #34d399;
    --sidebar-text: #9aa7bb;
    --sidebar-text-hover: #f1f5f9;
}

* {
    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: linear-gradient(180deg, var(--sidebar-bg-top) 0%, var(--sidebar-bg-bottom) 100%);
    border-right: 1px solid rgba(255, 255, 255, 0.06);
    box-shadow: 1px 0 0 rgba(0, 0, 0, 0.15);
    color: #f9fafb;
    height: 100vh;
    inset: 0 auto 0 0;
    overflow-y: auto;
    padding: 20px 12px;
    position: fixed;
    width: var(--sidebar-width);
    z-index: 100;
}

.brand {
    align-items: center;
    color: #ffffff;
    display: flex;
    gap: 10px;
    margin-bottom: 26px;
    padding: 0 8px;
    text-decoration: none;
}

.brand:hover {
    opacity: 0.88;
}

.brand-mark {
    align-items: center;
    background: linear-gradient(135deg, var(--sidebar-accent) 0%, #0ea5e9 100%);
    border-radius: 8px;
    color: #08131a;
    display: inline-flex;
    flex-shrink: 0;
    font-size: 15px;
    font-weight: 800;
    height: 30px;
    justify-content: center;
    width: 30px;
}

.brand-text {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 0.01em;
}

.sidebar-header {
    display: block;
}

.nav-toggle {
    display: none;
}

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

.nav a,
.nav button {
    align-items: center;
    background: transparent;
    border: 0;
    border-radius: 8px;
    color: var(--sidebar-text);
    cursor: pointer;
    display: flex;
    font: inherit;
    font-size: 13.5px;
    font-weight: 600;
    gap: 11px;
    padding: 9px 10px;
    text-align: left;
    transition: background 120ms ease, color 120ms ease;
    width: 100%;
}

.nav-icon {
    flex-shrink: 0;
    height: 18px;
    opacity: 0.85;
    transition: opacity 120ms ease;
    width: 18px;
}

.nav a:hover,
.nav button:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--sidebar-text-hover);
}

.nav a:hover .nav-icon,
.nav button:hover .nav-icon {
    opacity: 1;
}

.nav .active {
    background: rgba(52, 211, 153, 0.12);
    box-shadow: inset 3px 0 0 0 var(--sidebar-accent);
    color: #ffffff;
}

.nav .active .nav-icon {
    color: var(--sidebar-accent);
    opacity: 1;
}

.nav form {
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    margin-top: 10px;
    padding-top: 10px;
}

.nav-logout:hover {
    background: rgba(248, 113, 113, 0.12);
    color: #fca5a5;
}

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

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

h1 {
    font-size: 20px;
    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: 34px;
    padding: 7px 12px;
}

.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: 20px;
    height: 34px;
    justify-content: center;
    line-height: 1;
    width: 34px;
}

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

.row-actions-compact {
    display: flex;
    gap: 5px;
    justify-content: flex-end;
}

.icon-action-btn {
    align-items: center;
    background: #ffffff;
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--muted);
    display: inline-flex;
    height: 27px;
    justify-content: center;
    transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
    width: 27px;
}

.icon-action-btn svg {
    height: 14px;
    pointer-events: none;
    width: 14px;
}

.icon-action-btn:hover {
    background: #eef6f0;
    border-color: var(--primary);
    color: var(--primary);
}

.icon-action-btn.is-active {
    background: #eef6f0;
    border-color: var(--primary);
    color: var(--primary);
}

.icon-action-btn.danger {
    cursor: pointer;
}

.icon-action-btn.danger:hover {
    background: #fdecea;
    border-color: var(--danger);
    color: var(--danger);
}

.row-actions-compact form {
    margin: 0;
    display: flex;
}

.stats {
    display: grid;
    gap: 8px;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    margin-bottom: 12px;
}

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

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

.stat {
    padding: 9px 12px;
}

.stat .muted {
    font-size: 10.5px;
    font-weight: 800;
    text-transform: uppercase;
}

.stat strong {
    display: block;
    font-size: 18px;
    line-height: 1.2;
    margin-top: 3px;
}

.panel {
    overflow: hidden;
}

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

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

.panel-body {
    padding: 14px;
}

.panel-header-inline-filters {
    flex-wrap: wrap;
    gap: 10px 16px;
}

.panel-inline-filter-form {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: 0;
}

.panel-inline-filter-form select {
    min-height: 34px;
    padding: 6px 9px;
    width: auto;
}

.panel-inline-filter-form input[type="search"] {
    min-height: 34px;
    padding: 6px 9px;
    width: 200px;
}

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

.table-scroll {
    max-height: min(68vh, 700px);
    overflow: auto;
}

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

th {
    background: var(--panel);
    color: var(--muted);
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.02em;
    position: sticky;
    text-transform: uppercase;
    top: 0;
    z-index: 5;
}

td {
    font-size: 12.5px;
    line-height: 1.35;
}

td strong {
    white-space: nowrap;
}

td .muted {
    font-size: 11px;
}

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

.col-nowrap {
    white-space: nowrap;
}

.col-actions {
    text-align: right;
}

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

@media print {
    th {
        position: static;
    }
}

.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: 34px;
    padding: 7px 10px;
    width: 100%;
}

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

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

/* Shared clickable day-filter strip (Orders, Bills, ...) — one click to
   isolate a single day's activity instead of scrolling an unfiltered list. */
.day-chip-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 12px 0 4px;
}

.day-chip-row a {
    background: #f1f5f9;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: #475569;
    font-size: 12px;
    font-weight: 700;
    padding: 5px 12px;
    white-space: nowrap;
}

.day-chip-row a:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.day-chip-row a.is-active {
    background: var(--primary);
    border-color: var(--primary);
    color: #ffffff;
}

.day-chip-nav {
    align-items: center;
    background: #f1f5f9;
    border: 1px solid var(--line);
    border-radius: 999px;
    color: #475569;
    display: inline-flex;
    font-weight: 800;
    height: 26px;
    justify-content: center;
    width: 26px;
}

.day-chip-nav:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.day-chip-nav-disabled {
    cursor: not-allowed;
    opacity: 0.35;
}

.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;
    width: 100%;
}

.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: 1024px) {
    :root {
        --sidebar-width: 176px;
    }

    .main {
        padding: 18px;
    }

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

    .modal-body .half-field {
        grid-column: 1 / -1;
    }

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

    .modal-backdrop {
        padding: 18px 18px 18px calc(var(--sidebar-width) + 18px);
    }
}

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

    .sidebar {
        height: auto;
        inset: auto;
        overflow: visible;
        padding: 0;
        position: sticky;
        top: 0;
        width: auto;
    }

    .sidebar-header {
        align-items: center;
        display: flex;
        justify-content: space-between;
        min-height: 58px;
        padding: 0 16px;
    }

    .brand {
        margin-bottom: 0;
    }

    .nav-toggle {
        align-content: center;
        align-items: center;
        background: #1f2937;
        border: 1px solid rgba(255, 255, 255, 0.14);
        border-radius: 6px;
        color: #ffffff;
        cursor: pointer;
        display: inline-grid;
        gap: 4px;
        height: 38px;
        justify-content: center;
        padding: 0;
        width: 38px;
    }

    .nav-toggle span {
        background: currentColor;
        border-radius: 999px;
        display: block;
        height: 2px;
        transition: transform 160ms ease, opacity 160ms ease;
        width: 18px;
    }

    .sidebar.is-open .nav-toggle span:nth-child(1) {
        transform: translateY(6px) rotate(45deg);
    }

    .sidebar.is-open .nav-toggle span:nth-child(2) {
        opacity: 0;
    }

    .sidebar.is-open .nav-toggle span:nth-child(3) {
        transform: translateY(-6px) rotate(-45deg);
    }

    .sidebar .nav {
        border-top: 1px solid rgba(255, 255, 255, 0.1);
        display: none;
        gap: 8px;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        padding: 12px 16px 16px;
    }

    .sidebar.is-open .nav {
        display: grid;
    }

    .nav form {
        grid-column: 1 / -1;
    }

    .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;
    }

    .topbar .actions,
    .panel-header .actions {
        width: 100%;
    }

    .actions .button,
    .actions button.button {
        justify-content: center;
    }

    .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;
    }
}

@media (max-width: 520px) {
    .main {
        padding: 16px 12px;
    }

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

    .sidebar .nav form {
        grid-column: 1 / -1;
    }

    .actions {
        display: grid;
        grid-template-columns: 1fr;
    }

    .button,
    button.button {
        width: 100%;
    }
}
