/* ============================================================================
   Monarch Dashboard — design tokens
   Grounded in the DSD/warehouse world: manifest-style numbering, signage
   amber, industrial condensed headers. Built for daily ops use by people
   who are not software-first — clarity and speed over decoration.
   ============================================================================ */

@import url('https://fonts.googleapis.com/css2?family=Barlow+Condensed:wght@600;700&family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  --bg: #161B22;
  --surface: #1F2630;
  --surface-raised: #262F3B;
  --border: #2B3440;
  --text: #EDEAE3;
  --text-muted: #8B94A3;
  --accent: #E8873B;
  --accent-dim: #B96A2C;
  --success: #5B9279;
  --danger: #C1553D;
  --info: #5C86A8;

  --font-display: 'Barlow Condensed', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --radius: 6px;
  --header-h: 73px; /* portal header: 16px + content + 16px + 1px border */
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  margin: 0;
}

.mono { font-family: var(--font-mono); }

a { color: var(--accent); text-decoration: none; }

button {
  font-family: var(--font-body);
  font-weight: 600;
  cursor: pointer;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--text);
  padding: 8px 16px;
  font-size: 13px;
  transition: border-color 0.15s ease, background 0.15s ease;
}
button:hover { border-color: var(--accent); }
button:focus-visible, a:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #1A1006;
}
button.primary:hover { background: var(--accent-dim); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

input, select, textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 9px 12px;
  font-family: var(--font-body);
  font-size: 14px;
  width: 100%;
}

/* ---- App shell ---- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 0;
  display: flex;
  flex-direction: column;
}
.sidebar-brand {
  padding: 0 20px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}
.sidebar-brand .mark {
  font-family: var(--font-display);
  font-size: 22px;
  color: var(--accent);
}
.sidebar-brand .sub {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: 2px;
}
.nav-item {
  display: block;
  padding: 11px 20px;
  color: var(--text-muted);
  font-weight: 500;
  border-left: 3px solid transparent;
  cursor: pointer;
}
.nav-item:hover { color: var(--text); }
.nav-item.active {
  color: var(--text);
  border-left-color: var(--accent);
  background: var(--surface-raised);
}
.sidebar-footer {
  margin-top: auto;
  padding: 12px 20px 0;
  border-top: 1px solid var(--border);
}
.sidebar-footer button { margin-top: 10px; width: 100%; font-size: 12px; }
.sidebar-footer .user-name { font-weight: 600; font-size: 13px; }
.sidebar-footer .user-role {
  font-size: 11px; color: var(--text-muted); text-transform: uppercase;
}

.main {
  flex: 1;
  padding: 28px 36px;
  max-width: 1100px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 22px;
}
.page-header h1 { font-size: 28px; }
.page-header .desc { color: var(--text-muted); font-size: 13px; margin-top: 4px; }

/* ---- Tabs (pipeline stages) ---- */
.tab-row { display: flex; gap: 4px; margin-bottom: 20px; border-bottom: 1px solid var(--border); }
.tab {
  padding: 9px 16px;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.tab .count {
  font-family: var(--font-mono);
  color: var(--text-muted);
  margin-left: 6px;
  font-size: 11px;
}

/* ---- Cards / list rows ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 12px;
}

.store-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color 0.15s ease;
}
.store-row:hover { border-color: var(--accent); }
.store-row .name { font-weight: 600; }
.store-row .meta { color: var(--text-muted); font-size: 12px; margin-top: 2px; }
.store-row .phone { font-family: var(--font-mono); color: var(--text-muted); font-size: 13px; }

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.badge.follow_up, .badge.new { background: rgba(92,134,168,0.18); color: var(--info); }
.badge.awaiting_response { background: rgba(232,135,59,0.18); color: var(--accent); }
.badge.wants_product { background: rgba(91,146,121,0.18); color: var(--success); }
.badge.sale_completed { background: rgba(91,146,121,0.3); color: var(--success); }
.badge.not_interested { background: rgba(193,85,61,0.18); color: var(--danger); }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state h3 { color: var(--text); margin-bottom: 8px; font-size: 18px; }

/* ---- Store detail panel ---- */
.detail-panel {
  position: fixed;
  top: 0; right: 0;
  width: 460px;
  height: 100vh;
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 24px;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform 0.2s ease;
  z-index: 50;
}
.detail-panel.open { transform: translateX(0); }
/* Sticky so the back button stays reachable while scrolling a long detail —
   otherwise it scrolls out of view and the panel feels like a dead end. */
.detail-panel .close-btn {
  position: sticky;
  top: 0;
  float: right;
  z-index: 2;
}

.comm-item {
  border-left: 2px solid var(--border);
  padding: 8px 0 8px 14px;
  margin-bottom: 10px;
}
.comm-item.outbound { border-left-color: var(--accent); }
.comm-item .comm-meta {
  font-size: 11px; color: var(--text-muted); text-transform: uppercase;
  display: flex; gap: 8px; margin-bottom: 4px;
}

/* ---- Route manifest (signature element) ---- */
.manifest {
  list-style: none;
  padding: 0;
  margin: 0;
}
.manifest-stop {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding: 14px 0;
  border-bottom: 1px dashed var(--border);
}
.manifest-stop:last-child { border-bottom: none; }
.stop-number {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 500;
  color: var(--accent);
  width: 32px;
  flex-shrink: 0;
}
.stop-number.completed { color: var(--text-muted); text-decoration: line-through; }
.stop-info .stop-name { font-weight: 600; }
.stop-info .stop-address { color: var(--text-muted); font-size: 12px; margin-top: 2px; }

.route-summary {
  display: flex; gap: 24px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 16px;
}
.route-summary strong { color: var(--text); }

/* ---- Global search palette (Cmd+K) ---- */
.kbd-hint {
  font-size: 10px; padding: 1px 5px; border: 1px solid var(--border); border-radius: 4px;
  color: var(--text-muted); margin-left: 4px; font-family: var(--font-mono);
}
.cmdk-overlay {
  position: fixed; inset: 0; z-index: 300; display: flex;
  align-items: flex-start; justify-content: center; padding: 12vh 16px 16px;
  background: rgba(0, 0, 0, 0.55); backdrop-filter: blur(2px);
}
.cmdk {
  width: 100%; max-width: 560px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px; overflow: hidden;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}
.cmdk input {
  width: 100%; border: none; border-bottom: 1px solid var(--border); border-radius: 0;
  background: transparent; padding: 16px 18px; font-size: 16px; outline: none; color: var(--text);
}
.cmdk-results { max-height: 46vh; overflow-y: auto; padding-bottom: 6px; }
.cmdk-group {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-muted); padding: 12px 18px 4px;
}
.cmdk-item { padding: 10px 18px; cursor: pointer; font-size: 14px; }
.cmdk-item:hover, .cmdk-item.sel { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.cmdk-item .hint { margin-left: 6px; }

/* ---- Route legs (assignment) ---- */
.leg-block { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 12px; overflow: hidden; }
.leg-block .manifest { margin: 0; padding: 0 12px; }
.leg-head {
  display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 12px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.leg-assign { display: flex; gap: 8px; align-items: center; }
.leg-assign select { min-width: 150px; }

/* ---- Login page ---- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-card {
  width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
}
.login-card .mark {
  font-family: var(--font-display);
  font-size: 28px;
  color: var(--accent);
  margin-bottom: 4px;
}
.login-card .sub { color: var(--text-muted); font-size: 13px; margin-bottom: 24px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.error-msg { color: var(--danger); font-size: 13px; margin-top: 12px; min-height: 18px; }

.stock-flag { color: var(--danger); font-size: 11px; font-weight: 700; text-transform: uppercase; }

/* ---- Action bar in page headers ---- */
.actions { display: flex; gap: 8px; }

/* ---- Modal ---- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 60px 20px;
  z-index: 100;
  overflow-y: auto;
}
.modal-overlay.open { display: flex; }
.modal {
  width: 480px;
  max-width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}
.modal .close-btn { float: right; }
.modal h2 { font-size: 20px; margin-bottom: 16px; }

/* ---- Forms ---- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.field textarea { min-height: 90px; resize: vertical; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; }
.hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ---- Banner (integration gating notices) ---- */
.banner {
  background: rgba(232,135,59,0.10);
  border: 1px solid var(--accent-dim);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 13px;
  margin-bottom: 16px;
  color: var(--text);
}
.banner.info { background: rgba(92,134,168,0.10); border-color: var(--info); }

/* ---- Integration status cards ---- */
.integration-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.integration-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
  display: flex; justify-content: space-between; align-items: center;
}
.integration-card.clickable { cursor: pointer; transition: border-color .12s, transform .12s; }
.integration-card.clickable:hover { border-color: var(--accent); transform: translateY(-1px); }
.integration-card .name { font-weight: 600; }
.integration-card .who { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.status-dot { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.status-dot::before { content: ''; width: 9px; height: 9px; border-radius: 50%; }
.status-dot.on { color: var(--success); }
.status-dot.on::before { background: var(--success); }
.status-dot.off { color: var(--text-muted); }
.status-dot.off::before { background: var(--text-muted); }

/* ---- Data table ---- */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted); padding: 10px 12px; border-bottom: 1px solid var(--border);
}
.data-table td { padding: 12px; border-bottom: 1px solid var(--border); font-size: 13px; }
.data-table tr:hover td { background: var(--surface); }

/* ---- Detail action buttons ---- */
.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0; }
.detail-actions button { flex: 1 1 auto; min-width: 120px; }

/* ---- Toast ---- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--surface-raised); border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  padding: 12px 18px; border-radius: var(--radius);
  font-size: 13px; z-index: 200; max-width: 90%;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--success); }

[data-admin].hidden-role { display: none; }
.pill { font-family: var(--font-mono); font-size: 12px; color: var(--text-muted); }
.pill.good { color: var(--success); font-weight: 700; }
.pill.warn { color: var(--danger); font-weight: 700; }

/* ---- Section headers with an action on the right ---- */
.section-head { font-size: 14px; margin: 20px 0 10px; }
.section-head-row { display: flex; align-items: baseline; justify-content: space-between; }
.link-btn {
  background: none; border: none; color: var(--accent);
  font-size: 12px; cursor: pointer; padding: 0;
}
.link-btn:hover { text-decoration: underline; }

/* ---- Call detail: key points, reason, transcript ---- */
.key-points { margin: 0 0 12px 18px; padding: 0; }
.key-points li { font-size: 13px; margin-bottom: 6px; }
.reason-box {
  background: var(--surface); border-left: 3px solid var(--accent);
  border-radius: 4px; padding: 10px 12px; margin: 12px 0; font-size: 13px;
}
.reason-label {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-muted); margin-bottom: 4px;
}
.reason-inline {
  font-size: 12px; color: var(--text-muted); font-style: italic; margin-top: 4px;
}
.transcript {
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px; font-size: 13px; line-height: 1.6;
  max-height: 320px; overflow-y: auto; white-space: pre-wrap;
}

/* ---- Invoice / order detail ---- */
.invoice-total {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 12px; margin-top: 8px;
  border-top: 2px solid var(--border); font-size: 15px;
}
.invoice-total strong { font-family: var(--font-mono); font-size: 18px; color: var(--accent); }

/* ---- Route detail: what was delivered at each stop ---- */
.delivered {
  margin-top: 8px; padding: 8px 10px;
  background: var(--bg); border-radius: 4px; border: 1px solid var(--border);
}
.line-item {
  display: flex; justify-content: space-between;
  font-size: 12px; padding: 3px 0; color: var(--text-muted);
}

/* ---- Print: only the invoice ---- */
@media print {
  body * { visibility: hidden; }
  #invoice-area, #invoice-area * { visibility: visible; }
  #invoice-area { position: absolute; left: 0; top: 0; width: 100%; color: #000; background: #fff; }
  #invoice-area .data-table th, #invoice-area .data-table td { color: #000; border-color: #ccc; }
}

/* ==========================================================================
   STORE PORTAL — what a store owner sees. Lighter, simpler, touch-friendly:
   they're often on a phone behind a counter, not at a desk.
   ========================================================================== */
/*
 * Portal layout: a two-column grid, header spanning both.
 *
 * The cart used to be position:fixed at top:0, which put it underneath the
 * sticky header — you could see its heading slide under the header while
 * scrolling. Making it a real grid child that sticks below the header removes
 * the overlap entirely, with no z-index fight and no magic padding.
 */
.portal-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  grid-template-areas:
    "header header"
    "main   cart";
  grid-template-rows: auto 1fr;
  min-height: 100vh;
}
.portal-header {
  grid-area: header;
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 24px; border-bottom: 1px solid var(--border); background: var(--surface);
  position: sticky; top: 0; z-index: 20; flex-wrap: wrap; gap: 12px;
}
.portal-store { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.portal-nav { display: flex; gap: 8px; align-items: center; }
.portal-tab {
  background: none; border: 1px solid transparent; color: var(--text-muted);
  padding: 8px 14px; border-radius: var(--radius); font-size: 13px; cursor: pointer;
}
.portal-tab.active { color: var(--text); border-color: var(--border); background: var(--surface-raised); }
.portal-main { grid-area: main; padding: 24px; min-width: 0; }
.pview { max-width: 900px; }

/* Cart docked on the right */
.cart {
  grid-area: cart;
  position: sticky;
  top: var(--header-h);
  align-self: start;
  max-height: calc(100vh - var(--header-h));
  background: var(--surface); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 20px; overflow-y: auto;
}
.cart-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.cart-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--border); }
.cart-line {
  display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.cart-line-name { font-size: 13px; font-weight: 500; }
.cart-line-total { font-size: 13px; min-width: 60px; text-align: right; }
.cart-total {
  display: flex; justify-content: space-between; align-items: center;
  margin: 12px 0; font-size: 15px;
}
.cart-total strong { font-family: var(--font-mono); font-size: 20px; color: var(--accent); }
.qty-control { display: flex; align-items: center; gap: 4px; }
.qty-control button {
  width: 28px; height: 28px; padding: 0; font-size: 16px; line-height: 1;
}
.qty-control input {
  width: 48px; text-align: center; padding: 4px; font-family: var(--font-mono);
}

/* Catalog */
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; margin-bottom: 20px; }
.product-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; gap: 4px;
}
.product-card:hover { border-color: var(--accent-dim); }
.product-name { font-weight: 600; font-size: 14px; }
.product-desc { font-size: 12px; color: var(--text-muted); margin: 6px 0; line-height: 1.5; }
.product-foot { display: flex; justify-content: space-between; align-items: center; margin-top: auto; padding-top: 10px; }

/* "Your usual order" */
.usual-box {
  background: rgba(232,135,59,0.08); border: 1px solid var(--accent-dim);
  border-radius: var(--radius); padding: 16px; margin-bottom: 22px;
}
.usual-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.usual-items { display: flex; flex-wrap: wrap; gap: 8px; }
.usual-chip {
  background: var(--surface); border: 1px solid var(--border); border-radius: 20px;
  padding: 6px 12px; font-size: 12px; cursor: pointer;
}
.usual-chip:hover { border-color: var(--accent); }

/* Portal on a phone: cart drops below the catalog */
/* (portal stacking now lives in the RESPONSIVE section below) */

/* ---- Overview stat cards ---- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
.stat-card.good { border-color: var(--success); }
.stat-card.warn { border-color: var(--accent); }
.stat-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted); margin-bottom: 6px;
}
.stat-value { font-family: var(--font-mono); font-size: 26px; font-weight: 600; }
.stat-sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.stat-sub .up { color: var(--success); }
.stat-sub .down { color: var(--danger); }

/* ---- SMS consent ---- */
.consent-status {
  font-size: 12px; padding: 10px 12px; border-radius: var(--radius);
  margin-bottom: 12px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}
.consent-status.ok { background: rgba(74,157,110,0.12); border: 1px solid var(--success); }
.consent-status.missing { background: rgba(200,80,60,0.10); border: 1px solid var(--danger); }
.consent-quote {
  background: var(--bg); border-left: 3px solid var(--accent);
  padding: 12px 14px; border-radius: 4px; font-size: 13px; line-height: 1.6; font-style: italic;
}
.consent-row {
  display: flex; gap: 10px; align-items: flex-start;
  font-size: 12px; color: var(--text-muted); line-height: 1.5;
}
.consent-row input { width: auto; margin-top: 2px; flex-shrink: 0; }

/* ==========================================================================
   CRAFT PASS
   Interaction, focus, motion, and the states that only show up in real use:
   loading, empty, hover, keyboard. Identity is unchanged — charcoal and
   monarch orange — this is execution, not redesign.
   ========================================================================== */

/* ---- Motion: opt out entirely if the OS asks. Non-negotiable. ---- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---- Keyboard focus. Visible, never removed. ---- */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}
:focus:not(:focus-visible) { outline: none; }

::selection { background: var(--accent-dim); color: var(--text); }

/* ---- Scrollbars: quiet, not invisible ---- */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border); border-radius: 6px;
  border: 2px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover { background: var(--surface-raised); }

/* ---- Buttons: press feedback, honest disabled state ---- */
button {
  transition: background 0.15s ease, border-color 0.15s ease,
              color 0.15s ease, transform 0.08s ease;
}
button:not(:disabled):active { transform: translateY(1px); }
button.primary:not(:disabled):hover { background: var(--accent-dim); }

/* ---- Inputs ---- */
input, select, textarea {
  transition: border-color 0.15s ease, background 0.15s ease;
}
input:hover:not(:disabled), select:hover:not(:disabled), textarea:hover:not(:disabled) {
  border-color: var(--surface-raised);
}
/* Quantity fields: the spinner arrows are useless next to +/- buttons */
.qty-control input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
.qty-control input[type="number"]::-webkit-outer-spin-button,
.qty-control input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* ---- Rows and cards: a hairline of accent on hover, not a lift ---- */
.store-row, .comm-item[data-comm], .comm-item[data-order] {
  transition: background 0.15s ease, border-color 0.15s ease;
}
.store-row:hover { background: var(--surface-raised); }
.comm-item[data-comm]:hover, .comm-item[data-order]:hover { border-color: var(--accent-dim); }

.product-card {
  transition: border-color 0.15s ease, background 0.15s ease;
}
.product-card:hover { background: var(--surface-raised); }

.stat-card { transition: border-color 0.15s ease; }
.stat-card:hover { border-color: var(--surface-raised); }

/* ---- Tables: header stays put on long lists, rows respond ---- */
.data-table { border-collapse: separate; border-spacing: 0; width: 100%; }
.data-table thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.data-table tbody tr { transition: background 0.12s ease; }
.data-table tbody tr:hover { background: var(--surface); }
.data-table tbody tr[data-order]:hover,
.data-table tbody tr[data-product]:hover,
.data-table tbody tr[data-route]:hover { background: var(--surface-raised); }

/* ---- Modal: never taller than the screen; close stays reachable ---- */
.modal {
  max-height: 85vh;
  overflow-y: auto;
  animation: modal-in 0.16s ease-out;
}
@keyframes modal-in {
  from { opacity: 0; transform: translateY(8px) scale(0.99); }
  to   { opacity: 1; transform: none; }
}
.modal .close-btn { position: sticky; top: 0; z-index: 2; }

/* ---- Toast: arrives from below, leaves quietly ---- */
.toast { animation: toast-in 0.18s ease-out; }
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* ---- Loading: a shape where the content will be, not a spinning void ---- */
.skeleton {
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-raised) 37%, var(--surface) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
  border-radius: 4px;
  height: 14px;
  margin-bottom: 10px;
}
.skeleton.row { height: 44px; margin-bottom: 8px; border-radius: var(--radius); }
.skeleton.wide { width: 100%; }
.skeleton.half { width: 50%; }
@keyframes shimmer {
  from { background-position: 100% 50%; }
  to   { background-position: 0 50%; }
}

/* ---- Empty states: an invitation, not an apology ---- */
.empty-state p { font-size: 13px; max-width: 42ch; margin: 0 auto; line-height: 1.6; }

/* ---- Cart: the total is the thing you look at ---- */
.cart-head { position: sticky; top: 0; background: var(--surface); padding-bottom: 10px; z-index: 1; }
.cart-foot { position: sticky; bottom: 0; background: var(--surface); }
.cart-line:last-child { border-bottom: none; }

/* ---- Detail panel: a shadow so it reads as *above*, not beside ---- */
.detail-panel { box-shadow: -24px 0 48px -24px rgba(0,0,0,0.6); }

/* ---- Nav ---- */
.nav-item, .portal-tab { transition: background 0.15s ease, color 0.15s ease; }
.nav-item:hover:not(.active), .portal-tab:hover:not(.active) { color: var(--text); }


/* ---- Filter inputs in page headers ---- */
.filter-input {
  width: 200px; padding: 8px 12px; font-size: 13px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text);
}
.filter-input:focus { border-color: var(--accent-dim); }
.filter-input::placeholder { color: var(--text-muted); }
.actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
@media (max-width: 720px) {
  .filter-input { width: 100%; }
}

/* ==========================================================================
   RESPONSIVE
   The admin dashboard was desktop-only: a 220px sidebar and a 460px detail
   panel don't fit a 375px phone. But a rep turning on texts for a store is
   standing in that store, holding a phone. The screen that matters most was
   the least usable one.

   Strategy: the sidebar becomes a scrollable tab bar, the detail panel goes
   full-bleed, tables scroll horizontally rather than crushing their columns,
   and every tap target grows on touch devices.
   ========================================================================== */

/* The detail panel parks off-screen at translateX(100%). On some mobile
   browsers that creates a phantom horizontal scrollbar. */
body { overflow-x: hidden; }

/* ---- Tablet and below: sidebar becomes a top tab bar ---- */
@media (max-width: 1024px) {
  .app-shell { flex-direction: column; }

  .sidebar {
    width: 100%;
    flex-direction: row;
    align-items: center;
    gap: 2px;
    padding: 0;
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    overflow-y: hidden;
    position: sticky;
    top: 0;
    z-index: 30;
    -webkit-overflow-scrolling: touch;
  }
  .sidebar::-webkit-scrollbar { height: 0; }

  .sidebar-brand {
    padding: 12px 16px;
    margin-bottom: 0;
    border-bottom: none;
    border-right: 1px solid var(--border);
    flex-shrink: 0;
  }
  .sidebar-brand .sub { display: none; }

  .nav-item {
    border-left: none;
    border-bottom: 3px solid transparent;
    white-space: nowrap;
    padding: 14px 16px;
    flex-shrink: 0;
  }
  .nav-item.active { border-left-color: transparent; border-bottom-color: var(--accent); }

  .sidebar-footer {
    margin-top: 0;
    margin-left: auto;
    padding: 8px 12px;
    border-top: none;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
  }
  .sidebar-footer .user-role { display: none; }
  .sidebar-footer button { width: auto; margin-top: 0; }

  .main { padding: 20px; max-width: none; }
  .detail-panel { width: min(460px, 100vw); }
}

/* Portal: the cart needs a real column. Below this it goes underneath. */
@media (max-width: 900px) {
  .portal-shell {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "header" "main" "cart";
    grid-template-rows: auto auto auto;
  }
  .cart { position: static; max-height: none; border-left: none; border-top: 1px solid var(--border); }
}

/* ---- Phone ---- */
@media (max-width: 640px) {
  .main { padding: 16px; }
  h1 { font-size: 22px; }

  .page-header { flex-direction: column; align-items: stretch; gap: 12px; }
  .actions { width: 100%; }
  .actions button { flex: 1; }
  .filter-input { width: 100%; }

  /* Full-bleed detail panel — 460px does not fit here */
  .detail-panel { width: 100%; padding: 16px; }
  .detail-actions { flex-wrap: wrap; }
  .detail-actions button { flex: 1 1 auto; }

  .modal-overlay { padding: 12px; }
  .modal { padding: 18px; max-height: 92vh; }
  .form-grid { grid-template-columns: 1fr; }
  .form-actions { flex-direction: column-reverse; }
  .form-actions button { width: 100%; }

  .stat-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat-value { font-size: 22px; }

  /* Tables scroll sideways rather than crushing every column to two words.
     Scoped to list containers so invoice tables inside modals still wrap. */
  [id$="-list"] { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  [id$="-list"] .data-table { min-width: 560px; }
  .modal .data-table { min-width: 0; }

  .route-summary, .invoice-total { flex-wrap: wrap; gap: 8px; }
  .product-grid { grid-template-columns: 1fr; }

  .portal-header { padding: 12px 16px; }
  .portal-main { padding: 16px; }
  .portal-nav { width: 100%; overflow-x: auto; }
  .portal-tab { flex-shrink: 0; }

  .login-card { padding: 24px; }
  .login-wrap { padding: 16px; }
}

/* Small phones */
@media (max-width: 380px) {
  .stat-grid { grid-template-columns: 1fr; }
}

/* Login and consent cards must never exceed the screen */
.login-card { max-width: 100%; }

/* ---- Notched phones (viewport-fit=cover): stay out of sensor/home areas ---- */
body { padding-bottom: env(safe-area-inset-bottom, 0px); }
@media (max-width: 1024px) {
  .sidebar { padding-top: env(safe-area-inset-top, 0px); }
}

/* ---- Touch devices: bigger targets, no accidental zoom ---- */
@media (pointer: coarse) {
  button, .nav-item, .portal-tab, .usual-chip { min-height: 44px; }
  .link-btn { min-height: 32px; }
  .qty-control button { width: 36px; height: 36px; }
  /* iOS zooms the page when a focused input is under 16px */
  input, select, textarea { font-size: 16px; }
  .filter-input { font-size: 16px; }
}

/* Body scroll lock while a full-screen overlay is open (see setScrollLock). */
body.scroll-locked { overflow: hidden; }

/* ---- Shared legal footer ---- */
.site-footer {
  display: flex; gap: 8px; justify-content: center; align-items: center;
  flex-wrap: wrap;
  padding: 16px; font-size: 12px; color: var(--text-muted);
}
.site-footer a { color: var(--text-muted); text-decoration: none; }
.site-footer a:hover { color: var(--accent); text-decoration: underline; }

/* Login and consent pages centre a card in the viewport; pin the footer to the
   bottom rather than pushing the page into a scroll. */
body.auth { position: relative; }
body.auth .login-wrap { padding-bottom: 56px; }
body.auth .site-footer { position: fixed; bottom: 0; left: 0; right: 0; }

/* In the dashboard sidebar the links stack tight under Sign out. */
.sidebar-footer .site-footer {
  padding: 10px 0 0; justify-content: flex-start; gap: 6px; font-size: 11px;
}
@media (max-width: 1024px) {
  /* Sidebar becomes a horizontal bar — the legal links would crowd it. */
  .sidebar-footer .site-footer { display: none; }
}

/* Order status badges (orders table + detail views) */
.badge.order-pending    { background: rgba(92,134,168,0.18);  color: var(--info); }
.badge.order-confirmed  { background: rgba(232,135,59,0.18);  color: var(--accent); }
.badge.order-fulfilled  { background: rgba(91,146,121,0.3);   color: var(--success); }
.badge.order-cancelled  { background: rgba(193,85,61,0.18);   color: var(--danger); }

/* ==========================================================================
   BRAND MARK — the monarch butterfly (injected by /js/brand.js)
   Motion philosophy: mostly still. A creature that flaps constantly reads
   as a cartoon; one that stirs occasionally reads as alive. Idle = one soft
   double wingbeat every ~7s. Hover = a brief lively flutter. Both gone
   entirely under prefers-reduced-motion.
   ========================================================================== */
.mark { display: flex; align-items: center; gap: 0.35em; color: var(--accent); font-family: var(--font-display); }
.mark-butterfly {
  width: 1.05em;
  height: 1.05em;
  flex-shrink: 0;
  overflow: visible;
  transform: rotate(-6deg); /* a hint of tilt so it doesn't sit like a pinned specimen */
}
.mark-butterfly .wing {
  transform-box: fill-box;
  animation: mon-idle-flap 7s ease-in-out infinite;
}
.mark-butterfly .wing-l { transform-origin: 100% 50%; }
.mark-butterfly .wing-r { transform-origin: 0% 50%; }
/* second wing pair beats a breath later — real wings aren't metronomes */
.mark-butterfly .wing-r { animation-delay: 0.06s; }

@keyframes mon-idle-flap {
  0%, 86%, 100% { transform: scaleX(1); }
  89%           { transform: scaleX(0.62); }
  92%           { transform: scaleX(1); }
  95%           { transform: scaleX(0.78); }
  97.5%         { transform: scaleX(1); }
}

.mark:hover .mark-butterfly .wing { animation: mon-flutter 0.5s ease-in-out infinite; }
@keyframes mon-flutter {
  0%, 100% { transform: scaleX(1); }
  50%      { transform: scaleX(0.6); }
}

@media (prefers-reduced-motion: reduce) {
  .mark-butterfly .wing { animation: none !important; }
}

/* ============================================================================
   Platform console (owner-only tab) — tier pills, usage meters, sliders
   ============================================================================ */
.tier-pill {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.5px; text-transform: uppercase;
  padding: 2px 10px; border-radius: 20px; border: 1px solid var(--border);
  color: var(--text-muted); background: rgba(139,148,163,0.08);
}
.tier-pill.starter { color: var(--info); border-color: rgba(92,134,168,0.45); background: rgba(92,134,168,0.10); }
.tier-pill.pro { color: var(--accent); border-color: rgba(232,135,59,0.5); background: rgba(232,135,59,0.10); }
.tier-pill.enterprise { color: #A98FD1; border-color: rgba(169,143,209,0.45); background: rgba(169,143,209,0.10); }
.tier-pill .custom-star { color: var(--accent); }

.status-pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; }
.status-pill::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: var(--success); box-shadow: 0 0 6px rgba(91,146,121,0.7); }
.status-pill.suspended::before { background: var(--danger); box-shadow: 0 0 6px rgba(193,85,61,0.7); }
.status-pill.cancelled::before { background: var(--text-muted); box-shadow: none; }

.usage-meter { min-width: 130px; }
.usage-meter .um-row { margin: 3px 0; }
.usage-meter .um-label { display: flex; justify-content: space-between; gap: 8px; font-size: 10.5px; color: var(--text-muted); line-height: 1.3; }
.usage-meter .um-label strong { color: var(--text); font-weight: 500; }
.usage-meter .um-track { height: 4px; border-radius: 2px; background: var(--surface-raised); overflow: hidden; margin-top: 1px; }
.usage-meter .um-fill { height: 100%; border-radius: 2px; background: var(--success); transition: width 0.3s ease; }
.usage-meter .um-fill.warn { background: var(--accent); }
.usage-meter .um-fill.over { background: var(--danger); }

/* Allowance sliders (platform modal) */
.pf-slider-row { margin-bottom: 16px; }
.pf-slider-row .pf-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 4px; }
.pf-slider-row .pf-qty { font-family: var(--font-mono); font-size: 15px; color: var(--accent); min-width: 70px; text-align: right; }
input[type="range"].pf-range {
  -webkit-appearance: none; appearance: none; width: 100%; height: 6px; border-radius: 3px;
  background: linear-gradient(to right, var(--accent) 0%, var(--accent) var(--fill, 0%), var(--surface-raised) var(--fill, 0%));
  outline: none; cursor: pointer;
}
input[type="range"].pf-range::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent); border: 3px solid var(--bg); box-shadow: 0 0 0 1px var(--accent), 0 2px 6px rgba(0,0,0,0.5);
  transition: transform 0.1s ease;
}
input[type="range"].pf-range::-webkit-slider-thumb:hover { transform: scale(1.15); }
input[type="range"].pf-range::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%; background: var(--accent);
  border: 3px solid var(--bg); box-shadow: 0 0 0 1px var(--accent);
}
.pf-price-banner {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  border: 1px solid rgba(232,135,59,0.35); background: rgba(232,135,59,0.07);
  border-radius: var(--radius); padding: 12px 14px; margin: 6px 0 2px;
}
.pf-price-banner .pf-total { font-family: var(--font-display); font-size: 26px; font-weight: 700; color: var(--accent); }
.pf-price-banner .pf-breakdown { font-size: 12px; color: var(--text-muted); }
.pf-margin-hint { font-size: 12px; color: var(--success); margin-top: 6px; }

/* Platform config: provider dots grid reuse; economics table margin col pop */
.econ-margin { color: var(--success); font-family: var(--font-mono); }

/* Manage-workspace modal action rows */
.btn-row {
  display: block; width: 100%; text-align: left;
  padding: 11px 14px; background: var(--surface-raised);
  border: 1px solid var(--border); border-radius: 8px;
  color: var(--text); font-size: 13.5px; font-family: inherit; cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease;
}
.btn-row:hover { border-color: var(--accent); background: var(--surface); }

/* ── Partner embed skin (Addy) ────────────────────────────────────────────
   Applied when the dashboard runs inside Addy's frame (html[data-embed]).
   The Suite presents as part of Addy — blue accent, ADDY brand block with a
   "powered by Monarch" credit — and hides chrome that belongs to a
   standalone session (sign-out lives in Addy, not the frame). */
html[data-embed="addy"] {
  --accent: #2563eb;
  --accent-dim: #1d4ed8;
}
html[data-embed="addy"] #logout-btn { display: none; }
html[data-embed="addy"] .sidebar-brand .mark-butterfly { display: none; }
html[data-embed="addy"] .sidebar-brand .sub {
  font-size: 10.5px; letter-spacing: 0.4px; text-transform: none;
}


/* ── Call recording player ──────────────────────────────────────────────── */
.call-player {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface-raised); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 14px; margin: 12px 0;
}
.call-player.unavailable { color: var(--text-muted); font-size: 13px; display: block; }
.cp-btn {
  width: 38px; height: 38px; min-width: 38px; border-radius: 50%;
  border: none; background: var(--accent); color: #fff; font-size: 14px;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  padding: 0; line-height: 1;
}
.cp-btn:hover { background: var(--accent-dim); border-color: transparent; }
.cp-time {
  font-family: var(--font-mono); font-size: 12px; color: var(--text-muted);
  min-width: 40px; text-align: center; font-variant-numeric: tabular-nums;
}
.cp-track {
  flex: 1; -webkit-appearance: none; appearance: none; height: 6px;
  border-radius: 3px; background: var(--border); cursor: pointer; margin: 0;
}
.cp-track::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--surface-raised); cursor: pointer;
}
.cp-track::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--surface-raised); cursor: pointer;
}
.cp-speed {
  font-family: var(--font-mono); font-size: 12px; padding: 4px 9px;
  background: transparent; border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text-muted); cursor: pointer;
}
.cp-speed:hover { border-color: var(--accent); color: var(--text); }
.cp-dl { color: var(--text-muted); font-size: 16px; text-decoration: none; padding: 2px 4px; }
.cp-dl:hover { color: var(--accent); }
