:root {
    color-scheme: light;
    --bg: #f5f6f3;
    --panel: #ffffff;
    --panel-soft: #f0f3ef;
    --ink: #1b1d1f;
    --muted: #626a70;
    --line: #dce1dc;
    --brand: #0090cd;
    --brand-strong: #0074a5;
    --accent: #b77c2f;
    --danger: #a3332c;
    --ok: #217a4b;
    --shadow: 0 18px 55px rgba(20, 30, 26, 0.12);
}

* {
    box-sizing: border-box;
}

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;
    font-size: 16px;
    line-height: 1.5;
}

a {
    color: var(--brand);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

.login-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    place-items: center;
    padding: 32px 16px;
    background:
        linear-gradient(140deg, rgba(0, 144, 205, 0.15), transparent 38%),
        linear-gradient(28deg, rgba(183, 124, 47, 0.14), transparent 42%),
        var(--bg);
}

.login-card {
    width: min(100%, 440px);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 28px;
}

.brand-mark {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
}

.brand-sign {
    width: 50px;
    height: 42px;
    display: grid;
    place-items: center;
    background: var(--ink);
    color: #fff;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 800;
}

.brand-title {
    margin: 0;
    font-size: 18px;
    line-height: 1.2;
}

.brand-subtitle {
    color: var(--muted);
    font-size: 13px;
}

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

.sidebar {
    background: #151819;
    color: #fff;
    padding: 22px;
    display: flex;
    flex-direction: column;
    gap: 26px;
}

.sidebar .brand-subtitle {
    color: rgba(255, 255, 255, 0.68);
}

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

.nav a,
.nav button {
    display: flex;
    align-items: center;
    min-height: 40px;
    padding: 9px 10px;
    color: rgba(255, 255, 255, 0.78);
    border-radius: 6px;
    border: 0;
    background: transparent;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.nav a:hover,
.nav a.active,
.nav button:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    text-decoration: none;
}

.sidebar-footer {
    margin-top: auto;
    color: rgba(255, 255, 255, 0.62);
    font-size: 13px;
}

.content {
    padding: 28px;
}

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

h1,
h2,
h3 {
    margin: 0;
    line-height: 1.2;
}

h1 {
    font-size: 28px;
}

h2 {
    font-size: 20px;
}

h3 {
    font-size: 17px;
}

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

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

.panel {
    padding: 20px;
}

.stack {
    display: grid;
    gap: 16px;
}

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

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

.kpi {
    min-height: 84px;
    display: grid;
    align-content: center;
    gap: 4px;
    padding: 16px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

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

.kpi strong {
    font-size: 24px;
    line-height: 1.15;
}

.module-card {
    padding: 18px;
    min-height: 132px;
    display: grid;
    gap: 10px;
}

.module-card strong {
    font-size: 16px;
}

.badge {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    min-height: 24px;
    border-radius: 999px;
    padding: 3px 9px;
    background: var(--panel-soft);
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.badge.ok {
    background: #dcefe5;
    color: var(--ok);
}

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

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

.button,
button {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    min-height: 40px;
    padding: 9px 14px;
    border-radius: 6px;
    border: 1px solid transparent;
    background: var(--brand);
    color: #fff;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.button:hover,
button:hover {
    background: var(--brand-strong);
    color: #fff;
    text-decoration: none;
}

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

.button.secondary:hover,
button.secondary:hover {
    background: var(--panel-soft);
}

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

label {
    display: grid;
    gap: 6px;
    font-weight: 700;
}

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

textarea {
    min-height: 92px;
    resize: vertical;
}

.check {
    display: flex;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: 9px;
    font-weight: 600;
}

.check input {
    width: 18px;
    height: 18px;
    min-height: 18px;
}

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

.full {
    grid-column: 1 / -1;
}

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

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

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

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

td form {
    margin: 0;
}

.inline-form {
    margin: 0;
}

.row-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

td input,
td select {
    min-width: 110px;
}

input[type="number"] {
    text-align: right;
}

.table-wrap {
    overflow-x: auto;
}

.flash {
    padding: 12px 14px;
    border-radius: 6px;
    border: 1px solid var(--line);
    background: var(--panel);
}

.flash.error {
    border-color: #e1b4af;
    background: #fff3f1;
    color: var(--danger);
}

.flash.success {
    border-color: #b8dac9;
    background: #f0fbf5;
    color: var(--ok);
}

.secret-box {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    word-break: break-all;
    background: #101314;
    color: #eef6f3;
}

.permission-grid {
    display: grid;
    gap: 10px;
}

.permission-row {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) 180px 220px;
    gap: 12px;
    align-items: center;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--panel-soft);
}

.permission-row label {
    font-size: 13px;
}

.bulk-upload {
    margin-bottom: 18px;
}

.dropzone {
    position: relative;
    display: grid;
    place-items: center;
    gap: 8px;
    min-height: 178px;
    padding: 24px;
    border: 2px dashed #a8cbd9;
    border-radius: 8px;
    background: #f8fbfc;
    text-align: center;
    cursor: pointer;
    transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.dropzone.compact {
    min-height: 138px;
    padding: 18px;
}

.dropzone:hover,
.dropzone.is-dragover {
    border-color: var(--brand);
    background: #eef8fb;
}

.dropzone.is-dragover {
    transform: translateY(-1px);
}

.dropzone-input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.dropzone-kicker {
    color: var(--brand-strong);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.dropzone .button {
    pointer-events: none;
}

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

.file-pill {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 9px 11px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--panel-soft);
    color: var(--muted);
    font-size: 13px;
}

.receipt-workbench {
    display: grid;
    grid-template-columns: minmax(340px, 0.92fr) minmax(520px, 1.18fr);
    gap: 18px;
    align-items: start;
}

.receipt-preview-column {
    position: sticky;
    top: 20px;
}

.receipt-viewer {
    width: 100%;
    min-height: 620px;
    max-height: 76vh;
    display: grid;
    place-items: center;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #eef0ec;
}

.receipt-viewer.empty {
    min-height: 330px;
    align-content: center;
    gap: 6px;
    padding: 24px;
    text-align: center;
}

.receipt-viewer img,
.receipt-viewer iframe {
    width: 100%;
    height: 100%;
    min-height: 620px;
    border: 0;
}

.receipt-viewer img {
    object-fit: contain;
    background: #fff;
}

.stored-files {
    display: grid;
    gap: 8px;
}

.stored-file {
    width: 100%;
    min-height: 54px;
    justify-content: flex-start;
    gap: 4px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--ink);
    text-align: left;
}

.stored-file,
.stored-file strong,
.stored-file span {
    display: grid;
}

.stored-file span {
    color: var(--muted);
    font-size: 13px;
    font-weight: 500;
}

.stored-file:hover {
    border-color: var(--brand);
    background: #f8fbfc;
    color: var(--ink);
}

.stored-file.empty {
    display: block;
    cursor: default;
}

.ocr-action {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    align-items: center;
    padding-top: 4px;
}

.ocr-action div,
.ocr-meta,
.ocr-suggestions,
.ocr-suggestion,
.ocr-tax-splits {
    display: grid;
}

.ocr-action span {
    display: block;
}

.ocr-meta {
    grid-template-columns: repeat(auto-fit, minmax(120px, max-content));
    gap: 8px;
    color: var(--muted);
    font-size: 13px;
}

.ocr-panel-head {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.ocr-warnings {
    margin: 0;
    padding-left: 20px;
    color: var(--danger);
}

.ocr-suggestions {
    gap: 10px;
}

.ocr-suggestion {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    align-items: center;
    padding: 10px 0;
    border-top: 1px solid var(--line);
}

.ocr-suggestion span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.ocr-suggestion strong {
    word-break: break-word;
}

.ocr-tax-splits {
    gap: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--line);
}

.field-group {
    display: grid;
    gap: 8px;
}

.field-label {
    font-weight: 700;
}

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

.suggestion-row label {
    font-size: 13px;
}

.suggestion-picker {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    align-items: end;
}

.suggestion-picker label {
    min-width: 0;
}

.suggestion-picker button {
    min-height: 42px;
    white-space: nowrap;
}

.form-actions {
    justify-content: flex-end;
}

.suggestion-tabs .button.active,
.button.secondary.active {
    border-color: var(--brand);
    color: var(--brand-strong);
    background: #eef8fb;
}

.suggestion-admin-list {
    display: grid;
    gap: 10px;
}

.suggestion-admin-row {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) 120px 150px 120px;
    gap: 12px;
    align-items: center;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
}

.suggestion-admin-row textarea {
    min-height: 76px;
}

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

    .sidebar {
        position: static;
        gap: 16px;
    }

    .content {
        padding: 20px 16px;
    }

    .topbar,
    .form-grid,
    .permission-row,
    .receipt-workbench,
    .ocr-action,
    .ocr-suggestion,
    .suggestion-row,
    .suggestion-picker,
    .suggestion-admin-row {
        grid-template-columns: 1fr;
    }

    .topbar {
        display: grid;
    }

    .receipt-preview-column {
        position: static;
    }

    .receipt-viewer,
    .receipt-viewer img,
    .receipt-viewer iframe {
        min-height: 420px;
    }
}
