:root {
    color-scheme: light;
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-soft: #f1f2f4;
    --ink: #191b20;
    --muted: #6e737c;
    --line: #e0e2e6;
    --primary: #b10f1b;
    --primary-dark: #7f0810;
    --accent: #d11b2a;
    --danger: #9c0710;
    --success: #1f7a4f;
    --shadow: 0 18px 50px rgba(48, 12, 16, 0.09);
}

* {
    box-sizing: border-box;
}

html {
    min-width: 320px;
}

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

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

button,
input,
select {
    font: inherit;
}

.guest-body {
    background:
        linear-gradient(120deg, rgba(177, 15, 27, 0.12), transparent 42%),
        linear-gradient(240deg, rgba(25, 27, 32, 0.08), transparent 38%),
        var(--bg);
}

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

.login-panel {
    width: min(1020px, 100%);
    min-height: 620px;
    display: grid;
    grid-template-columns: minmax(0, 1.08fr) minmax(360px, 0.92fr);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    overflow: hidden;
    position: relative;
}

.login-copy {
    background: #8d0711;
    color: white;
    padding: 36px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 12px;
}

.brand-mark {
    width: 44px;
    height: 44px;
    border-radius: 8px;
    display: grid;
    place-items: center;
    background: var(--primary);
    color: white;
    font-weight: 800;
    overflow: hidden;
    flex: 0 0 auto;
}

.brand-mark img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
}

.brand strong,
.brand small {
    display: block;
}

.brand small {
    color: rgba(255, 255, 255, 0.68);
    margin-top: 2px;
}

.login-brand .brand-mark {
    background: white;
    color: var(--primary-dark);
}

.ledger-visual {
    display: grid;
    gap: 18px;
    max-width: 440px;
}

.ledger-line {
    height: 14px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.24);
}

.ledger-line.strong {
    width: 78%;
    background: white;
}

.ledger-line.short {
    width: 54%;
}

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

.ledger-grid span {
    min-height: 72px;
    border: 1px solid rgba(255, 255, 255, 0.16);
    background: rgba(255, 255, 255, 0.08);
    border-radius: 6px;
}

.login-form {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 20px;
    padding: 56px;
}

.login-form h1,
.topbar h1 {
    margin: 4px 0 0;
    font-size: clamp(2rem, 4vw, 3rem);
    line-height: 1.02;
}

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

label {
    display: grid;
    gap: 8px;
    color: var(--muted);
    font-size: 0.88rem;
    font-weight: 700;
}

input,
select {
    width: 100%;
    min-height: 44px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: white;
    color: var(--ink);
    padding: 10px 12px;
    outline: none;
}

input:focus,
select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(177, 15, 27, 0.12);
}

.button {
    min-height: 44px;
    border: 1px solid transparent;
    border-radius: 6px;
    padding: 10px 16px;
    cursor: pointer;
    font-weight: 800;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    white-space: nowrap;
}

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

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

.button.secondary {
    background: #2b2f36;
    color: white;
}

.button.ghost {
    background: transparent;
    color: var(--primary);
    border-color: var(--line);
}

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

.button.compact {
    min-height: 36px;
    padding: 8px 12px;
    font-size: 0.84rem;
}

.button.table-action {
    min-height: 28px;
    padding: 5px 10px;
    font-size: 0.78rem;
    line-height: 1;
}

.demo-access {
    position: absolute;
    right: 56px;
    bottom: 32px;
}

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

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    gap: 28px;
    padding: 24px;
    background: #8d0711;
    color: white;
}

.sidebar .brand-mark {
    background: white;
    color: var(--primary-dark);
}

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

.nav a {
    min-height: 42px;
    display: flex;
    align-items: center;
    padding: 10px 12px;
    border-radius: 6px;
    color: rgba(255, 255, 255, 0.76);
    font-weight: 700;
}

.nav a:hover,
.nav a.is-active {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.sidebar-footer {
    margin-top: auto;
    display: grid;
    gap: 4px;
    padding-top: 18px;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
}

.sidebar-footer span {
    font-weight: 800;
}

.sidebar-footer small {
    color: rgba(255, 255, 255, 0.62);
}

.sidebar-footer a {
    color: #ffd7db;
    margin-top: 8px;
    font-weight: 800;
}

.main {
    width: min(1480px, 100%);
    padding: 28px;
}

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

.scope-pill,
.badge {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    min-height: 28px;
    padding: 5px 10px;
    border-radius: 999px;
    background: #fff1f2;
    color: var(--primary-dark);
    font-size: 0.78rem;
    font-weight: 800;
}

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

.badge.success-soft {
    background: #e8f7ef;
    color: var(--success);
}

.badge.danger-soft {
    background: #fff1ee;
    color: var(--danger);
}

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

.alert.success {
    background: #e8f7ef;
    color: var(--success);
}

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

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

.stat-card,
.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(24, 35, 45, 0.04);
}

.stat-card {
    padding: 20px;
    display: grid;
    gap: 14px;
}

.stat-card span {
    color: var(--muted);
    font-weight: 800;
}

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

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

.role-grid {
    align-items: start;
}

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

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

.panel-heading h2 {
    margin: 0;
    font-size: 1.05rem;
}

.panel-heading p {
    margin: 5px 0 0;
    color: var(--muted);
}

.panel-heading-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}

.definition-list {
    display: grid;
    gap: 12px;
    margin: 0;
}

.definition-list div {
    display: grid;
    grid-template-columns: 150px minmax(0, 1fr);
    gap: 12px;
}

.definition-list dt {
    color: var(--muted);
    font-weight: 800;
}

.definition-list dd {
    margin: 0;
    overflow-wrap: anywhere;
}

.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.chips span,
code {
    border-radius: 999px;
    background: #f4f4f5;
    color: #383c43;
    padding: 6px 10px;
    font-size: 0.82rem;
    font-weight: 800;
}

code {
    border-radius: 6px;
    font-family: "SFMono-Regular", Consolas, monospace;
}

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

.boundary-grid div {
    border-left: 3px solid var(--accent);
    padding-left: 14px;
}

.boundary-grid p {
    margin: 6px 0 0;
    color: var(--muted);
}

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

.summary-grid div {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
    background: #fbfcfd;
}

.summary-grid span {
    display: block;
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 800;
    margin-bottom: 8px;
}

.summary-grid strong {
    font-size: 1.25rem;
}

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

.company-sidebar {
    background: #8d0711;
}

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

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

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

.check-row {
    min-height: 44px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--ink);
}

.check-row input {
    width: 18px;
    min-height: 18px;
    flex: 0 0 auto;
}

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

table {
    width: 100%;
    min-width: 880px;
    border-collapse: collapse;
}

.compact-table {
    min-width: 420px;
}

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

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

td strong,
td span {
    display: block;
}

td span {
    color: var(--muted);
    margin-top: 3px;
}

.weekly-history-table td {
    vertical-align: middle;
}

.weekly-history-table td:first-child {
    vertical-align: top;
}

.weekly-history-table td:last-child {
    width: 1%;
    white-space: nowrap;
}

.actions {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    min-width: 210px;
}

details {
    position: relative;
}

summary {
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 7px 10px;
    font-weight: 800;
    cursor: pointer;
    background: white;
}

.stack-form {
    position: fixed;
    top: 50%;
    left: 50%;
    z-index: 60;
    width: min(520px, calc(100vw - 32px));
    max-height: calc(100vh - 64px);
    overflow: auto;
    transform: translate(-50%, -50%);
    display: grid;
    gap: 10px;
    margin-top: 0;
    padding: 18px;
    background: white;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

details:has(.stack-form)[open]::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(12, 22, 28, 0.46);
}

details:has(.stack-form)[open] summary {
    position: relative;
    z-index: 61;
}

.role-panel {
    display: grid;
    gap: 14px;
}

.permission-matrix {
    display: grid;
    gap: 12px;
}

fieldset {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    display: grid;
    gap: 8px;
}

legend {
    padding: 0 6px;
    color: var(--muted);
    font-weight: 800;
}

.compact-heading {
    margin-top: 18px;
}

.sales-entry {
    display: grid;
    gap: 14px;
}

.sales-category-list {
    display: grid;
    gap: 12px;
}

.sales-category {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcfd;
    padding: 10px;
}

.sales-category > summary {
    width: 100%;
    justify-content: space-between;
    border: 0;
    background: transparent;
    padding: 6px 4px 12px;
}

.sales-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
}

.sale-tile {
    min-height: 104px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(110px, 160px);
    align-items: center;
    gap: 12px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcfd;
    color: var(--ink);
}

.sale-tile strong,
.sale-tile small {
    display: block;
}

.sale-tile small {
    margin-top: 4px;
    color: var(--muted);
    font-weight: 700;
}

.sale-tile input {
    text-align: right;
}

.sale-inputs {
    display: grid;
    gap: 8px;
}

.sale-inputs input[type="text"] {
    text-align: left;
}

.manual-entry {
    margin-top: 14px;
}

.manual-entry-form {
    margin-top: 12px;
}

.category-list {
    display: grid;
    gap: 8px;
    margin-top: 14px;
}

.category-create-form {
    display: grid;
    gap: 14px;
}

.category-field-box {
    display: grid;
    gap: 10px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcfd;
}

.category-field-box strong {
    display: block;
}

.category-field-box p {
    margin: 0;
    color: var(--muted);
    font-size: 0.86rem;
}

.category-list details {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px;
    background: #fbfcfd;
}

.category-list summary {
    width: 100%;
    justify-content: space-between;
    border: 0;
    background: transparent;
    padding: 4px;
}

.stackless-form {
    display: grid;
    gap: 10px;
    margin: 10px 0;
}

.inline-edit {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.inline-edit input {
    width: 86px;
    min-height: 36px;
}

.inline-edit input[type="text"] {
    width: 180px;
}

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

    .sidebar {
        position: static;
        height: auto;
    }

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

    .form-grid,
    .section-grid,
    .role-grid,
    .boundary-grid {
        grid-template-columns: 1fr;
    }

    .span-2 {
        grid-column: auto;
    }
}

@media (max-width: 760px) {
    .login-panel {
        grid-template-columns: 1fr;
        min-height: auto;
    }

    .login-copy {
        min-height: 260px;
    }

    .login-form {
        padding: 28px;
    }

    .demo-access {
        position: static;
        padding: 0 28px 28px;
    }

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

    .topbar {
        display: grid;
    }

    .main {
        padding: 18px;
    }

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

    .definition-list div {
        grid-template-columns: 1fr;
        gap: 2px;
    }

    .actions {
        display: grid;
    }

    .stack-form {
        position: static;
        width: min(320px, 76vw);
    }
}
