/* Bampfylde Order Desk — brand tokens and the three layouts.
 *
 * Palette and type are the official brand (brand/guidelines.md §4–5), not the
 * off-brand tokens the marketing site currently ships. Status colours are
 * marked TO CONFIRM in the guidelines; the green/amber/red below is a
 * placeholder pending that decision, not a sanctioned brand choice.
 */

:root {
  /* Brand */
  --carbon: #0a0e16;
  --navy: #0a2a57;
  --navy-lift: #113a72;
  --signal: #1e5bb8;
  --sky: #4da6ff;
  --mist: #e7eaef;
  --paper: #ffffff;

  /* Surfaces */
  --chrome: var(--navy);
  --chrome-deep: #071f41;
  --surface: var(--paper);
  --surface-sunk: #f4f6f9;
  --line: #d8dde6;
  --line-strong: #b9c2d0;

  /* Ink */
  --ink: var(--carbon);
  --ink-soft: #48536b;
  --ink-faint: #78849c;
  --ink-on-chrome: #eef3fb;
  --ink-on-chrome-soft: #9fb4d4;

  /* Status — TO CONFIRM against the brand guidelines. */
  --ok: #14804a;
  --ok-bg: #e4f2ea;
  --warn: #9a6700;
  --warn-bg: #fdf3d7;
  --bad: #b3261e;
  --bad-bg: #fbe9e8;
  /* Not-carried is deliberately neutral, never red: "we don't sell that" is
     not a failure, and colouring it like one misreads the situation. */
  --none: #5b6577;
  --none-bg: #eceef2;

  --font-ui: "Space Grotesk", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif;
  /* Every numeral, SKU code and price is mono. More than any other single
     choice, this is what makes the page read as a system rather than a page. */
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    monospace;

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;
  --shadow: 0 1px 2px rgb(10 14 22 / 0.06), 0 8px 24px rgb(10 14 22 / 0.06);
  --shadow-lift: 0 12px 40px rgb(10 14 22 / 0.18);

  --header-h: 56px;
  --tabbar-h: 60px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  /* dvh, never vh: on iOS Safari the retracting toolbars make 100vh taller
     than the visible viewport, which puts the message composer under the
     fold — exactly where you cannot afford it during a demo. */
  height: 100dvh;
  overflow: hidden;
}

body {
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--surface-sunk);
  -webkit-font-smoothing: antialiased;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

/* 16px minimum on anything focusable, or iOS zooms the viewport on focus and
   never quite zooms back. */
input,
textarea,
select {
  font-size: 16px;
}

:focus-visible {
  outline: 2px solid var(--sky);
  outline-offset: 2px;
}

.mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ===================================================================== */
/* Login                                                                  */
/* ===================================================================== */

.login {
  display: grid;
  place-items: center;
  height: 100dvh;
  padding: 24px;
  background: linear-gradient(160deg, var(--navy) 0%, var(--chrome-deep) 60%, var(--carbon) 100%);
}

.login__card {
  width: min(100%, 380px);
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lift);
  padding: 32px 28px;
}

.login__mark {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}

.login h1 {
  font-size: 20px;
  letter-spacing: -0.01em;
  margin: 0 0 4px;
}

.login p {
  margin: 0 0 20px;
  color: var(--ink-soft);
  font-size: 14px;
}

.login label {
  display: block;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 6px;
}

.login input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface);
}

.login button {
  width: 100%;
  margin-top: 14px;
  padding: 13px;
  border: 0;
  border-radius: var(--r-md);
  background: var(--signal);
  color: var(--paper);
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
}

.login button:hover {
  background: var(--navy);
}

.login__error {
  margin: 14px 0 0;
  padding: 10px 12px;
  border-radius: var(--r-sm);
  background: var(--bad-bg);
  color: var(--bad);
  font-size: 14px;
}

/* ===================================================================== */
/* App shell                                                              */
/* ===================================================================== */

.app {
  display: grid;
  grid-template-rows: var(--header-h) 1fr;
  height: 100dvh;
}

.header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  background: var(--chrome);
  color: var(--ink-on-chrome);
  min-width: 0;
}

.header__mark {
  display: flex;
  align-items: center;
  gap: 9px;
  flex: none;
}

.header__title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.header__spacer {
  flex: 1;
}

.header select {
  background: var(--navy-lift);
  color: var(--ink-on-chrome);
  border: 1px solid rgb(255 255 255 / 0.16);
  border-radius: var(--r-sm);
  padding: 7px 10px;
  min-height: 38px;
  /* The select is the one header item allowed to absorb a narrow viewport:
     everything else is either an icon or a label that must stay readable.
     min-width: 0 is what actually lets a flex item shrink below its content. */
  flex: 0 1 auto;
  min-width: 5rem;
  max-width: 22rem;
  text-overflow: ellipsis;
}


.btn-ghost {
  background: transparent;
  color: var(--ink-on-chrome-soft);
  border: 1px solid rgb(255 255 255 / 0.18);
  border-radius: var(--r-sm);
  padding: 7px 12px;
  cursor: pointer;
  min-height: 38px;
  white-space: nowrap;
}

.btn-ghost:hover {
  color: var(--paper);
  border-color: rgb(255 255 255 / 0.45);
}

/* Phone: reclaim the ~82px the wordmark costs and tighten the gaps. The mark
   still identifies the app, and the region titles say where you are. */
@media (max-width: 639px) {
  .header {
    gap: 8px;
    padding: 0 10px;
  }

  .header__title {
    display: none;
  }

  /* With the select shrinking to fill, a separate spacer only competes with it
     for the same free space. */
  .header__spacer {
    display: none;
  }

  .header select {
    flex: 1 1 auto;
  }

  .btn-ghost {
    padding: 7px 9px;
    min-height: 44px;
  }

  .header select {
    flex: 1 1 auto;
    min-height: 44px;
  }
}

.btn-ghost--icon {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.btn-ghost__icon {
  display: none;
}

@media (max-width: 639px) {
  .btn-ghost__label {
    /* Hidden visually, still read aloud — the button keeps its name. */
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .btn-ghost__icon {
    display: block;
  }
}

.badge-offline {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: var(--warn-bg);
  color: var(--warn);
  padding: 3px 7px;
  border-radius: 999px;
}

/* --- The region grid. Three layouts, one DOM. ------------------------- */

.regions {
  display: grid;
  min-height: 0;
  background: var(--surface-sunk);
}

.region {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  background: var(--surface);
  border-right: 1px solid var(--line);
}

.region__head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  flex: none;
}

.region__title {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.region__body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

/* PHONE (default): one region at a time on a scroll-snap track.
   Deliberately the base case rather than an override — the mobile layout is a
   first-class target here, not a narrowed-down desktop. */
.regions {
  grid-auto-flow: column;
  grid-auto-columns: 100%;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  padding-bottom: var(--tabbar-h);
}

.regions::-webkit-scrollbar {
  display: none;
}

.region {
  scroll-snap-align: start;
  scroll-snap-stop: always;
}

/* TABLET: two columns, each pairing two regions behind a segmented control.
   Gated on height as well as width — a landscape phone is ~844px wide but
   only ~390px tall, and a width-only rule would hand it two columns with no
   vertical room to show anything. */
@media (min-width: 640px) and (min-height: 500px) {
  .regions {
    grid-auto-flow: row;
    grid-template-columns: 1fr 1fr;
    grid-template-areas: "left right";
    overflow-x: hidden;
    padding-bottom: 0;
  }

  .region[data-pane="chat"],
  .region[data-pane="order"] {
    grid-area: left;
  }

  .region[data-pane="stock"],
  .region[data-pane="customer"] {
    grid-area: right;
  }

  /* Only the selected region of each pair is shown. */
  .region[hidden] {
    display: none !important;
  }
}

/* DESKTOP: all four at once. This is where the dashboard earns its keep —
   availability resolving and the stocklist highlighting in the same instant. */
@media (min-width: 1024px) and (min-height: 500px) {
  .regions {
    grid-template-columns: minmax(320px, 360px) minmax(420px, 1fr) minmax(360px, 400px);
    grid-template-rows: 1fr 1fr;
    grid-template-areas:
      "chat order stock"
      "chat order customer";
  }

  .region[data-pane="chat"] {
    grid-area: chat;
  }
  .region[data-pane="order"] {
    grid-area: order;
  }
  .region[data-pane="stock"] {
    grid-area: stock;
    border-bottom: 1px solid var(--line);
  }
  .region[data-pane="customer"] {
    grid-area: customer;
  }

  .region[data-pane="customer"],
  .region[data-pane="stock"] {
    border-right: 0;
  }

  /* The tablet segmented controls and the phone tab bar are both meaningless
     when every region is on screen. */
  .segmented,
  .tabbar {
    display: none !important;
  }
}

@media (min-width: 1024px) and (min-height: 500px) {
  .region[hidden] {
    display: flex !important;
  }
}

/* --- Phone tab bar ---------------------------------------------------- */

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--line);
  z-index: 20;
}

.tabbar button {
  border: 0;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 11px;
  color: var(--ink-faint);
  cursor: pointer;
  position: relative;
  min-height: 44px;
}

.tabbar button[aria-selected="true"] {
  color: var(--signal);
  font-weight: 600;
}

.tabbar button[aria-selected="true"]::before {
  content: "";
  position: absolute;
  top: 0;
  left: 22%;
  right: 22%;
  height: 2px;
  background: var(--signal);
  border-radius: 0 0 2px 2px;
}

.tabbar .dot {
  position: absolute;
  top: 8px;
  right: calc(50% - 20px);
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--bad);
  opacity: 0;
  transform: scale(0.4);
  transition: opacity 160ms ease, transform 160ms ease;
}

.tabbar button[data-badge="true"] .dot {
  opacity: 1;
  transform: scale(1);
}

@media (min-width: 640px) and (min-height: 500px) {
  .tabbar {
    display: none;
  }
}

/* --- Tablet segmented control ----------------------------------------- */

.segmented {
  display: none;
  gap: 2px;
  padding: 2px;
  background: var(--surface-sunk);
  border-radius: var(--r-sm);
}

@media (min-width: 640px) and (min-height: 500px) {
  .segmented {
    display: inline-flex;
  }
}

.segmented button {
  border: 0;
  background: transparent;
  padding: 5px 10px;
  border-radius: 4px;
  font-size: 12px;
  color: var(--ink-soft);
  cursor: pointer;
  min-height: 32px;
}

.segmented button[aria-selected="true"] {
  background: var(--surface);
  color: var(--ink);
  font-weight: 600;
  box-shadow: 0 1px 2px rgb(10 14 22 / 0.12);
}
