/**
 * Stock AI Lab v2.0 - CDSL Collateral Margin Haircut Matrix & Header Gauge
 * Namespace: src/ui/collateral_margin.css
 * Theme: Obsidian Dark (#090A0F) with SEBI 50:50 Clamp Tokens
 * Chief Quantitative Architect Directive: Google Gemini 4 Argon
 */

.collateral-matrix-card {
  background: var(--bg-surface, #0E1017);
  border: 1px solid var(--border-hairline, rgba(255, 255, 255, 0.07));
  border-radius: var(--r-outer, 16px);
  padding: 20px 22px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 4px 28px rgba(0, 0, 0, 0.45), var(--inner-glow, inset 0 1px 0 rgba(255, 255, 255, 0.06));
  margin-bottom: 20px;
}

.cm-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-hairline, rgba(255, 255, 255, 0.07));
}

.cm-title-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.cm-title {
  font-size: 14.5px;
  font-weight: 700;
  color: var(--text-primary, #F3F4F6);
  display: flex;
  align-items: center;
  gap: 8px;
}

.cm-badge-pledge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 6px;
  font-size: 10.5px;
  font-family: var(--font-mono, monospace);
  font-weight: 700;
  background: rgba(6, 182, 212, 0.12);
  border: 1px solid rgba(6, 182, 212, 0.3);
  color: #06B6D4;
}

/* 4-Stat High Level Metric Quad */
.cm-metrics-quad {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}

.cm-metric-tile {
  background: var(--bg-elevated, #131620);
  border: 1px solid var(--border-faint, rgba(255, 255, 255, 0.04));
  border-radius: var(--r-inner, 10px);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 4px;
}

.cm-metric-lbl {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted, #64748B);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.cm-metric-val {
  font-family: var(--font-mono, monospace);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.cm-metric-sub {
  font-size: 10.5px;
  color: var(--text-secondary, #9CA3AF);
}

/* SEBI 50:50 Cash Backing Clamp Visualizer Bar */
.cm-clamp-box {
  background: var(--bg-canvas, #090A0F);
  border: 1px solid var(--border-hairline, rgba(255, 255, 255, 0.07));
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 18px;
}

.cm-clamp-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 8px;
}

.cm-clamp-track {
  height: 8px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 999px;
  overflow: hidden;
  display: flex;
  margin-bottom: 8px;
}

.cm-clamp-fill-cash {
  height: 100%;
  background: var(--emerald, #10B981);
  transition: width 0.3s ease;
}

.cm-clamp-fill-margin {
  height: 100%;
  background: var(--cyan, #06B6D4);
  transition: width 0.3s ease;
}

.cm-clamp-fill-excess {
  height: 100%;
  background: var(--amber, #F59E0B);
  transition: width 0.3s ease;
}

.cm-clamp-legend {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  font-family: var(--font-mono, monospace);
  color: var(--text-muted, #64748B);
  flex-wrap: wrap;
  gap: 8px;
}

/* Interactive Haircut Table & Sliders */
.cm-table-wrap {
  width: 100%;
  overflow-x: auto;
  border-radius: var(--r-inner, 10px);
  border: 1px solid var(--border-faint, rgba(255, 255, 255, 0.04));
  background: var(--bg-elevated, #131620);
  margin-bottom: 14px;
}

.cm-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  text-align: left;
}

.cm-table th {
  padding: 10px 14px;
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted, #64748B);
  background: rgba(0, 0, 0, 0.25);
  border-bottom: 1px solid var(--border-hairline, rgba(255, 255, 255, 0.07));
  white-space: nowrap;
}

.cm-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-faint, rgba(255, 255, 255, 0.03));
  color: var(--text-primary, #F3F4F6);
  white-space: nowrap;
}

.cm-table tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

.cm-table tr:last-child td {
  border-bottom: none;
}

/* Haircut Range Slider Input */
.haircut-slider-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}

.haircut-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 110px;
  height: 4px;
  background: rgba(255, 255, 255, 0.12);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.haircut-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--cyan, #06B6D4);
  cursor: pointer;
  box-shadow: 0 0 6px rgba(6, 182, 212, 0.6);
}

.cm-summary-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 11px 16px;
  background: var(--bg-elevated, #131620);
  border: 1px solid var(--border-hairline, rgba(255, 255, 255, 0.07));
  border-radius: 10px;
  font-size: 11.5px;
  font-family: var(--font-mono, monospace);
  flex-wrap: wrap;
  gap: 8px;
}

/* ==========================================================================
   DAY 14: COLLATERAL UTILIZATION GAUGE IN UI HEADER
   Theme: Obsidian Dark (#090A0F) with SEBI 50:50 Cyan/Emerald Split
   ========================================================================== */
.cm-header-gauge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(14, 16, 23, 0.85);
  border: 1px solid var(--border-hairline, rgba(255, 255, 255, 0.08));
  box-shadow: var(--inner-glow, inset 0 1px 0 rgba(255, 255, 255, 0.05));
  border-radius: 8px;
  padding: 4px 10px;
  cursor: pointer;
  user-select: none;
  transition: all 160ms cubic-bezier(0.16, 1, 0.3, 1);
}

.cm-header-gauge:hover {
  background: var(--bg-elevated, #131620);
  border-color: rgba(6, 182, 212, 0.45);
  box-shadow: 0 0 12px rgba(6, 182, 212, 0.20), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.cm-hg-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #06B6D4;
  box-shadow: 0 0 6px #06B6D4;
  flex-shrink: 0;
  animation: cmPulseDot 2s infinite ease-in-out;
}

@keyframes cmPulseDot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.55; transform: scale(0.85); }
}

.cm-hg-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.cm-hg-top {
  display: flex;
  align-items: center;
  gap: 6px;
  line-height: 1;
}

.cm-hg-label {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text-muted, #64748B);
  text-transform: uppercase;
}

.cm-hg-val {
  font-family: var(--font-mono, monospace);
  font-size: 11.5px;
  font-weight: 700;
  color: #10B981;
}

.cm-hg-bar-track {
  width: 76px;
  height: 3px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 2px;
  overflow: hidden;
  display: flex;
}

.cm-hg-bar-cash {
  height: 100%;
  background: #10B981;
  transition: width 240ms ease;
}

.cm-hg-bar-margin {
  height: 100%;
  background: #06B6D4;
  transition: width 240ms ease;
}

.cm-hg-clamp-tag {
  font-family: var(--font-mono, monospace);
  font-size: 9px;
  font-weight: 800;
  padding: 2px 5px;
  border-radius: 4px;
  background: rgba(6, 182, 212, 0.12);
  border: 1px solid rgba(6, 182, 212, 0.3);
  color: #06B6D4;
  white-space: nowrap;
}

/* Flash pulse highlight when jumped to from header */
@keyframes cmHighlightPulse {
  0% { box-shadow: 0 0 0 0 rgba(6, 182, 212, 0.8); }
  40% { box-shadow: 0 0 28px 8px rgba(6, 182, 212, 0.45); border-color: #06B6D4; }
  100% { box-shadow: 0 4px 28px rgba(0, 0, 0, 0.45); }
}

.highlight-pulse {
  animation: cmHighlightPulse 1.8s ease;
}

@media (max-width: 900px) {
  .cm-metrics-quad { grid-template-columns: repeat(2, 1fr); }
  .haircut-slider { width: 80px; }
}

@media (max-width: 600px) {
  .cm-hg-bar-track { width: 44px; }
  .cm-hg-label { display: none; }
  .cm-header-gauge { padding: 3px 6px; gap: 5px; }
}

/* ==========================================================================
   DAY 14 COLLATERAL & KNAPSACK TELEMETRY DESIGN SYSTEM (GEMINI 4 ARGON)
   ========================================================================== */
:root {
  --telemetry-ok-bg: rgba(16, 185, 129, 0.12);
  --telemetry-ok-border: rgba(16, 185, 129, 0.4);
  --telemetry-ok-text: #10b981;

  --telemetry-warn-bg: rgba(245, 158, 11, 0.12);
  --telemetry-warn-border: rgba(245, 158, 11, 0.4);
  --telemetry-warn-text: #f59e0b;

  --telemetry-clamp-bg: rgba(239, 68, 68, 0.15);
  --telemetry-clamp-border: rgba(239, 68, 68, 0.5);
  --telemetry-clamp-text: #ef4444;

  --meter-track-bg: #1e293b;
  --ceiling-marker-color: #f43f5e;
  --font-mono-tabular: 'JetBrains Mono', 'Fira Code', monospace;
}

.d14-pill, .d14-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.55rem;
  border-radius: 9999px;
  font-family: var(--font-mono-tabular);
  font-size: 0.68rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  border: 1px solid transparent;
  transition: background-color 150ms ease, border-color 150ms ease;
}

.d14-pill[data-state="OPTIMAL"], .d14-badge[data-state="PASS"] {
  background: var(--telemetry-ok-bg);
  border-color: var(--telemetry-ok-border);
  color: var(--telemetry-ok-text);
}

.d14-pill[data-state="CLAMPED"], .d14-badge[data-state="BLOCKED"] {
  background: var(--telemetry-clamp-bg);
  border-color: var(--telemetry-clamp-border);
  color: var(--telemetry-clamp-text);
}

/* 70% Margin Ceiling Meter */
.d14-margin-meter-container {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  width: 100%;
}

.d14-meter-track {
  position: relative;
  height: 8px;
  background: var(--meter-track-bg);
  border-radius: 4px;
  overflow: hidden;
  contain: strict;
}

.d14-meter-fill {
  height: 100%;
  width: 0%;
  background: var(--telemetry-ok-text);
  transition: width 300ms cubic-bezier(0.4, 0, 0.2, 1), background-color 200ms ease;
  border-radius: 4px;
}

.d14-meter-fill[data-zone="WARN"] { background: var(--telemetry-warn-text); }
.d14-meter-fill[data-zone="HALT"] { background: var(--telemetry-clamp-text); }

/* Hard 70% Ceiling Tick Mark */
.d14-meter-ceiling-line {
  position: absolute;
  left: 70%;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--ceiling-marker-color);
  z-index: 2;
  box-shadow: 0 0 4px var(--ceiling-marker-color);
}

.qty-discrete {
  font-family: var(--font-mono-tabular);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
