/* ============================================================================
   ElloTree design system — mobile-first, no framework.
   ========================================================================= */

:root {
  --green-900: #14532d;
  --green-700: #15803d;
  --green-600: #16a34a;
  --green-100: #dcfce7;
  --ink: #111827;
  --ink-soft: #4b5563;
  --muted: #6b7280;
  --line: #e5e7eb;
  --bg: #f3f4f6;
  --card: #ffffff;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --amber: #d97706;
  --amber-bg: #fef3c7;
  --blue: #2563eb;
  --blue-bg: #dbeafe;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --sidebar-w: 232px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
a { color: var(--green-700); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.35rem; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 24px 0 10px; }
h3 { font-size: 1rem; margin: 16px 0 8px; }
p  { margin: 8px 0; }
code { background: #eef2f1; padding: 1px 5px; border-radius: 4px; font-size: .85em; }

/* --- Shell -------------------------------------------------------------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); background: var(--green-900); color: #e7f0e9;
  flex-shrink: 0; display: flex; flex-direction: column; padding: 12px 0 20px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 8px 18px 16px; font-weight: 700; font-size: 1.05rem; color: #fff; }
.brand-mark { font-size: 1.3rem; flex-shrink: 0; }
/* Stacked wordmark: first word large, the rest smaller on the line below —
   keeps "ElloTree / Inventory Management" tidy in the sidebar, auth cards
   and on phones. */
.brand-name { display: inline-flex; flex-direction: column; line-height: 1.12; }
.brand-lead { font-weight: 700; }
.brand-sub { font-size: .58em; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; opacity: .82; }
.nav { display: flex; flex-direction: column; }
.nav-link {
  display: flex; align-items: center; gap: 11px; padding: 10px 18px;
  color: #cfe3d4; font-weight: 500;
}
.nav-link:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.nav-link.active { background: rgba(255,255,255,.12); color: #fff; box-shadow: inset 3px 0 0 var(--green-600); }
.nav-ic { width: 20px; text-align: center; opacity: .85; }
.nav-section { padding: 18px 18px 6px; font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; color: #86a892; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 40;
}
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.content { padding: 20px 16px 60px; max-width: 1200px; width: 100%; margin: 0 auto; }

.menu-btn { display: none; }
.sidebar-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 90; }

/* --- Buttons / inputs ---------------------------------------------------- */
.btn, button.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 15px;
  background: var(--green-700); border: 1px solid var(--green-700); color: #fff;
  border-radius: 8px; font-weight: 600; font-size: .9rem; cursor: pointer;
}
.btn:hover { background: var(--green-600); text-decoration: none; }
/* `button.btn` (0,1,1) out-specifies a bare `.btn-outline` / `.btn-danger`
   (0,1,0), so on a <button> every variant lost to the primary green: Delete
   looked exactly like Save, and every secondary action looked primary.
   Anchors were never affected — there is no `a.btn` rule — which is why the
   bug hid for so long. Qualifying each variant to the same specificity hands
   the decision back to source order, which is what the cascade intended. */
.btn-outline, button.btn-outline { background: transparent; color: var(--green-700); }
.btn-outline:hover, button.btn-outline:hover { background: var(--green-100); }
.btn-danger, button.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger:hover, button.btn-danger:hover { background: #b91c1c; }
/* Used in five views and defined in none: the quiet neighbour of a danger
   button ("Disable" beside "Delete"), which was rendering as a primary. */
.btn-ghost, button.btn-ghost { background: transparent; color: var(--ink-soft); border-color: var(--line); }
.btn-ghost:hover, button.btn-ghost:hover { background: var(--bg); color: var(--ink); }
.btn-sm { padding: 4px 10px; font-size: .8rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.icon-btn {
  background: none; border: none; font-size: 1.15rem; cursor: pointer;
  padding: 6px 8px; border-radius: 8px; position: relative; color: var(--ink);
}
.icon-btn:hover { background: var(--bg); }
.bell-count {
  position: absolute; top: 0; right: 0; background: var(--red); color: #fff;
  font-size: .62rem; font-weight: 700; border-radius: 999px; padding: 1px 5px;
}

input, select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 8px;
  font: inherit; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--green-600); outline-offset: 0; border-color: var(--green-600); }
input[type="checkbox"], input[type="radio"] { width: auto; }
label { font-weight: 600; font-size: .84rem; display: block; margin-bottom: 4px; color: var(--ink-soft); }
.hint { font-size: .8rem; color: var(--muted); margin-top: 3px; }
.req::after { content: " *"; color: var(--red); }

.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
.form-actions { margin-top: 18px; display: flex; gap: 10px; flex-wrap: wrap; }
.field { min-width: 0; }
.check-row { display: flex; align-items: center; gap: 8px; }
.check-row label { margin: 0; }

/* --- Cards / KPIs --------------------------------------------------------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px; }
.card-title { font-weight: 700; margin: 0 0 12px; font-size: 1rem; display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); font-size: .88rem; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi .kpi-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.kpi .kpi-value { font-size: 1.5rem; font-weight: 700; margin-top: 2px; }
.kpi.warn .kpi-value { color: var(--amber); }
.kpi.crit .kpi-value { color: var(--red); }
.kpi.good .kpi-value { color: var(--green-700); }

/* --- Tables (stack to cards on phones) ------------------------------------ */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; background: var(--card); font-size: .9rem; }
table.data th {
  text-align: left; padding: 9px 12px; border-bottom: 2px solid var(--line);
  font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
  white-space: nowrap;
}
table.data td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.data tr:hover td { background: #fafcfa; }
/* `table.data th` (0,1,2) out-specifies a bare `th.num` (0,1,1), so every
   numeric heading in the app rendered left while its figures rendered right —
   the heading and the number it labels sat at opposite ends of the column.
   Qualifying the selector to match puts them back over each other. */
td.num, th.num, table.data td.num, table.data th.num {
  text-align: right; font-variant-numeric: tabular-nums;
}
.row-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }

/* --- Badges ----------------------------------------------------------------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: .72rem; font-weight: 700; white-space: nowrap; }
.badge-green { background: var(--green-100); color: var(--green-900); }
.badge-red { background: var(--red-bg); color: var(--red); }
.badge-amber { background: var(--amber-bg); color: var(--amber); }
.badge-blue { background: var(--blue-bg); color: var(--blue); }
.badge-gray { background: #f3f4f6; color: var(--ink-soft); }

/* --- List thumbnails ------------------------------------------------------------ */
.thumb-cell { width: 44px; padding-right: 0 !important; }
.thumb { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px;
         border-radius: 6px; object-fit: cover; border: 1px solid var(--line); background: #fff; vertical-align: middle; }
.thumb-empty { color: var(--line); font-size: 1rem; background: #fafafa; }

/* --- 2FA QR enrolment ----------------------------------------------------------- */
.qr-enroll { display: flex; gap: 20px; flex-wrap: wrap; align-items: flex-start; margin: 10px 0 14px; }
.qr-box { background: #fff; padding: 10px; border: 1px solid var(--line); border-radius: 10px; flex-shrink: 0; }
.qr-box svg { display: block; width: 200px; height: 200px; }
.qr-manual { min-width: 220px; flex: 1; }
.qr-manual code { word-break: break-all; }

/* --- Callouts (inline emphasis boxes) ----------------------------------------- */
.callout { border: 1px solid var(--line); border-left-width: 4px; border-radius: 8px; padding: 12px 16px; font-size: .9rem; }
.callout-warn { background: var(--amber-bg); border-color: var(--amber); }
.callout-danger { background: var(--red-bg); border-color: var(--red); }

/* --- Toasts / flashes -------------------------------------------------------- */
.toasts { position: fixed; top: 14px; right: 14px; z-index: 200; display: flex; flex-direction: column; gap: 8px; max-width: min(92vw, 380px); }
.toast { padding: 11px 16px; border-radius: 8px; box-shadow: var(--shadow); background: var(--ink); color: #fff; font-size: .9rem; animation: toast-in .25s ease; }
.toast-ok { background: var(--green-700); }
.toast-error { background: var(--red); }
.toast-warn { background: var(--amber); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } }

/* --- Modals -------------------------------------------------------------------- */
.modal-backdrop { position: fixed; inset: 0; background: rgba(17,24,39,.5); z-index: 150; display: flex; align-items: flex-start; justify-content: center; padding: 6vh 12px; overflow-y: auto; }
.modal { background: #fff; border-radius: var(--radius); max-width: 620px; width: 100%; padding: 20px; box-shadow: 0 10px 40px rgba(0,0,0,.2); }
.modal h2 { margin-top: 0; }
[hidden] { display: none !important; }

/* --- Misc components ------------------------------------------------------------ */
.filter-bar { display: flex; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; align-items: center; }
/* The min-width is for the text and select controls. Applied to every input it
   also stretched CHECKBOXES to 140px, so each one sat a hundred pixels from
   the label it belongs to — invisible until a filter bar grew its first tick
   box, and then wrong on every one of them. */
.filter-bar input:not([type="checkbox"]):not([type="radio"]),
.filter-bar select { width: auto; min-width: 140px; }
/* A tick and its label wrap to the next line of the bar as a unit rather than
   being squeezed narrower than their own text — the label is itself a nowrap
   flex line, so squeezed text spills instead of wrapping. The max-width is the
   escape hatch: a tick whose label is longer than the whole bar (the compliance
   one, for a business licensed in a dozen states) would otherwise hold its
   one-line width and run off the right of the card, scrolling the page
   sideways. Capped at the bar, its own text wraps instead. */
.filter-bar .check-row { flex-shrink: 0; max-width: 100%; }
.empty { text-align: center; color: var(--muted); padding: 34px 10px; }
.pager { display: flex; gap: 6px; margin-top: 14px; flex-wrap: wrap; }
.pager a, .pager span { padding: 5px 11px; border: 1px solid var(--line); border-radius: 6px; background: #fff; font-size: .85rem; }
.pager .on { background: var(--green-700); color: #fff; border-color: var(--green-700); }
.spark { width: 110px; height: 30px; }
.progress { height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; }
.progress > div { height: 100%; background: var(--green-600); }
.progress.warn > div { background: var(--amber); }
.progress.crit > div { background: var(--red); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.audit-diff { font-size: .82rem; }
.audit-diff .from { color: var(--red); text-decoration: line-through; }
.audit-diff .to { color: var(--green-700); font-weight: 600; }
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs a { padding: 8px 14px; font-weight: 600; color: var(--muted); border-radius: 8px 8px 0 0; }
.tabs a.on { color: var(--green-900); box-shadow: inset 0 -2px 0 var(--green-700); }
.tabs a:hover { text-decoration: none; background: var(--green-100); }

/* --- Public storefront (guest catalog) ----------------------------------------- */
.shop-body { background: var(--bg); }
.shop-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 18px; background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 50; flex-wrap: wrap;
}
.shop-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.05rem; color: var(--green-900); }
.shop-brand:hover { text-decoration: none; }
.shop-nav { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.shop-nav > a:first-child { font-weight: 600; }
.shop-main { max-width: 1100px; margin: 0 auto; padding: 22px 16px 40px; }
.shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; margin-bottom: 18px; }
.shop-card {
  display: flex; flex-direction: column; gap: 6px; background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 16px; color: var(--ink);
}
.shop-card:hover { text-decoration: none; border-color: var(--green-600); }
.shop-card-cat { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.shop-card-name { font-weight: 700; line-height: 1.3; }
.shop-card-desc { font-size: .82rem; color: var(--ink-soft); }
.shop-card-price { margin-top: auto; padding-top: 6px; }
.shop-price-locked { color: var(--muted); font-weight: 600; }
.shop-big-price { font-size: 1.4rem; font-weight: 700; margin-bottom: 6px; }
.shop-cta { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.shop-footer {
  max-width: 1100px; margin: 0 auto; padding: 14px 16px 40px;
  border-top: 1px solid var(--line); font-size: .78rem; color: var(--muted);
}

/* --- Auth screens ------------------------------------------------------------------ */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(160deg, var(--green-900), #0b3018 70%); padding: 20px; }
.auth-card { background: #fff; border-radius: 14px; padding: 30px 28px; width: 100%; max-width: 400px; box-shadow: 0 15px 50px rgba(0,0,0,.35); }
.auth-card .brand { justify-content: center; color: var(--green-900); padding: 0 0 6px; font-size: 1.3rem; }
.auth-card h1 { text-align: center; font-size: 1.1rem; color: var(--ink-soft); font-weight: 500; }
.auth-card form { margin-top: 18px; display: flex; flex-direction: column; gap: 13px; }
.auth-links { margin-top: 14px; text-align: center; font-size: .85rem; display: flex; flex-direction: column; gap: 5px; }
.auth-error { background: var(--red-bg); color: var(--red); padding: 9px 12px; border-radius: 8px; font-size: .88rem; }
.auth-ok { background: var(--green-100); color: var(--green-900); padding: 9px 12px; border-radius: 8px; font-size: .88rem; }

/* --- User menu dropdown --------------------------------------------------------------- */
.user-menu { position: relative; }
.user-btn { display: flex; align-items: center; gap: 8px; background: none; border: none; cursor: pointer; font: inherit; padding: 4px 8px; border-radius: 8px; }
.user-btn:hover { background: var(--bg); }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--green-700); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: .85rem; }
.dropdown { display: none; position: absolute; right: 0; top: calc(100% + 6px); background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); min-width: 210px; z-index: 100; overflow: hidden; }
.user-menu.open .dropdown { display: block; }
.dropdown a, .dropdown button { display: block; width: 100%; text-align: left; padding: 10px 14px; background: none; border: none; font: inherit; color: var(--ink); cursor: pointer; }
.dropdown a:hover, .dropdown button:hover { background: var(--bg); text-decoration: none; }
.dropdown-meta { padding: 10px 14px; font-size: .78rem; color: var(--muted); border-bottom: 1px solid var(--line); }
.biz-switcher select { max-width: 230px; font-weight: 600; }
.brand-logo { max-height: 34px; max-width: 170px; object-fit: contain; border-radius: 6px; background: #fff; padding: 2px 6px; }
.global-search { flex: 1; max-width: 340px; }
.global-search input { padding: 7px 12px; border-radius: 999px; font-size: .88rem; }
@media (max-width: 700px) { .global-search { display: none; } }

/* --- Alerts list ----------------------------------------------------------------------- */
.alert-item { display: flex; gap: 12px; padding: 13px 6px; border-bottom: 1px solid var(--line); align-items: flex-start; }
.alert-item.unread { background: #f4faf5; }
.alert-dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 6px; flex-shrink: 0; }
.alert-dot.info { background: var(--blue); } .alert-dot.warning { background: var(--amber); } .alert-dot.critical { background: var(--red); }
.alert-item .when { color: var(--muted); font-size: .78rem; white-space: nowrap; }

.site-footer { margin-top: 40px; padding-top: 14px; border-top: 1px solid var(--line); font-size: .78rem; color: var(--muted); }
.billing-banner { background: var(--amber-bg); color: var(--amber); padding: 9px 16px; font-size: .88rem; font-weight: 600; border-bottom: 1px solid var(--line); }
.billing-banner a { color: inherit; text-decoration: underline; }
.chart-box { position: relative; width: 100%; }
.chart-box canvas { width: 100%; height: 100%; display: block; }
.chart-controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.chart-controls select { width: auto; }
.chart-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .8rem; margin-top: 8px; }
.chart-legend .key { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend .swatch { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }

/* --- Print (invoices / POs) --------------------------------------------------------------- */
@media print {
  .sidebar, .topbar, .toasts, .no-print { display: none !important; }
  .content { padding: 0; max-width: none; }
  .card { border: none; box-shadow: none; }
  body { background: #fff; }
}

/* --- Mobile ---------------------------------------------------------------------------------- */
@media (max-width: 900px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 95; transform: translateX(-100%); transition: transform .2s ease; }
  body.sidebar-open .sidebar { transform: none; }
  body:not(.sidebar-open) .sidebar-backdrop { display: none; }
  .menu-btn { display: inline-flex; }
  .user-name { display: none; }
  .two-col { grid-template-columns: 1fr; }

  /* Tables become stacked cards; cells label themselves via data-th. */
  table.data.stack thead { display: none; }
  table.data.stack, table.data.stack tbody, table.data.stack tr, table.data.stack td { display: block; width: 100%; }
  table.data.stack tr { border: 1px solid var(--line); border-radius: 10px; margin-bottom: 10px; background: var(--card); padding: 4px 0; }
  table.data.stack td { border: none; padding: 6px 14px; text-align: left !important; }
  table.data.stack td[data-th]::before { content: attr(data-th); display: block; font-size: .68rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
  .row-actions { justify-content: flex-start; }
}

/* --- Searchable selects (combobox) --------------------------------------------
   app.js upgrades big <select>s into .combo: the native select stays in the
   DOM (visually hidden, script-focusable for browser validation) under a
   button + filter panel. Touch targets and a 16px search input keep it
   comfortable on phones (sub-16px inputs make iOS zoom the page). */
.combo { position: relative; min-width: 0; }
.combo-native {
  position: absolute !important; width: 1px !important; height: 1px !important;
  padding: 0 !important; margin: -1px !important; border: 0 !important;
  clip: rect(0 0 0 0); overflow: hidden; white-space: nowrap;
}
.combo-btn {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%; min-height: 38px; padding: 8px 10px;
  border: 1px solid #d1d5db; border-radius: 8px; background: #fff;
  font: inherit; color: var(--ink); cursor: pointer; text-align: left;
}
.combo-btn:focus { outline: 2px solid var(--green-600); outline-offset: 0; border-color: var(--green-600); }
.combo-btn[disabled] { opacity: .55; cursor: not-allowed; background: var(--bg); }
.combo-txt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-height: 1.2em; }
.combo-txt.combo-placeholder { color: var(--muted); }
.combo-caret { color: var(--muted); font-size: .78em; flex-shrink: 0; }
.combo-panel {
  /* min-width has to yield on a narrow phone: a flat 230px overhung the field
     it belongs to on a 320px screen. */
  position: absolute; z-index: 160; top: calc(100% + 4px); left: 0; right: 0;
  min-width: min(230px, 100%); max-width: calc(100vw - 16px);
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 10px 34px rgba(0,0,0,.16); padding: 8px;
}
.combo-panel:focus { outline: none; }   /* focus target on touch, not a control */
.combo-panel.up { top: auto; bottom: calc(100% + 4px); }
.combo-panel.fixed { position: fixed; right: auto; min-width: min(230px, calc(100vw - 16px)); }
.combo-search { font-size: 16px; margin-bottom: 6px; }
.combo-list {
  list-style: none; margin: 0; padding: 0;
  max-height: min(300px, 42vh); overflow-y: auto; -webkit-overflow-scrolling: touch;
}
.combo-opt { padding: 10px 10px; border-radius: 6px; cursor: pointer; }
.combo-opt:hover, .combo-opt.active { background: var(--green-100); }
.combo-opt.sel { font-weight: 700; }
.combo-opt.sel::after { content: " ✓"; color: var(--green-700); }
.combo-group { padding: 8px 10px 2px; font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.combo-none { padding: 10px; color: var(--muted); }
.filter-bar .combo { width: auto; min-width: 180px; }
.biz-switcher .combo { min-width: 170px; max-width: 230px; }
.biz-switcher .combo-btn { font-weight: 600; }

/* --- CRM: pipeline board, timeline, detail grids ------------------------------ */
.pipe-board { display: flex; gap: 12px; overflow-x: auto; align-items: flex-start; padding-bottom: 10px; margin-bottom: 18px; -webkit-overflow-scrolling: touch; }
.pipe-col { flex: 0 0 250px; min-width: 250px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 10px 4px; }
.pipe-col-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; padding: 2px 4px 10px; border-bottom: 2px solid var(--line); margin-bottom: 10px; }
.deal-card { border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; margin-bottom: 9px; background: #fff; box-shadow: var(--shadow); }
.deal-amount { font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.deal-moves { display: flex; gap: 5px; margin-top: 8px; flex-wrap: wrap; }
.deal-moves form { display: inline-flex; }
.pipe-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.pipe-sum-col { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.pipe-sum-stage { font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.pipe-sum-count { font-weight: 600; margin-top: 2px; }
.pipe-sum-value { color: var(--green-700); font-weight: 700; font-variant-numeric: tabular-nums; }
.stage-track { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.stage-track form { display: inline-flex; }
.lost-form { display: inline-flex !important; gap: 6px; align-items: center; flex-wrap: wrap; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { border-left: 2px solid var(--line); margin-left: 9px; padding: 0 0 16px 16px; position: relative; }
.timeline li:last-child { padding-bottom: 2px; }
.timeline li::before { content: ''; width: 10px; height: 10px; border-radius: 50%; background: var(--green-600); border: 2px solid #fff; position: absolute; left: -7px; top: 3px; }
.tl-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.tl-ic { opacity: .7; }
.tl-body { margin: 4px 0 2px; font-size: .9rem; white-space: pre-wrap; word-break: break-word; }
.mini-row { display: flex; gap: 10px; align-items: center; padding: 8px 2px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.mini-row:last-child { border-bottom: none; }
.mini-row form { display: inline-flex; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.link-btn { background: none; border: 0; padding: 0; font: inherit; font-size: inherit; color: var(--green-700); cursor: pointer; text-decoration: underline; }
.link-btn.link-danger { color: var(--red); }
@media (max-width: 900px) {
  .pipe-col { flex-basis: 220px; min-width: 220px; }
}

/* --- Image gallery + lightbox ------------------------------------------------ */
.img-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(116px, 1fr));
  gap: 10px;
  margin: 4px 0 2px;
}
.img-gallery a {
  display: block;
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--card);
  cursor: zoom-in;
}
.img-gallery img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .2s ease; }
.img-gallery a:hover img { transform: scale(1.06); }

body.lightbox-open { overflow: hidden; }
.lightbox {
  position: fixed; inset: 0; z-index: 2000;
  display: flex; align-items: center; justify-content: center;
  background: rgba(9, 14, 11, .92);
}
.lightbox[hidden] { display: none; }
.lightbox-stage {
  margin: 0; max-width: 94vw; max-height: 90vh;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.lightbox-img {
  max-width: 94vw; max-height: 84vh; object-fit: contain;
  border-radius: 8px; background: #fff; box-shadow: 0 12px 48px rgba(0, 0, 0, .55);
  cursor: zoom-in; transition: transform .15s ease;
}
.lightbox-img.zoomed { transform: scale(2.3); cursor: zoom-out; }
.lightbox-cap { color: #e8f0ea; font-size: .9rem; text-align: center; max-width: 82vw; }
.lightbox-btn {
  position: absolute; border: none; cursor: pointer;
  width: 46px; height: 46px; border-radius: 50%;
  background: rgba(255, 255, 255, .15); color: #fff;
  font-size: 1.7rem; line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.lightbox-btn:hover { background: rgba(255, 255, 255, .3); }
.lightbox-close { top: 16px; right: 16px; }
.lightbox-prev { left: 14px; top: 50%; transform: translateY(-50%); }
.lightbox-next { right: 14px; top: 50%; transform: translateY(-50%); }

/* --- Command palette (Ctrl-K) ------------------------------------------------ */
.palette-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 120; display: flex; align-items: flex-start; justify-content: center; padding: 12vh 16px 16px; }
.palette { background: var(--card, #fff); border-radius: 12px; box-shadow: 0 24px 60px rgba(0, 0, 0, .3); width: 100%; max-width: 560px; overflow: hidden; }
.palette input { width: 100%; border: 0; border-bottom: 1px solid var(--line, #e5e7eb); padding: 14px 16px; font-size: 1rem; outline: none; background: transparent; color: inherit; }
.palette ul { list-style: none; margin: 0; padding: 6px 0; max-height: 46vh; overflow-y: auto; }
.palette li { display: flex; align-items: center; gap: 10px; padding: 8px 16px; cursor: pointer; font-size: .92rem; }
.palette li.on, .palette li:hover { background: var(--green-50, #f0fdf4); }
.palette .pal-group { flex-shrink: 0; font-size: .7rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted, #6b7280); width: 74px; }
.palette-hint { padding: 8px 16px; font-size: .74rem; color: var(--muted, #6b7280); border-top: 1px solid var(--line, #e5e7eb); }
.saved-views > summary { list-style: none; cursor: pointer; }
.saved-views > summary::-webkit-details-marker { display: none; }

/* --- Inline quick-edit (td[data-edit]) -----------------------------------
   The affordance has to be discoverable without shouting: a dotted underline
   on hover/focus, and the cell keeps its own width so the row does not jump
   when the input appears. */
td[data-edit] { cursor: text; }
td[data-edit]:hover, td[data-edit]:focus-visible { background: var(--green-50, #f0fdf4); outline: none; }
td[data-edit]:hover:not(.editing) { box-shadow: inset 0 -1px 0 0 var(--line, #e5e7eb); }
td[data-edit].is-empty { color: var(--muted, #6b7280); }
td[data-edit].saving { opacity: .55; pointer-events: none; }
td[data-edit].editing { padding: 2px 6px; }
.quick-edit { width: 100%; min-width: 90px; box-sizing: border-box; font: inherit;
  padding: 4px 6px; border: 1px solid var(--accent, #16a34a); border-radius: 6px; background: #fff; }
.quick-edit:focus { outline: 2px solid var(--accent, #16a34a); outline-offset: -1px; }
/* Wider modal for the CRM record forms — a 620px box makes a 14-field grid
   into a single tall column. */
.modal.modal-wide { max-width: 860px; }

/* Company logos: a fixed box so a wide wordmark and a square icon line up in
   the same column, and a neutral frame so a transparent PNG stays visible in
   both themes. */
.crm-logo { object-fit: contain; border-radius: 4px; background: #fff;
  border: 1px solid var(--line, #e5e7eb); padding: 1px; vertical-align: middle; margin-right: 6px; flex-shrink: 0; }

/* A 37-field record form is taller than the viewport, and a Save button you
   have to scroll to find reads as a form with no Save button. */
.modal .form-actions { position: sticky; bottom: -20px; background: #fff;
  padding: 12px 0; margin-bottom: -20px; border-top: 1px solid var(--line, #e5e7eb); z-index: 1; }

/* --- Long-value containment ---------------------------------------------
   A CRM holds strings nobody chose: a 100-character Facebook URL, an email
   at a corporate subdomain, an imported company name with no spaces in it.
   Grid and flex children default to min-width:auto, which refuses to shrink
   below their content — so one long value pushes its neighbour sideways and
   the whole page gains a horizontal scrollbar. These rules make the layout
   the authority on width and the text wrap to fit. */
.two-col > *, .page-head > *, .card, .kpi { min-width: 0; }
.detail-grid > * { min-width: 0; }
/* anywhere, not break-word: break-word will not split an unbroken URL that
   started on its own line, which is exactly the case that overflows. */
.detail-grid > * > div, .detail-grid > * > span,
.page-head h1, .page-head .sub,
.card > p, .card > h3 + p { overflow-wrap: anywhere; }
/* Links are the worst offenders and appear in both grids and cells — but NOT
   buttons: "anywhere" happily breaks Edit into Ed / it, and a two-word action
   like "Open full record" into confetti. A button's label is a fixed short
   phrase; if a column is too narrow for it the column is wrong, not the word. */
.detail-grid a:not(.btn), td a:not(.btn), .card > p a:not(.btn) { overflow-wrap: anywhere; }
.btn, button.btn { white-space: nowrap; }
/* The actions column sizes to its buttons instead of being squeezed by the
   data columns beside it. */
td:has(> .row-actions), th:last-child { width: 1%; white-space: nowrap; }
/* Read-only values echoed into inputs stay on one line and scroll internally,
   which is correct for a field — but the field itself must not stretch. */
.field, .field input, .field select, .field textarea { max-width: 100%; }
/* Compact rows (a company's contacts, its deals) and empty-state copy both
   quote record names back at the reader, so both meet the same strings. */
.mini-row > * { min-width: 0; }
.mini-row, .empty { overflow-wrap: anywhere; }

/* --- Filter-box type-ahead ------------------------------------------------
   Anchored to a wrapper we insert, because the filter bar is a flex row and
   the input's own parent is not a positioning context. */
.suggest-wrap { position: relative; display: inline-flex; flex: 1 1 auto; min-width: 0; }
.suggest-wrap > input { width: 100%; }
.suggest { position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 60;
  list-style: none; margin: 0; padding: 4px 0; max-height: 300px; overflow-y: auto;
  background: var(--card, #fff); border: 1px solid var(--line, #e5e7eb);
  border-radius: 10px; box-shadow: 0 12px 32px rgba(0, 0, 0, .16); }
.suggest li { display: flex; align-items: baseline; gap: 10px; padding: 7px 12px;
  cursor: pointer; font-size: .9rem; }
.suggest li.on, .suggest li:hover { background: var(--green-50, #f0fdf4); }
.sg-label { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.sg-hint { flex-shrink: 0; font-size: .76rem; color: var(--muted, #6b7280); }

/* --- Sortable column headings ------------------------------------------- */
.th-sort { color: inherit; text-decoration: none; display: inline-block; white-space: nowrap; }
.th-sort:hover { color: var(--green-700, #15803d); text-decoration: none; }
.th-sort.on { color: var(--green-700, #15803d); }
th[aria-sort]:not([aria-sort="none"]) { background: var(--green-50, #f0fdf4); }

/* --- Touch --------------------------------------------------------------------
   Keyed on (pointer: coarse) — a finger rather than a mouse — so a desktop keeps
   its compact controls and a phone, tablet or touch laptop gets room. Two rules
   carry most of it.

   16px on anything you type into. Safari on iOS zooms the page in when a focused
   field's text is smaller than that, and it does not zoom back out: one tap on a
   search box and the rest of the visit is a pinch-to-read exercise. The base font
   is 15px, so every input on the site qualified. (.combo-search already set this
   for the same reason — this generalises it.)

   40px on anything you tap. The published guidance is 44; 40 is what these
   controls reach without redrawing anything, and it is padding on the inside, so
   nothing shifts on a pointer device. */
@media (pointer: coarse) {
  input, select, textarea { font-size: 16px; }
  .global-search input { font-size: 16px; }
  input:not([type="checkbox"]):not([type="radio"]), select, textarea { min-height: 40px; }
  input[type="checkbox"], input[type="radio"] { width: 20px; height: 20px; }

  .btn, button.btn { min-height: 40px; }
  .btn-sm { min-height: 40px; padding: 7px 13px; font-size: .82rem; }
  .icon-btn { min-width: 40px; min-height: 40px; justify-content: center; }
  .icon-btn, .user-btn { display: inline-flex; align-items: center; }
  .user-btn { min-height: 40px; }
  .menu-btn { font-size: 1.35rem; }
  .combo-btn { min-height: 44px; }
  .combo-opt { padding: 12px 10px; }
  .pager a, .pager span { min-width: 40px; min-height: 40px; display: inline-flex; align-items: center; justify-content: center; }
  .tabs a { padding: 12px 14px; }
  .nav-link { padding: 12px 18px; }
  .dropdown a, .dropdown button { padding: 13px 14px; }
  .suggest li { padding: 11px 12px; }
}

/* Narrow phones: give the content back the width the chrome was taking, and let
   filter controls have a line each instead of three stubs on one. */
@media (max-width: 560px) {
  .card { padding: 14px; }
  .content { padding: 16px 12px 60px; }
  /* Text fields and selects go full width on a phone; a TICK BOX must not —
     stretched to 100% it pushes its own label off the row and the page scrolls
     sideways. Same exclusion the min-height rule above already makes. */
  .filter-bar input:not([type="checkbox"]):not([type="radio"]),
  .filter-bar select, .filter-bar .combo { flex: 1 1 100%; width: 100%; min-width: 0; }
  .filter-bar .check-row { flex: 0 1 auto; }
  .kpis { grid-template-columns: repeat(auto-fit, minmax(132px, 1fr)); gap: 10px; }
}

/* A toast pinned top-right lands squarely on the bell and the account menu at
   phone width — after every save, the header is unusable until it times out.
   Bottom of the screen instead: out of the way, and inside thumb reach. */
@media (max-width: 560px) {
  .toasts { top: auto; bottom: 12px; left: 12px; right: 12px; max-width: none; }
  /* A modal that starts 6vh down wastes the only screen a phone has. */
  .modal-backdrop { padding: 12px; }
  .modal { padding: 16px; }
}

/* Row-select boxes are the one control a finger has to hit exactly, and the
   browser default is about 13px square. */
@media (pointer: coarse) {
  table.data td input[type="checkbox"], table.data th input[type="checkbox"] { width: 24px; height: 24px; }
}

/* --- Auth screens on a phone ---------------------------------------------------
   The picker's buttons carry business names — arbitrary text, unlike the fixed
   short labels .btn is built for, so the nowrap that stops "Edit" breaking
   mid-word pushed the whole page sideways here. Every button on an auth card is
   a one-per-line choice, so full width, centred, and free to wrap. */
.auth-card .btn { width: 100%; justify-content: center; white-space: normal; text-align: center; }
/* A consent checkbox is a flex item next to a two-line label; without this it
   gets squeezed to 13px while the label takes the room. */
.check-row input[type="checkbox"], .check-row input[type="radio"] { flex-shrink: 0; }

@media (max-width: 400px) {
  .auth-wrap { padding: 14px; }
  .auth-card { padding: 22px 18px; }
}
/* Turnstile renders a fixed 300x65 iframe. Below about 360px the card cannot
   hold that however little padding it has, and the page scrolled sideways on
   sign-in, sign-up and password reset alike. Scaling keeps the checkbox both
   legible and tappable; transform does not disturb anything around it. */
@media (max-width: 360px) {
  .cf-turnstile { transform: scale(.84); transform-origin: left center; }
}

/* --- Two-factor setup ------------------------------------------------------------
   Its own shapes because this screen is a one-off: numbered steps, a code field
   you can read at arm's length, and buttons that fill the line on any device —
   most people meet it once, on a phone, having just been told they must. */
.auth-card-wide { max-width: 460px; }
.auth-lede { color: var(--ink-soft); font-size: .92rem; margin: 2px 0 14px; }
.btn-block { width: 100%; justify-content: center; }

.setup-steps { list-style: none; counter-reset: step; margin: 4px 0 18px; padding: 0; }
.setup-steps > li { counter-increment: step; position: relative; padding: 0 0 20px 34px; }
.setup-steps > li::before {
  content: counter(step); position: absolute; left: 0; top: 0;
  width: 24px; height: 24px; border-radius: 50%;
  background: var(--green-700); color: #fff;
  font-size: .78rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.setup-steps > li > strong { display: block; margin-bottom: 2px; }
.setup-steps .btn { margin-top: 8px; }
.setup-steps .hint { margin-top: 4px; }

.qr-box-center { display: flex; justify-content: center; margin: 10px 0; }
.qr-box-center svg { width: 176px; height: 176px; }

.copy-row { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.copy-key {
  flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: .08em; font-size: .84rem; padding: 8px 10px;
}

/* Six digits, spaced out — this is the field people squint at. */
.code-input {
  font-size: 1.5rem; letter-spacing: .35em; text-align: center;
  font-variant-numeric: tabular-nums; padding: 10px;
}
.code-input::placeholder { letter-spacing: .35em; opacity: .35; }

.code-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(112px, 1fr));
  gap: 8px; margin: 12px 0 4px;
}
.code-grid code {
  text-align: center; padding: 9px 6px; font-size: .92rem;
  letter-spacing: .06em; background: var(--bg); border: 1px solid var(--line);
}

/* --- File drop zones -----------------------------------------------------------
   Wraps every <input type="file"> (see app.js). The real input stays inside and
   visible: a zone that hides it would take the keyboard and screen-reader path
   away with it, and "drag files here" is worthless on a phone. */
.dropzone {
  border: 1px dashed #cbd5cf; border-radius: var(--radius);
  padding: 12px; background: #fbfcfb; transition: border-color .12s, background .12s;
}
.dropzone-cap { font-size: .8rem; color: var(--muted); margin-bottom: 8px; }
.dropzone input[type="file"] { width: 100%; background: transparent; border: none; padding: 0; }
.dropzone.is-over { border-color: var(--green-600); border-style: solid; background: #f0faf2; }
/* The drag is over the zone, so nothing inside it may become the drop target
   and swallow the event — dragleave would fire as the pointer crosses a child. */
.dropzone.is-over * { pointer-events: none; }

/* Capped and scrollable: a thirty-file drop must not push the Upload button
   below the fold — the whole point of the bulk path is one click at the end. */
.dropzone-list:not(:empty) {
  margin-top: 10px; border-top: 1px solid var(--line); padding-top: 8px;
  max-height: 200px; overflow-y: auto;
}
.dropzone-file {
  display: flex; gap: 10px; align-items: baseline; justify-content: space-between;
  font-size: .84rem; padding: 2px 0;
}
.dropzone-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dropzone-file .hint { margin: 0; white-space: nowrap; }
.dropzone-note { margin-top: 6px; font-weight: 600; }

/* --- Upload progress -----------------------------------------------------------
   Shown under the form actions while a multipart POST is in flight (app.js). */
.upload-progress { margin-top: 12px; }
.upload-progress-foot {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-top: 5px;
}
.upload-progress-text { font-size: .82rem; color: var(--muted); }
.upload-progress-foot .btn { flex: 0 0 auto; }
.upload-progress .progress > div { transition: width .15s linear; }
/* No measurable progress to show — a bar that sweeps says "working" without
   claiming a percentage it does not have. */
.upload-progress.is-indeterminate .progress > div {
  width: 40% !important;
  animation: upload-sweep 1.1s ease-in-out infinite;
}
@keyframes upload-sweep {
  0%   { margin-left: -40%; }
  100% { margin-left: 100%; }
}
.upload-progress.is-error .progress { background: var(--red-bg); }
.upload-progress.is-error .upload-progress-text { color: var(--red); font-weight: 600; }

@media (prefers-reduced-motion: reduce) {
  .upload-progress .progress > div { transition: none; }
  .upload-progress.is-indeterminate .progress > div { animation: none; margin-left: 0; width: 100% !important; }
}
