/* Castle Packaging — Business Suite shared styles */
:root {
  --ink: #17130D;
  --gold: #A9791F;
  --gold-deep: #7C5A16;
  --gold-light: #E7C983;
  --sage: #56643B;
  --sage-deep: #3E4A2A;
  --sage-light: #E1E8D3;
  --kraft: #B5723A;
  --kraft-deep: #8A5427;
  --danger: #B3261E;
  --danger-light: #FBE9E7;
  --bg: #FFFFFF;
  --bg-alt: #FAF7F1;
  --card: #FFFFFF;
  --border: #E9E2D2;
  --text: #221D15;
  --muted: #756C5C;
  --radius: 10px;
  --sidebar-w: 230px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: Arial, "Helvetica Neue", Helvetica, sans-serif;
  background: var(--bg-alt);
  color: var(--text);
  line-height: 1.5;
}
img { max-width: 100%; display: block; }
a { color: var(--gold-deep); text-decoration: none; }
h1, h2, h3, h4 { font-family: Georgia, "Times New Roman", serif; color: var(--ink); margin: 0 0 8px; }
button, input, select, textarea { font-family: inherit; font-size: 15px; }

/* ---------- Auth screen ---------- */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, var(--bg-alt), var(--sage-light));
}
.auth-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 12px 30px rgba(23,19,13,0.08);
  text-align: center;
}
.auth-card img.logo { width: 160px; margin: 0 auto 18px; }
.auth-card h1 { font-size: 20px; margin-bottom: 4px; }
.auth-card p.sub { color: var(--muted); font-size: 13.5px; margin-bottom: 24px; }
.field { text-align: left; margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: bold; color: var(--ink); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--gold);
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 11px 20px;
  border-radius: 8px;
  border: none;
  font-weight: bold;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
}
.btn-primary { background: var(--gold); color: #fff; }
.btn-primary:hover { background: var(--gold-deep); }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--ink); }
.btn-outline:hover { background: var(--bg-alt); }
.btn-danger { background: var(--danger-light); color: var(--danger); }
.btn-sage { background: var(--sage); color: #fff; }
.btn-full { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.form-error {
  background: var(--danger-light);
  color: var(--danger);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 14px;
  display: none;
}
.form-error.show { display: block; }

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w);
  background: var(--ink);
  color: #fff;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 40;
  transition: transform 0.2s ease;
}
.sidebar .brand { padding: 20px 18px; border-bottom: 1px solid rgba(255,255,255,0.08); }
.sidebar .brand img { width: 130px; filter: brightness(0) invert(1); opacity: 0.95; }
.sidebar nav { flex: 1; overflow-y: auto; padding: 14px 10px; }
.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: rgba(255,255,255,0.78);
  font-size: 14px;
  margin-bottom: 2px;
}
.sidebar nav a:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar nav a.active { background: var(--gold); color: #fff; }

/* Collapsible sidebar groups (Sales & CRM, Procurement, etc.) — the nav
   had grown to 20+ flat links one Phase at a time and become hard to scan,
   so related pages are grouped under a bold, icon-led header that stands
   out against the plain links above and below it. Nothing is collapsed by
   default; this only ever hides a section once the person explicitly
   clicks its header (see layout.js renderSidebar), and the section
   collapses/expands with a smooth slide rather than snapping instantly. */
.nav-group { margin: 16px 0 6px; }
.nav-group:first-of-type { margin-top: 8px; }
.nav-group-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 9px;
  background: rgba(255,255,255,0.05);
  border: none;
  border-left: 3px solid var(--gold);
  border-radius: 0 8px 8px 0;
  cursor: pointer;
  padding: 9px 10px 9px 11px;
  margin-bottom: 4px;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--gold-light);
  transition: background 0.15s ease, color 0.15s ease;
}
.nav-group-toggle:hover { background: rgba(255,255,255,0.1); color: #fff; }
.nav-group-icon { font-size: 14px; line-height: 1; flex-shrink: 0; }
.nav-group-label { flex: 1; text-align: left; }
.nav-group-chevron { font-size: 10px; color: rgba(255,255,255,0.5); transition: transform 0.2s ease; }
.nav-group.collapsed .nav-group-chevron { transform: rotate(-90deg); }
.nav-group-items {
  overflow: hidden;
  max-height: 600px;
  transition: max-height 0.25s ease;
}
.nav-group.collapsed .nav-group-items { max-height: 0; }
.sidebar .user-box {
  padding: 14px 18px;
  border-top: 1px solid rgba(255,255,255,0.08);
  font-size: 12.5px;
  color: rgba(255,255,255,0.7);
}
.sidebar .user-box strong { display: block; color: #fff; font-size: 13.5px; }
.sidebar .user-box .role-badge {
  display: inline-block;
  margin-top: 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  background: rgba(255,255,255,0.1);
  padding: 2px 8px;
  border-radius: 20px;
}
.sidebar .logout-link { margin-top: 8px; display: inline-block; color: var(--gold-light); font-size: 12.5px; }

/* ---------- Command Palette (global search — Ctrl/Cmd+K) ---------- */
/* Trigger button injected into the sidebar, right under the logo, on every
   page (see layout.js renderCommandPalette). */
.cmdk-trigger {
  display: flex; align-items: center; gap: 8px;
  margin: 12px 14px 0; padding: 8px 10px;
  background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px; color: rgba(255,255,255,0.75);
  font-size: 12.5px; cursor: pointer; text-align: left; width: calc(100% - 28px);
}
.cmdk-trigger:hover { background: rgba(255,255,255,0.1); color: #fff; }
.cmdk-trigger-icon { font-size: 13px; line-height: 1; flex-shrink: 0; }
.cmdk-trigger-label { flex: 1; }
.cmdk-trigger-kbd {
  font-size: 10px; color: rgba(255,255,255,0.5);
  border: 1px solid rgba(255,255,255,0.2); border-radius: 4px;
  padding: 1px 5px; flex-shrink: 0;
}

.cmdk-overlay {
  position: fixed; inset: 0; background: rgba(23,19,13,0.45);
  display: none; align-items: flex-start; justify-content: center;
  padding: 12vh 16px 16px; overflow-y: auto; z-index: 100;
}
.cmdk-overlay.open { display: flex; }
.cmdk-modal {
  background: #fff; border-radius: var(--radius); width: 100%; max-width: 560px;
  max-height: 70vh; display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 20px 60px rgba(23,19,13,0.3);
}
.cmdk-input-row {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.cmdk-input-icon { font-size: 15px; color: var(--muted); flex-shrink: 0; }
.cmdk-input {
  flex: 1; border: none; outline: none; font-size: 14.5px; font-family: inherit;
  color: var(--ink); background: transparent;
}
.cmdk-input::placeholder { color: var(--muted); }
.cmdk-esc-hint {
  font-size: 10.5px; color: var(--muted); border: 1px solid var(--border);
  border-radius: 4px; padding: 2px 6px; flex-shrink: 0;
}
.cmdk-list { overflow-y: auto; padding: 6px; }
.cmdk-section-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.4px;
  color: var(--muted); padding: 8px 10px 4px;
}
.cmdk-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 8px; cursor: pointer; font-size: 13.5px;
}
.cmdk-item:hover, .cmdk-item.active { background: var(--sage-light); }
.cmdk-item-icon { font-size: 15px; flex-shrink: 0; width: 18px; text-align: center; }
.cmdk-item-label { flex: 1; color: var(--ink); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cmdk-item-section { font-size: 11px; color: var(--muted); flex-shrink: 0; }
.cmdk-empty { padding: 24px 16px; text-align: center; color: var(--muted); font-size: 13px; }

/* Briefly pulses whatever element a search result jumped to (a field, a
   tab, a section heading) so it's obvious what just got scrolled to. */
@keyframes cmdk-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(169,121,31,0); }
  15% { box-shadow: 0 0 0 4px rgba(169,121,31,0.35); }
  50% { box-shadow: 0 0 0 4px rgba(169,121,31,0.2); }
}
.cmdk-highlight {
  animation: cmdk-pulse 1.1s ease-out 2;
  border-radius: 6px;
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}
@media (max-width: 600px) {
  .cmdk-overlay { padding: 8vh 10px 10px; }
  .cmdk-trigger-kbd { display: none; }
}

.nav-toggle-mobile {
  display: none;
  position: fixed;
  top: 14px; left: 14px;
  z-index: 50;
  background: var(--ink);
  color: #fff;
  border: none;
  border-radius: 8px;
  width: 40px; height: 40px;
  font-size: 18px;
  cursor: pointer;
}

.main { margin-left: var(--sidebar-w); flex: 1; min-width: 0; }
.topbar {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 16px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}
.topbar h1 { font-size: 20px; margin: 0; }
.content { padding: 24px 28px 60px; max-width: 1200px; }

/* ---------- Dashboard section dividers ---------- */
/* Groups the dashboard into the two guiding questions ("What's happening
   right now?" / "What needs my attention today?") rather than one long
   undifferentiated stack of cards. Deliberately plain — a label plus a
   rule — so it reads as organization, not another card competing for
   attention. */
.dashboard-section-title { display: flex; align-items: baseline; gap: 10px; margin: 30px 0 14px; }
.dashboard-section-title:first-of-type { margin-top: 6px; }
.dashboard-section-title h2 { font-size: 17px; margin: 0; color: var(--ink); white-space: nowrap; }
.dashboard-section-title .sub { font-size: 12.5px; color: var(--muted); }
.dashboard-section-title .rule { flex: 1; height: 1px; background: var(--border); }

/* Dashboard alone gets more horizontal room than the standard 1200px page
   width — it's a multi-column widget grid (like a BI-style overview
   screen), not a single-column form/table page, so it needs it to avoid
   forcing 4-column widget rows down to 1-2 columns unnecessarily on a
   normal desktop viewport. Every other page is untouched. */
.content.dashboard-wide { max-width: 1600px; }

/* ---------- Dashboard compact tiles ---------- */
/* A denser alternative to .stat-card for the dashboard specifically —
   smaller footprint so more figures fit above the fold, each with an icon
   for quick visual scanning (same idea as the reference screenshot the
   layout was modeled on). Still just a label+value+optional-subtext, same
   data as a .stat-card would show, just laid out tighter. */
.tile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(155px, 1fr)); gap: 10px; margin-bottom: 18px; }
.tile {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 13px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.tile-top { display: flex; align-items: center; gap: 6px; }
.tile-icon { font-size: 15px; line-height: 1; }
.tile-label { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.3px; }
.tile-value { font-size: 18px; font-weight: bold; color: var(--ink); line-height: 1.25; }
.tile.warn .tile-value { color: var(--danger); }
.tile-sub { font-size: 10.5px; color: var(--muted); }

/* ---------- Dashboard widgets (compact cards in a multi-column grid) ---------- */
.widget-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; margin-bottom: 18px; align-items: start; }
.widget-wide { grid-column: span 2; }
.widget {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 15px;
  min-width: 0;
}
.widget-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 9px; }
.widget-head h3 { font-size: 13px; margin: 0; color: var(--ink); }
.widget-head a, .widget-head .widget-link { font-size: 11px; }
.widget-sub { font-size: 10.5px; color: var(--muted); margin: -6px 0 8px; }
.widget-list { list-style: none; margin: 0; padding: 0; font-size: 12px; }
.widget-list li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 5.5px 0; border-bottom: 1px solid var(--border); }
.widget-list li:last-child { border-bottom: none; }
.widget-list .wl-main { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.widget-list .wl-side { flex-shrink: 0; text-align: right; color: var(--muted); font-size: 11px; }
.widget-empty { font-size: 12px; color: var(--muted); padding: 6px 0; }
.widget-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 14px; font-size: 12px; }
.widget-2col div { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px solid var(--border); gap: 6px; }
.widget-2col span:last-child { font-weight: bold; color: var(--ink); }

.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 7px; flex-shrink: 0; }
.status-dot.ok { background: var(--sage); }
.status-dot.warn { background: var(--gold); }
.status-dot.danger { background: var(--danger); }

.mini-progress { background: var(--border); border-radius: 4px; height: 5px; overflow: hidden; margin-top: 4px; }
.mini-progress > div { background: var(--sage); height: 100%; }

.alert-feed { list-style: none; margin: 0; padding: 0; }
.alert-feed li { display: flex; gap: 8px; padding: 6.5px 0; border-bottom: 1px solid var(--border); font-size: 12px; align-items: flex-start; }
.alert-feed li:last-child { border-bottom: none; }
.alert-feed .status-dot { margin-top: 4px; }
.alert-feed .af-time { display: block; font-size: 10.5px; color: var(--muted); margin-top: 1px; }

.chart-wrap { position: relative; height: 150px; }
.chart-wrap.donut { height: 140px; display: flex; align-items: center; justify-content: center; }

/* ---------- Cards / grids ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 26px; }
@media (max-width: 900px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.stat-card .label { font-size: 12.5px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; margin-bottom: 6px; }
.stat-card .value { font-size: 26px; font-weight: bold; color: var(--ink); }
.stat-card.warn .value { color: var(--danger); }
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 20px;
  /* A wide table (e.g. Settings' Module Access by Role, with 14+ columns)
     can be wider than the card itself. Without this, the table just
     overflows straight past the card's own border/background — it shows
     up sitting on the bare page background, looking broken. This confines
     it to a horizontal scrollbar inside the card instead, on every screen
     size, not just the mobile breakpoint below. */
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; flex-wrap: wrap; gap: 10px; }
.card-head h2 { font-size: 16px; margin: 0; }

/* Collapsible cards — card-head becomes clickable when a .card-toggle-icon
   is present, toggling a .collapsed class on the parent .card that hides
   .card-body. Used on pages with several stacked cards (e.g. Settings) so
   the person can close sections they aren't working on right now. */
.card.collapsible > .card-head { cursor: pointer; user-select: none; }
.card.collapsible.collapsed > .card-head { margin-bottom: 0; }
.card-toggle-icon {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 12px;
  transition: transform 0.15s ease;
}
.card.collapsed .card-toggle-icon { transform: rotate(-90deg); }
.card.collapsed .card-body { display: none; }

/* Quick Actions — the Dashboard's "what do you want to do now?" helper.
   Icon-led shortcut buttons that deep-link straight to a page's own "+ New"
   form (see utils.js's maybeTriggerQuickstart), so a role-appropriate list
   of common tasks is always the first thing on the Dashboard. */
.quick-actions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
}
.quick-action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
  padding: 16px 10px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--ink);
  text-decoration: none;
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}
.quick-action-btn:hover {
  border-color: var(--gold);
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(169, 121, 31, 0.15);
}
.quick-action-icon { font-size: 24px; line-height: 1; }
.quick-action-label { font-size: 13px; font-weight: bold; }

/* ---------- Tables ---------- */
table.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data-table th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--muted);
  border-bottom: 2px solid var(--border);
  padding: 10px 12px;
}
table.data-table td { padding: 11px 12px; border-bottom: 1px solid var(--border); }
table.data-table tr:last-child td { border-bottom: none; }
table.data-table tr:hover td { background: var(--bg-alt); }
.row-actions { display: flex; gap: 6px; }
.empty-row { text-align: center; color: var(--muted); padding: 30px !important; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11.5px; font-weight: bold; text-transform: uppercase; }
.badge-ok { background: var(--sage-light); color: var(--sage-deep); }
.badge-warn { background: var(--gold-light); color: var(--gold-deep); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-muted { background: var(--border); color: var(--muted); }

/* KPI Dashboard RAG (Red/Amber/Green) status dots — small colored circle
   sitting inline next to a stat-card's label, cheaper visually than a full
   badge pill when it's just one of several labels on a crowded grid. The
   "KPI Health & Suggested Actions" card uses the full .badge-* pills
   instead, since that's where the detail (value + suggested action) lives. */
.rag-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-left: 4px; vertical-align: middle; }
.rag-dot.rag-green { background: var(--sage); }
.rag-dot.rag-amber { background: var(--gold); }
.rag-dot.rag-red { background: var(--danger); }
.rag-dot.rag-muted { background: var(--border); }

.rag-kpi-table { width: 100%; border-collapse: collapse; margin: 10px 0 18px; }
.rag-kpi-table th { text-align: left; font-size: 11.5px; text-transform: uppercase; color: var(--muted); border-bottom: 2px solid var(--border); padding: 8px; }
.rag-kpi-table td { padding: 8px; border-bottom: 1px solid var(--border); font-size: 13.5px; vertical-align: top; }
.rag-kpi-table .rag-action-cell { color: var(--muted); font-size: 12.5px; }
.rag-category-heading { font-size: 13px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted); margin: 14px 0 0; }

/* Printable KPI report — reuses .doc-preview, with its own simple table
   styling for the RAG breakdown (the report's items table is intentionally
   plainer than doc-items, which is tuned for line-item pricing tables). */
.kpi-report-items { width: 100%; border-collapse: collapse; margin: 10px 0 22px; }
.kpi-report-items th { text-align: left; font-size: 11px; text-transform: uppercase; color: var(--muted); border-bottom: 2px solid var(--border); padding: 7px; }
.kpi-report-items td { padding: 7px; border-bottom: 1px solid var(--border); font-size: 12.5px; vertical-align: top; }
.kpi-report-items .fill-blank { border-bottom: 1px solid var(--border); min-width: 90px; display: inline-block; height: 14px; }
@media print {
  .kpi-report-items { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .badge { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(23,19,13,0.45);
  display: none; align-items: flex-start; justify-content: center;
  padding: 40px 16px; overflow-y: auto; z-index: 60;
}
.modal-overlay.open { display: flex; }
.modal {
  background: #fff; border-radius: var(--radius); padding: 26px 26px 20px;
  width: 100%; max-width: 560px;
}
.modal.wide { max-width: 780px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-close {
  background: none; border: none; font-size: 20px; cursor: pointer; color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center;
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

/* ---------- Rate Card (grouped, denser grid for many small fields) ---------- */
.rc-group-label { font-size: 13px; font-weight: bold; color: var(--gold, #A9791F); margin: 18px 0 8px; text-transform: uppercase; letter-spacing: .02em; }
.rc-group-label:first-of-type { margin-top: 4px; }
.form-grid.rc-grid { grid-template-columns: repeat(4, 1fr); gap: 12px 14px; }
@media (max-width: 900px) { .form-grid.rc-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .form-grid.rc-grid { grid-template-columns: 1fr; } }
.form-grid.rc-grid .field { margin-bottom: 4px; }

/* ---------- Line item editor (quotes/invoices) ---------- */
.line-items { width: 100%; border-collapse: collapse; margin-bottom: 12px; }
.line-items th { text-align: left; font-size: 12px; color: var(--muted); padding: 6px 8px; }
.line-items td { padding: 6px 8px; }
.line-items input, .line-items select { width: 100%; padding: 7px 8px; border: 1px solid var(--border); border-radius: 6px; }
.line-items .qty-col { width: 80px; }
.line-items .price-col { width: 110px; }
.line-items .total-col { width: 110px; text-align: right; font-weight: bold; }
.totals-box { margin-left: auto; width: 280px; }
.totals-box .row { display: flex; justify-content: space-between; padding: 5px 0; font-size: 14px; }
.totals-box .row.grand { border-top: 2px solid var(--border); margin-top: 6px; padding-top: 10px; font-size: 17px; font-weight: bold; color: var(--ink); }

/* ---------- QR label ---------- */
.qr-label {
  border: 1px dashed var(--border);
  border-radius: 8px;
  padding: 14px;
  text-align: center;
  width: 220px;
}
.qr-label canvas, .qr-label img { margin: 0 auto 8px; }
.qr-label .batch-code { font-weight: bold; font-size: 13px; letter-spacing: 0.5px; }
.qr-label .batch-meta { font-size: 11.5px; color: var(--muted); }

/* ---------- Printable quote/invoice ---------- */
.doc-preview {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  max-width: 800px;
  margin: 0 auto;
}
.doc-preview .doc-head { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 26px; }
.doc-preview .doc-head img { width: 150px; }
.doc-preview .doc-title { text-align: right; }
.doc-preview .doc-title h2 { margin: 0; font-size: 22px; }
.doc-preview .doc-title .num { color: var(--muted); font-size: 13px; }
.doc-preview .parties { display: flex; justify-content: space-between; margin-bottom: 24px; gap: 20px; }
.doc-preview .parties .block h4 { font-size: 12px; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.doc-preview .parties .block p { font-size: 13.5px; margin: 0; }
.doc-preview table.doc-items { width: 100%; border-collapse: collapse; margin-bottom: 20px; }
.doc-preview table.doc-items th { text-align: left; font-size: 11.5px; text-transform: uppercase; color: var(--muted); border-bottom: 2px solid var(--border); padding: 8px; }
.doc-preview table.doc-items td { padding: 8px; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.doc-preview .doc-footer { display: flex; justify-content: space-between; align-items: flex-end; margin-top: 30px; }
.doc-preview .doc-footer .notes { font-size: 12px; color: var(--muted); max-width: 320px; }
.doc-preview .doc-footer .signature { font-size: 13px; text-align: right; color: var(--ink); }
.doc-preview .doc-footer .signature .sign-space { height: 46px; }
.doc-preview .doc-footer .signature .sign-line { border-top: 1px solid var(--border); padding-top: 4px; white-space: nowrap; }
.doc-preview .place-of-supply { font-size: 12px; color: var(--muted); margin: 4px 0 18px; }
.doc-preview .doc-terms-block { margin-top: 18px; padding-top: 10px; border-top: 1px solid var(--border); font-size: 10.5px; line-height: 1.5; color: var(--muted); }
.doc-preview .doc-terms-block .doc-terms-label { display: block; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; font-size: 10px; color: var(--ink); margin-bottom: 3px; }

/* Hidden on screen, shown only when the browser is actually printing —
   used for the Job Card's printable document (see manufacturing.html),
   which previously sat visibly at the top of the on-screen detail view at
   all times. Now the on-screen view is normal tabbed UI, and this only
   appears in the output triggered by the "Print Job Card" button. */
.print-only { display: none; }

@media print {
  .sidebar, .topbar, .no-print { display: none !important; }
  .main { margin-left: 0 !important; }
  body { background: #fff; }
  .doc-preview { border: none; padding: 0; }
  .print-only { display: block !important; }
}

/* ---------- Utility ---------- */
.muted { color: var(--muted); }
.text-right { text-align: right; }
.flex-between { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; }
.gap-8 { display: flex; gap: 8px; flex-wrap: wrap; }
.mt-16 { margin-top: 16px; }
.mb-0 { margin-bottom: 0; }
.search-box { padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; min-width: 220px; }
.demo-banner {
  background: var(--gold-light);
  color: var(--gold-deep);
  font-size: 13px;
  font-weight: bold;
  text-align: center;
  padding: 8px 16px;
}

.install-banner {
  background: var(--sage-light);
  color: var(--sage-deep);
  font-size: 13px;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  text-align: center;
}
.install-banner .btn {
  padding: 5px 14px;
  font-size: 12.5px;
}
.install-banner .install-dismiss {
  background: none;
  border: none;
  color: var(--sage-deep);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.offline-banner {
  background: var(--danger-light);
  color: var(--danger);
  font-size: 13px;
  font-weight: bold;
  text-align: center;
  padding: 8px 16px;
}

.backup-banner {
  background: var(--gold-light);
  color: var(--gold-deep);
  font-size: 13px;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  text-align: center;
}
.backup-banner .btn {
  padding: 5px 14px;
  font-size: 12.5px;
}
.backup-banner .backup-dismiss {
  background: none;
  border: none;
  color: var(--gold-deep);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.update-banner {
  background: var(--sage);
  color: #fff;
  font-size: 13px;
  font-weight: bold;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  text-align: center;
}
.update-banner .btn {
  padding: 5px 14px;
  font-size: 12.5px;
  font-weight: bold;
}
.update-banner .update-dismiss {
  background: none;
  border: none;
  color: #fff;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .nav-toggle-mobile { display: block; }
  .topbar { padding-left: 60px; }
}

/* ---------- Mobile refinement pass ----------
   Touch targets, table overflow, modal sizing — applied on top of the
   existing responsive rules above rather than replacing them. */
@media (max-width: 860px) {
  .content { padding: 18px 14px 50px; }
  .topbar { padding: 14px 16px 14px 60px; }

  /* Tables: .card already scrolls sideways (see the base rule above) —
     just keep columns from getting crushed on a small screen. */
  table.data-table { min-width: 640px; }
  .line-items { min-width: 480px; }

  /* Search box + card-head action buttons: each takes the full row width
     when it wraps onto its own line, instead of staying pinned to a narrow
     intrinsic width in the middle of the screen. */
  .card-head .search-box { min-width: 0; width: 100%; }
  .card-head > .gap-8 { width: 100%; }
  .card-head > .gap-8 .btn { flex: 1; }

  /* Modals: reclaim vertical space and centre instead of anchoring to the
     top, which wastes a lot of room on a phone. */
  .modal-overlay { padding: 12px; align-items: center; }
  .modal { padding: 20px 16px 16px; max-height: calc(100vh - 24px); overflow-y: auto; }
  .modal-actions { flex-wrap: wrap; }
  .modal-actions .btn { flex: 1; min-width: 120px; }
}

/* Minimum comfortable tap-target size on touch devices, regardless of
   viewport width (covers small tablets and folded phones too). */
@media (pointer: coarse) {
  .btn, .btn-sm { min-height: 40px; }
  .modal-close, .install-dismiss, .backup-dismiss, .update-dismiss { min-width: 40px; min-height: 40px; }
  .row-actions .btn-sm { min-height: 36px; }
  table.data-table td, table.data-table th { padding: 12px; }
}

/* ---------- Field Sales / Delivery / Map (Phase 2) ---------- */
.field-tabs { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.field-tabs .btn { opacity: 0.6; }
.field-tabs .btn.active { opacity: 1; }

.badge-info { background: #DCEAF6; color: #1E5A8A; }

.photo-capture {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 16px;
  text-align: center;
  cursor: pointer;
  background: var(--bg-alt);
}
.photo-capture:hover { border-color: var(--gold); }
.photo-capture input[type="file"] { display: none; }
.photo-capture .hint { font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.photo-preview { max-width: 220px; border-radius: 8px; margin: 10px auto 0; display: block; border: 1px solid var(--border); }

.delivery-line-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.delivery-line-row:last-child { border-bottom: none; }
.delivery-line-row .name { flex: 1; font-size: 14px; }
.delivery-line-row .ordered-qty { font-size: 12.5px; color: var(--muted); }
.delivery-line-row input.delivered-qty { width: 80px; padding: 7px 8px; border: 1px solid var(--border); border-radius: 6px; }

.geo-status { font-size: 12.5px; color: var(--muted); margin: 8px 0; display: flex; align-items: center; gap: 6px; }
.geo-status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--sage); flex-shrink: 0; }
.geo-status.pending .dot { background: var(--gold); }
.geo-status.failed .dot { background: var(--danger); }

/* Map page */
.map-layout { display: grid; grid-template-columns: 300px 1fr; gap: 18px; align-items: start; }
@media (max-width: 900px) { .map-layout { grid-template-columns: 1fr; } }
.map-canvas { height: 560px; border-radius: var(--radius); border: 1px solid var(--border); overflow: hidden; }
.exec-list-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 8px; border-bottom: 1px solid var(--border); cursor: pointer;
}
.exec-list-item:last-child { border-bottom: none; }
.exec-list-item:hover { background: var(--bg-alt); }
.exec-list-item .swatch { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.exec-list-item .meta { flex: 1; min-width: 0; }
.exec-list-item .meta strong { display: block; font-size: 13.5px; }
.exec-list-item .meta span { font-size: 12px; color: var(--muted); }

.leaflet-popup-content { font-size: 13px; }

/* Attendance Kiosk */
.kiosk-wrap { max-width: 520px; margin: 0 auto; text-align: center; }
.kiosk-wrap h2 { margin-bottom: 4px; }
.kiosk-camera-box {
  position: relative; width: 100%; aspect-ratio: 4/3; background: #111;
  border-radius: var(--radius); overflow: hidden; margin: 16px 0;
}
.kiosk-camera-box video, .kiosk-camera-box img { width: 100%; height: 100%; object-fit: cover; display: block; }
.kiosk-overlay-msg {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 14px; padding: 20px; text-align: center; background: rgba(0,0,0,0.5);
}
.kiosk-actions { display: flex; gap: 14px; justify-content: center; margin-bottom: 10px; flex-wrap: wrap; }
.kiosk-actions .btn { flex: 1; min-width: 140px; max-width: 220px; padding: 16px; font-size: 16px; }
.kiosk-status { font-size: 13.5px; color: var(--muted); min-height: 20px; margin: 6px 0; }
.kiosk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; margin: 14px 0; }
.kiosk-grid button {
  padding: 16px 8px; border: 1px solid var(--border); border-radius: var(--radius);
  background: #fff; cursor: pointer; font-size: 13.5px; font-weight: bold; color: var(--ink);
}
.kiosk-grid button:hover { border-color: var(--gold); background: var(--bg-alt); }
.kiosk-success { padding: 26px 10px; }
.kiosk-success .big-check {
  width: 64px; height: 64px; line-height: 64px; border-radius: 50%; background: var(--sage-light);
  color: var(--sage-deep); font-size: 30px; margin: 0 auto 14px; font-weight: bold;
}
.attendance-photo-thumb {
  width: 42px; height: 42px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border);
  cursor: pointer; margin-right: 4px;
}

.leaflet-popup-content { font-size: 13px; }

/* Production Stages board (Manufacturing) — one column per stage, cards
   for each stage-tracking-enabled open Job Card currently sitting there. */
.stages-board { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 8px; }
.stage-column {
  background: var(--bg-alt); border: 1px solid var(--border); border-radius: var(--radius);
  min-width: 220px; flex: 1 0 220px; padding: 12px;
}
.stage-column h3 { font-size: 13px; margin: 0 0 10px; color: var(--gold-deep); text-transform: uppercase; letter-spacing: 0.03em; }
.stage-column.stage-column-done h3 { color: var(--sage-deep); }
.stage-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px; margin-bottom: 10px; font-size: 13px;
}
.stage-card .stage-card-title { font-weight: 600; margin-bottom: 2px; }
.stage-card .stage-card-meta { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.stage-column-empty { color: var(--muted); font-size: 12.5px; font-style: italic; }
