/* Fonts are bundled so the app looks the same with no internet. */
@font-face { font-family: "Poppins"; font-style: normal; font-weight: 400; font-display: swap; src: url("fonts/poppins-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Poppins"; font-style: normal; font-weight: 500; font-display: swap; src: url("fonts/poppins-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "Poppins"; font-style: normal; font-weight: 600; font-display: swap; src: url("fonts/poppins-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "Poppins"; font-style: normal; font-weight: 700; font-display: swap; src: url("fonts/poppins-latin-700-normal.woff2") format("woff2"); }
@font-face { font-family: "Poppins"; font-style: normal; font-weight: 800; font-display: swap; src: url("fonts/poppins-latin-800-normal.woff2") format("woff2"); }
@font-face { font-family: "Poppins"; font-style: italic; font-weight: 500; font-display: swap; src: url("fonts/poppins-latin-500-italic.woff2") format("woff2"); }
@font-face { font-family: "Montserrat"; font-style: italic; font-weight: 500; font-display: swap; src: url("fonts/montserrat-latin-500-italic.woff2") format("woff2"); }
@font-face { font-family: "Source Sans 3"; font-style: normal; font-weight: 400; font-display: swap; src: url("fonts/source-sans-3-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Source Sans 3"; font-style: normal; font-weight: 600; font-display: swap; src: url("fonts/source-sans-3-latin-600-normal.woff2") format("woff2"); }

/* Layout: app bar, then a two-pane workbench (form left, A5 paper preview right); panes become tabs on phones. */
:root {
  --bg: #F5F3F7;
  --surface: #FFFFFF;
  --ink: #1F1A24;
  --muted: #645C6E;
  --line: #E2DDE8;
  --field: #FFFFFF;
  --brand: #47195F;
  --btn: #47195F;
  --btn-ink: #FFFFFF;
  --accent: #FF6600;
  --accent-ink: #A84300;
  --soft: #F1EBF5;
  --ok: #1F7A4D;
  --danger: #B3261E;
  --desk: #E7E2EC;
  --font-display: "Poppins", "Segoe UI", system-ui, sans-serif;
  --font-body: "Source Sans 3", "Segoe UI", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141118; --surface: #1E1A24; --ink: #EEE9F2; --muted: #A99FB3; --line: #362F3F; --field: #17131C;
    --brand: #D2B3E8; --btn: #7A3AA0; --btn-ink: #FFFFFF; --accent: #FF8A3D; --accent-ink: #FFB27F; --soft: #2A2233;
    --ok: #5FC795; --danger: #FF8A80; --desk: #0E0C11; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #141118; --surface: #1E1A24; --ink: #EEE9F2; --muted: #A99FB3; --line: #362F3F; --field: #17131C;
  --brand: #D2B3E8; --btn: #7A3AA0; --btn-ink: #FFFFFF; --accent: #FF8A3D; --accent-ink: #FFB27F; --soft: #2A2233;
  --ok: #5FC795; --danger: #FF8A80; --desk: #0E0C11; color-scheme: dark;
}
* { box-sizing: border-box; }
body { background: var(--bg); color: var(--ink); font-family: var(--font-body); font-size: 15px; line-height: 1.45; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.appbar { position: sticky; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line); padding-inline: 16px; }
.appbar-in { max-width: 1320px; margin: 0 auto; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding-block: 10px; }
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--font-display); font-weight: 700; font-size: 17px; color: var(--brand); }
.brand svg { width: 34px; height: 34px; }
.tabs { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; }
.tab { border: 0; background: transparent; padding: 8px 12px; border-radius: 8px; cursor: pointer; font-weight: 600; color: var(--muted); min-height: 40px; }
.tab[aria-selected="true"] { background: var(--soft); color: var(--brand); }
.status { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--accent); }

main { max-width: 1320px; margin: 0 auto; padding-inline: 16px; padding-block: 18px 60px; }
.bench { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); gap: 22px; align-items: start; }
.pane-switch { display: none; gap: 6px; margin-bottom: 12px; }
.pane-switch button { flex: 1; }
@media (max-width: 960px) {
  .bench { grid-template-columns: minmax(0, 1fr); }
  .pane-switch { display: flex; }
  .bench[data-pane="form"] .preview-pane { display: none; }
  .bench[data-pane="preview"] .form-pane { display: none; }
}

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.form-pane { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
h2 { font-family: var(--font-display); font-size: 15px; font-weight: 600; margin: 0; color: var(--brand); letter-spacing: 0.2px; text-wrap: balance; }
.hint { font-size: 13px; color: var(--muted); margin: 0; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px 12px; }
@media (max-width: 520px) { .grid2, .grid3 { grid-template-columns: minmax(0, 1fr); } }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.field input, .field select, .field textarea { width: 100%; min-height: 42px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--field); }
.field textarea { min-height: 60px; resize: vertical; }
.field input:disabled, .field select:disabled, .field textarea:disabled { opacity: 0.75; }
.req { color: var(--accent-ink); }

.item { border: 1px solid var(--line); border-radius: 10px; padding: 12px; display: flex; flex-direction: column; gap: 10px; background: var(--bg); }
.item-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.item-head strong { font-family: var(--font-display); font-size: 13px; color: var(--brand); }
.amount { font-variant-numeric: tabular-nums; font-weight: 600; }

.btn { border: 1px solid var(--line); background: var(--surface); padding: 9px 14px; border-radius: 9px; cursor: pointer; min-height: 42px; font-weight: 600; }
.btn:hover:not(:disabled) { border-color: var(--brand); }
.btn.primary { background: var(--btn); color: var(--btn-ink); border-color: var(--btn); }
.btn.orange { background: var(--accent); color: #FFFFFF; border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 34px; padding: 5px 10px; font-size: 13.5px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.totals { display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; font-variant-numeric: tabular-nums; background: var(--soft); border-radius: 10px; padding: 12px 14px; }
.totals .big { font-family: var(--font-display); font-weight: 700; font-size: 17px; color: var(--brand); }
.totals .due { color: var(--accent-ink); font-weight: 700; }

.pad { width: 100%; height: 120px; border: 1.5px dashed var(--line); border-radius: 10px; background: #FFFFFF; touch-action: none; cursor: crosshair; display: block; }
.sigimg { height: 70px; background: #FFFFFF; border: 1px solid var(--line); border-radius: 10px; padding: 6px; object-fit: contain; max-width: 100%; }
.choice { display: flex; gap: 8px; flex-wrap: wrap; }
.choice label { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; cursor: pointer; min-height: 42px; }
.choice input { accent-color: var(--btn); }

.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.photo { display: flex; flex-direction: column; gap: 6px; }
.photo img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); max-width: 100%; }
.photo input { min-height: 34px; padding: 4px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--field); font-size: 13px; width: 100%; }

.banner { border-radius: 10px; padding: 10px 14px; font-size: 14px; background: var(--soft); border: 1px solid var(--line); }
.banner.saved { border-color: var(--ok); }
.banner.void { border-color: var(--danger); }

.preview-pane { position: sticky; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.desk { background: var(--desk); border-radius: 12px; padding: 18px; display: flex; flex-direction: column; align-items: center; gap: 18px; max-height: calc(100vh - 190px); overflow: auto; }
@media (max-width: 960px) { .preview-pane { position: static; } .desk { max-height: none; padding: 10px; } }
.paper-wrap { width: 100%; max-width: 600px; }
.paper-scale { transform-origin: top left; width: 600px; }
.paper-shadow { box-shadow: 0 2px 10px rgba(20, 10, 30, 0.18); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions .btn { flex: 1 1 140px; }

.list { display: flex; flex-direction: column; gap: 8px; }
.rec { display: grid; grid-template-columns: 130px minmax(0, 1fr) auto; gap: 12px; align-items: center; text-align: left; width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 12px 14px; cursor: pointer; min-height: 56px; }
.rec:hover { border-color: var(--brand); }
.rec .no { font-family: var(--font-display); font-weight: 600; color: var(--brand); font-variant-numeric: tabular-nums; }
.rec .who { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rec .sum { font-variant-numeric: tabular-nums; font-weight: 600; text-align: right; }
.pill { font-size: 11.5px; font-weight: 700; letter-spacing: 0.5px; padding: 2px 8px; border-radius: 99px; border: 1px solid var(--danger); color: var(--danger); margin-left: 6px; }
@media (max-width: 560px) { .rec { grid-template-columns: minmax(0, 1fr) auto; } .rec .no { grid-column: 1 / -1; } }
.stats { display: flex; gap: 22px; flex-wrap: wrap; font-variant-numeric: tabular-nums; }
.stats div { display: flex; flex-direction: column; }
.stats b { font-family: var(--font-display); font-size: 20px; color: var(--brand); }
.stats span { font-size: 12.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }

.toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 20px); transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600; z-index: 50; max-width: calc(100% - 32px); }
#export-host { position: fixed; left: -14000px; top: 0; width: 600px; pointer-events: none; }

/* ---------- Standalone app additions ---------- */
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; padding-bottom: env(safe-area-inset-bottom, 0px); }
[hidden] { display: none !important; }
img { max-width: 100%; }
.appbar { top: 0; padding-top: env(safe-area-inset-top, 0px); }
.preview-pane { top: calc(env(safe-area-inset-top, 0px) + 74px); }
.gps { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 13.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.gps b { color: var(--ink); font-weight: 600; }
.gps .dot { flex: none; }
.backup-row { display: flex; gap: 8px; flex-wrap: wrap; }
.notice { border-left: 0; border-radius: 10px; padding: 10px 14px; background: var(--soft); border: 1px solid var(--accent); font-size: 14px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: space-between; }
.steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; font-size: 14px; }
a { color: var(--brand); }

/* ---------- Receipt paper (always printed on white, independent of theme) ---------- */
.rc { width: 600px; height: 849px; box-sizing: border-box; padding: 24px 28px 18px; background: #FFFFFF; color: #1F1A24; font-family: "Poppins", Arial, sans-serif; font-size: 10px; line-height: 1.35; display: flex; flex-direction: column; gap: 7px; position: relative; isolation: isolate; overflow: hidden; }
.rc * { box-sizing: border-box; }
.rc-wm { position: absolute; left: 0; top: 0; width: 600px; height: 849px; z-index: -1; pointer-events: none; display: flex; align-items: center; justify-content: center; opacity: 0.045; }
.rc-wmtext { position: absolute; left: -100px; top: 400px; width: 800px; z-index: -1; transform: rotate(-30deg); text-align: center; font-size: 15px; font-weight: 700; letter-spacing: 6px; color: #47195F; opacity: 0.06; white-space: nowrap; }
.rc-void { position: absolute; left: 0; top: 300px; width: 600px; text-align: center; transform: rotate(-24deg); font-size: 120px; font-weight: 800; letter-spacing: 16px; color: #B3261E; opacity: 0.22; z-index: 5; }
.rc-head { display: flex; justify-content: space-between; align-items: flex-start; }
.rc-logo { display: flex; flex-direction: column; gap: 3px; }
.rc-tag { font-family: "Montserrat", Arial, sans-serif; font-style: italic; font-weight: 500; font-size: 14px; color: #47195F; padding-left: 5px; letter-spacing: 0.1px; }
.rc-title { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; padding-top: 4px; }
.rc-title h1 { margin: 0; font-size: 19px; font-weight: 700; letter-spacing: 1.5px; color: #47195F; }
.rc-no { display: flex; align-items: baseline; gap: 6px; }
.rc-no span { font-size: 11px; color: #5B5563; font-weight: 500; }
.rc-no b { font-size: 19px; color: #C8102E; letter-spacing: 0.5px; }
.rc-small { font-size: 9px; color: #5B5563; }
.rc-contact { display: flex; flex-direction: column; gap: 2px; padding: 6px 0; border-top: 3px solid #47195F; border-bottom: 1px solid #FF6600; }
.rc-contact .r { display: flex; justify-content: space-between; gap: 10px; }
.rc-handle { font-weight: 600; color: #47195F; }
.rc-cust { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 20px; }
.rc-f { display: flex; gap: 6px; align-items: flex-end; min-width: 0; }
.rc-f b { white-space: nowrap; font-weight: 600; }
.rc-f span { flex: 1; border-bottom: 1px solid #9A93A3; min-height: 15px; padding: 0 2px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.rc-table { border: 1px solid #CFC8D6; border-radius: 4px; overflow: hidden; }
.rc-tr { display: grid; grid-template-columns: 26px minmax(0, 1fr) 104px 70px 72px 78px; }
.rc-th { background: #47195F; color: #FFFFFF; font-weight: 600; font-size: 8.5px; }
.rc-th div { padding: 6px 4px; }
.rc-td { border-top: 1px solid #E4DFE9; min-height: 28px; }
.rc-td div { padding: 4px; border-right: 1px solid #E4DFE9; display: flex; flex-direction: column; justify-content: center; min-width: 0; overflow: hidden; }
.rc-td div:last-child { border-right: 0; }
.rc-c { text-align: center; align-items: center; }
.rc-rt { text-align: right; align-items: flex-end; font-variant-numeric: tabular-nums; }
.rc-sub { font-size: 7.5px; color: #6B6474; }
.rc-desc { font-weight: 500; overflow-wrap: anywhere; }
.rc-imei { font-size: 8.5px; overflow-wrap: anywhere; }
.rc-notes { display: flex; gap: 6px; align-items: flex-start; }
.rc-notes b { white-space: nowrap; font-weight: 600; padding-top: 1px; }
.rc-notes span { flex: 1; border-bottom: 1px solid #9A93A3; min-height: 15px; padding: 0 2px 1px; overflow-wrap: anywhere; }
.rc-mid { display: flex; gap: 14px; align-items: stretch; }
.rc-pay { flex: 1; display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.rc-lab { font-weight: 600; color: #47195F; font-size: 9px; letter-spacing: 0.5px; }
.rc-paid { display: flex; flex-direction: column; gap: 2px; }
.rc-bank { background: #F5F1F8; border-radius: 4px; padding: 7px 9px; display: flex; flex-direction: column; gap: 2px; }
.rc-bank .r { display: flex; justify-content: space-between; }
.rc-tot { width: 220px; border: 1px solid #CFC8D6; border-radius: 4px; overflow: hidden; display: flex; flex-direction: column; font-variant-numeric: tabular-nums; }
.rc-tot .r { display: flex; justify-content: space-between; padding: 5px 10px; border-bottom: 1px solid #E4DFE9; }
.rc-tot .r:last-child { border-bottom: 0; }
.rc-tot .t { background: #47195F; color: #FFFFFF; font-weight: 700; font-size: 11.5px; padding: 7px 10px; border-bottom: 0; }
.rc-tot .due b { color: #C8102E; }
.rc-sign { display: flex; gap: 14px; align-items: flex-end; }
.rc-qr { width: 84px; display: flex; flex-direction: column; align-items: center; gap: 2px; text-align: center; }
.rc-qr img { width: 74px; height: 74px; image-rendering: pixelated; }
.rc-qr span { font-size: 7.5px; color: #5B5563; line-height: 1.2; }
.rc-sigs { flex: 1; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.rc-sigs .r { display: flex; gap: 12px; }
.rc-sl { flex: 1; display: flex; gap: 6px; align-items: flex-end; min-width: 0; }
.rc-sl b { white-space: nowrap; font-weight: 600; }
.rc-sl span { flex: 1; border-bottom: 1px solid #9A93A3; height: 30px; display: flex; align-items: flex-end; overflow: hidden; padding: 0 2px; white-space: nowrap; }
.rc-sl img { height: 30px; max-width: 100%; object-fit: contain; object-position: left bottom; }
.rc-stamp { width: 150px; height: 100px; border: 1.2px dashed #C9C3D0; border-radius: 4px; display: flex; align-items: center; justify-content: center; color: #8A8392; font-size: 9px; }
.rc-stamp img.round { width: 100px; height: 100px; transform: rotate(-8deg); }
.rc-stamp img.rect { width: 144px; transform: rotate(-4deg); }
.rc-foot { margin-top: auto; display: flex; flex-direction: column; gap: 3px; padding-top: 7px; border-top: 1px solid #FF6600; }
.rc-terms { font-size: 8px; color: #4A4452; line-height: 1.45; }
.rc-foot .r { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.rc-thanks { font-weight: 600; color: #47195F; font-size: 10px; white-space: nowrap; }
.rc-issued { font-size: 8px; color: #5B5563; text-align: right; }
.rc-ev-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.rc-ev { display: flex; flex-direction: column; gap: 4px; }
.rc-ev .ph { height: 196px; border: 1px solid #E4DFE9; border-radius: 4px; background: #FAF8FB; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.rc-ev img { max-width: 100%; max-height: 100%; object-fit: contain; }
.rc-ev span { font-size: 9px; color: #4A4452; }
