/*
 * _v1_primitives.css \u2014 styles for the v1 dashboard primitives.
 *
 * Spec: docs/dashboard-rebuild-spec.md \u00a72.
 * One CSS file per primitive class taxonomy. All selectors are
 * .lp- prefixed to avoid collision with the legacy leafpulse.css
 * widgets that share the same template tree.
 *
 * Components covered here:
 *   .lp-drp                <DateRangePicker>
 *   .lp-kpi                <KpiCard> (v1)
 *   .lp-chart-modal        <ChartModal>
 *   .lp-trend              <TrendCell>
 *   .lp-stock-chip         <StockStatusChip>
 *   .lp-product-cell       <ProductCell>
 *   .lp-breadcrumb         <DrillBreadcrumb>
 *   .lp-rail               <RightRailPanel>
 */


/* ============================================================================
 * <DateRangePicker> \u2014 .lp-drp
 * ========================================================================== */

.lp-drp {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.lp-drp-input {
  padding: 6px 10px;
  background: var(--bg-surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  font-variant-numeric: tabular-nums;
}

.lp-drp-input:focus {
  outline: none;
  border-color: var(--accent-blue);
}

.lp-drp-sep {
  color: var(--text-muted);
  font-size: 13px;
}

.lp-drp-presets {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 4px;
}


/* ============================================================================
 * <KpiCard> v1 \u2014 .lp-kpi
 * ========================================================================== */

.lp-kpi {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.lp-kpi-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.lp-kpi-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.lp-kpi-sub {
  font-size: 11px;
  color: var(--text-muted);
}

.lp-kpi-delta {
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}
.lp-kpi-delta-up   { color: #6fd672; }
.lp-kpi-delta-down { color: #ff8080; }
.lp-kpi-delta-flat { color: var(--text-muted); }

.lp-kpi-sparkline {
  margin-top: 6px;
  width: 100%;
  height: 24px;
  display: block;
}

/* Color variants \u2014 mirror the existing legacy .kpi-* tokens but namespaced. */
.lp-kpi-value.lp-kpi-green  { color: var(--accent-green); }
.lp-kpi-value.lp-kpi-red    { color: var(--accent-red); }
.lp-kpi-value.lp-kpi-blue   { color: var(--accent-blue); }
.lp-kpi-value.lp-kpi-yellow { color: var(--accent-yellow); }


/* ============================================================================
 * <ChartModal> \u2014 .lp-chart-modal
 * ========================================================================== */

.lp-chart-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.lp-chart-modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: min(900px, 100%);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5);
}

.lp-chart-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.lp-chart-modal-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.lp-chart-modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
}
.lp-chart-modal-close:hover { color: var(--text-primary); }

.lp-chart-modal-body {
  padding: 18px;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.lp-chart-modal-grain-strip {
  display: inline-flex;
  gap: 4px;
  margin-bottom: 12px;
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.lp-chart-modal-canvas-wrap {
  flex: 1;
  min-height: 280px;
  position: relative;
}

.lp-chart-modal-status {
  text-align: center;
  padding: 24px;
  color: var(--text-muted);
  font-size: 13px;
}

.lp-chart-modal-status.error { color: #ff8080; }


/* ============================================================================
 * <TrendCell> \u2014 .lp-trend
 * ========================================================================== */

.lp-trend {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-variant-numeric: tabular-nums;
}

.lp-trend-spark {
  width: 60px;
  height: 18px;
  display: inline-block;
  vertical-align: middle;
}

.lp-trend-up   { color: #6fd672; }
.lp-trend-down { color: #ff8080; }
.lp-trend-flat { color: var(--text-muted); }


/* ============================================================================
 * <StockStatusChip> \u2014 .lp-stock-chip
 * ========================================================================== */

.lp-stock-chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.lp-stock-chip-healthy  { background: #1a2e1a; color: #6fd672; }
.lp-stock-chip-watch    { background: #2e2a1a; color: #e8c96d; }
.lp-stock-chip-critical { background: #2e1a1a; color: #ff8080; }
.lp-stock-chip-dead     { background: #21262d; color: var(--text-muted); }


/* ============================================================================
 * <ProductCell> - .lp-product-cell
 * ========================================================================== */

.lp-product-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: left;
}

.lp-product-cell-thumb {
  width: 28px;
  height: 28px;
  border-radius: 4px;
  object-fit: cover;
  background: var(--bg-surface2);
  flex-shrink: 0;
}

.lp-product-cell-text {
  min-width: 0;
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.lp-product-cell-name {
  color: var(--text-primary);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 280px;
}

.lp-product-cell-sub {
  color: var(--text-muted);
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 280px;
}


/* ============================================================================
 * <DrillBreadcrumb> - .lp-breadcrumb
 * ========================================================================== */

.lp-breadcrumb {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--text-muted);
}

.lp-breadcrumb-group {
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.05em;
  padding-right: 4px;
}

.lp-breadcrumb-sep {
  color: var(--text-muted);
  user-select: none;
}

.lp-breadcrumb-link {
  background: transparent;
  border: none;
  padding: 0;
  color: var(--accent-blue);
  font: inherit;
  cursor: pointer;
}
.lp-breadcrumb-link:hover { text-decoration: underline; }

.lp-breadcrumb-current {
  color: var(--text-primary);
  font-weight: 500;
}


/* ============================================================================
 * <RightRailPanel> - .lp-rail
 *
 * Three viewport variants (spec section 6):
 *   > 1280px : persistent rail docked right (in-flow, page reflows)
 *   768-1280 : slide-out from right with backdrop
 *   < 768    : full-screen overlay
 * ========================================================================== */

.lp-rail {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 8000;
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.4);
  /* Default to closed = removed from layout. Specific mode classes override. */
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 0;
  overflow: hidden;
  transform: translateX(100%);
  transition: transform 200ms ease, width 200ms ease;
}

.lp-rail.lp-rail-open {
  transform: translateX(0);
}

.lp-rail-persistent {
  /* Persistent: take ~32% of the viewport width, in-flow alongside content. */
  position: fixed;
  width: clamp(320px, 32vw, 480px);
  border-left: 1px solid var(--border);
  border-top: none;
  border-bottom: none;
  border-right: none;
  box-shadow: none;
}

.lp-rail-slideout {
  width: clamp(320px, 50vw, 520px);
}

.lp-rail-fullscreen {
  width: 100vw;
  z-index: 9000;
}

.lp-rail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.lp-rail-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lp-rail-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  padding: 4px 8px;
}
.lp-rail-close:hover { color: var(--text-primary); }

.lp-rail-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
}

.lp-rail-footer {
  border-top: 1px solid var(--border);
  padding: 12px 18px;
  display: none;  /* shown only when content is set */
}

.lp-rail-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 7900;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}
.lp-rail-backdrop-open {
  opacity: 1;
  pointer-events: auto;
}

/* When a persistent rail is open, page content shifts left to make room.
 * Pages opt-in by wrapping content in .lp-rail-aware-page. */
body.lp-rail-body-persistent .lp-rail-aware-page {
  margin-right: clamp(320px, 32vw, 480px);
  transition: margin-right 200ms ease;
}
