:root {
    color-scheme: light;
    --ink: #1e1a17;
    --muted: #6f655c;
    --line: #e6ddd2;
    --paper: #f3eee7;
    --card: #fffdfb;
    --accent: #9a3412;
    --accent-dark: #7c2d12;
    --good: #3f6212;
    --good-bg: #e7f2dc;
    --draft: #92400e;
    --draft-bg: #f8ecd9;
    --danger: #9f1239;
    --shadow: 0 18px 50px rgba(62, 42, 24, 0.06);
}

* { box-sizing: border-box; }

html { scroll-padding-bottom: 140px; }

[hidden] { display: none !important; }

body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    background:
        radial-gradient(900px 420px at 0% -10%, rgba(154, 52, 18, 0.08), transparent 55%),
        var(--paper);
    font-family: Outfit, "Segoe UI", sans-serif;
    font-size: 16px;
    line-height: 1.45;
}

button, input, select, textarea { font: inherit; }

a { color: var(--accent-dark); }

h1, h2, h3 { font-family: Fraunces, Georgia, serif; font-weight: 560; letter-spacing: -0.03em; }

h1 { font-size: clamp(2rem, 4vw, 2.7rem); margin: 0; line-height: 1.05; }

h2 { font-size: 1.45rem; margin: 0; }

h3 { font-size: 1.05rem; margin: 0 0 10px; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 22px;
    padding: 14px 22px;
    background: rgba(243, 238, 231, 0.92);
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(12px);
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: inherit;
    text-decoration: none;
}

.brand-mark {
    display: grid;
    width: 42px;
    height: 42px;
    place-items: center;
    border-radius: 50%;
    background: var(--ink);
    color: #f6eadc;
    font-family: Fraunces, Georgia, serif;
    font-size: 13px;
    letter-spacing: 0.06em;
}

.brand strong { display: block; font-size: 15px; }
.brand small { display: block; color: var(--muted); font-size: 12px; }

.nav { display: flex; gap: 4px; }

.nav a {
    padding: 8px 12px;
    border-radius: 999px;
    color: #3c342d;
    font-weight: 600;
    text-decoration: none;
}

.nav a.is-active { background: var(--ink); color: #fff; }

.topbar > .btn { margin-left: auto; }

main {
    width: min(1120px, calc(100% - 32px));
    margin: 0 auto;
    padding: 28px 0 72px;
}

.page-head, .section-head, .actions, .filters, .savebar, .system-fields, .service-card-top {
    display: flex;
    gap: 16px;
}

.page-head, .section-head, .filters, .savebar { justify-content: space-between; align-items: flex-end; }

.page-head { margin-bottom: 22px; align-items: flex-start; }

.kicker {
    margin: 0 0 6px;
    color: var(--accent);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

.lede, .section-head p, .hint, .muted, .sheet-contact { color: var(--muted); }

.lede { max-width: 64ch; margin: 10px 0 0; }

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 22px;
    box-shadow: var(--shadow);
}

.stack { display: grid; gap: 16px; }
.stack-sm, .fields { display: grid; gap: 14px; }
.stack-sm { margin-top: 16px; }

.grid-2, .split, .fact-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px 16px;
}

.split { align-items: start; gap: 16px; }

.span-2 { grid-column: span 2; }

.system-fields {
    margin: 16px 0;
    padding: 14px;
    border-radius: 14px;
    background: #f7f2eb;
    border: 1px dashed #ddcfc0;
}

.system-fields div { flex: 1; }
.system-fields span, .sheet-id span { display: block; color: var(--muted); font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase; }
.system-fields strong { font-family: Fraunces, Georgia, serif; font-size: 1.6rem; letter-spacing: 0.04em; }

.field { display: flex; flex-direction: column; gap: 6px; color: #4a433c; font-size: 13px; font-weight: 600; }
.optional { color: #8d8276; font-style: normal; font-weight: 500; }

input, select, textarea {
    width: 100%;
    padding: 11px 12px;
    border: 1px solid #ddd4c8;
    border-radius: 10px;
    background: #fff;
    color: var(--ink);
    font-weight: 450;
}

textarea { resize: vertical; }

input:focus, select:focus, textarea:focus {
    outline: 2px solid rgba(154, 52, 18, 0.28);
    border-color: var(--accent);
}

input[readonly] { background: #f6f1ea; color: #3f3832; }

.hint { margin: 12px 0 0; font-size: 14px; }

.btn, .text-btn, input, select, textarea {
    scroll-margin-bottom: 140px;
}

.btn, .text-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    cursor: pointer;
    text-decoration: none;
}

.btn {
    padding: 10px 16px;
    border: 1px solid #d9cfc3;
    background: #fff;
    color: var(--ink);
    font-weight: 600;
}

.btn:hover { border-color: #c9b8a6; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: #fffaf7; }
.btn-primary:hover { background: var(--accent-dark); }

.btn-light { background: transparent; border-color: rgba(255, 255, 255, 0.35); color: #fff; }
.btn-danger { color: var(--danger); background: #fff; }

.text-btn { padding: 0; border: 0; background: transparent; color: var(--danger); font-weight: 600; }

.service-card {
    margin-top: 12px;
    padding: 14px;
    border: 1px solid #eadfd3;
    border-radius: 14px;
    background: #fff;
}

.service-card-top { justify-content: space-between; align-items: center; margin-bottom: 10px; font-weight: 600; }

.service-grid {
    display: grid;
    grid-template-columns: 1.5fr 0.9fr 0.7fr 0.7fr 0.9fr;
    gap: 10px;
}

.savebar {
    position: sticky;
    bottom: 14px;
    align-items: center;
    padding: 14px 16px;
    border-radius: 16px;
    background: var(--ink);
    color: #f7f1ea;
    box-shadow: 0 16px 40px rgba(30, 26, 23, 0.25);
}

.savebar-total { display: flex; gap: 22px; }
.savebar strong { font-family: Fraunces, Georgia, serif; font-size: 1.35rem; font-weight: 560; margin-left: 6px; }

.flash {
    margin-bottom: 16px;
    padding: 12px 14px;
    border-radius: 12px;
    background: var(--good-bg);
    color: var(--good);
    font-weight: 600;
}

.flash ul { margin: 6px 0 0; padding-left: 18px; font-weight: 500; }
.flash-error { background: #fde8ee; color: var(--danger); }
.flash a { color: inherit; }

.filters { align-items: center; margin-bottom: 14px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chips a {
    padding: 7px 12px;
    border-radius: 999px;
    background: transparent;
    color: #3c342d;
    font-weight: 600;
    text-decoration: none;
    border: 1px solid transparent;
}
.chips a.is-on { background: #fff; border-color: var(--line); }

.search { display: flex; gap: 8px; }
.search input { width: min(280px, 70vw); }

.table-wrap { overflow-x: auto; }

table.data { width: 100%; border-collapse: collapse; }
table.data th, table.lines th {
    padding: 8px 10px;
    border-bottom: 1px solid var(--ink);
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-align: left;
    text-transform: uppercase;
}
table.data td { padding: 14px 10px; border-bottom: 1px solid #f0e7dc; vertical-align: middle; }
table.data tbody tr:hover { background: #fbf7f2; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.invoice-no { font-family: Fraunces, Georgia, serif; font-size: 1.15rem; letter-spacing: 0.04em; }
.row-actions { display: flex; justify-content: flex-end; gap: 12px; white-space: nowrap; }
.row-actions a { font-weight: 600; text-decoration: none; }

.pill {
    display: inline-flex;
    padding: 3px 8px;
    border-radius: 999px;
    font-family: Outfit, "Segoe UI", sans-serif;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}
.pill-draft { background: var(--draft-bg); color: var(--draft); }
.pill-final { background: var(--good-bg); color: var(--good); }

.pager { display: flex; justify-content: space-between; gap: 12px; margin-top: 16px; }
.pager a { font-weight: 600; }

.empty { padding: 28px 8px; text-align: center; }
.empty p { color: var(--muted); }

.sheet {
    width: min(840px, 100%);
    margin: 8px auto 20px;
    padding: 42px 46px 36px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    box-shadow: var(--shadow);
}

.sheet-head { display: flex; justify-content: space-between; gap: 24px; padding-bottom: 18px; border-bottom: 2px solid var(--ink); }
.sheet h2 { font-size: 2.3rem; }
.sheet-id { text-align: right; }
.sheet-id strong { display: block; margin: 2px 0 6px; font-family: Fraunces, Georgia, serif; font-size: 2rem; letter-spacing: 0.08em; }
.fact-grid { margin: 26px 0; }
.meta-list { display: grid; gap: 8px; margin: 0; }
.meta-list div { display: grid; grid-template-columns: 92px 1fr; gap: 10px; }
.meta-list dt { color: var(--muted); }
.meta-list dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }

table.lines { width: 100%; border-collapse: collapse; }
table.lines td { padding: 10px 6px; border-bottom: 1px solid #f0e7dc; }
.total-row td { border-bottom: 0; border-top: 2px solid var(--ink); font-weight: 700; padding-top: 12px; }
.sheet-thanks { margin: 28px 0 0; color: var(--muted); }
.draft-banner { margin: 0 0 18px; padding: 10px 12px; border-radius: 10px; background: var(--draft-bg); color: var(--draft); font-weight: 650; }

@media (max-width: 900px) {
    .service-grid { grid-template-columns: 1fr 1fr; }
    .topbar { flex-wrap: wrap; }
    .sheet { padding: 24px 18px; }
}

@media (max-width: 760px) {
    .grid-2, .split, .fact-grid, .page-head, .section-head, .filters, .savebar { display: grid; grid-template-columns: 1fr; }
    .span-2 { grid-column: auto; }
    .search, .actions, .savebar .actions { display: flex; flex-wrap: wrap; }
    .meta-list div { grid-template-columns: 1fr; gap: 2px; }
    .sheet-head { display: block; }
    .sheet-id { text-align: left; margin-top: 16px; }
}

@media print {
    @page { margin: 14mm; }
    body { background: #fff; }
    .topbar, .no-print, .flash { display: none !important; }
    main { width: auto; margin: 0; padding: 0; }
    .sheet { width: auto; margin: 0; border: 0; border-radius: 0; box-shadow: none; padding: 0; }
}
