:root {
  color-scheme: light dark;

  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --line: #e3e6ea;
  --line-strong: #cfd4da;
  --text: #16191d;
  --text-2: #5b6470;
  --text-3: #8b94a0;

  --accent: #1f6b4a;
  --accent-hover: #185639;
  --accent-soft: #e6f2eb;
  --accent-line: #b9d8c7;

  --danger: #b3382e;
  --danger-soft: #fceceb;
  --danger-line: #f0c5c1;
  --warn: #8a5800;
  --warn-soft: #fdf3e0;
  --warn-line: #eed9ab;

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-md: 0 4px 16px rgba(16, 24, 40, .09);
  --shadow-lg: 0 16px 48px rgba(16, 24, 40, .18);

  --header-h: 56px;
  --tabbar-h: 60px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #1d222a;
    --line: #2a3139;
    --line-strong: #3a434e;
    --text: #e8ecf1;
    --text-2: #a2adbb;
    --text-3: #727d8b;

    --accent: #4bb183;
    --accent-hover: #5cc694;
    --accent-soft: #15301f;
    --accent-line: #265b3d;

    --danger: #f08b82;
    --danger-soft: #33191a;
    --danger-line: #5e2d2a;
    --warn: #e0b561;
    --warn-soft: #2f2615;
    --warn-line: #574522;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, .5);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, .6);
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  overflow-wrap: break-word;
}

.hidden { display: none !important; }
.muted { color: var(--text-2); }
.tiny { font-size: 12.5px; }
.error { color: var(--danger); margin: 10px 0 0; font-size: 14px; }

/* ---------- form controls ---------- */

input, select, textarea, button { font: inherit; color: inherit; }

input[type=text], input[type=password], input[type=number], input[type=search], select, textarea {
  width: 100%;
  padding: 9px 11px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  transition: border-color .12s, box-shadow .12s;
}
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { min-height: 96px; resize: vertical; line-height: 1.55; }
select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-2) 50%),
                    linear-gradient(135deg, var(--text-2) 50%, transparent 50%);
  background-position: calc(100% - 17px) calc(50% + 1px), calc(100% - 12px) calc(50% + 1px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 32px;
}
input.num { text-align: right; font-variant-numeric: tabular-nums; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .field-label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.field .hint { font-size: 12px; color: var(--text-3); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 16px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  background: var(--surface);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  transition: background .12s, border-color .12s, opacity .12s;
}
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { border-color: var(--line-strong); color: var(--text); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); border-color: var(--text-3); }
.btn-quiet { background: transparent; color: var(--text-2); padding: 7px 10px; }
.btn-quiet:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn-danger { background: transparent; border-color: var(--danger-line); color: var(--danger); }
.btn-sm { padding: 6px 11px; font-size: 13px; }
.btn-icon { padding: 7px; width: 34px; height: 34px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-block { width: 100%; }

/* ---------- login ---------- */

.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login form {
  width: 100%;
  max-width: 380px;
  padding: 32px 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.login .brand { display: flex; flex-direction: column; gap: 3px; margin-bottom: 4px; }
.login .brand b { font-size: 21px; letter-spacing: -.01em; }

/* ---------- app shell ---------- */

.shell { min-height: 100dvh; display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 16px;
  height: var(--header-h);
  padding: 0 16px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar .logo { font-weight: 700; letter-spacing: -.01em; font-size: 16px; white-space: nowrap; }
.topbar .tabs { display: flex; gap: 2px; }
.topbar .tabs button {
  padding: 7px 13px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--text-2);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
.topbar .tabs button:hover { background: var(--surface-2); color: var(--text); }
.topbar .tabs button[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.topbar .spacer { flex: 1; }
.topbar .who { font-size: 13.5px; color: var(--text-2); white-space: nowrap; }

main { flex: 1; width: 100%; max-width: 1180px; margin: 0 auto; padding: 22px 16px 32px; min-width: 0; }

.page-head { margin-bottom: 18px; }
.page-head h1 { margin: 0 0 3px; font-size: 22px; font-weight: 650; letter-spacing: -.015em; }
.page-head p { margin: 0; font-size: 14px; color: var(--text-2); }

.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.toolbar .grow { flex: 1; min-width: 180px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  margin-bottom: 18px;
}
.card > header {
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  font-size: 13.5px;
  font-weight: 600;
}
.card > .body { padding: 16px; }

/* ---------- data table ---------- */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
thead th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  font-size: 11.5px;
  font-weight: 650;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--text-3);
  white-space: nowrap;
  z-index: 1;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }

.thumb {
  width: 40px; height: 40px;
  object-fit: cover;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--surface-2);
  display: block;
  flex: none;
}
.thumb.placeholder { display: grid; place-items: center; color: var(--text-3); font-size: 16px; }

.stack { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.stack b { font-weight: 550; }
.stack span { font-size: 12.5px; color: var(--text-3); }

.tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 550;
  white-space: nowrap;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--text-2);
}
.tag.ok { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }
.tag.bad { background: var(--danger-soft); border-color: var(--danger-line); color: var(--danger); }
.tag.warn { background: var(--warn-soft); border-color: var(--warn-line); color: var(--warn); }
.tag.mono { font-variant-numeric: tabular-nums; }

/* order flow */
.stepper { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 0; }
.stepper li { display: flex; align-items: center; gap: 7px; flex: 1 1 auto; min-width: 0; }
.stepper li::after {
  content: "";
  flex: 1;
  height: 2px;
  background: var(--line);
  margin: 0 6px;
  min-width: 8px;
}
.stepper li:last-child::after { display: none; }
.stepper .bullet {
  flex: none;
  width: 23px; height: 23px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 11.5px;
  font-weight: 650;
  background: var(--surface-2);
  border: 1px solid var(--line-strong);
  color: var(--text-3);
}
.stepper .label { font-size: 12px; color: var(--text-3); white-space: nowrap; }
.stepper li.done .bullet { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }
.stepper li.done .label { color: var(--text-2); }
.stepper li.done::after { background: var(--accent-line); }
.stepper li.now .bullet { background: var(--accent); border-color: var(--accent); color: #fff; }
.stepper li.now .label { color: var(--text); font-weight: 650; }
.stepper.cancelled .bullet { opacity: .5; }

.kv { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 16px; }
.kv > div { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.kv .k { font-size: 12px; color: var(--text-3); }
.kv .v { font-size: 14px; overflow-wrap: anywhere; }

.note {
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  font-size: 13.5px;
  color: var(--text-2);
}
.doc-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

tfoot td { border-top: 1px solid var(--line); border-bottom: 0; font-size: 13.5px; color: var(--text-2); }
tfoot tr.grand td { font-weight: 650; color: var(--text); font-size: 15px; }

.dot-new {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--warn);
  display: inline-block;
  flex: none;
}

.with-add { display: flex; gap: 8px; align-items: center; }
.with-add select { flex: 1; min-width: 0; }

.legend {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 10px 20px;
  padding: 13px 15px;
  margin-bottom: 14px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}
.legend > div { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.legend b { font-size: 12.5px; font-weight: 650; }
.legend span { font-size: 12.5px; color: var(--text-2); }

/* rich text */
.rt {
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  overflow: hidden;
  transition: border-color .12s, box-shadow .12s;
}
.rt:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.rt-bar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 5px 6px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}
.rt-btn {
  min-width: 28px;
  height: 26px;
  padding: 0 7px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
  line-height: 1;
}
.rt-btn:hover { background: var(--line); color: var(--text); }
.rt-sep { width: 1px; height: 16px; background: var(--line); margin: 0 4px; }
.rt-area {
  padding: 10px 12px;
  min-height: 96px;
  max-height: 320px;
  overflow-y: auto;
  outline: none;
  font-size: 14.5px;
  line-height: 1.55;
}
.rt-area.compact { min-height: 54px; }
.rt-area:empty::before {
  content: attr(data-placeholder);
  color: var(--text-3);
  pointer-events: none;
}
.rt-area p { margin: 0 0 8px; }
.rt-area p:last-child { margin-bottom: 0; }
.rt-area ul, .rt-area ol { margin: 0 0 8px; padding-left: 20px; }

/* modal */
.modal-scrim { z-index: 50; background: rgba(10, 14, 18, .55); }
.modal {
  position: fixed;
  z-index: 51;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100dvh - 48px);
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  animation: pop .16s cubic-bezier(.3, .8, .4, 1);
}
@keyframes pop {
  from { opacity: 0; transform: translate(-50%, -46%) scale(.97); }
  to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
.modal-body { padding: 22px 22px 18px; display: flex; flex-direction: column; gap: 14px; }
.modal-body h3 { margin: 0; font-size: 17px; font-weight: 650; letter-spacing: -.01em; }
.modal-body > p { margin: -6px 0 0; font-size: 14px; color: var(--text-2); line-height: 1.5; }
.modal-actions {
  display: flex;
  gap: 10px;
  padding: 14px 22px;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 0 0 var(--r-lg) var(--r-lg);
}
.modal-actions .btn { flex: 1; }
.btn-danger-solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger-solid:hover:not(:disabled) { filter: brightness(1.08); }

@media (max-width: 480px) {
  .modal { width: calc(100vw - 24px); }
  .modal-body { padding: 18px 18px 14px; }
  .modal-actions { padding: 12px 18px; }
}

.inline-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline-row select { flex: 1 1 160px; min-width: 0; }
.pct-input { display: inline-flex; align-items: center; gap: 6px; }
.pct-input span { color: var(--text-2); font-size: 14px; }
input.w-sm { width: 86px; }
.gift-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 4px; }
.owing { color: var(--danger); }

.group-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 13px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  flex-wrap: wrap;
}
.group-fields { display: flex; gap: 8px; align-items: center; flex: 1 1 320px; min-width: 0; justify-content: flex-end; }
.group-fields input[type=text] { flex: 1 1 140px; min-width: 0; }

@media (max-width: 860px) {
  .group-row { flex-direction: column; align-items: stretch; }
  .group-fields { justify-content: stretch; flex-wrap: wrap; }
  .group-fields .btn { flex: 1 1 100%; }
}

.cat-field { display: flex; flex-direction: column; gap: 8px; }
.inline-add {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  flex-wrap: wrap;
}
.inline-add input { flex: 1 1 180px; min-width: 0; }

.check-row {
  display: flex;
  gap: 11px;
  align-items: flex-start;
  padding: 12px 13px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  cursor: pointer;
}
.check-row input[type=checkbox] { width: 17px; height: 17px; margin: 2px 0 0; accent-color: var(--accent); flex: none; cursor: pointer; }
.check-row .stack b { font-size: 14px; font-weight: 600; }
.check-row .stack span { font-size: 12.5px; color: var(--text-2); }

.line.no-price { grid-template-columns: minmax(0, 1fr) 110px 38px; }

.price-pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.price-pair > label { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.price-pair > label > span { font-size: 11.5px; color: var(--text-3); font-weight: 600; }

.qty-uom { display: flex; gap: 8px; align-items: center; }
.qty-uom input { flex: 1 1 40%; min-width: 0; }
.qty-uom select { flex: 1 1 60%; min-width: 0; }

/* banner + stats (ΑΑΔΕ) */
.banner {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 14px 16px;
  margin-bottom: 16px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  border-left-width: 4px;
}
.banner.ok { border-left-color: var(--accent); background: var(--accent-soft); }
.banner.warn { border-left-color: var(--warn); background: var(--warn-soft); }
.banner.bad { border-left-color: var(--danger); background: var(--danger-soft); }
.banner .stack b { font-size: 15px; font-weight: 650; }
.banner .stack span { font-size: 13px; color: var(--text-2); }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}
.stat {
  padding: 15px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat b { font-size: 26px; font-weight: 650; letter-spacing: -.02em; line-height: 1.15; }
.stat span { font-size: 12.5px; color: var(--text-2); }
.stat.ok b { color: var(--accent); }
.stat.warn b { color: var(--warn); }
.stat.bad b { color: var(--danger); }

.fail {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 13px 14px;
  border: 1px solid var(--danger-line);
  background: var(--danger-soft);
  border-radius: var(--r-md);
  flex-wrap: wrap;
}
.fail .stack b { font-size: 14px; }
.fail .stack span { font-size: 13px; color: var(--text-2); }

a.btn { text-decoration: none; }

/* filters + pagination */
.section-title { margin: 22px 0 12px; font-size: 16px; font-weight: 650; }
.section-title:first-child { margin-top: 0; }

.filters {
  display: flex;
  gap: 9px;
  align-items: center;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.filters .filter { min-width: 0; }
.filters .filter.grow { flex: 1 1 220px; }
.filters select { min-width: 150px; }

.pager {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 11px 14px;
  border-top: 1px solid var(--line);
  background: var(--surface-2);
  flex-wrap: wrap;
}
.pager .spacer { flex: 1; }
.pager-count { font-size: 13px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.pager .page-size { width: auto; min-width: 118px; padding: 5px 30px 5px 9px; font-size: 13px; }

.stats-3 { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.stat small { font-size: 11.5px; color: var(--text-3); margin-top: 2px; display: block; }
.stat-btn { text-align: left; cursor: pointer; font: inherit; transition: border-color .12s, transform .08s; }
.stat-btn:hover:not(:disabled) { border-color: var(--line-strong); }
.stat-btn:active:not(:disabled) { transform: translateY(1px); }
.stat-btn:disabled { cursor: default; opacity: 1; }

.split { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-bottom: 18px; align-items: start; }

.card > header { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

.row-btn {
  width: 100%;
  text-align: left;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 11px 13px;
  cursor: pointer;
  font: inherit;
  color: inherit;
  transition: border-color .12s, background .12s;
}
.row-btn:hover { border-color: var(--line-strong); background: var(--surface); }

.alert { border-left-width: 3px; }
.alert.warn { background: var(--warn-soft); border-color: var(--warn-line); }
.alert.bad { background: var(--danger-soft); border-color: var(--danger-line); }
.alert .stack b { font-size: 14px; }
.alert .stack span { font-size: 13px; color: var(--text-2); }

.stage-bars { display: flex; flex-direction: column; gap: 9px; }
.stage-bar { display: grid; grid-template-columns: 140px 1fr 42px; gap: 12px; align-items: center; }
.sb-label { font-size: 13px; color: var(--text-2); }
.sb-track { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; border: 1px solid var(--line); }
.sb-fill { display: block; height: 100%; background: var(--text-3); border-radius: 999px; }
.sb-fill.ok { background: var(--accent); }
.sb-fill.warn { background: var(--warn); }
.sb-fill.bad { background: var(--danger); }
.sb-count { font-size: 13px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

.empty { padding: 44px 20px; text-align: center; color: var(--text-2); }
.empty b { display: block; margin-bottom: 4px; color: var(--text); font-weight: 600; }

/* skeleton */
.skeleton { padding: 16px; display: flex; flex-direction: column; gap: 11px; }
.skeleton i {
  display: block;
  height: 15px;
  border-radius: var(--r-sm);
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--line) 50%, var(--surface-2) 75%);
  background-size: 300% 100%;
  animation: shimmer 1.3s infinite linear;
}
@keyframes shimmer { from { background-position: 150% 0; } to { background-position: -150% 0; } }

/* ---------- editor rows (invoice / stock lines) ---------- */

.lines { display: flex; flex-direction: column; gap: 9px; }
.line {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 110px 120px 38px;
  gap: 9px;
  align-items: center;
}
.line .line-label { display: none; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 14px; }

/* ---------- drawer ---------- */

.scrim {
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 18, .45);
  backdrop-filter: blur(2px);
  z-index: 40;
  animation: fade .15s ease-out;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(560px, 100vw);
  background: var(--bg);
  z-index: 41;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: slide-in .2s cubic-bezier(.3, .8, .4, 1);
}
@keyframes slide-in { from { transform: translateX(100%); } to { transform: none; } }

.drawer > header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  flex: none;
}
.drawer > header h2 { margin: 0; font-size: 16px; font-weight: 650; }
.drawer > .body { flex: 1; overflow-y: auto; padding: 18px 16px 24px; display: flex; flex-direction: column; gap: 20px; }
.drawer > footer {
  display: flex;
  gap: 10px;
  padding: 13px 16px;
  background: var(--surface);
  border-top: 1px solid var(--line);
  flex: none;
  padding-bottom: max(13px, env(safe-area-inset-bottom));
}
.drawer > footer .btn { flex: 1; }

.image-edit { display: flex; gap: 14px; align-items: center; }
.image-edit img, .image-edit .ph {
  width: 84px; height: 84px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  object-fit: cover;
  background: var(--surface-2);
  flex: none;
}
.image-edit .ph { display: grid; place-items: center; color: var(--text-3); font-size: 22px; }

/* ---------- toast ---------- */

.toasts {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  width: max-content;
  max-width: min(92vw, 460px);
  pointer-events: none;
}
.toast {
  padding: 11px 17px;
  border-radius: var(--r-md);
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  box-shadow: var(--shadow-md);
  animation: rise .18s ease-out;
}
.toast.bad { background: var(--danger); color: #fff; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- mobile ---------- */

.tabbar { display: none; }

@media (max-width: 860px) {
  .topbar .tabs { display: none; }
  main { padding: 18px 14px calc(var(--tabbar-h) + 26px); }

  .tabbar {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 30;
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: saturate(1.6) blur(12px);
    border-top: 1px solid var(--line);
  }
  .tabbar button {
    border: 0;
    background: transparent;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    font-size: 11px;
    font-weight: 550;
    color: var(--text-3);
    cursor: pointer;
  }
  .tabbar button svg { width: 21px; height: 21px; }
  .tabbar button span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 2px; }
  .tabbar button[aria-current="page"] { color: var(--accent); }

  .drawer { width: 100vw; border-radius: 0; animation: slide-up .22s cubic-bezier(.3, .8, .4, 1); }
  @keyframes slide-up { from { transform: translateY(100%); } to { transform: none; } }

  .grid-2, .grid-3 { grid-template-columns: 1fr; gap: 20px; }
  .split { grid-template-columns: 1fr; gap: 14px; }
  .stats-3 { grid-template-columns: 1fr; }
  .stage-bar { grid-template-columns: 110px 1fr 34px; gap: 9px; }
  .sb-label { font-size: 12.5px; }
  .stepper { flex-direction: column; align-items: stretch; gap: 0; }
  .stepper li { flex: none; padding: 5px 0; }
  .stepper li::after { display: none; }
  .stepper .label { font-size: 13px; white-space: normal; }
  .kv { grid-template-columns: 1fr; gap: 10px; }
  .stats { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat b { font-size: 23px; }
  .fail { flex-direction: column; align-items: stretch; }
  .fail .btn { width: 100%; }

  /* table -> cards */
  .cards thead { display: none; }
  .cards, .cards tbody, .cards tr, .cards td { display: block; width: 100%; }
  .cards tr {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    box-shadow: var(--shadow-sm);
    margin-bottom: 10px;
    padding: 4px 2px;
  }
  .cards td {
    border: 0;
    padding: 7px 14px;
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 14px;
    text-align: right;
    min-width: 0;
    overflow-wrap: anywhere;
  }
  .cards td > :last-child { min-width: 0; }
  .cards td::before {
    content: attr(data-label);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-3);
    text-align: left;
    flex: none;
  }
  .cards td[data-label=""] { justify-content: flex-start; text-align: left; }
  .cards td[data-label=""]::before { display: none; }
  .cards td.lead { padding-top: 12px; }
  .cards td:last-child { padding-bottom: 12px; }
  .card { border-radius: 0; border-left: 0; border-right: 0; margin-left: -14px; margin-right: -14px; }
  .filters { gap: 8px; }
  .filters .filter { flex: 1 1 calc(50% - 4px); }
  .filters .filter.grow { flex: 1 1 100%; }
  .filters select { min-width: 0; width: 100%; }
  .filters > .btn { flex: 1 1 100%; }
  .pager { justify-content: space-between; }
  .pager .spacer { flex: 1 1 100%; height: 0; }
  .pager-count { flex: 1 1 100%; }
  .pager .btn { flex: 1; }
  .card.plain { border: 0; background: transparent; box-shadow: none; margin: 0; }
  .card.plain > .body { padding: 0; }
  .table-wrap { overflow: visible; }
  thead th { position: static; }

  .line { grid-template-columns: 1fr 1fr; gap: 10px; }
  .line .sel { grid-column: 1 / -1; }
  .line .line-label { display: block; font-size: 11.5px; font-weight: 600; color: var(--text-3); margin-bottom: 4px; }
  .line .rm { grid-column: 1 / -1; }
  .line .rm .btn { width: 100%; }
  .lines .line {
    padding: 12px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
  }
}

@media (max-width: 480px) {
  .page-head h1 { font-size: 20px; }
  .topbar { padding: 0 14px; gap: 10px; }
  .topbar .who { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

.line-total {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 10px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface-2);
}

.line-total .preview {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 9px;
  margin-bottom: 2px;
  border-bottom: 1px solid var(--line);
}

.preview-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 14px;
}

.preview-row .stack b {
  font-weight: 600;
}

.preview-row .stack span {
  color: var(--text-3);
  font-size: 12px;
}

.preview-row .amounts {
  align-items: flex-end;
  text-align: right;
  white-space: nowrap;
}

.preview-row .amounts b,
.preview-row .amounts span {
  font-variant-numeric: tabular-nums;
}

.preview-row .amounts span {
  color: var(--text-3);
  font-size: 12px;
}

.total-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 14px;
  color: var(--text-2);
}

.total-row b {
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.total-row.strong {
  margin-top: 2px;
  padding-top: 7px;
  border-top: 1px solid var(--line);
  color: var(--text);
  font-weight: 600;
}

.total-row.strong b {
  font-size: 17px;
}

.logo-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.logo-pick {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 128px;
  height: 64px;
  padding: 6px;
  border: 1px dashed var(--line);
  border-radius: var(--r-md);
  background: var(--surface-2);
}

.logo-preview {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.logo-empty {
  color: var(--text-2);
  font-size: 12px;
}
