:root {
    color-scheme: light;
    --bg: #f5f7f9;
    --panel: #ffffff;
    --text: #17202a;
    --muted: #667085;
    --line: #d9e0e7;
    --accent: #1769aa;
    --accent-dark: #0d4f86;
    --danger: #b42318;
    --ok: #067647;
}

* {
    box-sizing: border-box;
}

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

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

.sidebar {
    background: #ffffff;
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    gap: 24px;
    padding: 22px 18px;
}

.sidebar-brand {
    display: grid;
    gap: 8px;
}

.sidebar-brand .pill {
    margin-left: 0;
    width: fit-content;
}

.side-nav {
    display: grid;
    gap: 6px;
}

.side-nav a,
.sidebar-footer a {
    border-radius: 6px;
    color: var(--text);
    display: block;
    min-height: 38px;
    padding: 9px 10px;
    text-decoration: none;
}

.side-nav a:hover,
.sidebar-footer a:hover {
    background: #eef3f7;
}

.side-nav a.active {
    background: #e8f2fb;
    color: var(--accent-dark);
    font-weight: 700;
}

.sidebar-footer {
    display: grid;
    gap: 8px;
    margin-top: auto;
}

button,
input,
select {
    font: inherit;
}

button {
    border: 0;
    border-radius: 6px;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    min-height: 40px;
    padding: 0 16px;
}

button:hover {
    background: var(--accent-dark);
}

button.secondary {
    border: 1px solid var(--line);
    background: #fff;
    color: var(--text);
}

button.secondary:hover {
    background: #eef3f7;
}

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

.button-link {
    align-items: center;
    background: var(--accent);
    border-radius: 6px;
    color: #fff;
    display: inline-flex;
    min-height: 40px;
    padding: 0 14px;
    text-decoration: none;
}

.button-link:hover {
    background: var(--accent-dark);
}

.nav-actions {
    align-items: center;
    display: flex;
    gap: 12px;
}

.nav-link {
    color: var(--text);
    text-decoration: none;
}

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

.auth-panel {
    width: min(420px, 100%);
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    padding: 28px;
    box-shadow: 0 12px 32px rgb(16 24 40 / 8%);
}

.auth-panel h1,
.page h1 {
    margin: 0 0 8px;
    font-size: 28px;
    letter-spacing: 0;
}

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

.form {
    display: grid;
    gap: 16px;
    margin-top: 22px;
}

.form label {
    display: grid;
    gap: 6px;
    color: #344054;
    font-weight: 600;
}

.form input {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    min-height: 42px;
    padding: 8px 10px;
}

.form select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    min-height: 42px;
    padding: 8px 10px;
    background: #fff;
}

.inline-form {
    align-items: end;
    grid-template-columns: 150px 150px minmax(180px, 1fr) minmax(160px, 1fr) auto;
}

.alert,
.notice {
    border-radius: 6px;
    margin-top: 16px;
    padding: 10px 12px;
}

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

.notice {
    background: #eff8ff;
    color: #175cd3;
}

.topbar {
    align-items: center;
    background: #fff;
    border-bottom: 1px solid var(--line);
    display: flex;
    justify-content: space-between;
    min-height: 58px;
    padding: 0 28px;
}

.pill {
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--muted);
    font-size: 12px;
    margin-left: 8px;
    padding: 2px 8px;
}

.pill.ok {
    border-color: #abefc6;
    color: var(--ok);
}

.pill.danger {
    border-color: #fecdca;
    color: var(--danger);
}

.page {
    margin: 0 auto;
    max-width: 1120px;
    padding: 32px 24px;
}

.page.narrow {
    max-width: 680px;
}

.title-row {
    align-items: center;
    display: flex;
    gap: 16px;
    justify-content: space-between;
}

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

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

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

.card {
    min-height: 160px;
    padding: 20px;
}

.card h2,
.panel h2 {
    font-size: 16px;
    margin: 0 0 12px;
}

.metric {
    font-size: 28px;
    font-weight: 700;
    margin: 0 0 8px;
}

.metric.ok {
    color: var(--ok);
}

.metric.bad {
    color: var(--danger);
}

.panel {
    margin-top: 16px;
    padding: 20px;
}

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

.data-table th,
.data-table td {
    border-bottom: 1px solid var(--line);
    padding: 12px 10px;
    text-align: left;
    vertical-align: top;
}

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

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

code {
    background: #f2f4f7;
    border-radius: 4px;
    padding: 2px 5px;
    word-break: break-all;
}

.kv {
    display: grid;
    gap: 5px;
    margin-bottom: 14px;
}

.kv span {
    color: var(--muted);
    font-size: 13px;
}

.filter-group {
    border-top: 1px solid var(--line);
    padding: 16px 0;
}

.filter-group h3 {
    font-size: 15px;
    margin: 0 0 10px;
}

.filter-list {
    display: grid;
    gap: 8px;
}

.filter-row {
    align-items: center;
    display: grid;
    gap: 10px;
    grid-template-columns: 22px minmax(0, 1fr) auto auto 88px;
}

.filter-code {
    color: var(--muted);
    display: block;
    font-size: 12px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    overflow-wrap: anywhere;
}

.filter-title {
    display: block;
    font-weight: 600;
}

.order-input {
    border: 1px solid var(--line);
    border-radius: 6px;
    min-height: 34px;
    padding: 4px 8px;
    width: 88px;
}

.custom-rules {
    display: grid;
    gap: 8px;
    margin-bottom: 14px;
    overflow-x: auto;
}

.custom-rule-head,
.custom-rule-row {
    align-items: stretch;
    display: grid;
    gap: 8px;
    grid-template-columns: 42px minmax(150px, 1.2fr) 92px minmax(150px, 1fr) minmax(110px, .8fr) minmax(120px, .9fr) minmax(180px, 1.4fr) 88px 58px;
    min-width: 1060px;
}

.custom-rule-head {
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
}

.custom-rule-row input,
.custom-rule-row select,
.custom-rule-row textarea {
    border: 1px solid var(--line);
    border-radius: 6px;
    font: inherit;
    min-height: 38px;
    padding: 7px 8px;
    width: 100%;
}

.custom-rule-row textarea {
    min-height: 38px;
    resize: vertical;
}

.checkbox-cell {
    align-items: center;
    display: flex;
    justify-content: center;
}

.checkbox-cell input {
    min-height: auto;
    width: auto;
}

.custom-rule-new {
    border-top: 1px solid var(--line);
    padding-top: 10px;
}

.panel ul {
    margin-bottom: 0;
    padding-left: 20px;
}

.report-filter {
    align-items: end;
    display: grid;
    gap: 12px;
    grid-template-columns: minmax(220px, 1fr) 170px 170px auto;
}

.report-filter label {
    display: grid;
    gap: 6px;
    color: #344054;
    font-weight: 600;
}

.report-filter input,
.report-filter select {
    border: 1px solid var(--line);
    border-radius: 6px;
    min-height: 40px;
    padding: 7px 9px;
}

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

.breakdown h3 {
    font-size: 14px;
    margin: 0 0 8px;
}

.breakdown-row {
    border-top: 1px solid var(--line);
    display: grid;
    gap: 6px;
    grid-template-columns: minmax(0, 1fr) auto auto;
    padding: 8px 0;
}

.breakdown-row span {
    overflow-wrap: anywhere;
}

.breakdown-row small {
    color: var(--muted);
}

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

    .sidebar {
        border-bottom: 1px solid var(--line);
        border-right: 0;
        gap: 14px;
        padding: 16px;
    }

    .sidebar-footer {
        margin-top: 0;
    }

    .report-filter,
    .breakdown-grid,
    .inline-form {
        grid-template-columns: 1fr;
    }

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

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

    .filter-row {
        grid-template-columns: 22px minmax(0, 1fr);
    }

    .filter-row .pill,
    .filter-row .order-input {
        grid-column: 2;
    }

    .topbar {
        padding: 0 16px;
    }
}
