/* ==========================================================================
   Tally - app.css
   Mobile-first. Base styles target a 360px-wide phone; the
   @media (min-width: 900px) block near the bottom adapts the layout for
   desktop. Colors and spacing are CSS custom properties so a company theme
   can override them in Phase 2 without touching the rules below.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Theme tokens (light mode defaults)
   -------------------------------------------------------------------------- */
:root {
  --color-bg: #f3f4f6;            /* page background */
  --color-surface: #ffffff;       /* cards, bars, inputs */
  --color-text: #111827;          /* main text */
  --color-muted: #6b7280;         /* secondary text */
  --color-border: #d1d5db;        /* hairlines around inputs, bars, cards */
  --color-primary: #1d4ed8;       /* buttons, active nav, focus rings */
  --color-primary-text: #ffffff;  /* text on top of --color-primary */
  --color-danger: #b91c1c;        /* error text */
  --color-danger-bg: #fee2e2;     /* error background */
  --color-warn: #92400e;          /* banner text (acting company, password warning) */
  --color-warn-bg: #fef3c7;       /* banner background */
  --color-ok: #166534;            /* success badge text */
  --color-ok-bg: #dcfce7;         /* success badge background */
  --radius: 8px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 16px;
  --space-4: 24px;
  --nav-height: 56px;             /* bottom tab bar and top bar height */
  --sidebar-width: 220px;         /* desktop only */
  --tap: 44px;                    /* minimum tap-target height */
}

/* --------------------------------------------------------------------------
   2. Dark mode: swap the tokens only, no layout changes
   -------------------------------------------------------------------------- */
@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #0f172a;
    --color-surface: #1e293b;
    --color-text: #f1f5f9;
    --color-muted: #94a3b8;
    --color-border: #334155;
    --color-primary: #60a5fa;
    --color-primary-text: #0f172a;
    --color-danger: #fca5a5;
    --color-danger-bg: #450a0a;
    --color-warn: #fde68a;
    --color-warn-bg: #451a03;
    --color-ok: #86efac;
    --color-ok-bg: #052e16;
  }
}

/* --------------------------------------------------------------------------
   3. Minimal reset
   -------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
  min-height: 100vh;
}
h1, h2, h3, h4, p, dl, dd { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
legend { padding: 0; }
[hidden] { display: none !important; }

/* Keyboard focus is always visible. */
:focus-visible {
  outline: 3px solid var(--color-primary);
  outline-offset: 2px;
}

/* --------------------------------------------------------------------------
   4. Components
   -------------------------------------------------------------------------- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-4);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  padding: 0 var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { filter: brightness(0.96); }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn-primary {
  background: var(--color-primary);
  color: var(--color-primary-text);
  border-color: var(--color-primary);
}
.btn-block { width: 100%; }
.btn-small { padding: 0 var(--space-2); font-size: 14px; }
.btn-danger { color: var(--color-danger); border-color: var(--color-danger); }
.btn-icon { min-width: var(--tap); padding: 0; }
a.btn { text-decoration: none; }

/* "‹ Back to items": a button that looks like a link. */
.link-back {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  padding: 0;
  border: 0;
  background: none;
  color: var(--color-primary);
  font-weight: 600;
  cursor: pointer;
}

/* Keeps an element for screen readers and the keyboard but takes it off screen
   (the real <input type="file"> behind a styled label). */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin-bottom: var(--space-3);
}
.field label, .field-label { font-size: 14px; font-weight: 600; }
.field input, .field select, .field textarea {
  width: 100%;
  min-height: var(--tap);
  font-size: 16px;                /* 16px stops iPhones zooming on focus */
  padding: 0 var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
}
.field textarea { padding: var(--space-2); resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--color-primary); }
.field input:disabled, .field select:disabled { background: var(--color-bg); color: var(--color-muted); }
.field [aria-invalid="true"] { border-color: var(--color-danger); }
.field-error { font-size: 14px; color: var(--color-danger); }

/* Checkbox row: the whole label is the tap target. */
.field-check label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--tap);
  font-weight: 600;
  cursor: pointer;
}
.field-check input[type="checkbox"], .toggle input[type="checkbox"] {
  width: 24px;
  height: 24px;
  min-height: 0;
  margin: 0;
  flex-shrink: 0;
  accent-color: var(--color-primary);
}

/* Radio group: each choice is a label with a one-line explanation. */
.radio-group { margin-bottom: var(--space-3); }
.radio-group legend { font-size: 14px; font-weight: 600; margin-bottom: var(--space-1); }
.radio-choice {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  min-height: var(--tap);
  padding: var(--space-1) 0;
}
.radio-choice input { width: 24px; height: 24px; margin: 2px 0 0; flex-shrink: 0; accent-color: var(--color-primary); }
.radio-choice label { display: flex; flex-direction: column; cursor: pointer; }
.radio-label { font-weight: 600; }

.hint { font-size: 14px; color: var(--color-muted); }
.muted { color: var(--color-muted); }

.error {
  color: var(--color-danger);
  background: var(--color-danger-bg);
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-3);
  margin-bottom: var(--space-3);
  font-size: 14px;
}

.empty-state {
  text-align: center;
  color: var(--color-muted);
  padding: var(--space-4) var(--space-3);
}
.empty-state h2 {
  font-size: 20px;
  color: var(--color-text);
  margin-bottom: var(--space-2);
}

/* --------------------------------------------------------------------------
   5. Auth pages (login, change password): one centered card
   -------------------------------------------------------------------------- */
.auth {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-3);
}
.auth-card { width: 100%; max-width: 400px; }
.auth-title { font-size: 24px; margin-bottom: var(--space-1); }
.auth-subtitle { margin-bottom: var(--space-4); }

/* "Forgot password?" / "‹ Back to sign in" under the button (D47): a plain
   link with a full tap-height hit area. */
.auth-links { margin-top: var(--space-3); text-align: center; font-size: 14px; }
.auth-link {
  display: inline-flex;
  align-items: center;
  min-height: var(--tap);
  padding: 0 var(--space-2);
  color: var(--color-primary);
  font-weight: 600;
  text-decoration: none;
}
.auth-link:hover { text-decoration: underline; }

/* A green "it worked" box, the counterpart of .error (forgot-password's reply). */
.notice {
  color: var(--color-ok);
  background: var(--color-ok-bg);
  border-radius: var(--radius);
  padding: var(--space-2) var(--space-3);
  margin-bottom: var(--space-3);
  font-size: 14px;
}

/* --------------------------------------------------------------------------
   6. App shell, phone layout: sticky top bar, fixed bottom tab bar
   -------------------------------------------------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  min-height: var(--nav-height);
  padding: var(--space-2) var(--space-3);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}
.topbar-company {
  font-weight: 700;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar-user {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}
/* The user's name is a button that opens the Account panel (D48): looks like
   text, but 44px tall and underlined on hover so it reads as tappable. */
.topbar-name {
  min-height: var(--tap);
  padding: 0 var(--space-1);
  border: 0;
  border-radius: var(--radius);
  background: none;
  font-size: 14px;
  color: var(--color-muted);
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}
.topbar-name:hover { color: var(--color-primary); text-decoration: underline; }
.topbar-name[aria-current="true"] { color: var(--color-primary); }   /* while the Account panel shows */

.nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: flex;
  height: var(--nav-height);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
}
.nav-item {
  flex: 1 1 0;
  min-width: 0;
  min-height: var(--tap);
  padding: 0 var(--space-1);
  border: 0;
  background: none;
  color: var(--color-muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.nav-item[aria-current="true"] {
  color: var(--color-primary);
  box-shadow: inset 0 3px 0 var(--color-primary);   /* top indicator line */
}

.main {
  padding: var(--space-3);
  padding-bottom: calc(var(--nav-height) + var(--space-4)); /* clear the tab bar */
}

/* Only the panel matching <main data-view="..."> is shown. app.js changes
   the attribute; nothing else is needed to switch views. */
.panel { display: none; }
.main[data-view="quotes"]    .panel[data-panel="quotes"],
.main[data-view="new-quote"] .panel[data-panel="new-quote"],
.main[data-view="catalog"]   .panel[data-panel="catalog"],
.main[data-view="users"]     .panel[data-panel="users"],
.main[data-view="settings"]  .panel[data-panel="settings"],
.main[data-view="platform"]  .panel[data-panel="platform"],
.main[data-view="account"]   .panel[data-panel="account"] { display: block; }

/* --------------------------------------------------------------------------
   6a. Account panel (Phase 5, D48): the two cards and the sessions list
   -------------------------------------------------------------------------- */
.account .link-back { margin-bottom: var(--space-1); }
.account .screen-header { margin-bottom: var(--space-1); }
.account-who { margin-bottom: var(--space-3); font-size: 14px; overflow-wrap: anywhere; }
.account-name { font-weight: 600; color: var(--color-text); }
.account-card { max-width: 760px; }
.account-card .hint { margin-bottom: var(--space-3); }

/* One row per signed-in device: label + "This device" badge, then ip and
   last seen underneath in muted text; "Log out" on the right. */
.sessions-list { margin-bottom: var(--space-2); }
.session-row .row-main { flex-basis: 220px; }
.session-meta { overflow-wrap: anywhere; }
.session-current { background: var(--color-bg); }
.sessions-count { align-self: center; }

/* --------------------------------------------------------------------------
   6b. Admin screens (Phase 2): headers, tabs, lists, badges, forms, dialogs
   -------------------------------------------------------------------------- */

/* Screen header: title on the left, buttons wrap underneath on a phone. */
.screen-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}
.screen-header h2, .form-title { font-size: 22px; }
.toolbar, .actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); }

/* Catalog header on a phone: the three small controls sit in one wrapping
   row under the title (flex-basis 100% forces the wrap) instead of fighting
   the title for the first line. The desktop block puts them back beside it. */
.toolbar-under { flex: 1 1 100%; }
.toolbar-under .toggle { padding: 0 var(--space-2); font-size: 13px; }

/* "Show inactive" toggle: a pill-shaped label with a checkbox inside. */
.toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--tap);
  padding: 0 var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

/* Tab strip (the builder's Add items / Quote tabs on a phone). Categories no
   longer use it (D37: a dropdown instead), but it may still scroll sideways
   inside its own box should it ever get too wide. */
.tabs {
  display: flex;
  gap: var(--space-2);
  min-width: 0;                   /* may shrink below its content, which then scrolls */
  overflow-x: auto;
  padding-bottom: var(--space-2);
  margin-bottom: var(--space-3);
  border-bottom: 1px solid var(--color-border);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}
.tab {
  flex: 0 0 auto;
  min-height: var(--tap);
  padding: 0 var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-surface);
  color: var(--color-text);
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.tab[aria-selected="true"] {
  background: var(--color-primary);
  color: var(--color-primary-text);
  border-color: var(--color-primary);
}

/* Category dropdown (D37), on the Catalog screen and the builder's Add items
   tab: a full-width select (44px tall, 16px text so iPhones do not zoom) with,
   on the Catalog screen, the "Manage categories" button beside it. Both shrink
   before anything overflows a 360px phone. */
.category-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}
.category-select {
  flex: 1 1 180px;
  min-width: 0;
  max-width: 100%;
  min-height: var(--tap);
  font-size: 16px;
  padding: 0 var(--space-4) 0 var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background-color: var(--color-surface);
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 14px) 50%, calc(100% - 9px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  -webkit-appearance: none;
  appearance: none;
}
.category-select:focus { border-color: var(--color-primary); }
.manage-categories-toggle { flex: 0 0 auto; }
.manage-categories-toggle[aria-expanded="true"] { border-color: var(--color-primary); color: var(--color-primary); }

/* "All categories": every category's items under a small heading. */
.category-group { margin-bottom: var(--space-3); }
.category-heading {
  font-size: 13px;
  font-weight: 600;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin: 0 0 var(--space-1);
}

/* The "Manage categories" card: a list of rows with Edit / up / down / Deactivate. */
.manage-categories { margin-bottom: var(--space-3); }
.manage-categories .list { margin-bottom: var(--space-2); }

/* Sections inside a screen (Settings has four). */
.section { margin-bottom: var(--space-4); }
.section-title {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}
.section-title h3 { font-size: 18px; }
.section.card { padding: var(--space-3); }   /* a phone needs the width more than the margin */
.option-group { font-size: 14px; color: var(--color-muted); margin: var(--space-3) 0 var(--space-1); }

/* Lists: a bordered stack of rows. A row is a <button> when tapping opens a form. */
.list {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  overflow: hidden;
}
.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  min-height: 56px;
  padding: var(--space-2) var(--space-3);
  border: 0;
  border-bottom: 1px solid var(--color-border);
  background: none;
  color: inherit;
  text-align: left;
  width: 100%;
}
.row:last-child { border-bottom: 0; }
.row-button { cursor: pointer; }
.row-button:hover { background: var(--color-bg); }
.row-main { flex: 1 1 200px; min-width: 0; }
.row-title { font-weight: 600; overflow-wrap: anywhere; }
.row-sub { font-size: 14px; color: var(--color-muted); overflow-wrap: anywhere; }
.row-actions { display: flex; flex-wrap: wrap; gap: var(--space-1); flex-shrink: 0; }

/* Per-option buttons (Edit, up, down, Deactivate): compact enough that all
   four fit on one line beside the name, or one line under it, on a 360px
   phone. Still 44px tall (and the arrows 44px wide) for a fingertip. */
.row-actions-compact { margin-left: auto; }
.row-actions-compact .btn { min-height: var(--tap); padding: 0 var(--space-2); font-size: 13px; }
.row-actions-compact .btn-icon { min-width: var(--tap); padding: 0; font-size: 12px; }
.row-chevron { color: var(--color-muted); font-size: 24px; line-height: 1; }
.row-chevron::after { content: "\203A"; }

/* Badges: small pills after a name. */
.badge {
  display: inline-block;
  vertical-align: middle;
  padding: 1px var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-bg);
  color: var(--color-muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-inactive { border-style: dashed; }
.badge-default { color: var(--color-primary); border-color: var(--color-primary); background: var(--color-surface); }
.badge-ok { color: var(--color-ok); background: var(--color-ok-bg); border-color: transparent; }
.badge-error { color: var(--color-danger); background: var(--color-danger-bg); border-color: transparent; }
.summary { display: flex; flex-wrap: wrap; gap: var(--space-2); margin: var(--space-3) 0; }

/* Banner: "Acting in Acme" at the top of main, and the password warning. */
.banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  margin-bottom: var(--space-3);
  border: 1px solid var(--color-warn);
  border-radius: var(--radius);
  background: var(--color-warn-bg);
  color: var(--color-warn);
}
.banner-warn { display: block; margin-top: var(--space-3); font-size: 14px; }

/* Forms: a card with a Back link; the grid becomes two columns on desktop. */
.form-card { margin-bottom: var(--space-3); }
.form-card .link-back { margin-bottom: var(--space-1); }
.form-card .form-title { margin-bottom: var(--space-3); }
.form-grid { display: grid; grid-template-columns: 1fr; column-gap: var(--space-3); }
.form-grid h4 { font-size: 16px; margin: var(--space-3) 0 var(--space-2); }
.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-2);
}
.form-error { margin-top: var(--space-1); }
.unsaved-marker { align-self: center; font-style: italic; }
.option-form {
  margin-top: var(--space-3);
  padding-top: var(--space-3);
  border-top: 1px solid var(--color-border);
}

/* Volume pricing (D63), inside the item form: one row per tier reading
   "From [2] units: $[40.00] each [x]". The inputs are short (a quantity, a
   price) but keep the 44px height and 16px text of every other input; the
   words between them sit on the same baseline. On a narrow phone the row
   wraps after "units:". */
.tiers-editor legend { margin-bottom: var(--space-1); }
.tiers-rows { display: flex; flex-direction: column; gap: var(--space-2); margin-top: var(--space-2); }
.tier-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-1) var(--space-2); }
.tier-row input { width: 6.5em; flex: 0 0 auto; }
.tier-row .tier-min { width: 5em; }
.tier-word { font-size: 14px; color: var(--color-muted); white-space: nowrap; }
.tier-currency { margin-right: calc(-1 * var(--space-1)); }
.tier-row .btn-icon { margin-left: auto; }
.tiers-empty { font-size: 14px; margin: var(--space-2) 0; }
.tiers-editor .btn-small { margin-top: var(--space-2); align-self: flex-start; }
.tiers-percent-hint { margin: 0; }

/* Temporary password reveal. */
.details { display: grid; grid-template-columns: auto 1fr; gap: var(--space-1) var(--space-3); margin: var(--space-3) 0; }
.details dt { color: var(--color-muted); font-size: 14px; }
.details dd { overflow-wrap: anywhere; }
.reveal-password {
  width: 100%;
  min-height: var(--tap);
  margin: var(--space-1) 0 var(--space-2);
  padding: var(--space-2);
  border: 1px dashed var(--color-primary);
  border-radius: var(--radius);
  background: var(--color-bg);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 20px;
  letter-spacing: 1px;
}

/* Logo preview. */
.logo-preview {
  display: inline-block;
  padding: var(--space-2);
  margin-bottom: var(--space-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: #ffffff;           /* logos are designed for white paper */
}
.logo-preview img { display: block; max-width: 240px; max-height: 120px; }

/* CSV preview tables scroll sideways inside their own box, never the page. */
.table-wrap {
  overflow-x: auto;
  margin: var(--space-2) 0 var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  -webkit-overflow-scrolling: touch;
}
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td {
  padding: var(--space-1) var(--space-2);
  border-bottom: 1px solid var(--color-border);
  text-align: left;
  white-space: nowrap;
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.table th { background: var(--color-bg); font-weight: 600; text-transform: capitalize; }
.table tr:last-child td { border-bottom: 0; }

/* Confirm dialog: a plain <dialog>, centred by the browser. */
.dialog {
  width: calc(100% - 2 * var(--space-3));
  max-width: 380px;
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
}
.dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.dialog-message { margin-bottom: var(--space-4); }
.dialog-actions { display: flex; justify-content: flex-end; gap: var(--space-2); }

/* Toast: bottom of the screen, above the tab bar, fades in and out. */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-height) + var(--space-3));
  z-index: 20;
  max-width: calc(100% - 2 * var(--space-3));
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
  background: var(--color-text);
  color: var(--color-bg);
  font-size: 14px;
  transform: translate(-50%, 8px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.toast-visible { opacity: 1; transform: translate(-50%, 0); }

/* --------------------------------------------------------------------------
   6b. Platform company management (D59) and the Users header counter (D58)
   -------------------------------------------------------------------------- */

/* A company row: name block, then the three stat cells, then the buttons.
   On a phone everything wraps inside the row (the base .row is already
   flex-wrap) so nothing pushes the page wider than 360px. */
.company-row { align-items: flex-start; padding-top: var(--space-3); padding-bottom: var(--space-3); }
.company-row .row-main { flex: 1 1 100%; }
.company-stats {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  flex: 1 1 100%;
  min-width: 0;
}
.company-row .row-actions { flex: 1 1 100%; }
.stat { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.stat-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-muted);
}
.stat-value { font-size: 16px; font-weight: 600; white-space: nowrap; }

/* The users cell is a button: tapping it opens the limit editor. Looks like
   text with a dotted underline so it reads as editable; 44px tall. */
.stat-button {
  min-height: var(--tap);
  padding: 0;
  border: 0;
  background: none;
  color: var(--color-primary);
  text-align: left;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
  cursor: pointer;
}
.stat-button:hover { text-decoration-style: solid; }

/* Inline limit editor: "3 /" followed by a short number input. */
.limit-editor { display: flex; flex-direction: column; gap: var(--space-1); min-width: 0; }
.limit-editor-line { display: flex; align-items: center; gap: var(--space-2); }
.limit-input {
  width: 7.5em;
  min-height: var(--tap);
  font-size: 16px;                /* 16px stops iPhones zooming on focus */
  font-weight: 600;
  padding: 0 var(--space-2);
  border: 1px solid var(--color-primary);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
}
.limit-input[aria-invalid="true"] { border-color: var(--color-danger); }
.limit-input::placeholder { font-weight: 400; color: var(--color-muted); }
.limit-error { font-size: 14px; color: var(--color-danger); max-width: 32em; overflow-wrap: anywhere; }
.limit-hint { font-size: 12px; color: var(--color-muted); }

/* Users screen header: "Users" with "3 of 5 users" beside it; the hint under
   the header repeats the refusal when the company is full. */
.users-heading { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--space-1) var(--space-2); min-width: 0; }
.users-count { font-size: 14px; color: var(--color-muted); white-space: nowrap; }
.users-count-full { color: var(--color-warn); font-weight: 600; }
.users-limit-hint {
  margin: calc(-1 * var(--space-2)) 0 var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
  color: var(--color-warn);
  background: var(--color-warn-bg);
}

/* --------------------------------------------------------------------------
   7. Desktop (900px and up): the tab bar becomes a left sidebar
   -------------------------------------------------------------------------- */
@media (min-width: 900px) {
  .app-body {
    display: grid;
    /* minmax(0, 1fr), not 1fr: a plain 1fr column refuses to shrink below its
       content's natural width, so a wide Catalog tab strip pushed the whole
       page wider instead of scrolling inside its own box. */
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    grid-template-rows: auto 1fr;
    min-height: 100vh;
  }
  .topbar { grid-column: 1 / -1; padding: var(--space-2) var(--space-4); }
  .topbar-name { max-width: none; }

  .nav {
    position: static;
    grid-row: 2;
    grid-column: 1;
    flex-direction: column;
    gap: var(--space-1);
    height: auto;
    padding: var(--space-3) var(--space-2);
    border-top: 0;
    border-right: 1px solid var(--color-border);
  }
  .nav-item {
    flex: 0 0 auto;
    text-align: left;
    padding: 0 var(--space-3);
    font-size: 15px;
    border-radius: var(--radius);
  }
  .nav-item[aria-current="true"] {
    box-shadow: none;
    background: var(--color-bg);
  }

  .main {
    grid-row: 2;
    grid-column: 2;
    width: 100%;
    min-width: 0;                  /* same reason as minmax(0, 1fr) above */
    max-width: 1100px;
    padding: var(--space-4);
  }

  /* Back to a full card and a right-aligned toolbar (phone rules below). */
  .section.card { padding: var(--space-4); }
  .toolbar-under { flex: 0 1 auto; }

  /* Company management reads as a table on a wide screen: name | stats | buttons
     on one line, the stats in three fixed columns so the rows line up. */
  .company-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; align-items: center; column-gap: var(--space-4); }
  .company-row .row-main, .company-stats, .company-row .row-actions { flex: none; }
  .company-stats { display: grid; grid-template-columns: 11em 5em 8em; gap: var(--space-3); }
  .company-row .row-actions { justify-content: flex-end; }

  /* Forms use two columns; fields marked .span-2 (name, description, buttons) take both. */
  .form-grid { grid-template-columns: 1fr 1fr; }
  .form-grid .span-2 { grid-column: 1 / -1; }
  .form-card { max-width: 760px; }

  /* No tab bar on desktop, so the toast sits in the bottom-right corner. */
  .toast {
    left: auto;
    right: var(--space-4);
    bottom: var(--space-4);
    transform: translate(0, 8px);
  }
  .toast-visible { transform: translate(0, 0); }
}
