/* ═══════════════════════════════════════════════
   COMPONENTS — All UI building blocks.
   Each section is self-contained and documented.
   ═══════════════════════════════════════════════ */

/* ══════════════════════════
   GRID SYSTEM
══════════════════════════ */
.grid-4   { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.grid-3   { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-2   { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.grid-3-2 { display: grid; grid-template-columns: 3fr 2fr;        gap: 16px; }
.grid-2-1 { display: grid; grid-template-columns: 2fr 1fr;        gap: 16px; }

/* ══════════════════════════
   CARD
══════════════════════════ */
.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-card);
}

:root.dark .card { box-shadow: none; }

/* Subtle top-edge highlight */
.card::before {
  content: '';
  position: absolute;
  inset: 0 0 auto 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.06), transparent);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
  flex-wrap: wrap;
}

.card-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  font-family: var(--font-mono);
}

.card-action {
  font-size: 11px;
  color: var(--text-gold);
  cursor: pointer;
  font-family: var(--font-mono);
  opacity: 0.7;
  transition: opacity 0.15s;
  white-space: nowrap;
}
.card-action:hover { opacity: 1; }

/* ══════════════════════════
   KPI CARD
══════════════════════════ */
.kpi-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  position: relative;
  overflow: hidden;
  cursor: default;
  transition: border-color 0.2s, transform 0.2s;
}

.kpi-card:hover { border-color: var(--border-bright); transform: translateY(-1px); }

/* Colour accent bar at bottom */
.kpi-card::after {
  content: '';
  position: absolute;
  inset: auto 0 0 0;
  height: 2px;
}
.kpi-card.gold::after  { background: linear-gradient(90deg, transparent, var(--gold),  transparent); }
.kpi-card.cyan::after  { background: linear-gradient(90deg, transparent, var(--cyan),  transparent); }
.kpi-card.green::after { background: linear-gradient(90deg, transparent, var(--green), transparent); }
.kpi-card.red::after   { background: linear-gradient(90deg, transparent, var(--red),   transparent); }
.kpi-card.amber::after { background: linear-gradient(90deg, transparent, var(--amber), transparent); }

/* Light-mode overrides */
:root:not(.dark) .kpi-card        { background: #ffffff; }
:root:not(.dark) .kpi-card.gold   { border-color: rgba(154,111,30,0.2); }
:root:not(.dark) .kpi-card.cyan   { border-color: rgba(0,119,204,0.2); }
:root:not(.dark) .kpi-card.green  { border-color: rgba(26,138,74,0.2); }
:root:not(.dark) .kpi-card.red    { border-color: rgba(217,48,37,0.2); }

.kpi-label {
  font-size: 10px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.kpi-icon {
  width: 20px; height: 20px;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  flex-shrink: 0;
}
.kpi-card.gold  .kpi-icon { background: var(--gold-dim);  color: var(--gold);  }
.kpi-card.cyan  .kpi-icon { background: var(--cyan-dim);  color: var(--cyan);  }
.kpi-card.green .kpi-icon { background: var(--green-dim); color: var(--green); }
.kpi-card.red   .kpi-icon { background: var(--red-dim);   color: var(--red);   }
.kpi-card.amber .kpi-icon { background: var(--amber-dim); color: var(--amber); }

.kpi-value {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text-primary);
  line-height: 1;
  margin-bottom: 8px;
}
.kpi-value sup { font-size: 14px; vertical-align: super; }

.kpi-change {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-family: var(--font-mono);
}
.kpi-change.up   { color: var(--green); }
.kpi-change.down { color: var(--red); }
.kpi-change .period { color: var(--text-muted); margin-left: 4px; }

.kpi-sparkline {
  position: absolute;
  bottom: 12px; right: 16px;
  opacity: 0.4;
}

/* ══════════════════════════
   SECTION HEADER
══════════════════════════ */
.section-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.section-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}
.section-title em {
  font-style: italic;
  font-family: var(--font-serif);
  font-size: 22px;
  color: var(--gold-light);
}

.section-eyebrow {
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

/* ══════════════════════════
   DATA TABLE
══════════════════════════ */

/* Wrapper enables horizontal scroll on small screens */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  /* Hide scrollbar on non-touch while keeping scrollability */
  scrollbar-width: thin;
  scrollbar-color: var(--surface2) transparent;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 520px; /* prevents columns crushing on tiny viewports */
}

.data-table th {
  font-size: 10px;
  font-family: var(--font-mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 11px 12px;
  font-size: 13px;
  border-bottom: 1px solid rgba(255,255,255,0.03);
  vertical-align: middle;
}
:root:not(.dark) .data-table td { border-bottom-color: var(--border); }

.data-table tr:last-child td   { border-bottom: none; }
.data-table tr:hover  td       { background: rgba(255,255,255,0.02); }
:root:not(.dark) .data-table tr:hover td { background: rgba(0,0,0,0.02); }

.data-table .mono    { font-family: var(--font-mono); font-size: 12px; }
.data-table .muted   { color: var(--text-muted); }
.data-table .primary { color: var(--text-primary); font-weight: 500; }

/* ══════════════════════════
   BADGES
══════════════════════════ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 20px;
  font-size: 10px;
  font-family: var(--font-mono);
  font-weight: 500;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.badge-dot { width: 5px; height: 5px; border-radius: 50%; flex-shrink: 0; }

.badge.success { background: var(--green-dim); color: var(--green); border: 1px solid rgba(46,213,115,0.2); }
.badge.success .badge-dot { background: var(--green); }

.badge.warning { background: var(--amber-dim); color: var(--amber); border: 1px solid rgba(255,165,2,0.2); }
.badge.warning .badge-dot { background: var(--amber); }

.badge.danger  { background: var(--red-dim);   color: var(--red);   border: 1px solid rgba(255,71,87,0.2); }
.badge.danger  .badge-dot { background: var(--red); }

.badge.info    { background: var(--cyan-dim);  color: var(--cyan);  border: 1px solid rgba(0,212,255,0.2); }
.badge.info    .badge-dot { background: var(--cyan); }

.badge.neutral { background: rgba(255,255,255,0.05); color: var(--text-secondary); border: 1px solid var(--border); }
:root:not(.dark) .badge.neutral { background: rgba(0,0,0,0.04); }

.badge.gold    { background: var(--gold-dim);  color: var(--gold);  border: 1px solid rgba(201,168,76,0.2); }

/* ══════════════════════════
   PROGRESS BARS
══════════════════════════ */
.progress-bar {
  height: 4px;
  background: rgba(255,255,255,0.06);
  border-radius: 2px;
  overflow: hidden;
}
:root:not(.dark) .progress-bar { background: rgba(0,0,0,0.06); }

.progress-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 1s ease;
}
.progress-fill.gold  { background: linear-gradient(90deg, var(--gold), var(--gold-light)); }
.progress-fill.green { background: var(--green); }
.progress-fill.red   { background: var(--red); }
.progress-fill.cyan  { background: var(--cyan); }
.progress-fill.amber { background: var(--amber); }

/* ══════════════════════════
   HORIZONTAL BAR ROWS
══════════════════════════ */
.hbar-row { margin-bottom: 12px; }

.hbar-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.hbar-label { font-size: 12px; color: var(--text-secondary); }
.hbar-value { font-family: var(--font-mono); font-size: 12px; color: var(--text-primary); }

/* ══════════════════════════
   STAT ROW
══════════════════════════ */
.stat-row   { display: flex; gap: 4px; align-items: center; }
.stat-num   { font-family: var(--font-mono); font-size: 13px; font-weight: 500; }
.stat-label { font-size: 11px; color: var(--text-muted); }

/* ══════════════════════════
   LIVE BADGE
══════════════════════════ */
.live-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(46,213,115,0.08);
  border: 1px solid rgba(46,213,115,0.2);
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--green);
  letter-spacing: 0.06em;
  flex-shrink: 0;
}

.live-dot {
  width: 6px; height: 6px;
  background: var(--green);
  border-radius: 50%;
  animation: pulse-green 2s infinite;
}

/* ══════════════════════════
   THEME TOGGLE
══════════════════════════ */
.theme-toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px;
  background: var(--surface);
  border: 1px solid var(--border-bright);
  border-radius: 20px;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
  user-select: none;
  flex-shrink: 0;
}
.theme-toggle:hover { color: var(--text-primary); border-color: var(--gold); }

.toggle-track {
  width: 28px; height: 16px;
  background: var(--surface2);
  border-radius: 8px;
  position: relative;
  border: 1px solid var(--border-bright);
  flex-shrink: 0;
  transition: background 0.25s, border-color 0.25s !important;
}
:root.dark .toggle-track { background: var(--gold-dim); border-color: var(--gold); }

.toggle-thumb {
  position: absolute;
  top: 2px; left: 2px;
  width: 10px; height: 10px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: left 0.22s ease, background 0.22s !important;
}
:root.dark .toggle-thumb { left: 14px; background: var(--gold); }

/* ══════════════════════════
   SEARCH BAR
══════════════════════════ */
.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  flex: 1;
  max-width: 280px;
}

.search-bar input {
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font-display);
  font-size: 12px;
  width: 100%;
}
.search-bar input::placeholder { color: var(--text-muted); }
.search-icon { color: var(--text-muted); font-size: 13px; }

/* ══════════════════════════
   TAB GROUP
══════════════════════════ */
.tab-group {
  display: flex;
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 2px;
}

.tab-btn {
  padding: 5px 14px;
  border-radius: 6px;
  font-size: 11px;
  font-family: var(--font-mono);
  cursor: pointer;
  color: var(--text-muted);
  border: none;
  background: none;
  letter-spacing: 0.04em;
  transition: all 0.15s;
}
.tab-btn.active          { background: var(--surface2); color: var(--text-primary); }
.tab-btn:hover:not(.active) { color: var(--text-secondary); }

/* ══════════════════════════
   ALERT / FEED ITEMS
══════════════════════════ */
.alert-item {
  display: flex;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.alert-item:last-child { border-bottom: none; }

.alert-indicator {
  width: 3px;
  border-radius: 2px;
  flex-shrink: 0;
  align-self: stretch;
}
.alert-indicator.danger  { background: var(--red); }
.alert-indicator.warning { background: var(--amber); }
.alert-indicator.info    { background: var(--cyan); }

.alert-body    { flex: 1; min-width: 0; }
.alert-title   { font-size: 12px; font-weight: 600; color: var(--text-primary); margin-bottom: 2px; }
.alert-desc    { font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.alert-time    { font-family: var(--font-mono); font-size: 10px; color: var(--text-muted); flex-shrink: 0; }

/* ══════════════════════════
   RISK MATRIX
══════════════════════════ */
.risk-matrix {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows:    repeat(5, 1fr);
  gap: 3px;
  aspect-ratio: 1;
  max-width: 220px;
}

.risk-cell {
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 9px;
  font-family: var(--font-mono);
  font-weight: 500;
  cursor: default;
  transition: transform 0.15s;
  position: relative;
}
.risk-cell:hover   { transform: scale(1.08); z-index: 2; }
.risk-cell.low      { background: rgba(46,213,115,0.15); color: var(--green); }
.risk-cell.medium   { background: rgba(255,165,2,0.15);  color: var(--amber); }
.risk-cell.high     { background: rgba(255,71,87,0.15);  color: var(--red); }
.risk-cell.critical { background: rgba(255,71,87,0.3);   color: var(--red); border: 1px solid rgba(255,71,87,0.4); }

/* ══════════════════════════
   DONUT CHART
══════════════════════════ */
.donut-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.donut-center {
  position: absolute;
  text-align: center;
  pointer-events: none;
}
.donut-center-value { font-size: 22px; font-weight: 700; letter-spacing: -0.03em; }
.donut-center-label { font-size: 9px; font-family: var(--font-mono); color: var(--text-muted); letter-spacing: 0.08em; }

/* ══════════════════════════
   SVG CHARTS
══════════════════════════ */
.chart-area { position: relative; width: 100%; }
svg.chart   { width: 100%; overflow: visible; }

/* Theme-aware SVG element colours */
.chart-grid           { stroke: rgba(0,0,0,0.07); }
:root.dark .chart-grid { stroke: rgba(255,255,255,0.05); }

.chart-text           { fill: rgba(0,0,0,0.28); }
:root.dark .chart-text { fill: rgba(255,255,255,0.22); }

.chart-forecast-line           { stroke: rgba(0,0,0,0.18); }
:root.dark .chart-forecast-line { stroke: rgba(255,255,255,0.15); }

.chart-forecast-label           { fill: rgba(0,0,0,0.28); }
:root.dark .chart-forecast-label { fill: rgba(255,255,255,0.28); }

.chart-zero-label           { fill: rgba(0,0,0,0.28); }
:root.dark .chart-zero-label { fill: rgba(255,255,255,0.2); }

/* Gradient fill overrides for light mode */
:root:not(.dark) #g-gold  stop:first-child { stop-color: rgba(154,111,30,0.18); }
:root:not(.dark) #g-cyan  stop:first-child { stop-color: rgba(0,119,204,0.12); }
:root:not(.dark) #g-green stop:first-child { stop-color: rgba(26,138,74,0.10); }

/* ─── Chart Legend ─── */
.chart-legend {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-secondary);
}

.legend-dot { width: 8px; height: 8px; border-radius: 2px; flex-shrink: 0; }

/* ══════════════════════════
   FX TICKER
══════════════════════════ */
.fx-ticker {
  display: flex;
  overflow-x: auto;
  background: var(--deep);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 11px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.fx-ticker::-webkit-scrollbar { display: none; }
:root:not(.dark) .fx-ticker { background: #f6f7fb; }

.fx-item {
  padding: 6px 16px;
  border-right: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  flex-shrink: 0;
}
.fx-item:last-child { border-right: none; }

.fx-pair         { color: var(--text-muted); font-size: 10px; }
.fx-rate         { color: var(--text-primary); font-weight: 500; }
.fx-chg.pos      { color: var(--green); }
.fx-chg.neg      { color: var(--red); }

/* ══════════════════════════
   COMPLIANCE TRACKER
══════════════════════════ */
.compliance-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.compliance-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
}
:root:not(.dark) .compliance-item { background: #f6f7fb; }

.compliance-name   { font-size: 11px; font-weight: 600; color: var(--text-primary); margin-bottom: 4px; }
.compliance-sub    { font-size: 10px; color: var(--text-muted); font-family: var(--font-mono); margin-bottom: 10px; }
.compliance-score  { display: flex; align-items: baseline; gap: 4px; margin-bottom: 6px; }
.compliance-pct    { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
.compliance-target { font-size: 10px; color: var(--text-muted); font-family: var(--font-mono); }

/* ══════════════════════════
   LOAN PORTFOLIO
══════════════════════════ */
.loan-items { display: flex; flex-direction: column; gap: 10px; flex: 1; }

.loan-item {
  display: flex;
  align-items: center;
  gap: 10px;
}

.loan-type   { font-size: 11px; color: var(--text-secondary); width: 90px; flex-shrink: 0; }
.loan-bar-wrap { flex: 1; }
.loan-amount { font-family: var(--font-mono); font-size: 11px; color: var(--text-primary); text-align: right; width: 70px; flex-shrink: 0; }

/* ══════════════════════════
   TREASURY / FX POSITIONS
══════════════════════════ */
.position-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
:root:not(.dark) .position-row { border-bottom-color: var(--border); }
.position-row:last-child { border-bottom: none; }

.position-currency { display: flex; align-items: center; gap: 8px; }

.currency-flag {
  width: 26px; height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  background: var(--surface2);
}
:root:not(.dark) .currency-flag { background: #eef0f6; }

.currency-code { font-weight: 600; font-size: 13px; }
.currency-name { font-size: 10px; color: var(--text-muted); font-family: var(--font-mono); }

.position-amount { text-align: right; }
.position-value  { font-family: var(--font-mono); font-size: 13px; font-weight: 500; }
.position-pnl    { font-family: var(--font-mono); font-size: 10px; }

/* ══════════════════════════
   WATERMARK
══════════════════════════ */
.d365-mark {
  position: fixed;
  bottom: 20px;
  right: 28px;
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  opacity: 0.4;
  letter-spacing: 0.08em;
  pointer-events: none;
  z-index: 100;
}
