/* ============================================================
   Invoice Maker — design tokens
   Subject: computer sales & repair shop.
   Signature: the "service-ticket" tear-line divider, a faint
   schematic dot-grid backdrop (PCB blueprint), and a rubber-
   stamp treatment for the Paid/Due status — like a real job
   ticket off a workshop counter. Monospace carries every
   number: serials, invoice IDs, money.
   ============================================================ */

@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 {
  --ink: #12151b;
  --ink-soft: #333c4a;
  --paper: #f2f3ee;
  --paper-raised: #ffffff;
  --line: #dfe2da;
  --line-strong: #bfc4b7;
  --muted: #5c6470;

  --accent: #146c48;      /* circuit-board green */
  --accent-hover: #0e5738;
  --accent-soft: #e1f1e8;

  --accent2: #b3382a;     /* red / due-status, ink-stamp red */
  --accent2-hover: #97301f;
  --accent2-soft: #fbe3e0;

  --info: #33538f;        /* service badge blue */
  --info-soft: #e7edf7;

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

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

  --shadow-xs: 0 1px 2px rgba(18, 21, 27, 0.05);
  --shadow-sm: 0 2px 6px -2px rgba(18, 21, 27, 0.12), 0 1px 2px rgba(18, 21, 27, 0.06);
  --shadow: 0 10px 28px -12px rgba(18, 21, 27, 0.22), 0 2px 6px -2px rgba(18, 21, 27, 0.08);
  --shadow-lg: 0 24px 48px -18px rgba(18, 21, 27, 0.32);

  --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;
}

body {
  min-height: 100vh;
  background-color: var(--paper);
  background-image: radial-gradient(circle at 1px 1px, rgba(18, 21, 27, 0.07) 1px, transparent 0);
  background-size: 24px 24px;
}

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;
}

/* ---------- Layout shell ---------- */

.shell {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 20px 64px;
}

.topbar {
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow-xs);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  width: 100%;
  padding: 14px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.brand img {
  width: 36px;
  height: 36px;
  object-fit: contain;
  border-radius: var(--radius-sm);
  background: var(--paper);
  border: 1px solid var(--line);
}

.brand-logo-fallback {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 13px;
  flex: none;
}

.brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16.5px;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav {
  display: flex;
  gap: 4px;
}

.nav a {
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  transition: background .15s ease, color .15s ease;
}

.nav a:hover { background: var(--accent-soft); color: var(--accent-hover); }
.nav a.active { background: var(--accent); color: #fff; box-shadow: var(--shadow-xs); }

.nav-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  flex: none;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--paper-raised);
  color: var(--ink);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--shadow-xs);
}
.nav-toggle:hover { background: var(--paper); }

.nav-mobile {
  display: none;
  flex-direction: column;
  gap: 2px;
  max-width: 1080px;
  margin: 0 auto;
  padding: 8px 0 14px;
  border-top: 1px solid var(--line);
}
.nav-mobile.open { display: flex; }
.nav-mobile a {
  padding: 12px 10px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 500;
  color: var(--muted);
}
.nav-mobile a:hover { background: var(--accent-soft); color: var(--accent-hover); }
.nav-mobile a.active { background: var(--accent); color: #fff; }

/* ---------- 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;
  box-shadow: var(--shadow-xs);
  transition: transform .1s ease, box-shadow .15s ease, background .15s ease, border-color .15s ease;
}
.btn:hover { border-color: var(--line-strong); background: #fff; transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn:active { transform: translateY(0); box-shadow: var(--shadow-xs); }

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

.btn-accent {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 3px 10px -4px rgba(20, 108, 72, 0.55);
}
.btn-accent:hover { background: var(--accent-hover); border-color: var(--accent-hover); box-shadow: 0 6px 16px -6px rgba(20, 108, 72, 0.6); }

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

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

.btn-sm { padding: 6px 10px; font-size: 13px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; box-shadow: none; }

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

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

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

.card {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px 24px 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-xs);
}

.card-title {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 600;
  margin: 0 0 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 10px;
}

.card-title .step-dot {
  width: 23px; height: 23px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 12px;
  display: flex; align-items: center; justify-content: center;
  flex: none;
}

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

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

.stat {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-left: 3px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-xs);
  transition: transform .15s ease, box-shadow .15s ease;
}
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow-sm); }

.stat .label {
  font-size: 11.5px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .07em;
  margin-bottom: 7px;
  font-weight: 500;
}

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

.stat.ok { border-left-color: var(--accent); }
.stat.ok .value { color: var(--accent); }
.stat.due { border-left-color: var(--accent2); }
.stat.due .value { color: var(--accent2); }

/* ---------- 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); }

.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; }

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 .15s ease, box-shadow .15s ease, background .15s 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);
  box-shadow: var(--shadow-xs);
  margin-bottom: 22px;
}

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

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

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

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

.line-item-row {
  display: grid;
  gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--paper-raised);
  position: relative;
  transition: background .15s ease;
}
.line-item-row:last-child { border-bottom: none; }
.line-item-row:nth-child(even) { background: #fafbf8; }
.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 .warranty-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 1fr 1fr 1.4fr;
  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; }

.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 .15s ease, transform .1s ease;
}
.remove-row:hover { background: #f5cfca; transform: scale(1.06); }

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

/* ---------- 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);
}

/* ---------- 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: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  padding: 12px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

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

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

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

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 11px;
  border-radius: 999px;
  font-size: 12px;
  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); }
.due-amount { color: var(--accent2); 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;
}

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

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

.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: 999px;
}
.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;
}
.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;
}
.ticket table.items td.num, .ticket table.items th.num { text-align: right; font-family: var(--font-mono); }
.ticket table.items .item-name { font-weight: 600; }
.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: 999px;
  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: 2px 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;
  transform: rotate(-0.5deg);
}
.due-strip.paid { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-hover); }
.due-strip .amount { font-size: 15px; }

/* ---------- 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 ---------- */

/* Tablet: loosen up the widest field grids to 2 columns */
@media (max-width: 880px) {
  .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 .warranty-grid { grid-template-columns: 1fr 1fr; }
  .ticket-parties { grid-template-columns: 1fr; }
  .sign-row { grid-template-columns: 1fr; gap: 26px; }

  .nav { display: none; }
  .nav-toggle { display: flex; }

  .ticket { padding: 22px; }

  .page-head { margin: 22px 0 18px; }
  .page-head h1 { font-size: 22px; }

  /* 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: 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 2px 14px;
    background: var(--paper-raised);
    box-shadow: var(--shadow-xs);
  }
  table.list tr:hover td { background: transparent; }
  table.list td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px dashed var(--line);
    white-space: normal;
    text-align: right;
  }
  table.list tr td:last-child { border-bottom: none; padding-top: 12px; }
  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; }
  table.list .table-actions { width: 100%; justify-content: flex-end; flex-wrap: wrap; }
}

@media (max-width: 480px) {
  .shell { padding: 0 14px 48px; }
  .topbar { padding: 0 14px; }
  .topbar-inner { padding: 11px 0; }
  .brand img, .brand-logo-fallback { width: 30px; height: 30px; }
  .brand-name { font-size: 15px; }

  .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 .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 { width: 100%; }

  .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; }

  .totals { max-width: none; }
}

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

@media print {
  .topbar, .nav, .ticket-actions, .no-print { display: none !important; }
  body { background: #fff; font-size: 11.5px; }
  .shell { max-width: none; padding: 0; margin: 0; }
  .ticket { box-shadow: none; border: 1px solid var(--ink-soft); padding: 16px 20px; }
  .ticket::before { display: none; }

  .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; transform: none; 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: A5; margin: 9mm; }

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

/* ---------- Print density (auto font-shrink for longer item lists) ---------- */
/* Applied via JS (view.js) based on how many line items an invoice has,
   so a 10-15 item invoice still fits on one A5 page. */

@media print {
  /* 7–10 items: slightly tighter */
  .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; }

  /* 11–15 items: noticeably smaller */
  .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: 3.5px 6px; }
  .ticket.density-sm table.items .item-sub { font-size: 9px; }
  .ticket.density-sm table.items .warranty-tag { padding: 0 5px; font-size: 9px; margin-top: 2px; }
  .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; }

  /* 16+ items: as small as reasonably readable */
  .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: 2.5px 5px; }
  .ticket.density-xs table.items .item-sub { font-size: 8px; }
  .ticket.density-xs table.items .warranty-tag { padding: 0 4px; font-size: 8px; 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 div[style*="margin-top:20px"] { margin-top: 4px !important; }
  .ticket.density-xs div[style*="margin-top:18px"] { margin-top: 4px !important; }
}
