:root {
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 15px;
    color-scheme: light;
    --page: #ffffff;
    --side: #f5f6f9;
    --panel: #fafbfc;
    --text: #192437;
    --muted: #58677c;
    --border: #dfe5ee;
    --accent: #284fc2;
    --accent-ink: #fff;
    --active: #eaf0ff;
    --danger: #a72c39;
    --success: #246449;
}
[data-theme="dark"] {
    color-scheme: dark;
    --page: #161b25;
    --side: #1b2230;
    --panel: #202837;
    --text: #e9eef9;
    --muted: #aab8cd;
    --border: #364258;
    --accent: #9eb7ff;
    --accent-ink: #13254f;
    --active: #293955;
    --danger: #ff9eaa;
    --success: #87d8ad;
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--page); color: var(--text); line-height: 1.45; }
button, input, textarea, select { font: inherit; color: inherit; }
button { border: 1px solid var(--border); background: var(--page); border-radius: 7px; padding: .48rem .72rem; cursor: pointer; }
button:hover { background: var(--active); }
button:disabled { opacity: .55; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 650; }
button.danger { color: var(--danger); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
a { color: var(--accent); }
input, textarea, select {
    max-width: 100%; min-width: 0; width: 100%; background: var(--page);
    padding: .55rem .65rem; border: 1px solid var(--border); border-radius: 7px;
}
textarea { resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .9; }
input[type="file"] { padding: .45rem; }
label { display: block; font-size: .86rem; color: var(--muted); }
label > input, label > textarea, label > select { display: block; margin-top: .24rem; color: var(--text); }
h1, h2, h3, p { margin: 0; }
h1, h2, h3 { color: var(--text); font-weight: 670; line-height: 1.23; }
h1 { font-size: 1.38rem; }
h2 { font-size: 1.22rem; }
h3 { font-size: 1rem; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.workspace { display: grid; grid-template-columns: 208px 295px minmax(0, 1fr); min-height: 100vh; min-height: 100dvh; }
.navigation, .listing, .detail { height: 100vh; height: 100dvh; min-width: 0; }
.navigation { display: flex; flex-direction: column; padding: 22px 14px 14px; background: var(--side); border-right: 1px solid var(--border); overflow: auto; }
.brand { display: flex; align-items: center; gap: 11px; margin: 0 4px 30px; }
.brand strong { font-size: 1.08rem; line-height: 1.1; }
.brand strong span { display: block; margin-top: 4px; font-weight: 500; color: var(--muted); font-size: .78rem; }
.brand-mark { display: grid; flex: 0 0 auto; place-items: center; height: 39px; width: 39px; border-radius: 10px; font-weight: 750; letter-spacing: -.08em; background: var(--accent); color: var(--accent-ink); }
.module-nav, .nav-footer, #sidebar-tags { display: grid; gap: 4px; }
.module-nav button, .nav-footer button, #sidebar-tags button { text-align: left; width: 100%; border-color: transparent; background: transparent; }
.module-nav button:hover, .nav-footer button:hover, #sidebar-tags button:hover { background: var(--active); }
.module-nav button[aria-current], #sidebar-tags button[aria-pressed="true"] { background: var(--active); color: var(--accent); font-weight: 650; }
.module-nav button span { display: inline-block; width: 1.45rem; color: var(--accent); }
.sidebar-tags { margin: 28px 0 16px; }
.sidebar-tags h2 { padding: 0 .72rem .45rem; font-size: .78rem; color: var(--muted); }
#sidebar-tags { overflow-wrap: anywhere; }
.nav-footer { margin-top: auto; border-top: 1px solid var(--border); padding-top: .5rem; }
.listing { background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; }
.list-header { padding: 20px 15px 9px; }
.section-heading, .detail-bar, .tool-row, .detail-nav { display: flex; align-items: center; gap: .55rem; }
.section-heading h1 { flex: 1; }
.searchbox { margin: 13px 0 7px; }
.searchbox input { font-size: .9rem; }
.result-count { min-height: 1.3rem; margin: .25rem .2rem 0; font-size: .76rem; color: var(--muted); }
.records { overflow: auto; padding: 0 10px 14px; }
.record { display: block; width: 100%; text-align: left; border: 1px solid transparent; background: transparent; padding: .69rem .69rem; margin-bottom: 3px; overflow: hidden; }
.record[aria-selected="true"] { background: var(--active); border-color: var(--border); }
.record strong, .record span { display: block; white-space: nowrap; text-overflow: ellipsis; overflow: hidden; }
.record span { font-size: .79rem; margin-top: .21rem; color: var(--muted); }
.record.is-pinned strong::before { content: "◆ "; color: var(--accent); font-size: .68em; }
.detail { display: flex; flex-direction: column; }
.detail-bar { min-height: 58px; justify-content: flex-end; padding: .55rem 1.35rem; border-bottom: 1px solid var(--border); }
.detail-nav { margin-right: auto; }
.drawer-toggle, #back { display: none; }
.sync { font-size: .82rem; color: var(--muted); overflow-wrap: anywhere; }
.sync[data-level="error"], .field-error { color: var(--danger); }
.sync[data-level="saved"] { color: var(--success); }
.editor { padding: 25px clamp(15px, 3vw, 40px) 44px; flex: 1; min-height: 0; overflow: auto; }
.empty { display: grid; place-content: center; min-height: 58%; color: var(--muted); text-align: center; gap: .5rem; padding: 1.5rem; }
.list-empty { color: var(--muted); padding: .9rem .65rem; font-size: .86rem; }
.editor-header { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: .8rem; margin-bottom: 1.2rem; }
.tool-row { flex-wrap: wrap; }
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .85rem; }
.full { grid-column: 1 / -1; }
.muted { color: var(--muted); font-size: .87rem; }
.block-section { padding-top: 1.2rem; margin-top: 1.2rem; border-top: 1px solid var(--border); }
.note-title { font-size: clamp(1.45rem, 3vw, 2.25rem); font-weight: 660; border: 0; border-radius: 0; padding: .45rem 0; }
.note-body { border: 0; border-top: 1px solid var(--border); border-radius: 0; padding: .9rem 0; min-height: 42vh; line-height: 1.65; }
.note-tags { border-top: 1px solid var(--border); padding-top: .8rem; }
.markdown { min-height: 42vh; padding: 1rem .2rem; overflow-wrap: anywhere; }
.markdown > * { margin: 0 0 .75rem; }
.markdown ul, .markdown ol { padding-left: 1.6rem; }
.markdown ul { list-style: disc; }
.markdown ol { list-style: decimal; }
.markdown pre { margin-top: .5rem; overflow: auto; padding: .75rem; border: 1px solid var(--border); border-radius: 7px; background: var(--panel); white-space: pre-wrap; }
.markdown code { font-family: ui-monospace, monospace; background: var(--panel); }
.markdown blockquote { margin-left: 0; padding-left: .75rem; border-left: 3px solid var(--border); color: var(--muted); }
.table-wrap { overflow: auto; margin: .8rem 0; border: 1px solid var(--border); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: .5rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { white-space: nowrap; background: var(--panel); color: var(--muted); font-size: .82rem; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.selected td { background: var(--active); }
.order-table { min-width: 1810px; }
.order-table input, .order-table select, .order-table textarea { font-size: .86rem; }
.order-table textarea { min-width: 170px; }
.order-table select { min-width: 155px; }
.order-table input[type="date"] { min-width: 135px; }
.order-table .tags-cell { min-width: 140px; }
.order-table td:first-child, .order-table th:first-child { position: sticky; left: 0; background: var(--panel); }
.order-table td:first-child { font-variant-numeric: tabular-nums; }
.quote-table { min-width: 510px; }
.quote-table td:first-child { width: 53%; }
.quote-table td:nth-child(2) input { min-width: 65px; }
.quote-table td:nth-child(3) input { min-width: 105px; }
.quote-table td:nth-child(4) { text-align: right; white-space: nowrap; }
.quote-table textarea { min-height: 3rem; }
.totals { margin-left: auto; width: min(100%, 410px); display: grid; gap: .5rem; padding-top: .8rem; }
.total-line, .total-input { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: .75rem; }
.total-input input, .total-input select { width: 108px; margin: 0; }
.total-final { font-size: 1.15rem; padding-top: .65rem; border-top: 1px solid var(--border); }
.client-picker { position: relative; }
.client-results { display: grid; padding: .3rem; border: 1px solid var(--border); background: var(--page); border-radius: 7px; max-height: 13rem; overflow: auto; margin-top: .3rem; gap: .18rem; }
.client-results button { text-align: left; border-color: transparent; }
.logo-preview { display: block; max-width: 170px; max-height: 90px; object-fit: contain; margin: .5rem 0; }
dialog { background: var(--page); color: var(--text); border: 1px solid var(--border); border-radius: 12px; width: min(540px, calc(100% - 28px)); max-height: 90dvh; padding: 20px; }
dialog::backdrop, #scrim { background: rgba(10, 17, 31, .55); }
dialog .tool-row { justify-content: flex-end; margin-top: 1rem; }
#scrim { position: fixed; inset: 0; border: 0; border-radius: 0; z-index: 2; }
.login-page { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 22px; background: var(--side); }
.login-card { width: min(100%, 420px); display: grid; gap: .87rem; padding: 28px; background: var(--page); border: 1px solid var(--border); border-radius: 14px; }
.login-card form { display: grid; gap: .85rem; }
.login-card p { color: var(--muted); }
.login-card p.field-error { color: var(--danger); }
#print-sheet { display: none; }
@media (max-width: 1180px) {
    .workspace { grid-template-columns: 177px 233px minmax(0, 1fr); }
}
@media (max-width: 940px) {
    .workspace { grid-template-columns: 230px minmax(0, 1fr); }
    .navigation { display: none; position: fixed; z-index: 3; inset: 0 auto 0 0; width: min(280px, 84vw); }
    body[data-drawer="open"] .navigation { display: flex; }
    .drawer-toggle { display: inline-block; }
}
@media (max-width: 690px) {
    .workspace { display: block; }
    body[data-pane="list"] .detail, body[data-pane="detail"] .listing { display: none; }
    .listing { border: 0; }
    .detail-bar { padding-inline: .7rem; }
    #back { display: inline-block; }
    .editor { padding-top: 15px; }
    .fields { grid-template-columns: 1fr; }
    .editor-header { align-items: flex-start; }
    .section-heading, .detail-bar { gap: .4rem; }
    button { min-height: 38px; }
}
@page { size: A4 portrait; margin: 14mm; }
@media print {
    #workspace, dialog, #scrim { display: none !important; }
    body[data-print-ready="true"] #print-sheet { display: block; }
    body { color: #111; background: white; font-family: Arial, sans-serif; font-size: 10pt; }
    #print-sheet { overflow-wrap: anywhere; }
    #print-sheet h1, #print-sheet h2, #print-sheet h3 { color: #111; }
    .print-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12mm; border-bottom: 1px solid #202a39; padding-bottom: 5mm; margin-bottom: 5mm; }
    .print-header img { max-height: 24mm; max-width: 52mm; display: block; margin-bottom: 3mm; }
    .print-header h1 { font-size: 21pt; margin-bottom: 2mm; }
    .print-header h2 { font-size: 14pt; margin-bottom: 2mm; }
    .print-number { text-align: right; }
    .print-client { margin-bottom: 5mm; }
    .print-client h3 { margin-bottom: 2mm; }
    #print-sheet table { table-layout: fixed; margin-bottom: 5mm; }
    #print-sheet thead { display: table-header-group; }
    #print-sheet th, #print-sheet td { border-bottom: 1px solid #c0c7d0; color: #111; background: white; padding: 2mm; white-space: pre-wrap; }
    #print-sheet th:first-child { width: 49%; }
    #print-sheet th:nth-child(2) { width: 11%; }
    #print-sheet th:nth-child(3), #print-sheet th:nth-child(4) { width: 20%; }
    #print-sheet th:not(:first-child), #print-sheet td:not(:first-child) { text-align: right; }
    #print-sheet tr { break-inside: avoid; }
    .print-totals { margin-left: auto; width: min(100%, 85mm); break-inside: avoid; }
    .print-totals div { display: flex; justify-content: space-between; gap: 4mm; }
    .print-totals div:last-child { margin-top: 2mm; padding-top: 2mm; border-top: 1px solid #202a39; font-weight: bold; font-size: 12pt; }
    .print-condition { margin: 4mm 0; white-space: pre-wrap; }
    .print-condition h3 { break-after: avoid; }
}
