:root {
    --ink: #1c1915;
    --ink-soft: #3a342c;
    --paper: #f3efe6;
    --card: #fffdf8;
    --line: #e3daca;
    --line-strong: #cfc4b0;
    --muted: #6f675d;
    --cyan: #2e75b6;
    --red: #a33b32;
    --green: #2f6b3c;
    --amber: #8a5a00;
    --shadow: 0 10px 30px rgba(48, 36, 18, 0.05);
    --sidebar: 232px;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
    font-family: "Outfit", "Segoe UI", sans-serif;
    color: var(--ink);
    background: var(--paper);
    font-size: 15px;
    line-height: 1.45;
}

h1, h2, h3 {
    font-family: "Fraunces", Georgia, serif;
    font-weight: 560;
    letter-spacing: -0.02em;
    margin: 0;
}

h1 { font-size: 32px; line-height: 1.1; }
h2 { font-size: 22px; }
h3 { font-size: 18px; }

p { margin: 0; }

a { color: var(--cyan); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select, textarea { font: inherit; color: inherit; }

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar);
    flex: 0 0 var(--sidebar);
    background: var(--ink);
    color: #f6f1e7;
    padding: 22px 16px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}

.brand {
    display: flex;
    gap: 12px;
    align-items: center;
    color: inherit;
    text-decoration: none;
    padding: 4px 8px 22px;
}

.brand:hover { text-decoration: none; }

.brand strong {
    display: block;
    font-family: "Fraunces", Georgia, serif;
    font-size: 18px;
    font-weight: 560;
}

.brand small { color: #c8bfb2; font-size: 12px; }

.brand-logo {
    width: 52px;
    height: 40px;
    object-fit: contain;
    flex: 0 0 auto;
}

.login-logo {
    display: block;
    width: 132px;
    height: auto;
    margin-bottom: 10px;
}

.side-nav { display: flex; flex-direction: column; gap: 4px; }

.side-nav a {
    color: #efe8dc;
    text-decoration: none;
    padding: 10px 12px;
    border-radius: 8px;
    border-left: 3px solid transparent;
}

.side-nav a:hover { background: rgba(255, 255, 255, 0.06); text-decoration: none; }
.side-nav a.active { background: rgba(255, 255, 255, 0.08); border-left-color: #2e75b6; }

.workspace { flex: 1; min-width: 0; }

.topbar {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 12px;
    padding: 16px 32px 0;
    color: var(--muted);
}

.nav-toggle {
    display: none;
    margin-right: auto;
    background: var(--ink);
    color: #f6f1e7;
    border: 0;
    border-radius: 8px;
    padding: 8px 12px;
}

main {
    width: min(1120px, calc(100% - 64px));
    margin: 0 auto;
    padding: 12px 0 56px;
}

.page-head, .section-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 16px;
    margin-bottom: 18px;
}

.page-head p, .lede { color: var(--muted); margin-top: 6px; }

.page-actions, .inline-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.stat-grid, .card-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
}

.stat-grid.six { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.stat, .card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: var(--shadow);
}

.stat { padding: 14px 16px; }
.stat span, .muted { color: var(--muted); font-size: 13px; }
.stat strong { display: block; margin-top: 6px; font-size: 22px; font-variant-numeric: tabular-nums; font-weight: 600; }
.stat em { font-style: normal; color: var(--muted); font-size: 12px; }

.card { padding: 16px 18px; }
.card + .card, .stack > * + * { margin-top: 16px; }

.split {
    display: grid;
    grid-template-columns: 1.3fr 0.9fr;
    gap: 16px;
    margin-top: 16px;
}

.detail-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 300px;
    gap: 16px;
    align-items: start;
}

.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 14px;
}

.filters input, .filters select { width: auto; min-width: 160px; }

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }

th {
    text-align: left;
    font-size: 11px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
    font-weight: 600;
    padding: 8px 10px;
    border-bottom: 1px solid var(--line);
}

td {
    padding: 10px;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
}

tr.low td { background: #fbf3ea; }

.num, .money { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
th.num { text-align: right; }

.badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 2px 8px;
    font-size: 12px;
    font-weight: 600;
    background: #efe8dc;
    color: #5c5348;
    white-space: nowrap;
}

.badge-draft { background: #efe8dc; color: #5c5348; }
.badge-confirmed, .badge-new, .badge-contacted { background: #e5eef2; color: #0d5f70; }
.badge-production, .badge-quoted, .badge-partial { background: #f8ecd4; color: #8a5a00; }
.badge-ready, .badge-won, .badge-paid { background: #e5f0e4; color: #2f6b3a; }
.badge-delivered { background: #eceae6; color: #44403c; }
.badge-cancelled, .badge-lost, .badge-unpaid { background: #f8e4e1; color: #8d2e26; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    border: 1px solid var(--line-strong);
    background: #fff;
    color: var(--ink);
    padding: 8px 12px;
    min-height: 38px;
    text-decoration: none;
    cursor: pointer;
}

.btn:hover { text-decoration: none; border-color: #b7ab96; }

.btn-primary { background: #2e75b6; color: #fff; border-color: #2e75b6; }
.btn-primary:hover { background: #245f92; }

.btn-danger { color: var(--red); border-color: #e7c6c2; background: #fff; }
.btn-small { min-height: 32px; padding: 4px 8px; font-size: 13px; }

input[type="text"], input[type="number"], input[type="date"], input[type="email"], input[type="tel"], input[type="search"], select, textarea {
    width: 100%;
    background: #fff;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    padding: 8px 10px;
    min-height: 38px;
}

textarea { min-height: 90px; resize: vertical; }

input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
    outline: 2px solid var(--cyan);
    outline-offset: 1px;
}

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.wide, .form-grid .wide { grid-column: 1 / -1; }
.field span, .check { font-size: 13px; color: var(--ink-soft); }
.check { display: flex; align-items: center; gap: 8px; }
.check input { width: auto; min-height: 0; }

.field-error, .form-errors { color: var(--red); font-size: 13px; }
.form-errors:empty, .form-errors ul:empty { display: none; }
.form-errors ul { margin: 0 0 12px; padding-left: 18px; }

.banner { border-radius: 10px; padding: 10px 12px; margin-bottom: 14px; }
.banner.success { background: #e7f3e8; color: #24562e; }
.banner.error { background: #fbeceb; color: #8d2e26; }

.empty { padding: 28px 8px; color: var(--muted); }

.meta { display: grid; grid-template-columns: 120px 1fr; gap: 8px 12px; margin: 0; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; }

.totals { margin-top: 12px; display: grid; justify-content: end; gap: 4px; min-width: 240px; }
.totals div { display: flex; justify-content: space-between; gap: 24px; }
.totals .grand { font-weight: 600; font-size: 18px; }

.line-head, .line-row {
    display: grid;
    grid-template-columns: 190px minmax(140px, 1.3fr) minmax(120px, 1fr) 80px 100px 100px 36px;
    gap: 8px;
    align-items: center;
}

.line-head { color: var(--muted); font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; margin-bottom: 6px; }
.line-row { margin-bottom: 8px; }
.line-total { text-align: right; font-variant-numeric: tabular-nums; }

.remove-line {
    width: 36px;
    height: 38px;
    border-radius: 8px;
    border: 1px solid var(--line-strong);
    background: #fff;
    cursor: pointer;
}

.stock-forms { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.stock-forms form, .side-form { display: grid; gap: 8px; }

.print-only { display: none; }

.receipt {
    max-width: 680px;
    margin: 0 auto;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 28px 32px 32px;
}

.receipt-head { text-align: center; margin-bottom: 18px; }
.receipt-head strong {
    display: block;
    font-family: "Fraunces", Georgia, serif;
    font-size: 28px;
    font-weight: 560;
}
.receipt-head p { margin: 4px 0 0; color: var(--muted); }
.receipt .totals { margin-left: auto; }
.receipt .totals .grand { border-top: 1px solid var(--line); padding-top: 6px; margin-top: 2px; }

@media (max-width: 980px) {
    .stat-grid, .stat-grid.six, .split, .detail-grid, .stock-forms, .form-grid { grid-template-columns: 1fr 1fr; }
    .line-head { display: none; }
    .line-row { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 760px) {
    .sidebar {
        position: fixed;
        z-index: 20;
        transform: translateX(-105%);
        transition: transform 0.18s ease;
    }
    body.nav-open .sidebar { transform: none; }
    .nav-toggle { display: inline-flex; }
    .topbar, main { width: auto; }
    main { width: min(1120px, calc(100% - 32px)); }
    .stat-grid, .stat-grid.six, .split, .detail-grid, .stock-forms, .form-grid, .page-head { grid-template-columns: 1fr; display: grid; }
    .page-head { align-items: start; }
    .quote-head { display: none; }
    .quote-row { grid-template-columns: 1fr 1fr; }
}

.quote-editor { margin-top: 16px; }
.quote-head, .quote-row {
    display: grid;
    grid-template-columns: minmax(140px, 1.1fr) minmax(180px, 1.6fr) 90px 110px 36px;
    gap: 8px;
    align-items: start;
}
.quote-head { color: var(--muted); font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; margin-bottom: 6px; }
.quote-row { margin-bottom: 8px; }
.quote-row textarea { min-height: 64px; }
#add-quote-line { margin-top: 4px; }

.paper-doc {
    position: relative;
    max-width: 860px;
    margin: 0 auto;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 32px 36px 40px;
    overflow: hidden;
    color: #1c1c1c;
}
.doc-watermark {
    position: absolute;
    left: 50%;
    top: 46%;
    width: min(460px, 70%);
    transform: translate(-50%, -50%);
    opacity: 0.12;
    pointer-events: none;
    z-index: 0;
}
.paper-doc > :not(.doc-watermark) { position: relative; z-index: 1; }
.doc-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; }
.doc-logo { width: 150px; height: auto; }
.doc-title { text-align: right; }
.doc-title h1 {
    font-family: "Outfit", "Segoe UI", sans-serif;
    font-weight: 500;
    font-size: 40px;
    color: #2e75b6;
    letter-spacing: 0;
    line-height: 1;
}
.doc-title p { margin: 8px 0 0; font-weight: 700; }
.doc-company { margin-top: 22px; font-size: 13px; line-height: 1.45; }
.doc-company strong { display: block; font-size: 15px; margin-bottom: 2px; }
.doc-parties {
    display: flex;
    justify-content: space-between;
    gap: 24px;
    margin: 22px 0 16px;
    align-items: flex-end;
}
.doc-label { color: #444; margin-bottom: 2px; }
.doc-parties strong { display: block; }
.doc-detail { white-space: pre-line; }
.doc-date { display: flex; gap: 28px; align-items: baseline; }
.doc-date span { color: #444; }
.doc-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.doc-table th {
    background: #2e75b6;
    color: #fff;
    font-weight: 600;
    text-align: left;
    padding: 8px 10px;
}
.doc-table td { padding: 8px 10px; border-bottom: 1px solid #e4e4e4; vertical-align: top; }
.doc-table .num { text-align: right; white-space: nowrap; }
.doc-table .col-no { width: 36px; }
.doc-spec { white-space: pre-line; color: #333; margin-top: 4px; font-weight: 400; }
.doc-rate { color: #666; font-size: 12px; }
.doc-sub td { border-bottom: 1px solid #111; font-weight: 700; }
.doc-sub .label { background: #e7f1f8; }
.doc-grand {
    display: flex;
    justify-content: flex-end;
    gap: 48px;
    margin: 10px 0 22px;
    padding: 8px 10px;
    background: #f3f6f8;
    font-size: 16px;
}
.doc-grand strong { font-size: 18px; }
.doc-grand-stack {
    margin: 12px 0 22px auto;
    width: min(320px, 100%);
    display: grid;
    gap: 6px;
}
.doc-grand-stack div { display: flex; justify-content: space-between; gap: 24px; }
.doc-grand-stack .grand { font-weight: 700; font-size: 16px; border-top: 1px solid #d7d7d7; padding-top: 6px; }
.paper-doc h2 {
    font-family: "Outfit", "Segoe UI", sans-serif;
    font-size: 16px;
    font-weight: 600;
    letter-spacing: 0;
    margin: 18px 0 8px;
}
.doc-tax-total td { font-weight: 700; border-bottom: 2px solid #111; }
.doc-note { white-space: pre-line; margin-top: 4px; }
.ticket-head img { width: 72px; height: auto; }
.ticket-head strong { display: block; }

@media print {
    .sidebar, .topbar, .no-print, .banner { display: none !important; }
    .app-shell, .workspace, main { display: block; width: auto; margin: 0; padding: 0; }
    body { background: white; }
    .card, .stat { box-shadow: none; }
    .print-only { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
    .receipt, .paper-doc { border: 0; border-radius: 0; max-width: none; padding: 0; }
    .doc-table th, .doc-sub .label, .doc-grand {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}

@media (max-width: 760px) {
    .quote-head { display: none; }
    .quote-row { grid-template-columns: 1fr 1fr; }
}
