/* Pine Tree billing styles. Every colour is a variable; dark theme follows the device. */
:root {
  --brand: #6f7d17;
  --brand-ink: #ffffff;
  --accent: #f9a40f;
  --accent-ink: #3a2a24;
  --heading: #4a2e24;
  --page: #faf7f0;
  --card: #ffffff;
  --text: #3a2a24;
  --muted: #7a6a62;
  --border: #e6dfd2;
  --soft: #f3f4e3;
  --red: #c0392b;
  --input: #ffffff;
  --discount: #5b7a12;
  --shadow: 0 1px 2px rgba(74, 46, 36, .06), 0 4px 14px rgba(74, 46, 36, .05);
  --b-invoice: #6f7d17; --b-receipt: #2e7d6b; --b-credit: #b0531d;
  --st-neutral: #7a6a62; --st-warn: #b36b00; --st-good: #4f7a12; --st-bad: #c0392b; --st-info: #2b6c8f;
  --radius: 16px;
  --font-head: "Fredoka", "Trebuchet MS", system-ui, sans-serif;
  --font-body: "Nunito Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --brand: #b7c94a;
    --brand-ink: #221a14;
    --accent: #f9a40f;
    --accent-ink: #221a14;
    --heading: #f1dccb;
    --page: #1c1612;
    --card: #2a211b;
    --text: #efe4d8;
    --muted: #b8a698;
    --border: #44372e;
    --soft: #343019;
    --red: #ef7564;
    --input: #221b16;
    --discount: #b7c94a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --b-invoice: #b7c94a; --b-receipt: #6fc8b0; --b-credit: #f0a070;
    --st-neutral: #b8a698; --st-warn: #f5b850; --st-good: #b7c94a; --st-bad: #ef7564; --st-info: #7fbde0;
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--page); color: var(--text);
  font: 15px/1.45 var(--font-body); overflow-x: hidden;
}
h1, h2, h3 { font-family: var(--font-head); color: var(--heading); font-weight: 600; margin: 0; }
h2 { font-size: 1.15rem; margin-bottom: 12px; }
h3 { font-size: 1rem; margin: 16px 0 8px; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.r { text-align: right; }

.wrap { max-width: 1240px; margin: 0 auto; padding: 16px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.wrap-head { flex-wrap: wrap; }

/* ---------- header ---------- */
.page-header { display: flex; align-items: center; gap: 16px; }
.logo-ring {
  flex: 0 0 auto; width: 84px; height: 84px; border-radius: 50%; background: #fff;
  border: 2px solid var(--brand); display: grid; place-items: center; overflow: hidden;
}
.logo-img { width: 100%; height: 100%; display: block; object-fit: contain; }
.head-side { flex: 0 0 auto; display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.who { font-size: .82rem; color: var(--muted); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.who #whoName { font-weight: 700; color: var(--text); }
.link-btn { border: 0; background: none; padding: 2px 0; color: var(--brand); font: 700 .82rem var(--font-body); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.login-logo { width: min(200px, 60%); height: auto; display: block; margin: 6px 0 4px; }
.small { font-size: .8rem; }
.staff-table { font-size: .9rem; min-width: 520px; }
.staff-table th { text-align: left; font-size: .75rem; text-transform: uppercase; color: var(--muted); padding: 6px; border-bottom: 1px solid var(--border); }
.staff-table td { padding: 6px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.staff-table select { width: auto; padding: 4px 6px; }
.dialog-msg { min-height: 1.3em; font-weight: 700; margin-top: 10px; color: var(--brand); }
.dialog-msg.error { color: var(--red); }
.logo-ring.no-logo::after { content: "PT"; font: 600 26px var(--font-head); color: #6f7d17; }
.logo-ring.no-logo .logo-img { display: none; }
.head-text { flex: 1; min-width: 0; }
.tagline { color: var(--accent); font-size: .72rem; font-weight: 800; letter-spacing: .22em; text-transform: uppercase; }
.page-header h1 { font-size: 1.6rem; line-height: 1.2; }
.contact { color: var(--muted); font-size: .88rem; overflow-wrap: anywhere; }
.num-pill {
  flex: 0 0 auto; background: var(--soft); color: var(--heading); border: 1px solid var(--border);
  font: 600 1rem var(--font-head); padding: 8px 14px; border-radius: 999px; white-space: nowrap;
}

/* ---------- type switch ---------- */
.type-switch {
  display: inline-flex; margin: 14px 0 4px; padding: 4px; gap: 2px;
  background: var(--card); border: 1px solid var(--border); border-radius: 999px; max-width: 100%;
}
.type-switch button {
  border: 0; background: transparent; color: var(--text); font: 700 .95rem var(--font-body);
  padding: 8px 18px; border-radius: 999px; cursor: pointer; white-space: nowrap;
}
.type-switch button:hover { background: var(--soft); }
.type-switch button.active { background: var(--brand); color: var(--brand-ink); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  font: 700 .9rem var(--font-body); padding: 8px 14px; border-radius: 12px; cursor: pointer;
  min-height: 38px; text-decoration: none;
}
.btn:hover { border-color: var(--brand); }
.btn:focus-visible, .type-switch button:focus-visible, .handle:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.small { padding: 5px 10px; min-height: 32px; font-size: .84rem; border-radius: 10px; }
.btn.danger.armed, .btn.danger:hover { border-color: var(--red); color: var(--red); }
.btn:disabled { opacity: .6; cursor: progress; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.action-bar { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px; margin: 10px 0 6px; }
.actions-main, .actions-side { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.save-state { font-size: .85rem; color: var(--muted); font-weight: 700; padding: 0 4px; }
.save-state.dirty { color: var(--st-warn); }
.save-state.saved { color: var(--st-good); }

.status { min-height: 24px; font-size: .9rem; font-weight: 700; padding: 2px 4px; opacity: 0; transition: opacity .2s; }
.status.show { opacity: 1; }
.status.info { color: var(--brand); }
.status.warn { color: var(--st-warn); }
.status.error { color: var(--red); }

/* ---------- layout ---------- */
.layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-items: start; }
.col-main { display: grid; gap: 16px; min-width: 0; }
.col-side { min-width: 0; }
@media (min-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr) 340px; }
  .summary { position: sticky; top: 16px; }
}
.saved { margin-top: 16px; }

/* ---------- forms ---------- */
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.grid2.tight { gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field > span { font-size: .8rem; font-weight: 700; color: var(--muted); }
.internal { font-style: normal; font-weight: 600; color: var(--accent); font-size: .72rem; margin-left: 4px; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--input); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 10px; width: 100%; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: var(--brand); }
textarea { resize: vertical; }
textarea.notes { min-height: 100px; }
@media (max-width: 640px) {
  .grid2 { grid-template-columns: minmax(0, 1fr); }
  .grid2.tight { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- items table ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
table { border-collapse: collapse; width: 100%; }
.items { min-width: 560px; table-layout: fixed; }
.items col.c-handle { width: 30px; } .items col.c-qty { width: 66px; } .items col.c-price { width: 100px; }
.items col.c-amt { width: 108px; } .items col.c-del { width: 34px; }
.items th {
  font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 800;
  white-space: nowrap; vertical-align: bottom; padding: 0 6px 8px; border-bottom: 1px solid var(--border); text-align: left;
}
.items th.c-desc { padding-left: 6px; }
.items th.c-qty { text-align: center; }
.items th.c-price, .items th.c-amt { text-align: right; }
.items td { padding: 6px; vertical-align: top; border-bottom: 1px solid var(--border); }
.items tr.dragging { opacity: .75; background: var(--soft); }
.handle {
  border: 0; background: transparent; color: var(--muted); font-size: 18px; line-height: 1; padding: 8px 2px;
  cursor: grab; touch-action: none; border-radius: 6px; width: 100%;
}
.handle:active { cursor: grabbing; }
.desc-wrap { display: flex; gap: 4px; align-items: flex-start; }
textarea.desc { resize: none; overflow: hidden; min-height: 38px; line-height: 1.35; padding: 8px 10px; flex: 1; }
.picker {
  position: relative; flex: 0 0 32px; height: 38px; border: 1px solid var(--border); border-radius: 10px;
  display: grid; place-items: center; color: var(--brand); background: var(--soft); font-size: 14px;
}
.picker:hover { border-color: var(--brand); }
.picker select { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; padding: 0; }
.items input.qty { text-align: center; }
.items input.price { text-align: right; }
.items .amt { display: block; text-align: right; font-weight: 800; padding-top: 9px; white-space: nowrap; }
.items tr.is-discount .amt { color: var(--discount); }
.items tr.is-discount textarea.desc { border-color: color-mix(in srgb, var(--discount) 45%, var(--border)); }
.del {
  border: 0; background: transparent; color: var(--muted); font-size: 20px; cursor: pointer; padding: 6px 4px; border-radius: 6px;
}
.del:hover { color: var(--red); }
input[type=number] { -moz-appearance: textfield; }
.items input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 14px 0 12px; }
.chip {
  border: 1px dashed var(--brand); background: transparent; color: var(--brand); border-radius: 999px;
  padding: 4px 10px; font: 700 .8rem var(--font-body); cursor: pointer;
}
.chip:hover { background: var(--soft); }

/* ---------- summary ---------- */
.totals { margin: 16px 0 0; display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; }
.totals dt { color: var(--muted); }
.totals dd { margin: 0; text-align: right; font-weight: 700; white-space: nowrap; }
.totals .neg { color: var(--discount); }
.main-figure { margin-top: 14px; background: var(--soft); border-radius: 14px; padding: 14px; text-align: right; }
.mf-label { font-weight: 800; color: var(--heading); text-transform: uppercase; font-size: .8rem; letter-spacing: .06em; }
.mf-value { font: 600 2rem/1.15 var(--font-head); color: var(--brand); }
.mf-sub { color: var(--muted); font-size: .85rem; min-height: 1em; overflow-wrap: anywhere; }

/* ---------- saved list ---------- */
.saved-tools { display: flex; flex-wrap: wrap; gap: 6px; }
.filters { display: grid; grid-template-columns: minmax(0, 1fr) 160px 180px; gap: 8px; margin-bottom: 10px; }
@media (max-width: 640px) { .filters { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } .filters input { grid-column: 1 / -1; } }
.saved-summary { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.saved-summary span { background: var(--soft); border-radius: 999px; padding: 3px 10px; font-size: .82rem; font-weight: 700; }
.saved-table { min-width: 860px; font-size: .9rem; }
.saved-table th { text-align: left; font-size: .76rem; text-transform: uppercase; color: var(--muted); padding: 6px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.saved-table th.r { text-align: right; }
.saved-table td { padding: 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.saved-table tr.is-open td { background: var(--soft); }
.saved-table tr.is-open td:first-child { box-shadow: inset 4px 0 0 var(--brand); }
.sv-num { font-weight: 800; white-space: nowrap; }
.sv-for { font-size: .78rem; color: var(--muted); white-space: nowrap; }
.badge { display: inline-block; font-size: .68rem; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; padding: 1px 7px; border-radius: 999px; color: #fff; }
.badge.b-invoice { background: var(--b-invoice); } .badge.b-receipt { background: var(--b-receipt); } .badge.b-credit { background: var(--b-credit); }
@media (prefers-color-scheme: dark) { .badge { color: #1c1612; } }
.sv-status { width: auto; min-width: 140px; font-weight: 700; padding: 5px 8px; }
.st-neutral { color: var(--st-neutral); } .st-warn { color: var(--st-warn); } .st-good { color: var(--st-good); }
.st-bad { color: var(--st-bad); } .st-info { color: var(--st-info); }
.empty { color: var(--muted); text-align: center; padding: 18px; }

/* ---------- dialogs ---------- */
.dialog {
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); color: var(--text);
  width: min(720px, calc(100vw - 32px)); max-height: calc(100vh - 40px); padding: 20px;
}
.dialog::backdrop { background: rgba(30, 20, 15, .45); }
.dialog h2 { margin-bottom: 14px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.price-rows { display: grid; gap: 8px; margin-bottom: 10px; }
.price-row { display: grid; grid-template-columns: minmax(0, 1fr) 100px auto 34px; gap: 8px; align-items: center; }
.price-row label.tick { display: flex; align-items: center; gap: 6px; font-size: .82rem; white-space: nowrap; }
.price-row label.tick input { width: auto; }
@media (max-width: 560px) { .price-row { grid-template-columns: minmax(0, 1fr) 90px; } }
#copyText { font-family: ui-monospace, Consolas, monospace; font-size: .85rem; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); display: grid; gap: 12px; justify-items: center; text-align: center; }
.login-card .field { width: 100%; text-align: left; }
.login-card .btn { width: 100%; }
.login-msg { color: var(--red); font-weight: 700; min-height: 1.2em; }

/* ---------- phones ---------- */
@media (max-width: 640px) {
  .wrap { padding: 12px; }
  .card { padding: 14px; }
  .page-header { flex-wrap: wrap; gap: 8px 12px; }
  .page-header .logo-ring { width: 64px; height: 64px; }
  .head-text { flex: 1 1 200px; }
  .page-header h1 { font-size: 1.2rem; }
  .tagline { font-size: .66rem; letter-spacing: .16em; }
  .contact { font-size: .8rem; }
  .head-side { order: 3; flex-direction: row; justify-content: space-between; align-items: center; width: 100%; }
  .num-pill { padding: 5px 12px; font-size: .9rem; }
  .type-switch { display: flex; width: 100%; }
  .type-switch button { flex: 1; padding: 8px 6px; font-size: .88rem; }
  .actions-main .btn, .actions-side .btn { flex: 1 1 auto; }
}

/* ---------- print view (only the formatted document) ---------- */
#printArea { display: none; }
@media print {
  @page { size: A4; margin: 14mm; }
  body { background: #fff; color: #3a2a24; font-size: 10.5pt; }
  body > *:not(#printArea) { display: none !important; }
  #printArea { display: block; }
}
.pd { color: #3a2a24; font-family: var(--font-body); }
.pd-head { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; }
.pd-brand { display: flex; gap: 14px; align-items: flex-start; }
.pd-logo { width: 26mm; height: 26mm; border-radius: 50%; border: 2px solid #6f7d17; }
.pd-name { font: 600 17pt var(--font-head); color: #4a2e24; }
.pd-small { font-size: 9pt; color: #7a6a62; white-space: pre-line; }
.pd-title { font: 600 22pt var(--font-head); color: #6f7d17; text-align: right; letter-spacing: .04em; }
.pd-meta { text-align: right; font-size: 9.5pt; }
.pd-meta b { color: #4a2e24; }
.pd-rule { border: 0; border-top: 2.5px solid #6f7d17; margin: 10px 0 14px; }
.pd-parties { display: flex; gap: 30px; margin-bottom: 14px; }
.pd-parties > div { flex: 1; }
.pd-label { font-size: 8pt; font-weight: 800; color: #7a6a62; letter-spacing: .08em; text-transform: uppercase; }
.pd-table { width: 100%; border-collapse: collapse; font-size: 10pt; }
.pd-table thead { display: table-header-group; }
.pd-table th { background: #6f7d17; color: #fff; text-align: left; padding: 6px 8px; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.pd-table td { padding: 6px 8px; border-bottom: 1px solid #e6dfd2; vertical-align: top; }
.pd-table tr { break-inside: avoid; }
.pd-table .n { text-align: right; white-space: nowrap; }
.pd-table .c { text-align: center; }
.pd-table .disc { color: #5b7a12; }
.pd-totals { margin: 12px 0 0 auto; width: 280px; border-collapse: collapse; font-size: 10pt; }
.pd-totals td { padding: 3px 8px; }
.pd-totals td:last-child { text-align: right; white-space: nowrap; }
.pd-totals tr.main td { font-weight: 800; font-size: 12pt; background: #f3f4e3; border-top: 2px solid #6f7d17; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.pd-block { margin-top: 14px; break-inside: avoid; }
.pd-block p { margin: 3px 0 0; white-space: pre-line; }
.pd-foot { display: flex; justify-content: space-between; border-top: 1px solid #e6dfd2; margin-top: 24px; padding-top: 8px; font-size: 9pt; color: #7a6a62; }
