/* ============================================================
   AI Loan Underwriting Demo — Styles
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f0f4fa;
  --surface: #ffffff;
  --glass: rgba(255,255,255,.78);
  --glass-border: rgba(220,225,238,.7);
  --text: #1a1e2e;
  --text-muted: #6b7280;
  --primary: #4F6EF7;
  --primary-dark: #3b57d9;
  --primary-light: #8ba3fc;
  --primary-glow: rgba(79,110,247,.35);
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 14px;
  --radius-sm: 8px;
  --shadow: 0 2px 16px rgba(30,40,90,.07);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --transition: .3s cubic-bezier(.4,0,.2,1);
  --header-h: 56px;
}

html { font-size: 14px; scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(79,110,247,.08), transparent),
    radial-gradient(ellipse 60% 40% at 80% 100%, rgba(16,185,129,.05), transparent);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* ── Header ── */
.site-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  backdrop-filter: blur(16px);
  background: var(--glass);
  border-bottom: 1px solid var(--glass-border);
  z-index: 100;
  padding: 0 1.25rem;
}

.header-inner {
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: 1.15rem;
  font-weight: 700;
  white-space: nowrap;
}

.logo small { font-weight: 400; color: var(--text-muted); font-size: .7rem; margin-left: .1rem; }
.logo-icon { width: 30px; height: 30px; }

.header-right { display: flex; align-items: center; gap: .75rem; }

.header-flow {
  font-size: .68rem;
  color: var(--text-muted);
  letter-spacing: .02em;
  display: none;
}

.badge {
  font-size: .65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: .25rem .6rem;
  border-radius: 99px;
  background: var(--primary);
  color: #fff;
  white-space: nowrap;
}

/* ============================================================
   3-Column Dashboard Layout
   ============================================================ */
.app-layout {
  display: grid;
  grid-template-columns: 260px 1fr 280px;
  gap: 1rem;
  height: calc(100vh - var(--header-h));
  padding: .75rem 1rem;
  max-width: 1600px;
  margin: 0 auto;
}

/* ── Panels ── */
.panel {
  background: var(--glass);
  backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.panel-head {
  padding: 1rem 1.15rem .6rem;
  flex-shrink: 0;
}

.panel-head h2 { font-size: 1rem; font-weight: 700; }
.panel-head p  { font-size: .72rem; color: var(--text-muted); margin-top: .15rem; }

/* ── Left Panel (Form) ── */
.panel-left {
  overflow-y: auto;
}

.panel-left form {
  padding: 0 1.15rem 1.15rem;
  display: flex;
  flex-direction: column;
  gap: .85rem;
}

.field label {
  display: block;
  font-size: .68rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: .3rem;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.field input,
.field select {
  width: 100%;
  padding: .55rem .7rem;
  border: 1.5px solid #dde3ee;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: .88rem;
  color: var(--text);
  background: var(--surface);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

/* ── Button ── */
#run-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  width: 100%;
  padding: .65rem 1rem;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: #fff;
  font-family: var(--font);
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), transform .15s ease, box-shadow var(--transition);
  box-shadow: 0 3px 12px var(--primary-glow);
  margin-top: .25rem;
}

#run-btn:hover:not(:disabled) {
  background: var(--primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 5px 18px var(--primary-glow);
}

#run-btn:active:not(:disabled) { transform: translateY(0); }
#run-btn:disabled { opacity: .6; cursor: not-allowed; }

#run-btn:not(:disabled) { animation: ctaPulse 3s ease-in-out infinite; }
#run-btn:hover:not(:disabled) { animation: none; }

.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2.5px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes ctaPulse {
  0%, 100% { box-shadow: 0 3px 12px var(--primary-glow); }
  50%      { box-shadow: 0 3px 22px rgba(79,110,247,.45); }
}

/* ============================================================
   Center Panel — Architecture Diagram
   ============================================================ */
.panel-center {
  min-width: 0;
}

#arch-container {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

#arch-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
}

#arch-nodes {
  position: absolute;
  inset: 0;
  z-index: 2;
}

/* ── Regular Node ── */
.arch-node {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: .5rem .6rem;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1.5px solid #dde3ee;
  box-shadow: 0 1px 6px rgba(30,40,90,.05);
  transition: border-color .4s ease, box-shadow .4s ease, transform .4s ease, background .4s ease;
  cursor: default;
  overflow: visible;
  box-sizing: border-box;
}

.arch-node .node-icon { font-size: 1.1rem; margin-bottom: .12rem; flex-shrink: 0; }
.arch-node .node-title { font-size: .62rem; font-weight: 700; line-height: 1.25; white-space: nowrap; }
.arch-node .node-sub   { font-size: .52rem; opacity: .65; line-height: 1.25; }

.arch-node .node-status {
  font-size: .52rem;
  color: var(--text-muted);
  margin-top: .2rem;
  min-height: 1.2em;
  line-height: 1.3;
  opacity: 0;
  transition: opacity .3s ease;
  white-space: normal;
  word-break: break-word;
  text-align: center;
}

.arch-node .node-status.visible { opacity: 1; }

/* Tooltip */
.arch-node::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  background: var(--text);
  color: #fff;
  font-size: .62rem;
  padding: .4rem .6rem;
  border-radius: 6px;
  white-space: normal;
  width: max-content;
  max-width: 190px;
  text-align: center;
  pointer-events: none;
  opacity: 0;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 30;
  line-height: 1.35;
}

.arch-node:hover::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Orchestration (Large Hub) ── */
.arch-node.orch-node {
  background: linear-gradient(135deg, #4F6EF7 0%, #6C5CE7 100%);
  border: 2px solid #4F6EF7;
  color: #fff;
  box-shadow: 0 4px 20px var(--primary-glow);
  z-index: 5;
  padding: .65rem .75rem;
}

.arch-node.orch-node .node-icon { font-size: 1.5rem; }
.arch-node.orch-node .node-title { font-size: .82rem; color: #fff; }
.arch-node.orch-node .node-sub   { color: rgba(255,255,255,.75); font-size: .58rem; }
.arch-node.orch-node .node-status { color: rgba(255,255,255,.8); }

/* Active state */
.arch-node.active {
  border-color: var(--primary);
  background: #eef2ff;
  box-shadow: 0 0 0 4px var(--primary-glow), 0 4px 20px var(--primary-glow);
  transform: scale(1.08);
  animation: pulseGlow 1.2s ease infinite;
}

.arch-node.orch-node.active {
  background: linear-gradient(135deg, #3b57d9 0%, #5a4bd6 100%);
  box-shadow: 0 0 0 6px rgba(79,110,247,.3), 0 6px 30px rgba(79,110,247,.4);
  transform: scale(1.06);
  animation: orchPulse 1.2s ease infinite;
}

/* Done state */
.arch-node.done {
  border-color: var(--success);
  background: #ecfdf5;
  box-shadow: 0 0 0 2px rgba(16,185,129,.15);
}

.arch-node.orch-node.done {
  background: linear-gradient(135deg, #059669 0%, #10b981 100%);
  border-color: var(--success);
  box-shadow: 0 0 0 3px rgba(16,185,129,.2), 0 4px 16px rgba(16,185,129,.25);
}

@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 0 0 4px var(--primary-glow), 0 4px 20px var(--primary-glow); }
  50%      { box-shadow: 0 0 0 8px rgba(79,110,247,.15), 0 4px 28px var(--primary-glow); }
}

@keyframes orchPulse {
  0%, 100% { box-shadow: 0 0 0 6px rgba(79,110,247,.3), 0 6px 30px rgba(79,110,247,.4); }
  50%      { box-shadow: 0 0 0 12px rgba(79,110,247,.12), 0 6px 40px rgba(79,110,247,.45); }
}

/* ── SVG Edges ── */
.edge-line {
  stroke: #c8d1e0;
  stroke-width: 1.5;
  fill: none;
  transition: stroke .4s ease, stroke-width .3s ease;
}

.edge-line.active {
  stroke: var(--primary);
  stroke-width: 2;
  filter: drop-shadow(0 0 3px var(--primary-glow));
}

.edge-line.done { stroke: var(--success); }

.edge-particle {
  fill: var(--primary);
  r: 3;
  opacity: 0;
}

.edge-particle.moving { opacity: 1; }

.arrow-marker { fill: #c8d1e0; }

/* ============================================================
   Right Panel — Decision Output
   ============================================================ */
.panel-right {
  overflow-y: auto;
}

/* Placeholder */
#output-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2rem 1.25rem;
  color: var(--text-muted);
}

#output-placeholder .ph-icon { font-size: 2.5rem; margin-bottom: .75rem; opacity: .5; }
#output-placeholder p { font-size: .82rem; line-height: 1.5; max-width: 220px; }

/* Results */
#output-results {
  padding: 0 1rem 1rem;
  display: flex;
  flex-direction: column;
  gap: .75rem;
}

#output-results.hidden { display: none; }

.result-card {
  background: var(--surface);
  border: 1.5px solid #e5e9f2;
  border-radius: var(--radius-sm);
  padding: .85rem;
  text-align: center;
  transition: border-color var(--transition);
}

.result-card h3 {
  font-size: .65rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  margin-bottom: .35rem;
}

.kpi {
  font-size: 1.55rem;
  font-weight: 800;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}

/* Gauge */
.gauge-wrap { display: flex; flex-direction: column; align-items: center; }
.gauge { width: 110px; height: 65px; }

.gauge-bg {
  fill: none;
  stroke: #e5e9f2;
  stroke-width: 10;
  stroke-linecap: round;
}

.gauge-fill {
  fill: none;
  stroke: var(--success);
  stroke-width: 10;
  stroke-linecap: round;
  stroke-dasharray: 157;
  stroke-dashoffset: 157;
  transition: stroke-dashoffset 1.2s cubic-bezier(.4,0,.2,1), stroke .6s ease;
}

.gauge-label {
  font-size: 1.05rem;
  font-weight: 800;
  margin-top: -.2rem;
}

.result-card.risk-low  { border-color: var(--success); }
.result-card.risk-med  { border-color: var(--warning); }
.result-card.risk-high { border-color: var(--danger); }

/* Reasoning */
.reasoning-box {
  background: #f7f9fc;
  border: 1.5px solid #e5e9f2;
  border-radius: var(--radius-sm);
  padding: .85rem 1rem;
}

.reasoning-box h3 {
  font-size: .65rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  margin-bottom: .55rem;
}

#reasoning-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: .4rem;
}

#reasoning-list li {
  font-size: .76rem;
  color: var(--text);
  padding-left: 1rem;
  position: relative;
  line-height: 1.45;
}

#reasoning-list li::before {
  content: '';
  position: absolute;
  left: 0;
  top: .45em;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--primary);
}

/* ── Utility ── */
.fade-in { animation: fadeIn .5s ease both; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.reveal { animation: slideReveal .5s cubic-bezier(.4,0,.2,1) both; }

@keyframes slideReveal {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Scrollbar ── */
.panel-left::-webkit-scrollbar,
.panel-right::-webkit-scrollbar {
  width: 4px;
}

.panel-left::-webkit-scrollbar-track,
.panel-right::-webkit-scrollbar-track {
  background: transparent;
}

.panel-left::-webkit-scrollbar-thumb,
.panel-right::-webkit-scrollbar-thumb {
  background: #d0d5e0;
  border-radius: 4px;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (min-width: 1200px) {
  .header-flow { display: block; }
}

@media (max-width: 1100px) {
  .app-layout { grid-template-columns: 230px 1fr 250px; }
}

@media (max-width: 900px) {
  body { overflow: auto; }
  .app-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(500px, 60vh) auto;
    height: auto;
    padding: .75rem;
  }
  .panel-left form { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
  #run-btn { grid-column: 1 / -1; }
  #arch-container { min-height: 480px; }
}

@media (max-width: 520px) {
  .panel-left form { grid-template-columns: 1fr; }
  .app-layout { gap: .6rem; }
}
