/* ============================================================
   Invoice Maker — design tokens
   Subject: computer sales & repair shop.
   Signature: flat colorful sidebar navigation — each section has
   its own solid icon color, thin borders everywhere, no gradients,
   no glow/drop shadows. Clean Notion/Linear-style flat look.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=IBM+Plex+Sans:wght@400;500;600&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

:root {
  --bg: #f7f7f5;
  --paper: #f7f7f5;
  --paper-raised: #ffffff;
  --surface: #ffffff;

  --ink: #1c1e22;
  --ink-soft: #40444c;
  --line: #e6e5e1;
  --line-strong: #d3d2cc;
  --muted: #747983;

  --accent: #1fa855;       /* flat green — primary / paid / new */
  --accent-hover: #178a45;
  --accent-soft: #e3f5ea;

  --accent2: #e0453a;      /* flat red — due / rejected */
  --accent2-hover: #c93a30;
  --accent2-soft: #fbe6e4;

  --info: #3b7cf6;         /* flat blue — service / dashboard */
  --info-soft: #e8f0fe;

  --danger: var(--accent2);
  --danger-soft: var(--accent2-soft);

  --warning: #c9740a;
  --warning-soft: #fbecd6;

  /* per-section nav palette */
  --c-dash:  #3b7cf6;
  --c-new:   #1fa855;
  --c-item:  #e8930b;
  --c-stock: #0f9e94;
  --c-sup:   #8358e6;
  --c-cust:  #e3418e;
  --c-claim: #e0453a;
  --c-due:   #ea7b1c;
  --c-rep:   #5257d6;
  --c-exp:   #a0522d;
  --c-return: #c2410c;
  --c-exchange: #7c3aed;
  --c-set:   #6b7180;

  --radius: 8px;
  --radius-sm: 6px;
  --radius-lg: 12px;

  --shadow-xs: none;
  --shadow-sm: 0 1px 2px rgba(28, 30, 34, 0.06);
  --shadow: 0 2px 8px rgba(28, 30, 34, 0.08);
  --shadow-lg: 0 12px 28px rgba(28, 30, 34, 0.16);

  --font-display: "Space Grotesk", sans-serif;
  --font-body: "IBM Plex Sans", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  width: 100%;
}

img, svg { max-width: 100%; height: auto; }

body {
  min-height: 100vh;
  background-color: var(--bg);
}

a { color: inherit; text-decoration: none; }

h1, h2, h3 {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: -0.015em;
  margin: 0 0 4px 0;
}

.mono { font-family: var(--font-mono); }

::selection { background: var(--accent-soft); color: var(--accent-hover); }

a:focus-visible, button:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------- App shell: flat sidebar + main column ---------- */

body { min-height: 100vh; }

.shell {
  max-width: 1080px;
  margin-left: 220px;
  margin-right: auto;
  padding-top: 28px;
  padding-left: 28px;
  padding-right: 28px;
  padding-bottom: 64px;
}

#footer-mount { margin-left: 220px; }

/* ---------- Sidebar ---------- */

.sidebar {
  width: 220px;
  height: 100vh;
  position: fixed;
  top: 0;
  left: 0;
  z-index: 30;
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 18px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
}

.brand-row { display: flex; align-items: center; gap: 9px; padding: 6px 8px 16px; min-width: 0; }
.brand-row.brand {
  color: inherit;
}
.brand-mark {
  width: 26px; height: 26px; border-radius: 6px;
  background: var(--ink); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 700; font-size: 11px;
  flex: none;
  overflow: hidden;
}
.brand-mark img { width: 100%; height: 100%; object-fit: contain; }
.brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* kept for JS compat (previous topbar fallback logo) */
.brand-logo-fallback {
  width: 26px; height: 26px; border-radius: 6px;
  background: var(--ink); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display); font-weight: 700; font-size: 11px;
  flex: none;
}

.sidebar-divider { height: 1px; background: var(--line); margin: 10px 8px; }

.nav-list { display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  --c: #999;
  display: flex; align-items: center; gap: 11px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--ink);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  transition: background .12s ease;
}
.nav-icon {
  width: 24px; height: 24px; border-radius: 6px;
  background: var(--c);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.nav-icon svg { width: 13px; height: 13px; stroke: #fff; fill: none; stroke-width: 2.3; }
.nav-item:hover { background: #f1f1ee; }
.nav-item.active { background: color-mix(in srgb, var(--c) 12%, white); font-weight: 600; }

.nav-subitem {
  --c: #999;
  display: flex; align-items: center; gap: 10px;
  padding: 6px 10px 6px 11px;
  margin-left: 22px;
  border-radius: var(--radius-sm);
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: background .12s ease;
}
.nav-subitem-icon {
  width: 19px; height: 19px; border-radius: 5px;
  background: var(--c);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.nav-subitem-icon svg { width: 11px; height: 11px; stroke: #fff; fill: none; stroke-width: 2.4; }
.nav-subitem:hover { background: #f1f1ee; }
.nav-subitem.active { background: color-mix(in srgb, var(--c) 12%, white); font-weight: 600; color: var(--ink); }

/* ---------- Mobile topbar + off-canvas sidebar drawer ---------- */

.mobile-topbar {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.mobile-menu-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  flex: none;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--paper-raised);
  color: var(--ink);
  cursor: pointer;
}
.mobile-menu-btn svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2.2; }
.mobile-brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.mobile-brand .brand-name { font-size: 15px; }

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(18, 21, 27, 0.4);
  z-index: 40;
}
.sidebar-backdrop.show { display: block; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--paper-raised);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease;
}
.btn:hover { border-color: var(--line-strong); background: #fbfbfa; }
.btn:active { background: var(--line); }

.btn-primary {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}
.btn-primary:hover { background: var(--ink-soft); border-color: var(--ink-soft); }

.btn-accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-accent:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-danger {
  background: var(--danger-soft);
  border-color: var(--danger-soft);
  color: var(--danger);
}
.btn-danger:hover { background: #f5cfca; border-color: #f5cfca; }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}
.btn-ghost:hover { background: var(--line); color: var(--ink); }

.btn-sm { padding: 6px 10px; font-size: 13px; }

/* Compact square icon buttons for table row actions (View/Edit/Share/
   Return/Exchange/Delete) — keeps a full action set on one line even
   with several actions per row, instead of stacked/wrapped text
   buttons that push the row width past what fits on screen. Each
   action gets a soft tinted background + matching icon color instead
   of a solid fill, so a row of six stays calm and readable. */
.action-btn {
  width: 32px;
  height: 32px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--muted);
}
.action-btn svg { width: 16px; height: 16px; display: block; }
.action-btn:hover { border-color: transparent; }
.action-btn:active { transform: scale(0.96); }

.action-btn-view, .action-btn-share { background: var(--info-soft); color: var(--info); }
.action-btn-view:hover, .action-btn-share:hover { background: #d7e6fd; }

.action-btn-edit { background: var(--warning-soft); color: var(--warning); }
.action-btn-edit:hover { background: #f6ddb2; }

.action-btn-return, .action-btn-exchange { background: var(--accent-soft); color: var(--accent); }
.action-btn-return:hover, .action-btn-exchange:hover { background: #cdeedb; }

.action-btn-delete { background: var(--danger-soft); color: var(--danger); }
.action-btn-delete:hover { background: #f5cfca; }

.action-btn-adjust { background: color-mix(in srgb, var(--c-stock) 16%, white); color: var(--c-stock); }
.action-btn-adjust:hover { background: color-mix(in srgb, var(--c-stock) 28%, white); }

.action-btn-print { background: var(--line); color: var(--ink-soft); }
.action-btn-print:hover { background: var(--line-strong); }

.action-btn-sms { background: color-mix(in srgb, var(--c-cust) 16%, white); color: var(--c-cust); }
.action-btn-sms:hover { background: color-mix(in srgb, var(--c-cust) 28%, white); }

.action-btn-pdf { background: var(--ink); color: #fff; }
.action-btn-pdf:hover { background: var(--ink-soft); }

/* Slightly larger variant for the invoice-view toolbar, where these
   are the only actions on the page (row actions elsewhere stay 32px
   to keep tables compact). */
.action-btn-lg { width: 40px; height: 40px; }
.action-btn-lg svg { width: 18px; height: 18px; }

.phone-row { display: flex; gap: 8px; margin-bottom: 8px; }
.phone-row input { flex: 1; }
.phone-row .remove-phone-btn { flex: none; padding: 6px 10px; }

.bank-account-block { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 14px 14px 4px; margin-bottom: 12px; }
.bank-account-block .remove-bank-btn { margin-bottom: 14px; }

/* Bank details shown in the supplier table */
.bank-line { display: inline-flex; align-items: center; gap: 5px; }
.copy-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 19px;
  height: 19px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
}
.copy-icon-btn:hover { background: var(--accent-soft); color: var(--accent-hover); border-color: var(--accent-soft); }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Cards / sections ---------- */

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin: 0 0 22px;
  flex-wrap: wrap;
}

.page-head h1 { font-size: 24px; }
.page-head p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.card {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px 20px;
  margin-bottom: 18px;
}

.card-title {
  font-family: var(--font-display);
  font-size: 14.5px;
  font-weight: 700;
  margin: 0 0 14px;
  display: flex;
  align-items: center;
  gap: 9px;
}
.card-title::before {
  content: "";
  width: 22px; height: 22px;
  border-radius: 6px;
  background: var(--accent);
  flex: none;
}

.card-title .step-dot {
  width: 23px; height: 23px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 12px;
  display: flex; align-items: center; justify-content: center;
  flex: none;
}
/* when a step-dot number is already present, skip the duplicate square */
.card-title:has(.step-dot)::before { display: none; }

/* ---------- Profit/Loss formula breakdown ---------- */

.pl-formula { display: flex; flex-direction: column; gap: 2px; }
.pl-formula-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 2px;
  font-size: 13.5px;
  border-bottom: 1px solid var(--line);
}
.pl-formula-row:last-child { border-bottom: none; }
.pl-formula-row.muted { color: var(--muted); }
.pl-formula-row .mono { font-weight: 600; }
.pl-formula-total { font-weight: 700; border-top: 1px dashed var(--line-strong); margin-top: 2px; padding-top: 10px; }
.pl-formula-total .mono { font-size: 15px; }
#pl-f-net-row.negative .mono { color: var(--accent2); }
#pl-f-net-row:not(.negative) .mono { color: var(--accent-hover); }

.cost-unknown-tag {
  display: inline-block;
  margin-left: 6px;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--muted);
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  padding: 1px 5px;
  vertical-align: middle;
}

/* ---------- Notice / callout banner ---------- */

.notice {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: var(--info-soft);
  border: 1px solid color-mix(in srgb, var(--info) 30%, white);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 18px;
  font-size: 13px;
  color: var(--ink-soft);
}
.notice .notice-icon { flex: none; color: var(--info); font-size: 16px; line-height: 1.3; }
.notice strong { color: var(--ink); }
.notice a { color: var(--info); font-weight: 600; text-decoration: underline; }

.notice.warn {
  background: color-mix(in srgb, var(--c-item) 12%, white);
  border-color: color-mix(in srgb, var(--c-item) 30%, white);
}
.notice.warn .notice-icon { color: var(--c-item); }
.notice.warn a { color: var(--c-item); }

/* ---------- Stats ---------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}

.stat {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.stat::before {
  content: "";
  width: 24px; height: 24px;
  border-radius: 6px;
  background: var(--info);
  display: block;
}
.stat.ok::before { background: var(--accent); }
.stat.due::before { background: var(--accent2); }
.stat.warn::before { background: var(--c-item); }

.stat .label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}

.stat .value {
  font-family: var(--font-mono);
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.stat.ok .value { color: var(--accent-hover); }
.stat.due .value { color: var(--accent2); }
.stat.warn .value { color: var(--c-item); }

/* ---------- Forms ---------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.field label {
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-soft);
}

.field .hint { font-size: 12px; color: var(--muted); }

/* ---------- Autocomplete dropdown (saved Items / Customers) ---------- */

.autocomplete-wrap { position: relative; }

.autocomplete-list {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 30;
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  max-height: 220px;
  overflow-y: auto;
}
.autocomplete-list.open { display: block; }

.autocomplete-item {
  padding: 9px 12px;
  font-size: 13.5px;
  cursor: pointer;
  border-bottom: 1px solid var(--line);
}
.autocomplete-item:last-child { border-bottom: none; }
.autocomplete-item:hover { background: var(--accent-soft); }

/* ---------- Customer picker (Purchase History search) ---------- */

.customer-pick-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.customer-pick-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  cursor: pointer;
  font: inherit;
  text-align: left;
  transition: background .12s ease, border-color .12s ease;
}
.customer-pick-card:hover { background: var(--accent-soft); border-color: var(--accent); }
.customer-pick-card .name { font-weight: 600; }
.customer-pick-card .phone { color: var(--muted); font-size: 13px; }

/* ---------- Warranty Claims: search results + context ---------- */

.claim-item-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 10px;
}

.claim-item-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
}
.claim-item-card .name { font-weight: 600; font-size: 14.5px; }
.claim-item-card .meta { color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.claim-item-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.claim-context {
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 18px;
  font-size: 13.5px;
}
.claim-context p { margin: 0 0 4px; }
.claim-context p:last-child { margin-bottom: 0; }

.row {
  display: grid;
  gap: 14px;
}
.row.cols-2 { grid-template-columns: 1fr 1fr; }
.row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.row.cols-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }

/* ---------- Item form: one continuous field grid ---------- */
.field-grid {
  grid-template-columns: repeat(3, 1fr);
}
@media (max-width: 880px) {
  .field-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 480px) {
  .field-grid #item-serial-field { grid-column: 1 / -1; }
}

input, select, textarea {
  font-family: var(--font-body);
  font-size: 14px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  width: 100%;
  transition: border-color .12s ease, box-shadow .12s ease, background .12s ease;
}

input.mono, .amount-input input { font-family: var(--font-mono); }

input:hover, select:hover, textarea:hover { border-color: var(--line-strong); }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px var(--accent-soft);
}

textarea { resize: vertical; min-height: 70px; }

.logo-upload {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo-preview {
  width: 64px; height: 64px;
  border-radius: var(--radius-sm);
  border: 1px dashed var(--line-strong);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden;
  background: var(--paper);
  flex: none;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}
.logo-preview img { width: 100%; height: 100%; object-fit: contain; }

/* ---------- Tabs (Sale / Service) ---------- */

.type-tabs {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 4px;
  background: var(--paper-raised);
  margin-bottom: 22px;
}

.type-tabs button {
  border: none;
  background: transparent;
  padding: 9px 20px;
  border-radius: 6px;
  font-family: var(--font-body);
  font-weight: 500;
  font-size: 14px;
  color: var(--muted);
  cursor: pointer;
  transition: background .12s ease, color .12s ease;
}
.type-tabs button:hover:not(.active) { background: var(--paper); color: var(--ink-soft); }

.type-tabs button.active {
  background: var(--accent);
  color: #fff;
}

/* ---------- Line item table ---------- */

.line-items { border: 1px solid var(--line); border-radius: var(--radius); overflow: visible; }

.line-item-row {
  display: grid;
  gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--paper-raised);
  position: relative;
  transition: background .12s ease;
}
.line-item-row:last-child { border-bottom: none; }
.line-item-row:first-child { border-top-left-radius: var(--radius); border-top-right-radius: var(--radius); }
.line-item-row:last-child { border-bottom-left-radius: var(--radius); border-bottom-right-radius: var(--radius); }
.line-item-row:nth-child(even) { background: #fafaf8; }
.line-item-row:focus-within { background: var(--accent-soft); }

.line-item-row .grid {
  display: grid;
  gap: 10px;
  grid-template-columns: 1.6fr 1fr 1fr 0.7fr 1fr;
}
.line-item-row .grid.grid-3 {
  grid-template-columns: 2fr 1fr 1fr;
}
.line-item-row .grid.grid-4 {
  grid-template-columns: 1.8fr 1.2fr 0.7fr 1fr;
}

.line-item-row .warranty-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 1fr 1fr;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--line-strong);
}

.field-mini { display: flex; flex-direction: column; gap: 4px; }
.field-mini label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 500; }
.field-mini .hint { font-size: 12px; color: var(--muted); margin: 2px 0 0; }

.remove-row {
  position: absolute;
  top: 12px;
  right: 14px;
  background: var(--danger-soft);
  color: var(--danger);
  border: none;
  border-radius: 7px;
  width: 25px; height: 25px;
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  transition: background .12s ease;
}
.remove-row:hover { background: #f5cfca; }

.line-items-footer {
  padding: 12px 16px;
  background: var(--paper);
}

/* ---------- Serial box (multi-serial add + scan) ---------- */

.serial-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.serial-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.serial-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.serial-row input {
  flex: 1;
  min-width: 0;
}

.btn-icon {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--paper-raised);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease;
}
.btn-icon:hover { border-color: var(--line-strong); background: #fbfbfa; }

.btn-icon-danger { color: var(--danger); }
.btn-icon-danger:hover { background: var(--danger-soft); border-color: var(--danger-soft); }

.serial-add-more { align-self: flex-start; }

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--ink-soft);
  cursor: pointer;
  align-self: center;
}
.checkbox-field input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

/* ---------- Invoice Template settings (theme swatches + preview) ---------- */

/* ---------- Invoice Template settings (layout cards, theme swatches, preview) ---------- */

.layout-card-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.layout-card {
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px;
  cursor: pointer;
  text-align: left;
  background: var(--paper-raised);
  transition: border-color .12s ease;
}
.layout-card:hover { border-color: var(--line-strong); }
.layout-card.active { border-color: var(--accent); background: var(--accent-soft); }
.layout-card .layout-card-thumb {
  height: 46px;
  border-radius: 4px;
  margin-bottom: 8px;
  border: 1px solid var(--line);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: #fff;
}
.layout-card .layout-card-name { font-size: 13px; font-weight: 600; color: var(--ink); }
.layout-card .layout-card-blurb { font-size: 11px; color: var(--muted); margin-top: 2px; line-height: 1.4; }

.theme-swatch-row { display: flex; flex-wrap: wrap; gap: 10px; }
.theme-swatch {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 0 1px var(--line) inset;
  transition: transform .12s ease;
}
.theme-swatch:hover { transform: scale(1.08); }
.theme-swatch.active { border-color: var(--ink); }
.theme-swatch svg { width: 14px; height: 14px; stroke: #fff; opacity: 0; }
.theme-swatch.active svg { opacity: 1; }

.template-preview-wrap {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
  padding: 14px;
  overflow: hidden;
}
.template-preview-scale {
  width: 760px;
  transform: scale(0.42);
  transform-origin: top left;
}
.template-preview-scale .ticket { margin: 0; }

.status-badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 5px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.status-badge.in-stock { background: var(--accent-soft); color: var(--accent-hover); }
.status-badge.sold { background: var(--line); color: var(--muted); }
.status-badge.low-stock { background: color-mix(in srgb, var(--c-item) 18%, white); color: var(--c-item); }
.status-badge.adjusted { background: var(--warning-soft); color: var(--warning); }
.status-badge.adj-add { background: var(--accent-soft); color: var(--accent-hover); }
.status-badge.adj-remove { background: var(--danger-soft); color: var(--danger); }
.low-stock-amount { color: var(--c-item); font-weight: 600; }
tr.item-sold-row { opacity: .65; }

/* ---------- Camera scanner modal ---------- */

.scanner-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(18, 21, 27, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.scanner-modal-box {
  width: 100%;
  max-width: 420px;
  background: var(--paper-raised);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.scanner-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--font-display);
  font-weight: 600;
}

.scanner-modal-head .btn-icon {
  width: 30px;
  height: 30px;
  font-size: 13px;
}

#scanner-viewport {
  width: 100%;
  min-height: 260px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: #000;
}

#scanner-status {
  margin: 0;
  text-align: center;
}

/* ---------- Totals block ---------- */

.totals {
  margin-left: auto;
  width: 100%;
  max-width: 300px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px 18px 0;
  display: flex;
  flex-direction: column;
  gap: 9px;
  overflow: hidden;
}

.totals .line {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  color: var(--ink-soft);
}

.totals .line span:last-child { font-family: var(--font-mono); }

.totals .line.grand {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 700;
  color: var(--ink);
  background: var(--accent-soft);
  border-top: 2px solid var(--accent);
  padding: 11px 18px 12px;
  margin: 5px -18px 0;
}
.totals .line.grand span:last-child { font-family: var(--font-mono); color: var(--accent-hover); }

.totals .line.due {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--accent2);
}

/* ---------- Payment History card (View page, not part of the ticket) ---------- */

.payment-summary {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 320px;
  margin-bottom: 18px;
  padding: 14px 18px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.payment-summary .line {
  display: flex;
  justify-content: space-between;
  font-size: 13.5px;
  color: var(--ink-soft);
}
.payment-summary .line span:last-child { font-family: var(--font-mono); }
.payment-summary .line.due { color: var(--accent2); font-weight: 700; }

#payment-form { margin-top: 18px; }

/* ---------- Reports: monthly trend bar chart ---------- */

.bar-chart {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
  height: 200px;
  padding: 10px 6px 0;
}

.bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  gap: 6px;
}

.bar-value {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--ink-soft);
  white-space: nowrap;
}

.bar {
  width: 100%;
  max-width: 46px;
  background: var(--accent);
  border-radius: 6px 6px 0 0;
  transition: height .3s ease;
  min-height: 2px;
}

.bar-label {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

/* ---------- Invoice list table ---------- */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

table.list {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

table.list th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  padding: 12px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}

table.list td {
  padding: 13px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  white-space: normal;
}

table.list td.mono,
table.list td .mono {
  white-space: nowrap;
}

table.list tr:last-child td { border-bottom: none; }
table.list tr { transition: background .1s ease; }
table.list tr:hover td { background: var(--accent-soft); }

.table-actions {
  display: flex;
  flex-wrap: nowrap;
  justify-content: flex-end;
  gap: 6px;
  margin-left: auto;
}

.cell-stack { display: flex; flex-direction: column; gap: 2px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 5px;
  font-size: 11.5px;
  font-weight: 600;
}
.badge.sale { background: var(--accent-soft); color: var(--accent-hover); }
.badge.service { background: var(--info-soft); color: var(--info); }
.badge.paid { background: var(--accent-soft); color: var(--accent-hover); }
.badge.due { background: var(--accent2-soft); color: var(--accent2); }
.badge.pending { background: var(--info-soft); color: var(--info); }
.badge.repaired, .badge.replaced { background: var(--accent-soft); color: var(--accent-hover); }
.badge.rejected { background: var(--accent2-soft); color: var(--accent2); }
.badge.expired { background: var(--accent2-soft); color: var(--accent2); }
.badge.active { background: var(--accent-soft); color: var(--accent-hover); }
.due-amount { color: var(--accent2); font-weight: 600; }
.credit-amount { color: var(--accent-hover); font-weight: 600; }

.empty-state {
  text-align: center;
  padding: 56px 20px;
  color: var(--muted);
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--paper);
}
.empty-state .glyph {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--line-strong);
  margin-bottom: 10px;
  letter-spacing: .3em;
}

/* ---------- Tear-line signature element ---------- */

.tear-line {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 22px 0;
  color: var(--line-strong);
}
.tear-line::before, .tear-line::after {
  content: "";
  flex: 1;
  border-top: 2px dashed var(--line-strong);
}
.tear-line .notch {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--paper);
  border: 2px solid var(--line-strong);
  flex: none;
}

/* ---------- App footer (not part of the invoice ticket) ---------- */

.app-footer {
  text-align: center;
  padding: 18px 20px 24px;
  font-size: 12.5px;
  color: var(--muted);
  border-top: 1px solid var(--line);
  margin-top: 12px;
}
.app-footer a {
  color: var(--accent-hover);
  font-weight: 600;
  text-decoration: none;
}
.app-footer a:hover { text-decoration: underline; }

/* ---------- Invoice / ticket view ---------- */

.ticket {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 34px 36px;
  position: relative;
  overflow: hidden;
}
.ticket::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: var(--accent);
}
.ticket.pdf-export::before { display: none; }

.ticket-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 20px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.ticket-head .biz { display: flex; gap: 13px; align-items: center; }
.ticket-head .biz img { width: 48px; height: 48px; border-radius: var(--radius-sm); object-fit: contain; border: 1px solid var(--line); }
.ticket-head .biz-name { font-family: var(--font-display); font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.ticket-head .biz-meta { font-size: 12.5px; color: var(--muted); line-height: 1.6; margin-top: 2px; }

.ticket-head .doc-type {
  text-align: right;
}
.ticket-head .doc-type .kind {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--accent-hover);
  background: var(--accent-soft);
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 5px;
}
.ticket-head .doc-type .num {
  font-family: var(--font-mono);
  font-size: 21px;
  font-weight: 600;
  margin-top: 7px;
}
.ticket-head .doc-type .date { font-size: 12.5px; color: var(--muted); margin-top: 4px; }

.ticket-parties {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-top: 6px;
}
.ticket-parties .block-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  font-weight: 500;
  margin-bottom: 6px;
}
.ticket-parties .name { font-weight: 600; }
.ticket-parties .meta { font-size: 13px; color: var(--ink-soft); line-height: 1.6; }

.ticket table.items {
  width: 100%;
  border-collapse: collapse;
  margin-top: 6px;
  font-size: 13.5px;
  table-layout: fixed;
}
.ticket table.items th:nth-child(1), .ticket table.items td:nth-child(1) { width: 46%; }
.ticket table.items th:nth-child(2), .ticket table.items td:nth-child(2) { width: 15%; }
.ticket table.items th:nth-child(3), .ticket table.items td:nth-child(3) { width: 19%; }
.ticket table.items th:nth-child(4), .ticket table.items td:nth-child(4) { width: 20%; }
.ticket table.items th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  padding: 9px 10px;
  border-bottom: 1.5px solid var(--line-strong);
}
.ticket table.items td {
  padding: 11px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  overflow-wrap: break-word;
}
.ticket table.items td.num, .ticket table.items th.num { text-align: right; font-family: var(--font-mono); letter-spacing: 0; }
.ticket table.items .item-name { font-weight: 600; display: flex; align-items: center; gap: 5px; }
.ticket table.items .item-serial { font-weight: 600; color: var(--muted); font-size: 0.92em; flex: none; }
.ticket table.items .item-dot { width: 7px; height: 7px; border-radius: 50%; flex: none; background: #378ADD; }
.ticket table.items tbody tr:nth-child(even) { background: #EDF9F1; }
.ticket table.items tbody tr:nth-child(even) .item-dot { background: #1fa855; }
.ticket table.items .item-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.ticket table.items .warranty-tag {
  display: inline-block;
  margin-top: 4px;
  font-size: 11px;
  font-weight: 500;
  padding: 2px 9px;
  border-radius: 5px;
  background: var(--accent-soft);
  color: var(--accent-hover);
}

.ticket .service-block { font-size: 13.5px; }
.ticket .service-block .problem { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px; margin: 6px 0 16px; }

.ticket .terms {
  font-size: 12px;
  color: var(--muted);
  white-space: pre-wrap;
  line-height: 1.7;
}

.sign-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 40px;
  margin-top: 48px;
}
.sign-box { border-top: 1px solid var(--ink); padding-top: 8px; font-size: 12.5px; color: var(--muted); text-align: center; }

.ticket-actions { display: flex; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }

.invoice-footer {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
  text-align: center;
  font-size: 13px;
  font-style: italic;
  color: var(--muted);
  white-space: pre-line;
}

.due-strip {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--accent2-soft);
  border: 1.5px dashed var(--accent2);
  color: var(--accent2);
  padding: 11px 18px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-top: 16px;
}
.due-strip.paid { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-hover); }
.due-strip.rejected { background: var(--accent2-soft); border-color: var(--accent2); color: var(--accent2-hover); }
.due-strip .amount { font-size: 15px; }

/* ---------- Invoice ticket v2 (matches the shop's own demo template:
   name+address / logo box header, centered title, billed-to + info
   box, product table, in-words + totals box, numbered terms,
   receiver/authorized signatures) ---------- */

.ticket:has(.inv-header)::before { display: none; }

.inv-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
  margin-top: 4px;
}
.inv-header-left { flex: 1; min-width: 200px; }
.inv-biz-name {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.01em;
  text-transform: uppercase;
}
.inv-biz-address {
  font-size: 13px;
  color: var(--muted);
  margin-top: 6px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
  max-width: 360px;
}
.inv-biz-contact-line {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-top: 5px;
}
.inv-biz-contact-line:first-child { margin-top: 0; }
.inv-biz-contact-icon {
  width: 20px;
  height: 20px;
  flex: none;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.inv-biz-contact-icon svg { width: 12px; height: 12px; display: block; }
.inv-biz-contact-icon-location { background: var(--info-soft); color: var(--info); }
.inv-biz-contact-icon-phone { background: var(--accent-soft); color: var(--accent); }
.inv-biz-contact-icon-mail { background: var(--warning-soft); color: var(--warning); }
.inv-logo-box {
  width: 100px;
  height: 100px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
  padding: 5px;
  background: var(--paper);
}
.inv-logo-box img { max-width: 100%; max-height: 100%; object-fit: contain; }
.inv-logo-placeholder { font-style: italic; color: var(--muted); font-size: 13px; }

/* Save PDF / Share renders the ticket off-screen (see
   ICMTicket.renderOffscreen) and snapshots it with html2canvas —
   that path never goes through @media print, so the print-only
   header sizing below wouldn't reach the actual downloaded/shared
   PDF. Pin the same logo/business-name/address sizing here,
   scoped to .pdf-export, so the exported file matches. */
.ticket.pdf-export .inv-logo-box { width: 100px; height: 100px; }
.ticket.pdf-export .inv-biz-name { font-size: 23px; }
.ticket.pdf-export .inv-biz-address { font-size: 13px; }

.inv-title-wrap { text-align: center; margin: 26px 0 24px; }
.inv-title {
  display: inline-block;
  font-family: var(--font-display);
  font-size: 21px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  padding-bottom: 8px;
  border-bottom: 3px solid var(--accent);
}

.inv-parties {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 12px;
  align-items: stretch;
}
.inv-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 3px;
}
.inv-billed {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--paper);
  padding: 6px 10px;
  width: fit-content;
  min-width: 190px;
  max-width: 100%;
}

.inv-meta-box {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--paper);
  padding: 6px 10px;
  width: fit-content;
  min-width: 190px;
  max-width: 100%;
  margin-left: auto;
}
.inv-meta-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 3px 0;
  border-bottom: 1px solid var(--line);
}
.inv-meta-row:last-child { border-bottom: none; }
.inv-meta-label {
  font-size: 9px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  font-weight: 600;
}
.inv-meta-val { font-size: 10.5px; font-weight: 600; text-align: right; }

/* Billed To's label+icon variant — same row as the plain meta rows,
   just with a small colored icon badge (profile/phone/location)
   before the label text. */
.inv-meta-label-icon { display: inline-flex; align-items: center; gap: 4px; }
.inv-meta-icon {
  width: 13px;
  height: 13px;
  flex: none;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.inv-meta-icon svg { width: 8px; height: 8px; display: block; }
.inv-meta-icon-profile { background: color-mix(in srgb, var(--c-cust) 15%, white); color: var(--c-cust); }
.inv-meta-icon-phone { background: var(--accent-soft); color: var(--accent); }
.inv-meta-icon-location { background: var(--info-soft); color: var(--info); }
.inv-meta-icon-invoice { background: color-mix(in srgb, var(--c-rep) 15%, white); color: var(--c-rep); }
.inv-meta-icon-calendar { background: var(--warning-soft); color: var(--warning); }
.inv-meta-icon-payment { background: color-mix(in srgb, var(--c-sup) 15%, white); color: var(--c-sup); }

/* Billed To rows: line up Name/Phone/Address values in a clean
   column instead of right-aligning them — right-alignment made each
   value start at a different x depending on its own text length
   (short name vs. long address), which looked scattered. */
.inv-billed .inv-meta-row { justify-content: flex-start; }
.inv-billed .inv-meta-label-icon { width: 58px; flex: none; }
.inv-billed .inv-meta-val { text-align: left; }

/* Invoice No. / Date / Payment Method box: same idea — a fixed label
   column so every value lines up at the same x instead of each one
   right-aligning to a different starting point. "Payment Method" is
   the longest label and may wrap to two lines, which is fine. */
.inv-meta-box .inv-meta-row { justify-content: flex-start; }
.inv-meta-box .inv-meta-label { width: 56px; flex: none; }
.inv-meta-box .inv-meta-val { text-align: left; }

.inv-items-wrap { margin-top: 16px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.inv-items-wrap table.items { min-width: 460px; }

.inv-bottom-row {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 24px;
  align-items: start;
  margin-top: 22px;
}
.inv-words-text {
  font-size: 13px;
  color: var(--ink-soft);
  line-height: 1.6;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.inv-totals-box {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--paper);
  padding: 6px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: fit-content;
  min-width: 190px;
  max-width: 100%;
  margin-left: auto;
}
.inv-totals-line { display: flex; justify-content: space-between; font-size: 10.5px; color: var(--ink-soft); }
.inv-totals-line span:last-child { font-family: var(--font-mono); }
.inv-totals-line.muted { font-size: 9.5px; color: var(--muted); }
.inv-totals-line.total {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  color: var(--ink);
  border-bottom: 2px solid var(--accent);
  padding-bottom: 5px;
  margin-top: 1px;
}
.inv-totals-line.total span:last-child { color: var(--accent-hover); }
.inv-totals-line.due { color: var(--accent2); font-weight: 600; }

.inv-terms-block { margin-top: 26px; }
.inv-terms-title { font-family: var(--font-display); font-weight: 700; font-size: 14px; margin-bottom: 10px; }
.inv-terms-list { margin: 0; padding: 0; list-style: none; counter-reset: inv-term; }
.inv-terms-list li {
  counter-increment: inv-term;
  display: flex;
  gap: 8px;
  font-size: 12.5px;
  color: var(--ink-soft);
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
}
.inv-terms-list li:last-child { border-bottom: none; }
.inv-terms-list li::before { content: counter(inv-term) "."; color: var(--muted); flex: none; }

/* ---------- Invoice Template layouts (Settings → Invoice Template) ----------
   Same underlying .inv-* markup as above (so density scaling, the
   single-page PDF fit, and print rules all keep working); each layout
   below is purely a CSS skin over it. .layout-classic needs no rules —
   it's the look already defined above. */

/* Modern — colored header card, tinted totals & table header. */
.ticket.layout-modern .inv-header {
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 18px 20px;
  margin: 0 0 18px;
}
.ticket.layout-modern .inv-biz-address { border-bottom-color: rgba(255,255,255,.32); }
.ticket.layout-modern .inv-biz-contact-icon { background: rgba(255,255,255,.18) !important; color: #fff !important; }
.ticket.layout-modern .inv-logo-box { background: #fff; border-color: transparent; }
.ticket.layout-modern .inv-title-wrap { margin-top: 4px; }
.ticket.layout-modern .inv-title {
  border-bottom: none;
  background: var(--accent-soft);
  color: var(--accent-hover);
  padding: 8px 22px;
  border-radius: 999px;
}
.ticket.layout-modern .inv-billed,
.ticket.layout-modern .inv-meta-box {
  border: none;
  background: var(--paper);
  border-top: 3px solid var(--accent);
  border-radius: 4px;
}
.ticket.layout-modern table.items th {
  background: var(--accent-soft);
  color: var(--accent-hover);
  border-bottom: none;
}
.ticket.layout-modern table.items tbody tr:nth-child(even) { background: var(--accent-soft); }
.ticket.layout-modern table.items .item-dot { background: var(--accent); }
.ticket.layout-modern .inv-totals-box {
  border: none;
  background: var(--accent-soft);
  border-left: 4px solid var(--accent);
}
.ticket.layout-modern .inv-totals-line.total { border-bottom-color: var(--accent); }

/* Minimal — no boxes, no shading; thin rules only, ink-friendly. */
.ticket.layout-minimal .inv-logo-box { background: transparent; border: none; }
.ticket.layout-minimal .inv-title {
  border-bottom: none;
  font-size: 13px;
  letter-spacing: .18em;
  color: var(--muted);
  font-weight: 600;
}
.ticket.layout-minimal .inv-billed,
.ticket.layout-minimal .inv-meta-box {
  border: none;
  background: transparent;
  padding: 0;
}
.ticket.layout-minimal table.items th {
  background: transparent;
  border-bottom: 1px solid var(--ink);
}
.ticket.layout-minimal table.items tbody tr:nth-child(even) { background: transparent; }
.ticket.layout-minimal table.items .item-dot { display: none; }
.ticket.layout-minimal .inv-totals-box {
  border: none;
  background: transparent;
  padding: 0;
  gap: 6px;
}
.ticket.layout-minimal .inv-totals-line.total {
  border-bottom: none;
  border-top: 2px solid var(--ink);
  padding-top: 6px;
}
.ticket.layout-minimal .inv-totals-line.total span:last-child { color: var(--ink); }
.ticket.layout-minimal .warranty-tag { background: transparent; color: var(--ink-soft); border: 1px solid var(--line); }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: var(--ink);
  color: var(--paper);
  padding: 11px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 100;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); pointer-events: auto; }

/* ---------- Utility ---------- */

.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.muted { color: var(--muted); }
.mt-0 { margin-top: 0; }
.text-right { text-align: right; }
.small { font-size: 12.5px; }

/* ---------- Responsive: switch sidebar to off-canvas drawer ---------- */

@media (max-width: 880px) {
  body { display: block; }
  #topbar-mount { display: contents; }

  .sidebar {
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    width: 240px;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }

  .mobile-topbar { display: flex; }

  .shell {
    max-width: none;
    margin-left: 0;
    padding: 20px 18px 48px;
  }

  #footer-mount { margin-left: 0; }

  .row.cols-3, .row.cols-4 { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 720px) {
  .row.cols-2, .row.cols-3, .row.cols-4 { grid-template-columns: 1fr; }
  .line-item-row .grid { grid-template-columns: 1fr 1fr; }
  .line-item-row .grid.grid-3 { grid-template-columns: 1fr 1fr; }
  .line-item-row .grid.grid-4 { grid-template-columns: 1fr 1fr; }
  .line-item-row .warranty-grid { grid-template-columns: 1fr 1fr; }
  .ticket-parties { grid-template-columns: 1fr; }
  .sign-row { grid-template-columns: 1fr; gap: 26px; }

  .inv-header { flex-direction: column; align-items: flex-start; }
  .inv-parties, .inv-bottom-row { grid-template-columns: 1fr; }
  .inv-meta-box, .inv-totals-box { width: 100%; min-width: 0; margin-left: 0; }

  .ticket { padding: 22px; }

  .page-head { margin-bottom: 18px; }
  .page-head h1 { font-size: 21px; }

  /* Invoice list: table -> stacked cards */
  .table-wrap { overflow-x: visible; border: none; }
  table.list thead { display: none; }
  table.list, table.list tbody, table.list tr, table.list td { display: block; width: 100%; }
  table.list tr {
    margin-bottom: 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 2px 14px;
    background: var(--paper-raised);
  }
  table.list tr:hover td { background: transparent; }
  table.list td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 6px 0;
    border-bottom: 1px dashed var(--line);
    white-space: normal;
    text-align: right;
  }
  table.list tr td:last-child { border-bottom: none; padding-top: 8px; }
  table.list .table-actions { width: 100%; max-width: none; justify-content: flex-end; flex-wrap: wrap; }
  table.list td[data-label]::before {
    content: attr(data-label);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--muted);
    text-align: left;
    flex: none;
  }
  table.list .cell-stack { align-items: flex-end; }
}

@media (max-width: 480px) {
  .shell { padding: 16px 14px 48px; }
  .mobile-topbar { padding: 10px 14px; }

  .card { padding: 16px 16px 18px; }
  .page-head { flex-direction: column; align-items: stretch; gap: 12px; }
  .page-head .btn { width: 100%; }

  .stat-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat { padding: 13px 14px; }
  .stat .value { font-size: 19px; }

  .type-tabs { display: flex; width: 100%; }
  .type-tabs button { flex: 1; padding: 9px 6px; font-size: 13px; }

  .line-item-row { padding: 14px; }
  .line-item-row .grid,
  .line-item-row .grid.grid-3,
  .line-item-row .grid.grid-4,
  .line-item-row .warranty-grid { grid-template-columns: 1fr; }

  .logo-upload { flex-wrap: wrap; }
  .logo-upload input[type="file"] { max-width: 100%; }

  .form-actions { flex-direction: column; }
  .form-actions .btn { width: 100%; }

  .ticket-actions { flex-direction: column; align-items: stretch; }
  .ticket-actions > .btn:not(.action-btn) { width: 100%; }
  .ticket-actions .table-actions { margin-left: 0 !important; justify-content: center; flex-wrap: wrap; }

  .ticket { padding: 16px; }
  .ticket-head .biz-name { font-size: 17px; }
  .ticket-head .biz-meta { font-size: 11.5px; }
  .ticket-head .doc-type .num { font-size: 18px; }

  .inv-biz-name { font-size: 18px; }
  .inv-title { font-size: 16px; }
  .inv-logo-box { width: 64px; height: 64px; }

  .totals { max-width: none; }
}

/* ---------- Print ---------- */

@media print {
  /* Browsers strip background colors by default when printing —
     this forces every colored badge, icon, total box, due strip,
     etc. to print exactly as it looks on screen instead of turning
     plain black-and-white. */
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
  }

  #topbar-mount, #footer-mount, .sidebar, .mobile-topbar, .sidebar-backdrop, .ticket-actions, .no-print { display: none !important; }
  body { display: block; background: #fff; font-size: 11.5px; }
  .shell { max-width: none; padding: 0; margin: 0; }
  .ticket { border: 1px solid var(--ink-soft); padding: 16px 20px; max-width: 480px; margin: 0 auto; }
  .ticket::before { display: none; }

  /* The modern invoice template (Billed To / Invoice No. layout) reads
     best with more breathing room than the old narrow receipt-style
     ticket above (still used for warranty claim slips) — give it a
     wider print column so those boxes keep their on-screen, compact
     look instead of being squeezed. */
  .ticket:has(.inv-header) { max-width: 680px; padding: 24px 28px; }

  .ticket-head .biz img { width: 38px; height: 38px; }
  .ticket-head .biz-name { font-size: 15px; }
  .ticket-head .biz-meta { font-size: 11px; line-height: 1.4; }
  .ticket-head .doc-type .num { font-size: 15px; }
  .ticket-head .doc-type .kind { font-size: 10px; padding: 2px 7px; }
  .ticket-head .doc-type .date { font-size: 11px; margin-top: 2px; }

  .tear-line { margin: 12px 0; }

  .ticket-parties { margin-top: 2px; gap: 14px; }
  .ticket-parties .block-label { margin-bottom: 3px; }
  .ticket-parties .meta { font-size: 11.5px; line-height: 1.4; }

  .ticket table.items { font-size: 11.5px; margin-top: 2px; }
  .ticket table.items th { padding: 5px 8px; }
  .ticket table.items td { padding: 6px 8px; }
  .ticket table.items .item-sub { font-size: 10.5px; }
  .ticket table.items .warranty-tag { padding: 1px 7px; font-size: 10px; margin-top: 3px; }

  .ticket .service-block .problem { padding: 8px 10px; margin: 4px 0 10px; }

  div[style*="margin-top:20px"] { margin-top: 10px !important; }
  div[style*="margin-top:18px"] { margin-top: 10px !important; }

  .totals { max-width: 260px; padding: 8px 12px 0; gap: 5px; }
  .totals .line { font-size: 11.5px; }
  .totals .line.grand { font-size: 15px; padding: 6px 12px 7px; margin: 3px -12px 0; }

  .due-strip { padding: 6px 12px; margin-top: 8px; font-size: 11px; border-width: 1.5px; }

  .ticket .terms { font-size: 10px; line-height: 1.4; }

  .sign-row { margin-top: 24px; gap: 30px; }
  .sign-box { padding-top: 5px; font-size: 11px; }

  @page { size: A4; margin: 14mm; }

  .invoice-footer { padding-top: 8px; font-size: 10.5px; }

  .ticket-head,
  .ticket-parties,
  .totals,
  .due-strip,
  .sign-row,
  .invoice-footer,
  table.items tr {
    page-break-inside: avoid;
    break-inside: avoid;
  }

  /* Invoice ticket v2 */
  .inv-biz-name { font-size: 23px; }
  .inv-biz-address { font-size: 13px; padding-bottom: 6px; }
  .inv-logo-box { width: 100px; height: 100px; }
  .inv-title-wrap { margin: 14px 0 12px; }
  .inv-title { font-size: 15px; padding-bottom: 5px; }
  .inv-parties, .inv-bottom-row { gap: 20px; }
  .inv-billed, .inv-meta-box, .inv-totals-box { max-width: 260px; }
  .inv-items-wrap { margin-top: 10px; overflow-x: visible; }
  .inv-items-wrap table.items { min-width: 0; width: 100%; table-layout: fixed; }
  .inv-words-text { font-size: 11px; }
  .inv-terms-block { margin-top: 12px; }
  .inv-terms-title { font-size: 12px; margin-bottom: 6px; }
  .inv-terms-list li { font-size: 10px; padding: 4px 0; }

  .inv-header,
  .inv-parties,
  .inv-totals-box,
  .inv-terms-block {
    page-break-inside: avoid;
    break-inside: avoid;
  }
}


/* ---------- Density (auto font-shrink for longer item lists) ----------
   Applied unconditionally (not just @media print) so the same compact
   layout is captured by html2canvas for Save PDF / Share, guaranteeing
   the invoice always fits on a single A4 page regardless of item count. */

  .ticket.density-md { padding: 13px 17px; }
  .ticket.density-md .ticket-head .biz-name { font-size: 14px; }
  .ticket.density-md .ticket-head .biz-meta { font-size: 10px; }
  .ticket.density-md .ticket-head .doc-type .num { font-size: 14px; }
  .ticket.density-md table.items { font-size: 10.5px; }
  .ticket.density-md table.items th { padding: 4px 7px; }
  .ticket.density-md table.items td { padding: 4.5px 7px; }
  .ticket.density-md table.items .item-sub { font-size: 10px; }
  .ticket.density-md .totals { font-size: 10.5px; padding: 6px 12px 0; }
  .ticket.density-md .totals .line.grand { font-size: 13.5px; }
  .ticket.density-md .terms { font-size: 9.5px; }
  .ticket.density-md .sign-row { margin-top: 16px; }
  .ticket.density-md .invoice-footer { margin-top: 10px; padding-top: 8px; font-size: 10px; }
  .ticket.density-md .inv-title { font-size: 13px; }
  .ticket.density-md .inv-totals-box { font-size: 10.5px; padding: 6px 12px; }
  .ticket.density-md .inv-totals-line.total { font-size: 13px; }
  .ticket.density-md .inv-terms-list li { font-size: 9.5px; }

  .ticket.density-md .inv-header { margin-top: 0; }
  .ticket.density-md .inv-biz-address { margin-top: 3px; padding-bottom: 7px; }
  .ticket.density-md .inv-title-wrap { margin: 14px 0 12px; }
  .ticket.density-md .inv-parties { gap: 16px; }
  .ticket.density-md .inv-label { font-size: 10px; margin-bottom: 5px; }
  .ticket.density-md .inv-billed { padding: 7px 10px; }
  .ticket.density-md .inv-meta-box { padding: 8px 12px; }
  .ticket.density-md .inv-meta-row { padding: 4px 0; }
  .ticket.density-md .inv-meta-label { font-size: 10px; }
  .ticket.density-md .inv-meta-val { font-size: 12px; }
  .ticket.density-md .inv-items-wrap { margin-top: 12px; }
  .ticket.density-md .inv-bottom-row { margin-top: 12px; gap: 16px; }
  .ticket.density-md .inv-words-text { font-size: 11px; padding-bottom: 7px; }
  .ticket.density-md .inv-terms-block { margin-top: 12px; }
  .ticket.density-md .inv-terms-title { font-size: 12px; margin-bottom: 6px; }

  .ticket.density-sm { padding: 11px 15px; }
  .ticket.density-sm .ticket-head .biz-name { font-size: 13px; }
  .ticket.density-sm .ticket-head .biz-meta { font-size: 9px; line-height: 1.3; }
  .ticket.density-sm .ticket-head .doc-type .num { font-size: 13px; }
  .ticket.density-sm .ticket-head .doc-type .kind { font-size: 9px; padding: 1px 6px; }
  .ticket.density-sm .ticket-parties .meta { font-size: 10px; }
  .ticket.density-sm table.items { font-size: 9.5px; margin-top: 0; }
  .ticket.density-sm table.items th { padding: 3px 6px; }
  .ticket.density-sm table.items td { padding: 2.5px 6px; }
  .ticket.density-sm table.items .item-sub { font-size: 9px; margin-top: 1px; }
  .ticket.density-sm table.items .warranty-tag { padding: 0 5px; font-size: 8.5px; margin-top: 1px; }
  .ticket.density-sm .totals { font-size: 9.5px; max-width: 230px; padding: 5px 10px 0; gap: 3px; }
  .ticket.density-sm .totals .line.grand { font-size: 12px; padding: 4px 10px 5px; }
  .ticket.density-sm .due-strip { padding: 4px 10px; font-size: 9.5px; }
  .ticket.density-sm .terms { font-size: 9px; line-height: 1.3; }
  .ticket.density-sm .sign-row { margin-top: 10px; gap: 24px; }
  .ticket.density-sm .invoice-footer { margin-top: 8px; padding-top: 6px; font-size: 9px; }
  .ticket.density-sm .inv-title { font-size: 12px; }
  .ticket.density-sm .inv-totals-box { font-size: 9.5px; padding: 5px 10px; }
  .ticket.density-sm .inv-totals-line.total { font-size: 12px; }
  .ticket.density-sm .inv-terms-list li { font-size: 9px; }

  .ticket.density-sm .inv-header { margin-top: 0; }
  .ticket.density-sm .inv-biz-address { margin-top: 2px; padding-bottom: 5px; }
  .ticket.density-sm .inv-title-wrap { margin: 9px 0 8px; }
  .ticket.density-sm .inv-parties { gap: 12px; }
  .ticket.density-sm .inv-label { font-size: 9.5px; margin-bottom: 4px; }
  .ticket.density-sm .inv-billed { padding: 6px 9px; }
  .ticket.density-sm .inv-meta-box { padding: 6px 10px; }
  .ticket.density-sm .inv-meta-row { padding: 3px 0; }
  .ticket.density-sm .inv-meta-label { font-size: 9.5px; }
  .ticket.density-sm .inv-meta-val { font-size: 11px; }
  .ticket.density-sm .inv-items-wrap { margin-top: 8px; }
  .ticket.density-sm .inv-bottom-row { margin-top: 8px; gap: 12px; }
  .ticket.density-sm .inv-words-text { font-size: 10px; padding-bottom: 5px; line-height: 1.4; }
  .ticket.density-sm .inv-terms-block { margin-top: 8px; }
  .ticket.density-sm .inv-terms-title { font-size: 11px; margin-bottom: 5px; }

  .ticket.density-xs { padding: 9px 13px; }
  .ticket.density-xs .ticket-head .biz-name { font-size: 12px; }
  .ticket.density-xs .ticket-head .biz-meta { font-size: 8px; line-height: 1.25; }
  .ticket.density-xs .ticket-head .doc-type .num { font-size: 12px; }
  .ticket.density-xs .ticket-head .doc-type .kind { font-size: 8px; padding: 1px 5px; }
  .ticket.density-xs .ticket-parties { margin-top: 0; gap: 10px; }
  .ticket.density-xs .ticket-parties .meta { font-size: 9px; }
  .ticket.density-xs table.items { font-size: 8.5px; margin-top: 0; }
  .ticket.density-xs table.items th { padding: 2px 5px; }
  .ticket.density-xs table.items td { padding: 1.5px 5px; }
  .ticket.density-xs table.items .item-sub { font-size: 7.5px; margin-top: 0; }
  .ticket.density-xs table.items .warranty-tag { padding: 0 4px; font-size: 7.5px; margin-top: 1px; }
  .ticket.density-xs .totals { font-size: 8.5px; max-width: 210px; padding: 4px 9px 0; gap: 2px; }
  .ticket.density-xs .totals .line.grand { font-size: 11px; padding: 3px 9px 4px; }
  .ticket.density-xs .due-strip { padding: 3px 9px; font-size: 8.5px; margin-top: 5px; }
  .ticket.density-xs .terms { font-size: 8px; line-height: 1.25; }
  .ticket.density-xs .sign-row { margin-top: 6px; gap: 18px; }
  .ticket.density-xs .invoice-footer { margin-top: 6px; padding-top: 4px; font-size: 8px; }
  .ticket.density-xs .inv-title { font-size: 11px; }
  .ticket.density-xs .inv-totals-box { font-size: 8.5px; padding: 4px 9px; }
  .ticket.density-xs .inv-totals-line.total { font-size: 11px; }
  .ticket.density-xs .inv-terms-list li { font-size: 8px; }

  .ticket.density-xs .inv-header { margin-top: 0; }
  .ticket.density-xs .inv-biz-address { margin-top: 1px; padding-bottom: 3px; }
  .ticket.density-xs .inv-title-wrap { margin: 5px 0 5px; }
  .ticket.density-xs .inv-parties { gap: 8px; }
  .ticket.density-xs .inv-label { font-size: 9px; margin-bottom: 3px; }
  .ticket.density-xs .inv-billed { padding: 5px 8px; }
  .ticket.density-xs .inv-meta-box { padding: 4px 8px; }
  .ticket.density-xs .inv-meta-row { padding: 2px 0; }
  .ticket.density-xs .inv-meta-label { font-size: 9px; }
  .ticket.density-xs .inv-meta-val { font-size: 10px; }
  .ticket.density-xs .inv-items-wrap { margin-top: 4px; }
  .ticket.density-xs .inv-bottom-row { margin-top: 4px; gap: 8px; }
  .ticket.density-xs .inv-words-text { font-size: 9px; padding-bottom: 3px; line-height: 1.3; }
  .ticket.density-xs .inv-terms-block { margin-top: 4px; }
  .ticket.density-xs .inv-terms-title { font-size: 10px; margin-bottom: 3px; }
  .ticket.density-xs div[style*="margin-top:20px"] { margin-top: 4px !important; }
  .ticket.density-xs div[style*="margin-top:18px"] { margin-top: 4px !important; }

/* ==========================================================
   Feature toggle switches (Settings → Feature Settings)
   ========================================================== */
.feature-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.feature-toggle-row:last-child { border-bottom: none; }
.feature-toggle-name { font-weight: 600; font-size: 14px; }
.feature-toggle-desc { font-size: 12px; color: var(--muted); margin-top: 2px; }

.switch { position: relative; display: inline-block; width: 44px; height: 26px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider {
  position: absolute; cursor: pointer; inset: 0;
  background: var(--line-strong);
  border-radius: 999px;
  transition: background .15s ease;
}
.switch .slider::before {
  content: "";
  position: absolute;
  height: 20px; width: 20px;
  left: 3px; bottom: 3px;
  background: var(--paper-raised);
  border-radius: 50%;
  transition: transform .15s ease;
  box-shadow: var(--shadow-sm);
}
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider::before { transform: translateX(18px); }
.switch input:focus-visible + .slider { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (max-width: 640px) {
  .feature-toggle-row { align-items: flex-start; }
}

/* ---------- Sub-tabs (e.g. Suppliers / Supplier Due) ---------- */
.subtabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 0;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.subtab-btn {
  padding: 10px 18px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  flex: none;
  transition: color .12s ease, border-color .12s ease;
}

@media (max-width: 480px) {
  .subtab-btn { padding: 9px 12px; font-size: 13px; }
}

.subtab-btn:hover { color: var(--accent-hover); }
.subtab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------- Invoice Template toggles ---------- */
/* "Colorful icons" off (Settings → Invoice Template): every icon badge
   on the printed/shared invoice — business Address/Phone/Email in the
   header, and Name/Phone/Address/Invoice No./Date/Payment Method in
   the Billed To & meta boxes — turns plain black & white instead of
   its usual distinct color per field. High specificity + last in the
   stylesheet so this wins over the per-icon and per-layout colors
   above, including the Modern layout's white-on-banner override. */
.ticket.mono-icons .inv-biz-contact-icon,
.ticket.mono-icons .inv-meta-icon {
  background: #e9e9e9 !important;
  color: #444 !important;
}

/* "Show item color dot" off: hides the small colored dot printed
   between the item number prefix and the item name on every line —
   same effect the Minimal layout already applies on its own. */
.ticket.no-item-dot table.items .item-dot { display: none; }

/* ==========================================================
   Purchase History page — layout & readability polish
   Scoped to this page's element IDs only; no other page uses
   #ph-* ids so this cannot affect any other screen.
   ========================================================== */

/* ---- Filter toolbar ---- */
.ph-filter-bar { padding-top: 16px; }
.ph-filter-row {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  flex-wrap: wrap;
}
.ph-filter-field { margin-bottom: 0; min-width: 170px; flex: 1 1 170px; max-width: 260px; }
.ph-print-btn { margin-left: auto; white-space: nowrap; }
.ph-custom-range { margin-top: 14px; margin-bottom: 0; }

@media (max-width: 640px) {
  .ph-filter-row { align-items: stretch; }
  .ph-filter-field { max-width: none; }
  .ph-print-btn { margin-left: 0; width: 100%; }
}

/* ---- Fixed layout so the <colgroup> widths actually hold, with
   sane wrapping per column type instead of runaway auto-sizing.
   Nothing is ever clipped/ellipsized — a too-narrow column wraps
   its text onto a second line rather than hiding data. ---- */
table.ph-fixed { table-layout: fixed; }
table.ph-fixed th,
table.ph-fixed td { overflow-wrap: break-word; }
table.ph-fixed td[data-label="Item"] { line-height: 1.35; }

/* Short, uniform-length values stay on one line */
table.ph-fixed td[data-label="Date"],
table.ph-fixed td.num { white-space: nowrap; }

/* Numeric columns — right-aligned, same convention already used on
   the printed invoice's table.items .num columns. */
table.ph-fixed th.num,
table.ph-fixed td.num { text-align: right; }

#ph-table td .table-actions,
#ph-latest-table td .table-actions { flex-wrap: wrap; row-gap: 4px; }

@media (max-width: 640px) {
  /* the shared mobile card-row layout already stacks table.list —
     undo the fixed sizing so it doesn't fight that transformation */
  table.ph-fixed { table-layout: auto; }
  table.ph-fixed td[data-label="Date"],
  table.ph-fixed td.num { white-space: normal; }
  table.ph-fixed th.num,
  table.ph-fixed td.num { text-align: right; }
}

/* ---- Paid / Due as small status pills instead of plain colored text,
   for faster scanning down a long history table ---- */
.ph-pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  line-height: 1.6;
}
.ph-pill-due { background: var(--accent2-soft); color: var(--accent2); }
.ph-pill-credit { background: var(--accent-soft); color: var(--accent-hover); }
.ph-pill-paid { background: var(--accent-soft); color: var(--accent-hover); }

/* ---- Alternate shading per purchase entry (not per <tr>), so a
   multi-item purchase reads as one grouped block at a glance ---- */
#ph-table tbody tr.ph-alt td,
#ph-latest-table tbody tr.ph-alt td { background: #fafaf9; }
#ph-table tbody tr.ph-alt:hover td,
#ph-latest-table tbody tr.ph-alt:hover td { background: var(--accent-soft); }


