/* SJ Books: plain CSS, no build step. Breakpoints: phone <600, tablet 600-1023, desktop >=1024. */
:root {
    --accent: #6D28D9; --accent-dark: #5B21B6; --accent-soft: #F3EEFC;
    --text: #1F2937; --muted: #4B5563; --border: #D9DDE3; --bg: #F5F6F8; --surface: #FFFFFF;
    --green-bg: #DCFCE7; --green-fg: #166534; --red-bg: #FEE2E2; --red-fg: #991B1B; --grey-bg: #E5E7EB; --grey-fg: #374151;
    --danger: #B91C1C; --sidebar-w: 248px; --topbar-h: 56px; --bottombar-h: 60px; --radius: 8px; --tap: 44px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
*, *::before, *::after { box-sizing: border-box; }
[x-cloak] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.5 var(--font); color: var(--text); background: var(--bg); }
body.nav-locked { overflow: hidden; }
a { color: var(--accent); }
h1 { font-size: 1.5rem; line-height: 1.25; margin: 0; }
h2 { font-size: 1.1rem; margin: 0; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: -999px; top: 0; background: var(--surface); padding: 8px 12px; z-index: 100; }
.skip-link:focus { left: 8px; top: 8px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 16px; border: 1px solid transparent;
    border-radius: var(--radius); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; background: none; color: var(--text); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-primary:disabled { opacity: .7; cursor: progress; }
.btn-secondary { background: var(--surface); border-color: var(--border); }
.btn-secondary:hover { background: #F0F1F4; }
.btn-link { color: var(--accent); }
.btn.is-disabled, .is-disabled { color: #6B7280; cursor: not-allowed; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: var(--tap); height: var(--tap); border: 0; background: none; color: var(--text); font-size: 28px; cursor: pointer; border-radius: var(--radius); }
.tag { display: inline-block; padding: 0 6px; border-radius: 999px; background: #EEF0F3; color: #4B5563; font-size: 11px; font-weight: 600; line-height: 18px; vertical-align: middle; }

/* Shell */
.sidebar { position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); max-width: 86vw; background: var(--surface); border-right: 1px solid var(--border); overflow-y: auto; z-index: 40;
    transform: translateX(-100%); transition: transform .2s ease; padding-bottom: 24px; }
.sidebar.is-open { transform: none; box-shadow: 0 0 30px rgba(0,0,0,.2); }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; height: var(--topbar-h); padding: 0 12px 0 16px; border-bottom: 1px solid var(--border); }
.brand { font-weight: 800; font-size: 1.15rem; color: var(--accent); text-decoration: none; }
.sidebar-company { padding: 10px 16px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--border); }
.nav-group { padding: 10px 8px 2px; }
.nav-group ul { list-style: none; margin: 0; padding: 0; }
.nav-title { margin: 0 8px 4px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.nav-item { display: flex; align-items: center; justify-content: space-between; min-height: 36px; padding: 6px 10px; border-radius: 6px; color: var(--text); text-decoration: none; font-size: 14px; }
a.nav-item:hover { background: #F0F1F4; }
a.nav-item.is-active { background: var(--accent-soft); color: var(--accent-dark); font-weight: 700; }
.scrim { position: fixed; inset: 0; background: rgba(17,24,39,.45); z-index: 30; }
.main-wrap { min-height: 100vh; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 8px; height: var(--topbar-h); padding: 0 12px; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-title { font-weight: 700; font-size: 1.05rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-company { font-weight: 600; }
.topbar-spacer { flex: 1; }
.content { max-width: 1200px; margin: 0 auto; padding: 20px 16px 96px; }
.offline-banner { position: sticky; top: 0; z-index: 60; background: #FEF3C7; color: #78350F; padding: 10px 16px; text-align: center; font-weight: 600; }
.only-phone { display: none !important; }
.only-drawer { display: inline-flex; }

/* Menus */
.menu { position: relative; display: inline-block; }
.menu-panel { position: absolute; left: 0; top: calc(100% + 4px); min-width: 200px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.14); padding: 4px; z-index: 50; }
.menu-panel.right { left: auto; right: 0; }
.menu-item { display: flex; align-items: center; width: 100%; min-height: var(--tap); padding: 8px 12px; border: 0; background: none; font: inherit; color: var(--text); text-decoration: none; text-align: left; cursor: pointer; border-radius: 6px; }
.menu-item:hover { background: #F0F1F4; }
.menu-info { padding: 8px 12px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.user-btn { display: inline-flex; align-items: center; gap: 8px; min-height: var(--tap); padding: 0 8px; border: 0; background: none; font: inherit; color: var(--text); cursor: pointer; border-radius: var(--radius); }
.avatar { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: 50%; background: var(--accent); color: #fff; font-weight: 700; }

/* Page header, flash */
.page-header { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.page-header p { margin: 4px 0 0; }
.page-header-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.flash { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; font-weight: 500; }
.flash-success { background: var(--green-bg); color: var(--green-fg); }
.flash-error { background: var(--red-bg); color: var(--red-fg); }
.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; letter-spacing: .03em; }
.badge-green { background: var(--green-bg); color: var(--green-fg); }
.badge-red { background: var(--red-bg); color: var(--red-fg); }
.badge-grey { background: var(--grey-bg); color: var(--grey-fg); }

/* Dashboard cards */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; margin-bottom: 20px; }
.card-tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.card-tile-title { font-weight: 700; margin-bottom: 4px; }

/* Data table */
.dt-section { margin-bottom: 24px; }
.dt-heading { margin: 8px 0; color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .06em; }
.dt-toolbar { display: flex; gap: 8px; margin-bottom: 12px; }
.dt-toolbar input[type=search] { flex: 1; max-width: 420px; }
.dt-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: auto; max-height: 75vh; }
.dt { width: 100%; border-collapse: separate; border-spacing: 0; }
.dt th, .dt td { padding: 10px 14px; text-align: left; border-bottom: 1px solid #EBEDF0; vertical-align: middle; }
.dt th.num, .dt td.num { text-align: right; }
.dt thead th { position: sticky; top: 0; background: #F0F1F4; font-size: 13px; color: var(--grey-fg); z-index: 1; white-space: nowrap; }
.dt thead th a { color: inherit; text-decoration: none; }
.dt thead th a:hover { text-decoration: underline; }
.dt tbody tr.is-link { cursor: pointer; }
.dt tbody tr.is-link:hover { background: var(--accent-soft); }
.dt tfoot td { position: sticky; bottom: 0; background: #F0F1F4; font-weight: 700; border-top: 2px solid var(--border); }
.dt-cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.dt-card { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; min-height: var(--tap); padding: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); text-decoration: none; }
.dt-card-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.dt-card-primary { font-size: 1.1rem; font-weight: 700; overflow-wrap: anywhere; }
.dt-card-secondary { color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.dt-card-side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex-shrink: 0; }
.dt-card-amount { font-weight: 700; font-variant-numeric: tabular-nums; }
.dt-card-total { font-weight: 700; justify-content: space-between; background: #F0F1F4; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; flex-wrap: wrap; }
.empty-state { background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); padding: 40px 16px; text-align: center; }
.empty-title { font-weight: 700; margin: 0 0 4px; }
.empty-actions { margin-top: 12px; }

/* Forms */
input[type=text], input[type=search], input[type=email], input[type=tel], input[type=number], input[type=password], select, textarea {
    width: 100%; min-height: 40px; padding: 8px 12px; font: inherit; color: var(--text); background: var(--surface); border: 1px solid #9CA3AF; border-radius: var(--radius); }
input:disabled, input[readonly], select:disabled { background: #F0F1F4; color: var(--grey-fg); }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 3px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.form { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 20px; }
.span-2 { grid-column: span 2; }
.field label, .field .label { display: block; font-weight: 600; margin-bottom: 4px; }
.field .req { color: var(--danger); }
.field .hint { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.field .error { margin: 4px 0 0; color: var(--danger); font-size: 13px; font-weight: 600; }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--danger); }
.check { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; font-weight: 500 !important; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.readout { margin: 0; font-size: 1.3rem; font-weight: 700; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); position: sticky; bottom: 0; background: var(--surface); }

/* Plain (error) pages */
body.plain { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.plain-box { max-width: 460px; text-align: center; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 32px 24px; }
.err-code { margin: 0; font-size: 3rem; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }

/* Desktop */
@media (min-width: 1024px) {
    .sidebar { transform: none; box-shadow: none; transition: none; }
    .main-wrap { margin-left: var(--sidebar-w); }
    .only-drawer { display: none; }
    .scrim { display: none; }
    .content { padding: 28px 32px 48px; }
    .topbar { padding: 0 24px; }
}
/* Tablet */
@media (min-width: 600px) and (max-width: 1023px) {
    .content { padding: 24px 24px 48px; }
}
/* Phone */
@media (max-width: 599px) {
    .not-phone { display: none !important; }
    .only-phone { display: block !important; }
    .dt-cards.only-phone { display: grid !important; }
    .bottombar.only-phone { display: grid !important; }
    .topbar-title { flex: 1; }
    .content { padding: 16px 16px calc(var(--bottombar-h) + 24px); }
    .page-header-actions { width: 100%; }
    .page-header-actions .btn { flex: 1; min-height: var(--tap); }
    .btn, .menu-item, .user-btn { min-height: var(--tap); }
    input[type=text], input[type=search], input[type=email], input[type=tel], input[type=number], select, textarea { min-height: var(--tap); font-size: 16px; }
    .form { padding: 14px; border-radius: 0; border-left: 0; border-right: 0; margin: 0 -16px; }
    .form-grid { grid-template-columns: 1fr; }
    .span-2 { grid-column: auto; }
    .form-actions { bottom: var(--bottombar-h); margin: 20px -14px -14px; padding: 12px 14px; box-shadow: 0 -4px 12px rgba(0,0,0,.06); }
    .form-actions .btn { flex: 1; }
    .dt-toolbar input[type=search] { max-width: none; }
    .bottombar { position: fixed; inset: auto 0 0 0; z-index: 25; display: grid; grid-template-columns: repeat(4, 1fr); height: var(--bottombar-h); padding-bottom: env(safe-area-inset-bottom);
        background: var(--surface); border-top: 1px solid var(--border); }
    .bottombar > * { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: var(--tap); font-size: 12px; font-weight: 600; text-decoration: none; color: var(--text); }
    .bottombar a.is-active { color: var(--accent-dark); }
    .menu-panel.right { position: fixed; right: 8px; top: calc(var(--topbar-h) + 4px); }
}
@media (prefers-reduced-motion: reduce) { .sidebar { transition: none; } }
.role { text-transform: capitalize; }

/* Reports */
.reports-directory ul { list-style: none; margin: 10px 0 0; padding: 0; }
.reports-directory li { padding: 8px 0; }
.reports-filters { display: flex; flex-wrap: wrap; gap: 16px; align-items: end; margin-bottom: 20px; }
.reports-filters .field { flex: 1 1 180px; }
.reports-filters input[type=date] { width: 100%; min-height: 44px; padding: 8px 12px; border: 1px solid #9CA3AF; border-radius: var(--radius); background: var(--surface); color: var(--text); font: inherit; }
.reports-table-wrap { max-width: 100%; }
.reports-table td { background: var(--surface); }
.reports-table .reports-row-heading td { font-weight: 700; background: #F0F1F4; }
.reports-table .reports-row-subtotal td { font-weight: 700; border-top: 1px solid var(--border); }
.reports-table .reports-row-total td { font-weight: 800; background: var(--accent-soft); border-top: 2px solid var(--border); }
.reports-table .reports-row-detail td:first-child { padding-left: 26px; }
@media (max-width: 599px) {
    .reports-table { min-width: 640px; }
    .reports-table th:first-child, .reports-table td:first-child { position: sticky; left: 0; z-index: 2; min-width: 110px; max-width: 210px; box-shadow: 1px 0 var(--border); }
    .reports-table thead th:first-child { z-index: 3; }
    .reports-filters { margin: 0 0 16px; border: 1px solid var(--border); border-radius: var(--radius); }
    .reports-filters input[type=date] { font-size: 16px; }
}
@media print {
    .sidebar, .topbar, .bottombar, .scrim, .skip-link, .offline-banner, .reports-filters, .reports-back, .page-header-actions, .reports-pager { display: none !important; }
    .main-wrap { margin: 0; }
    .content { max-width: none; padding: 0; }
    body { background: white; font-size: 10pt; }
    .reports-table-wrap { overflow: visible; max-height: none; border: 0; }
    .reports-table { min-width: 0; width: 100%; }
    .reports-table th, .reports-table td { position: static !important; min-width: 0 !important; max-width: none !important; padding: 5px; box-shadow: none !important; }
    .reports-table thead { display: table-header-group; }
    .reports-table tfoot { display: table-row-group; }
    .reports-table tr { break-inside: avoid; }
    .reports-table a { color: inherit; text-decoration: none; }
    .reports-screen .page-header { break-after: avoid; }
}

/* Documents */
.doc-section { margin: 24px 0; }
.doc-section h2 { margin-bottom: 12px; }
.doc-table { margin: 16px 0; }
.doc-filters { margin-bottom: 20px; }
.doc-lines { display: grid; gap: 12px; margin: 16px 0; }
.doc-line { min-width: 0; border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.doc-line legend { font-weight: 700; padding: 0 6px; }
.doc-details { display: grid; grid-template-columns: 130px 1fr; gap: 8px 16px; }
.doc-details dt { color: var(--muted); }
.doc-details dd { margin: 0; overflow-wrap: anywhere; }
.doc-allocation { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.doc-audit { overflow-wrap: anywhere; max-width: 420px; }
/* End Documents */
