/* Hand-written stylesheet (CSP: no CDN, no inline styles, Node/Tailwind not installed). Mirrors the Nexus staff app look:
   slate palette, dark sidebar, white cards, orange accents. Colours chosen for >= 4.5:1 text contrast. */
:root {
    --slate-50: #f8fafc; --slate-100: #f1f5f9; --slate-200: #e2e8f0; --slate-300: #cbd5e1; --slate-500: #64748b;
    --slate-600: #475569; --slate-700: #334155; --slate-800: #1e293b; --slate-900: #0f172a;
    --orange: #f97316; --brand: #c2410c; --brand-dark: #9a3412;
    --bad: #b91c1c; --good: #166534;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(15, 23, 42, .06);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif; color: var(--slate-900); background: var(--slate-100); line-height: 1.5; font-size: 15px; }
a { color: var(--brand); text-underline-offset: 2px; }
a:hover { color: var(--brand-dark); }
:focus-visible { outline: 3px solid var(--orange); outline-offset: 2px; border-radius: 4px; }
.sidebar :focus-visible { outline-color: #fff; }
.skip { position: absolute; left: -9999px; top: 8px; background: #fff; color: var(--slate-900); padding: 8px 12px; border-radius: 6px; z-index: 50; }
.skip:focus { left: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- App shell (signed in) ---------- */
.app { min-height: 100vh; }
.sidebar { background: var(--slate-900); color: #cbd5e1; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 12px; padding: 8px 12px 0; border-bottom: 3px solid var(--orange); }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-weight: 600; }
.brand:hover { color: #fff; }
.logo-tile { background: #fff; border-radius: 8px; padding: 3px 6px; display: inline-flex; }
.logo-tile img { height: 26px; width: auto; display: block; }
.brand-name { font-size: .95rem; letter-spacing: .01em; }
.nav { order: 3; flex: 1 0 100%; display: flex; gap: 2px; overflow-x: auto; padding: 4px 0 8px; scrollbar-width: thin; }
.nav a { display: flex; align-items: center; gap: 8px; padding: 8px 12px; color: #e2e8f0; text-decoration: none; border-radius: 6px; white-space: nowrap; font-size: .9rem; font-weight: 500; border-bottom: 2px solid transparent; }
.nav a:hover { background: var(--slate-800); color: #fff; }
.nav a[aria-current=page] { background: var(--slate-700); color: #fff; border-bottom-color: var(--orange); }
.ico { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.userblock { display: flex; align-items: center; gap: 10px; }
.userblock .who { display: none; }
.userblock form { margin: 0; }
.signout { margin: 0; padding: 6px 10px; background: transparent; color: #e2e8f0; border: 1px solid var(--slate-600); border-radius: 6px; font-size: .85rem; font-weight: 500; }
.signout:hover { background: var(--slate-800); color: #fff; }
.main-col { min-width: 0; }
.topbar { background: #fff; border-bottom: 1px solid var(--slate-200); padding: 12px 16px; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.topbar-title { margin: 0; font-size: 1.05rem; font-weight: 600; }
.topbar-user { font-size: .85rem; color: var(--slate-600); }
main { padding: 16px; }

@media (min-width: 1024px) {
    .app { display: flex; }
    .sidebar { position: sticky; top: 0; height: 100vh; width: 240px; flex: none; flex-direction: column; align-items: stretch; justify-content: flex-start; flex-wrap: nowrap; gap: 8px; padding: 20px 12px 16px; border-bottom: 0; }
    .brand { padding: 0 8px 16px; border-bottom: 1px solid var(--slate-800); margin-bottom: 8px; }
    .logo-tile img { height: 30px; }
    .nav { order: 0; flex: 1; flex-direction: column; overflow: visible; padding: 0; gap: 2px; }
    .nav a { border-bottom: 0; border-left: 2px solid transparent; border-radius: 0 6px 6px 0; padding: 10px 12px; }
    .nav a[aria-current=page] { border-left-color: var(--orange); }
    .userblock { flex-direction: column; align-items: stretch; gap: 8px; padding: 12px 8px 0; border-top: 1px solid var(--slate-800); }
    .userblock .who { display: block; color: #fff; font-size: .85rem; overflow-wrap: anywhere; }
    .userblock .who small { display: block; color: #cbd5e1; font-size: .75rem; }
    .signout { width: 100%; text-align: left; }
    .main-col { flex: 1; }
    .topbar { padding: 14px 32px; }
    main { padding: 24px 32px 48px; }
}

/* ---------- Signed-out pages ---------- */
.guest-wrap { max-width: 480px; margin: 0 auto; padding: 32px 16px 48px; }
.guest-brand { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-bottom: 20px; text-align: center; }
.guest-brand img { height: 56px; width: auto; }
.guest-brand span { font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; color: var(--slate-600); font-weight: 600; }
.guest-wrap main { padding: 0; }
.guest-wrap .card.narrow { max-width: none; }

/* ---------- Cards, type ---------- */
.card { background: #fff; border: 1px solid var(--slate-200); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; box-shadow: var(--shadow); }
.card.narrow { max-width: 440px; margin-left: auto; margin-right: auto; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
h1 { margin: 0 0 8px; font-size: 1.4rem; font-weight: 700; letter-spacing: -.01em; }
h2 { margin: 0 0 12px; font-size: 1.05rem; font-weight: 600; }
.eyebrow { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--slate-600); font-weight: 600; }
.small { font-size: .875rem; color: var(--slate-600); }
.page-head { margin-bottom: 16px; }
.page-head h1 { margin-bottom: 4px; }
.page-head p { margin: 4px 0 0; }
.back { display: inline-block; margin-bottom: 12px; font-size: .9rem; }
.empty { text-align: center; padding: 28px 12px; color: var(--slate-600); margin: 0; }
.empty strong { display: block; color: var(--slate-900); margin-bottom: 4px; }
code { background: var(--slate-100); padding: 2px 6px; border-radius: 4px; word-break: break-all; }
ul.codes { columns: 2; list-style: none; padding: 0; }
details { margin: 16px 0; }
.cf-turnstile { margin-top: 16px; }
.qr svg, .qr img { max-width: 100%; height: auto; }

/* ---------- Forms and buttons ---------- */
label { display: block; margin: 16px 0 4px; font-weight: 600; font-size: .9rem; }
label.choice, label.check { font-weight: 400; margin: 8px 0; }
input[type=email], input[type=password], input[type=text], input:not([type]) { width: 100%; padding: 10px 12px; border: 1px solid var(--slate-300); border-radius: 8px; font: inherit; background: #fff; color: var(--slate-900); }
input[inputmode=numeric] { width: 100%; padding: 10px 12px; border: 1px solid var(--slate-300); border-radius: 8px; font: inherit; letter-spacing: .2em; }
input:focus { outline: 3px solid var(--orange); outline-offset: 0; border-color: var(--slate-700); }
input[type=checkbox], input[type=radio] { accent-color: var(--brand); width: 16px; height: 16px; vertical-align: -3px; margin-right: 6px; }
fieldset { border: 1px solid var(--slate-300); border-radius: 8px; margin: 20px 0; padding: 8px 16px 12px; }
button, .button { display: inline-flex; align-items: center; gap: 8px; margin-top: 20px; padding: 10px 18px; background: var(--brand); color: #fff; border: 0; border-radius: 8px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
button:hover, .button:hover { background: var(--brand-dark); color: #fff; }
button.secondary, .button.secondary { background: #fff; color: var(--slate-800); border: 1px solid var(--slate-300); }
button.secondary:hover, .button.secondary:hover { background: var(--slate-100); color: var(--slate-900); }
button.link { background: none; color: var(--brand); padding: 0; margin: 0; font-weight: 400; text-decoration: underline; display: inline; }
form.inline { display: inline; margin: 0; }
.notice { border-radius: 8px; padding: 8px 16px; margin: 16px 0; border: 1px solid; }
.notice p { margin: 8px 0; }
.notice.error { color: var(--bad); border-color: #fca5a5; background: #fef2f2; }
.notice.ok { color: var(--good); border-color: #86efac; background: #f0fdf4; }
.btn-pdf { margin: 0; padding: 6px 12px; font-size: .85rem; white-space: nowrap; }
.btn-pdf::before { content: ""; width: 14px; height: 14px; background: no-repeat center / contain url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 4v11m0 0l-4-4m4 4l4-4M5 20h14'/%3E%3C/svg%3E"); }
.filters { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: flex-end; margin-bottom: 16px; padding-bottom: 16px; border-bottom: 1px solid var(--slate-200); }
.filters .field { flex: 1 1 240px; }
.filters label { margin-top: 0; }
.filters button { margin: 0; }
.filters label.check { margin: 0 0 10px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--slate-200); vertical-align: top; }
thead th { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--slate-600); background: var(--slate-50); font-weight: 600; white-space: nowrap; }
tbody tr:hover { background: var(--slate-50); }
tbody tr:last-child td { border-bottom: 0; }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
.pager { display: flex; gap: 16px; align-items: center; justify-content: space-between; margin-top: 16px; }

/* ---------- Badges ---------- */
.badge, .status { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: .8rem; font-weight: 600; white-space: nowrap; background: var(--slate-100); color: var(--slate-700); }
.badge::before, .status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }
.badge-received, .badge-in-progress { background: var(--slate-100); color: var(--slate-700); }
.badge-in-production { background: #dbeafe; color: #1e40af; }
.badge-on-hold { background: #fef3c7; color: #92400e; }
.badge-part-despatched { background: #e0e7ff; color: #3730a3; }
.badge-despatched { background: #dcfce7; color: #166534; }
.badge-due { background: var(--slate-100); color: var(--slate-700); }
.badge-late-1 { background: #fef3c7; color: #92400e; }
.badge-late-2 { background: #ffedd5; color: #9a3412; }
.badge-late-3 { background: #fee2e2; color: #991b1b; }
.badge-credit { background: #dcfce7; color: #166534; }

/* ---------- Tiles ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(135px, 1fr)); gap: 12px; margin-bottom: 20px; }
.tile { display: block; background: #fff; border: 1px solid var(--slate-200); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); color: inherit; text-decoration: none; border-top: 3px solid var(--slate-300); }
a.tile:hover { border-top-color: var(--orange); color: inherit; }
.tile .label { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--slate-600); font-weight: 600; }
.tile .big { font-size: 1.3rem; font-weight: 700; line-height: 1.3; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.tile .sub { font-size: .8rem; color: var(--slate-600); }
.tile.b1 { background: #fffbeb; border-top-color: #f59e0b; }
.tile.b2 { background: #fff7ed; border-top-color: #f97316; }
.tile.b3 { background: #fef2f2; border-top-color: #ef4444; }
.tile.b4 { background: #fee2e2; border-top-color: #b91c1c; }
.tile.warn { border-top-color: #f97316; }
.tile.bad { border-top-color: #b91c1c; }
.tiles.five { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }

/* ---------- Facts ---------- */
.facts, dl { display: grid; grid-template-columns: 1fr; gap: 2px 24px; margin: 0; }
.facts dt, dl dt { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--slate-600); font-weight: 600; margin-top: 10px; }
.facts dt { margin-top: 0; }
.facts { gap: 14px 24px; }
h2.eyebrow, h3.eyebrow { margin: 20px 0 8px; }
.facts dd, dl dd { margin: 0; }
.order-title { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.order-title h1 { margin: 0; }
@media (min-width: 640px) {
    .facts { grid-template-columns: repeat(2, 1fr); }
    dl:not(.facts) { grid-template-columns: max-content 1fr; gap: 8px 24px; }
    dl:not(.facts) dt { margin-top: 0; }
}
@media (min-width: 1024px) { .facts { grid-template-columns: repeat(3, 1fr); } }

/* ---------- Dashboard ---------- */
.grid-2 { display: grid; grid-template-columns: 1fr; gap: 20px; }
.grid-2 > .card { margin-bottom: 0; }
.grid-2 > * { min-width: 0; }
@media (min-width: 1536px) { .grid-2.wide { grid-template-columns: 1fr 1fr; } }
td.nowrap { white-space: nowrap; }
@media (max-width: 640px) { td.nowrap { white-space: normal; } }
.ageing-bar { display: flex; height: 14px; border-radius: 999px; overflow: hidden; background: var(--slate-200); margin: 8px 0 12px; }
.ageing-bar span { display: block; height: 100%; }
.seg0 { background: #94a3b8; } .seg1 { background: #f59e0b; } .seg2 { background: #f97316; } .seg3 { background: #ef4444; } .seg4 { background: #991b1b; }
.legend { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 6px 12px; font-size: .85rem; }
.legend li { display: flex; flex-wrap: wrap; align-items: center; gap: 0 6px; }
.legend i { width: 10px; height: 10px; border-radius: 2px; flex: none; }
.legend .amt { flex-basis: 100%; padding-left: 16px; font-variant-numeric: tabular-nums; font-weight: 600; }
.w-0 { width: 0; } .w-5 { width: 5%; } .w-10 { width: 10%; } .w-15 { width: 15%; } .w-20 { width: 20%; } .w-25 { width: 25%; }
.w-30 { width: 30%; } .w-35 { width: 35%; } .w-40 { width: 40%; } .w-45 { width: 45%; } .w-50 { width: 50%; } .w-55 { width: 55%; }
.w-60 { width: 60%; } .w-65 { width: 65%; } .w-70 { width: 70%; } .w-75 { width: 75%; } .w-80 { width: 80%; } .w-85 { width: 85%; }
.w-90 { width: 90%; } .w-95 { width: 95%; } .w-100 { width: 100%; }

/* ---------- Small screens: stacked tables ---------- */
@media (max-width: 640px) {
    table.stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
    table.stack tr { display: block; border-bottom: 1px solid var(--slate-200); padding: 8px 0; }
    table.stack tbody tr:last-child { border-bottom: 0; }
    table.stack td { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 4px 0; border: 0; text-align: right; }
    table.stack td::before { content: attr(data-label); font-weight: 600; text-align: left; color: var(--slate-600); font-size: .8rem; }
    table.stack td:empty { display: none; }
    .card { padding: 16px; }
}
@media print {
    .sidebar, .topbar, .filters, .pager, form, .skip { display: none; }
    body, .app { background: #fff; display: block; }
    main { padding: 0; }
    .card, .tile { border: 0; box-shadow: none; padding: 0; }
}
.card > form:not(.filters) { max-width: 480px; }
