/* Oriana ERP v2: the look, exactly as DESIGN.md sets it out ("Studio, done the Apple way").
   One accent (blue). Green = done / money in. Red = needs you / money out. Nothing else uses them. */
:root {
  --bg: #F5F5F7;
  --card: #FFFFFF;
  --hair: #E5E5EA;
  --text: #1D1D1F;
  --text2: #6E6E73;
  --text3: #86868B;
  --accent: #0071E3;
  --accent-dark: #0058B0;
  --good: #1F7A3A;
  --bad: #D70015;
  --warn: #C93400;
  --side: #F0F0F2;
  --side-line: #E2E2E6;
  --field: #D2D2D7;
  --ring: 0 0 0 1px rgba(0, 0, 0, 0.04);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", system-ui,
               "Helvetica Neue", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
  font-size: 15px;
  line-height: 1.3;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-dark); }
h1 { margin: 0; font-size: 32px; font-weight: 600; letter-spacing: -0.02em; }
h2 { margin: 0; font-size: 19px; font-weight: 600; letter-spacing: -0.01em; }
p { margin: 0; }
.good { color: var(--good); }
.bad { color: var(--bad); }
.warn { color: var(--warn); }
.muted { color: var(--text2); }
.faint { color: var(--text3); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.right { text-align: right; }
.hidden { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- frame: sidebar on the left, content on the right */
.shell { display: flex; min-height: 100vh; }
.side {
  flex: 0 0 236px; width: 236px; background: var(--side); border-right: 1px solid var(--side-line);
  padding: 18px 12px 16px; display: flex; flex-direction: column; gap: 2px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; flex-direction: column; gap: 10px; padding: 0 6px 14px; }
.logo { background: #FFFFFF; border-radius: 12px; padding: 10px 14px; display: flex; justify-content: center; }
.logo img { width: 160px; max-width: 100%; height: auto; display: block; }
.company { display: flex; flex-direction: column; line-height: 1.15; padding: 0 4px; }
.company b { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.company span { font-size: 12px; color: var(--text2); }
.search {
  display: flex; align-items: center; gap: 8px; height: 34px; padding: 0 10px; margin: 0 0 12px;
  border-radius: 9px; background: #E4E4E8;
}
.search input {
  flex: 1 1 auto; min-width: 0; border: none; background: transparent; font: inherit; font-size: 14px;
  color: var(--text); outline: none; -webkit-appearance: none;
}
.search input::placeholder { color: var(--text3); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px; height: 36px; padding: 0 10px; border-radius: 8px;
  color: var(--text); font-size: 14px;
}
.nav a:hover { background: rgba(0, 0, 0, 0.05); color: var(--text); }
.nav a[aria-current="page"] { background: var(--accent); color: #FFFFFF; font-weight: 500; }
.nav a.later { color: var(--text2); }
.nav a.later .tile { opacity: 0.45; }
.nav a[aria-current="page"].later { color: #FFFFFF; }
.nav a[aria-current="page"].later .tile { opacity: 1; }
.tile {
  width: 26px; height: 26px; border-radius: 7px; flex: 0 0 26px; display: inline-flex;
  align-items: center; justify-content: center;
}
.nothing { padding: 8px 10px; font-size: 13px; color: var(--text3); }
.who { margin-top: auto; padding: 14px 6px 0; border-top: 1px solid var(--side-line); position: relative; }
.who summary {
  list-style: none; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  height: 40px; padding: 0 10px; border-radius: 9px; cursor: pointer; font-size: 14px;
}
.who summary::-webkit-details-marker { display: none; }
.who summary:hover { background: rgba(0, 0, 0, 0.05); }
.who .me { display: flex; align-items: center; gap: 10px; min-width: 0; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%; background: #D9E6F7; color: #1C4F8A; flex: 0 0 30px;
  display: inline-flex; align-items: center; justify-content: center; font-weight: 600; font-size: 12px;
}
.who .me div { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.who .me b { font-weight: 500; }
.who .me span { font-size: 12px; color: var(--text2); }
.menu {
  position: absolute; left: 6px; right: 6px; bottom: calc(100% - 8px); background: #FFFFFF; border-radius: 12px;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.06), 0 10px 30px rgba(0, 0, 0, 0.14); padding: 6px; z-index: 30;
}
.menu .label { padding: 8px 10px 4px; font-size: 12px; color: var(--text3); }
.menu button {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; width: 100%; min-height: 36px;
  padding: 6px 10px; border: none; background: transparent; border-radius: 8px; font: inherit; font-size: 14px;
  color: var(--text); text-align: left; cursor: pointer;
}
.menu button:hover { background: rgba(0, 0, 0, 0.05); }
.menu button small { display: block; font-size: 12px; color: var(--text2); }
.menu hr { border: none; border-top: 1px solid var(--hair); margin: 6px 0; }
.topbar { display: none; }

.main {
  flex: 1 1 auto; min-width: 0; padding: 28px 32px 40px; display: flex; flex-direction: column; gap: 20px;
}
.head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 14px; }
.head .titles { display: flex; flex-direction: column; gap: 3px; }
.head .sub { font-size: 15px; color: var(--text2); }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.pill {
  display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 14px; border-radius: 980px;
  background: #FFFFFF; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.06); font-size: 14px; color: var(--text2);
}
.pill b { font-weight: 500; color: var(--text); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; height: 36px; padding: 0 16px;
  border-radius: 980px; border: 1px solid #C9C9CE; background: #FFFFFF; color: var(--text); font: inherit;
  font-size: 14px; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: #FAFAFA; color: var(--text); }
.btn.primary { border: none; padding: 0 18px; background: var(--accent); color: #FFFFFF; font-weight: 500; }
.btn.primary:hover { background: var(--accent-dark); }
.btn:focus-visible, input:focus-visible, .who summary:focus-visible, .nav a:focus-visible {
  outline: 3px solid rgba(0, 113, 227, 0.35); outline-offset: 1px;
}

/* ---------- cards */
.card { background: var(--card); border-radius: 16px; box-shadow: var(--ring); min-width: 0; }
.cardhead { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 18px 20px 10px; }
.cardhead a, .cardhead .side-note { font-size: 14px; }
.pad { padding: 0 20px 18px; }
.lead { padding: 0 20px 14px; color: var(--text2); font-size: 14px; }

/* key numbers: ONE card, split into columns by hairlines */
.stats {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px; background: var(--hair);
  border-radius: 16px; overflow: hidden; box-shadow: var(--ring);
}
.stat { background: #FFFFFF; padding: 18px 20px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.stat .k { font-size: 13px; color: var(--text2); }
.stat .v { font-size: 26px; font-weight: 600; letter-spacing: -0.02em; line-height: 1.15; overflow-wrap: anywhere; }
.stat .v.later { color: var(--text2); }
.stat .n { font-size: 13px; color: var(--text3); }

.two { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 20px; align-items: start; }

/* lists: hairline rows */
.row {
  display: flex; align-items: center; gap: 14px; padding: 13px 20px; border-bottom: 1px solid var(--hair);
  color: var(--text);
}
.row:last-child { border-bottom: none; }
.row .grow { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
.row .grow b { font-weight: 500; }
.row .grow span, .row .detail { font-size: 13px; color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .amount { font-weight: 500; white-space: nowrap; }
.row .when { flex: 0 0 68px; font-size: 13px; color: var(--text3); }
.row .status { font-size: 13px; font-weight: 500; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 8px; background: var(--warn); }
.dot.red { background: var(--bad); }
.balance {
  display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1.5fr) 124px 72px; gap: 14px;
  align-items: center; padding: 13px 20px; border-bottom: 1px solid var(--hair);
}
.balance:last-child { border-bottom: none; }
.balance .name { display: flex; flex-direction: column; min-width: 0; }
.balance .name b { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.balance .name span { font-size: 13px; color: var(--text2); }
.balance .detail { font-size: 14px; color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.balance .amount { font-weight: 500; text-align: right; white-space: nowrap; }
.balance .status { font-size: 13px; font-weight: 500; text-align: right; white-space: nowrap; }
.foot { padding: 10px 20px 14px; font-size: 13px; color: var(--text3); }

/* tables wider than the screen scroll inside their card, never the page */
.scroll { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; }
table.grid th {
  text-align: left; font-size: 13px; font-weight: 400; color: var(--text2); padding: 8px 20px;
  border-bottom: 1px solid var(--hair); white-space: nowrap;
}
table.grid td { padding: 12px 20px; border-bottom: 1px solid var(--hair); vertical-align: top; }
table.grid tr:last-child td { border-bottom: none; }
table.grid .right { text-align: right; }

/* ---------- forms */
.fields { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label, .field .label { font-size: 13px; color: var(--text2); }
input[type="text"], input[type="password"] {
  height: 38px; border: 1px solid var(--field); border-radius: 9px; padding: 0 12px; font: inherit;
  color: var(--text); background: #FFFFFF; width: 100%; -webkit-appearance: none;
}
input[type="text"]:focus, input[type="password"]:focus { border-color: var(--accent); outline: 3px solid rgba(0, 113, 227, 0.2); }
.seg { display: inline-flex; background: #E4E4E8; border-radius: 9px; padding: 2px; gap: 2px; align-self: flex-start; }
.seg label { position: relative; cursor: pointer; }
.seg input { position: absolute; opacity: 0; inset: 0; }
.seg span {
  display: inline-flex; align-items: center; height: 32px; padding: 0 16px; border-radius: 7px; font-size: 14px;
  color: var(--text);
}
.seg input:checked + span { background: #FFFFFF; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.14); font-weight: 500; }
.seg input:focus-visible + span { outline: 3px solid rgba(0, 113, 227, 0.35); }
.formrow { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.message { font-size: 14px; }
.kv { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 16px; }

/* ---------- the login screens (no sidebar) */
.door { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.door .card { width: 100%; max-width: 400px; padding: 28px 28px 26px; display: flex; flex-direction: column; gap: 18px; }
.door .logo { padding: 6px 0 2px; }
.door .logo img { width: 200px; }
.door h1 { font-size: 26px; text-align: center; }
.door .sub { text-align: center; color: var(--text2); margin-top: -10px; }
.door form { display: flex; flex-direction: column; gap: 14px; }
.door .btn { height: 44px; font-size: 15px; }
.door .under { text-align: center; font-size: 14px; }

/* ---------- narrower screens */
@media (max-width: 1180px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .two { grid-template-columns: minmax(0, 1fr); }
  .fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- phone: the sidebar becomes a top bar with a menu */
@media (max-width: 700px) {
  .shell { flex-direction: column; }
  .topbar {
    display: flex; align-items: center; justify-content: space-between; gap: 10px; position: sticky; top: 0;
    z-index: 20; height: 56px; padding: 0 8px 0 16px; background: var(--side); border-bottom: 1px solid var(--side-line);
  }
  .topbar .company { padding: 0; }
  .menu-btn {
    width: 44px; height: 44px; border: none; background: transparent; border-radius: 10px; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center; color: var(--text);
  }
  .side {
    display: none; position: fixed; top: 56px; left: 0; right: 0; bottom: 0; width: auto; height: auto;
    z-index: 19; border-right: none; padding: 14px 12px 20px;
  }
  body.menu-open .side { display: flex; }
  body.menu-open { overflow: hidden; }
  .side .brand { display: none; }      /* the top bar already names the company */
  .nav a { height: 44px; font-size: 16px; }
  .who summary { height: 48px; }
  .menu button { min-height: 44px; }
  .main { padding: 20px 16px 32px; gap: 16px; }
  h1 { font-size: 28px; }
  .stats { grid-template-columns: minmax(0, 1fr); }
  .fields { grid-template-columns: minmax(0, 1fr); }
  .btn { height: 44px; padding: 0 18px; font-size: 15px; }
  .balance { grid-template-columns: minmax(0, 1fr) auto; row-gap: 2px; }
  .balance .detail { display: none; }
  .balance .status { grid-column: 2; }
  .balance .name { grid-row: span 2; }
  .row .when { flex-basis: 60px; }
}

/* ================= Stage 1: lists, forms, invoices ================= */
.note { padding: 13px 20px; font-weight: 500; }

/* every list: search, a filter, Export to Excel */
.filters { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--hair); }
.searchbox {
  display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 12px; border: 1px solid var(--field);
  border-radius: 9px; background: #FFFFFF; flex: 0 1 420px;
}
.flex-break { flex-basis: 100%; height: 0; }
.searchbox:focus-within { border-color: var(--accent); outline: 3px solid rgba(0, 113, 227, 0.2); }
.searchbox input {
  flex: 1 1 auto; min-width: 0; border: none; outline: none; background: transparent; font: inherit; color: var(--text);
  height: auto; padding: 0; -webkit-appearance: none;
}
.seg a {
  display: inline-flex; align-items: center; height: 32px; padding: 0 14px; border-radius: 7px; font-size: 14px;
  color: var(--text); white-space: nowrap;
}
.seg a.on { background: #FFFFFF; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.14); font-weight: 500; }
.seg.wrap { flex-wrap: wrap; }
.count { font-size: 13px; color: var(--text3); margin-left: auto; white-space: nowrap; }
a.item, .item { display: grid; gap: 14px; align-items: center; padding: 13px 20px; border-bottom: 1px solid var(--hair); color: var(--text); }
a.item:hover { background: #FAFAFC; color: var(--text); }
.item:last-child { border-bottom: none; }
.item .pair { display: flex; flex-direction: column; min-width: 0; }
.item .pair b { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .pair span, .item .dim { font-size: 13px; color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .amount { font-weight: 500; text-align: right; white-space: nowrap; }
.item .status { font-size: 13px; font-weight: 500; text-align: right; white-space: nowrap; }
.chev { justify-self: end; flex: 0 0 14px; }
.party-row { grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr) minmax(0, 1fr) 14px; }
.invoice-row { grid-template-columns: 110px minmax(0, 1.5fr) 110px 160px 130px 14px; }
a.row { color: var(--text); }
a.row:hover { background: #FAFAFC; color: var(--text); }
.empty { padding: 28px 20px; color: var(--text2); }

/* forms: grouped white cards, a label above every field, the summary sticky on the right */
.form2 { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.stack { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.aside { position: sticky; top: 20px; display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.body { padding: 0 20px 18px; }
.hint { font-size: 13px; color: var(--text2); }
.fields.two-col { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.fields.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.field.wide { grid-column: 1 / -1; }
.field .under { font-size: 13px; color: var(--text2); }
.field .under.bad { color: var(--bad); }
.field .under.warn { color: var(--warn); }
select, textarea, input[type="date"], input[type="email"], input[type="tel"] {
  height: 38px; border: 1px solid var(--field); border-radius: 9px; padding: 0 12px; font: inherit; color: var(--text);
  background: #FFFFFF; width: 100%; -webkit-appearance: none; appearance: none;
}
select {
  padding-right: 32px;
  /* a choice longer than its box (an invoice with its supplier, date and amount) is cut with dots, not spilled past the screen */
  overflow: hidden; text-overflow: ellipsis; max-width: 100%;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2386868B' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}
textarea { height: auto; padding: 9px 12px; line-height: 1.35; resize: vertical; }
select:focus, textarea:focus, input[type="date"]:focus, input[type="email"]:focus, input[type="tel"]:focus {
  border-color: var(--accent); outline: 3px solid rgba(0, 113, 227, 0.2);
}
input.num { text-align: right; font-variant-numeric: tabular-nums; }
.static { min-height: 38px; display: flex; align-items: center; font-variant-numeric: tabular-nums; }

/* Apple-style switch, 51 x 31 */
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 9px 0; border-bottom: 1px solid var(--hair); }
.switch-row:last-child { border-bottom: none; }
.switch-row .what { display: flex; flex-direction: column; }
.switch-row .what span { font-size: 13px; color: var(--text2); }
.switch { position: relative; display: inline-block; width: 51px; height: 31px; flex: 0 0 51px; }
.switch input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch span { position: absolute; inset: 0; border-radius: 31px; background: #E9E9EA; transition: background 0.15s; pointer-events: none; }
.switch span::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%; background: #FFFFFF;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25); transition: transform 0.15s;
}
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { outline: 3px solid rgba(0, 113, 227, 0.35); outline-offset: 1px; }

/* invoice lines */
.line { display: grid; gap: 10px; align-items: end; padding: 12px 0; border-bottom: 1px solid var(--hair); }
.line:first-child { padding-top: 0; }
.kind-export .line { grid-template-columns: minmax(110px, 1.3fr) minmax(104px, 0.9fr) minmax(84px, 0.8fr) minmax(120px, 1.2fr) minmax(70px, 0.7fr) 36px; }
.kind-local .line { grid-template-columns: minmax(130px, 2fr) minmax(84px, 0.8fr) minmax(120px, 1.2fr) minmax(70px, 0.7fr) 36px; }
.kind-proforma .line { grid-template-columns: 140px 180px 110px; }
.kind-commission .line { grid-template-columns: minmax(0, 1fr) 190px; }
.line .per { height: 38px; display: flex; align-items: center; justify-content: flex-end; color: var(--text2); white-space: nowrap; }
.line .label { white-space: nowrap; }
.icon-btn {
  width: 36px; height: 38px; border: none; background: transparent; border-radius: 9px; cursor: pointer; color: var(--text3);
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: rgba(0, 0, 0, 0.05); color: var(--bad); }
.icon-btn:disabled { opacity: 0.3; cursor: default; }
.below { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding-top: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; height: 28px; padding: 0 12px; border-radius: 980px; border: 1px solid #C9C9CE;
  background: #FFFFFF; font: inherit; font-size: 13px; color: var(--accent); cursor: pointer;
}
.chip:hover { background: #FAFAFA; }

/* the money panel */
.sum { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 7px 0; font-size: 14px; }
.sum .l { color: var(--text2); display: flex; flex-direction: column; }
.sum .l small { font-size: 12px; color: var(--text3); }
.sum .r { font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 500; }
.sum.rule { border-top: 1px solid var(--hair); margin-top: 6px; padding-top: 12px; }
.sum.total { border-top: 1px solid var(--hair); margin-top: 6px; padding-top: 12px; }
.sum.total .l { color: var(--text); font-weight: 600; font-size: 15px; }
.sum.total .r { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; }
.problems { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; font-size: 14px; }
.problems .bad { font-weight: 500; }

/* one invoice */
.split { display: grid; grid-template-columns: 360px minmax(0, 1fr); gap: 20px; align-items: start; }
.preview { width: 100%; height: 900px; border: none; border-radius: 16px; background: #FFFFFF; display: block; }
.btn.danger { color: var(--bad); }
.inline-form { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.inline-form input[type="text"] { flex: 1 1 160px; }
.phone-only { display: none; }

@media (max-width: 1180px) {
  .form2 { grid-template-columns: minmax(0, 1fr); }
  .aside { position: static; }
  .split { grid-template-columns: minmax(0, 1fr); }
  .invoice-row { grid-template-columns: 100px minmax(0, 1fr) 150px 124px 14px; }
  .invoice-row .c-carats { display: none; }
  .fields.four { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 700px) {
  .filters { padding: 14px 16px; }
  .searchbox { flex: 1 1 100%; height: 44px; }
  .flex-break { display: none; }
  .seg.wrap { width: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .seg a { height: 44px; }                     /* tall enough for a thumb */
  .count { margin-left: 0; }
  a.item, .item { padding: 13px 16px; }
  .party-row { grid-template-columns: minmax(0, 1fr) 14px; }
  .party-row .c-tax, .party-row .c-contact { display: none; }
  .invoice-row { grid-template-columns: minmax(0, 1fr) auto 14px; row-gap: 2px; }
  .invoice-row .c-no { grid-column: 1; grid-row: 1; }
  .invoice-row .c-client { grid-column: 1; grid-row: 2; }
  .invoice-row .c-amount { grid-column: 2; grid-row: 1; }
  .invoice-row .c-status { grid-column: 2; grid-row: 2; }
  .invoice-row .chev { grid-column: 3; grid-row: 1 / span 2; }
  .fields.two-col, .fields.four { grid-template-columns: minmax(0, 1fr); }
  .body { padding: 0 16px 16px; }
  .cardhead { padding: 16px 16px 10px; }
  .lead { padding: 0 16px 14px; }
  input[type="text"], input[type="password"], select, input[type="date"], input[type="email"], input[type="tel"] { height: 44px; font-size: 16px; }
  textarea { font-size: 16px; }
  .kind-export .line { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .kind-local .line { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .kind-proforma .line { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .kind-commission .line { grid-template-columns: minmax(0, 1fr); }
  .line .f-desc, .line .f-ref { grid-column: 1 / -1; }
  .line .per { justify-content: flex-start; height: 44px; }
  .icon-btn { width: 44px; height: 44px; justify-self: end; }
  .head .actions { width: 100%; }
  .head .actions .btn { flex: 1 1 auto; }
  .preview { display: none; }
  .phone-only { display: block; }
  .desktop-only { display: none; }
}

/* ================= Stage 2: purchases, the client ledger, To Pay / Got ================= */
a.balance { color: var(--text); }
a.balance:hover { background: #FAFAFC; color: var(--text); }
a.pill:hover { color: var(--text2); }
.pill .small { color: var(--good); }
.pill .small.faint { color: var(--text3); }
.head .titles .sub a { color: var(--text2); }
.head .titles .sub a:hover { color: var(--accent); }
.stats.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.two.even { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stack.narrow, .card.narrow { max-width: 780px; width: 100%; }
.note.bad { color: var(--bad); }
label.inline { display: inline-flex; align-items: center; }
label.inline select, label.inline input { width: auto; min-width: 150px; }
.purchase-row { grid-template-columns: 110px minmax(0, 1.5fr) 110px 160px 110px 14px; }
.ledger-row { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1.5fr) 150px 90px 14px; }

/* the purchase form */
.kind-lot .line { grid-template-columns: minmax(130px, 1.5fr) minmax(80px, 0.7fr) minmax(120px, 1.2fr) minmax(120px, 1.1fr) minmax(70px, 0.7fr) 36px; }
.kind-expense .line { grid-template-columns: minmax(130px, 1.6fr) minmax(100px, 1fr) 110px minmax(110px, 1fr) 36px; }
.kind-adjustment .line { grid-template-columns: minmax(0, 1fr) 190px 36px; }
.kind-expense .line:first-child, .kind-adjustment .line:first-child { padding-top: 0; }
details.more > summary { list-style: none; cursor: pointer; padding-bottom: 18px; align-items: center; }
details.more > summary::-webkit-details-marker { display: none; }
details.more > summary::after {
  content: ""; flex: 0 0 14px; width: 14px; height: 14px; margin-left: 4px; transition: transform 0.15s;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2386868B' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat center;
}
details.more > summary h2 { flex: 1 1 auto; }
details.more[open] > summary { padding-bottom: 12px; }
details.more[open] > summary::after { transform: rotate(180deg); }
details.more > summary:focus-visible { outline: 3px solid rgba(0, 113, 227, 0.35); border-radius: 16px; }

/* one client's ledger: a table on the Mac, two-line rows on the phone */
.entry-head, .entry-row { grid-template-columns: 96px 78px minmax(0, 1fr) 124px 124px 158px 14px; }
.entry-head { display: grid; gap: 14px; padding: 10px 20px; font-size: 13px; color: var(--text2); border-bottom: 1px solid var(--hair); }
.entry-row i { display: none; font-style: normal; font-weight: 400; color: var(--text2); }
.entry-row .amount { font-weight: 400; }
.entry-row .c-balance { font-weight: 500; }
.entry-row.opening, .entry-row.closing { background: #FAFAFC; }
.entry-row.closing .amount { font-weight: 600; }

/* To Pay / Got */
.quick { display: grid; grid-template-columns: minmax(0, 1fr) 120px 104px auto; gap: 8px; padding: 0 20px 16px; border-bottom: 1px solid var(--hair); }
.flow-row { grid-template-columns: 28px minmax(0, 1fr) auto 14px; }
.flow-row a { color: var(--text); }
.flow-row form { display: flex; }
.flow-row.done .pair b { color: var(--text2); font-weight: 400; }
.flow-row.done .amount { color: var(--text2); font-weight: 400; }
.tick {
  width: 24px; height: 24px; padding: 0; border-radius: 50%; border: 1.5px solid #C7C7CC; background: #FFFFFF;
  color: transparent; cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
}
.tick:hover { border-color: var(--good); color: #C7C7CC; }
.tick.on { border-color: var(--good); color: var(--good); }
.tick:focus-visible { outline: 3px solid rgba(0, 113, 227, 0.35); outline-offset: 1px; }
.lock-line { display: flex; flex-direction: column; gap: 10px; }

@media (max-width: 1180px) {
  .two.even { grid-template-columns: minmax(0, 1fr); }
  .purchase-row { grid-template-columns: 100px minmax(0, 1fr) 150px 104px 14px; }
  .purchase-row .c-carats { display: none; }
  .ledger-row { grid-template-columns: minmax(0, 1fr) 150px 90px 14px; }
  .ledger-row .c-last { display: none; }
  .entry-head, .entry-row { grid-template-columns: 92px 70px minmax(0, 1fr) 112px 112px 142px 14px; gap: 10px; }
}

@media (max-width: 700px) {
  .stats.three { grid-template-columns: minmax(0, 1fr); }
  .purchase-row { grid-template-columns: minmax(0, 1fr) auto 14px; row-gap: 2px; }
  .purchase-row .c-no { grid-column: 1; grid-row: 1; }
  .purchase-row .c-client { grid-column: 1; grid-row: 2; }
  .purchase-row .c-amount { grid-column: 2; grid-row: 1; }
  .purchase-row .c-status { grid-column: 2; grid-row: 2; }
  .purchase-row .chev { grid-column: 3; grid-row: 1 / span 2; }
  .ledger-row { grid-template-columns: minmax(0, 1fr) auto 14px; row-gap: 2px; }
  .ledger-row .c-name { grid-column: 1; grid-row: 1 / span 2; }
  .ledger-row .c-amount { grid-column: 2; grid-row: 1; }
  .ledger-row .c-status { grid-column: 2; grid-row: 2; }
  .ledger-row .chev { grid-column: 3; grid-row: 1 / span 2; }
  .kind-lot .line, .kind-expense .line, .kind-adjustment .line { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 44px; }
  .line .f-house { grid-column: 1 / -1; }
  .line .f-zar, .line .f-cur { grid-column: 2 / -1; }
  .kind-adjustment .line .field:nth-child(2) { grid-column: 1 / 3; }
  .kind-expense .line .f-eq { grid-column: 1 / 3; }
  label.inline, label.inline select, label.inline input { width: 100%; }
  .entry-head { display: none; }
  .entry-row { grid-template-columns: minmax(0, 1fr) auto 14px; row-gap: 2px; column-gap: 12px; }
  .entry-row .c-what { grid-column: 1; grid-row: 1; }
  .entry-row .c-what b { white-space: normal; }
  .entry-row .c-debit, .entry-row .c-credit { grid-column: 2; grid-row: 1; }
  .entry-row .c-debit:empty, .entry-row .c-credit:empty, .entry-row .c-ref { display: none; }
  .entry-row .c-date { grid-column: 1; grid-row: 2; }
  .entry-row .c-balance { grid-column: 2; grid-row: 2; font-size: 13px; color: var(--text2); font-weight: 400; }
  .entry-row .chev { grid-column: 3; grid-row: 1 / span 2; }
  .entry-row i { display: inline; }
  .entry-row.closing .c-debit::before { content: "Debits "; font-weight: 400; color: var(--text2); }
  .entry-row.closing .c-credit { grid-row: 2; }
  .entry-row.closing .c-credit::before { content: "Credits "; font-weight: 400; color: var(--text2); }
  .entry-row.closing .c-balance { grid-row: 3; font-size: 15px; color: inherit; font-weight: 600; }
  .entry-row.closing .c-what { grid-row: 1 / span 3; align-self: start; }
  .quick { grid-template-columns: minmax(0, 1fr) 104px auto; padding: 0 16px 16px; }
  .quick .q-desc { grid-column: 1 / -1; }
  .tick { width: 28px; height: 28px; }
  .flow-row { grid-template-columns: 30px minmax(0, 1fr) auto 14px; }
}

/* ================= Stage 3: stock book, tender sales, exports, levy ================= */
.lot-tag { grid-column: 1 / -1; font-size: 13px; margin-top: -4px; }
a.stat { color: var(--text); }
a.stat:hover { background: #FAFAFC; color: var(--text); }
.lot-row { grid-template-columns: 110px minmax(0, 1.5fr) 120px 170px 150px 14px; }
.pick-row { grid-template-columns: 24px minmax(0, 1fr) 120px 170px; cursor: pointer; }
.pick-row input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); }
.reg-row { grid-template-columns: minmax(0, 1fr) 110px 150px; }
.levy-row { grid-template-columns: minmax(0, 1fr) 110px 130px 160px; }
.flow-lot { grid-template-columns: minmax(0, 1fr) 110px 140px auto; }
.polished-row { grid-template-columns: minmax(0, 1fr) 110px 130px 150px; }
.flow-lot a.pair { color: var(--text); }
.small-btn { height: 30px; padding: 0 12px; font-size: 13px; }
.kind-part .line { grid-template-columns: 130px minmax(0, 1fr) 220px; }
.kind-pick .line { grid-template-columns: minmax(0, 1fr) 170px auto; }
.kind-ship .line { grid-template-columns: minmax(0, 1fr) 130px 170px 36px; }
.line.result { grid-template-columns: minmax(150px, 1.2fr) minmax(150px, 1fr) minmax(100px, 0.7fr) minmax(130px, 0.9fr); }
.line.result:first-child { padding-top: 0; }
.kind-part .line:first-child, .kind-pick .line:first-child, .kind-ship .line:first-child { padding-top: 0; }
input[type="file"] { font: inherit; font-size: 14px; max-width: 100%; flex: 1 1 220px; }

@media (max-width: 1180px) {
  .lot-row { grid-template-columns: 100px minmax(0, 1fr) 150px 130px 14px; }
  .lot-row .c-carats { display: none; }
  .levy-row { grid-template-columns: minmax(0, 1fr) 110px 150px; }
  .levy-row .c-usd { display: none; }
}

@media (max-width: 700px) {
  .lot-row { grid-template-columns: minmax(0, 1fr) auto 14px; row-gap: 2px; }
  .lot-row .c-no { grid-column: 1; grid-row: 1; }
  .lot-row .c-client { grid-column: 1; grid-row: 2; }
  .lot-row .c-amount { grid-column: 2; grid-row: 1; }
  .lot-row .c-status { grid-column: 2; grid-row: 2; }
  .lot-row .chev { grid-column: 3; grid-row: 1 / span 2; }
  .pick-row { grid-template-columns: 24px minmax(0, 1fr) auto; }
  .pick-row .dim { display: none; }
  .reg-row { grid-template-columns: minmax(0, 1fr) auto; }
  .reg-row .dim { display: none; }
  .polished-row { grid-template-columns: minmax(0, 1fr) auto; row-gap: 2px; }
  .polished-row .c-per { display: none; }
  .polished-row .c-carats { grid-column: 2; grid-row: 1; }
  .polished-row .amount { grid-column: 2; grid-row: 2; }
  .polished-row .pair { grid-row: 1 / span 2; }
  .levy-row { grid-template-columns: minmax(0, 1fr) auto; }
  .levy-row .c-carats { display: none; }
  .flow-lot { grid-template-columns: minmax(0, 1fr) auto; row-gap: 6px; }
  .flow-lot .dim { grid-column: 2; grid-row: 1; }
  .flow-lot .amount { grid-column: 1; grid-row: 2; text-align: left; }
  .flow-lot form, .flow-lot > .btn { grid-column: 2; grid-row: 2; justify-self: end; }
  .kind-part .line, .kind-pick .line, .kind-ship .line, .line.result { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .kind-ship .line .icon-btn { grid-column: 2; }
  .small-btn { height: 44px; }
}

/* ================= Stage 4: purchase invoices, monthly VAT ================= */
fieldset.plain { border: none; margin: 0; padding: 0; min-width: 0; }
fieldset.plain:disabled input, fieldset.plain:disabled select { background: #F5F5F7; color: var(--text2); }
.linklike { border: none; background: none; padding: 0; font: inherit; color: var(--accent); cursor: pointer; }
.linklike:hover { text-decoration: underline; }
.head.sub-head { margin-top: 12px; }
.head.sub-head h2 { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; }
.vat-row { grid-template-columns: minmax(0, 1.3fr) 150px 150px 160px 150px 80px 14px; }
.vat-row.heads { font-size: 13px; color: var(--text2); padding-top: 9px; padding-bottom: 9px; }
.vat-row .right { text-align: right; }
.import-row.left { grid-template-columns: 110px minmax(0, 1.3fr) 120px 150px 300px 0; }
.import-row.left .inline-form { flex-wrap: nowrap; justify-content: flex-end; }
.import-row.left select { width: auto; min-width: 150px; height: 30px; font-size: 13px; }
a.row { color: var(--text); }
a.row:hover { background: #FAFAFC; color: var(--text); }
#new-key { width: 100%; font-size: 14px; }

@media (max-width: 1180px) {
  .vat-row { grid-template-columns: minmax(0, 1.2fr) 140px 150px 76px 14px; }
  .vat-row .c-out, .vat-row .c-sars { display: none; }
  .import-row.left { grid-template-columns: 100px minmax(0, 1fr) 150px 290px 0; }
}

@media (max-width: 700px) {
  .vat-row { grid-template-columns: minmax(0, 1fr) auto 14px; row-gap: 2px; }
  .vat-row.heads { display: none; }
  .vat-row .pair { grid-column: 1; grid-row: 1 / span 2; }
  .vat-row > .dim { display: none; }
  .vat-row .amount { grid-column: 2; grid-row: 1; }
  .vat-row .c-state { grid-column: 2; grid-row: 2; }
  .vat-row .chev { grid-column: 3; grid-row: 1 / span 2; }
  .import-row.left { grid-template-columns: minmax(0, 1fr) auto; }
  .import-row.left .inline-form { grid-column: 1 / -1; grid-row: 3; justify-content: flex-start; }
  .import-row.left select { height: 36px; flex: 1 1 auto; }
  .head.sub-head h2 { font-size: 20px; }
}
.import-row .c-client span { white-space: normal; }

/* ================= Stage 5: bank ================= */
.bank-row { grid-template-columns: 110px minmax(0, 1fr) 170px 110px; }
.bank-row.open { box-shadow: inset 3px 0 0 var(--bad); }
.bank-row.info { color: var(--text3); }
.bank-row .c-desc b a { color: var(--text); }
.bank-row .c-desc span { white-space: normal; }
.bank-row .c-act { display: flex; justify-content: flex-end; }
.kind-home .line { grid-template-columns: minmax(150px, 1fr) minmax(0, 2fr) 150px minmax(0, 1fr); }
.kind-home .line .target { min-width: 0; }
.sum .r.wraps { white-space: normal; text-align: right; min-width: 0; }   /* words, not a figure: they fold on a phone */
@media (max-width: 700px) {
  .bank-row { grid-template-columns: minmax(0, 1fr) auto; row-gap: 4px; }
  .bank-row .c-date { grid-column: 1; grid-row: 1; flex-direction: row; gap: 8px; }
  .bank-row .c-amount { grid-column: 2; grid-row: 1; }
  .bank-row .c-desc { grid-column: 1 / -1; grid-row: 2; }
  .bank-row .c-act { grid-column: 1 / -1; grid-row: 3; justify-content: flex-start; }
  .bank-row .c-act .btn { height: 40px; min-width: 120px; }
  .kind-home .line { grid-template-columns: minmax(0, 1fr); }
}

/* the two-step login: the square to scan, the steps, the code box */
.door .steps { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--text2); }
.door .qr { display: flex; justify-content: center; padding: 6px 0; }
.door .qr svg { width: 190px; height: 190px; background: #fff; border-radius: 10px; }
.door .key { display: inline-block; max-width: 100%; font-weight: 600; letter-spacing: .5px; overflow-wrap: anywhere; }
input.code { font-size: 20px; letter-spacing: 4px; text-align: center; }
/* a copy that takes nothing in any more */
.readonly-note { margin: 0 0 14px; padding: 10px 14px; border-radius: 12px; background: #FFF4E5; color: #8A4B00; font-size: 14px; }
.readonly-note a { color: inherit; text-decoration: underline; }
