@import url('https://fonts.googleapis.com/css2?family=Archivo:ital,wght@0,400;0,600;0,700;0,800;1,400&display=swap');

:root {
    /* Modernist token sheet — Hwayang invoice/accounting system design, 2026-08-27 */
    --bg: #f3f2f2;
    --panel: #f3f2f2;
    --panel-inset: #eae9e9;
    --placeholder: #d7d3d3;
    --border: rgba(32, 30, 29, .18);
    --border-strong: rgba(32, 30, 29, .4);
    --text: #201e1d;
    --text-dim: rgba(32, 30, 29, .6);
    --text-faint: rgba(32, 30, 29, .5);
    --text-disabled: rgba(32, 30, 29, .45);
    --accent: #ec3013;
    --accent-deep: #ae1800;
    --accent-700: #7c1405;
    --accent-dim: #ffe0d9;
    --danger: #ec3013;
    --danger-dim: #ffe0d9;
    --success: #ae1800;
    --success-dim: var(--panel-inset);
    --warn: #ae1800;
    --warn-dim: #ffe0d9;
    --radius: 0px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: Archivo, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
}

a { color: var(--accent-deep); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- app shell: desktop sidebar / mobile top bar + bottom tabs ---------- */

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    flex: none;
    width: 224px;
    background: var(--panel);
    border-right: 2px solid var(--border-strong);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}
.sidebar .brand { padding: 20px 20px 16px; font: 800 15px/1.1 Archivo, sans-serif; }
.sidebar .brand span { color: var(--accent); }
.sidebar nav { flex: 1; overflow-y: auto; }
.sidebar nav a, .sidebar nav .nav-locked {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 11px 20px;
    font: 800 13px/1.2 Archivo, sans-serif;
    color: var(--text);
}
.sidebar nav a:hover { background: var(--panel-inset); text-decoration: none; }
.sidebar nav a.active { background: var(--accent-dim); box-shadow: inset 3px 0 0 var(--accent); color: var(--accent-700); }
.sidebar nav .nav-locked { color: var(--text-disabled); cursor: not-allowed; }
.sidebar nav .nav-locked .lock-label { font: 400 10px/1 Archivo, sans-serif; text-transform: uppercase; letter-spacing: .06em; }
.sidebar nav .queue-count { color: var(--accent); }
.sidebar-footer {
    border-top: 2px solid var(--border-strong);
    padding: 14px 20px;
    font-size: 12px;
}
.sidebar-footer .name { font-weight: 800; }
.sidebar-footer .role { color: var(--text-dim); text-transform: capitalize; }
.sidebar-footer a { display: block; margin-top: 8px; font: 800 12px/1 Archivo, sans-serif; color: var(--accent-deep); }

.topbar {
    display: none;
    align-items: flex-end;
    gap: 10px;
    padding: 60px 16px 10px;
    background: var(--panel);
    border-bottom: 2px solid var(--border-strong);
    position: sticky;
    top: 0;
    z-index: 5;
}
.topbar .brand { font: 800 17px/1.1 Archivo, sans-serif; letter-spacing: -.015em; }
.topbar .brand span { color: var(--accent); }
.topbar .user-tag {
    margin-left: auto;
    font: 400 11px/1.2 Archivo, sans-serif;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--text-dim);
}
.topbar nav { display: none; }
.topbar .logout-link { display: none; }

.tab-bar {
    display: none;
    flex: none;
    border-top: 2px solid var(--border-strong);
    padding-bottom: env(safe-area-inset-bottom, 12px);
    background: var(--panel);
    position: sticky;
    bottom: 0;
    z-index: 5;
}
.tab-bar a {
    flex: 1;
    padding: 12px 6px 10px;
    border-top: 2px solid transparent;
    margin-top: -2px;
    background: none;
    text-align: center;
    font: 800 11px/1 Archivo, sans-serif;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--text-dim);
}
.tab-bar a.active { border-top-color: var(--accent); color: var(--accent); }
.tab-bar a .tab-badge { display: block; margin-top: 4px; font: 800 10px/1 Archivo, sans-serif; color: var(--accent); }
.tab-bar a.active .tab-badge { color: var(--accent); }

.main-column { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.container {
    max-width: 1080px;
    margin: 0 auto;
    padding: 24px;
    width: 100%;
}

.container.narrow { max-width: 480px; }

@media (max-width: 860px) {
    .app-shell { display: block; }
    .sidebar { display: none; }
    .topbar { display: flex; }
    .tab-bar { display: flex; }
    .container { padding: 16px; }
    .container.narrow { padding-top: 16px; }
}

.card {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
}

h1 { font: 800 26px/1.1 Archivo, sans-serif; letter-spacing: -.02em; margin: 0 0 6px; }
h2 { font: 800 18px/1.15 Archivo, sans-serif; letter-spacing: -.01em; margin: 0 0 12px; }
h3 { font: 400 11px/1 Archivo, sans-serif; text-transform: uppercase; letter-spacing: .08em; color: var(--text-dim); margin: 0 0 10px; }
.subtitle { color: var(--text-dim); margin: 0 0 20px; font-size: 13px; }

.flash-list { list-style: none; padding: 0; margin: 0 0 16px; }
.flash {
    padding: 10px 14px;
    border-radius: var(--radius);
    margin-bottom: 8px;
    font-size: 13px;
    border: 1px solid transparent;
}
.flash.error { background: var(--danger-dim); color: var(--danger); border-color: var(--danger); }
.flash.success { background: var(--success-dim); color: var(--success); border-color: var(--success); }
.flash.warning { background: var(--warn-dim); color: var(--warn); border-color: var(--warn); }

.summary-row { display: flex; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.summary-tile {
    flex: 1 1 140px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
}
.summary-tile .num { font-size: 24px; font-weight: 700; }
.summary-tile .label { color: var(--text-dim); font-size: 12px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); font-size: 13px; }
th { color: var(--text-dim); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.02em; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; }

/* Record lists (supplier invoices, claims, sales invoices) render as a real
   .table on desktop and a stacked row-list of cards on mobile, matching the
   design's phone pattern — a wide table with sideways scroll reads as
   desktop-in-miniature, not a phone layout. Both are emitted by the same
   Jinja loop from the same data; only one is ever visible at a time. */
.desktop-table-wrap { display: block; }
.row-list { display: none; }
.row-list-item {
    display: block;
    width: 100%;
    padding: 14px 0;
    border-top: 1px solid var(--border);
    background: none;
    border-left: 0; border-right: 0; border-bottom: 0;
    text-align: left;
    font-family: inherit;
    color: inherit;
    cursor: pointer;
}
.row-list-item:first-child { border-top: none; }
/* Rows that hold a link plus their own buttons (e.g. a PDF download) */
.row-list-item > .rli-link { display: block; color: inherit; text-decoration: none; }
.row-list-item:hover { text-decoration: none; background: var(--panel-inset); }
.row-list-item .rli-top { display: flex; gap: 10px; align-items: flex-start; }
.row-list-item .rli-main { flex: 1; min-width: 0; }
.row-list-item .rli-title { font: 800 14px/1.25 Archivo, sans-serif; }
.row-list-item .rli-meta { font: 400 12px/1.35 Archivo, sans-serif; color: var(--text-dim); margin-top: 4px; }
.row-list-item .rli-tags { margin-top: 8px; display: flex; gap: 6px; flex-wrap: wrap; }
.row-list-item .rli-side { text-align: right; flex: none; }
.row-list-item .rli-amount { font: 800 15px/1.2 Archivo, sans-serif; font-variant-numeric: tabular-nums; }
.row-list-item .rli-id { font: 400 11px/1 Archivo, sans-serif; color: var(--text-faint); margin-top: 4px; }
.row-list-item .rli-actions { margin-top: 10px; display: flex; gap: 8px; }

@media (max-width: 700px) {
    .desktop-table-wrap { display: none; }
    .row-list { display: block; }
}

/* Tags — three variants only, matching the design system's restraint:
   accent = needs attention / pending action, neutral = informational,
   outline = flagged / de-emphasized. Old .badge-* names are mapped onto
   these three below so existing templates don't need touching yet. */
.badge, .tag {
    display: inline-block;
    padding: 3px 9px;
    border-radius: var(--radius);
    font: 400 10px/1.3 Archivo, sans-serif;
    text-transform: uppercase;
    letter-spacing: .06em;
}
.tag-accent, .badge-pending_approval, .badge-submitted, .badge-sent, .badge-finalized, .badge-approved {
    background: var(--accent); color: #fff;
}
.tag-neutral, .badge-extracted, .badge-draft, .badge-approved_paid, .badge-reimbursed, .badge-paid {
    background: var(--panel-inset); color: var(--text-dim);
}
.tag-outline, .badge-rejected, .badge-overdue, .badge-cancelled, .badge-duplicate {
    background: none; color: var(--accent-700); border: 1px solid var(--accent);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 44px;
    padding: 0 18px;
    border-radius: var(--radius);
    border: 1px solid var(--border-strong);
    background: none;
    color: var(--text);
    font: 800 14px/1 Archivo, sans-serif;
    cursor: pointer;
    font-family: inherit;
    transition: background .12s ease, color .12s ease;
}
.btn:hover { background: var(--panel-inset); text-decoration: none; }
.btn:active { background: var(--panel-inset); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { background: rgba(32, 30, 29, .18); color: var(--text-disabled); border-color: transparent; cursor: not-allowed; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #cf2a10; border-color: #cf2a10; }

.btn-danger { background: var(--text); border-color: var(--text); color: var(--panel); }
.btn-danger:hover { background: #3a3634; border-color: #3a3634; }

.btn-sm { min-height: 34px; padding: 0 12px; font-size: 12px; }
.btn-block { width: 100%; justify-content: flex-start; text-align: left; }

.actions-row { display: flex; gap: 10px; margin-top: 4px; flex-wrap: wrap; }

label { display: block; font-size: 12px; font-weight: 600; color: var(--text-dim); margin-bottom: 4px; }
input[type=text], input[type=number], input[type=date], input[type=email], input[type=password], input[type=tel], select, textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    font-family: inherit;
    background: var(--panel);
    color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
.field { margin-bottom: 14px; }
.upload-choice { display: flex; gap: 10px; }
.upload-choice .btn { flex: 1; padding: 14px 10px; font-size: 14px; }
.file-chosen-note { margin-top: 8px; font-size: 12px; color: var(--text-dim); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
/* Two fields side by side are too narrow on a phone (a date picker in
   particular), so rows stack there. */
@media (max-width: 560px) { .field-row { grid-template-columns: 1fr; } }
.field input, .field select { min-width: 0; }
/* Section headings inside forms: an h2 for the outline, sized like h3. */
h2.form-section { font: 400 11px/1 Archivo, sans-serif; text-transform: uppercase; letter-spacing: .08em; color: var(--text-dim); margin: 18px 0 10px; }
.field-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.checkbox-field { display: flex; align-items: center; }
.checkbox-label { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 400; color: var(--text); cursor: pointer; margin-bottom: 0; }
.checkbox-label input[type=checkbox] { width: 16px; height: 16px; margin: 0; }

/* Side-by-side image+fields review is the reason desktop exists for this
   flow — stays two-pane down to ~1100px, only collapses below that. */
.layout-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 1100px) { .layout-2col { grid-template-columns: 1fr; } }

.field-grid-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 20px; }
.field-grid-2col .review-field.span-2 { grid-column: 1 / -1; }
@media (max-width: 560px) { .field-grid-2col { grid-template-columns: 1fr; } }

.image-toolbar {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 10px; margin: -10px -10px 10px; background: var(--panel-inset);
    font: 400 11px/1 Archivo, sans-serif; letter-spacing: .06em; text-transform: uppercase; color: var(--text-dim);
}

.readonly-fields { display: flex; flex-direction: column; }
.readonly-field { display: flex; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border); }
.readonly-field .k { flex: none; width: 150px; font: 400 11px/1.4 Archivo, sans-serif; letter-spacing: .06em; text-transform: uppercase; color: var(--text-dim); }
.readonly-field .v { font: 400 13px/1.4 Archivo, sans-serif; font-variant-numeric: tabular-nums; }
.readonly-field:last-child { border-bottom: none; }

.month-chart { display: flex; flex-direction: column; gap: 6px; }
.month-chart-row { display: grid; grid-template-columns: 40px 1fr 90px; align-items: center; gap: 10px; }
.month-chart-label { font-size: 12px; color: var(--text-dim); }
.month-chart-bar-track { background: var(--bg); border-radius: 0; height: 16px; overflow: hidden; }
.month-chart-bar { background: var(--accent); height: 100%; border-radius: 0; min-width: 2px; }
.month-chart-value { font-size: 12px; text-align: right; color: var(--text-dim); }

.invoice-image-wrap {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px;
    position: sticky;
    top: 20px;
}
@media (max-width: 1100px) {
    /* .layout-2col collapses to one column here — sticky has no side-by-side
       form to stay level with, and an uncapped photo would otherwise fill
       the whole screen with nothing else visible below it. */
    .invoice-image-wrap { position: static; }
    .invoice-image-wrap img { max-height: 50vh; object-fit: contain; }
}
.invoice-image-wrap img { width: 100%; border-radius: 0; display: block; }
.invoice-image-wrap .no-preview {
    padding: 40px 10px;
    text-align: center;
    color: var(--text-dim);
    background: var(--bg);
    border-radius: 0;
}

.items-table input { padding: 6px 8px; }
.items-table td { vertical-align: middle; }
.items-table .remove-row { color: var(--danger); cursor: pointer; background: none; border: none; font-size: 16px; }
.items-total-row td { font-weight: 700; border-top: 2px solid var(--border); }

.receipt-status { margin-top: 4px; font: 400 11px/1.3 Archivo, sans-serif; color: var(--accent-deep); }
.receipt-status.receipt-attached { color: var(--text-dim); }

/* AI self-check field gating — a field flagged low-confidence gets an accent
   left-edge + "Looks right" button; confirming it swaps in a quiet
   "Confirmed" label. Shared between the invoice review screen and claim
   receipt capture, both feeding the same "AI read something, verify before
   submitting" pattern. */
.review-field-flagged input { border-color: var(--accent); box-shadow: inset 3px 0 0 var(--accent); }
.review-field.field-confirmed input { border-color: var(--border); box-shadow: none; }
.review-field.field-confirmed .field-status-tag { display: none; }
.review-field.field-confirmed .confirm-field-btn { display: none; }
.review-field.field-confirmed::after { content: 'Confirmed'; display: block; font: 400 11px/1 Archivo, sans-serif; text-transform: uppercase; letter-spacing: .06em; color: var(--accent-deep); margin-top: 6px; }

.claim-item-card { border: 1px solid var(--border); padding: 14px; margin-bottom: 12px; }
/* Receipt fields (date/company, amount/column) go one per line on phones —
   two side by side are too narrow for a date picker or "Subscription / licence". */
@media (max-width: 560px) { .claim-item-card .field-row { grid-template-columns: 1fr; } }
.claim-item-card .field input, .claim-item-card .field select { min-width: 0; }
.claim-item-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.claim-item-header .claim-item-num { font: 800 12px/1 Archivo, sans-serif; text-transform: uppercase; letter-spacing: .06em; color: var(--text-dim); }
.claim-item-header .remove-row { border: 0; background: none; color: var(--accent-deep); cursor: pointer; font: 800 12px/1 Archivo, sans-serif; padding: 0; }
.extract-loading { margin-top: 8px; font: 400 12px/1.4 Archivo, sans-serif; color: var(--text-dim); }
.extract-loading::before { content: ''; display: inline-block; width: 10px; height: 10px; margin-right: 6px; border: 2px solid var(--border-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; vertical-align: -1px; }
@keyframes spin { to { transform: rotate(360deg); } }

.activity-list { list-style: none; padding: 0; margin: 0; }
.activity-list li { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 12px; }
.activity-list li:last-child { border-bottom: none; }
.activity-list .who { font-weight: 600; }
.activity-list .when { color: var(--text-dim); float: right; }
.activity-list .action-tag {
    display: inline-block;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--accent);
    margin-right: 6px;
}

.batch-approve-panel {
    margin-top: 18px;
    padding: 16px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.batch-approve-panel h3 { margin-bottom: 8px; }
#batch-summary.warn { color: var(--danger); }
.approve-checkbox { width: 16px; height: 16px; }

.rejection-banner {
    background: var(--danger-dim);
    color: var(--danger);
    border: 1px solid var(--danger);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-bottom: 16px;
    font-size: 13px;
}
.rejection-banner strong { display: block; margin-bottom: 2px; }

.duplicate-banner {
    background: var(--warn-dim);
    color: var(--warn);
    border: 1px solid var(--warn);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-bottom: 16px;
    font-size: 13px;
}
.duplicate-banner strong { display: block; margin-bottom: 2px; }
.duplicate-banner a { color: var(--warn); text-decoration: underline; }

.badge-duplicate {
    background: var(--warn-dim);
    color: var(--warn);
    border: 1px solid var(--warn);
    font-size: 10px;
    margin-left: 6px;
}

.low-confidence-note {
    background: var(--warn-dim);
    color: var(--warn);
    border: 1px solid var(--warn);
    border-radius: var(--radius);
    padding: 10px 14px;
    margin-bottom: 16px;
    font-size: 12px;
}

.dashboard-header { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 20px; flex-wrap: wrap; gap: 10px; }
/* Mobile primary actions go full-width and stack, per the design's phone
   convention — a header's title + its action buttons wrapping side-by-side
   reads as desktop-in-miniature, not a phone layout. Must come after the
   base .dashboard-header rule above: equal specificity, so source order
   decides, and @media alone doesn't add specificity. */
@media (max-width: 860px) {
    .dashboard-header { flex-direction: column; align-items: stretch; }
    .dashboard-header .actions-row { flex-direction: column; align-items: stretch; }
    .dashboard-header .actions-row .btn { width: 100%; justify-content: flex-start; text-align: left; }
}

.filter-tabs { display: flex; flex-wrap: wrap; gap: 2px; margin-bottom: 16px; }
.filter-tabs a {
    padding: 8px 14px;
    background: var(--panel-inset);
    color: var(--text-dim);
    font: 800 12px/1 Archivo, sans-serif;
    letter-spacing: .02em;
}
.filter-tabs a:hover { background: rgba(32, 30, 29, .12); text-decoration: none; }
.filter-tabs a.active { background: var(--accent); color: #fff; }
.filter-tab-count { opacity: .75; font-weight: 400; }
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-dim); }

.pagination { display: flex; align-items: center; justify-content: center; gap: 16px; margin-top: 18px; }
.pagination-label { font-size: 13px; color: var(--text-dim); }

.pnl-summary-row { display: flex; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.pnl-tile { flex: 1 1 160px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.pnl-tile .num { font-size: 26px; font-weight: 700; }
.pnl-tile .label { color: var(--text-dim); font-size: 12px; margin-top: 2px; }
.pnl-tile.profit .num { color: var(--success); }
.pnl-tile.loss .num { color: var(--danger); }
.pnl-filter-row { display: flex; gap: 14px; align-items: flex-end; margin-bottom: 20px; flex-wrap: wrap; }
.pnl-filter-row .field { margin-bottom: 0; }

.claim-total-block {
    margin-top: 16px;
    padding: 14px 16px;
    background: var(--text);
    color: var(--panel);
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}
.claim-total-block span { font: 400 11px/1 Archivo, sans-serif; letter-spacing: .08em; text-transform: uppercase; }
.claim-total-block strong { font: 800 22px/1 Archivo, sans-serif; font-variant-numeric: tabular-nums; }

.supplier-group { margin-bottom: 20px; }
.supplier-group:last-child { margin-bottom: 0; }
.supplier-group-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 8px 10px;
    background: var(--panel-inset);
    font: 800 12px/1 Archivo, sans-serif;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.supplier-group-header span:last-child { font-variant-numeric: tabular-nums; }

.voucher-box {
    background: #fff;
    border: 2px solid var(--text);
    border-radius: var(--radius);
    padding: 20px;
    max-width: 640px;
    margin: 0 auto;
    font-size: 11px;
}
.voucher-box h1 { text-align: center; margin-bottom: 16px; font-size: 18px; }
.voucher-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 24px; margin-bottom: 12px; font-size: 11px; }
.voucher-meta .k { color: var(--text-dim); }
.voucher-total { text-align: right; font-size: 15px; font-weight: 700; margin-top: 10px; }
.voucher-sign-row { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-top: 32px; }
.voucher-sign-row .line { border-top: 1px solid var(--text); padding-top: 6px; font-size: 10px; color: var(--text-dim); }
.voucher-box table { font-size: 11px; }
.voucher-box th, .voucher-box td { padding: 6px 8px; }

/* Company letterhead + footer — shared by every printed document (invoice,
   payslip, claim sheet, voucher) via _print_letterhead.html/_print_footer.html.
   Fixed colors, not theme tokens: these are print pages meant to look the
   same as the physical letterhead regardless of the app's own light/dark UI.
   The banner is deliberately larger than the body text scale around it —
   it's the visual anchor of the page, not just another line of text. */
.letterhead { display: flex; align-items: center; gap: 16px; margin-bottom: 14px; }
.letterhead-banner { width: 100%; height: auto; display: block; }
.letterhead-name { font: 800 22px/1.2 Arial, sans-serif; color: #1a2b6b; letter-spacing: .01em; }
.letterhead-regno { font: 400 13px/1.4 Arial, sans-serif; color: #1a2b6b; margin-top: 2px; }

.letterfoot {
    margin-top: 20px;
    padding-top: 8px;
    border-top: 1px solid #1a2b6b;
    text-align: center;
    font: 400 10px/1.5 Arial, sans-serif;
    color: #1a2b6b;
}

/* Sales invoice print layout — modeled on the real Hwayang Ventures paper
   invoice: centered title, an item grid with row separators (not a dense
   per-cell grid — just an outer frame + horizontal lines, matching a
   cleaner invoice style), a single TOTAL row inside that same grid, and a
   bank-details + signature block.

   .invoice-doc-flex + .doc-block-* is the layer the template editor
   controls (order/spacing/size, as CSS custom properties set per-invoice
   in an inline <style> block — see invoice_template_editor.html and the
   |ordinal_date-style injection in sales_invoice_print.html/pdf.html).
   Deliberately scoped to its own wrapper rather than making .voucher-box
   itself flex — that class is shared with payslip/claim/voucher print
   pages, and flex's default align-items:stretch would silently change
   how their own tables size themselves. Each doc-block-* var has a
   fallback matching what was hardcoded before the editor existed, so an
   invoice with no saved settings (or a print/PDF path that doesn't inject
   the <style> block) still renders identically. */
.invoice-doc-flex { display: flex; flex-direction: column; }
.doc-block-letterhead { order: var(--order-letterhead, 1); margin-top: var(--margin_top-letterhead, 0px); margin-bottom: var(--margin_bottom-letterhead, 14px); }
.doc-block-letterhead .letterhead-banner { width: var(--width-letterhead, 100%); }
.doc-block-letterhead .letterhead-name { font-family: var(--font_family-letterhead, Arial, sans-serif); }
.doc-block-letterhead .letterhead-regno { font-family: var(--font_family-letterhead, Arial, sans-serif); }
.doc-block-title { order: var(--order-title, 2); margin-top: var(--margin_top-title, 4px); margin-bottom: var(--margin_bottom-title, 16px); }
.doc-block-title .invoice-print-title { font-size: var(--font_size-title, 16px); font-family: var(--font_family-title, inherit); margin: 0; text-align: var(--text_align-title, center); letter-spacing: .04em; }
.doc-block-date_row { order: var(--order-date_row, 3); margin-top: var(--margin_top-date_row, 0px); margin-bottom: var(--margin_bottom-date_row, 12px); font-size: var(--font_size-date_row, 11px); font-family: var(--font_family-date_row, inherit); }
.doc-block-date_row .invoice-date-row { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 0; }
.doc-block-bill_to { order: var(--order-bill_to, 4); margin-top: var(--margin_top-bill_to, 0px); margin-bottom: var(--margin_bottom-bill_to, 12px); font-size: var(--font_size-bill_to, 11px); font-family: var(--font_family-bill_to, inherit); text-align: var(--text_align-bill_to, left); }
.doc-block-bill_to .invoice-bill-to { margin-bottom: 2px; }
.doc-block-bill_to .invoice-contact-line { margin-bottom: 0; }
.invoice-customer-name { font-weight: 700; }
.invoice-customer-address { white-space: pre-line; }

.doc-block-items_table { order: var(--order-items_table, 5); margin-top: var(--margin_top-items_table, 0px); margin-bottom: var(--margin_bottom-items_table, 6px); }
.invoice-print-table { border: 1px solid var(--text); border-collapse: collapse; width: 100%; }
.invoice-print-table th, .invoice-print-table td {
    border: none;
    border-bottom: 1px solid var(--border);
    padding: 5px 8px;
    font-size: var(--font_size-items_table, 11px);
    font-family: var(--font_family-items_table, inherit);
    text-transform: none;
    color: var(--text);
    font-weight: 400;
}
.invoice-print-table thead th { text-align: center; font-weight: 700; border-bottom: 1px solid var(--text); }
.invoice-print-table .invoice-total-row td { font-weight: 800; border-top: 2px solid var(--text); border-bottom: none; }

.doc-block-payable_block { order: var(--order-payable_block, 6); margin-top: var(--margin_top-payable_block, 14px); margin-bottom: var(--margin_bottom-payable_block, 0px); font-size: var(--font_size-payable_block, 11px); font-family: var(--font_family-payable_block, inherit); text-align: var(--text_align-payable_block, left); }
.invoice-payable-block div + div { margin-top: 2px; }
.doc-block-signature_block { order: var(--order-signature_block, 7); margin-top: var(--margin_top-signature_block, 24px); margin-bottom: var(--margin_bottom-signature_block, 0px); font-size: var(--font_size-signature_block, 11px); font-family: var(--font_family-signature_block, inherit); text-align: var(--text_align-signature_block, left); }
.invoice-signature-block {
    /* text-align alone wouldn't move the fixed-width line/space below —
       it only affects inline content — so alignment also drives this
       flex column's cross-axis position (see TEMPLATE_ALIGN_ITEMS_MAP
       in app.py, which derives --align_items-signature_block from the
       same text_align setting). */
    display: flex;
    flex-direction: column;
    align-items: var(--align_items-signature_block, flex-start);
}
.invoice-signature-space { height: 32px; }
.invoice-signature-line { width: 200px; border-top: 1px solid var(--text); margin-bottom: 4px; }

/* Invoice layout editor (invoice_template_editor.html) — a sidebar
   (draggable section list + a property panel for whichever section is
   selected) next to a live preview of the actual invoice markup, which is
   just .voucher-box/.invoice-doc-flex rendered on-screen instead of print,
   so it inherits all of the .doc-block-* rules above for free. */
.template-editor-layout { display: grid; grid-template-columns: 320px 1fr; gap: 24px; align-items: start; }
.template-editor-panel { position: sticky; top: 16px; }
.template-editor-preview { min-width: 0; }
@media (max-width: 860px) {
    .template-editor-layout { grid-template-columns: 1fr; }
    .template-editor-panel { position: static; }
}

.block-list { list-style: none; margin: 0 0 16px; padding: 0; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.block-list-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--panel);
    cursor: grab;
    font-size: 13px;
}
.block-list-item:last-child { border-bottom: none; }
.block-list-item:hover { background: var(--panel-inset); }
.block-list-item.selected { background: var(--accent); color: #fff; }
.block-drag-handle { color: var(--text-disabled); font-size: 14px; line-height: 1; }
.block-list-item.selected .block-drag-handle { color: rgba(255,255,255,.7); }
.block-props .field label { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 4px; }
.block-props input[type="range"] { width: 100%; }

.payslip-header-fields { font-size: 11px; }
.payslip-header-fields div { margin-bottom: 4px; }
.payslip-header-fields .k { font-weight: 700; }

.payslip-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    border: 1px solid var(--text);
}
.payslip-col { padding: 10px 12px; }
.payslip-col + .payslip-col { border-left: 1px solid var(--border); }
.payslip-col h4 {
    font-size: 10px; text-transform: uppercase; letter-spacing: 0.02em;
    font-weight: 700; color: var(--text); margin: 0 0 6px; padding-bottom: 5px;
    border-bottom: 1px solid var(--text);
}
.payslip-col table { width: 100%; }
.payslip-col td { padding: 3px 0; border-bottom: none; }
.payslip-col td.num { text-align: right; white-space: nowrap; }
@media (max-width: 700px) {
    .payslip-grid { grid-template-columns: 1fr; }
    .payslip-col + .payslip-col { border-left: none; border-top: 1px solid var(--border); }
}

.payslip-totals {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    border: 1px solid var(--text);
}
.payslip-totals div { padding: 8px 12px; }
.payslip-totals div + div { border-left: 1px solid var(--border); }
.payslip-totals .k { font-weight: 700; display: block; margin-bottom: 2px; }
.payslip-totals .v { font-size: 13px; font-weight: 700; }
@media (max-width: 700px) {
    .payslip-totals { grid-template-columns: 1fr; }
    .payslip-totals div + div { border-left: none; border-top: 1px solid var(--border); }
}

/* Payslip document layout — same order/spacing/font/alignment editor
   architecture as the sales invoice (.invoice-doc-flex above); see the
   comment there for why this is a separate wrapper class rather than
   making .voucher-box itself flex, and why "letterhead" is reused
   verbatim across both doc types. The 4 inner components that already
   carried their own margin (payslip-grid/payslip-totals/voucher-meta/
   voucher-sign-row) have that margin zeroed at the point they're wrapped
   below — otherwise it would collapse with the wrapper's own var
   -controlled margin (flex items aren't exempt from margin collapsing
   with THEIR OWN children, only from collapsing with the flex container),
   silently putting a floor under how far the editor's slider could
   actually close the gap. font-size/font-family/text-align are likewise
   applied on the innermost element that already sets its own font-size
   directly (an explicit same-element declaration always beats an
   inherited one, so setting these only on the wrapper would have no
   visible effect). */
.payslip-doc-flex { display: flex; flex-direction: column; }
.doc-block-payslip_title { order: var(--order-payslip_title, 2); margin-top: var(--margin_top-payslip_title, 0px); margin-bottom: var(--margin_bottom-payslip_title, 16px); }
.doc-block-payslip_title .payslip-print-title { font-size: var(--font_size-payslip_title, 18px); font-family: var(--font_family-payslip_title, inherit); text-align: var(--text_align-payslip_title, center); text-decoration: underline; margin: 0; }
.doc-block-header_fields { order: var(--order-header_fields, 3); margin-top: var(--margin_top-header_fields, 0px); margin-bottom: var(--margin_bottom-header_fields, 12px); }
.doc-block-header_fields .payslip-header-fields { font-size: var(--font_size-header_fields, 11px); font-family: var(--font_family-header_fields, inherit); text-align: var(--text_align-header_fields, left); }
.doc-block-earnings_grid { order: var(--order-earnings_grid, 4); margin-top: var(--margin_top-earnings_grid, 0px); margin-bottom: var(--margin_bottom-earnings_grid, 12px); }
.doc-block-earnings_grid .payslip-grid { margin-bottom: 0; }
.doc-block-earnings_grid .payslip-col td { font-size: var(--font_size-earnings_grid, 11px); font-family: var(--font_family-earnings_grid, inherit); }
.doc-block-totals { order: var(--order-totals, 5); margin-top: var(--margin_top-totals, 0px); margin-bottom: var(--margin_bottom-totals, 16px); }
.doc-block-totals .payslip-totals { margin-bottom: 0; }
.doc-block-totals .payslip-totals div { font-size: var(--font_size-totals, 11px); font-family: var(--font_family-totals, inherit); }
.doc-block-payment_status { order: var(--order-payment_status, 6); margin-top: var(--margin_top-payment_status, -16px); margin-bottom: var(--margin_bottom-payment_status, 24px); }
.doc-block-payment_status .voucher-meta { margin-bottom: 0; font-size: var(--font_size-payment_status, 11px); font-family: var(--font_family-payment_status, inherit); }
.doc-block-signature_row { order: var(--order-signature_row, 7); margin-top: var(--margin_top-signature_row, 32px); margin-bottom: var(--margin_bottom-signature_row, 0px); }
.doc-block-signature_row .voucher-sign-row { margin-top: 0; }
.doc-block-signature_row .voucher-sign-row .line { font-size: var(--font_size-signature_row, 10px); font-family: var(--font_family-signature_row, inherit); }
/* Fixed-height space above each line, content sitting on the line: the
   signature image on the left, the cheque number / bank account on the
   right. Empty space is the "write it here" gap when nothing is set. */
.payslip-sign-space { height: 64px; display: flex; align-items: flex-end; padding-bottom: 4px; }
.payslip-signature-img { max-height: 60px; max-width: 220px; width: auto; height: auto; display: block; mix-blend-mode: multiply; }
/* Authorised signatory: line only as long as its label, larger signature
   centred on it. Both columns' lines sit level (align-items: end). */
.doc-block-signature_row .voucher-sign-row { align-items: end; }
.payslip-signatory { display: inline-block; text-align: center; }
.payslip-signatory .payslip-sign-space { height: 96px; justify-content: center; }
.payslip-signatory .payslip-signature-img { max-height: 92px; max-width: 200px; }
.payslip-signatory .line { padding-left: 8px; padding-right: 8px; }
.payslip-sign-value { font-size: 12px; font-family: var(--font_family-signature_row, inherit); font-weight: 600; color: var(--text); }

/* Locks every printed document (and "Save as PDF" from the print dialog,
   which uses the same @page box) to A4 — without this the browser/OS print
   default decides, which isn't always A4. Margin here is the page's own
   margin, so .voucher-box just fills the resulting printable area rather
   than applying its own separate max-width on top of it. */
@page {
    size: A4;
    margin: 15mm;
}

/* One claim as the petty cash filing sheet (_claim_sheet.html) — fixed
   print colours like the other printed documents, Arial 8pt like the
   Excel template. Category headers are rotated 90° with a transform on an
   absolutely-placed span (WeasyPrint has no vertical writing-mode). */
.pc-box { max-width: 900px; }
.pc-sheet { font: 8pt/1.25 Arial, 'Liberation Sans', sans-serif; color: #000; background: #fff; }
.pc-sheet .pc-company, .pc-sheet .pc-title { font-weight: 700; margin-bottom: 6px; }
.pc-sheet .pc-title { margin-bottom: 10px; }
.pc-sheet table { border-collapse: collapse; }
.pc-sheet .pc-meta { margin-bottom: 10px; }
.pc-sheet .pc-meta th { text-align: left; font-weight: 700; padding: 1px 24px 1px 0; border: 0; background: none; color: #000; font-size: 8pt; text-transform: none; letter-spacing: 0; }
.pc-sheet .pc-meta td { padding: 1px 0; border: 0; font-size: 8pt; }
.pc-sheet .pc-grid { width: 100%; table-layout: fixed; }
.pc-sheet .pc-grid th, .pc-sheet .pc-grid td { border: 0.75pt solid #000; padding: 1px 2px; font-size: 7pt; color: #000; background: #fff; overflow: hidden; }
.pc-sheet .pc-grid th { font-weight: 700; text-align: center; vertical-align: top; text-transform: none; letter-spacing: 0; }
.pc-sheet .pc-grid thead tr { height: 100px; }
.pc-sheet .pc-grid th.pc-rot { padding: 0; vertical-align: bottom; }
/* A block wrapper as the positioning box (WeasyPrint ignores position on
   table cells). Rotated around its bottom-left corner, the one-line label
   runs up from 4px above the bottom border; margin-left recentres it. */
.pc-sheet .pc-grid .pc-rotbox { position: relative; height: 112px; }
.pc-sheet .pc-grid th.pc-rot span { position: absolute; left: 50%; bottom: 4px; margin-left: 0.5em; white-space: nowrap; line-height: 1; font-size: 6.2pt; transform-origin: 0 100%; transform: rotate(-90deg); }
.pc-sheet .pc-grid td { height: 14px; vertical-align: top; }
.pc-sheet .pc-grid td.c { text-align: center; }
/* Amounts: never hide digits (a clipped figure on a filed claim reads as
   the wrong number). 6.3pt fits "123,456.78" in a category column. */
.pc-sheet .pc-grid td.n { text-align: right; white-space: nowrap; padding: 1px 1px; overflow: visible; font-size: 6.3pt; }
.pc-sheet .pc-grid td.n.b:last-child { font-size: 7pt; }
.pc-sheet .pc-grid td.b { font-weight: 700; }
.pc-sheet .pc-grid td.pc-desc { word-wrap: break-word; }
.pc-sheet .pc-grid td.pc-nob { border: 0; }
.pc-sheet .pc-sign { width: 100%; margin-top: 14px; }
.pc-sheet .pc-sign td { width: 33%; border: 0; padding: 0 16px 0 0; font-size: 8pt; vertical-align: top; }
.pc-sheet .pc-sign-line { margin-top: 36px; border-top: 0.75pt solid #000; padding-top: 3px; min-height: 12px; }
.pc-receipt-caption { font: 700 9pt/1.3 Arial, sans-serif; color: #000; margin-bottom: 10px; }
.pc-receipt-img { display: block; max-width: 100%; max-height: 900px; margin: 0 auto; }
/* The wide sheet scrolls sideways on phones instead of squashing. */
@media screen and (max-width: 700px) { .pc-box { overflow-x: auto; } .pc-sheet { min-width: 640px; } }

@media print {
    .no-print { display: none !important; }
    body { background: #fff; }
    .voucher-box { border: none; padding: 0 0 50px; max-width: 100%; }
    /* Pins the footer to the physical bottom of every page (WeasyPrint's
       documented way to do running headers/footers in paged media — it
       doesn't rely on @page margin boxes, just repeats position:fixed
       elements per page) instead of wherever the content happens to end,
       which is what "footer isn't at the bottom of the page" meant. The
       50px padding-bottom above reserves room so the last bit of content
       never sits underneath it. */
    .letterfoot { position: fixed; bottom: 0; left: 0; right: 0; margin-top: 0; }
    .pc-receipt-page { page-break-before: always; }
    .pc-box { max-width: none; overflow: visible; }
    .pc-sheet { min-width: 0; }
}
