/* ============================================================
   shared.css — Design tokens + shared header + dashboard tiles
   Used by every page in the unified operations system.
   ============================================================ */

:root {
  --font-aptos: 'Aptos', 'Aptos Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;

  /* Brand colours kept the same — the navy/blue/red trio is part of
     the visual identity. Tints (blue-lt, red-lt, etc.) lightened a
     touch for better contrast with their dark text counterparts on
     small pills + chips. */
  --navy:     #0a1628;
  --navy2:    #0f1f3a;
  --navy3:    #162847;
  --blue:     #1e4780;
  --blue2:    #2b5fa8;
  --blue3:    #2b5fa8;
  --blue-lt:  #dbe7fa;
  --red:      #c0152a;
  --red-lt:   #fbdde2;
  --green:    #15803d;
  --green-lt: #d1ecdc;
  --amber:    #b45309;
  --amber-lt: #fbe5c4;

  --surface:  #ffffff;
  /* App background (page) and panel background (cards-on-page) now
     have a meaningful 4-step luminance gap so a card sitting on the
     page actually reads as a card instead of bleeding into the
     surrounding chrome. */
  --bg:       #eef2f8;
  --bg2:      #e1e7f0;

  /* Borders bumped from "barely visible against white" to "clearly
     visible against white". Hairlines were ~1.15:1 contrast — at
     a normal viewing distance card/input edges effectively didn't
     exist. New values clear ~1.5–1.9:1 which is the modern UI sweet
     spot (still subtle, but reads as a real edge). */
  --border:   #cdd5e3;
  --border2:  #b3bdd0;

  /* Text greys were the main contrast offender. Old values:
       --ink3 #5a6b86 ≈ 4.4:1 (borderline AA — fails for small text)
       --ink4 #8a97ad ≈ 2.8:1 (FAILS AA for normal body text)
     New values clear AA (4.5:1) on white, which is what we need for
     small UI labels + field-help + sub-text. Body/heading colours
     unchanged — they were already strong. */
  --ink:      #0a1628;  /* 17.4:1 — body / headings */
  --ink2:     #2d3f5e;  /* 8.7:1 — secondary body */
  --ink3:     #475569;  /* 6.7:1 — UI labels (was 4.4:1, borderline) */
  --ink4:     #64748b;  /* 4.5:1 — hints + meta (was 2.8:1, failed AA) */

  --r:  4px;
  --r2: 8px;
  /* Subtle inset ring + drop shadow — cards now lift off the page
     instead of looking flush. The ring is the main contrast lever
     (works on darker page backgrounds too); the soft drop carries
     a tiny bit of physicality without being noisy. */
  --sh:  0 1px 2px rgba(10,22,40,.08), 0 0 0 1px rgba(10,22,40,.04);
  --sh2: 0 12px 32px rgba(10,22,40,.22);
}

*, *::before, *::after { box-sizing:border-box; margin:0; padding:0; }
html { scroll-behavior:smooth; }
body.shared-body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-aptos);
  font-size: 15px;
  line-height: 1.55;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  /* Plain zeros — no slash/dot through them. Aptos enables a slashed
     zero ("zero") by default; turn it off ERP-wide. */
  font-feature-settings: "zero" 0;
  font-variant-numeric: normal;
}

/* ── Per-user theme overrides ────────────────────────────────
   Applied by /shared/header.js after auth/me resolves — the
   matched theme name becomes a class on <body>. Adding a new
   one is a) add an entry in USER_THEMES in header.js, and
   b) define the matching --token overrides here.

   theme-pink: requested by Liz/Elizabeth. The token approach
   means every component that already uses --blue3 / --blue /
   --blue-lt for accent gets re-skinned automatically. We swap
   only the blue family + page bg + borders so contrast stays
   readable; ink colours stay the same. */
body.shared-body.theme-pink {
  --blue:     #b8348a;   /* deep magenta-pink, replaces nav blue */
  --blue2:    #d44ea3;
  --blue3:    #d44ea3;
  --blue-lt:  #fde4f1;   /* soft pink tint for chips + soft buttons */
  --bg:       #fdf2f8;   /* page bg — barely-pink */
  --bg2:      #fce7f3;   /* card bg / dividers — slightly more pink */
  --border:   #f3c9dc;
  --border2:  #ec9ec3;
  --navy:     #4a1a32;   /* dark plum — replaces navy headings */
  --navy2:    #5a223e;
  --navy3:    #6a2a4a;
}
/* Header keeps the standard light surface — same as every other page
   and as her own cards. The earlier dark-plum header bar made the pink
   accent text (links, clock, user picker) unreadable; the pink
   border-bottom (--border) already ties the strip into the theme. */
body.shared-body.theme-pink .app-header { background: var(--surface); color: var(--ink); }
body.shared-body.theme-pink .dash-tile { border-left-color: #ec9ec3; }

/* Liz's Diet Coke cursor — applied by setupUserCursor() in header.js,
   toggleable from the wee 🥤 button in the top bar. Same pattern as
   Sanjay's pride cursor on the Sales Station. */
body.cursor-coke, body.cursor-coke * { cursor: url('/diet-coke-cursor.png') 12 3, auto !important; }

.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1, "zero" 0; }

/* ── Shared header ─────────────────────────────────────────── */

.app-header {
  background: var(--surface);
  color: var(--ink);
  height: 68px;
  border-bottom: 1px solid var(--border);
  padding: 0 28px;
  display: flex;
  align-items: center;
  gap: 20px;
  position: sticky;
  top: 0;
  z-index: 300;
  box-shadow: var(--sh);
}

.app-header .ah-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  flex-shrink: 0;
}
/* Renamed from .ah-logo-svg → .ah-logo-img on Apr 28 when the
   inline-SVG SARKAR text logo was replaced with the PNG asset
   at /sarkar-logo.png. Keeping the same 42px display height so
   the rest of the header geometry doesn't shift. */
.app-header .ah-logo-img {
  height: 42px;
  width: auto;
  flex-shrink: 0;
  display: block;
}
.app-header .ah-logo-sub-text {
  font-size: 9px;
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: var(--ink3);
  font-weight: 600;
  border-left: 1px solid var(--border);
  padding-left: 10px;
  line-height: 1.3;
}

.app-header .ah-home-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  flex-shrink: 0;
  padding: 6px 14px;
  border: 1px solid var(--border2);
  background: var(--bg);
  color: var(--ink2);
  text-decoration: none;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  border-radius: var(--r);
  transition: background .12s, border-color .12s;
}
.app-header .ah-home-btn:hover {
  background: var(--bg2);
  border-color: var(--blue3);
  color: var(--blue3);
}
.app-header .ah-home-btn.hidden { display: none; }

.app-header .ah-help-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--border2);
  background: var(--bg);
  color: var(--ink2);
  text-decoration: none;
  font-size: 14px;
  font-weight: 700;
  border-radius: 50%;
  transition: background .12s, border-color .12s;
}
.app-header .ah-help-btn:hover {
  background: var(--bg2);
  border-color: var(--blue3);
  color: var(--blue3);
}

.app-header .ah-center {
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}
.app-header .ah-clock-time,
.app-header .ah-clock-date { width: 100%; text-align: center; }
.app-header .ah-clock-time {
  font-size: 20px;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: 1px;
}
.app-header .ah-clock-date {
  font-size: 11px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--ink3);
  margin-top: 3px;
}
/* Extra world clocks (non-sales users) beside the main Glasgow clock,
   styled to match it. Injected by setupWorldClocks() in header.js. */
.app-header .ah-wc {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 0 16px; line-height: 1.15; font-variant-numeric: tabular-nums;
}
.app-header .ah-wc-time { font-size: 17px; font-weight: 600; color: var(--ink2); letter-spacing: .5px; }
.app-header .ah-wc-sub  { font-size: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 1.2px; color: var(--ink3); margin-top: 2px; }
/* Glasgow (the middle clock) is the prominent one — a size up + bolder. */
.app-header .ah-center.ah-center-main .ah-clock-time { font-size: 28px; }
.app-header .ah-center.ah-center-main .ah-clock-date { font-size: 12px; }
@media (max-width: 760px) {
  .app-header .ah-wc { padding: 0 9px; }
  .app-header .ah-wc-time { font-size: 14px; }
  .app-header .ah-wc-sub  { font-size: 9px; }
  .app-header .ah-center.ah-center-main .ah-clock-time { font-size: 20px; }
}

.app-header .ah-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.app-header .ah-user {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border2);
  border-radius: var(--r);
  padding: 5px 10px 5px 14px;
  min-width: 180px;
}
.app-header .ah-user.unset {
  background: var(--red-lt);
  border-color: rgba(192,21,42,.4);
}
.app-header .ah-user label {
  font-size: 10px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
  color: var(--ink4);
  font-weight: 600;
}
.app-header .ah-user select,
.app-header .ah-user input {
  background: transparent;
  border: none;
  color: var(--ink);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  outline: none;
  min-width: 90px;
}

.ah-status {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 6px 12px;
  background: var(--bg);
  border: 1px solid var(--border2);
  border-radius: var(--r);
  font-size: 11px;
  line-height: 1.3;
  min-width: 180px;
}
.ah-status.ok     { border-color: rgba(34,197,94,.4); background: var(--green-lt); }
.ah-status.warn   { border-color: rgba(245,158,11,.45); background: var(--amber-lt); }
.ah-status.down   { border-color: rgba(192,21,42,.5); background: var(--red-lt); }
.ah-status-head {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: .5px;
  text-transform: uppercase;
  font-size: 10px;
}
.ah-status-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #6b7a90;
  flex-shrink: 0;
}
.ah-status.ok   .ah-status-dot { background: #22c55e; }
.ah-status.warn .ah-status-dot { background: #f59e0b; }
.ah-status.down .ah-status-dot { background: #ef4444; }
.ah-status-line {
  color: var(--ink3);
  font-size: 10.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 240px;
}
.ah-status-line strong {
  color: var(--ink2);
  font-weight: 600;
  letter-spacing: .3px;
  margin-right: 4px;
}

/* ── Dashboard tiles ──────────────────────────────────────── */

.dash-main {
  padding: 40px 32px 64px;
  max-width: 1650px;   /* widened ~25% for large screens */
  margin: 0 auto;
}
.dash-intro {
  margin-bottom: 32px;
}
.dash-intro h1 {
  font-size: 28px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -.2px;
}
.dash-intro p {
  color: var(--ink3);
  margin-top: 6px;
  font-size: 14px;
}
.dash-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 18px;
}
/* Multi-line sections (e.g. Recipes & Patterns, Shipping) stack several
   .dash-tiles rows under one label — keep the same 18px rhythm between
   rows as within them. */
.dash-tiles + .dash-tiles { margin-top: 18px; }
/* "split" variant — used on rows where one tile (e.g. Pricing Engine)
   sits visually apart from its neighbours. Flexbox + margin-left:auto
   on the .pin-right tile pushes it to the right edge of the row,
   leaving a visible gap when there's spare width. Falls back to
   normal wrapping on narrow viewports. */
.dash-tiles.split-row {
  display: flex; flex-wrap: wrap; gap: 18px;
}
.dash-tiles.split-row > .dash-tile {
  flex: 1 1 280px; min-width: 280px; max-width: 420px;
}
.dash-tiles.split-row > .pin-right { margin-left: auto; }
.dash-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 22px 22px 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r2);
  box-shadow: var(--sh);
  text-decoration: none;
  color: inherit;
  min-height: 124px;
  transition: border-color .15s, box-shadow .15s, transform .1s;
}
.dash-tile:hover {
  border-color: var(--blue3);
  box-shadow: var(--sh2);
  transform: translateY(-1px);
}
.dash-tile.disabled {
  pointer-events: none;
  opacity: .58;
  background: var(--bg2);
}
.dash-tile-num {
  /* The little "01 / 02 / 03…" reference numbers (and a handful of
     duplicate emoji icons) used to live in the top-right corner of
     every home-page tile. Operators don't navigate by number — the
     tile title is the affordance — so the numbers were just visual
     noise. Hidden globally rather than stripped from the markup so
     re-enabling is one CSS line if we ever need them back. */
  display: none;
  position: absolute;
  top: 12px;
  right: 14px;
  font-size: 11px;
  font-weight: 700;
  color: var(--ink4);
  letter-spacing: 1px;
}
.dash-tile-icon {
  font-size: 24px;
  line-height: 1;
  margin-bottom: 8px;
}
.dash-tile-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: -.1px;
}
.dash-tile-sub {
  font-size: 12.5px;
  color: var(--ink3);
  line-height: 1.45;
}
.dash-tile-badge {
  align-self: flex-start;
  margin-top: 6px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--amber);
  background: var(--amber-lt);
  border: 1px solid rgba(180,83,9,.3);
  padding: 3px 8px;
  border-radius: 3px;
}
.dash-tile-badge.live {
  color: var(--green);
  background: var(--green-lt);
  border-color: rgba(21,128,61,.25);
}

/* ── Generic page shell ───────────────────────────────────── */

.page-main {
  padding: 32px 28px 64px;
  max-width: 1750px;   /* widened ~25% for large screens */
  margin: 0 auto;
}

/* Prominent back row — sits at the top of a detail page, ABOVE the
   page-header. Big, top-left, hard to mis-click. Used by item /
   order / sample / reservation detail pages where the small "Back"
   button kept getting confused with the home-tile click target. */
.back-bar { margin-bottom: 14px; }
.btn-back-prominent {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: var(--r);
  font-family: var(--font-aptos);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  transition: background .12s, border-color .12s, transform .08s;
  box-shadow: var(--sh);
}
.btn-back-prominent:hover {
  background: var(--bg2);
  border-color: var(--blue3);
  color: var(--blue3);
}
.btn-back-prominent:active { transform: translateY(1px); }
.btn-back-prominent .arrow {
  font-size: 18px; line-height: 1; font-weight: 900;
  color: var(--blue3);
}

/* Breadcrumb trail rendered by /shared/back-button.js — replaces the
   single .btn-back-prominent so users see every level back to the
   dashboard and can click any of them. The first link keeps the
   leading arrow so the bar still reads as a "back" affordance at a
   glance. */
.breadcrumb {
  display: inline-flex; align-items: center; flex-wrap: wrap;
  gap: 6px;
  padding: 8px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  font-family: var(--font-aptos);
  font-size: 13px;
  box-shadow: var(--sh);
  max-width: 100%;
}
.breadcrumb .bc-link {
  color: var(--ink2); text-decoration: none; font-weight: 600;
  padding: 2px 6px; border-radius: 4px;
  display: inline-flex; align-items: center; gap: 4px;
  transition: background .12s, color .12s;
}
.breadcrumb .bc-link:hover {
  background: var(--bg2); color: var(--blue3);
}
.breadcrumb .bc-link .arrow {
  font-size: 14px; font-weight: 900; color: var(--blue3);
  margin-right: 2px;
}
/* The leading ← (up one level) reads as a distinct control: a hairline
   divider separates it from the breadcrumb crumbs that follow. */
.breadcrumb .bc-back {
  margin-right: 4px; padding-right: 8px;
  border-right: 1px solid var(--border);
}
.breadcrumb .bc-back .arrow { margin-right: 0; }
/* Single "Return" button (back-button.js renders just this one link). */
.breadcrumb .bc-back-single { font-weight: 700; gap: 5px; }
.breadcrumb .bc-back-single .arrow { margin-right: 2px; }
.breadcrumb .bc-sep {
  color: var(--ink4); font-weight: 700; user-select: none;
  padding: 0 2px;
}
.breadcrumb .bc-current {
  color: var(--ink); font-weight: 700;
  padding: 2px 6px;
}

.page-header {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}
.page-header h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -.2px;
  color: var(--ink);
}
.page-header .page-sub {
  color: var(--ink3);
  font-size: 13px;
  margin-top: 2px;
}
.page-header .page-actions {
  margin-left: auto;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

/* ── Cards / panels ───────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r2);
  box-shadow: var(--sh);
  overflow: hidden;
}
/* Use the general sibling combinator (~) instead of adjacent (+) so
   the spacing still applies when a `<style>` block (or any non-card
   element) sits between two cards. The order page has scoped style
   blocks per card section — `.card + .card` was silently dropping
   the margin between, e.g., Order progress and Stock used because a
   <style> tag interrupted the adjacency. */
.card ~ .card { margin-top: 18px; }
.card-head {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}
.card-head h2 {
  font-size: 14px;
  font-weight: 700;
  color: var(--ink);
  letter-spacing: .3px;
  text-transform: uppercase;
}
.card-head .card-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.card-body { padding: 20px; }
.card-body.slim { padding: 14px 20px; }

/* ── Buttons ──────────────────────────────────────────────── */

/* ── Button hierarchy ─────────────────────────────────────
 * Five intentional levels, matched to Nielsen's "consistency &
 * standards" + "recognition rather than recall":
 *
 *   .btn-primary  — blue, the ONE main action of a page (Save,
 *                   Generate, Open, Apply). Visible weight: shadow +
 *                   bold + larger padding. Operator's eye should
 *                   land on this without reading.
 *   .btn-success  — green, affirmative confirmations (Send to Order,
 *                   Mark complete, Confirm). Distinct from blue so
 *                   a "commit a change" reads differently from a
 *                   "main page action".
 *   .btn-danger   — red, destructive (Delete, Discard).
 *   .btn          — neutral default, secondary actions sitting next
 *                   to a primary. Quieter background so they don't
 *                   compete with the primary's saturation.
 *   .btn-ghost    — text-only tertiary (Cancel, Close, Reset). No
 *                   border, no fill — just enough hover affordance
 *                   to know it's clickable.
 *
 * Touch target ≥ 32px tall (was 30 — easier to hit on a trackpad
 * and meets WCAG's 24px minimum with comfortable padding).
 */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border2);
  background: var(--bg2);
  color: var(--ink);
  font-family: var(--font-aptos);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .2px;
  padding: 8px 16px;
  border-radius: var(--r);
  cursor: pointer;
  transition: background .12s, border-color .12s, color .12s, transform .06s, box-shadow .12s;
  text-decoration: none;
  min-height: 32px;
}
.btn:hover { border-color: var(--blue3); background: var(--surface); color: var(--blue3); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

/* Primary — the page's main action. The shadow + bigger padding
   give it real visual weight so the operator picks it out at a
   glance (the user's "logical things to click are not sticking
   out" complaint comes down to this button being too quiet). */
.btn-primary {
  background: var(--blue3); color: #fff; border-color: var(--blue3);
  font-weight: 700; padding: 9px 18px;
  box-shadow: 0 2px 6px rgba(43,95,168,.25);
}

/* Export / download actions — deliberately distinct from the grey
   default so "get it out of the system" buttons (PDF, Excel, CSV,
   downloads) are findable at a glance. Deep teal: not the blue of
   the page's ONE primary action, not the green of stock-in. */
.btn-export {
  background: #0e7490; color: #fff; border-color: #0e7490;
  font-weight: 700;
  box-shadow: 0 2px 6px rgba(14,116,144,.25);
}
.btn-export:hover {
  background: #155e75; border-color: #155e75; color: #fff;
  box-shadow: 0 4px 10px rgba(14,116,144,.35);
}
.btn-primary:hover {
  background: #214d93; border-color: #214d93; color: #fff;
  box-shadow: 0 4px 10px rgba(43,95,168,.35);
}
.btn-primary:active { box-shadow: 0 1px 3px rgba(43,95,168,.3); }

/* Success — green affirmative action. Same weight as primary so
   it feels equally "clickable", colour shifted to green so an
   operator can tell at a glance that this commits / saves / sends
   rather than navigates. */
.btn-success {
  background: #15803d; color: #fff; border-color: #14532d;
  font-weight: 700; padding: 9px 18px;
  box-shadow: 0 2px 6px rgba(21,128,61,.28);
}
.btn-success:hover {
  background: #166534; border-color: #14532d; color: #fff;
  box-shadow: 0 4px 10px rgba(21,128,61,.4);
}
.btn-success:active { box-shadow: 0 1px 3px rgba(21,128,61,.3); }

/* Danger — destructive. Same prominence as primary so the user
   sees it but the colour signals "careful". */
.btn-danger {
  background: var(--red); color: #fff; border-color: var(--red);
  font-weight: 700;
  box-shadow: 0 2px 6px rgba(192,21,42,.22);
}
.btn-danger:hover {
  background: #970f20; border-color: #970f20; color: #fff;
  box-shadow: 0 4px 10px rgba(192,21,42,.32);
}

/* Ghost — text-only tertiary. */
.btn-ghost {
  background: transparent; border-color: transparent; color: var(--ink2);
  box-shadow: none;
}
.btn-ghost:hover {
  background: var(--bg2); color: var(--ink); border-color: transparent;
}

.btn-outline { background: transparent; }
.btn-sm { padding: 6px 12px; font-size: 12px; min-height: 28px; }
.btn-sm.btn-primary, .btn-sm.btn-success, .btn-sm.btn-danger { padding: 6px 12px; }
.btn-xs { padding: 4px 9px; font-size: 11px; min-height: 24px; }
.btn-xs.btn-primary, .btn-xs.btn-success, .btn-xs.btn-danger { padding: 4px 9px; }
.btn-icon { padding: 6px 8px; }

/* ── Form inputs ──────────────────────────────────────────── */

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px 18px;
}
.form-grid.wide { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.form-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.form-field.col-2 { grid-column: span 2; }
.form-field label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--ink3);
}
.form-field .field-help {
  font-size: 11px;
  color: var(--ink4);
  margin-top: -2px;
}
.form-input,
.form-select,
.form-textarea {
  width: 100%;
  background: var(--surface);
  /* Stronger default border so empty fields read as fields, not as
     bare text. Was border2 (~1.4:1) — now the same darker grey that
     other UI edges use. */
  border: 1px solid var(--border2);
  border-radius: var(--r);
  padding: 9px 12px;
  font-family: var(--font-aptos);
  font-size: 14px;
  color: var(--ink);
  outline: none;
  transition: border-color .12s, box-shadow .12s;
}
.form-input:hover,
.form-select:hover,
.form-textarea:hover { border-color: #8a97ad; }
.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--blue3);
  /* Heavier focus ring (was .12 alpha) so keyboard + low-vision users
     can clearly see which field is active. */
  box-shadow: 0 0 0 3px rgba(43,95,168,.22);
}
.form-input::placeholder,
.form-textarea::placeholder { color: var(--ink4); }
.form-textarea { min-height: 80px; resize: vertical; font-family: inherit; }
.form-row-flex {
  display: flex;
  gap: 10px;
  align-items: stretch;
}
.form-row-flex > .form-input,
.form-row-flex > .form-select { flex: 1; min-width: 0; }
.form-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--ink2);
  cursor: pointer;
}

/* ── Tables ───────────────────────────────────────────────── */

.data-table-wrap { overflow-x: auto; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table thead th {
  text-align: left;
  padding: 10px 12px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--ink3);
  white-space: nowrap;
}
.data-table tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  color: var(--ink);
}
.data-table tbody tr:hover { background: #f8fafc; }
.data-table tbody tr.sel { background: #eaf1fb; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1, "zero" 0; }
.data-table .thin { color: var(--ink4); }
.data-table .actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
  white-space: nowrap;
}
.data-table input,
.data-table select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border2);
  border-radius: 3px;
  font-size: 12.5px;
  font-family: inherit;
  background: var(--surface);
}
.data-table input:focus,
.data-table select:focus { outline: none; border-color: var(--blue3); }
.empty-row td {
  color: var(--ink4);
  font-style: italic;
  text-align: center;
  padding: 26px 10px;
}

/* ── Status pills / badges ────────────────────────────────── */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .8px;
  text-transform: uppercase;
  border: 1px solid var(--border2);
  background: var(--bg2);
  color: var(--ink2);
  white-space: nowrap;
}
.pill.blue  { background: var(--blue-lt); color: var(--blue); border-color: rgba(30,71,128,.22); }
.pill.green { background: var(--green-lt); color: var(--green); border-color: rgba(21,128,61,.22); }
.pill.amber { background: var(--amber-lt); color: var(--amber); border-color: rgba(180,83,9,.22); }
.pill.red   { background: var(--red-lt);   color: var(--red);   border-color: rgba(192,21,42,.22); }

/* ── Search box ───────────────────────────────────────────── */

.search-input {
  min-width: 260px;
  padding: 9px 12px;
  border: 1px solid var(--border2);
  border-radius: var(--r);
  font-size: 13px;
  font-family: inherit;
  background: var(--surface);
}
.search-input:focus { outline: none; border-color: var(--blue3); }

/* ── Inline typeahead picker ──────────────────────────────── */

.picker {
  position: relative;
}
.picker-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 260px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: var(--r);
  box-shadow: var(--sh2);
  z-index: 200;
  display: none;
}
.picker-list.open { display: block; }
.picker-item {
  padding: 9px 12px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  color: var(--ink);
}
.picker-item:last-child { border-bottom: none; }
.picker-item:hover,
.picker-item.active { background: var(--blue-lt); }
.picker-item .picker-sub {
  color: var(--ink4);
  font-size: 11px;
  margin-top: 2px;
}

/* ── Split layouts ────────────────────────────────────────── */

.split {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 18px;
}
@media (max-width: 980px) { .split { grid-template-columns: 1fr; } }

/* ── Anti-flash auth gate ─────────────────────────────────────
   Pages with the shared header stay invisible until header.js has
   confirmed the session (it adds .auth-ok to <body>), so an
   anonymous visitor never glimpses ERP content before the PIN page
   redirect. Standalone pages without #app-header are unaffected,
   and header.js carries a failsafe reveal in case the API hangs. */
body.shared-body:has(#app-header):not(.auth-ok) { visibility: hidden; }

/* ── Dialogs (basic) ──────────────────────────────────────── */

.dialog-backdrop {
  position: fixed; inset: 0;
  background: rgba(10,22,40,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 900;
}
.dialog {
  background: var(--surface);
  border-radius: var(--r2);
  box-shadow: var(--sh2);
  width: min(560px, 92vw);
  max-height: 90vh;
  overflow: auto;
}
.dialog .card-head { position: sticky; top: 0; background: var(--surface); z-index: 1; }

/* ── Responsive stack ─────────────────────────────────────────
   Two breakpoints:
     ≤ 900px — tablets, small laptops. Soften spacing.
     ≤ 640px — phones. Full reflow: header stacks, page actions wrap
               into a full-width button row, forms collapse to one
               column, tables announce their horizontal scroll, dash
               tiles become a single column. */

@media (max-width: 900px) {
  .app-header {
    height: auto;
    flex-wrap: wrap;
    padding: 10px 16px;
    gap: 10px;
  }
  .app-header .ah-center { order: 10; margin: 4px auto 0; flex-basis: 100%; }
  .dash-main { padding: 24px 16px 48px; }
  .page-main { padding: 20px 14px 48px; }
  .form-field.col-2 { grid-column: auto; }
  .form-grid { gap: 12px 14px; }
  .page-header h1 { font-size: 21px; }
  .page-header .page-sub { font-size: 12px; }
  .card-head { padding: 12px 16px; }
  .card-body { padding: 16px; }
}

@media (max-width: 640px) {
  :root { --r: 7px; --r2: 10px; }

  /* ── Top bar ────────────────────────────────────────────── */
  /* Phone header = two clean rows:
       row 1 — the clocks (Brasília | Glasgow | Plano), centred
       row 2 — ← Dashboard on the left, user name on the right
     Logo and the Live/status pill are hidden: on a phone they only
     eat vertical space, and the status detail lives on System. */
  .app-header {
    padding: 8px 12px;
    gap: 8px;
    row-gap: 8px;
  }
  .app-header .ah-logo { display: none; }
  .app-header .ah-status { display: none; }
  /* Row 1 — clock trio. header.js puts auto-margins on the outer
     chips, which centres the group once it owns the row. */
  .app-header .ah-center, .app-header .ah-wc { order: 1; }
  .app-header .ah-center { font-size: 12px; flex-basis: auto; margin: 0 10px; }
  .app-header .ah-wc { margin-top: 0; }
  .app-header .ah-clock-time { font-size: 16px; letter-spacing: .5px; }
  .app-header .ah-clock-date { font-size: 10px; letter-spacing: 1px; margin-top: 1px; }
  /* Invisible full-width flex item: forces the wrap between the
     clock row and the dashboard/user row. */
  .app-header::after { content: ''; order: 1; flex-basis: 100%; height: 0; }
  /* Row 2 — dashboard left, user right */
  .app-header .ah-home-btn { order: 2; margin-right: auto; padding: 5px 10px; font-size: 10px; }
  .app-header .ah-help-btn { order: 2; width: 26px; height: 26px; font-size: 13px; }
  .app-header .ah-right { order: 3; margin-left: auto; gap: 6px; flex-wrap: wrap; }
  .app-header .ah-user { min-width: 0; padding: 4px 8px 4px 10px; }
  .app-header .ah-user label { font-size: 9px; letter-spacing: 1px; }
  .app-header .ah-user select,
  .app-header .ah-user input { font-size: 12px; min-width: 70px; }

  /* ── Page chrome ────────────────────────────────────────── */
  .page-main, .dash-main { padding: 14px 12px 40px; }
  .page-header {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    margin-bottom: 16px;
  }
  .page-header > div:first-child { min-width: 0; }
  .page-header h1 { font-size: 20px; letter-spacing: -.1px; }
  .page-header .page-sub {
    font-size: 12px;
    line-height: 1.45;
    /* Long help copy gets two lines max on phones to keep the
       actions button row within thumb reach. */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .page-header .page-actions {
    margin-left: 0;
    width: 100%;
    gap: 6px;
  }
  /* Buttons in the page-actions row grow to share the width so
     each tap target is ≥ 40px tall on phones — no more 80-character
     labels overflowing a 120-wide button. */
  .page-header .page-actions > .btn,
  .page-header .page-actions > a.btn {
    flex: 1 1 auto;
    min-height: 40px;
    padding: 8px 12px;
    font-size: 13px;
  }

  /* ── Cards ──────────────────────────────────────────────── */
  .card ~ .card { margin-top: 12px; }
  .card-head {
    padding: 11px 14px;
    gap: 8px;
    flex-wrap: wrap;
  }
  .card-head h2 { font-size: 13px; letter-spacing: .2px; }
  .card-head .card-actions {
    margin-left: 0;
    gap: 6px;
  }
  .card-body { padding: 14px; }
  .card-body.slim { padding: 10px 14px; }

  /* ── Forms ──────────────────────────────────────────────── */
  .form-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .form-grid.wide { grid-template-columns: 1fr; }
  .form-field label { font-size: 10px; }
  .form-input, .form-select, .form-textarea {
    padding: 10px 12px;
    font-size: 16px; /* iOS auto-zooms the viewport for ANY field under 16px */
  }
  .form-textarea { min-height: 70px; }
  /* Same iOS-zoom guard for the other frequently-typed fields: in-table
     cell inputs (order lines, variants, CIPL) and the list search boxes. */
  .data-table input, .data-table select { font-size: 16px; }
  .search-input { font-size: 16px; }

  /* ── Buttons — tap-target friendly ─────────────────────── */
  .btn {
    min-height: 40px;
    padding: 8px 14px;
    font-size: 13px;
  }
  .btn-sm { min-height: 34px; padding: 6px 10px; font-size: 12px; }
  .btn-xs { min-height: 28px; padding: 4px 8px; font-size: 11px; }
  .btn-icon { min-height: 36px; padding: 6px 8px; }

  /* ── Tables ─────────────────────────────────────────────── */
  /* Wrap any table that scrolls with a subtle gradient hint so
     users realise they can swipe. Non-invasive — only shows when
     the content actually overflows. */
  .data-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    background:
      linear-gradient(to right, var(--surface) 30%, rgba(255,255,255,0)),
      linear-gradient(to right, rgba(255,255,255,0), var(--surface) 70%) 100% 0,
      linear-gradient(to right, rgba(10,22,40,.08), rgba(10,22,40,0) 20px),
      linear-gradient(to left,  rgba(10,22,40,.08), rgba(10,22,40,0) 20px) 100% 0;
    background-repeat: no-repeat;
    background-size: 30px 100%, 30px 100%, 20px 100%, 20px 100%;
    background-attachment: local, local, scroll, scroll;
  }
  .data-table { font-size: 12px; }
  .data-table th, .data-table td { padding: 7px 8px; }

  /* Belt-and-braces fallback: any table dropped straight into a
     card-body WITHOUT an explicit .data-table-wrap scroll container
     would otherwise blow the page width out on a phone. Making the
     table itself a block-level scroll box keeps its column layout
     intact (rows/cells stay table-internal display types) while
     giving it its own horizontal scroll. Wrapped tables are direct
     children of .data-table-wrap, not .card-body, so they're
     unaffected. */
  .card-body > table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }

  /* ── Dashboard tiles ─────────────────────────────────────── */
  /* Two-up on phones — halves the scroll length of the dashboard
     versus a single tall column. Drops to one column ≤380px. */
  .dash-tiles {
    grid-template-columns: 1fr 1fr !important;
    gap: 10px;
  }
  .dash-tiles.split-row > .dash-tile { flex: 1 1 46%; min-width: 0; max-width: none; }
  .dash-tile { padding: 12px 13px; }
  .dash-tile-num { font-size: 20px; }
  .dash-tile-title { font-size: 14px; }
  .dash-tile-sub {
    font-size: 11.5px; line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .dash-intro h1 { font-size: 22px; }
  .dash-intro p { font-size: 13px; }
  .dash-row-label { font-size: 10px; }

  /* ── Dialogs / modals ─────────────────────────────────────
     On phones modals should feel like a full-screen sheet, not a
     postage-stamp. Width: 100vw, rounded only at the top edge so
     it reads as a bottom sheet / full overlay. */
  .dialog {
    width: 100vw !important;
    max-width: 100vw !important;
    max-height: 100vh;
    height: 100vh;
    border-radius: 0;
    display: flex;
    flex-direction: column;
  }
  .dialog .card-head { padding: 12px 14px; }
  .dialog .card-head h2 { font-size: 14px; }
  .dialog .card-body { padding: 14px; }
  .dialog-backdrop { padding: 0; }

  /* Fields flagged col-2 that SHOULD stretch stay stretched; the
     default form-grid is already 1-col so no change needed. */
  .form-field.col-2 { grid-column: auto; }

  /* Stat cards / chips / pills — keep readable at small size. */
  .stat-strip { grid-template-columns: repeat(2, 1fr) !important; gap: 8px; }
  .stat-card { padding: 10px 12px; }
  .stat-val  { font-size: 18px; }
  .stat-label { font-size: 9px; }
}

/* ── Phone rescue (≤ 640px) ───────────────────────────────────
   Generic safety nets for page-local layouts that predate the
   responsive pass — many pages build desktop grids with inline
   styles or local <style> blocks the shared breakpoints can't
   name. Three nets:
     1. Inline-styled FIXED grids collapse to one column. Fluid
        auto-fit / auto-fill grids already reflow on their own and
        are deliberately excluded.
     2. Filter bars give up their inline min-widths so the fields
        share rows two-up instead of forcing a sideways scroll.
     3. Images never overflow the viewport. */
@media (max-width: 640px) {
  .page-main [style*="grid-template-columns"]:not([style*="auto-fill"]):not([style*="auto-fit"]),
  .dash-main [style*="grid-template-columns"]:not([style*="auto-fill"]):not([style*="auto-fit"]) {
    grid-template-columns: 1fr !important;
  }
  .filter-bar { gap: 8px; }
  .filter-bar .form-field { min-width: 0 !important; flex: 1 1 46%; }
  .filter-bar .form-field .form-input,
  .filter-bar .form-field .form-select { width: 100%; }
  .page-main img, .dash-main img { max-width: 100%; height: auto; }
}

/* ── Extra-small (≤ 380px — old / narrow phones) ─────────── */
@media (max-width: 380px) {
  .page-header .page-actions > .btn { flex-basis: 100%; }
  .dash-tiles { grid-template-columns: 1fr !important; }
  .dash-tile { padding: 12px 14px; }
  .app-header .ah-user { display: none; } /* free up a row — pick user from within pages instead */
}
