@font-face {
  font-family: "Archivo";
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url(/fonts/archivo-latin-ext-wght-normal.woff2) format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Archivo";
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url(/fonts/archivo-latin-wght-normal.woff2) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* Page switches cross-fade while the top bar stays put. */
@view-transition { navigation: auto; }
::view-transition-old(root), ::view-transition-new(root) { animation-duration: 120ms; }

/* Layout: variant C. Order list on the left, scan column on the right with the green total at the bottom. */
:root {
  --bg: #EEF1F4;
  --paper: #FFFFFF;
  --ink: #17202A;
  --on-ink: #FFFFFF;
  --muted: #5E6A77;
  --line: #D8DEE4;
  --head: #F8FAFB;
  --field-line: #B9C2CB;
  --placeholder: #8A95A1;
  --green: #178A4C;
  --green-tint: #E5F4EA;
  --red: #C42F29;
  --red-tint: #FCEBEA;
  --mark: #FFE58A;
  --focus: #1F5FD6;
  --amber-tint: #FFF6DA;
  --amber-line: #E0B23C;
  --amber-ink: #5A4300;
  --amber-icon: #8A5A00;
  --nav-ink: #3C4652;
  --kbd-on-ink: #3A4552;
  --green-ink: #0F5E33;
  --red-ink: #8E1F1A;
  --red-line: #E8A9A6;
  --radius: 10px;
  --font: "Archivo", system-ui, -apple-system, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.4;
  font-variant-numeric: tabular-nums;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
/* Fields get the ring on their own edge: it follows the rounded corners and is never cut off by a scrolling panel. */
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--focus); outline-offset: -1px; }
[hidden] { display: none !important; }
/* Names and addresses may contain long unbroken words (codes, links): let them wrap instead of widening the page. */
h1, h2, .name, .r-name, .t-name, .pname, .party p, .picker-list b, .picker-list small, .dropdown .opt span, .who, .doc td { overflow-wrap: anywhere; }

/* ---------- chrome ---------- */
.app { height: 100%; display: flex; flex-direction: column; }
.topbar {
  flex: none; display: flex; align-items: center; gap: 20px; view-transition-name: topbar; position: relative; z-index: 20;
  padding: 0 16px 0 20px; height: 60px; background: var(--paper); border-bottom: 1px solid var(--line);
}
.nav { display: flex; gap: 4px; }
.nav a, .nav-more {
  display: flex; align-items: center; gap: 8px; height: 42px; padding: 0 10px; border-radius: 9px;
  text-decoration: none; color: var(--nav-ink); font-weight: 600; font-size: 15px; white-space: nowrap;
}
.nav svg { width: 20px; height: 20px; flex: none; }
.nav a:hover { background: var(--bg); color: var(--ink); }
.nav a[aria-current] { background: var(--ink); color: var(--on-ink); }
.nav-more { display: none; border: 0; background: transparent; }
kbd { font: 600 11px var(--font); padding: 2px 5px; border-radius: 4px; background: var(--bg); color: var(--muted); }
.nav a[aria-current] kbd, .btn.primary kbd { background: var(--kbd-on-ink); color: var(--on-ink); }
.btn kbd { margin-left: 8px; vertical-align: 2px; }
.topbar .right { margin-left: auto; display: flex; align-items: center; gap: 14px; }
.stack { display: flex; flex-direction: column; line-height: 1.15; white-space: nowrap; }
.stack span { font-size: 12px; color: var(--muted); }
.stack b { font-size: 16px; font-weight: 700; }
.status {
  height: 36px; padding: 0 12px; display: inline-flex; align-items: center; gap: 8px; border-radius: 999px;
  border: 1px solid transparent; font-size: 14px; font-weight: 600; white-space: nowrap;
}
.status i { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.status[data-state="ok"] { background: var(--green-tint); color: var(--green-ink); }
.status[data-state="ok"] i { background: var(--green); }
.status[data-state="paused"] { background: var(--amber-tint); color: var(--amber-ink); border-color: var(--amber-line); }
.status[data-state="paused"] i { background: var(--amber-icon); }
.status[data-state="offline"] { background: var(--red-tint); color: var(--red-ink); border-color: var(--red-line); }
.status[data-state="offline"] i { background: var(--red); }
.menu {
  position: fixed; z-index: 60; left: var(--x, 8px); top: var(--y, 64px); min-width: 230px; padding: 6px;
  display: grid; background: var(--paper); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 14px 40px rgba(23, 32, 42, .18);
}
.menu > * {
  display: flex; align-items: center; gap: 10px; height: 46px; padding: 0 12px; border: 0; border-radius: 8px;
  background: transparent; color: var(--ink); text-decoration: none; font-weight: 600; font-size: 15px; text-align: left;
}
.menu > *:hover { background: var(--bg); }
.menu svg { width: 20px; height: 20px; flex: none; color: var(--muted); }
#menu-sound { display: none; }
/* Under the top bar: the scan field lost its focus, or the server cannot be reached. */
.banner { flex: none; display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 6px 12px 6px 20px; font-size: 15px; }
.banner > svg { width: 20px; height: 20px; flex: none; }
.banner p { margin: 0; flex: 1; min-width: 0; }
.banner .btn { height: 40px; padding: 0 14px; font-size: 14px; white-space: nowrap; }
.banner[data-state="paused"] { background: var(--amber-tint); border-bottom: 1px solid var(--amber-line); }
.banner[data-state="paused"] > svg { color: var(--amber-icon); }
.banner[data-state="paused"] p span { color: var(--amber-ink); }
.banner[data-state="offline"] { background: var(--red-tint); border-bottom: 1px solid var(--red-line); }
.banner[data-state="offline"] > svg { color: var(--red); }
.banner[data-state="offline"] p span, .banner .retry { color: var(--red-ink); }
.banner .retry { font-size: 14px; white-space: nowrap; }

/* Page content stays hidden until its script has filled it in, so it appears in one piece.
   If the script never runs, it is shown anyway after 1.5 s. */
.app:not(.ready) > main { visibility: hidden; animation: reveal 0s linear 1.5s forwards; }
@keyframes reveal { to { visibility: visible; } }
.chip {
  display: inline-grid; place-items: center; width: 40px; height: 40px; padding: 0;
  border: 1px solid var(--line); background: var(--paper); border-radius: 8px; color: var(--ink);
}
.chip svg { width: 18px; height: 18px; }
.chip[aria-pressed="false"] { color: var(--muted); }

/* ---------- buttons ---------- */
.btn {
  height: 52px; padding: 0 22px; border-radius: var(--radius); font-weight: 700; font-size: 17px;
  border: 1px solid var(--line); background: var(--paper);
}
.btn.primary { background: var(--ink); border-color: var(--ink); color: var(--on-ink); }
.btn.danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn.small { height: 44px; font-size: 15px; padding: 0 16px; }
.btn:disabled { opacity: .4; }
.link-btn { border: 0; background: transparent; color: var(--muted); font-weight: 600; padding: 6px 8px; border-radius: 6px; }
.link-btn.danger { color: var(--red); }

/* ---------- scan field ---------- */
.scan-row { display: flex; gap: 8px; }
.scan { position: relative; flex: 1; min-width: 0; }
.cam-btn { width: 56px; height: 56px; flex: none; border: 0; border-radius: var(--radius); background: var(--ink); color: var(--on-ink); display: grid; place-items: center; }
.cam-btn svg { width: 24px; height: 24px; }
/* A form's barcode field with the camera next to it. */
.code-row { display: flex; gap: 8px; }
.code-row input { flex: 1; min-width: 0; }
.code-row .cam-btn { width: 46px; height: 46px; border-radius: 8px; }
.code-row .cam-btn svg { width: 22px; height: 22px; }
/* The camera is for phones and tablets; a computer has the scanner. */
@media (pointer: fine) and (min-width: 1101px) { .cam-btn { display: none; } }
.scan .icon { position: absolute; left: 14px; top: 16px; width: 24px; height: 24px; color: var(--muted); pointer-events: none; }
.scan input {
  width: 100%; height: 56px; padding: 0 16px 0 48px;
  font-size: 20px; border: 2px solid var(--ink); border-radius: var(--radius); background: var(--paper);
}
.scan input::placeholder { color: var(--placeholder); }
.scan.error input { border-color: var(--red); background: var(--red-tint); }
.scan input:focus { border-color: var(--green); outline: none; box-shadow: 0 0 0 3px var(--green-tint); }
.scan input:disabled { background: var(--bg); border-color: var(--line); }
.scan-msg { margin-top: -6px; display: flex; align-items: center; gap: 8px 12px; flex-wrap: wrap; color: var(--red); font-weight: 600; }
.scan-msg button {
  border: 1px solid var(--red); background: var(--paper); color: var(--red);
  border-radius: 8px; padding: 6px 12px; font-weight: 700;
}
.scan-hint { margin-top: -6px; font-size: 13px; color: var(--muted); }
.dropdown {
  position: absolute; z-index: 5; left: 0; right: 0; top: 62px;
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(23, 32, 42, .14); overflow: hidden;
}
.dropdown .opt {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 16px; align-items: center;
  padding: 10px 16px; border-bottom: 1px solid var(--line); cursor: pointer;
}
.dropdown .opt .code { grid-column: 1; grid-row: 2; color: var(--muted); font-size: 14px; }
.dropdown .opt b { grid-row: 1 / span 2; grid-column: 2; }
.dropdown .opt.active, .dropdown .opt:hover { background: var(--green-tint); }
.dropdown mark { background: var(--mark); color: inherit; border-radius: 2px; }
.dropdown .hint { padding: 8px 16px; font-size: 13px; color: var(--muted); background: var(--bg); }

/* ---------- order list ---------- */
.list { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); overflow: auto; min-height: 0; }
.list table { width: 100%; border-collapse: collapse; }
.list th {
  text-align: left; font-size: 13px; font-weight: 600; color: var(--muted);
  padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--head);
  position: sticky; top: 0; z-index: 1;
}
.list td { padding: 10px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.list tr:last-child td { border-bottom: 0; }
.list .num { text-align: right; white-space: nowrap; }
.list td.code { color: var(--muted); font-size: 14px; white-space: nowrap; }
.list td.code.wrap { white-space: normal; min-width: 180px; }
.clients-page td.row-actions { white-space: normal; }
.clients-page td.row-actions button { display: block; margin-left: auto; }
.list td.name { font-weight: 600; }
/* In the order the code sits under the name, so the name gets the width and breaks between words. */
.screen .list td.name { overflow-wrap: break-word; }
.screen .list td.name b { display: block; font-size: 16px; }
.screen .list td.name .code { display: block; margin-top: 2px; font-size: 13px; font-weight: 400; color: var(--muted); }
.screen .list .unit-price { display: none; }
.list tr.fresh td { background: var(--green-tint); }
.qty { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); }
.qty button { width: 34px; height: 34px; border: 0; background: transparent; font-size: 18px; font-weight: 700; color: var(--muted); border-radius: 8px; }
.qty span { min-width: 30px; text-align: center; font-weight: 700; }
.icon-btn { width: 36px; height: 36px; border: 0; background: transparent; color: var(--muted); border-radius: 8px; }
.icon-btn svg { width: 20px; height: 20px; }
.empty { height: 100%; min-height: 220px; display: grid; place-content: center; text-align: center; color: var(--muted); padding: 32px; }
.empty strong { display: block; color: var(--ink); font-size: 20px; margin-bottom: 4px; }

/* ---------- kasa (variant C) ---------- */
.screen { flex: 1; min-height: 0; scrollbar-gutter: stable; padding: 20px; display: grid; gap: 20px; grid-template-columns: 1fr 380px; }
.screen .main { display: grid; grid-template-rows: auto 1fr; gap: 12px; min-height: 0; min-width: 0; }
.order-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.order-head h1 { margin: 0; font-size: 21px; font-weight: 700; }
.order-head .count-text { color: var(--muted); font-size: 14px; }
.client-btn { height: 38px; padding: 0 10px; display: inline-flex; align-items: center; gap: 6px; border-color: var(--field-line); font-size: 14px; font-weight: 600; }
.client-btn svg { width: 17px; height: 17px; }
.client-btn kbd { margin-left: 2px; }
.screen aside { display: flex; flex-direction: column; gap: 14px; min-height: 0; }
.screen aside .spacer { flex: 1; }
.last {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; align-items: center;
  padding: 16px 18px; border-radius: 12px; background: var(--paper); border: 1px solid var(--line);
}
.last > svg, .last .added { display: none; }
.last .lbl { grid-column: 1 / -1; font-size: 13px; color: var(--muted); }
.last .name { font-size: 20px; font-weight: 600; }
.last .price { font-size: 20px; font-weight: 700; white-space: nowrap; }
.last.none .name { color: var(--muted); font-weight: 500; font-size: 18px; }
.actions { display: flex; flex-direction: column; gap: 10px; }
.actions .btn { width: 100%; }
.actions .btn:not(.primary) { height: 46px; font-size: 15px; }
.cancel-btn { color: var(--red); }
a.btn { display: inline-flex; align-items: center; color: inherit; text-decoration: none; }
.issue-btn { display: none; }
.head-clock, .order-head .status { display: none; }
.total { background: var(--green); color: #fff; border-radius: 12px; padding: 18px 22px; }
.total .lbl { font-size: 15px; opacity: .9; }
.total .sum { font-size: 64px; font-weight: 800; line-height: 1.05; letter-spacing: -.02em; white-space: nowrap; }
.total.bump { animation: bump .25s ease-out; }
@keyframes bump { 50% { transform: scale(1.03); } }

/* ---------- products page ---------- */
.products { flex: 1; min-height: 0; scrollbar-gutter: stable; padding: 20px; display: grid; grid-template-columns: 1fr 380px; gap: 20px; align-items: start; overflow: auto; }
.products section { min-width: 0; }
.toolbar { display: flex; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; align-items: center; }
.toolbar input {
  flex: 1; min-width: 200px; height: 46px; padding: 0 14px;
  border: 1px solid var(--field-line); border-radius: var(--radius); background: var(--paper);
}
.count { color: var(--muted); font-size: 14px; margin: 0 0 8px; min-height: 1.4em; }
.pager { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 12px; }
.pager span { color: var(--muted); font-size: 14px; white-space: nowrap; }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.card h2 { margin: 0 0 4px; font-size: 19px; }
.card p { margin: 0 0 16px; color: var(--muted); font-size: 14px; }
.card + .card { margin-top: 16px; }
.field { display: grid; align-content: start; gap: 6px; margin-bottom: 14px; }
.field label { font-weight: 600; font-size: 14px; }
.field input { height: 46px; padding: 0 12px; border: 1px solid var(--field-line); border-radius: 8px; background: var(--paper); }
.field input[aria-invalid="true"] { border-color: var(--red); background: var(--red-tint); }
.field .err { color: var(--red); font-size: 14px; font-weight: 600; }
.form-actions { display: flex; gap: 10px; }
.form-actions .btn { flex: 1; }
.drop {
  display: block; border: 2px dashed var(--field-line); border-radius: var(--radius); padding: 18px; text-align: center; color: var(--muted); cursor: pointer;
}
.drop b { color: var(--ink); }
.drop.over { border-color: var(--green); background: var(--green-tint); }
.preview { margin-top: 14px; display: grid; gap: 10px; }
.preview ul { margin: 0; padding-left: 18px; color: var(--muted); font-size: 14px; max-height: 160px; overflow: auto; }
.preview .stats { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; font-size: 15px; }
.row-actions { white-space: nowrap; text-align: right; }
.list tr.editing td { background: var(--green-tint); }

/* ---------- statistics ---------- */
.stats > .stats-head { grid-column: 1 / -1; }
.segmented {
  display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 3px;
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
}
.segmented button { height: 38px; padding: 0 14px; border: 0; border-radius: 7px; background: transparent; font-weight: 600; color: var(--muted); }
.segmented button[aria-pressed="true"] { background: var(--ink); color: var(--on-ink); }
.receipts { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; align-items: start; }
.receipt { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; display: grid; gap: 12px; }
.receipt header { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: baseline; gap: 4px 12px; padding-bottom: 10px; border-bottom: 1px dashed var(--field-line); }
.receipt h3 { margin: 0; font-size: 16px; }
.receipt time { color: var(--muted); font-size: 14px; white-space: nowrap; }
.receipt time b { color: var(--ink); font-weight: 600; }
.receipt ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.receipt li { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; }
.r-name { font-weight: 600; min-width: 0; }
.r-sum { font-weight: 600; white-space: nowrap; text-align: right; }
.r-meta { grid-column: 1 / -1; color: var(--muted); font-size: 13px; }
.r-code { margin-left: 6px; }
.receipt footer { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding-top: 10px; border-top: 1px dashed var(--field-line); color: var(--muted); font-size: 14px; }
.receipt footer b { color: var(--ink); font-size: 20px; font-weight: 800; }
.more { margin-top: 16px; display: flex; justify-content: center; }
.summary { margin: 12px 0 0; display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.summary div { display: grid; gap: 2px; min-width: 0; }
.summary dt { font-size: 13px; color: var(--muted); }
.summary dd { margin: 0; font-size: 18px; font-weight: 700; white-space: nowrap; }
.summary .s-main { grid-column: 1 / -1; }
.summary .s-main dd { font-size: 34px; font-weight: 800; letter-spacing: -.01em; }
/* The period's figures as tiles: the amount sold stands out, the three counts sit side by side. */
.summary > div { padding: 10px 12px; border-radius: 10px; background: var(--bg); gap: 4px; }
.summary .s-main { padding: 14px 16px; background: var(--green-tint); }
.summary .s-main dt { color: var(--green-ink); font-weight: 600; font-size: 14px; }
.summary .s-main dd { font-size: 38px; font-weight: 700; line-height: 1.1; color: var(--green-ink); letter-spacing: -.01em; }
.summary dd { font-size: 20px; font-weight: 600; }
.top { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; counter-reset: rank; }
.top li { counter-increment: rank; display: grid; grid-template-columns: 22px 1fr auto; gap: 4px 10px; align-items: center; }
.top li::before { content: counter(rank); grid-row: 1; color: var(--muted); font-weight: 700; }
.t-name { grid-column: 2; font-weight: 600; min-width: 0; }
.t-qty { grid-column: 3; font-weight: 700; white-space: nowrap; text-align: right; }
.t-bar { grid-column: 2; height: 6px; border-radius: 3px; background: var(--green-tint); overflow: hidden; }
.t-bar i { display: block; height: 100%; border-radius: 3px; background: var(--green); }
.t-rev { grid-column: 3; color: var(--muted); font-size: 13px; white-space: nowrap; text-align: right; }
.top li.top-empty { display: block; color: var(--muted); }
.segmented.small { margin: 8px 0 14px; }
.segmented.small button { height: 32px; font-size: 14px; padding: 0 10px; }
#anonymous { margin: 12px 0 0; }
.top li.top-empty::before { content: none; }

/* ---------- forms in two columns ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.form-grid .field { min-width: 0; }
.form-grid .field.wide { grid-column: 1 / -1; }
.field input, .field select { width: 100%; min-width: 0; }
.products aside .form-grid { grid-template-columns: 1fr; }
.doc .transport p { margin: 0; }
.doc .table-wrap { overflow-x: auto; }

/* ---------- kasa: buyer and documents ---------- */
.order-head .title { display: flex; align-items: center; gap: 8px 12px; flex-wrap: wrap; min-width: 0; }
.doc-buttons, .sub-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.doc-buttons .btn { padding: 0 10px; }
.sub-buttons .btn { height: 44px; font-size: 15px; padding: 0 10px; }
dialog.wide { width: min(640px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow: auto; }
.picker { display: grid; gap: 8px; margin-bottom: 16px; }
.picker input { height: 46px; padding: 0 12px; border: 1px solid var(--field-line); border-radius: 8px; background: var(--paper); }
/* A fixed height: the dialog keeps its size while the list loads or a search narrows it. */
.picker-list { border: 1px solid var(--line); border-radius: var(--radius); height: 240px; overflow: auto; }
.picker-list button {
  display: grid; gap: 2px; width: 100%; text-align: left; padding: 10px 14px;
  border: 0; border-bottom: 1px solid var(--line); background: var(--paper);
}
.picker-list button:last-child { border-bottom: 0; }
.picker-list button[aria-selected="true"] { background: var(--green-tint); box-shadow: inset 4px 0 0 var(--green); }
.picker-list b { font-weight: 600; }
.picker-list small { color: var(--muted); }
.picker-list .none { padding: 14px; color: var(--muted); }
.picker .link-btn { justify-self: start; color: var(--focus); }
.dialog-error { color: var(--red); font-weight: 600; margin: 0 0 12px; }

/* ---------- settings ---------- */
.narrow { flex: 1; min-height: 0; overflow: auto; scrollbar-gutter: stable; padding: 20px; }
.narrow > * { max-width: 760px; margin-left: auto; margin-right: auto; }
.narrow .card + .card { margin-top: 16px; }
.narrow .form-actions { margin-top: 16px; }
.field select { height: 46px; padding: 0 10px; border: 1px solid var(--field-line); border-radius: 8px; background: var(--paper); font: inherit; }
.field small { color: var(--muted); font-size: 13px; }

/* ---------- receipts with documents ---------- */
.receipt .who { margin: -4px 0 0; font-weight: 600; display: grid; gap: 2px; justify-items: start; }
.receipt .doc-link { color: var(--focus); font-size: 14px; font-weight: 600; text-decoration: none; }
.receipt .docs { display: flex; flex-wrap: wrap; gap: 2px 12px; }
@media (pointer: coarse), (max-width: 1000px) {
  .receipt .doc-link { display: inline-block; padding: 8px 0; }
}

/* ---------- client page ---------- */
.client-link { color: inherit; text-decoration: none; }
.client-link:hover { color: var(--focus); text-decoration: underline; }
.client-page > * { max-width: 960px; }
.client-page .back { margin: 0 auto 12px; }
.client-page .back a { color: var(--focus); font-weight: 600; text-decoration: none; }
.client-title { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.client-title h1 { margin: 0; font-size: 24px; }
.client-title .btn { display: inline-flex; align-items: center; text-decoration: none; color: inherit; }
.details { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; }
.details dt { color: var(--muted); font-size: 14px; }
.details dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.docs-head { display: flex; justify-content: space-between; align-items: center; gap: 8px 16px; flex-wrap: wrap; margin-bottom: 8px; }
.docs-head h2 { margin: 0; }
.docs-head .segmented.small { margin: 0; }
.list .doc-link { color: var(--focus); font-weight: 700; text-decoration: none; }
.client-page .row-actions a { text-decoration: none; }

/* ---------- document (waybill / invoice) ---------- */
.doc-page { flex: 1; min-height: 0; overflow: auto; padding: 20px; }
.doc-toolbar { max-width: 210mm; margin: 0 auto 16px; display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.doc-toolbar a.btn { display: inline-flex; align-items: center; text-decoration: none; color: inherit; }
.doc-toolbar .note { color: var(--muted); font-size: 14px; }
.doc-toolbar .note.nowrap { white-space: nowrap; }
.doc-versions { padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); }
/* The buyer's details changed after issuing: hard to miss, since it decides what gets printed. */
.doc-warning {
  flex-direction: column; align-items: stretch; gap: 12px; padding: 14px 16px;
  border: 1px solid var(--amber-line); border-radius: var(--radius); background: var(--amber-tint);
}
.doc-warning .warn-text { display: flex; gap: 10px; align-items: flex-start; }
.doc-warning svg { width: 22px; height: 22px; flex: none; margin-top: 1px; color: var(--amber-icon); }
.doc-warning b { display: block; font-size: 16px; }
.doc-warning span { display: block; margin-top: 2px; font-size: 14px; color: var(--amber-ink); }
.doc-warning .segmented { align-self: flex-start; border-color: var(--amber-line); }
.doc .client-link { display: inline-block; margin-top: 6px; padding: 6px 0; font-weight: 700; color: var(--focus); text-decoration: none; }
.doc .client-link:hover { text-decoration: underline; }
@media (max-width: 720px) {
  .doc-toolbar > .btn { flex: 1 1 100%; justify-content: center; }
}
@media (pointer: coarse), (max-width: 1000px) {
  .doc .client-link { padding: 12px 0; }
}
.doc {
  max-width: 210mm; margin: 0 auto; background: #fff; color: #111; padding: 16mm 14mm;
  border: 1px solid var(--line); border-radius: 4px; font-size: 13px; line-height: 1.45;
}
.doc h1 { margin: 0; font-size: 20px; letter-spacing: .02em; text-align: center; }
.doc .doc-no { text-align: center; margin: 4px 0 2px; font-size: 14px; }
.doc .doc-dates { text-align: center; color: #444; margin-bottom: 18px; }
.doc .parties { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 14px; }
.doc .party h2 { margin: 0 0 4px; font-size: 12px; color: #555; font-weight: 600; }
.doc .party p { margin: 0; }
.doc .party .pname { font-weight: 700; font-size: 14px; }
.doc .transport { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 16px; margin-bottom: 14px; }
.doc .transport span { color: #555; }
.doc table { width: 100%; border-collapse: collapse; margin: 6px 0 10px; }
.doc th, .doc td { border: 1px solid #999; padding: 5px 6px; vertical-align: top; }
.doc th { background: #f1f1f1; font-weight: 600; font-size: 12px; text-align: left; }
.doc td.n, .doc th.n { text-align: right; white-space: nowrap; }
.doc .totals { margin-left: auto; width: min(320px, 100%); display: grid; grid-template-columns: 1fr auto; gap: 3px 16px; }
.doc .totals b { font-size: 15px; }
.doc .words { margin: 10px 0 0; }
.doc .doc-note { margin: 10px 0 0; }
.doc .signs { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 24px; margin-top: 36px; }
.doc .signs div { border-top: 1px solid #555; padding-top: 4px; font-size: 12px; color: #444; }

.doc table.print-frame { margin: 0; border: 0; table-layout: fixed; } /* stays as wide as the page */
.doc table.print-frame > * > tr > td { border: 0; padding: 0; }
.doc table.print-frame td.pad { height: 0; }

/* On a narrow screen the code and unit columns are hidden; printing always shows them. */
@media screen and (max-width: 720px) {
  .doc .c-code, .doc .c-unit { display: none; }
  .doc th, .doc td { padding: 4px 5px; }
  .doc th.n { white-space: normal; }
}

@page { size: A4; margin: 0; }
@media print {
  html, body { height: auto; background: #fff; }
  .app { height: auto; display: block; }
  .topbar, .doc-toolbar, .toast, .no-print { display: none !important; }
  .doc-page { padding: 0; overflow: visible; }
  .doc { border: 0; border-radius: 0; padding: 0; max-width: none; }
  .doc table.print-frame td.pad { height: 12mm; }
  .doc table.print-frame td.frame { padding: 0 14mm; }
}

/* ---------- dialog & toast ---------- */
dialog {
  border: 0; border-radius: 14px; padding: 24px; width: min(440px, calc(100vw - 32px));
  box-shadow: 0 20px 60px rgba(23, 32, 42, .3); color: var(--ink);
}
dialog::backdrop { background: rgba(23, 32, 42, .45); }
dialog h2 { margin: 0 0 8px; font-size: 21px; }
dialog p { margin: 0 0 20px; color: var(--muted); }
dialog .big { font-size: 34px; font-weight: 800; color: var(--ink); margin: 0 0 20px; }
dialog .form-actions { margin-top: 4px; }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  background: var(--ink); color: var(--on-ink); padding: 12px 18px; border-radius: 10px; font-weight: 600;
  box-shadow: 0 10px 30px rgba(23, 32, 42, .25); max-width: calc(100vw - 32px);
  pointer-events: none;   /* never swallow a tap on the button underneath */
}

/* ---------- login ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(380px, 100%); }
.login .brand { margin-bottom: 12px; }

/* ---------- camera ---------- */
dialog.camera {
  width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; border-radius: 0;
  background: #1C2329; color: #fff; display: flex; flex-direction: column;
}
dialog.camera:not([open]) { display: none; }
.camera header {
  flex: none; display: flex; align-items: center; gap: 10px; padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
}
.camera header b { flex: 1; text-align: center; font-size: 17px; }
.cam-round { width: 44px; height: 44px; border: 0; border-radius: 50%; background: #343D45; color: #fff; display: grid; place-items: center; }
.cam-round svg { width: 20px; height: 20px; }
.cam-round[aria-pressed="true"] { background: #fff; color: #1C2329; }
.cam-view { flex: 1; min-height: 0; position: relative; background: #2B343C; overflow: hidden; }
.cam-view video { width: 100%; height: 100%; object-fit: cover; display: block; }
.cam-frame { position: absolute; left: 50%; top: 45%; width: min(78vw, 340px); aspect-ratio: 16 / 9; transform: translate(-50%, -50%);
  border-radius: 14px; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .35); outline: 4px solid #fff; outline-offset: -4px; }
.cam-frame i { position: absolute; left: 14px; right: 14px; top: 50%; height: 3px; border-radius: 2px; background: #3BD27F; }
/* Above the white strip when it shows, above the phone's home bar when it does not. */
.cam-hint { position: absolute; left: 16px; right: 16px; bottom: calc(18px + env(safe-area-inset-bottom)); margin: 0; text-align: center; font-size: 15px; color: #E6EBEF; text-shadow: 0 1px 3px rgba(0, 0, 0, .5); }
.camera:has(.cam-panel:not(.is-empty)) .cam-hint { bottom: 36px; }
.cam-panel {
  flex: none; display: grid; gap: 12px; padding: 12px 16px calc(16px + env(safe-area-inset-bottom));
  background: var(--paper); color: var(--ink); border-radius: 18px 18px 0 0; margin-top: -18px; position: relative;
}
.cam-panel.is-empty, .cam-footer:empty { display: none; }
.cam-result { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; }
/* Only a message (no price, no button): it stands in the middle. */
.cam-result.solo { justify-content: center; min-height: 64px; }
.cam-result.solo > div { flex: 0 1 auto; }
.cam-result > svg { width: 22px; height: 22px; flex: none; }
.cam-result > div { flex: 1; min-width: 0; display: grid; }
.cam-result span { font-size: 13px; }
.cam-result.ok { background: var(--green-tint); }
.cam-result.ok > svg { color: var(--green); }
.cam-result.bad { background: var(--red-tint); }
.cam-result.bad > svg { color: var(--red); }
.cam-result .btn { flex: none; height: 40px; padding: 0 12px; }
.cam-footer { display: grid; gap: 12px; }
.cam-qty, .cam-total { display: flex; align-items: center; gap: 12px; }
.cam-qty > span:first-child { flex: 1; }
.cam-qty .qty button { width: 44px; height: 44px; }
.cam-total > div { flex: 1; display: grid; line-height: 1.15; }
.cam-total span { font-size: 13px; color: var(--muted); }
.cam-total b { font-size: 24px; color: var(--green-ink); }
.cam-total .btn { padding: 0 28px; }

/* ---------- sheet from below (phone "Išrašyti") ---------- */
dialog.sheet h2 { margin: 0; font-size: 20px; }
dialog.sheet p { margin: 2px 0 0; font-size: 14px; }
.sheet { display: none; }
.sheet[open] { display: flex; flex-direction: column; gap: 10px; }
.sheet-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 4px; }
.sheet-head > div { flex: 1; min-width: 0; }
.sheet-head b { font-size: 22px; color: var(--green-ink); white-space: nowrap; }
.sheet-options { display: grid; gap: 8px; }
.sheet-options .btn { display: flex; align-items: center; gap: 14px; height: 64px; padding: 0 16px; text-align: left; }
.sheet-options svg { width: 26px; height: 26px; flex: none; }
.sheet .sheet-cancel { align-self: center; height: 44px; margin-top: 4px; font-size: 15px; }

/* ---------- price check ---------- */
.price-check > * { max-width: 560px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.page-head h1 { margin: 0; font-size: 22px; }
.page-head a { color: var(--focus); font-weight: 600; text-decoration: none; padding: 8px 0; }
.price-check .scan-row { margin-bottom: 14px; }
.price-card { display: grid; gap: 14px; }
.price-card .p-code { color: var(--muted); font-size: 14px; }
.price-card h2 { margin: 2px 0 0; font-size: 22px; line-height: 1.25; }
.price-card .p-price { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.price-card .p-price b { font-size: 56px; font-weight: 800; line-height: 1; letter-spacing: -.02em; white-space: nowrap; }
.price-card .p-price span { color: var(--muted); font-size: 14px; }
.price-card .btn { width: 100%; }
.price-card .btn.go { background: var(--green); border-color: var(--green); color: #fff; }
.price-card .form-actions { margin-top: 0; }
.recent { margin-top: 16px; }
.recent h2 { margin: 0 0 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.recent ul { list-style: none; margin: 0; padding: 0; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.recent button { width: 100%; min-height: 52px; display: flex; align-items: center; gap: 10px; padding: 8px 12px; border: 0; border-bottom: 1px solid var(--line); background: transparent; text-align: left; }
.recent li:last-child button { border-bottom: 0; }
.recent button span { flex: 1; min-width: 0; }
.picks { display: grid; gap: 8px; }

/* ---------- responsive ---------- */
/* Keyboard hints only where there is a keyboard and room for them. */
@media (max-width: 1280px), (pointer: coarse) { kbd { display: none; } }

/* Tablet and small laptop window: the menu becomes a rail on the left. */
@media (min-width: 721px) and (max-width: 1100px) {
  .app { display: grid; grid-template-columns: 84px minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }
  .topbar {
    grid-column: 1; grid-row: 1 / -1; flex-direction: column; align-items: stretch; gap: 6px;
    width: 84px; height: auto; padding: 12px 8px; border-bottom: 0; border-right: 1px solid var(--line);
  }
  .nav { flex-direction: column; gap: 6px; }
  .nav a { flex-direction: column; justify-content: center; height: 64px; padding: 0; gap: 4px; font-size: 12px; border-radius: 10px; }
  .nav svg { width: 24px; height: 24px; }
  .topbar .right { margin: auto 0 0; flex-direction: column; gap: 6px; }
  .topbar .right .status, .today, .clock { display: none; }
  .topbar .chip { width: 100%; height: 52px; border: 0; }
  .menu { left: 92px; top: auto; bottom: 12px; }
  .banner { grid-column: 2; grid-row: 1; }
  .app > main { grid-column: 2; grid-row: 2; }
  .order-head .status { display: inline-flex; height: 32px; font-size: 13px; }
  .head-clock { display: block; font-size: 16px; }
  .order-head .count-text { display: none; }
  .order-head .status { margin-left: auto; }
  .screen { grid-template-columns: minmax(0, 1fr) 320px; padding: 16px; gap: 16px; }
  .screen .list .c-price { display: none; }
  .screen .list .unit-price { display: inline; }
  .doc-buttons .btn { font-size: 16px; }
  .cancel-btn .long { display: none; }
  .total .sum { font-size: 50px; }
}

@media (max-width: 1000px) {
  .products { grid-template-columns: 1fr; }
  .products aside { order: -1; }
  .clients-page aside { order: 0; }
  .stats > .stats-head { order: -2; }
}

/* Upright tablet: the Kasa in one column, scan field first. */
@media (max-width: 900px) {
  .screen { grid-template-columns: 1fr; grid-auto-rows: max-content; overflow: auto; }
  .screen aside { display: contents; }
  .screen aside .spacer { display: none; }
  .screen .scan-row { order: 0; }
  .screen .scan-msg, .screen .scan-hint { order: 0; margin-top: -8px; }
  .screen .last { order: 1; grid-template-columns: 1fr; }
  .screen .last .price { justify-self: start; }
  .cancel-btn .long { display: inline; }
  .screen .main { order: 2; grid-template-rows: auto auto; }
  .screen .actions { order: 3; }
  .screen .total { order: 4; }
}

/* Phone: tab bar at the bottom, total and "Išrašyti" always in view above it. */
@media (max-width: 720px) {
  .topbar {
    order: 9; height: auto; padding: 0 0 env(safe-area-inset-bottom); gap: 0;
    border-bottom: 0; border-top: 1px solid var(--line);
  }
  .nav { flex: 1; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 0; }
  .nav a, .nav-more {
    flex-direction: column; justify-content: center; height: 62px; padding: 0; gap: 3px;
    font-size: 11px; border-radius: 0; background: transparent; color: var(--nav-ink);
  }
  .nav-more { display: flex; }
  .nav svg { width: 22px; height: 30px; padding: 4px 0; box-sizing: border-box; }
  .nav a:hover { background: transparent; }
  .nav a[aria-current] { background: transparent; color: var(--ink); }
  .nav a[aria-current] svg { width: 52px; padding: 4px 15px; border-radius: 999px; background: var(--ink); color: var(--on-ink); }
  .topbar .right { display: none; }
  #menu-sound { display: flex; }
  .menu { left: auto; right: 8px; top: auto; bottom: calc(70px + env(safe-area-inset-bottom)); }
  .banner { padding: 8px 12px; font-size: 14px; }
  .banner .retry { display: none; }

  .form-grid { grid-template-columns: 1fr; }
  .details { grid-template-columns: 1fr; gap: 0; }
  .details dd { margin-bottom: 8px; }
  .doc .parties, .doc .transport { grid-template-columns: 1fr; }
  .doc { padding: 16px; font-size: 12px; }
  .doc .totals { width: 100%; }
  .products { padding: 12px 16px; }
  .list thead { display: none; }
  .list tr { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; padding: 12px; border-bottom: 1px solid var(--line); }
  .list td { padding: 0; border: 0; }
  .list td.name { grid-column: 1; grid-row: 1; }
  .list td.code { grid-column: 1; grid-row: 2; }
  .list td.c-qty { grid-column: 1; grid-row: 3; }
  .list td.c-price { display: none; }
  .list td.code.wrap { min-width: 0; }
  .list td.c-sum { grid-column: 2; grid-row: 1; }
  .list td.c-del { grid-column: 2; grid-row: 2 / span 2; text-align: right; align-self: end; }
  .list tr.fresh, .list tr.editing { background: var(--green-tint); }
  /* The four periods share one row on a phone; they wrap only on very narrow screens. */
  .segmented { display: flex; width: 100%; }
  .segmented button, .segmented.small button { flex: 1 1 auto; padding: 0 6px; font-size: 14px; white-space: nowrap; }

  /* Kasa */
  .screen { display: flex; flex-direction: column; gap: 10px; padding: 12px 12px 0; }
  .order-head { order: -1; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 0 10px; }
  .order-head .title { display: grid; gap: 0; }
  .order-head h1 { font-size: 18px; }
  .client-btn { height: 36px; padding: 0; border: 0; background: transparent; color: var(--focus); justify-self: start; }
  .client-btn svg { display: none; }
  .order-head .status { display: inline-flex; grid-column: 2; grid-row: 1; align-self: start; height: 32px; padding: 0 10px; font-size: 13px; }
  .order-head .count-text { display: none; }
  .head-clock { display: none; }
  .screen .main { display: contents; }
  .screen .list { order: 2; overflow: visible; border-radius: 10px; }
  .scan-row .cam-btn, .scan input { height: 52px; }
  .scan .icon { top: 14px; }
  .dropdown { top: 58px; }
  .screen .scan-hint { display: none; }
  .screen .last { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 0; border-radius: 10px; background: var(--green-tint); }
  .screen .last.none { display: none; }
  .last > svg { display: block; width: 20px; height: 20px; flex: none; color: var(--green); }
  .last .lbl { display: none; }
  .last .added { display: inline; font-weight: 400; }
  .screen .last .name { flex: 1; min-width: 0; font-size: 14px; }
  .screen .last .price { font-size: 15px; }
  .screen .list tr { grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 6px 8px; padding: 10px 12px; }
  .screen .list td.name { display: contents; }
  .screen .list td.name b { grid-column: 1 / 3; grid-row: 1; font-size: 15px; }
  .screen .list td.name .code { grid-column: 1; grid-row: 2; font-size: 12px; }
  .screen .list .unit-price { display: inline; }
  .screen .list td.c-sum { grid-column: 3; grid-row: 1; align-self: start; }
  .screen .list td.c-qty { grid-column: 2; grid-row: 2; }
  .screen .list td.c-del { grid-column: 3; grid-row: 2; align-self: center; }
  .screen .qty button { width: 44px; height: 44px; }
  .screen .icon-btn { width: 44px; height: 44px; }
  .screen .actions { display: none; }
  .total {
    order: 5; position: sticky; bottom: 0; z-index: 2; margin: auto -12px 0; padding: 12px 12px 12px 16px;
    display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 0 12px;
    border-radius: 0; background: var(--paper); color: var(--ink); border-top: 1px solid var(--line);
  }
  .total .lbl { color: var(--muted); font-size: 13px; opacity: 1; }
  .total .sum { font-size: 30px; color: var(--green-ink); }
  .issue-btn { display: block; grid-column: 2; grid-row: 1 / span 2; height: 54px; padding: 0 26px; border: 0; background: var(--green); color: #fff; }
  dialog.sheet {
    margin: auto 0 0; width: 100%; max-width: 100%; border-radius: 18px 18px 0 0;
    padding: 10px 16px calc(20px + env(safe-area-inset-bottom));
  }
  dialog.sheet::before { content: ""; align-self: center; width: 40px; height: 5px; border-radius: 3px; background: var(--field-line); }
  .narrow { padding: 12px 16px; }
}
@media (max-width: 380px) {
  .segmented { gap: 0; }
  .segmented button, .segmented.small button { padding: 0 4px; font-size: 13px; }
  .issue-btn { padding: 0 18px; }
}
@media (prefers-reduced-motion: reduce) {
  .total.bump { animation: none; }
  ::view-transition-old(root), ::view-transition-new(root) { animation: none; }
}

/* ---------- product and client lists: columns, sorting, editing a row in place ---------- */
/* top/left 0: left where it stands, a hidden label far down a scrolling list would make the whole page
   scrollable (and on an iPhone the page would then stay moved up after the keyboard). */
.visually-hidden { position: absolute; top: 0; left: 0; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.narrow-only { display: none; }
.list-page .toolbar { margin-bottom: 12px; }
/* Prekės and Klientai: the search (with "Tikrinti kainą" next to it), then the count and the actions. */
.tb-search { flex: 1 1 360px; display: flex; gap: 8px; min-width: 0; }
.tb-search .search-box { min-width: 0; }
.tb-actions { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.list-page .toolbar .btn.small { height: 46px; }   /* level with the search field */
#excel-btn .tb-chevron { width: 16px; height: 16px; }
.list-page .count { margin: 0; white-space: nowrap; min-height: 0; }
.search-box {
  flex: 1; min-width: 200px; height: 46px; padding: 0 14px; display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--field-line); border-radius: var(--radius); background: var(--paper);
}
.search-box:focus-within { border-color: var(--focus); box-shadow: 0 0 0 3px rgba(31, 95, 214, .15); }
.search-box svg { width: 18px; height: 18px; flex: none; color: var(--muted); }
.toolbar .search-box input { flex: 1; min-width: 0; height: 100%; padding: 0; border: 0; outline: none; background: transparent; }
.toolbar .btn.small { display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; }
.toolbar .btn.small svg { width: 18px; height: 18px; flex: none; }
.clients-page { grid-template-columns: minmax(0, 1fr); }
.products-page .toolbar .add-btn { display: none; }
.data-table .sub-phone a { color: var(--focus); font-weight: 600; text-decoration: none; }
.products-page aside { position: sticky; top: 0; }
/* No room for the form beside the list: "Nauja prekė" opens it in the panel, as "Naujas klientas" does. */
@media (max-width: 1000px) {
  .products-page aside { display: none; }
  .products-page .toolbar .add-btn { display: inline-flex; }
}

.menu-anchor { position: relative; }
.drop-menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; width: 300px; padding: 6px; display: grid;
  background: var(--paper); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 14px 40px rgba(23, 32, 42, .18);
}
.drop-menu > * {
  display: flex; gap: 12px; padding: 10px 12px; border: 0; border-radius: 8px; background: transparent;
  color: var(--ink); text-decoration: none; text-align: left; font-size: 15px;
}
.drop-menu > *:hover { background: var(--bg); }
.drop-menu svg { width: 20px; height: 20px; flex: none; margin-top: 1px; color: var(--muted); }
.drop-menu span { display: grid; }
.drop-menu small { font-size: 13px; color: var(--muted); }

/* The header stays in view while the page scrolls (the list clips, it does not scroll by itself). */
.list.data { overflow: clip; }
.data-table { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: 14px; }
.data-table th {
  /* The page has 20px of padding at the top; the header sticks above it, so no row shows through. */
  position: sticky; top: -20px; z-index: 2; height: 44px; padding: 0;
  background: var(--head); border-bottom: 2px solid var(--line); text-align: left;
}
.th-sort {
  width: 100%; height: 44px; padding: 0 12px; display: flex; align-items: center; gap: 5px;
  border: 0; background: transparent; font-size: 13px; font-weight: 600; color: var(--muted); text-align: left;
}
.data-table th.c-name .th-sort { padding-left: 18px; }
.data-table th.num .th-sort { justify-content: flex-end; }
.th-sort:hover, .data-table th[aria-sort] .th-sort { color: var(--ink); }
.th-sort svg { width: 12px; height: 12px; flex: none; }
.data-table td {
  height: 52px; padding: 0 12px; border-bottom: 1px solid #E3E8ED; vertical-align: middle;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:nth-child(even) td { background: var(--head); }
.data-table tbody tr:not(.edit-row):hover td { background: #EEF3F7; }
.data-table td.c-name { padding-left: 18px; font-weight: 600; font-size: 15px; }
/* A <b> inside an already bold cell would turn "bolder" (900), which is hard to read. */
.data-table td.c-name b, .list td.name b { font-weight: inherit; }
.data-table td.c-price b { font-weight: 700; }
.data-table td.c-code, .data-table td.c-vat { color: var(--nav-ink); }
.data-table td.c-price { font-size: 15px; }
.data-table .none { color: var(--placeholder); }
.data-table .sub, .data-table .sub-phone, .data-table .m-code, .data-table .row-go { display: none; }
.data-table td.c-act { padding: 0 6px; text-align: right; overflow: visible; }
.data-table .row-edit, .data-table .row-del { display: inline-grid; place-items: center; vertical-align: middle; }
.row-edit { width: 40px; height: 40px; color: var(--nav-ink); }
.row-edit svg { width: 20px; height: 20px; }
.row-del { width: 34px; height: 34px; color: var(--red); }
.row-del svg { width: 16px; height: 16px; }
.row-edit:hover, .row-del:hover { background: var(--bg); }
.clients-table .w-name { width: 18%; }
.clients-table .w-code { width: 9%; }
.clients-table .w-vat { width: 11%; }
.clients-table .w-addr { width: 17%; }
.clients-table .w-contact { width: 10%; }
.clients-table .w-email { width: 15%; }
.clients-table .w-phone { width: 11%; }
.clients-table .w-act { width: 9%; }
.products-table .w-code { width: 18%; }
.products-table .w-price { width: 12%; }
.products-table .w-act { width: 104px; }

.data-table tbody tr.edit-row td {
  height: auto; padding: 0; white-space: normal; overflow: visible;
  background: #F2FAF5; border-top: 2px solid var(--green); border-bottom: 2px solid var(--green);
}
.data-table tbody tr.edit-row:has(.has-error) td { background: #FDF3F2; border-color: var(--red); }
.data-table tbody tr.edit-row:has(.unsaved) td { background: var(--amber-tint); border-color: var(--amber-line); }
.row-form { padding: 8px 4px 8px 0; display: grid; gap: 8px; }
.rf-main { display: grid; align-items: center; }
.clients-form .rf-main { grid-template-columns: 18% 9% 11% 17% 10% 15% 11% 9%; }
.products-form .rf-main { grid-template-columns: 18% minmax(0, 1fr) 12% 104px; }
.rf-field { display: block; min-width: 0; padding: 0 4px; }
.rf-main > .rf-field:first-child { padding-left: 10px; }
.rf-label { display: none; }   /* the column headers above name the fields */
.rf-field input {
  width: 100%; height: 40px; padding: 0 8px; border: 1px solid var(--field-line); border-radius: 7px;
  background: var(--paper); font-size: 14px;
}
.rf-field input:focus { outline: none; border-color: var(--green); box-shadow: 0 0 0 3px var(--green-tint); }
.rf-field input[aria-invalid="true"] { border: 2px solid var(--red); }
.rf-main .f-name input { font-weight: 600; font-size: 15px; }
.products-form .f-price input { text-align: right; font-weight: 700; font-size: 15px; }
.rf-act { display: flex; align-items: center; justify-content: flex-end; gap: 4px; }
.rf-save { width: 40px; height: 40px; border: 0; border-radius: 8px; background: var(--green); color: #fff; display: grid; place-items: center; }
.rf-save svg { width: 20px; height: 20px; }
.rf-cancel { width: 34px; height: 34px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); color: var(--nav-ink); display: grid; place-items: center; }
.rf-cancel svg { width: 14px; height: 14px; }
.rf-extra { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; padding-left: 10px; }
.rf-extra .rf-field { display: flex; align-items: center; gap: 8px; padding: 0; }
.rf-extra .rf-label { display: inline; font-size: 13px; font-weight: 600; color: var(--nav-ink); white-space: nowrap; }
.rf-extra input { width: 300px; height: 36px; }
.rf-hint { margin: 0; padding-left: 10px; font-size: 13px; color: var(--muted); }
.products-form .rf-hint { display: none; }
.rf-error { margin: 0; padding-left: 10px; display: flex; align-items: center; gap: 6px; color: #A12620; font-size: 14px; font-weight: 600; }
.rf-error svg { width: 16px; height: 16px; flex: none; }
.rf-unsaved { margin: 0 4px 0 10px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 10px; font-size: 14px; color: var(--amber-ink); }
.rf-unsaved > svg { width: 18px; height: 18px; flex: none; color: var(--amber-icon); }
.rf-unsaved > span { flex: 1 1 300px; }
.rf-unsaved b { color: var(--ink); }
.rf-unsaved .btn { height: 38px; }

/* Panel on the right: a new client (and, on a phone, editing as a sheet from below). */
dialog.panel {
  margin: 0 0 0 auto; width: min(460px, 100vw); height: 100dvh; max-height: 100dvh; border-radius: 0;
  padding: 22px 24px; box-shadow: -16px 0 40px rgba(23, 32, 42, .16);
}
dialog.panel[open] { display: flex; flex-direction: column; }
dialog.panel::backdrop { background: rgba(23, 32, 42, .25); }
dialog.panel > form { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: auto; }
dialog.panel .card { border: 0; padding: 0; border-radius: 0; }
dialog.panel .form-actions { margin-top: auto; padding-top: 16px; }
.panel-head { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 14px; }
.panel-head > div { flex: 1; min-width: 0; }
.panel-head h2 { margin: 0; font-size: 21px; }
.panel-head p { margin: 2px 0 0; font-size: 14px; color: var(--muted); }
.panel-close { width: 40px; height: 40px; background: var(--bg); color: var(--ink); display: grid; place-items: center; }
.panel-close svg { width: 18px; height: 18px; }
/* Inside the button: at the panel's edge an outer ring is cut off by the scrolling form. */
.panel-close:focus-visible { outline-offset: -3px; }
.panel-delete { align-self: center; display: inline-flex; align-items: center; gap: 6px; height: 44px; margin-top: 8px; padding: 0 14px; font-size: 15px; }
.panel-delete svg { width: 16px; height: 16px; }
.panel-delete:hover { background: var(--red-tint); }

/* ---------- settings: danger zone ---------- */
.danger-zone { padding: 0; overflow: hidden; border-color: var(--red-line); }
.dz-head {
  width: 100%; min-height: 60px; padding: 10px 18px; display: flex; align-items: center; gap: 12px;
  border: 0; background: var(--red-tint); color: var(--ink); text-align: left;
}
.dz-head[aria-expanded="true"] { border-bottom: 1px solid #F0C2BF; }
.dz-head > svg { width: 22px; height: 22px; flex: none; color: var(--red); }
.dz-head span { flex: 1; display: grid; }
.dz-head b { font-size: 17px; }
.dz-head small { font-size: 13px; color: var(--red-ink); }
.dz-head .dz-chevron { width: 20px; height: 20px; color: var(--red-ink); transition: transform .15s; }
.dz-head[aria-expanded="true"] .dz-chevron { transform: rotate(180deg); }
.dz-row { padding: 16px 18px; display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; border-bottom: 1px solid #F0C2BF; }
.dz-row:last-child { border-bottom: 0; }
.dz-row.open { background: #FFFAFA; }
.dz-text { flex: 1 1 300px; display: grid; gap: 2px; }
.dz-text span { font-size: 14px; color: var(--muted); }
.btn.dz-open { color: var(--red); border-color: var(--red); }
.dz-confirm { flex: 1 1 100%; display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; }
.dz-confirm .field { flex: 1 1 260px; margin: 0; }
.dz-confirm input { border: 2px solid var(--red); }

/* ---------- price check: the way back ---------- */
.price-check .page-head { flex-direction: column; align-items: flex-start; gap: 10px; }
.price-check .page-head .back-btn { display: inline-flex; align-items: center; gap: 6px; padding: 0 14px 0 10px; color: var(--ink); text-decoration: none; }
.back-btn svg { width: 18px; height: 18px; }
.hint-line { margin-top: -6px; margin-bottom: 14px; font-size: 13px; color: var(--muted); }   /* sides stay auto: in the column */
@media (pointer: coarse) { .hint-line { display: none; } }

/* Laptop and tablet: related values share a column on two lines, so everything stays visible. */
@media (max-width: 1280px) {
  /* The cells stay (so the columns keep their places) but take no room. */
  .clients-table td.c-vat, .clients-table td.c-email, .clients-table td.c-phone,
  .clients-table th.c-vat, .clients-table th.c-email, .clients-table th.c-phone { padding: 0; font-size: 0; visibility: hidden; }
  .clients-table .w-vat, .clients-table .w-email, .clients-table .w-phone { width: 0; }
  .clients-table .w-name { width: 25%; }
  .clients-table .w-code { width: 15%; }
  .clients-table .w-addr { width: 22%; }
  .clients-table .w-contact { width: 28%; }
  .clients-table .w-act { width: 10%; }
  .clients-table td:not(.c-vat):not(.c-email):not(.c-phone) { white-space: normal; height: 62px; padding-top: 8px; padding-bottom: 8px; overflow-wrap: anywhere; }
  .clients-table .sub { display: block; }
  .clients-table .sub-phone { display: inline; }
  .clients-table .wide-only { display: none; }
  .clients-table .narrow-only { display: inline; }
  .clients-form .rf-main { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px 0; }
  .clients-form .rf-label { display: block; margin: 0 0 3px 2px; font-size: 12px; font-weight: 600; color: var(--nav-ink); }
  .clients-form .rf-main > .rf-field { padding: 0 4px; }
  .clients-form .rf-main > .rf-field:nth-child(4n + 1) { padding-left: 10px; }
  .clients-form .rf-act { align-self: end; }
}

/* Phone: lists become cards; a tap opens the item in a sheet from below. */
@media (max-width: 720px) {
  /* Two rows, the same on both lists: search (+ price check), then the count and "Nauja prekė" / "Naujas klientas" on the right. */
  .list-page .toolbar { flex-direction: column; align-items: stretch; gap: 8px; }
  .tb-search { flex: none; }
  .tb-actions { margin-left: 0; gap: 8px; position: relative; }
  .list-page .count { margin-right: auto; }
  .tb-label, .tb-chevron { display: none; }
  .tb-price, #excel-btn { width: 46px; padding: 0; justify-content: center; flex: none; }
  /* The Excel menu opens under the whole row (from its button it would run off the left edge). */
  .tb-actions .menu-anchor { position: static; }
  .tb-actions .drop-menu { left: 0; right: 0; width: auto; }
  .clients-table .c-code .sub.is-empty { display: none; }
  .products-page aside { display: none; }
  .data-table, .data-table tbody { display: block; }
  .data-table colgroup, .data-table thead { display: none; }
  .list .data-table tr { display: grid; padding: 12px 6px 12px 14px; border-bottom: 1px solid #E3E8ED; }
  .list .data-table tbody tr:last-child { border-bottom: 0; }
  .list .data-table td { display: block; height: auto; padding: 0; border: 0; white-space: normal; overflow: visible; background: none; }
  .list .data-table tbody tr:nth-child(even) td, .data-table tbody tr:not(.edit-row):hover td { background: none; }
  .clients-table tr { grid-template-columns: minmax(0, 1fr) auto; gap: 3px 6px; }
  .list .clients-table td { grid-column: 1; }
  .list .clients-table td:not(.c-vat):not(.c-email):not(.c-phone) { height: auto; padding: 0; }   /* not the tablet's 62px rows */
  .list .clients-table td.c-name { font-size: 16px; }
  .list .clients-table td.c-code { font-size: 13px; color: var(--muted); }
  .clients-table .c-code .v::before { content: "Įm. k. "; }
  .clients-table .c-code .sub { display: inline; }
  .clients-table .c-code .sub::before { content: "· PVM k. "; }
  .clients-table .c-contact .sub-phone { display: inline; }
  .clients-table .c-contact .sub-phone a { font-weight: 600; text-decoration: none; }
  .clients-table .c-contact .sub { display: block; font-size: 13px; color: var(--nav-ink); overflow-wrap: anywhere; }
  .list .clients-table td.c-vat, .list .clients-table td.c-email, .list .clients-table td.c-phone { display: none; visibility: visible; }
  /* Edit at the top of the card, delete at the bottom: apart, so a tap on one never hits the other. */
  .list .clients-table td.c-act { grid-column: 2; grid-row: 1 / span 4; display: flex; flex-direction: column; justify-content: space-between; align-items: center; padding: 0; }
  .clients-table .row-edit, .clients-table .row-del { flex: none; width: 44px; height: 44px; }
  .products-table tr { grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; gap: 0 8px; cursor: pointer; }
  .list .products-table td.c-code { display: none; }
  .list .products-table td.c-name { padding: 0; }
  .products-table .m-code { display: block; font-size: 12px; font-weight: 400; color: var(--muted); }
  .list .products-table td.c-price { display: block; grid-column: 2; grid-row: 1; }
  .list .products-table td.c-act { grid-column: 3; grid-row: 1; padding: 0; }
  .products-table .row-edit, .products-table .row-del { display: none; }
  .products-table .row-go { display: block; width: 18px; height: 18px; color: var(--placeholder); }
  dialog.panel {
    margin: auto 0 0; width: 100%; max-width: 100%; height: auto; max-height: 92dvh;
    border-radius: 18px 18px 0 0; padding: 10px 16px calc(20px + env(safe-area-inset-bottom));
  }
  dialog.panel::before { content: ""; flex: none; align-self: center; width: 40px; height: 5px; margin-bottom: 10px; border-radius: 3px; background: var(--field-line); }
  .price-check .page-head { flex-direction: row; justify-content: flex-start; align-items: center; gap: 4px; }
  .hint-line { display: none; }
  .price-check .back-btn { width: 44px; height: 44px; margin-left: -10px; padding: 0; justify-content: center; border: 0; background: transparent; }
  .price-check .back-btn span { display: none; }
  .price-check .back-btn svg { width: 22px; height: 22px; }
}

/* ---------- another client already has this name, code or address ---------- */
.dup, .rf-dup p {
  display: flex; align-items: flex-start; gap: 6px; margin: 0; padding: 5px 8px; font-size: 13px; line-height: 1.35;
  color: var(--amber-ink); background: var(--amber-tint); border: 1px solid var(--amber-line); border-radius: 6px;
}
.dup svg, .rf-dup svg { width: 15px; height: 15px; flex: none; margin-top: 1px; color: var(--amber-icon); }
.dup a, .rf-dup a { color: inherit; font-weight: 700; }
.dup-move { padding: 0; border: 0; background: none; font: inherit; font-weight: 700; color: inherit; text-decoration: underline; cursor: pointer; }
.rf-dup { display: grid; gap: 4px; margin: 0 4px 0 10px; }

/* The client panel fits a laptop screen without scrolling: tighter fields than the big forms. */
dialog.panel { padding-block: 18px; }
dialog.panel .panel-head { margin-bottom: 10px; }
dialog.panel .panel-head h2 { font-size: 20px; }
dialog.panel .field { gap: 4px; margin-bottom: 10px; }
dialog.panel .field label { font-size: 13px; }
dialog.panel .field input { height: 40px; }
dialog.panel .code-row .cam-btn { width: 40px; height: 40px; }
dialog.panel .form-grid { gap: 0 10px; }
dialog.panel .form-actions { padding-top: 8px; }
dialog.panel .form-actions .btn { height: 46px; font-size: 16px; }

/* A heading that receives the focus when a dialog opens shows no ring (it is not a control). */
[tabindex="-1"]:focus { outline: none; }
#import-dialog .panel-head { margin-bottom: 14px; }
#import-dialog .panel-head p { margin: 4px 0 0; }

/* Under the client picker: how many are shown out of how many. */
.picker-note { margin: -2px 2px 0; min-height: 1.35em; font-size: 13px; color: var(--muted); }
.picker-list mark { background: var(--mark); color: inherit; border-radius: 2px; }
