:root {
  --bg: #f3f6f5; --card: #ffffff; --text: #1b2421; --muted: #66726d; --line: #d6dedb;
  --accent: #1f7a5a; --accent-text: #ffffff; --danger: #c0392b; --warn: #c27a0e;
}
:root[data-theme="dark"] {
  --bg: #121715; --card: #1b221f; --text: #e5ece9; --muted: #98a6a0; --line: #2c3834;
  --accent: #4fc79c; --accent-text: #08150f; --danger: #ef6b5b; --warn: #e5a84a;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121715; --card: #1b221f; --text: #e5ece9; --muted: #98a6a0; --line: #2c3834;
    --accent: #4fc79c; --accent-text: #08150f; --danger: #ef6b5b; --warn: #e5a84a;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
button { border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 7px 12px; cursor: pointer; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.danger { color: var(--danger); border-color: var(--danger); }
button.ghost { background: transparent; }
input, select, textarea { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; width: 100%; }
a { color: var(--accent); }
.spacer { flex: 1; }
.muted { color: var(--muted); font-size: 13px; }

#app { max-width: 860px; margin: 0 auto; padding: 0 12px 96px; }
.bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 12px 0;
  padding-top: max(12px, env(safe-area-inset-top)); }
.brand { font-size: 18px; color: var(--accent); }
.tabs { display: flex; gap: 6px; margin-left: auto; }
.tabs button.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

.banner { padding: 10px 12px; border: 1px solid var(--warn); border-radius: 8px; background: var(--card); margin-bottom: 10px; }
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; }
.summary > div { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px; }
.summary .k { color: var(--muted); font-size: 12px; }
.summary .v { font-size: 18px; font-weight: 700; margin-top: 2px; }
.summary .bad .v { color: var(--danger); }

.toolbar { display: flex; gap: 8px; margin-bottom: 10px; }
.toolbar select { width: auto; }
.list { display: flex; flex-direction: column; gap: 8px; }
.item { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; cursor: pointer;
  display: flex; gap: 10px; align-items: center; }
.item .main { flex: 1; min-width: 0; }
.item .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .amt { font-weight: 700; white-space: nowrap; }
.badge { font-size: 11px; border-radius: 999px; padding: 1px 8px; border: 1px solid var(--line); color: var(--muted); }
.badge.paid { color: var(--accent); border-color: var(--accent); }
.badge.accepted { color: var(--accent); border-color: var(--accent); }
.badge.declined { color: var(--muted); border-color: var(--line); text-decoration: line-through; }
.badge.expired { color: var(--danger); border-color: var(--danger); }
.badge.overdue { color: var(--danger); border-color: var(--danger); }
.badge.sent { color: var(--warn); border-color: var(--warn); }
.empty { text-align: center; color: var(--muted); padding: 36px 12px; }

.panel { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 12px; }
.panel h2 { font-size: 17px; margin: 14px 0 8px; }
.panel h2:first-child { margin-top: 0; }
.panel h3 { font-size: 14px; margin: 14px 0 6px; color: var(--muted); }
label { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; font-size: 13px; color: var(--muted); flex: 1; min-width: 0; }
label input, label select, label textarea { color: var(--text); font-size: 15px; }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); font-size: 15px; }
label.check input { width: auto; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > label { min-width: 120px; }
.actions { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.actions.wrap { flex-wrap: wrap; }

.line { display: grid; grid-template-columns: 1fr 70px 90px 90px 30px; gap: 6px; align-items: center; margin-bottom: 8px; }
.line .ltotal { text-align: right; font-weight: 600; }
.line .ltax { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; font-size: .85rem; color: var(--muted); }
.line .ltax input { width: 90px; }
.line button { padding: 2px 0; }
.totals { margin: 12px 0; border-top: 1px solid var(--line); padding-top: 8px; }
.totals div { display: flex; justify-content: space-between; padding: 2px 0; }
.totals .grand { font-size: 18px; font-weight: 700; border-top: 1px solid var(--line); margin-top: 4px; padding-top: 6px; }

.fab { position: fixed; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom)); width: 56px; height: 56px; border-radius: 50%;
  background: var(--accent); color: var(--accent-text); font-size: 30px; line-height: 1; border: 0; padding: 0; box-shadow: 0 4px 14px rgba(0,0,0,.3); }

dialog { width: min(520px, 94vw); border: 1px solid var(--line); border-radius: 14px; background: var(--card); color: var(--text); padding: 16px; }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog h2 { margin: 0 0 10px; font-size: 18px; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: 90px; background: var(--text); color: var(--bg);
  padding: 8px 14px; border-radius: 8px; z-index: 20; }

@media (max-width: 640px) {
  .line { grid-template-columns: 1fr 1fr 1.3fr 34px; }
  .line .ldesc { grid-column: 1 / -1; }
  .lhead { display: none; }
  .summary .v { font-size: 15px; }
}

.btnlink { display: inline-block; border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 8px; padding: 7px 12px; text-decoration: none; }
dialog textarea { width: 100%; }

/* ---- Printable invoice ---- */
#printArea { display: none; }
@media print {
  body { background: #fff; color: #000; }
  #app, .fab, .toast, dialog { display: none !important; }
  #printArea { display: block; }
  @page { margin: 14mm; }
}
.inv { font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: #111; max-width: 780px; margin: 0 auto; }
.inv h1 { font-size: 26px; margin: 0; letter-spacing: 1px; }
.inv .head { display: flex; justify-content: space-between; gap: 20px; border-bottom: 2px solid var(--inv-accent, #1f7a5a); padding-bottom: 10px; margin-bottom: 14px; }
.inv .biz { white-space: pre-line; }
.inv .biz b { font-size: 16px; }
.inv .meta { text-align: right; margin-left: auto; }
.inv .cols { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 14px; }
.inv .lab { color: #666; font-size: 12px; text-transform: uppercase; }
.inv .pre { white-space: pre-line; }
.inv table { width: 100%; border-collapse: collapse; margin: 6px 0; }
.inv th { text-align: left; font-size: 12px; text-transform: uppercase; color: #555; border-bottom: 1px solid #999; padding: 4px 6px; }
.inv td { padding: 5px 6px; border-bottom: 1px solid #ddd; vertical-align: top; }
.inv .r { text-align: right; }
.inv .tot { margin-left: auto; width: 260px; margin-top: 8px; }
.inv .tot div { display: flex; justify-content: space-between; padding: 2px 6px; }
.inv .tot .g { font-weight: 700; font-size: 16px; border-top: 2px solid #111; margin-top: 4px; padding-top: 5px; }
.inv .foot { margin-top: 18px; font-size: 13px; }
.inv .paid { color: var(--inv-accent, #1f7a5a); font-weight: 700; border: 2px solid var(--inv-accent, #1f7a5a); display: inline-block; padding: 2px 10px; transform: rotate(-4deg); }

.badge.partial { color: var(--warn); border-color: var(--warn); }
.todo { background: var(--card); border: 1px solid var(--accent); border-radius: 10px; padding: 8px 12px; margin-bottom: 10px; }
.todo h3 { margin: 4px 0 6px; font-size: 14px; }
.todorow { display: flex; gap: 8px; align-items: center; padding: 6px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.todorow .main { flex: 1; min-width: 160px; }
.todorow .t { font-weight: 600; }
.payrow { display: flex; gap: 8px; align-items: center; justify-content: space-between; padding: 3px 0; border-bottom: 1px solid var(--line); }
.payrow span { flex: 1; min-width: 0; }
.payrow button { padding: 0 8px; }
.rtable { width: 100%; border-collapse: collapse; font-size: 14px; }
.rtable th, .rtable td { padding: 5px 4px; border-bottom: 1px solid var(--line); text-align: left; }
.rtable th { color: var(--muted); font-weight: 600; font-size: 12px; }
.rtable .r { text-align: right; white-space: nowrap; }
.bars { display: flex; gap: 8px; align-items: flex-end; }
.bar1 { flex: 1; text-align: center; min-width: 0; }
.fillbox { height: 90px; display: flex; align-items: flex-end; background: var(--bg); border-radius: 6px; overflow: hidden; }
.fillbox .fill { width: 100%; background: var(--accent); min-height: 1px; }
.barv { font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 640px) { .tabs { flex-wrap: wrap; } }
[hidden] { display: none !important; }

.intro { background: var(--card); border: 1px solid var(--accent); border-radius: 10px; padding: 10px 14px; margin-bottom: 10px; }
.intro p { margin: 6px 0; }
#screenHelp ul, #screenHelp ol { padding-left: 1.2em; margin: 4px 0 8px; }
#screenHelp li { margin: 3px 0; }

.callout { border-color: var(--warn); }

.reflink { text-decoration: none; color: var(--muted); font-size: 20px; line-height: 1; padding: 6px 8px; border-radius: 6px; }
.reflink:hover, .reflink:focus-visible { color: var(--text); background: var(--line); }

/* ---- Layout variants (the same markup, different styling) ---- */
.inv, .inv * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
/* modern: coloured header band, tinted table header */
.inv.lay-modern .head { background: var(--inv-accent); color: #fff; border: 0; border-radius: 6px; padding: 16px 18px; }
.inv.lay-modern .head h1, .inv.lay-modern .head b { color: #fff; }
.inv.lay-modern th { background: #f1f3f4; color: #222; border-bottom: 2px solid var(--inv-accent); }
.inv.lay-modern .tot .g { color: var(--inv-accent); border-top: 2px solid var(--inv-accent); }
.inv.lay-modern .lab { color: var(--inv-accent); font-weight: 700; }
/* minimal: hairlines, quiet type, accent only on the title and totals */
.inv.lay-minimal { font-weight: 300; letter-spacing: .1px; }
.inv.lay-minimal .head { border-bottom: 1px solid #ddd; padding-bottom: 14px; margin-bottom: 20px; }
.inv.lay-minimal h1 { font-size: 20px; font-weight: 300; letter-spacing: 6px; color: var(--inv-accent); }
.inv.lay-minimal .biz b, .inv.lay-minimal .cols b { font-weight: 600; }
.inv.lay-minimal th { border-bottom: 1px solid #bbb; color: #777; font-weight: 400; }
.inv.lay-minimal td { border-bottom: 1px solid #f0f0f0; padding: 8px 6px; }
.inv.lay-minimal .tot .g { border-top: 1px solid #bbb; color: var(--inv-accent); }
.inv.lay-minimal .lab { color: #999; }
/* compact: small type and tight rows so long invoices stay on one page */
.inv.lay-compact { font-size: 12px; line-height: 1.3; }
.inv.lay-compact h1 { font-size: 20px; }
.inv.lay-compact .head { padding-bottom: 6px; margin-bottom: 8px; border-bottom-width: 1px; }
.inv.lay-compact .cols { margin-bottom: 8px; }
.inv.lay-compact th, .inv.lay-compact td { padding: 2px 5px; }
.inv.lay-compact .tot .g { font-size: 13px; }
.inv.lay-compact .foot { margin-top: 10px; font-size: 11px; }

/* settings: accent swatches and preview */
.swatches { display: flex; gap: 8px; flex-wrap: wrap; margin: 4px 0 10px; }
.swatch { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--line); padding: 0; }
.swatch[aria-pressed="true"] { outline: 3px solid var(--text); outline-offset: 2px; }
.layoutpreview { border: 1px solid var(--line); border-radius: 8px; background: #fff; overflow: hidden; margin: 6px 0 10px; }
.previewinner { transform-origin: top left; padding: 24px; box-sizing: border-box; background: #fff; }

.lhead { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.lhead .r { text-align: right; }

.chargerow { display: grid; grid-template-columns: 1fr 110px auto 30px; gap: 6px; align-items: center; margin-bottom: 8px; }
.chargerow label.check { margin: 0; flex: none; }
.chargerow button { padding: 2px 0; }
@media (max-width: 640px) { .chargerow { grid-template-columns: 1fr 1fr; } .chargerow label.check { grid-column: 1; } }

.itemrow { display: grid; grid-template-columns: 1fr 110px 44px; gap: 6px; align-items: center; margin-bottom: 6px; }
.itemrow button { padding: 6px 0; }
.unitrow { margin-left: 18px; }
.unitadd { margin: 0 0 8px 18px; padding: 4px 8px; font-size: 13px; }
#itemsList { max-height: 45vh; overflow: auto; }

.combo { position: relative; }
.combolist { position: absolute; z-index: 30; left: 0; right: 0; top: calc(100% + 2px); max-height: 260px; overflow: auto; background: var(--card); color: var(--text);
  border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 6px 18px rgba(0,0,0,.25); }
.comboitem { padding: 8px 10px; cursor: pointer; font-size: 15px; }
.comboitem.active, .comboitem:hover { background: var(--bg); }
.comboitem.create { color: var(--accent); font-weight: 600; border-top: 1px solid var(--line); }
.comboempty { padding: 8px 10px; }

#settingsStatus.bad { color: var(--danger); }

#app { padding-bottom: calc(90px + env(safe-area-inset-bottom)); }

.inv .biz.withlogo { display: flex; align-items: center; gap: 12px; }
.inv .bt { white-space: pre-line; }
.inv .biz img.logo { display: block; flex: none; max-width: 150px; max-height: 60px; object-fit: contain; }
.inv.lay-modern .biz img.logo { background: #fff; padding: 3px 5px; border-radius: 4px; }
.inv.lay-compact .biz img.logo { max-height: 44px; max-width: 110px; }
.logorow { margin: 8px 0 12px; }
.logoprev { max-width: 160px; max-height: 64px; object-fit: contain; border: 1px solid #ddd; border-radius: 4px; background: #fff; padding: 2px; }

#impBody .ok { color: var(--accent); font-weight: 600; }
#impBody select { max-width: 100%; }
#importDialog { width: min(600px, 94vw); max-height: 92vh; overflow: auto; }

/* About and FAQ text for search engines and first-time visitors; hidden in the installed app and when printing */
.about { max-width: 760px; margin: 0 auto; padding: 8px 16px 96px; color: var(--text); }
.about h2 { font-size: 1.2rem; margin: 1.4em 0 .4em; }
.about h3 { font-size: 1rem; margin: 1.1em 0 .3em; }
.about p, .about li { color: var(--muted); line-height: 1.55; }
.about ol { padding-left: 1.2em; }
.about details { border-top: 1px solid var(--line); padding: .6em 0; }
.about summary { cursor: pointer; font-weight: 600; color: var(--text); }
.about a { color: inherit; }
@media (display-mode: standalone) { .about { display: none; } }
@media print { .about { display: none !important; } }
/* shown only once the app has drawn its first screen (the app adds .ready), so it never flashes at the top while loading */
html:not(.ready) .about { display: none; }

/* keep the shell invisible until the app has drawn its first screen, so nothing shifts as banners and lists are filled in */
html:not(.ready) body > :not(script):not(style):not(link) { visibility: hidden; }

/* ---- Receipt (POS) layout: narrow till-roll bill ---- */
.inv.lay-pos { width: var(--pos-w, 302px); max-width: none; margin: 0; font: 12px/1.35 ui-monospace, "Courier New", Consolas, monospace, system-ui; color: #000; padding: 0 2px; box-sizing: border-box; }
.lay-pos .ptop { text-align: center; white-space: pre-line; }
.lay-pos .ptop b { display: block; font-size: 15px; }
.lay-pos .ptitle { text-align: center; font-weight: 700; letter-spacing: 1px; margin: 2px 0; }
.lay-pos .rule { border-top: 1px dashed #000; margin: 5px 0; }
.lay-pos .pr { display: flex; justify-content: space-between; gap: 8px; }
.lay-pos .pr span:last-child { text-align: right; white-space: nowrap; }
.lay-pos .pd { margin-top: 3px; overflow-wrap: anywhere; }
.lay-pos .pg { font-weight: 700; font-size: 14px; margin-top: 2px; }
.lay-pos .pnote { margin: 3px 0; font-size: 11px; overflow-wrap: anywhere; }
.lay-pos .pfoot { text-align: center; margin-top: 4px; }
