/* ==========================================================================
   Pharma Orders: mobile-first styles
   Palette: pharmacist's green ink on a cool mint paper. One bold element:
   the order "slip" (indent slip with a torn edge) that carries the total.
   ========================================================================== */

:root {
    --green: #0B6E63;
    --green-deep: #084C45;
    --green-tint: #DDEFE7;
    --ink: #13302C;
    --muted: #57716C;
    --paper: #EDF3F0;
    --surface: #FFFFFF;
    --line: #D5E2DD;
    --line-strong: #B9CCC5;
    --amber: #8A5200;
    --amber-tint: #FCEFD9;
    --blue: #1F4F8A;
    --blue-tint: #E3ECF8;
    --rose: #A8324A;
    --rose-tint: #F8E3E7;

    --age-1: #7FC4B4; --age-2: #3E9C8A; --age-3: #E1B24A;
    --age-4: #D98A2B; --age-5: #C55A3F; --age-6: #A8324A;

    --font: "Atkinson Hyperlegible", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --r-sm: 8px;
    --r: 12px;
    --r-lg: 18px;
    --nav-h: 64px;
    --safe-b: env(safe-area-inset-bottom, 0px);
    --focus: 0 0 0 3px rgba(11, 110, 99, .38);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.5;
    color: var(--ink);
    background: var(--paper);
    -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 26px; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 18px; font-weight: 700; }
p { margin: 0; }
a { color: var(--green); text-underline-offset: 3px; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.ic { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--r-sm); }

/* ---------- buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 44px; padding: 10px 18px;
    border: 1px solid transparent; border-radius: var(--r);
    font-weight: 700; font-size: 16px; text-decoration: none; cursor: pointer;
    background: var(--surface); color: var(--ink);
    transition: background-color .15s, border-color .15s;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:not(:disabled):hover { background: var(--green-deep); }
.btn-quiet { background: var(--surface); border-color: var(--line-strong); }
.btn-quiet:hover { border-color: var(--green); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { color: var(--ink); background: var(--paper); }
.btn-danger-quiet { background: transparent; color: var(--rose); padding-left: 8px; padding-right: 8px; }
.btn-danger-quiet:hover { background: var(--rose-tint); }
.btn-block { width: 100%; }
.btn-big { min-height: 56px; font-size: 18px; width: 100%; }
.btn-small { min-height: 36px; padding: 6px 12px; font-size: 14px; border-color: var(--line); }
.btn-small .ic { width: 16px; height: 16px; }
.icon-btn {
    display: grid; place-items: center; width: 44px; height: 44px; flex: none;
    border: 0; border-radius: 50%; background: var(--paper); cursor: pointer;
}

/* ---------- top bar (mobile) ---------- */
.topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; gap: 12px;
    min-height: 56px; padding: 8px 8px 8px 16px;
    padding-top: max(8px, env(safe-area-inset-top));
    background: var(--green); color: #fff;
}
.topbar-shop { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.shop-name { font-weight: 700; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.shop-switch { color: #CDEBE3; font-size: 13px; text-decoration: none; }
.shop-switch:hover { text-decoration: underline; }

.account { position: relative; }
.account summary { list-style: none; cursor: pointer; padding: 4px; border-radius: 50%; }
.account summary::-webkit-details-marker { display: none; }
.avatar {
    display: grid; place-items: center; width: 38px; height: 38px; border-radius: 50%;
    background: rgba(255,255,255,.16); color: #fff; font-weight: 700; font-size: 14px; letter-spacing: .02em;
}
.avatar-sm { width: 36px; height: 36px; background: var(--green-tint); color: var(--green-deep); flex: none; }
.account-menu {
    position: absolute; right: 0; top: calc(100% + 6px); width: 240px; padding: 8px;
    background: var(--surface); color: var(--ink); border-radius: var(--r);
    box-shadow: 0 12px 32px rgba(8, 40, 36, .22);
}
.account-who { display: flex; flex-direction: column; padding: 8px 10px 10px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.account-who span { color: var(--muted); font-size: 14px; }
.account-menu a, .account-menu button {
    display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px; border: 0; background: none;
    border-radius: var(--r-sm); color: var(--ink); text-decoration: none; cursor: pointer; text-align: left;
}
.account-menu a:hover, .account-menu button:hover { background: var(--paper); }
.account-menu form { margin: 0; }

/* ---------- nav: bottom bar on phones, left rail on desktop ---------- */
.rail {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    background: var(--surface); border-top: 1px solid var(--line);
    padding-bottom: var(--safe-b);
}
.rail-brand, .rail-foot { display: none; }
.nav-links { display: flex; height: var(--nav-h); }
.nav-links a {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    color: var(--muted); text-decoration: none; font-size: 12px; font-weight: 700;
}
.nav-links a .ic { width: 24px; height: 24px; }
.nav-links a[aria-current="page"] { color: var(--green); }
.nav-links a[aria-current="page"] .ic { stroke-width: 2.2; }

.main { padding: 20px 16px calc(var(--nav-h) + var(--safe-b) + 32px); max-width: 1040px; }

/* ---------- page heads ---------- */
.page-head { margin-bottom: 20px; display: flex; flex-direction: column; gap: 6px; }
.page-head-row.start-row { justify-content: flex-start; }
.page-head-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-direction: row; flex-wrap: wrap; }
.lede { color: var(--muted); max-width: 60ch; }
.back { display: inline-flex; align-items: center; gap: 2px; margin-left: -6px; color: var(--muted); text-decoration: none; font-size: 15px; width: fit-content; }
.back:hover { color: var(--green); }

/* ---------- panels and lists ---------- */
.panel { background: var(--surface); border-radius: var(--r-lg); padding: 18px 16px; margin-bottom: 16px; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.panel-head a { font-size: 15px; font-weight: 700; text-decoration: none; }
.panel-label { font-size: 15px; color: var(--muted); font-weight: 400; }
.panel .list { margin: 0 -16px -18px; border-radius: 0 0 var(--r-lg) var(--r-lg); }
.big-amount { font-size: 34px; font-weight: 700; letter-spacing: -.02em; margin: 2px 0 14px; }

.list { list-style: none; margin: 0 0 16px; padding: 0; background: var(--surface); border-radius: var(--r-lg); overflow: hidden; }
.list > li + li, .list > .row + .row { border-top: 1px solid var(--line); }
.list > li > form { margin: 0; }
.row {
    display: flex; align-items: center; gap: 12px; padding: 14px 16px;
    color: inherit; text-decoration: none; width: 100%;
}
a.row:hover, .row-button:hover, label.row:hover { background: #F6FAF8; }
.row-button { border: 0; background: none; text-align: left; cursor: pointer; }
.row-button.is-current { background: var(--green-tint); }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.row-main strong { font-weight: 700; overflow-wrap: anywhere; }
.row-sub { color: var(--muted); font-size: 14px; display: block; }
.row-end { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.row-chev { color: var(--line-strong); }
.list-foot { color: var(--muted); font-size: 14px; text-align: right; margin: -6px 4px 20px; }
.empty { color: var(--muted); padding: 20px 16px; background: var(--surface); border-radius: var(--r-lg); border: 1px dashed var(--line-strong); margin-bottom: 16px; }
.panel .empty { border: 0; padding: 4px 0 0; }

.pill {
    display: inline-block; padding: 2px 10px; border-radius: 999px;
    font-size: 13px; font-weight: 700; line-height: 1.6; white-space: nowrap;
}
.pill-draft { background: var(--amber-tint); color: var(--amber); }
.pill-sent { background: var(--blue-tint); color: var(--blue); }
.pill-received { background: var(--green-tint); color: var(--green-deep); }
.pill-new { display: none; }

/* ---------- forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin: 0 0 16px; border: 0; padding: 0; min-width: 0; }
.field > span:first-child, .field legend { font-weight: 700; font-size: 15px; padding: 0; }
.field i { font-style: normal; font-weight: 400; color: var(--muted); }
.field input, .field textarea, .field select, .remarks textarea {
    width: 100%; min-height: 48px; padding: 11px 14px;
    background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r);
}
.field input:focus, .remarks textarea:focus { border-color: var(--green); box-shadow: var(--focus); outline: none; }
.field-help { color: var(--muted); font-size: 14px; }
.field-error { color: var(--rose); font-size: 14px; font-weight: 700; }
.field-error:empty { display: none; }
.input-validation-error { border-color: var(--rose) !important; }
.form-error { background: var(--rose-tint); color: var(--rose); padding: 12px 14px; border-radius: var(--r); margin-bottom: 16px; font-weight: 700; }
.field-inline { margin: 0; flex: 1; min-width: 130px; }
.field-inline > span:first-child { font-size: 13px; color: var(--muted); }
.field-inline input { min-height: 44px; padding: 8px 10px; }

.pwd { position: relative; display: block; }
.pwd input { padding-right: 72px; }
.pwd-toggle {
    position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
    border: 0; background: none; color: var(--green); font-weight: 700; padding: 8px 10px; cursor: pointer; border-radius: var(--r-sm);
}

.check { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; cursor: pointer; }
.check input, .check-list input { width: 22px; height: 22px; accent-color: var(--green); flex: none; }

.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r); padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg label { position: relative; cursor: pointer; }
.seg input { position: absolute; opacity: 0; inset: 0; }
.seg span { display: block; padding: 8px 14px; border-radius: 9px; font-size: 15px; font-weight: 700; color: var(--muted); }
.seg input:checked + span { background: var(--green); color: #fff; }
.seg input:focus-visible + span { box-shadow: var(--focus); }
.seg-wide { display: flex; }
.seg-wide label { flex: 1; text-align: center; }

.search-field {
    display: flex; align-items: center; gap: 10px;
    background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r);
    padding: 0 14px; margin-bottom: 14px; min-height: 48px; color: var(--muted);
}
.search-field:focus-within { border-color: var(--green); box-shadow: var(--focus); }
.search-field input { flex: 1; min-width: 0; border: 0; background: none; padding: 12px 0; outline: none; color: var(--ink); }
.search-field input:focus-visible { box-shadow: none; }
.search-field input::-webkit-search-cancel-button { cursor: pointer; }

.date-filter { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: end; margin-bottom: 16px; max-width: 560px; }
.date-filter .field-inline { min-width: 0; }
.date-filter .btn { min-height: 44px; padding: 8px 14px; }
.user-filter { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.user-filter .search-field { margin: 0; }

.form-card { background: var(--surface); border-radius: var(--r-lg); padding: 20px 16px; max-width: 720px; }
.form-grid { display: grid; grid-template-columns: 1fr; column-gap: 16px; }
.form-actions { display: flex; justify-content: flex-end; align-items: center; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
.sticky-actions {
    position: sticky; bottom: calc(var(--nav-h) + var(--safe-b)); background: var(--paper);
    padding: 12px 0; margin-top: 0;
}
.sticky-actions .row-sub { margin-right: auto; }

/* ---------- login ---------- */
body.bare { background: var(--paper); }
.bare-main { min-height: 100vh; min-height: 100dvh; }
.login { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.login-intro {
    position: relative; overflow: hidden;
    background: var(--green); color: #fff;
    padding: max(40px, env(safe-area-inset-top)) 24px 40px;
}
.login-cross {
    position: absolute; right: -40px; top: -30px; width: 200px; height: 200px;
    fill: rgba(255,255,255,.08); stroke: none;
}
.login-intro h1 { font-size: 30px; max-width: 16ch; position: relative; }
.login-intro p { margin-top: 12px; max-width: 38ch; color: #D4EEE7; position: relative; }
.login-intro .login-sync { font-size: 14px; color: #A9DCCF; }
.login-form { padding: 28px 24px 40px; width: 100%; max-width: 440px; }
.login-form h2 { font-size: 22px; margin-bottom: 18px; }
.login-form .btn-block { margin-top: 6px; min-height: 52px; font-size: 17px; }
.demo-note, .login-help { margin-top: 18px; color: var(--muted); font-size: 14px; }
.demo-note { background: var(--amber-tint); color: var(--amber); padding: 10px 12px; border-radius: var(--r); }

.error-page { max-width: 480px; margin: 0 auto; padding: 80px 24px; display: flex; flex-direction: column; gap: 14px; align-items: flex-start; position: relative; }
.error-page .login-cross { fill: var(--green-tint); position: static; width: 56px; height: 56px; }

/* ---------- home ---------- */
.start { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }
.draft-card {
    display: grid; gap: 4px; padding: 18px 16px; text-decoration: none; color: inherit;
    background: var(--surface); border-radius: var(--r-lg); border-left: 5px solid #E0A33A;
}
.draft-card strong { font-size: 20px; }
.draft-tag { color: var(--amber); font-weight: 700; font-size: 14px; }
.draft-meta { color: var(--muted); }
.draft-card .btn { margin-top: 10px; }
.action-grid { display: grid; gap: 12px; }
.action {
    display: grid; gap: 4px; padding: 18px; border-radius: var(--r-lg); background: var(--surface);
    text-decoration: none; color: inherit; border: 1px solid transparent;
}
.action:hover { border-color: var(--green); }
.action .ic { width: 28px; height: 28px; color: var(--green); margin-bottom: 6px; }
.action span { color: var(--muted); font-size: 15px; }

/* ---------- outstanding ---------- */
.ageing-bar { display: flex; height: 14px; border-radius: 999px; overflow: hidden; gap: 2px; background: var(--paper); }
.ageing-bar span { min-width: 6px; }
.age-1 { background: var(--age-1); } .age-2 { background: var(--age-2); } .age-3 { background: var(--age-3); }
.age-4 { background: var(--age-4); } .age-5 { background: var(--age-5); } .age-6 { background: var(--age-6); }
.ageing-legend { margin: 14px 0 0; display: grid; gap: 6px; }
.ageing-legend div { display: flex; justify-content: space-between; gap: 12px; font-size: 15px; }
.ageing-legend dt { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.ageing-legend dd { margin: 0; font-weight: 700; }
.swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

.table-wrap { background: var(--surface); border-radius: var(--r-lg); overflow-x: auto; }
.bills { width: 100%; border-collapse: collapse; font-size: 15px; }
.bills th { text-align: left; font-size: 13px; color: var(--muted); font-weight: 700; padding: 12px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.bills td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.bills tr:last-child td { border-bottom: 0; }
.bills .r { text-align: right; }
@media (max-width: 639px) {
    .bills thead { display: none; }
    .bills tr { display: grid; grid-template-columns: 1fr auto; column-gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
    .bills tr:last-child { border-bottom: 0; }
    .bills td { border: 0; padding: 0; }
    .bills td:nth-child(1) { grid-column: 1; grid-row: 1; }
    .bills td:nth-child(4) { grid-column: 2; grid-row: 1; }
    .bills td:nth-child(2) { grid-column: 1; grid-row: 2; color: var(--muted); font-size: 14px; }
    .bills td:nth-child(3) { grid-column: 1; grid-row: 3; color: var(--muted); font-size: 14px; text-align: left; }
    .bills td:nth-child(3)::before { content: "Bill amount "; }
    .bills td:nth-child(5) { grid-column: 2; grid-row: 2 / span 2; align-self: end; }
}
.days { display: inline-block; min-width: 46px; text-align: center; padding: 1px 8px; border-radius: 999px; font-size: 13px; font-weight: 700; color: var(--ink); white-space: nowrap; }
.days.age-1 { background: #E1F2EC; } .days.age-2 { background: #CFE8E1; } .days.age-3 { background: #FAEED0; }
.days.age-4 { background: #F7E0C4; } .days.age-5 { background: #F4D7CF; } .days.age-6 { background: var(--rose); color: #fff; }

/* ---------- invoices ---------- */
.invoice-row { flex-wrap: wrap; }
.invoice-amt { font-weight: 700; }
.files { display: flex; gap: 8px; width: 100%; flex-wrap: wrap; }
.file {
    display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; min-height: 36px;
    border: 1px solid var(--line-strong); border-radius: var(--r-sm); font-size: 14px; font-weight: 700; text-decoration: none;
}
.file .ic { width: 16px; height: 16px; }
.file:hover { border-color: var(--green); background: var(--green-tint); }

/* ---------- users ---------- */
.user-row { flex-wrap: wrap; align-items: flex-start; }
.user-row.is-off { opacity: .6; }
.row-actions { display: flex; gap: 6px; width: 100%; padding-left: 48px; flex-wrap: wrap; }
.row-actions form { margin: 0; }
.warn-text { color: var(--amber); font-weight: 700; }
.check-list label.row { cursor: pointer; }

.legend { margin-top: 8px; color: var(--muted); font-size: 15px; }
.legend summary { cursor: pointer; font-weight: 700; padding: 6px 0; width: fit-content; }
.legend dl { display: grid; gap: 10px; margin: 8px 0 0; }
.legend dl div { display: grid; grid-template-columns: 96px 1fr; gap: 8px; align-items: start; }
.legend dd { margin: 0; }

/* ==========================================================================
   Order sheet
   ========================================================================== */
.order-app { padding-bottom: 120px; }
.order-layout { display: block; }
.finder { position: relative; margin-bottom: 20px; }
.search-big { min-height: 56px; margin-bottom: 6px; border-width: 2px; border-color: var(--green); }
.search-big .ic { color: var(--green); width: 22px; height: 22px; }
.search-big input { font-size: 17px; }
.finder-hint { color: var(--muted); font-size: 13px; padding: 0 4px; }

.results {
    list-style: none; margin: 8px 0 0; padding: 0;
    background: var(--surface); border-radius: var(--r-lg);
    box-shadow: 0 10px 30px rgba(8, 40, 36, .14);
    max-height: 60vh; overflow-y: auto; overscroll-behavior: contain;
}
.results li + li { border-top: 1px solid var(--line); }
.results-empty { padding: 16px; color: var(--muted); }

.result, .line {
    display: flex; gap: 12px; width: 100%; padding: 13px 16px; align-items: flex-start;
    border: 0; background: none; text-align: left; cursor: pointer; color: inherit;
}
.result:hover, .result:focus-visible, .line:not(:disabled):hover { background: #F3F8F6; }
.line:disabled { cursor: default; }
.line-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.line-main strong { overflow-wrap: anywhere; }
.line-end { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; text-align: right; }
.line-qty { font-size: 14px; color: var(--muted); white-space: nowrap; }
.line-qty b { color: var(--ink); font-size: 16px; }
.line-amt { font-weight: 700; }

.scheme { font-size: 13px; font-weight: 700; color: var(--blue); }
.stock { font-size: 13px; color: var(--muted); white-space: nowrap; }
.stock-low { color: var(--amber); font-weight: 700; }
.stock-out { color: var(--rose); font-weight: 700; }
.on-order { font-size: 13px; font-weight: 700; color: var(--green); white-space: nowrap; }

.lines-head { font-size: 15px; color: var(--muted); font-weight: 700; margin: 0 4px 8px; }
.lines { list-style: none; margin: 0 0 12px; padding: 0; background: var(--surface); border-radius: var(--r-lg); overflow: hidden; }
.lines:empty { display: none; }
.lines li + li { border-top: 1px solid var(--line); }

.remarks { margin: 4px 0 16px; }
.remarks summary { cursor: pointer; font-weight: 700; color: var(--green); padding: 8px 4px; width: fit-content; }
.remarks textarea { margin-top: 6px; resize: vertical; }
.delete-draft { margin: 0; }

/* The slip: an indent slip torn off a pad. Fixed above the bottom nav on phones. */
.slip {
    position: fixed; left: 0; right: 0; z-index: 25;
    bottom: calc(var(--nav-h) + var(--safe-b));
    filter: drop-shadow(0 -6px 14px rgba(8, 40, 36, .12));
}
.slip::before {
    content: ""; display: block; height: 10px;
    background:
        radial-gradient(circle at 8px 0, transparent 6px, var(--surface) 6.5px) 0 0 / 16px 10px repeat-x;
}
.slip-body {
    display: flex; align-items: center; gap: 14px;
    background: var(--surface); padding: 6px 16px 12px;
}
.slip-figures { flex: 1; display: grid; grid-template-columns: auto; line-height: 1.15; min-width: 0; }
.slip-count { font-size: 14px; color: var(--muted); font-weight: 700; }
.slip-total { font-size: 26px; letter-spacing: -.02em; }
.slip-note { display: none; }
.slip form { margin: 0; }
.btn-send { min-height: 52px; padding: 10px 20px; font-size: 17px; }
.slip-locked { color: var(--green-deep); font-weight: 700; font-size: 15px; }
.order-app.is-locked .slip-body { background: var(--green-tint); }
.order-app.is-locked .slip::before { background: radial-gradient(circle at 8px 0, transparent 6px, var(--green-tint) 6.5px) 0 0 / 16px 10px repeat-x; }

/* Quantity sheet: bottom sheet on phones, centred card on desktop. */
.qty-sheet {
    border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 100%;
    background: var(--surface); color: var(--ink);
    border-radius: 22px 22px 0 0;
    max-height: 92vh; max-height: 92dvh;
}
.qty-sheet[open] { animation: sheet-up .22s ease-out; }
.qty-sheet::backdrop { background: rgba(8, 30, 27, .45); }
@keyframes sheet-up { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
.qty-sheet form { padding: 18px 18px calc(18px + var(--safe-b)); display: flex; flex-direction: column; gap: 14px; }
.qs-head { display: flex; gap: 12px; align-items: flex-start; }
.qs-head > div { flex: 1; min-width: 0; }
.qs-head h2 { font-size: 20px; overflow-wrap: anywhere; }
.qs-facts { display: grid; grid-template-columns: repeat(4, 1fr); margin: 0; background: var(--paper); border-radius: var(--r); }
.qs-facts div { padding: 10px 8px; text-align: center; }
.qs-facts div + div { border-left: 1px solid var(--line); }
.qs-facts dt { font-size: 12px; color: var(--muted); font-weight: 700; }
.qs-facts dd { margin: 2px 0 0; font-weight: 700; font-size: 15px; }
.qs-scheme { color: var(--blue); font-weight: 700; font-size: 15px; }
.stepper { display: grid; grid-template-columns: 64px 1fr 64px; gap: 8px; }
.step {
    height: 60px; border: 1px solid var(--line-strong); border-radius: var(--r); background: var(--surface);
    display: grid; place-items: center; cursor: pointer; color: var(--green);
}
.step:active { background: var(--green-tint); }
.step .ic { width: 26px; height: 26px; stroke-width: 2.2; }
.stepper input {
    height: 60px; width: 100%; text-align: center; font-size: 28px; font-weight: 700;
    border: 2px solid var(--green); border-radius: var(--r); font-variant-numeric: tabular-nums; -moz-appearance: textfield;
}
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.stepper input:focus { outline: none; box-shadow: var(--focus); }
.quick-qty { display: flex; gap: 6px; }
.quick-qty button {
    flex: 1; min-height: 40px; border: 1px solid var(--line); background: var(--paper); border-radius: var(--r-sm);
    font-weight: 700; cursor: pointer; font-variant-numeric: tabular-nums;
}
.quick-qty button:hover { border-color: var(--green); }
.qs-warn { background: var(--amber-tint); color: var(--amber); padding: 10px 12px; border-radius: var(--r); font-size: 14px; font-weight: 700; }
.qs-amount { display: flex; justify-content: space-between; align-items: baseline; border-top: 1px dashed var(--line-strong); padding-top: 12px; }
.qs-amount span { color: var(--muted); font-weight: 700; }
.qs-amount strong { font-size: 24px; }
.qs-actions { display: flex; gap: 10px; }
.qs-actions .btn-primary { flex: 1; min-height: 52px; font-size: 17px; }

/* ---------- toast ---------- */
.toast {
    position: fixed; left: 16px; right: 16px; z-index: 60;
    bottom: calc(var(--nav-h) + var(--safe-b) + 96px);
    margin: 0 auto; max-width: 420px; width: fit-content;
    background: var(--ink); color: #fff; padding: 12px 16px; border-radius: var(--r);
    font-weight: 700; font-size: 15px; box-shadow: 0 10px 30px rgba(0,0,0,.25);
    opacity: 0; transform: translateY(8px); transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: none; }
.toast-error { background: var(--rose); }
body.bare .toast { bottom: 24px; }

/* ==========================================================================
   Larger screens
   ========================================================================== */
@media (min-width: 640px) {
    .main { padding-left: 24px; padding-right: 24px; }
    h1 { font-size: 30px; }
    .form-grid { grid-template-columns: 1fr 1fr; }
    .action-grid { grid-template-columns: 1fr 1fr; }
    .user-filter { flex-direction: row; align-items: center; }
    .user-filter .search-field { flex: 1; }
    .invoice-row { flex-wrap: nowrap; }
    .files { width: auto; }
    .user-row { flex-wrap: nowrap; align-items: center; }
    .row-actions { width: auto; padding-left: 0; }
    .start { flex-direction: row; align-items: stretch; }
    .start .btn-big { width: auto; padding-left: 28px; padding-right: 28px; }
    .draft-card { flex: 1; max-width: 460px; }
    .start .btn-quiet { align-self: flex-end; }
    .qty-sheet { margin: auto; max-width: 440px; border-radius: 22px; }
    .qty-sheet[open] { animation-name: sheet-in; }
    @keyframes sheet-in { from { transform: scale(.97); opacity: .4; } to { transform: none; opacity: 1; } }
}

@media (min-width: 960px) {
    body.app { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
    .topbar { display: none; }
    .rail {
        position: sticky; top: 0; bottom: auto; height: 100vh;
        display: flex; flex-direction: column; gap: 8px;
        border-top: 0; border-right: 1px solid var(--line); padding: 20px 14px;
    }
    .rail-brand {
        display: flex; align-items: center; gap: 10px; padding: 6px 10px 18px;
        color: var(--ink); text-decoration: none; font-weight: 700; line-height: 1.25;
    }
    .brand-cross { width: 34px; height: 34px; flex: none; fill: var(--green); stroke: none; }
    .nav-links { flex-direction: column; height: auto; gap: 2px; }
    .nav-links a { flex: none; flex-direction: row; justify-content: flex-start; gap: 12px; padding: 11px 12px; font-size: 16px; border-radius: var(--r); }
    .nav-links a:hover { background: var(--paper); color: var(--ink); }
    .nav-links a[aria-current="page"] { background: var(--green-tint); color: var(--green-deep); }
    .nav-links a .ic { width: 22px; height: 22px; }
    .rail-foot { display: flex; flex-direction: column; gap: 10px; margin-top: auto; padding: 14px 10px 0; border-top: 1px solid var(--line); }
    .rail-shop { display: flex; flex-direction: column; font-size: 14px; }
    .rail-shop span { color: var(--muted); font-size: 13px; }
    .rail-foot form { margin: 0; }
    .rail-logout { display: flex; align-items: center; gap: 10px; border: 0; background: none; color: var(--muted); padding: 8px 0; cursor: pointer; }
    .rail-logout:hover { color: var(--ink); }
    .main { padding: 36px 40px 56px; width: 100%; }
    .sticky-actions { bottom: 0; }
    .toast { bottom: 32px; }

    /* Order sheet: slip becomes a sticky column. */
    .order-app { padding-bottom: 0; }
    .order-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 28px; align-items: start; }
    .slip { position: sticky; top: 28px; bottom: auto; filter: drop-shadow(0 8px 22px rgba(8, 40, 36, .10)); }
    .slip::after {
        content: ""; display: block; height: 10px;
        background: radial-gradient(circle at 8px 10px, transparent 6px, var(--surface) 6.5px) 0 0 / 16px 10px repeat-x;
    }
    .order-app.is-locked .slip::after { background: radial-gradient(circle at 8px 10px, transparent 6px, var(--green-tint) 6.5px) 0 0 / 16px 10px repeat-x; }
    .slip-body { flex-direction: column; align-items: stretch; padding: 18px 20px; gap: 16px; }
    .slip-figures { gap: 4px; padding-bottom: 14px; border-bottom: 1px dashed var(--line-strong); }
    .slip-total { font-size: 34px; }
    .slip-note { display: block; color: var(--muted); font-size: 13px; }
    .btn-send { width: 100%; }
    .results { position: absolute; left: 0; right: 0; z-index: 10; max-height: 440px; }
}

@media (min-width: 960px) {
    .login { flex-direction: row; }
    .login-intro { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; padding: 64px; }
    .login-intro h1 { font-size: 44px; }
    .login-cross { width: 420px; height: 420px; right: -80px; top: -60px; }
    .login-form { flex: 1; max-width: none; display: flex; flex-direction: column; justify-content: center; padding: 64px; }
    .login-form > * { max-width: 380px; width: 100%; }
}

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

/* ---------- invoice download icons ---------- */
.invoice-row { flex-wrap: nowrap; align-items: center; }
.invoice-row .invoice-amt { font-weight: 700; margin-top: 2px; }
.file-icons { display: flex; gap: 6px; flex: none; }
.file-icon {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
    width: 46px; height: 50px; border-radius: var(--r-sm); border: 1px solid var(--line);
    text-decoration: none; font-size: 11px; font-weight: 700; color: var(--ink); background: var(--surface);
}
.file-icon .ic { width: 22px; height: 22px; }
.file-icon:hover { border-color: currentColor; }
.ft-pdf { color: #B42318; }
.ft-pdf:hover { background: #FDECEA; }
.ft-xls { color: #1D7044; }
.ft-xls:hover { background: #E4F4EA; }
.ft-csv { color: var(--blue); }
.ft-csv:hover { background: var(--blue-tint); }
.file-icon.is-missing { color: var(--line-strong); border-style: dashed; cursor: not-allowed; }

/* ---------- invoice table: Invoice no | Date | Amount | icons, rows two lines high ---------- */
.inv-row {
    display: grid; align-items: center; column-gap: 12px; padding: 8px 16px; min-height: 66px;
    grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas: "no no files" "date amt files";
}
.inv-list > li + li { border-top: 1px solid var(--line); }
.inv-no { grid-area: no; font-weight: 700; overflow-wrap: anywhere; }
.inv-date { grid-area: date; color: var(--muted); font-size: 14px; }
.inv-amt { grid-area: amt; font-weight: 700; text-align: right; font-size: 14px; }
@media (max-width: 639px) { .inv-row .file-icon { width: 42px; } }
.inv-files { grid-area: files; }
.inv-head { display: none; }
@media (min-width: 640px) {
    .inv-row { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) minmax(0, 1fr) auto; grid-template-areas: "no date amt files"; }
    .inv-date { font-size: 16px; color: var(--ink); }
    .inv-amt { font-size: 16px; }
    .inv-head {
        display: grid; min-height: 0; padding-top: 10px; padding-bottom: 10px;
        font-size: 13px; font-weight: 700; color: var(--muted); background: #F6FAF8;
    }
    .inv-head .inv-no, .inv-head .inv-amt { font-weight: 700; }
    .inv-head .inv-date { font-size: 13px; color: var(--muted); }
    .inv-head .inv-files { width: 150px; text-align: center; }
}

/* ---------- wholesaler home: orders from all shops ---------- */
.all-orders { margin-top: 20px; }
.all-orders .date-filter { margin-bottom: 12px; }
.all-orders .list { margin: 0 -16px; border-radius: 0; }
.all-orders .list-foot { margin: 10px 0 0; }
.view-lines .line { cursor: default; }

/* ---------- login: who is signing in ---------- */
.login-type { display: flex; margin-bottom: 18px; }
.login-type label { flex: 1; text-align: center; }
.login-switch { margin-top: 14px; font-size: 14px; }
.login-switch button { border: 0; background: none; color: var(--green); font-weight: 700; cursor: pointer; padding: 4px 0; }

/* ---------- one shop for a retailer login ---------- */
.check-list input[type="radio"] { width: 22px; height: 22px; accent-color: var(--green); flex: none; }

/* ---------- linked shops first + search button ---------- */
.check-list .group-head {
    padding: 10px 16px; font-size: 13px; font-weight: 700; color: var(--muted); background: #F6FAF8;
}
.check-list li.is-linked { background: #F3FAF7; }
.search-field .search-btn { margin-right: -8px; min-height: 36px; border: 0; }

/* ---------- order lines: serial no, MRP, remove button ---------- */
.mrp { font-size: 13px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.line-row { display: flex; align-items: center; }
.line-row .line { flex: 1; min-width: 0; padding-left: 4px; }
.sl {
    flex: none; width: 34px; padding-left: 12px; align-self: flex-start; margin-top: 15px;
    font-size: 13px; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums;
}
.view-lines .line { align-items: flex-start; padding-left: 16px; }
.view-lines .line:hover { background: none; }
.view-lines .sl { margin-top: 2px; padding-left: 0; width: 26px; }
.line-del { margin-right: 8px; background: transparent; color: var(--rose); }
.line-del:hover { background: var(--rose-tint); }

/* ---------- search results grouped by product + manufacturer ---------- */
.results .res-head {
    display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap;
    padding: 10px 16px 6px; background: #F6FAF8; border-top: 1px solid var(--line);
}
.results .res-head:first-child { border-top: 0; }
.results .res-head strong { overflow-wrap: anywhere; }
.results .res-head span { font-size: 13px; color: var(--muted); }
.results .res-head + li { border-top: 0; }
.result.variant { padding: 10px 16px 10px 28px; align-items: center; }
.var-facts { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: baseline; }
.fact { font-size: 14px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.fact i { font-style: normal; color: var(--muted); font-size: 12px; margin-right: 4px; }
.var-rate { font-weight: 700; }

/* ---------- wholesaler viewing a shop ---------- */
.viewing-banner {
    display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap;
    background: var(--amber-tint); color: var(--amber); border-radius: var(--r); padding: 10px 14px; margin-bottom: 16px;
}
.viewing-banner form { margin: 0; }
.viewing-banner .btn { border-color: #E8C98A; color: var(--amber); }

/* ---------- salesman logins in red ---------- */
.user-row.is-salesman { background: var(--rose-tint); box-shadow: inset 4px 0 0 var(--rose); }
.user-row.is-salesman .avatar-sm { background: var(--rose); color: #fff; }
.user-row.is-salesman .row-main strong { color: var(--rose); }
a.rail-logout { text-decoration: none; }
.viewing-banner a.btn { border-color: #E8C98A; color: var(--amber); }
