/* risk_engine.css
   Purpose: Risk Engine UI styling aligned to your reference screenshot.
   Notes:
   - Layout + components reusable (not tightly page-specific).
   - Uses the classnames from your Risk Engine HTML.
*/

:root{
  --bg: #f5f7fb;
  --panel: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: rgba(15, 23, 42, 0.10);
  --border-strong: rgba(15, 23, 42, 0.14);
  --shadow-soft: 0 8px 24px rgba(2, 6, 23, 0.06);
  --shadow-pill: 0 6px 18px rgba(2, 6, 23, 0.05);

  --primary: #2563eb;

  --good: #22c55e;
  --warn: #f59e0b;
  --bad:  #ef4444;

  --teal: #14b8a6;
  --blue: #2563eb;

  --radius: 18px;
  --radius-sm: 12px;
  --radius-xs: 10px;

  --track-bg: rgba(15,23,42,0.06);
  --track-border: rgba(15,23,42,0.08);
}

*{ box-sizing: border-box; }
html, body{ height: 100%; }

body{
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji","Segoe UI Emoji";
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 50% 0%, #e9efff 0%, rgba(233,239,255,0) 60%),
    radial-gradient(900px 500px at 80% 20%, #eefbf5 0%, rgba(238,251,245,0) 60%),
    var(--bg);
}

.muted{ color: var(--muted); }
.mono{
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

/* ===== Shell ===== */
.app-shell{ min-height: 100%; display: flex; flex-direction: column; }

/* ===== Topbar ===== */
.topbar{
  height: 72px;
  padding: 0 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  background: rgba(245,247,251,0.65);
  backdrop-filter: blur(10px);
}

.topbar-title{
  margin: 0;
  font-size: 26px;
  letter-spacing: -0.6px;
  font-weight: 900;
}

.topbar-right{
  display: flex;
  align-items: center;
  gap: 14px;
}

.status-pill{
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(16,185,129,0.08);
  border: 1px solid rgba(16,185,129,0.18);
  box-shadow: var(--shadow-pill);
}

.status-dot{
  width: 10px; height: 10px;
  border-radius: 999px;
  background: var(--good);
  box-shadow: 0 0 0 4px rgba(34,197,94,0.18);
}

.status-text{
  font-size: 13px;
  color: #0f766e;
  font-weight: 800;
}

.settings-link{
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.65);
  text-decoration: none;
  color: var(--text);
  font-weight: 800;
  font-size: 13px;
}
.settings-link:hover{
  background: rgba(255,255,255,0.9);
  box-shadow: var(--shadow-soft);
}

.settings-icon{
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  background: rgba(2,6,23,0.04);
}

.icon-btn{
  width: 40px; height: 40px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.65);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.icon-btn:hover{
  background: rgba(255,255,255,0.9);
  box-shadow: var(--shadow-soft);
}

/* ===== Main container ===== */
.main{
  width: min(1480px, calc(100% - 48px));
  margin: 0 auto;
  padding: 22px 0 28px;
}

/* ===== Subhead row ===== */
.subhead{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 10px 0 16px;
}

.subhead-text{
  margin: 0;
  font-size: 16px;
  color: rgba(15,23,42,0.55);
  font-weight: 700;
}

.subhead-right{
  display: flex;
  align-items: center;
  gap: 14px;
}

.live-pill{
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid rgba(34,197,94,0.20);
  background: rgba(34,197,94,0.08);
}
.live-dot{
  width: 10px; height: 10px;
  border-radius: 999px;
  background: var(--good);
  box-shadow: 0 0 0 4px rgba(34,197,94,0.18);
}
.live-text{
  font-weight: 900;
  color: #0f766e;
}
.updated-text{
  font-size: 13px;
  color: rgba(15,23,42,0.55);
}

/* ===== KPI Row (4-up desktop) ===== */
.kpi-row{
  display: grid;
  gap: 16px;
  margin: 6px 0 16px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: stretch;
}

.kpi-card{
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  padding: 16px 16px 14px;
  min-height: 120px;

  /* critical for 4-up: allow shrinking + prevent text forcing wrap to next row */
  min-width: 0;
  overflow: hidden;
}

.kpi-top{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.kpi-title{
  display: inline-flex;
  align-items: flex-start;
  gap: 10px;
  font-weight: 900;
  font-size: 16px;
  letter-spacing: -0.2px;
  color: rgba(15,23,42,0.85);

  min-width: 0;
}

.kpi-title span{
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.kpi-ic{
  width: 28px; height: 28px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  font-weight: 900;
  font-size: 13px;
  border: 1px solid rgba(15,23,42,0.08);
  background: rgba(2,6,23,0.03);
  flex: 0 0 auto;
}

.ic-red{  color: #b91c1c; background: rgba(239,68,68,0.10); border-color: rgba(239,68,68,0.18); }
.ic-blue{ color: #1d4ed8; background: rgba(37,99,235,0.10); border-color: rgba(37,99,235,0.18); }
.ic-teal{ color: #0f766e; background: rgba(20,184,166,0.12); border-color: rgba(20,184,166,0.20); }

.kpi-ic.ic-slate{
  background: rgba(15, 23, 42, 0.06);
  color: rgba(15, 23, 42, 0.75);
  border: 1px solid rgba(15, 23, 42, 0.10);
}

.kpi-main{ margin-top: 10px; }

.kpi-value{
  font-size: 40px;
  line-height: 1;
  font-weight: 950;
  letter-spacing: -1.2px;
}

.kpi-spark{
  margin-top: 10px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}

.kpi-limit{
  font-size: 13px;
  color: rgba(15,23,42,0.55);
  font-weight: 800;
  white-space: nowrap;
}
.kpi-limit strong{ color: rgba(15,23,42,0.9); font-weight: 950; }
.kpi-limit.split{
  width: 100%;
  display: flex;
  justify-content: space-between;
  gap: 10px;
}
.limit-red{ color: #b91c1c !important; }

/* Sparkline placeholder for drawdown */
.sparkline{
  height: 28px;
  width: 70%;
  border-radius: 999px;
  border: 1px solid var(--track-border);
  background: linear-gradient(180deg, rgba(2,6,23,0.02), rgba(2,6,23,0.01));
  position: relative;
  overflow: hidden;
}
.sparkline::before{
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(40px 20px at 10% 70%, rgba(239,68,68,0.35), transparent 60%),
    radial-gradient(60px 28px at 45% 60%, rgba(239,68,68,0.22), transparent 65%),
    radial-gradient(90px 40px at 80% 65%, rgba(239,68,68,0.28), transparent 70%);
  opacity: .9;
}
.spark-red{
  background: rgba(239,68,68,0.06);
  border-color: rgba(239,68,68,0.14);
}

/* Value colors */
.pos{ color: #2563eb; }          /* matches screenshot allocation number */
.neg{ color: #ef4444; }
.neu{ color: rgba(15,23,42,0.86); }

/* ===== Progress bar used in KPIs ===== */
.progress{
  width: 70%;
  height: 10px;
  border-radius: 999px;
  border: 1px solid var(--track-border);
  background: rgba(15,23,42,0.05);
  overflow: hidden;
  position: relative;
}
.progress-bar{
  height: 100%;
  border-radius: 999px;
}
.progress-bar.blue{  background: rgba(37,99,235,0.70); }
.progress-bar.green{ background: rgba(34,197,94,0.70); }
.progress-bar.slate{ background: rgba(15, 23, 42, 0.25); }

.progress-danger{
  position: absolute;
  right: 0;
  top: 0;
  height: 100%;
  width: 22%;
  background: rgba(239,68,68,0.25);
}

/* ===== Main grid ===== */
.grid-main{
  display: grid;
  gap: 16px;
  grid-template-columns: 2fr 1fr; /* left controls wider, right log slimmer */
  align-items: start;
}

/* ===== Panels ===== */
.panel{
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
}

.panel-header{
  padding: 16px 18px;
  border-bottom: 1px solid rgba(15,23,42,0.06);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-title{
  font-weight: 950;
  font-size: 16px;
  letter-spacing: -0.2px;
}

.panel-body{
  padding: 14px 14px 14px;
}

/* ===== Controls list ===== */
.control-row{
  display: grid;
  grid-template-columns: 1.2fr 1.8fr;
  gap: 12px;
  padding: 12px 12px;
  border-radius: 14px;
  border: 1px solid rgba(15,23,42,0.06);
  background: rgba(2,6,23,0.01);
  margin-bottom: 10px;
}

.control-left{
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.control-name{
  font-size: 14px;
  font-weight: 800;
  color: rgba(15,23,42,0.72);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.control-right{
  display: grid;
  grid-template-columns: 150px 1fr 92px;
  gap: 12px;
  align-items: center;
}

.control-current{
  font-size: 14px;
  font-weight: 900;
  color: rgba(15,23,42,0.72);
  white-space: nowrap;
}

.control-limit{
  text-align: right;
  font-size: 14px;
  font-weight: 950;
  color: rgba(15,23,42,0.62);
  white-space: nowrap;
}

.chev-right{
  margin-left: 6px;
  opacity: .55;
}

/* Slider-like track */
.control-track .track,
.emergency-track .track{
  height: 12px;
  border-radius: 999px;
  border: 1px solid var(--track-border);
  background: var(--track-bg);
  position: relative;
  overflow: hidden;
}

/* Track segments */
.track-ok, .track-bad, .track-warn, .track-blue{
  height: 100%;
  float: left;
}

.track-ok{ background: rgba(34,197,94,0.32); }
.track-warn{ background: rgba(245,158,11,0.32); }
.track-bad{ background: rgba(239,68,68,0.30); }
.track-blue{ background: rgba(37,99,235,0.35); }

/* Thumb */
.thumb{
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 14px; height: 14px;
  border-radius: 999px;
  background: #fff;
  border: 2px solid rgba(15,23,42,0.18);
  box-shadow: 0 6px 14px rgba(2,6,23,0.10);
}

/* ===== Switch (toggle) ===== */
.switch{
  position: relative;
  display: inline-block;
  width: 44px;
  height: 26px;
  flex: 0 0 auto;
}
.switch input{
  opacity: 0;
  width: 0;
  height: 0;
}
.slider{
  position: absolute;
  cursor: not-allowed; /* placeholder */
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(148,163,184,0.35);
  border: 1px solid rgba(15,23,42,0.10);
  transition: .2s;
  border-radius: 999px;
}
.slider:before{
  position: absolute;
  content: "";
  height: 20px; width: 20px;
  left: 3px; top: 50%;
  transform: translateY(-50%);
  background: white;
  border: 1px solid rgba(15,23,42,0.10);
  transition: .2s;
  border-radius: 999px;
  box-shadow: 0 6px 14px rgba(2,6,23,0.10);
}
.switch input:checked + .slider{
  background: rgba(37,99,235,0.75);
  border-color: rgba(37,99,235,0.20);
}
.switch input:checked + .slider:before{
  transform: translate(18px, -50%);
}

/* ===== Emergency block ===== */
.emergency{
  margin-top: 12px;
  padding: 14px 12px;
  border-radius: 14px;
  border: 1px solid rgba(15,23,42,0.06);
  background: rgba(2,6,23,0.01);
}

.emergency-top{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.emergency-label{
  font-size: 15px;
  font-weight: 950;
  color: rgba(15,23,42,0.72);
}

.input-pill{
  display: inline-flex;
  align-items: center;
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid rgba(15,23,42,0.10);
  background: rgba(255,255,255,0.85);
  font-weight: 950;
  color: rgba(15,23,42,0.78);
}

.emergency-track{ margin-top: 12px; }

.emergency-note{
  margin-top: 10px;
  font-size: 13px;
  color: rgba(15,23,42,0.55);
  font-weight: 650;
}

/* ===== Bottom strips ===== */
.strip{
  margin-top: 12px;
  padding: 12px 12px;
  border-radius: 14px;
  border: 1px solid rgba(15,23,42,0.06);
  background: rgba(2,6,23,0.01);
  display: grid;
  grid-template-columns: 1.2fr 1fr 0.8fr;
  gap: 12px;
  align-items: center;
}

.strip-title{
  font-size: 13px;
  font-weight: 900;
  color: rgba(15,23,42,0.55);
}
.strip-value{
  font-size: 14px;
  font-weight: 950;
  color: rgba(15,23,42,0.80);
  margin-left: 6px;
  display: inline-block;
}
.strip-sub{
  margin-top: 4px;
  font-size: 12px;
}

.strip-left{
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 6px;
}

.strip-mid{
  display: flex;
  justify-content: center;
}

.micro-track{
  width: 100%;
  max-width: 280px;
  height: 14px;
  padding: 2px;
  border-radius: 999px;
  border: 1px solid rgba(15,23,42,0.08);
  background: rgba(15,23,42,0.04);
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
}
.mseg{
  border-radius: 999px;
  background: rgba(148,163,184,0.40);
}
.mseg:nth-child(3){ background: rgba(239,68,68,0.55); }
.mseg:nth-child(4){ background: rgba(245,158,11,0.55); }
.mseg:nth-child(5){ background: rgba(34,197,94,0.55); }

.strip-right{
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
}

.strip-meta{
  font-size: 13px;
  font-weight: 900;
}

/* ===== Activity log ===== */
.activity{ padding: 12px; }

.log-item{
  padding: 12px 12px;
  border-radius: 14px;
  border: 1px solid rgba(15,23,42,0.06);
  background: rgba(2,6,23,0.01);
  margin-bottom: 10px;
}

.log-top{
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.log-time{
  font-size: 12px;
  font-weight: 900;
  color: rgba(15,23,42,0.48);
  white-space: nowrap;
}

.log-tag{
  font-size: 12px;
  font-weight: 950;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(15,23,42,0.08);
  background: rgba(148,163,184,0.20);
  color: rgba(15,23,42,0.75);
  white-space: nowrap;
}

.log-tag.ok{
  background: rgba(34,197,94,0.12);
  border-color: rgba(34,197,94,0.18);
  color: #15803d;
}

.log-tag.warn{
  background: rgba(245,158,11,0.14);
  border-color: rgba(245,158,11,0.20);
  color: #92400e;
}

.log-tag.danger{
  background: rgba(239,68,68,0.12);
  border-color: rgba(239,68,68,0.18);
  color: #b91c1c;
}

.log-tag.info{
  background: rgba(37,99,235,0.12);
  border-color: rgba(37,99,235,0.18);
  color: #1d4ed8;
}

.log-link{
  margin-left: auto;
  border: 0;
  background: transparent;
  color: rgba(15,23,42,0.45);
  cursor: pointer;
  padding: 4px;
  border-radius: 10px;
}
.log-link:hover{
  color: rgba(15,23,42,0.70);
  background: rgba(2,6,23,0.04);
}

.log-body{
  font-size: 13px;
  color: rgba(15,23,42,0.62);
  font-weight: 650;
  line-height: 1.35;
}

.log-empty{
  margin-top: 8px;
  padding: 12px 6px 6px;
  font-size: 12px;
  color: rgba(15,23,42,0.45);
}

/* Footer */
.footer{ padding: 20px 0 0; }
.footer-inner{
  display: flex;
  justify-content: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}
.footer-inner .dot{ opacity: .7; }

/* ===== Responsive ===== */
@media (max-width: 1180px){
  .grid-main{ grid-template-columns: 1fr; }
  .control-right{ grid-template-columns: 140px 1fr 86px; }
}

@media (max-width: 680px){
  .topbar{
    padding: 12px 14px;
    height: auto;
    gap: 12px;
    flex-wrap: wrap;
  }

  .subhead{
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  .control-row{ grid-template-columns: 1fr; }

  .control-right{
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .control-limit{ text-align: left; }

  .strip{ grid-template-columns: 1fr; }

  .strip-right{ justify-content: flex-start; }
}
/* ===== KPI Row: FORCE 4 CARDS ON ONE LINE (desktop) =====
   Put this at the *bottom* of the file to override any earlier .kpi-row rules.
*/
.kpi-row{
  display: flex;
  gap: 16px;
  flex-wrap: nowrap;      /* force single row */
}

/* Each card = 25% minus gap distribution */
.kpi-row > .kpi-card{
  flex: 0 0 calc(25% - 12px); /* 25% width */
  max-width: calc(25% - 12px);
  min-width: 0;               /* allow shrink */
}

/* Prevent long KPI titles from expanding layout pressure */
.kpi-title{
  min-width: 0 !important;
}
.kpi-title span{
  min-width: 0 !important;
  overflow-wrap: anywhere !important;
  word-break: break-word !important;
}

/* Optional tightening so 4-up feels natural */
.kpi-value{
  font-size: 34px !important;
  letter-spacing: -0.8px !important;
}

/* Responsive fallbacks */
@media (max-width: 1180px){
  .kpi-row{
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
}
@media (max-width: 620px){
  .kpi-row{
    grid-template-columns: 1fr !important;
  }
}