/* Supply Plan Grid — layout, sticky header + projection cell + arrival marker styles */

/* Wrapper is the scroll container for both axes (horizontal for the wide
   week-column table, vertical for sticky thead). max-height is twice the
   original (~2× viewport) so the planner sees a generous slice without
   excessive inner scroll, and sticky headers latch to the wrapper's top
   edge as expected. Page-level scroll still happens once the wrapper is
   exhausted. */
.sp-grid-wrapper {
  overflow: auto;
  max-height: calc(200vh - 210px);
  border: 1px solid var(--border, #e8e6e1);
  border-radius: 8px;
  background: #fff;
}

.supply-plan-grid thead th.sp-sticky-header {
  position: sticky;
  top: 0;
  z-index: 3;
  background: #fff;
}

.supply-plan-grid thead th.sp-sticky-corner {
  position: sticky;
  top: 0;
  left: 0;
  z-index: 4;
  background: #fff;
}

.supply-plan-grid tbody td.sp-sticky-col {
  position: sticky;
  left: 0;
  background: #fff;
  z-index: 1;
}

/* Weekly cells use vertical flex so qty stays top-aligned
   regardless of whether arrivals or per-location grids exist below */
.supply-plan-grid tbody td.text-center {
  vertical-align: top;
  padding-top: 10px;
}

.sp-inv-cell {
  display: inline-block;
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 600;
  border-radius: 4px;
  padding: 3px 6px;
  min-width: 36px;
  text-align: center;
}

.sp-cell-healthy {
  background: #e8f5e9;
  color: #2e7d32;
}

.sp-cell-low {
  background: #fff3e0;
  color: #e65100;
}

.sp-cell-stockout {
  background: #ffebee;
  color: #c62828;
}

/* Restock = arrivals landed and DOH is healthy. Same as healthy (green).
   The arrival pill below the cell already indicates arrivals. */
.sp-cell-restock {
  background: #e8f5e9;
  color: #2e7d32;
}

/* Excess/overstocked — projected DOH exceeds company threshold */
.sp-cell-excess {
  background: var(--purple-tint, #f5f3ff);
  color: var(--purple, #7c3aed);
}

.sp-arrival-marker {
  display: inline-block;
  font-size: 9px;
  font-weight: 700;
  background: #e3f2fd;
  color: #1565c0;
  border-radius: 3px;
  padding: 1px 4px;
  margin-top: 2px;
}

.sp-arrival-week {
  border-left: 2px solid var(--amber, #d97706);
  border-right: 2px solid var(--amber, #d97706);
  background: #fffbeb;
}

.sp-order-today-marker {
  font-size: 8px;
  color: var(--amber, #d97706);
  line-height: 1;
  margin-bottom: 1px;
}

/* ============================================================
   Kit-Aware Supply Plan — grid card, toolbar, per-location,
   bottleneck badges, arrival pills, utilization bars
   ============================================================ */

/* Grid card wrapper */
.sp-grid-card {
  background: #fff;
  border: 1px solid var(--border, #e8e6e1);
  border-radius: 8px;
  overflow: hidden;
}

.sp-grid-card .sp-grid-wrapper {
  border: none;
  border-radius: 0;
}

/* Grid toolbar */
.sp-grid-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-light, #f0eeea);
  background: #fafaf8;
  font-size: 12px;
}

.sp-grid-toolbar-left,
.sp-grid-toolbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.sp-toolbar-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--muted, #8a8a8a);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Per-location toggle switch */
.sp-toggle-switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #333;
  cursor: pointer;
  user-select: none;
}

.sp-toggle-track {
  width: 28px;
  height: 16px;
  border-radius: 999px;
  background: #d4d2cd;
  position: relative;
  transition: background 0.15s;
  flex-shrink: 0;
}

.sp-toggle-track::after {
  content: "";
  width: 12px;
  height: 12px;
  background: #fff;
  border-radius: 50%;
  position: absolute;
  top: 2px;
  left: 2px;
  transition: left 0.15s;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.sp-toggle-on .sp-toggle-track {
  background: var(--kit, #0d9488);
}

.sp-toggle-on .sp-toggle-track::after {
  left: 14px;
}

/* Location chips */
.sp-loc-chips {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.sp-loc-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 26px;
  padding: 0 10px 0 7px;
  border: 1px solid var(--border, #e8e6e1);
  border-radius: 999px;
  background: #fff;
  color: #555;
  cursor: pointer;
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  transition: all 0.15s;
}

.sp-loc-chip:hover { border-color: var(--border-hover, #d5d2cc); color: #1a1a1a; }

.sp-chip-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: 'JetBrains Mono', monospace;
  font-size: 7px;
  font-weight: 700;
  background: #f0eeea;
  color: #666;
}

.sp-chip-on { border-color: #1a1a1a; color: #1a1a1a; }
.sp-chip-off { color: #b0aead; background: #fafaf8; }
.sp-chip-off .sp-chip-dot { opacity: 0.5; }
.sp-chip-disabled { pointer-events: none; opacity: 0.5; }

/* View toggle (Individual / Kit View) */
.sp-view-toggle {
  display: inline-flex;
  background: #f0eeea;
  padding: 3px;
  border-radius: 7px;
  gap: 2px;
}

.sp-view-btn {
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 5px;
  border: none;
  background: transparent;
  color: var(--muted, #8a8a8a);
  cursor: pointer;
  text-decoration: none;
}

.sp-view-btn.active {
  background: #fff;
  color: var(--ink, #1a1a1a);
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

/* Kit badge */
.sp-kit-badge {
  background: var(--kit-tint, #ccfbf1);
  color: var(--kit, #0d9488);
  padding: 1px 6px;
  border-radius: 10px;
  font-size: 9px;
  font-weight: 600;
  margin-left: 4px;
}

/* Bottleneck badge */
.sp-bottleneck-badge {
  font-size: 10px;
  font-weight: 500;
  color: var(--amber, #d97706);
  margin-top: 3px;
}


/* Kit-feeds indicator on component rows */
.sp-feeds-badge {
  background: var(--kit-tint, #ccfbf1);
  color: var(--kit, #0d9488);
  padding: 1px 6px;
  border-radius: 10px;
  font-size: 9px;
  font-weight: 600;
  margin-left: 4px;
  cursor: help;
}

.sp-feeds-bottleneck {
  border: 1px solid var(--amber, #d97706);
  background: #fef7e6;
}

/* Unlock marker */
.sp-unlock-marker {
  font-size: 8.5px;
  color: var(--kit, #0d9488);
  font-weight: 700;
  margin-top: 1px;
}

/* Kit cascade banner */
.sp-kit-banner {
  background: linear-gradient(135deg, var(--kit-tint, #ccfbf1) 0%, #fff 60%);
  border: 1px solid var(--kit, #0d9488);
  border-radius: 8px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  font-size: 12.5px;
  color: #134e4a;
}

.sp-kit-banner-icon {
  font-size: 16px;
  color: var(--kit, #0d9488);
  flex-shrink: 0;
}

/* Per-location mini-grid (stacked in cell) */
.sp-loc-grid {
  margin-top: 3px;
  display: grid;
  grid-template-columns: repeat(var(--sp-loc-count, 3), 1fr);
  gap: 0 6px;
  align-items: center;
  justify-items: center;
  font-family: 'JetBrains Mono', monospace;
  letter-spacing: -0.2px;
}

.sp-loc-lbl {
  font-size: 8px;
  font-weight: 600;
  color: var(--muted, #8a8a8a);
  text-transform: uppercase;
}

.sp-loc-val {
  font-size: 10px;
  font-weight: 600;
  color: #555;
  margin-top: 1px;
}

.sp-loc-zero { color: #c28a5e; opacity: 0.75; }

.sp-loc-grid-comp { font-size: 9px; }
.sp-loc-grid-comp .sp-loc-lbl { font-size: 7px; }
.sp-loc-grid-comp .sp-loc-val { font-size: 9px; }

/* Per-location visibility — driven by body data-* attributes */
body[data-show-loc="0"] .sp-loc-grid { display: none; }
body[data-show-loc="0"] .sp-loc-chips { opacity: 0.5; pointer-events: none; }

/* Per-location element visibility and grid column count are JS-driven
   (sp_loc_toggle_controller.js) via inline display:none and --sp-loc-count
   CSS variable. Works for any number of locations with any abbreviations. */

/* Arrival pill (clickable) */
.sp-arrival-pill {
  display: inline-flex;
  align-items: center;
  font-size: 9.5px;
  font-weight: 700;
  padding: 1px 6px;
  margin-top: 2px;
  border-radius: 999px;
  background: #eff6ff;
  color: var(--blue, #2563eb);
  border: 1px solid #dbeafe;
  cursor: pointer;
  font-family: 'JetBrains Mono', monospace;
  letter-spacing: 0.1px;
  line-height: 1.5;
}

.sp-arrival-pill:hover { background: #dbeafe; border-color: #bfdbfe; }
.sp-pill-open { background: var(--blue, #2563eb); color: #fff; border-color: var(--blue, #2563eb); }

.sp-arr-count {
  font-size: 7.5px;
  font-weight: 800;
  letter-spacing: 0.3px;
  padding: 0 3px;
  border-radius: 3px;
  background: rgba(37,99,235,0.14);
  color: var(--blue, #2563eb);
  line-height: 1.4;
  margin-left: 4px;
}

.sp-pill-open .sp-arr-count { background: rgba(255,255,255,0.22); color: #fff; }

/* Arrival popover */
.sp-arr-popover {
  position: absolute;
  z-index: 50;
  background: #fff;
  border: 1px solid var(--border, #e8e6e1);
  border-radius: 8px;
  padding: 10px 12px;
  box-shadow: 0 8px 24px -6px rgba(15,23,42,0.18), 0 2px 4px rgba(15,23,42,0.06);
  min-width: 220px;
  max-width: 280px;
  font-size: 12px;
}

.sp-pop-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding-bottom: 8px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border-light, #f0eeea);
}

.sp-pop-type {
  font-family: 'JetBrains Mono', monospace;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.5px;
  padding: 2px 6px;
  border-radius: 4px;
  background: #eff6ff;
  color: var(--blue, #2563eb);
}

.sp-pop-type-transfer { background: rgba(124,58,237,0.1); color: #7c3aed; }
.sp-pop-type-external { background: rgba(5,150,105,0.1); color: var(--green, #059669); }

.sp-pop-dest {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 800;
  color: var(--ink, #1a1a1a);
  letter-spacing: 0.3px;
}

.sp-pop-qty {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  font-weight: 800;
  color: var(--blue, #2563eb);
}

.sp-pop-ref {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--muted, #8a8a8a);
  margin-left: auto;
}

.sp-pop-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 11px;
  padding: 3px 0;
}

.sp-pop-k { color: var(--muted, #8a8a8a); }
.sp-pop-v { color: var(--ink, #1a1a1a); font-weight: 600; font-family: 'JetBrains Mono', monospace; }

.sp-pop-multi-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--ink, #1a1a1a);
}

.sp-pop-events { display: flex; flex-direction: column; gap: 2px; }

.sp-pop-event {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  align-items: center;
  gap: 6px;
  padding: 6px 4px;
  border-radius: 6px;
  font-size: 11px;
}

.sp-pop-event:hover { background: #f8fafc; }
.sp-pop-event + .sp-pop-event { border-top: 1px dashed var(--border-light, #f0eeea); border-radius: 0; }

.sp-pop-ev-ref {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--ink, #1a1a1a);
}

.sp-pop-ev-qty {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  font-weight: 800;
  color: var(--blue, #2563eb);
  text-align: right;
}

.sp-pop-foot {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border-light, #f0eeea);
  font-size: 10.5px;
  color: var(--muted, #8a8a8a);
}

/* Utilization bar */
.sp-util-wrap {
  margin-top: 4px;
}

.sp-util-bar {
  width: 120px;
  height: 6px;
  border-radius: 3px;
  background: #e5e5e5;
  overflow: hidden;
  display: flex;
}

.sp-util-kit {
  background: var(--kit, #0d9488);
  height: 100%;
}

.sp-util-label {
  font-size: 9px;
  font-weight: 500;
  color: var(--muted, #8a8a8a);
  margin-top: 2px;
  font-family: 'JetBrains Mono', monospace;
  letter-spacing: -0.1px;
}

/* ============================================================
   Past-due pill tiers (Task 2)
   Tier classification computed at render time by the view helper
   so the visual stays correct across projection runs. The threshold
   policy lives on Company (overdue_minor/major_threshold_days).
   Token map per design system: --amber for warning text/border,
   #fffbeb for the Low Stock tint background.
   ============================================================ */

.sp-arrival-pill.is-overdue-minor {
  border-left: 3px solid var(--amber, #d97706);
}

.sp-arrival-pill.is-overdue-major {
  background: #fffbeb;
  color: var(--amber, #d97706);
  border-color: var(--amber, #d97706);
}

.sp-arrival-pill.is-overdue-major:hover {
  background: #fef3c7;
}

/* Popover overdue badge — uses raw days regardless of tier
   (planner has explicitly drilled in; full info welcome). */
.sp-pop-overdue {
  display: inline-block;
  margin-left: 6px;
  padding: 0 5px;
  font-size: 9.5px;
  font-weight: 700;
  border-radius: 3px;
  background: #fffbeb;
  color: var(--amber, #d97706);
  letter-spacing: 0.2px;
}

/* ============================================================
   Exception Inbox triage strip (Task 3)
   Tab-style filters with semantic icons. State-only lenses; chip
   bg + bottom underline mark the active tab. Counts colored by
   tone, labels in --ink for readability. Tones map to design
   system status patterns:
     oos       → red    (Out of Stock pattern — already failed)
     gap       → amber  (Low Stock pattern — about to fail)
     overstock → purple (Overstocked pattern — DS exact match)
     past_due  → stone  (data-quality lens, not inventory state)
   ============================================================ */

.sp-exception-bar {
  display: flex;
  align-items: stretch;
  margin: 0 0 16px;
  background: var(--surface, #fff);
  border: 1px solid var(--border, #e8e6e1);
  border-radius: 10px;
  overflow: hidden;
  min-height: 56px;
}

.sp-exception-eyebrow {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 8px 18px;
  border-right: 1px solid var(--border-light, #f0eeea);
  flex-shrink: 0;
}

.sp-exception-eyebrow-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.8px;
  color: var(--ink, #1a1a1a);
  line-height: 1.4;
}

.sp-exception-eyebrow-sub {
  font-size: 11px;
  color: var(--muted, #8a8a8a);
  line-height: 1.4;
}

.sp-exception-chips {
  display: flex;
  flex-wrap: wrap;
  flex: 1;
  align-items: stretch;
}

/* Each chip is a tab — full-height vertical fill, click target = whole cell. */
.sp-exception-chip {
  display: flex;
  align-items: center;
  align-self: stretch;
  gap: 8px;
  padding: 0 18px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink, #1a1a1a);
  text-decoration: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

/* Vertical separators between chips. Adjacent-sibling combinator
   ("any chip preceded by a chip") is layout-resilient and avoids the
   :first-child specificity gotchas. */
.sp-exception-chip + .sp-exception-chip {
  border-left: 1px solid var(--border, #e8e6e1);
}

/* Anchor reset: chip is a link_to but must read as a button. Suppress
   underlines in every interactive state (browsers add underlines on
   :hover for <a> by default, and a global anchor stylesheet may also
   contribute) and propagate the no-underline to inner spans. */
.sp-exception-chip,
.sp-exception-chip:hover,
.sp-exception-chip:focus,
.sp-exception-chip:active,
.sp-exception-chip:visited,
.sp-exception-chip-label,
.sp-exception-chip-count {
  text-decoration: none;
}

.sp-exception-chip-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.sp-exception-chip-count {
  font-weight: 700;
  font-size: 16px;
  font-family: 'JetBrains Mono', monospace;
  letter-spacing: -0.3px;
  margin-left: 2px;
}

/* Tone-specific colors apply to the icon and the count.
   Label stays in --ink for max readability. */
.sp-exception-chip-oos       .sp-exception-chip-icon,
.sp-exception-chip-oos       .sp-exception-chip-count { color: var(--red, #dc2626); }
.sp-exception-chip-gap       .sp-exception-chip-icon,
.sp-exception-chip-gap       .sp-exception-chip-count { color: var(--amber, #d97706); }
.sp-exception-chip-overstock .sp-exception-chip-icon,
.sp-exception-chip-overstock .sp-exception-chip-count { color: var(--purple, #7c3aed); }
.sp-exception-chip-past_due  .sp-exception-chip-icon,
.sp-exception-chip-past_due  .sp-exception-chip-count { color: var(--stone, #57534e); }

/* Hover and active share the SAME tier-tinted background so the chip
   reads as a button you're pressing into (not a link). Active also
   carries a colored bottom rule to mark the current filter. */
.sp-exception-chip-oos:hover,
.sp-exception-chip-oos.is-active       { background: #fef2f2; }
.sp-exception-chip-gap:hover,
.sp-exception-chip-gap.is-active       { background: #fffbeb; }
.sp-exception-chip-overstock:hover,
.sp-exception-chip-overstock.is-active { background: #f5f3ff; }
.sp-exception-chip-past_due:hover,
.sp-exception-chip-past_due.is-active  { background: var(--surface-alt, #fafaf8); }

.sp-exception-chip-oos.is-active       { border-bottom-color: var(--red, #dc2626); }
.sp-exception-chip-gap.is-active       { border-bottom-color: var(--amber, #d97706); }
.sp-exception-chip-overstock.is-active { border-bottom-color: var(--purple, #7c3aed); }
.sp-exception-chip-past_due.is-active  { border-bottom-color: var(--stone, #57534e); }

.sp-exception-clear {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 0 18px;
  margin-left: auto;
  font-size: 13px;
  color: var(--muted, #8a8a8a);
  text-decoration: none;
  border-left: 1px solid var(--border-light, #f0eeea);
  flex-shrink: 0;
}

.sp-exception-clear:hover { color: var(--ink, #1a1a1a); }

/* ============================================================
   Drill-to-peg popover (Task 4)
   Reuses .sp-arr-popover positioning + shadow but uses a
   table-style layout for the math breakdown.
   ============================================================ */

.sp-peg-popover {
  position: absolute;
  z-index: 1000;
  background: var(--surface, #fff);
  border: 1px solid var(--border, #e8e6e1);
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0,0,0,0.10);
  padding: 10px 12px;
  min-width: 220px;
  max-width: 280px;
  font-size: 12px;
}

.sp-peg-popover .sp-peg-head {
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--muted, #8a8a8a);
  border-bottom: 1px solid var(--border-light, #f0eeea);
  padding-bottom: 6px;
  margin-bottom: 6px;
}

.sp-peg-popover .sp-peg-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 3px 0;
  font-family: 'JetBrains Mono', monospace;
}

.sp-peg-popover .sp-peg-row.sp-peg-total {
  font-weight: 700;
  border-top: 1px solid var(--border-light, #f0eeea);
  padding-top: 6px;
  margin-top: 4px;
}

.sp-peg-popover .sp-peg-k { color: var(--muted, #8a8a8a); }
.sp-peg-popover .sp-peg-v { color: var(--ink, #1a1a1a); }
.sp-peg-popover .sp-peg-v-pos { color: var(--green, #16a34a); }
.sp-peg-popover .sp-peg-v-neg { color: var(--red, #dc2626); }

.sp-peg-popover .sp-peg-foot {
  font-size: 10px;
  color: var(--muted, #8a8a8a);
  margin-top: 6px;
  font-family: 'JetBrains Mono', monospace;
}

/* ============================================================
   Excess-cell DOH severity label (Phase 2 of past-due tier work)
   Renders the projected DOH below the qty in excess cells so the
   planner can triage "barely excess" (1-2x threshold) vs "massively
   excess" (>2x threshold) without hovering for the tooltip.
   Tier policy lives on Company#excess_tier — single source of truth.
   ============================================================ */

.sp-cell-excess-doh {
  font-size: 9.5px;
  font-family: 'JetBrains Mono', monospace;
  line-height: 1.4;
  margin-top: 1px;
}

.sp-cell-excess-doh-minor {
  color: var(--muted, #8a8a8a);
}

.sp-cell-excess-doh-major {
  color: var(--purple, #7c3aed);
  font-weight: 700;
}


/* ============================================================
   Outage $ column — projected lost revenue across first outage
   window. Right-aligned monospaced number; muted dash for SKUs
   without a stockout_date. Used by Mishimoto-style triage where
   the planner sorts the GAP/OOS chip by economic urgency.
   ============================================================ */

.sp-outage-cell {
  text-align: right;
  white-space: nowrap;
}

.supply-plan-grid tbody td.sp-outage-cell {
  vertical-align: top;
  padding-top: 10px;
}

.sp-outage-value {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  font-weight: 600;
  color: var(--ink, #1a1a1a);
  letter-spacing: -0.2px;
}

.sp-outage-empty {
  color: var(--muted, #8a8a8a);
  font-size: 11px;
}
