/* ============================================================
   components-base.css — Round 2 (post-audit)

   The PRIMITIVES library. Defines the canonical visual vocabulary:
   pills, badges, buttons, modals, panels, page-headers, section-headers,
   tables, status indicators.

   Loaded AFTER tokens.css and base.css, BEFORE components.css and
   styles-additions-v*.css. Component CSS should use these primitives by
   COMPOSITION (e.g., <span class="pill pill-sm pill-stream-components">),
   not by re-declaring rules.

   Migration target: every duplicated pill/chip/badge/modal definition
   in components.css and styles-additions-v*.css collapses into composed
   uses of these primitives. See DESIGN_SYSTEM.md for the catalog of
   migrations.
   ============================================================ */

/* ============================================================
   PILL — replaces 18 distinct pill-class names

   Composition pattern:
     <span class="pill pill-md pill-stream-components">Components</span>
     <span class="pill pill-sm pill-status-overdue">overdue 4d</span>
     <span class="pill pill-md pill-tier-hot">HOT</span>
   ============================================================ */

.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-0_5) var(--space-2);
  border-radius: var(--radius-pill);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  font-weight: 500;
  letter-spacing: var(--tracking-mono);
  text-transform: uppercase;
  white-space: nowrap;
  background: rgba(28, 28, 26, 0.06);
  color: var(--text-secondary);
}

/* Size variants */
.pill-sm { padding: var(--space-0_5) var(--space-1_5); font-size: 10px; }
.pill-md { /* default */ }
.pill-lg { padding: var(--space-1) var(--space-3); font-size: var(--text-xs); }

/* Status variants — operational (what action is needed) */
.pill-status-overdue   { background: var(--status-overdue-pill-bg);   color: var(--status-overdue-pill-fg); }
.pill-status-stale     { background: var(--status-stale-pill-bg);     color: var(--status-stale-pill-fg); }
.pill-status-active    { background: var(--status-active-pill-bg);    color: var(--status-active-pill-fg); }
.pill-status-quote-out { background: var(--status-quote-out-pill-bg); color: var(--status-quote-out-pill-fg); }

/* Subtle status variants — same hue, lower contrast */
.pill-status-overdue-subtle { background: var(--status-overdue-bg); color: var(--status-overdue-fg); }
.pill-status-stale-subtle   { background: var(--status-stale-bg);   color: var(--status-stale-fg); }
.pill-status-active-subtle  { background: var(--status-active-bg);  color: var(--status-active-fg); }

/* Stream variants */
.pill-stream-components    { background: var(--stream-components-bg);    color: var(--stream-components-fg); }
.pill-stream-scaff-used    { background: var(--stream-scaff-used-bg);    color: var(--stream-scaff-used-fg); }
.pill-stream-formwork-used { background: var(--stream-formwork-used-bg); color: var(--stream-formwork-used-fg); }
.pill-stream-other         { background: var(--stream-other-bg);         color: var(--stream-other-fg); }

/* Tier variants — multi-dimensional encoding (see tokens.css TIER section) */
.pill-tier-cold {
  background: var(--tier-cold-bg);
  color: var(--tier-cold-fg);
  font-size: 10px;
  padding: var(--space-0_5) var(--space-1_5);
}
.pill-tier-cool {
  background: var(--tier-cool-bg);
  color: var(--tier-cool-fg);
  font-size: 10px;
  padding: var(--space-0_5) var(--space-1_5);
}
.pill-tier-warm {
  background: var(--tier-warm-bg);
  color: var(--tier-warm-fg);
  /* default size */
}
.pill-tier-hot {
  background: var(--tier-hot-bg);
  color: var(--tier-hot-fg);
  font-weight: 600;
  padding: var(--space-1) var(--space-2);
  animation: pulse-subtle 1.5s ease-in-out infinite;
}

/* Pill with leading dot indicator */
.pill::before {
  content: "";
  display: none;
}
.pill-with-dot::before {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: var(--radius-pill);
  background: currentColor;
  opacity: 0.7;
  margin-right: var(--space-0_5);
}

/* ============================================================
   BADGE — counts, smaller than pill, no caps

   Composition:
     <span class="badge">3</span>
     <span class="badge badge-warning">12 overdue</span>
   ============================================================ */

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 var(--space-1);
  border-radius: var(--radius-pill);
  background: var(--text-primary);
  color: var(--text-on-accent);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  font-weight: 600;
  line-height: 1;
}

.badge-subtle  { background: rgba(28, 28, 26, 0.08); color: var(--text-primary); }
.badge-warning { background: var(--color-peach-100); color: var(--color-peach-800); }
.badge-danger  { background: var(--color-rose-100);  color: var(--color-rose-800); }
.badge-info    { background: var(--color-sky-100);   color: var(--color-sky-800); }
.badge-success { background: var(--color-mint-100);  color: var(--color-mint-900); }

/* ============================================================
   BUTTONS — primary / secondary / tertiary / danger / ghost
   plus -sm / -md (default) / -lg sizes

   Note: base.css has the original .btn-primary/.btn-secondary/.btn-danger
   definitions. Round 2 retires those in favor of these — base.css's
   versions become aliases (kept for back-compat, deprecated for new use).

   Composition:
     <button class="btn btn-primary">Save</button>
     <button class="btn btn-secondary btn-sm">Cancel</button>
     <button class="btn btn-ghost">x</button>
   ============================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1_5);
  padding: var(--space-2) var(--space-3_5);
  border-radius: var(--radius-sm);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-primary);
  transition:
    background var(--motion-fast) var(--easing-out),
    color      var(--motion-fast) var(--easing-out),
    border-color var(--motion-fast) var(--easing-out),
    opacity    var(--motion-fast) var(--easing-out);
  white-space: nowrap;
}

.btn:focus-visible {
  outline: 2px solid var(--border-focus);
  outline-offset: 2px;
}

.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* Sizes */
.btn-sm { padding: var(--space-1) var(--space-2_5); font-size: var(--text-sm); }
.btn-md { /* default */ }
.btn-lg { padding: var(--space-3) var(--space-5); font-size: var(--text-md); }

/* Variants */
.btn-primary {
  background: var(--text-primary);
  color: var(--bg-page);
  border-color: var(--text-primary);
}
.btn-primary:hover { opacity: 0.85; }

.btn-secondary {
  background: transparent;
  color: var(--text-primary);
  border-color: var(--border-default);
}
.btn-secondary:hover { background: rgba(28, 28, 26, 0.04); }

.btn-tertiary {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.btn-tertiary:hover { color: var(--text-primary); }

.btn-danger {
  background: transparent;
  color: var(--color-rose-600);
  border-color: var(--color-rose-600);
}
.btn-danger:hover { background: var(--color-rose-50); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}
.btn-ghost:hover { background: rgba(28, 28, 26, 0.04); color: var(--text-primary); }

/* ============================================================
   MODAL — overlay + shell + header + body + actions

   Replaces ~6 modal-internal patterns scattered across components.css
   and styles-additions-v*.css. Each existing modal becomes:
     <div class="modal-overlay">
       <div class="modal-shell">
         <div class="modal-header">...</div>
         <div class="modal-body">...</div>
         <div class="modal-actions">...</div>
       </div>
     </div>
   ============================================================ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--motion-base) var(--easing-out);
  padding: var(--space-4);
}

.modal-overlay.is-open {
  opacity: 1;
  pointer-events: auto;
}

.modal-shell {
  background: var(--bg-elev-1);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  max-width: 600px;
  width: 100%;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(8px) scale(0.98);
  transition:
    transform var(--motion-base) var(--easing-out),
    opacity var(--motion-base) var(--easing-out);
  opacity: 0;
}

.modal-overlay.is-open .modal-shell {
  transform: translateY(0) scale(1);
  opacity: 1;
}

.modal-shell-lg { max-width: 820px; }

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-6) var(--space-3);
  border-bottom: 1px solid var(--border-subtle);
}

.modal-header-title {
  font-family: var(--font-serif);
  font-size: var(--text-xl);
  font-weight: 500;
  margin: 0;
  line-height: var(--leading-tight);
}

.modal-header-subtitle {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: var(--tracking-mono);
  margin-top: var(--space-1);
}

.modal-close {
  background: transparent;
  border: 0;
  font-size: var(--text-xl);
  line-height: 1;
  cursor: pointer;
  color: var(--text-secondary);
  padding: var(--space-1);
  border-radius: var(--radius-sm);
}
.modal-close:hover {
  color: var(--text-primary);
  background: rgba(28, 28, 26, 0.04);
}

.modal-body {
  flex: 1;
  min-height: 0;
  padding: var(--space-5) var(--space-6);
  overflow-y: auto;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-elev-2);
}

.modal-actions-spread {
  justify-content: space-between;
}

@media (max-width: 480px) {
  .modal-overlay { padding: 0; }
  .modal-shell {
    max-width: 100vw;
    max-height: 100vh;
    border-radius: 0;
    height: 100vh;
  }
}

/* ============================================================
   PANEL — right-drawer (account panel, contact detail panel)

   base.css defines .panel with the same semantics; this restates as
   .panel-shell for naming consistency with .modal-shell. base.css's
   .panel rules continue to work for now; migrate at MB1 build time.
   ============================================================ */

.panel-shell {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 100%;
  max-width: 520px;
  background: var(--bg-page);
  box-shadow: var(--shadow-lg);
  transform: translateX(100%);
  transition: transform var(--motion-slow) var(--easing-out);
  overflow-y: auto;
  z-index: 101;
  padding: var(--space-6) var(--space-7, 28px);
  display: flex;
  flex-direction: column;
}

.panel-shell.is-open { transform: translateX(0); }

@media (max-width: 540px) {
  .panel-shell { max-width: 100%; padding: var(--space-5); }
}

/* ============================================================
   PAGE HEADER — used by Email Outreach today, replicated for
   Companies / Contacts / Activities standalone pages in MB1
   ============================================================ */

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-5) 0;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: var(--space-6);
  flex-wrap: wrap;
}

.page-header-left {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
}

.page-header-back {
  /* uses .btn .btn-ghost .btn-sm */
}

.page-header-title {
  font-family: var(--font-serif);
  font-size: var(--text-2xl);
  font-weight: 500;
  margin: 0;
  line-height: var(--leading-tight);
}

.page-header-subtitle {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: var(--tracking-mono);
}

.page-header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

/* ============================================================
   SECTION HEADER — within panels, within pages
   Consolidates .panel-section-label, .h-section-label, and a few
   one-off section labels in components.css.
   ============================================================ */

.section-header {
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  color: var(--text-tertiary);
  margin: var(--space-6) 0 var(--space-2);
  padding-bottom: var(--space-1_5);
  border-bottom: 1px solid var(--border-subtle);
  font-weight: 500;
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
}

.section-header-count {
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  color: var(--text-tertiary);
  font-weight: 400;
  letter-spacing: var(--tracking-wide);
}

/* ============================================================
   TABLE — used by dashboard-summary-table and standalone pages
   ============================================================ */

.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-base);
}

.tbl-th {
  text-align: left;
  padding: var(--space-2) var(--space-3);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: var(--tracking-mono);
  color: var(--text-tertiary);
  border-bottom: 1px solid var(--border-default);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.tbl-th:hover { color: var(--text-primary); }

.tbl-th.is-sorted-asc::after  { content: "  ↑"; }
.tbl-th.is-sorted-desc::after { content: "  ↓"; }

.tbl-row {
  cursor: pointer;
  transition: background var(--motion-fast) var(--easing-out);
}
.tbl-row:hover { background: var(--bg-elev-2); }

.tbl-cell {
  padding: var(--space-3);
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}

/* Staleness encoding on rows — uses tokens from tokens.css */
.tbl-row.is-due-soon .tbl-cell {
  background: var(--staleness-due-soon-bg);
  border-left: var(--staleness-due-soon-border) solid var(--staleness-due-soon-accent);
}
.tbl-row.is-overdue .tbl-cell {
  background: var(--staleness-overdue-bg);
  border-left: var(--staleness-overdue-border) solid var(--staleness-overdue-accent);
}
.tbl-row.is-very-overdue .tbl-cell {
  background: var(--staleness-very-overdue-bg);
  border-left: var(--staleness-very-overdue-border) solid var(--staleness-very-overdue-accent);
}

/* Empty state */
.tbl-empty {
  padding: var(--space-8) var(--space-4);
  text-align: center;
  color: var(--text-secondary);
  font-style: italic;
}

/* ============================================================
   STATUS INDICATOR — primitive for the multi-dim encoding

   For dimensions where a pill is too heavy and a row tint is wrong:
   inline-text indicators with a leading dot.

     <span class="status-indicator status-indicator-positive">
       <span class="status-indicator-dot"></span>
       buying signal
     </span>
   ============================================================ */

.status-indicator {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-xs);
  font-family: var(--font-sans);
}

.status-indicator-dot {
  width: 6px;
  height: 6px;
  border-radius: var(--radius-pill);
  display: inline-block;
  flex-shrink: 0;
}

/* Sizes */
.status-indicator-dot-sm { width: 4px; height: 4px; }
.status-indicator-dot-md { /* default 6px */ }
.status-indicator-dot-lg { width: 8px; height: 8px; }

/* AI signal severity */
.status-indicator-positive .status-indicator-dot { background: var(--sentiment-positive); }
.status-indicator-neutral  .status-indicator-dot { background: var(--sentiment-neutral); }
.status-indicator-mixed    .status-indicator-dot { background: var(--sentiment-mixed); }
.status-indicator-negative .status-indicator-dot { background: var(--sentiment-negative); }

.status-indicator-positive { color: var(--color-mint-900); }
.status-indicator-mixed    { color: var(--color-peach-900); }
.status-indicator-negative { color: var(--color-rose-900); }

/* ============================================================
   STREAM CHIP — small inline marker showing which stream(s)
   an account belongs to. Composes pill + pill-stream-* + pill-with-dot.

   Convenience class for very common usage:
     <span class="stream-chip stream-chip-components">Components</span>
   ============================================================ */

.stream-chip {
  /* identical to .pill .pill-with-dot .pill-md but as single class */
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: var(--space-0_5) var(--space-2);
  border-radius: var(--radius-pill);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  font-weight: 500;
  letter-spacing: var(--tracking-mono);
  text-transform: uppercase;
  white-space: nowrap;
}

.stream-chip::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: var(--radius-pill);
  flex-shrink: 0;
}

.stream-chip-components    { background: var(--stream-components-bg);    color: var(--stream-components-fg); }
.stream-chip-components::before    { background: var(--stream-components-dot); }

.stream-chip-scaff-used    { background: var(--stream-scaff-used-bg);    color: var(--stream-scaff-used-fg); }
.stream-chip-scaff-used::before    { background: var(--stream-scaff-used-dot); }

.stream-chip-formwork-used { background: var(--stream-formwork-used-bg); color: var(--stream-formwork-used-fg); }
.stream-chip-formwork-used::before { background: var(--stream-formwork-used-dot); }

.stream-chip-other         { background: var(--stream-other-bg);         color: var(--stream-other-fg); }
.stream-chip-other::before         { background: var(--stream-other-dot); }
