/*
 * Slate + amber theme. The old variable names (--blue-*) are kept because they're
 * referenced throughout — they now mean "primary scale," not literally blue. If this
 * theme sticks, a rename pass (--primary-*) would be the cleanup; and the longer-term
 * plan is making the accent per-yard configurable from Settings.
 */
:root {
  --white: #ffffff;
  --page-bg: #f3f4f6;
  --panel: #ffffff;
  --border: #cbd5e1;
  --border-light: #e2e8f0;

  --text: #111827;
  --muted: #55606e;

  --blue-900: #0f172a;   /* deep slate — headers, topbar */
  --blue-800: #1e293b;   /* slate — headings, table headers */
  --blue-700: #b45309;   /* amber-dark — hovers, emphasized text */
  --blue-600: #d97706;   /* amber — primary actions, active nav */
  --blue-500: #f59e0b;   /* amber-light — logo, highlights */
  --blue-100: #fbe9c9;   /* amber tint — focus rings, timeline fill */
  --blue-50: #faf5eb;    /* pale amber — subtle backgrounds */

  --navy: #0f172a;

  --amber: #b45309;

  --red-600: #c62828;
  --red-50: #fdecea;
  --red-200: #f2b8b0;

  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--page-bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
}

header.topbar {
  background: var(--blue-900);
  color: white;
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.3);
  position: sticky;
  top: 0;
  z-index: 10;
}

header.topbar h1 {
  font-size: 19px;
  margin: 0;
  font-weight: 700;
  letter-spacing: 0.01em;
  display: flex;
  align-items: center;
  gap: 9px;
}

header.topbar h1 svg { display: block; flex-shrink: 0; }

header.topbar nav {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}

header.topbar nav a {
  color: #cbd5e1;
  text-decoration: none;
  padding: 7px 12px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
}

header.topbar nav a:hover { background: rgba(255, 255, 255, 0.12); color: white; }
header.topbar nav a.active { background: var(--blue-600); color: white; }

/* Grouped nav. The everyday links sit flat and bright; the rarer errands collapse into
   labeled clusters that recede visually, so the eye lands on the day's work first. */
.nav-group {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-left: 10px;
  margin-left: 4px;
  border-left: 1px solid rgba(255, 255, 255, 0.14);
}
.nav-group-label {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #64748b;
  white-space: nowrap;
}
.nav-group-links { display: flex; gap: 3px; flex-wrap: wrap; }
.nav-group .nav-group-links a { font-weight: 500; color: #94a3b8; padding: 6px 9px; }
.nav-group .nav-group-links a:hover { color: white; }
.nav-group .nav-group-links a.active { color: white; font-weight: 600; }
header.topbar nav a.nav-logout { margin-left: auto; color: #94a3b8; font-weight: 500; }

/* Global search. Sits at the far right of the topbar on every staff page. */
.nav-search { position: relative; margin-left: auto; flex: 0 0 auto; }
.nav-search input {
  width: 280px;
  padding: 8px 12px;
  border-radius: 7px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  background: rgba(255, 255, 255, 0.07);
  color: white;
  font-size: 13.5px;
  font-family: inherit;
}
.nav-search input::placeholder { color: #64748b; }
.nav-search input:focus {
  outline: none;
  border-color: var(--blue-600);
  background: rgba(255, 255, 255, 0.12);
  width: 340px;
}
.search-results {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 400px;
  max-height: 65vh;
  overflow-y: auto;
  background: white;
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.28);
  z-index: 200;
  padding: 6px;
}
.search-group {
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  color: #94a3b8; padding: 8px 10px 4px;
}
.search-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 7px;
  text-decoration: none; color: var(--blue-900);
}
.search-item:hover, .search-item.sel { background: var(--blue-50, #eff6ff); }
.search-icon { flex: 0 0 18px; text-align: center; color: #94a3b8; font-size: 13px; }
.search-body { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.search-title { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-sub { font-size: 12px; color: #64748b; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-meta {
  flex: 0 0 auto; font-size: 11px; font-weight: 600;
  color: #64748b; background: #f1f5f9; padding: 3px 7px; border-radius: 20px;
}
.search-meta.open { color: #166534; background: #dcfce7; }
.search-empty { padding: 14px 12px; font-size: 13.5px; color: #64748b; }

main {
  max-width: 1150px;
  margin: 0 auto;
  padding: 28px 24px 60px;
}

h2 { margin-top: 0; font-size: 22px; color: var(--blue-900); }
h3 { color: var(--blue-800); }

.panel {
  background: var(--panel);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 22px;
  box-shadow: var(--shadow);
}

label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 5px;
  margin-top: 14px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

label.inline-label {
  display: inline;
  font-weight: 500;
  text-transform: none;
  letter-spacing: normal;
  color: var(--text);
  font-size: 14px;
  margin: 0;
}

input[type=text], input[type=number], input[type=email], input[type=tel], input[type=password], select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  background: white;
  color: var(--text);
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--blue-600);
  box-shadow: 0 0 0 3px var(--blue-100);
}

button, a.primary, a.secondary, a.ghost, a.danger {
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  border-radius: 6px;
  border: 1.5px solid transparent;
  padding: 9px 18px;
  transition: background 0.1s ease;
  display: inline-block;
  text-decoration: none;
  text-align: center;
  box-sizing: border-box;
}

button.primary, a.primary { background: var(--blue-600); color: white; }
button.primary:hover, a.primary:hover { background: var(--blue-700); }
button.secondary, a.secondary { background: white; color: var(--blue-700); border-color: var(--blue-600); }
button.secondary:hover, a.secondary:hover { background: var(--blue-50); }
button.ghost, a.ghost { background: transparent; color: var(--muted); border-color: var(--border); }
button.ghost:hover, a.ghost:hover { background: var(--blue-50); color: var(--blue-700); }
button.danger, a.danger { background: white; color: var(--red-600); border-color: var(--red-200); }
button.danger:hover, a.danger:hover { background: var(--red-50); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.row { display: flex; gap: 14px; }
.row > * { flex: 1; }

.item-row {
  display: grid;
  grid-template-columns: 2fr 1fr 40px;
  gap: 10px;
  align-items: end;
  margin-top: 10px;
}

.item-group {
  padding-bottom: 10px;
  margin-bottom: 4px;
  border-bottom: 1px dashed var(--border-light);
}

/* --- Customer hero --- */
.hero {
  background: linear-gradient(135deg, var(--blue-900) 0%, var(--blue-700) 60%, var(--blue-600) 100%);
  color: white;
  border-radius: var(--radius);
  padding: 46px 28px;
  text-align: center;
  margin-bottom: 22px;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.3);
}

.hero h2 {
  color: white;
  font-size: 28px;
  margin: 0 0 10px;
}

.hero p {
  color: #cbd5e1;
  font-size: 15.5px;
  max-width: 520px;
  margin: 0 auto 24px;
}

/* Doubled selector on purpose: .cta-primary is defined later in this file, and at equal
   specificity it was silently overriding the hero variant — leaving an amber button on an
   amber gradient. */
.cta-primary.cta-hero {
  background: white;
  color: var(--blue-800);
  font-size: 16px;
  padding: 14px 32px;
}

.cta-primary.cta-hero:hover { background: var(--blue-50); color: var(--blue-900); }

/* --- Staff dashboard --- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}

.stat-card {
  display: block;
  background: var(--panel);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  text-decoration: none;
  color: var(--text);
  transition: border-color 0.1s ease, transform 0.1s ease;
}

a.stat-card:hover { border-color: var(--blue-600); transform: translateY(-1px); }

.stat-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.stat-value {
  font-size: 26px;
  font-weight: 800;
  color: var(--blue-900);
  margin-top: 4px;
  line-height: 1.1;
}

.stat-value.stat-warn { color: var(--amber, #b3781c); }
.stat-value.stat-bad { color: var(--red-600); }

/* --- Customer landing + tracking --- */
.cta-primary, .cta-secondary {
  display: inline-block;
  font-weight: 700;
  font-size: 15px;
  text-decoration: none;
  border-radius: 8px;
  padding: 13px 26px;
  border: 1.5px solid transparent;
}

.cta-primary { background: var(--blue-600); color: white; }
.cta-primary:hover { background: var(--blue-700); }
.cta-secondary {
  background: white;
  color: var(--blue-700);
  border-color: var(--blue-600);
  font-size: 14px;
  padding: 10px 18px;
}
.cta-secondary:hover { background: var(--blue-50); }

.track-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  text-decoration: none;
  color: var(--text);
  margin-bottom: 10px;
}

.track-card:hover { border-color: var(--blue-600); background: var(--blue-50); }

.track-steps {
  list-style: none;
  padding: 0;
  margin: 18px 0 0;
}

.track-step {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 0;
  position: relative;
  font-size: 14.5px;
}

/* Connector line between dots */
.track-step:not(:last-child)::after {
  content: "";
  position: absolute;
  left: 7px;
  top: 30px;
  bottom: -9px;
  width: 2px;
  background: var(--border-light);
}

.track-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: white;
  flex-shrink: 0;
  z-index: 1;
}

.track-step.done { color: var(--text); }
.track-step.done .track-dot { background: var(--blue-600); border-color: var(--blue-600); }
.track-step.done:not(:last-child)::after { background: var(--blue-600); }

.track-step.current { color: var(--blue-900); font-weight: 700; }
.track-step.current .track-dot {
  background: var(--blue-600);
  border-color: var(--blue-100);
  box-shadow: 0 0 0 4px var(--blue-100);
}

.track-step.todo { color: var(--muted); }

/* --- Delivery window picker --- */
.slot-btn {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 420px;
  margin-bottom: 8px;
  background: white;
  border: 1.5px solid var(--border);
  color: var(--text);
  text-align: left;
  font-weight: 600;
}

.slot-btn:hover:not(:disabled) { border-color: var(--blue-600); background: var(--blue-50); }
.slot-btn.selected { border-color: var(--blue-600); background: var(--blue-100); color: var(--blue-900); }
.slot-btn.full { opacity: 0.5; }
.slot-btn .slot-cap { font-weight: 500; font-size: 12.5px; color: var(--muted); }
.slot-btn.selected .slot-cap { color: var(--blue-800); }

.photo-upload-btn {
  display: block;
  margin-top: 5px;
  padding: 5px 8px;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
  color: var(--blue-700);
  background: white;
  border: 1.5px solid var(--blue-600);
  border-radius: 6px;
  cursor: pointer;
}

.photo-upload-btn:hover { background: var(--blue-50); }

.tile.out-of-stock { opacity: 0.45; cursor: not-allowed; }
.tile.out-of-stock:hover { border-color: var(--border); box-shadow: none; }

/* --- Product photos --- */
.product-thumb {
  display: block;
  width: 96px;
  height: 64px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border-light);
  background: var(--blue-50);
}

.thumb-empty {
  width: 96px;
  height: 64px;
  border-radius: 6px;
  border: 1px dashed var(--border);
  background: var(--blue-50);
  color: var(--muted);
  font-size: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* --- Category-first browse (customer order page) --- */
.tile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
  margin-top: 12px;
}

.tile {
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: white;
  padding: 0;
  overflow: hidden;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: border-color 0.1s ease, box-shadow 0.1s ease;
}

.tile:hover { border-color: var(--blue-600); box-shadow: var(--shadow); }

.tile img, .tile .tile-noimg {
  display: block;
  width: 100%;
  height: 110px;
  object-fit: cover;
  background: var(--blue-50);
}

.tile .tile-noimg {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 12px;
}

.tile-body { padding: 10px 12px; }
.tile-name { font-weight: 700; font-size: 14px; color: var(--text); line-height: 1.3; }
.tile-meta { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.tile-price { font-weight: 700; color: var(--blue-700); font-size: 14px; margin-top: 5px; }
.tile-price .was { color: var(--muted); font-weight: 500; text-decoration: line-through; margin-left: 5px; font-size: 12px; }

.browse-crumb {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 0 0;
  font-size: 14px;
  color: var(--muted);
}

.cart-line {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-light);
}

.cart-line:last-child { border-bottom: none; }
.cart-line .cart-name { flex: 1; font-size: 14px; }
.cart-line .cart-qty { width: 90px; }
.cart-line .cart-sub { width: 90px; text-align: right; font-weight: 700; font-size: 14px; }

.cart-total {
  display: flex;
  justify-content: space-between;
  padding-top: 10px;
  margin-top: 6px;
  border-top: 2px solid var(--blue-100);
  font-weight: 800;
  font-size: 16px;
  color: var(--blue-900);
}

.item-group:last-child { border-bottom: none; }

.error-box {
  background: var(--red-50);
  border: 1.5px solid var(--red-200);
  color: var(--red-600);
  padding: 11px 14px;
  border-radius: 8px;
  margin-top: 14px;
  font-size: 14px;
  font-weight: 600;
}

.success-box {
  background: var(--blue-50);
  border: 1.5px solid var(--blue-100);
  color: var(--blue-900);
  padding: 11px 14px;
  border-radius: 8px;
  margin-top: 14px;
  font-size: 14px;
  font-weight: 600;
}

.pile-group { margin-bottom: 28px; }
.pile-group h3 {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--blue-800);
  border-bottom: 2px solid var(--blue-100);
  padding-bottom: 8px;
  margin-bottom: 12px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border-light);
  border-left: 5px solid var(--blue-600);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

.card.delivery { border-left-color: var(--navy); border-left-style: dashed; }

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 4px 10px;
  border-radius: 12px;
  color: white;
  background: var(--blue-600);
}

.badge.delivery { background: var(--navy); }
.badge.status {
  background: var(--blue-50);
  color: var(--blue-800);
  border: 1px solid var(--blue-100);
  margin-left: 8px;
}

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.card .meta { color: var(--muted); font-size: 13.5px; margin: 8px 0 0; }
.card .items { font-size: 14px; margin: 10px 0; padding-left: 20px; }
.card .items li { margin-bottom: 3px; }
.card .address {
  font-size: 13.5px;
  background: var(--blue-50);
  color: var(--blue-900);
  padding: 8px 10px;
  border-radius: 6px;
  margin-top: 8px;
  font-weight: 600;
}

.card-actions { margin-top: 12px; display: flex; gap: 8px; flex-wrap: wrap; }

.columns {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 18px;
}

.column h3 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--blue-800);
  border-bottom: 2px solid var(--blue-100);
  padding-bottom: 8px;
}

.empty {
  color: var(--muted);
  font-style: italic;
  font-size: 14px;
  padding: 14px;
  text-align: center;
  background: var(--blue-50);
  border-radius: 8px;
  border: 1px dashed var(--border);
}

.dispatch-form { display: flex; gap: 8px; margin-top: 12px; align-items: end; }
.dispatch-form > div { flex: 1; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

thead th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--blue-800);
  background: var(--blue-50);
  padding: 10px 12px;
  border-bottom: 2px solid var(--blue-100);
}

tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-light);
  color: var(--text);
}

tbody tr:hover { background: var(--blue-50); cursor: default; }
tbody tr.clickable:hover { cursor: pointer; }

.pill {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 10px;
  background: var(--blue-100);
  color: var(--blue-900);
}

.pill.inactive { background: #e6e9ef; color: var(--muted); }

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.toolbar .filters { display: flex; gap: 10px; flex-wrap: wrap; }
.toolbar input[type=text] { min-width: 220px; width: auto; }
.toolbar select { width: auto; }

.detail-panel {
  border-top: 1px solid var(--border-light);
  margin-top: 10px;
  padding-top: 10px;
  font-size: 13.5px;
}

.timeline { list-style: none; padding: 0; margin: 8px 0 0; }
.timeline li {
  padding: 6px 0 6px 18px;
  border-left: 2px solid var(--blue-100);
  position: relative;
  color: var(--muted);
}
.timeline li::before {
  content: "";
  position: absolute;
  left: -5px;
  top: 10px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--blue-600);
}
.timeline li strong { color: var(--text); }

@media (max-width: 900px) {
  .columns { grid-template-columns: 1fr; }
  header.topbar { flex-direction: column; align-items: flex-start; gap: 10px; }
}

/* ============================================================
   Phones (iPhone portrait and similar).
   Most orders happen from a truck cab, so this is the primary
   surface for the customer side — not an afterthought.
   ============================================================ */
@media (max-width: 640px) {

  /* THE iOS ZOOM FIX. Safari force-zooms into any input whose font is
     under 16px the moment it's tapped, and never zooms back out — which
     reads to the user as "the page randomly changed." 16px stops it dead.
     Desktop keeps the denser 14px above this breakpoint. */
  input[type=text], input[type=number], input[type=email], input[type=tel],
  input[type=password], input[type=date], select, textarea {
    font-size: 16px;
    padding: 12px 12px;
  }

  /* Side-by-side form fields are unusable at 390px — stack them. */
  .row { flex-direction: column; gap: 12px; }
  .row > * { width: 100%; }

  /* Wide tables scroll inside themselves instead of pushing the whole
     page sideways (horizontal page scroll is the classic "broken on
     mobile" symptom). */
  table { display: block; overflow-x: auto; white-space: nowrap; }

  /* Thumb-sized tap targets. Apple's guidance is ~44px minimum; a glove
     in a truck cab needs every bit of it. */
  button, .primary, .ghost, .cta-primary, .cta-secondary, .secondary {
    min-height: 44px;
  }
  button.primary, .cta-primary { width: 100%; }

  /* The staff nav has a dozen links; stacking them vertically buries the
     page content under a wall of nav. Scroll it sideways instead. */
  header.topbar nav {
    display: flex; flex-wrap: nowrap; overflow-x: auto;
    width: 100%; gap: 4px; padding-bottom: 4px;
    -webkit-overflow-scrolling: touch;
  }
  header.topbar nav a { white-space: nowrap; flex: 0 0 auto; }

  /* On a phone the nav is one horizontal scroll strip, so the group dividers and their
     labels would just eat width someone has to swipe past. Links only. */
  .nav-group { border-left: none; padding-left: 4px; margin-left: 0; flex: 0 0 auto; }
  .nav-group-label { display: none; }
  .nav-group-links { flex-wrap: nowrap; }
  header.topbar nav a.nav-logout { margin-left: 0; }

  /* Search goes full width above the nav strip on a phone — it's the fastest way to
     anything, so it should be the easiest thing to hit with a thumb. */
  .nav-search { margin-left: 0; width: 100%; order: -1; }
  .nav-search input, .nav-search input:focus { width: 100%; }
  .search-results { width: 100%; right: auto; left: 0; }

  main { padding-left: 12px; padding-right: 12px; }
  .panel { padding: 16px 14px; }

  /* Two product tiles per row reads well at phone width. */
  .tile-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }

  /* Never let anything push the page sideways. */
  body { overflow-x: hidden; }
  img, .tile img { max-width: 100%; }
}
