/* ─────────────────────────────────────────────────────────────────────────
   DESIGN SYSTEM LAYER — one look for every module.

   Loaded after the per-view stylesheets (and before dark.css), so these
   rules settle the shared pieces each view used to style on its own:
   page shell, page headers, toolbar controls, filter pills, empty states
   and icons. Per-view files keep their layout-specific rules (widths,
   grids, cards); anything here is meant to look identical in every tab.
   See BRAND_GUIDELINES.md §8 for the reference table.
   ───────────────────────────────────────────────────────────────────────── */

:root {
  /* Page shell: every module view shares one gutter and content width. */
  --page-max: 1400px;
  --page-pad-x: var(--space-8);
  --page-pad-top: var(--space-6);
  --page-pad-bottom: var(--space-12);

  /* Toolbar controls (buttons, search, selects) share one height. */
  --control-h: 34px;
  --control-h-sm: 28px;
  --pill-h: 32px;
  --control-radius: var(--radius-md);

  --icon-search: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'><circle cx='11' cy='11' r='7'/><path d='m20 20-3.5-3.5'/></svg>");
  --icon-chevron: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
}
@media (max-width: 768px) {
  :root {
    --page-pad-x: var(--space-4);
    --page-pad-top: var(--space-4);
    --page-pad-bottom: var(--space-10);
  }
}

/* ── Icons (uiIcon() in js/util.js; same stroke style as the header nav) ── */
.ui-icon {
  display: inline-block;
  width: 1em;
  height: 1em;
  flex-shrink: 0;
  vertical-align: -0.14em;
}
.btn .ui-icon, .btn-toolbar .ui-icon, .rec-btn .ui-icon { width: 14px; height: 14px; }
.btn-sm .ui-icon { width: 13px; height: 13px; }

/* ── Page shell ── */
.dashboard-view,
.quotes-view,
.pos-view,
.marketing-view,
.settings-view,
.mfrs-view,
.hy-view,
.crm-view {
  /* Every module spans the window (--page-max is kept only for prose blocks). */
  max-width: none;
  margin: 0 auto;
  padding: var(--page-pad-top) var(--page-pad-x) var(--page-pad-bottom);
}
/* Contacts / Companies keep extra bottom room for the floating selection bar.
   The CRM sub-nav sits in the same centered column as the views below it. */
.crm-table-view { padding-bottom: 90px; }
/* Contact / company record pages sit in the same column. */
.rec-view {
  max-width: none;
  margin: 0 auto;
  padding: var(--space-5) var(--page-pad-x) 90px;
}
.crm-subnav {
  max-width: none;
  margin: 0 auto;
  padding: var(--space-4) var(--page-pad-x) 0;
}
.crm-subnav + .crm-view, .crm-subnav ~ .crm-view { padding-top: var(--space-5); }
/* The distributor map/table inside Companies had its own 1600px cap. */
.dist-view { max-width: none; }

/* ── Page header: title + one-line description ── */
.view-head { margin: 0 0 var(--space-5); }
.view-title,
.dash-title {
  font-family: var(--font-display);
  font-size: var(--fs-page-title);
  font-weight: 700;
  line-height: var(--lh-tight);
  letter-spacing: var(--tracking-tight);
  color: var(--text-primary);
  margin: 0;
}
.view-sub,
.dash-subtitle,
.mfrs-subtitle {
  margin: 6px 0 0;
  max-width: 720px;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text-secondary);
}
.view-sub:empty { display: none; }
.iq-header.view-head { margin-bottom: var(--space-5); }
.iq-header .iq-explain-sub { margin-top: 2px; }

/* ── Toolbar rows ── */
.quotes-toolbar, .pos-toolbar, .crm-toolbar, .mfrs-toolbar { margin: 0 0 var(--space-5); }
.mkt-toolbar { padding: 0; margin: 0 0 var(--space-5); }
.crm-count { font-size: 12px; color: var(--text-tertiary); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ── Buttons ── */
.btn {
  min-height: var(--control-h);
  justify-content: center;
  border-radius: var(--control-radius);
  white-space: nowrap;
  line-height: 1.2;
}
.btn-sm { min-height: var(--control-h-sm); padding: 4px 12px; font-size: 12px; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none !important; }

.btn-secondary { box-shadow: var(--shadow-sm); }

/* Toolbar buttons (Price Book + CRM): default to the secondary look so a bare
   .btn-toolbar (e.g. Duplicates) matches Import; .btn-add-item is primary. */
.btn-toolbar,
.pos-icon-btn {
  min-height: var(--control-h);
  padding: 0 14px;
  border-radius: var(--control-radius);
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  color: var(--text-secondary);
  box-shadow: var(--shadow-sm);
}
.btn-toolbar:hover,
.pos-icon-btn:hover {
  color: var(--brand-primary);
  border-color: rgba(var(--brand-primary-rgb), 0.35);
}
.btn-toolbar.btn-add-item {
  background: linear-gradient(135deg, var(--brand-primary), var(--brand-secondary));
  border-color: transparent;
  color: #fff;
  box-shadow: 0 2px 8px rgba(var(--brand-primary-rgb), 0.25);
}
.btn-toolbar.btn-add-item:hover { color: #fff; border-color: transparent; }

/* Round icon buttons (refresh) line up with the controls beside them. */
.icon-btn, .dash-refresh, .pos-refresh-btn, .dist-icon-btn {
  width: var(--control-h);
  height: var(--control-h);
  box-shadow: var(--shadow-sm);
}

/* Empty-state call to action = a regular primary button. */
.crm-empty-cta { border-radius: var(--control-radius); min-height: var(--control-h); padding: 0 18px; }

/* ── Search fields: one icon, one height ── */
.search-box,
.search-field,
.quotes-search,
.pos-search,
.crm-search {
  height: var(--control-h);
  padding: 0 12px 0 34px;
  border: 1px solid var(--border-default);
  border-radius: var(--control-radius);
  background-color: var(--bg-surface);
  background-image: var(--icon-search);
  background-repeat: no-repeat;
  background-position: 11px 50%;
  background-size: 15px 15px;
  box-shadow: var(--shadow-sm);
  font-size: 13px;
}
.search-box:focus,
.search-field:focus,
.quotes-search:focus,
.pos-search:focus,
.crm-search:focus {
  outline: none;
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px rgba(var(--brand-primary-rgb), 0.18);
}
@media (min-width: 769px) {
  .quotes-search, .pos-search { width: 230px; }
  .crm-search { min-width: 0; width: 220px; }
  .crm-type-select { max-width: 200px; text-overflow: ellipsis; }
}
@media (max-width: 768px) {
  .quotes-toolbar-right, .pos-toolbar-right, .crm-toolbar-right { flex-wrap: wrap; }
  .quotes-search-wrap, .pos-search-wrap, .crm-search-wrap { flex: 1 1 180px; min-width: 0; }
  .quotes-search, .pos-search, .crm-search { width: 100%; min-width: 0; }
}

/* ── Selects: custom chevron, same height + radius as the search field ── */
.quotes-sort-select,
.pos-sort-select,
.page-size-select,
.crm-type-select {
  height: var(--control-h);
  padding: 0 32px 0 12px;
  border: 1px solid var(--border-default);
  border-radius: var(--control-radius);
  background-color: var(--bg-surface);
  background-image: var(--icon-chevron);
  background-repeat: no-repeat;
  background-position: right 11px center;
  background-size: 12px 12px;
  box-shadow: var(--shadow-sm);
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: border-color var(--dur-fast) ease, color var(--dur-fast) ease, box-shadow var(--dur-fast) ease;
}
.quotes-sort-select:hover,
.pos-sort-select:hover,
.page-size-select:hover,
.crm-type-select:hover {
  border-color: rgba(var(--brand-primary-rgb), 0.35);
  color: var(--text-primary);
}
.quotes-sort-select:focus,
.pos-sort-select:focus,
.page-size-select:focus,
.crm-type-select:focus {
  outline: none;
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px rgba(var(--brand-primary-rgb), 0.18);
}

/* ── Filter pills / view switchers (Quotes, Orders, Review, Marketing, Settings, Dashboard ranges) ── */
.pill, .crm-pill, .pos-pill, .quotes-pill, .dash-chip, .mkt-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: var(--pill-h);
  padding: 0 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: 999px;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--dur-fast) ease, border-color var(--dur-fast) ease, color var(--dur-fast) ease, box-shadow var(--dur-fast) ease;
}
.pill:hover, .crm-pill:hover, .pos-pill:hover, .quotes-pill:hover, .dash-chip:hover, .mkt-pill:hover {
  border-color: rgba(var(--brand-primary-rgb), 0.35);
  color: var(--text-primary);
}
.pill.active, .crm-pill.active, .pos-pill.active, .quotes-pill.active, .dash-chip.active, .mkt-pill.active {
  background: var(--brand-primary);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 2px 8px rgba(var(--brand-primary-rgb), 0.25);
}
.mkt-pill .ui-icon { width: 14px; height: 14px; opacity: 0.75; }
.mkt-pill.active .ui-icon { opacity: 1; }
.mkt-pill.mkt-pill-sm { min-height: 26px; padding: 0 11px; font-size: 12px; }

/* ── Empty states (Price Book, Quotes, Orders, CRM, Marketing, Dashboard, Lists) ── */
.empty-state, .quotes-empty, .crm-empty, .mkt-empty, .pos-empty {
  text-align: center;
  padding: 56px 20px;
}
.empty-state { display: flex; flex-direction: column; align-items: center; }
.empty-icon,
.quotes-empty-icon,
.crm-empty-icon,
.dash-empty-icon,
.mkt-empty-icon,
.pos-empty-icon,
.seg-prev-empty-icon,
.dist-map-gate-icon,
.account-disabled-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: rgba(var(--brand-primary-rgb), 0.10);
  color: var(--brand-primary);
  font-size: 22px;
  line-height: 1;
  opacity: 1;
  filter: none;
}
.empty-icon .ui-icon,
.quotes-empty-icon .ui-icon,
.crm-empty-icon .ui-icon,
.dash-empty-icon .ui-icon,
.mkt-empty-icon .ui-icon,
.pos-empty-icon .ui-icon,
.seg-prev-empty-icon .ui-icon,
.dist-map-gate-icon .ui-icon,
.account-disabled-icon .ui-icon { width: 24px; height: 24px; vertical-align: 0; }
.empty-title,
.quotes-empty-title,
.crm-empty-title,
.dash-empty-title,
.mkt-empty-title,
.pos-empty-title,
.seg-prev-empty-title {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  margin: 0 0 6px;
}
.empty-sub,
.quotes-empty-sub,
.crm-empty-sub,
.dash-empty-sub,
.mkt-empty-sub,
.pos-empty-sub,
.seg-prev-empty-sub {
  max-width: 440px;
  margin: 0 auto;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-secondary);
}
.mkt-empty .btn, .pos-empty .btn, .dash-empty .btn { margin-top: 18px; }

/* Review queue row avatars carry an icon instead of an emoji. */
.intake-icon { color: var(--brand-primary); }
.intake-icon .ui-icon { width: 18px; height: 18px; }

/* ── Small fixes surfaced by the audit ── */
.dash-kpi-sub a { color: var(--brand-primary); font-weight: 600; text-decoration: none; }
.dash-kpi-sub a:hover { text-decoration: underline; }
.qca-btn .ui-icon, .mkt-icon-btn .ui-icon, .seg-ib .ui-icon, .qli-delete-btn .ui-icon { width: 15px; height: 15px; }
.quote-card-meta .ui-icon { width: 12px; height: 12px; opacity: 0.7; margin-right: 2px; }
