/* ============================================================
   INVOICE GENERATOR — document editor, soft classic theme.
   ============================================================ */
:root {
  --bg: #f4f6f4;
  --surface: #ffffff;
  --surface-2: #ecefeb;
  --ink: #1d2421;
  --muted: #5c665f;
  --subtle: #8a948c;
  --line: #e1e6e0;
  --accent: #2f7a5f;          /* calm finance green */
  --accent-soft: #e9f2ec;
  --danger: #b3503f;
  --shadow: 0 12px 32px -20px rgba(30, 45, 35, 0.30);
  --paper-shadow: 0 24px 60px -24px rgba(20, 35, 25, 0.30);
  --radius: 13px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15191a;
    --surface: #1c2123;
    --surface-2: #242a2b;
    --ink: #e6ebe7;
    --muted: #99a39b;
    --subtle: #6c766e;
    --line: #2b3133;
    --accent: #6fc09a;
    --accent-soft: #1f2926;
    --danger: #e08a78;
    --shadow: 0 20px 48px -24px rgba(0, 0, 0, 0.6);
    --paper-shadow: 0 28px 64px -26px rgba(0, 0, 0, 0.7);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; min-height: 100dvh; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 14px; line-height: 1.55; }
a { color: inherit; text-decoration: none; }
a:hover { color: var(--accent); }
button, input, select, textarea { font: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.site-header { position: sticky; top: 0; z-index: 20; height: 58px; display: flex; align-items: center; justify-content: space-between; padding: 0 clamp(18px, 4vw, 44px); border-bottom: 1px solid var(--line); background: color-mix(in srgb, var(--bg) 86%, transparent); backdrop-filter: blur(12px); }
.logo-link { display: inline-flex; align-items: center; gap: 10px; color: var(--ink); font-weight: 750; }
.logo-link img { display: block; }
.logo-link small { display: block; font-size: 9.5px; font-weight: 700; color: var(--muted); letter-spacing: 0.12em; text-transform: uppercase; }
.home-link { color: var(--muted); font-size: 13px; font-weight: 650; }
.home-link:hover { color: var(--accent); }

.app-shell { width: min(1480px, 100%); margin: 0 auto; padding: clamp(16px, 3vw, 34px); }

.invoice-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; flex-wrap: wrap; padding-bottom: 16px; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.invoice-head h1 { margin: 4px 0 0; }
.invoice-head .lede { color: var(--muted); max-width: 46ch; margin: 0; }

.eyebrow { margin: 0; color: var(--accent); font-size: 11px; font-weight: 800; letter-spacing: 0.13em; text-transform: uppercase; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(26px, 4vw, 44px); line-height: 1.04; letter-spacing: -0.01em; font-weight: 820; }

.invoice-shell { display: grid; grid-template-columns: minmax(0, 1fr) minmax(420px, 0.92fr); gap: 18px; align-items: start; }

/* Form */
.form-pane { display: grid; gap: 14px; }
.panel { padding: 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); display: grid; gap: 11px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.panel-head h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.09em; color: var(--muted); font-weight: 800; }
.panel-actions { display: flex; gap: 12px; }
.text-btn { border: 0; background: transparent; color: var(--accent); padding: 0; font-weight: 750; font-size: 12px; cursor: pointer; }
.text-btn.danger { color: var(--danger); }

.field { display: grid; gap: 6px; color: var(--muted); font-size: 12px; font-weight: 700; }
.field.inline { display: inline-grid; }
.mini-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mini-row:has(> :nth-child(3)) { grid-template-columns: 1fr 1fr 1fr; }
.check-line { display: inline-flex; align-items: center; gap: 9px; color: var(--ink); font-size: 13px; font-weight: 600; }
.check-line input { accent-color: var(--accent); width: 16px; height: 16px; }

input[type="text"], input[type="email"], input[type="tel"], input[type="number"], input[type="date"], select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 9px; background: var(--surface); color: var(--ink); padding: 9px 10px; outline: none;
}
textarea { resize: vertical; font-family: inherit; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 15%, transparent); }

.with-btn { display: flex; gap: 6px; }
.with-btn input { flex: 1; }
.mini-btn { flex-shrink: 0; width: 38px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface-2); color: var(--ink); font-weight: 800; cursor: pointer; }
.mini-btn:hover { border-color: var(--accent); color: var(--accent); }

.file-drop { display: grid; gap: 7px; color: var(--muted); font-size: 12px; font-weight: 700; }
.file-drop input { width: 100%; border: 1px dashed var(--line); border-radius: 9px; padding: 9px; background: var(--surface); color: var(--muted); }
.file-drop span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--subtle); font-family: var(--mono); font-size: 11px; }

.rule-hint { margin: 0; color: var(--subtle); font-size: 11px; font-weight: 600; }
.valid-pill { justify-self: start; font-family: var(--mono); font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); }
.valid-pill.is-ok { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); background: var(--accent-soft); }
.valid-pill.is-bad { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--line)); }

/* Items editor */
.items-head, .item-row { display: grid; grid-template-columns: 1fr 64px 96px 96px 30px; gap: 8px; align-items: center; }
.items-head { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--subtle); font-weight: 800; padding: 0 2px; }
.items-head span:nth-child(2), .items-head span:nth-child(3), .items-head span:nth-child(4) { text-align: right; }
.item-row { margin-top: 8px; }
.it-qty, .it-price { text-align: right; }
.it-amount { text-align: right; font-family: var(--mono); font-size: 12px; font-weight: 700; color: var(--ink); }
.it-del { width: 28px; height: 28px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface-2); color: var(--muted); cursor: pointer; font-size: 15px; line-height: 1; }
.it-del:hover { border-color: var(--danger); color: var(--danger); }

/* Preview */
.preview-pane { position: sticky; top: 74px; display: grid; gap: 12px; }
.preview-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }
.preview-toolbar .field.inline { flex-direction: row; align-items: center; gap: 8px; color: var(--muted); }
.preview-toolbar select { width: auto; }
.toolbar-actions { display: flex; gap: 8px; }
.primary-btn { min-height: 40px; padding: 0 18px; border-radius: 9px; border: 1px solid var(--accent); background: var(--accent); color: #fff; font-weight: 800; cursor: pointer; }
.primary-btn:hover { background: color-mix(in srgb, var(--accent) 88%, #000); }

.paper-wrap { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface-2); padding: clamp(10px, 2vw, 22px); overflow: auto; }

/* ---------- Invoice document (A4) ---------- */
.invoice-doc {
  --pad: clamp(22px, 4vw, 44px);
  width: 100%; max-width: 720px; margin: 0 auto; overflow: hidden;
  background: #ffffff; color: #1d2421; border-radius: 4px; box-shadow: var(--paper-shadow);
  padding: var(--pad); font-size: 13px; line-height: 1.5;
}
.invoice-doc h2, .invoice-doc h3, .invoice-doc p { margin: 0; }
.doc-head { display: flex; justify-content: space-between; gap: 24px; align-items: flex-start; }
.doc-from { flex: 1 1 auto; min-width: 0; }
.doc-logo { max-width: 130px; max-height: 56px; display: block; margin-bottom: 10px; }
.doc-fromname { font-size: 16px; font-weight: 800; word-break: break-word; }
.doc-meta { color: #5c665f; font-size: 12px; }
.doc-meta div { margin-top: 1px; word-break: break-word; }
.doc-title { text-align: right; flex: 0 0 auto; min-width: 188px; }
.doc-title h2 { font-size: 28px; letter-spacing: 0.06em; color: #2f7a5f; }
.doc-no { font-family: var(--mono); font-weight: 700; margin: 2px 0 8px; word-break: break-all; }
.doc-dates { margin-left: auto; border-collapse: collapse; font-size: 12px; }
.doc-dates td { padding: 1px 0 1px 12px; color: #5c665f; white-space: nowrap; }
.doc-dates td:last-child { color: #1d2421; font-weight: 600; text-align: right; }

.doc-billto { margin: 22px 0 14px; }
.doc-billto h3 { font-size: 10px; text-transform: uppercase; letter-spacing: 0.1em; color: #8a948c; margin-bottom: 4px; }
.doc-toname { font-weight: 700; font-size: 14px; }

.doc-items { width: 100%; border-collapse: collapse; margin-top: 8px; }
.doc-items th { text-align: left; font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: #8a948c; border-bottom: 2px solid #e1e6e0; padding: 8px 6px; }
.doc-items td { padding: 9px 6px; border-bottom: 1px solid #eef1ec; vertical-align: top; }
.doc-items .c-num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.doc-items th.c-num { text-align: right; }

.doc-bottom { display: flex; justify-content: space-between; gap: 28px; margin-top: 18px; }
.doc-pay { font-size: 12px; color: #5c665f; max-width: 60%; }
.doc-pay h3 { font-size: 10px; text-transform: uppercase; letter-spacing: 0.1em; color: #8a948c; margin-bottom: 4px; }
.doc-pay div { margin-top: 1px; }
.doc-notes { margin-top: 10px; }
.doc-note { margin-top: 10px; font-style: italic; }
.doc-summary { border-collapse: collapse; min-width: 240px; align-self: flex-start; }
.doc-summary td { padding: 5px 0; }
.doc-summary td:last-child { text-align: right; font-variant-numeric: tabular-nums; padding-left: 24px; }
.doc-summary .grand td { border-top: 2px solid #e1e6e0; padding-top: 9px; font-size: 16px; font-weight: 800; color: #1d2421; }

/* ---------- templates (visually distinct) ---------- */
/* Classic — green divider under the header, green accents */
.tpl-classic .doc-head { border-bottom: 2px solid #2f7a5f; padding-bottom: 16px; }
.tpl-classic .doc-title h2 { color: #2f7a5f; }
.tpl-classic .doc-summary .grand td { color: #2f7a5f; }

/* Modern — full-bleed coloured header band, accent total chip */
.tpl-modern .doc-head { background: #2f7a5f; color: #fff; margin: calc(var(--pad) * -1) calc(var(--pad) * -1) 0; padding: 30px var(--pad); align-items: center; }
.tpl-modern .doc-fromname { font-size: 18px; }
.tpl-modern .doc-meta, .tpl-modern .doc-dates td { color: rgba(255, 255, 255, 0.85); }
.tpl-modern .doc-dates td:last-child { color: #fff; }
.tpl-modern .doc-title h2 { color: #fff; font-size: 32px; font-weight: 800; }
.tpl-modern .doc-billto { margin-top: 20px; }
.tpl-modern .doc-items th { border-bottom-color: #2f7a5f; color: #2f7a5f; }
.tpl-modern .doc-summary .grand td { background: #eaf3ee; color: #2f7a5f; border-top: 0; padding: 10px 8px; border-radius: 4px; }

/* Minimal — monochrome, hairlines, light title, airy */
.tpl-minimal { color: #2b2b2b; }
.tpl-minimal .doc-head { border: 0; }
.tpl-minimal .doc-title h2 { color: #2b2b2b; font-weight: 400; letter-spacing: 0.18em; }
.tpl-minimal .doc-items th { border-bottom: 1px solid #cfcfcf; color: #9a9a9a; letter-spacing: 0.14em; }
.tpl-minimal .doc-items td { border-bottom: 1px solid #f0f0f0; }
.tpl-minimal .doc-summary .grand td { color: #2b2b2b; border-top: 1px solid #cfcfcf; font-weight: 700; }
.tpl-minimal .doc-billto h3, .tpl-minimal .doc-pay h3 { letter-spacing: 0.14em; }

/* Receipt — narrow monospace ticket */
.tpl-receipt { max-width: 420px; font-family: var(--mono); font-size: 12px; }
.tpl-receipt .doc-head { flex-direction: column; gap: 6px; text-align: center; align-items: center; border-bottom: 1px dashed #c9cfc7; padding-bottom: 12px; }
.tpl-receipt .doc-from { text-align: center; }
.tpl-receipt .doc-title { text-align: center; min-width: 0; }
.tpl-receipt .doc-title h2 { font-size: 18px; color: #1d2421; }
.tpl-receipt .doc-dates { margin: 0 auto; }
.tpl-receipt .doc-bottom { flex-direction: column; }
.tpl-receipt .doc-summary { min-width: 0; width: 100%; }
.tpl-receipt .doc-items th, .tpl-receipt .doc-items td { padding-left: 0; padding-right: 0; }

/* Disclaimer / info / faq */
.disclaimer { display: flex; gap: 12px; align-items: flex-start; margin-top: 18px; padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--accent-soft); color: var(--ink); font-size: 13px; line-height: 1.55; }
.disclaimer .dz-badge { flex-shrink: 0; font-size: 16px; color: var(--accent); }
.disclaimer p { margin: 0; }

.info { margin-top: 16px; padding: clamp(20px, 3vw, 30px); border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); display: grid; gap: 18px; }
.info-intro h2 { font-size: clamp(20px, 2.6vw, 30px); margin: 6px 0 8px; letter-spacing: -0.01em; }
.info-intro p { color: var(--muted); margin: 0; }
.faq { display: grid; gap: 10px; }
.faq-2col { grid-template-columns: 1fr 1fr; align-items: start; }
details { border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); padding: 0 16px; }
summary { cursor: pointer; font-weight: 750; padding: 13px 0; list-style: none; display: flex; justify-content: space-between; align-items: center; gap: 12px; color: var(--ink); }
summary::-webkit-details-marker { display: none; }
summary::after { content: "+"; color: var(--accent); font-weight: 800; font-size: 17px; }
details[open] summary::after { content: "\2013"; }
details > p { margin: 0 0 14px; color: var(--muted); font-size: 13px; line-height: 1.55; }

.site-footer { max-width: 1480px; margin: 0 auto; padding: 24px clamp(16px, 3vw, 34px) 36px; display: flex; gap: 16px; justify-content: space-between; color: var(--subtle); font-size: 12px; }
.site-footer nav { display: flex; flex-wrap: wrap; gap: 16px; }

@media (max-width: 1080px) {
  .invoice-shell { grid-template-columns: 1fr; }
  .preview-pane { position: static; order: -1; }
}
@media (max-width: 720px) {
  .app-shell { padding: 14px; }
  .mini-row, .mini-row:has(> :nth-child(3)), .faq-2col { grid-template-columns: 1fr; }
  .items-head { display: none; }
  .item-row { grid-template-columns: 1fr 1fr; gap: 6px; padding: 10px; border: 1px solid var(--line); border-radius: 9px; }
  .item-row .it-desc { grid-column: 1 / -1; }
  .it-amount { grid-column: 1 / 2; }
  .it-del { grid-column: 2 / 3; justify-self: end; }
  .site-header { padding: 0 14px; }
  .home-link { display: none; }
  .site-footer { flex-direction: column; }
}

/* ---------- print → PDF ---------- */
@media print {
  @page { size: A4; margin: 14mm; }
  .site-header, .site-footer, .form-pane, .invoice-head, .preview-toolbar, .print-tip, .disclaimer, .info { display: none !important; }
  body { background: #fff; }
  .app-shell { width: auto; max-width: none; padding: 0; }
  .invoice-shell { display: block; }
  .preview-pane { position: static; display: block; }
  .paper-wrap { border: 0; background: #fff; padding: 0; overflow: visible; }
  .invoice-doc { max-width: none; width: 100%; box-shadow: none; border-radius: 0; padding: 0; }
  .tpl-modern .doc-head { margin: 0; padding: 20px 24px; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* lang-switcher */
.lang-switcher { position: relative; }
.lang-switcher > summary { list-style: none; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 0 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface-2, transparent); color: var(--muted); font-size: 13px; font-weight: 700; }
.lang-switcher > summary::-webkit-details-marker { display: none; }
.lang-switcher > summary::marker { content: ""; }
.lang-switcher > summary:hover { color: var(--accent); border-color: var(--accent); }
.lang-menu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 60; display: grid; gap: 2px; max-height: 64vh; overflow: auto; min-width: 190px; padding: 8px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow, 0 14px 36px rgba(0,0,0,.25)); }
.lang-menu a { padding: 7px 10px; border-radius: 8px; color: var(--ink); font-size: 13px; font-weight: 600; white-space: nowrap; }
.lang-menu a:hover { background: var(--surface-2); color: var(--accent); }
@media (max-width: 720px) { .lang-switcher { display: none; } }
