:root { color-scheme: light dark;
  --bg: #f4f2ee; --panel: #fff; --ink: #121110; --ink-2: #55524c; --muted: #8b877f; --line: #e2ded6; --accent: #8a6a3a; --danger: #b42318; --r: 12px;
  --f-display: 'Archivo', system-ui, sans-serif; --f-body: 'Geist', system-ui, sans-serif; --f-mono: 'Geist Mono', ui-monospace, monospace; --f-serif: 'Instrument Serif', Georgia, serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --bg: #121110; --panel: #1b1a18; --ink: #f3f0ea; --ink-2: #c3beb4; --muted: #8f8a80; --line: #2f2d29; --accent: #d1a866; --danger: #f97066; }
  :root:not([data-theme="light"]) .brand img { filter: invert(1); }
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 var(--f-body); -webkit-font-smoothing: antialiased; }
a { color: inherit; }
button { font: inherit; color: inherit; cursor: pointer; }

.hd { position: sticky; top: 0; z-index: 20; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 16px; background: var(--bg); border-bottom: 1px solid var(--line); }
.brand { display: flex; gap: 10px; align-items: center; text-decoration: none; font: 500 16px var(--f-display); white-space: nowrap; }
.brand b { font-weight: 700; }
.hd__acts { display: flex; gap: 8px; }
@media (max-width: 480px) { .brand span { display: none; } }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 11px 18px; border-radius: 999px; background: var(--ink); color: var(--bg); border: 1px solid var(--ink); font-weight: 600; font-size: 14px; text-decoration: none; white-space: nowrap; }
.btn--sm { padding: 8px 14px; font-size: 13.5px; }
.btn--ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn--ghost:hover { border-color: var(--ink); }
.btn:active { transform: translateY(1px); }
.link { background: none; border: 0; padding: 0; color: var(--accent); font-size: 13px; text-decoration: underline; text-underline-offset: 2px; align-self: flex-start; }
.link.danger { color: var(--danger); }

.tabs { display: none; }
.app { display: grid; grid-template-columns: minmax(340px, 460px) 1fr; gap: 0; align-items: start; }
.ed { display: flex; flex-direction: column; gap: 12px; padding: 16px; max-height: calc(100vh - 61px); overflow-y: auto; position: sticky; top: 61px; border-right: 1px solid var(--line); }
.pv { padding: 16px; min-width: 0; }
.pv__scale { transform-origin: top left; margin: 0 auto; }

@media (max-width: 900px) {
  .tabs { display: flex; position: sticky; top: 59px; z-index: 15; background: var(--bg); border-bottom: 1px solid var(--line); }
  .tabs button { flex: 1; padding: 12px; background: none; border: 0; border-bottom: 2px solid transparent; font-weight: 600; color: var(--muted); }
  .tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); }
  .app { grid-template-columns: 1fr; }
  .ed { max-height: none; position: static; border-right: 0; }
  body:not([data-tab="preview"]) .pv { display: none; }
  body[data-tab="preview"] .ed { display: none; }
}

.box { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.box h2 { font: 600 16px var(--f-display); display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.box h2 small { font: 400 12px var(--f-body); color: var(--muted); }
.f { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.f > span { font-size: 12.5px; font-weight: 500; color: var(--ink-2); }
.f i { font-style: normal; color: var(--muted); font-weight: 400; }
.f input, .f select, .f textarea { width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--ink); font: inherit; font-size: 14.5px; outline: none; }
.f input[type="file"] { padding: 7px; font-size: 13px; }
.f input:focus, .f select:focus, .f textarea:focus { border-color: var(--ink); }
.f textarea { resize: vertical; }
.f select:disabled { opacity: .5; }
.chk { flex-direction: row; align-items: center; gap: 8px; align-self: end; padding-bottom: 10px; }
.chk input { width: 16px; height: 16px; accent-color: var(--ink); }
.chk span { font-size: 13.5px; color: var(--ink-2); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (max-width: 420px) { .row2, .row3 { grid-template-columns: 1fr; } }
.mt { margin-top: 6px; }
.note { font-size: 12.5px; color: var(--muted); }

.it { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; padding: 10px 0 12px; border-bottom: 1px dashed var(--line); position: relative; }
.it__d { grid-column: 1 / -1; }
.it__x { position: absolute; top: 6px; right: 0; width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--line); background: var(--bg); font-size: 16px; line-height: 1; }
.it__x:hover { border-color: var(--danger); color: var(--danger); }

.pro ul { padding-left: 18px; color: var(--ink-2); font-size: 13.5px; display: grid; gap: 3px; }
.pro .btn { align-self: flex-start; }

.dlg { margin: auto; width: min(560px, calc(100vw - 32px)); max-height: 80vh; border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); color: var(--ink); padding: 18px; }
.dlg::backdrop { background: rgba(0, 0, 0, .4); }
.dlg__hd { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.dlg__hd h2 { font: 600 18px var(--f-display); }
.saved { list-style: none; margin-top: 12px; display: grid; gap: 8px; }
.saved li { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; }
.saved__open { flex: 1; text-align: left; background: none; border: 0; display: flex; flex-direction: column; min-width: 0; }
.saved__open span { font-size: 12.5px; color: var(--muted); }
.ft { padding: 20px 16px 28px; font-size: 12.5px; color: var(--muted); text-align: center; }

/* ---------- the A4 sheet (always light, like paper) ---------- */
.sheet { width: 794px; min-height: 1123px; padding: 52px 56px 36px; background: #fff; color: #0a0a0a; font: 13px/1.5 var(--f-body); display: flex; flex-direction: column; gap: 24px; box-shadow: 0 2px 18px rgba(0, 0, 0, .1); -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.sheet h3 { font: 500 10px var(--f-mono); letter-spacing: .1em; text-transform: uppercase; color: #74716b; margin-bottom: 6px; }
.sheet .mono { font: 500 12.5px var(--f-mono); }
.sheet .strong { font-weight: 600; }
.sheet .small { font-size: 11.5px; color: #55524c; margin-top: 6px; }
.sheet .ph { color: #b3aea5; font-weight: 400; }
.sheet .c { text-align: center; padding: 24px !important; }
.sh-head { display: flex; justify-content: space-between; gap: 24px; padding-bottom: 20px; border-bottom: 2px solid #0a0a0a; }
.sh-brand { display: flex; gap: 16px; align-items: center; }
.sh-brand img { max-width: 72px; max-height: 64px; object-fit: contain; }
.sh-brand h1 { font: 600 22px/1.15 var(--f-display); font-stretch: 112%; letter-spacing: -.02em; margin-bottom: 3px; }
.sh-brand p { font-size: 12px; color: #55524c; }
.sh-title { text-align: right; flex-shrink: 0; }
.sh-title h2 { font: italic 400 34px/1 var(--f-serif); color: #8a6a3a; margin-bottom: 8px; }
.sh-meta { display: grid; grid-template-columns: 1.2fr 1fr; gap: 32px; }
.sh-meta dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 14px; align-content: start; }
.sh-meta dt { color: #74716b; }
.sh-meta dd { text-align: right; font-weight: 500; }
.sh-subject { margin-top: -6px; }
.sh-items { width: 100%; border-collapse: collapse; }
.sh-items th { font: 500 10px var(--f-mono); letter-spacing: .08em; text-transform: uppercase; text-align: left; padding: 9px 8px; background: #0a0a0a; color: #fff; }
.sh-items td { padding: 10px 8px; border-bottom: 1px solid #e8e6e1; vertical-align: top; }
.sh-items tr { break-inside: avoid; }
.sh-items .n { text-align: right; white-space: nowrap; }
.sh-sum { display: grid; grid-template-columns: 1fr 280px; gap: 32px; align-items: start; break-inside: avoid; }
.sh-sum table { width: 100%; border-collapse: collapse; }
.sh-sum td { padding: 4px 8px; }
.sh-sum td:last-child { text-align: right; white-space: nowrap; }
.sh-sum .tot td { padding: 10px 8px; font: 600 16px var(--f-display); border-top: 2px solid #0a0a0a; }
.sh-foot { display: grid; grid-template-columns: 1fr 220px; gap: 28px; margin-top: auto; align-items: end; break-inside: avoid; }
.sh-notes { display: flex; flex-direction: column; gap: 12px; font-size: 12px; color: #3b3a37; }
.sh-sign { text-align: center; font-size: 12px; }
.sh-sign > .strong:first-child { text-align: right; margin-bottom: 6px; }
.sh-sign__img { height: 64px; display: flex; align-items: flex-end; justify-content: center; border-bottom: 1px solid #0a0a0a; margin-bottom: 5px; padding-bottom: 3px; }
.sh-sign__img img { max-height: 60px; max-width: 100%; }
.sh-made { padding-top: 12px; border-top: 1px solid #e8e6e1; font-size: 10px; color: #9a958c; text-align: center; }

@page { size: A4; margin: 0; }
@media print {
  html, body { background: #fff !important; }
  .no-print, .tabs, .dlg { display: none !important; }
  .app { display: block; }
  .pv { padding: 0; display: block !important; }
  .pv__scale { transform: none !important; width: auto !important; height: auto !important; }
  .sheet { box-shadow: none; min-height: 1122px; }
}
