html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: transparent;
}

#root { height: 100%; width: 100%; }

/* ═══════════════════════════════════════════
   VIZ MODE — KPI card
   ═══════════════════════════════════════════ */

.kpi-card {
  box-sizing: border-box;
  height: 100%;
  width: 100%;
  display: flex;
  flex-direction: column;
}

/* Status bar — shared color rules */
.kpi-status-bar {
  border-radius: 3px;
  flex-shrink: 0;
  transition: background 0.35s ease;
}
.kpi-status-bar.good    { background: linear-gradient(90deg, #16a34a, #14532d); }
.kpi-status-bar.bad     { background: linear-gradient(90deg, #b91c1c, #7f1d1d); }
.kpi-status-bar.neutral { background: rgba(128, 128, 128, 0.18); }

/* Top position (horizontal pill above content) */
.kpi-status-bar.bar-top {
  height: 5px;
  margin: 6px 10px 0;
}

/* Left positions — shared vertical bar style */
.kpi-status-bar.bar-left {
  width: 5px;
  border-radius: 3px;
  flex-shrink: 0;
  align-self: stretch;   /* guarantees full height in any flex-row parent */
}
.kpi-status-bar.bar-left.good { background: linear-gradient(180deg, #16a34a, #14532d); }
.kpi-status-bar.bar-left.bad  { background: linear-gradient(180deg, #b91c1c, #7f1d1d); }
.kpi-status-bar.bar-left.neutral { background: rgba(128,128,128,0.18); }

/* left-ban: bar beside the BAN value only */
.kpi-value-wrap {
  display: flex;
  align-items: stretch;
  gap: 12px;
  margin-bottom: 5px;
}
.kpi-value-wrap .kpi-value { margin-bottom: 0; }

/* left-full: bar beside text elements only (chart sits below as a flex sibling) */
.kpi-content-body {
  display: flex;
  align-items: stretch;
  gap: 12px;
}
.kpi-content-right {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* Main content: stacks label → BAN → delta → chart */
.kpi-content {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 12px 18px 10px;
}

.kpi-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  opacity: 0.45;
  margin: 0 0 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kpi-value {
  font-size: clamp(48px, 14vw, 120px);
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.03em;
  margin: 0 0 5px;
}

.kpi-delta {
  font-size: clamp(11px, 1.5vw, 13px);
  font-weight: 600;
  margin: 0 0 10px;
  opacity: 0.9;
}
.kpi-delta.positive { color: #15803d; }
.kpi-delta.negative { color: #b91c1c; }

.kpi-caption {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0.45;
  margin: 0 0 8px;
}

/* Chart fills all remaining vertical space */
.kpi-chart {
  flex: 1;
  min-height: 48px;
  overflow: hidden;
}
.kpi-chart svg {
  display: block;
  width: 100%;
  height: 100%;
}

/* ── Chart dot tooltip ── */
.kpi-tooltip {
  display: none;
  position: fixed;
  z-index: 9999;
  pointer-events: none;
  background: rgba(15, 23, 42, 0.91);
  color: #f1f5f9;
  border-radius: 7px;
  padding: 8px 11px 9px;
  font-size: 11px;
  line-height: 1.45;
  box-shadow: 0 4px 22px rgba(0,0,0,0.28);
  backdrop-filter: blur(6px);
  min-width: 110px;
  white-space: nowrap;
}
.kti-lbl {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  opacity: 0.55;
  margin-bottom: 3px;
}
.kti-cur {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 5px;
}
.kti-prev {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  opacity: 0.65;
  margin-bottom: 2px;
}
.kti-delta       { font-weight: 700; font-size: 11px; }
.kti-delta.pos   { color: #4ade80; }
.kti-delta.neg   { color: #f87171; }

.kpi-message {
  font-size: 0.9rem;
  font-weight: 500;
  opacity: 0.65;
  padding: 1rem 0 0.5rem;
  max-width: 24ch;
}

.kpi-disclaimer {
  font-size: 0.7rem;
  font-weight: 400;
  opacity: 0.4;
  max-width: 32ch;
  line-height: 1.5;
  padding-bottom: 0.5rem;
}

/* Gear icon — appears on hover */
#gear {
  position: fixed;
  top: 8px;
  right: 8px;
  width: 26px;
  height: 26px;
  border: none;
  border-radius: 5px;
  background: rgba(128, 128, 128, 0.15);
  color: inherit;
  font-size: 14px;
  line-height: 26px;
  text-align: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease;
  z-index: 20;
}
body:hover #gear  { opacity: 0.55; }
#gear:hover       { opacity: 1 !important; }

#version {
  position: fixed;
  left: 10px;
  bottom: 8px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.05em;
  opacity: 0.3;
  pointer-events: none;
  user-select: none;
}

/* ═══════════════════════════════════════════
   DIALOG MODE — settings form (?dialog=1)
   ═══════════════════════════════════════════ */

.cfg {
  box-sizing: border-box;
  padding: 16px 18px 80px;
  color: #1c2433;
  font-size: 13px;
}
.cfg h2 { font-size: 15px; margin: 0 0 3px; }
.cfg .sub { color: #6b7280; margin: 0 0 14px; font-size: 12px; }

.cfg fieldset {
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 10px 12px 12px;
  margin: 0 0 12px;
}
.cfg legend {
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 11px;
  color: #374151;
  padding: 0 6px;
}
.cfg .row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 7px 0;
}
.cfg .row label { flex: 1; color: #374151; }
.cfg input[type="text"],
.cfg input[type="number"],
.cfg select {
  flex: 1;
  min-width: 0;
  padding: 5px 7px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font: inherit;
  background: #fff;
  color: #111827;
}
.cfg input[type="number"] { max-width: 72px; }
.cfg input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; flex: none; }
.cfg input[type="color"] {
  width: 42px; height: 26px;
  padding: 0; border: 1px solid #d1d5db;
  border-radius: 6px; background: none; cursor: pointer; flex: none;
}
.cfg .hint { font-size: 11px; color: #9ca3af; margin: 0 0 4px; }

/* ── Three-level right-cascading color picker ── */

/* Row layout: label (fixed) + picker trigger */
.clr-row { display: flex; align-items: center; gap: 8px; margin: 5px 0; }
.clr-row > label { font-size: 12px; color: #374151; flex: 0 0 96px; }

/* Level 0: the trigger swatch button */
.pal-picker { position: relative; }
.pal-trigger-btn {
  display: block; width: 26px; height: 22px;
  border: 1.5px solid rgba(0,0,0,0.22);
  border-radius: 4px; cursor: pointer; padding: 0;
  transition: box-shadow 0.1s;
}
.pal-trigger-btn:hover { box-shadow: 0 0 0 2px rgba(0,0,0,0.15); }

/* Level 1: palette families panel */
.pal-families-panel {
  display: none;
  position: absolute;
  left: 30px; top: 0;
  width: 108px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.14);
  z-index: 400;
  overflow: visible;
  padding: 3px;
}
.pal-picker.open > .pal-families-panel { display: block; }
/* flip-up: panel opens above the trigger when near the dialog bottom */
.pal-picker.flip-up > .pal-families-panel { top: auto; bottom: 0; }

/* Level 1 items */
.pal-family-item {
  position: relative;
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px 6px; border-radius: 4px;
  font-size: 11px; color: #374151; cursor: default; white-space: nowrap;
}
.pal-family-item:hover { background: #f3f4f6; }
.pal-fi-arr { font-size: 9px; color: #9ca3af; margin-left: 4px; }

/* Level 2: color swatches panel, cascades to the RIGHT */
.pal-colors-panel {
  display: none;
  position: absolute;
  left: 100%; top: -3px;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.14);
  z-index: 401;
  padding: 5px;
  flex-wrap: wrap;
  gap: 3px;
  width: 116px;      /* fits 2 rows of 5 × 15px swatches with gaps */
}
.pal-family-item:hover > .pal-colors-panel { display: flex; }

.pal-swatch {
  width: 15px; height: 15px;
  border: 1.5px solid rgba(0,0,0,0.12);
  border-radius: 3px; cursor: pointer; padding: 0; flex-shrink: 0;
  transition: transform 0.1s;
}
.pal-swatch:hover { transform: scale(1.3); position: relative; z-index: 1; border-color: rgba(0,0,0,0.4); }

/* Custom option */
.pal-divider { border-top: 1px solid #e5e7eb; margin: 3px 0; }
.pal-custom-item {
  padding: 4px 6px; border-radius: 4px;
  font-size: 11px; color: #374151; cursor: pointer;
}
.pal-custom-item:hover { background: #f3f4f6; }

/* Hidden native color input (clicked programmatically for Custom) */
.pal-hidden-input {
  position: absolute; width: 0; height: 0;
  opacity: 0; pointer-events: none;
}

.cfg .actions {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: flex;
  gap: 8px;
  padding: 12px 18px;
  background: #fff;
  border-top: 1px solid #e5e7eb;
  z-index: 10;
}
.cfg .actions button {
  font: inherit; font-weight: 600; font-size: 13px;
  padding: 8px 14px; border-radius: 6px; cursor: pointer;
}
.cfg .primary { background: #161E46; color: #fff; border: none; }
.cfg .ghost   { background: #fff; color: #374151; border: 1px solid #d1d5db; }
.cfg .spacer  { flex: 1; }
