/* ========== SECTION: CSS Base ========== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #FAFAF5;
  --sidebar-bg: #0f172a;
  --sidebar-text: #cbd5e1;
  --sidebar-hover: rgba(255,255,255,.08);
  --sidebar-active: rgba(79,70,229,.25);
  --code-bg: #1A1A1A;
  --primary: #4F46E5;
  --primary-hover: #4338CA;
  --primary-light: rgba(79,70,229,.08);
  --success: #15803d;
  --success-bg: #f0fdf4;
  --warning: #b45309;
  --warning-bg: #fffbeb;
  --error: #b91c1c;
  --error-bg: #fef2f2;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --border-hover: #cbd5e1;
  --radius: 6px;
  --radius-lg: 10px;
  --shadow-sm: 0 1px 3px rgba(15,23,42,.06), 0 1px 2px rgba(15,23,42,.04);
  --shadow-md: 0 4px 12px rgba(15,23,42,.08), 0 2px 4px rgba(15,23,42,.04);
  --shadow-lg: 0 10px 25px rgba(15,23,42,.1), 0 4px 10px rgba(15,23,42,.05);
  --font-serif: 'Source Serif 4', 'Noto Serif SC', Georgia, serif;
  --font-sans: 'DM Sans', 'Noto Sans SC', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
}
body { font-family: var(--font-sans); font-size: 14px; color: var(--text); background: var(--bg); height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
code, pre, .mono { font-family: var(--font-mono); }
h1, h2, h3, .logo, .verdict-title { font-family: var(--font-serif); }

/* ========== SECTION: Layout ========== */
#topbar { height: 52px; background: var(--sidebar-bg); border-bottom: none; display: flex; align-items: center; padding: 0 20px; gap: 16px; flex-shrink: 0; z-index: 100; }
#topbar .logo { font-weight: 600; font-size: 16px; color: #f8fafc; letter-spacing: .3px; }
#stepper { display: flex; align-items: center; gap: 0; flex: 1; justify-content: center; }
.step-item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: #94a3b8; cursor: default; transition: color 200ms; }
.step-item.active { color: #e0e7ff; font-weight: 500; }
.step-item.done { color: #86efac; cursor: pointer; }
.step-dot { width: 22px; height: 22px; border-radius: 50%; border: 2px solid #475569; display: flex; align-items: center; justify-content: center; font-size: 10px; background: transparent; color: #94a3b8; flex-shrink: 0; transition: all 200ms; }
.step-item.active .step-dot { border-color: var(--primary); background: var(--primary); color: white; animation: pulse 1.5s infinite; }
.step-item.done .step-dot { border-color: #22c55e; background: #22c55e; color: white; }
.step-line { width: 32px; height: 1px; background: #334155; margin: 0 4px; }
@keyframes pulse { 0%,100%{box-shadow:0 0 0 0 rgba(79,70,229,.4)} 50%{box-shadow:0 0 0 5px rgba(79,70,229,0)} }

#engine-toggle { display: flex; align-items: center; gap: 8px; font-size: 12px; color: #94a3b8; }
.toggle-btn { display: flex; background: rgba(255,255,255,.06); border-radius: 6px; border: 1px solid #334155; overflow: hidden; }
.toggle-btn button { padding: 4px 10px; border: none; background: none; cursor: pointer; font-size: 12px; color: #94a3b8; transition: all 150ms; }
.toggle-btn button.active { background: var(--primary); color: white; }

#main-layout { display: flex; flex: 1; overflow: hidden; }
#sidebar { width: 210px; background: var(--sidebar-bg); border-right: none; display: flex; flex-direction: column; overflow-y: auto; flex-shrink: 0; padding: 14px 0; }
#content { flex: 1; display: flex; flex-direction: column; overflow: hidden; background: var(--bg); }
#chat-area { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 14px; }
#bottom-bar { border-top: 1px solid var(--border); padding: 14px 20px; background: white; display: flex; gap: 8px; align-items: flex-end; box-shadow: 0 -2px 8px rgba(15,23,42,.04); }
#canvas-panel { width: 0; background: white; border-left: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; transition: width 300ms ease; flex-shrink: 0; }
#canvas-panel.open { width: 480px; }

/* ========== SECTION: Sidebar ========== */
.sidebar-section { padding: 10px 16px 6px; font-size: 10px; font-weight: 600; color: #475569; text-transform: uppercase; letter-spacing: .8px; }
.sidebar-item { padding: 8px 16px; font-size: 13px; color: var(--sidebar-text); cursor: pointer; display: flex; align-items: center; gap: 10px; border-radius: 0; margin: 1px 0; transition: all 150ms; }
.sidebar-item:hover { background: var(--sidebar-hover); color: #f1f5f9; }
.sidebar-item.active { color: #e0e7ff; background: var(--sidebar-active); border-right: 2px solid var(--primary); }
.sidebar-item .step-status { margin-left: auto; font-size: 11px; }
.sidebar-item i[data-lucide] { opacity: .7; }
.sidebar-divider { height: 1px; background: #1e293b; margin: 10px 0; }

/* ========== SECTION: Cards & Buttons ========== */
.card { background: white; border: none; border-radius: var(--radius-lg); padding: 18px; box-shadow: var(--shadow-sm); transition: box-shadow 200ms; }
.card:hover { box-shadow: var(--shadow-md); }
.card.error { box-shadow: 0 0 0 1px var(--error), var(--shadow-sm); background: var(--error-bg); }
.card.warning { box-shadow: 0 0 0 1px var(--warning), var(--shadow-sm); background: var(--warning-bg); }
.card.success { box-shadow: 0 0 0 1px var(--success), var(--shadow-sm); background: var(--success-bg); }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 0 16px; height: 36px; border-radius: var(--radius); border: 1px solid transparent; cursor: pointer; font-size: 13px; font-weight: 500; font-family: var(--font-sans); transition: all 150ms; white-space: nowrap; }
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary { background: var(--primary); color: white; border-color: var(--primary); box-shadow: 0 1px 3px rgba(79,70,229,.3); }
.btn-primary:hover { background: var(--primary-hover); box-shadow: 0 2px 6px rgba(79,70,229,.35); }
.btn-secondary { background: white; color: var(--text); border-color: var(--border); box-shadow: var(--shadow-sm); }
.btn-secondary:hover { border-color: var(--border-hover); background: #f8fafc; }
.btn-danger { background: white; color: var(--error); border-color: var(--border); }
.btn-danger:hover { border-color: var(--error); background: var(--error-bg); }
.btn-sm { height: 28px; padding: 0 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

/* ========== SECTION: Chat ========== */
.msg-agent { max-width: 85%; align-self: flex-start; margin-bottom: 16px; }
.msg-user { max-width: 85%; align-self: flex-end; margin-bottom: 16px; }
.msg-bubble { padding: 14px 16px; border-radius: var(--radius-lg); line-height: 1.7; }
.msg-agent .msg-bubble { background: white; border: none; box-shadow: var(--shadow-sm); }
.msg-user .msg-bubble { background: linear-gradient(135deg, var(--primary), #6366f1); color: white; box-shadow: 0 2px 8px rgba(79,70,229,.25); }
.msg-label { font-size: 11px; color: var(--text-muted); margin-bottom: 4px; font-weight: 500; }

/* ========== SECTION: Step Cards ========== */
.step-card { border: none; border-radius: var(--radius-lg); overflow: hidden; background: white; box-shadow: var(--shadow-sm); transition: box-shadow 200ms, transform 200ms; }
.step-card:hover { box-shadow: var(--shadow-md); }
.step-card.running { box-shadow: 0 0 0 2px var(--primary), var(--shadow-md); animation: border-pulse 1.5s infinite; }
.step-card.done { box-shadow: 0 0 0 1px var(--success), var(--shadow-sm); }
.step-card.error { box-shadow: 0 0 0 1px var(--error), var(--shadow-sm); }
.step-card.warning { box-shadow: 0 0 0 1px var(--warning), var(--shadow-sm); }
.step-card.skipped { opacity: .5; border: 1px dashed var(--border); box-shadow: none; }
@keyframes border-pulse { 0%,100%{box-shadow:0 0 0 2px var(--primary), var(--shadow-md)} 50%{box-shadow:0 0 0 2px #a5b4fc, var(--shadow-md)} }

.step-card-header { display: flex; align-items: center; gap: 10px; padding: 12px 16px; cursor: pointer; }
.step-num { width: 26px; height: 26px; border-radius: 50%; background: #f1f5f9; border: none; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 600; flex-shrink: 0; color: var(--text-muted); transition: all 200ms; }
.step-card.running .step-num { background: var(--primary); color: white; }
.step-card.done .step-num { background: var(--success); color: white; }
.step-card.error .step-num { background: var(--error); color: white; }
.step-title { flex: 1; font-weight: 500; font-size: 13px; }
.step-method-tag { font-size: 11px; padding: 2px 8px; border-radius: 4px; background: var(--primary-light); color: var(--primary); font-weight: 500; }
.step-actions { display: flex; gap: 6px; margin-left: auto; }
.step-card-body { padding: 14px 16px; border-top: 1px solid var(--border); display: none; }
.step-card-body.open { display: block; }

/* ========== SECTION: Log ========== */
.log-block { background: var(--code-bg); color: #E5E7EB; border-radius: var(--radius); padding: 12px 14px; font-size: 12px; line-height: 1.6; max-height: 200px; overflow-y: auto; white-space: pre-wrap; word-break: break-all; }
.insight-card { margin-top: 10px; padding: 12px 14px; background: #f8fafc; border-radius: var(--radius-lg); border-left: 3px solid var(--primary); font-size: 13px; line-height: 1.6; box-shadow: var(--shadow-sm); }
.insight-card.warning { border-left-color: var(--warning); background: var(--warning-bg); }
.insight-card.error { border-left-color: var(--error); background: var(--error-bg); }
.metrics-row { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.metric-chip { padding: 4px 10px; background: white; border: 1px solid var(--border); border-radius: 6px; font-size: 12px; box-shadow: var(--shadow-sm); }
.metric-chip span { font-weight: 600; color: var(--primary); }

/* ========== SECTION: Canvas ========== */
#canvas-panel .canvas-header { display: flex; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); gap: 8px; }
#canvas-panel .canvas-header .canvas-title { font-weight: 500; font-size: 13px; flex: 1; }
.canvas-tabs { display: flex; border-bottom: 1px solid var(--border); }
.canvas-tab { padding: 10px 16px; font-size: 12px; cursor: pointer; color: var(--text-muted); border-bottom: 2px solid transparent; transition: all 150ms; font-weight: 500; }
.canvas-tab:hover { color: var(--text); }
.canvas-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.canvas-body { flex: 1; overflow-y: auto; padding: 16px; }

/* ========== SECTION: Upload ========== */
#upload-zone { border: 2px dashed var(--border); border-radius: var(--radius-lg); padding: 52px 24px; text-align: center; cursor: pointer; transition: all 200ms; background: white; }
#upload-zone:hover, #upload-zone.dragover { border-color: var(--primary); background: var(--primary-light); }
#upload-zone p { color: var(--text-muted); font-size: 13px; margin-top: 6px; }

/* ========== SECTION: Form ========== */
.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: 12px; font-weight: 500; color: var(--text-muted); margin-bottom: 5px; }
.form-input, .form-select, .form-textarea { width: 100%; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 13px; font-family: var(--font-sans); background: white; color: var(--text); outline: none; transition: border 150ms, box-shadow 150ms; }
.form-input:focus, .form-select:focus, .form-textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.1); }
.form-textarea { resize: vertical; min-height: 72px; }
.form-row { display: flex; gap: 10px; }
.form-row .form-group { flex: 1; }

/* ========== SECTION: Misc ========== */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 5px; font-size: 11px; font-weight: 500; }
.badge-success { background: rgba(21,128,61,.08); color: var(--success); }
.badge-warning { background: rgba(180,83,9,.08); color: var(--warning); }
.badge-error { background: rgba(185,28,28,.08); color: var(--error); }
.badge-info { background: var(--primary-light); color: var(--primary); }
.badge-gray { background: #f1f5f9; color: var(--text-muted); }

.toast-container { position: fixed; top: 16px; right: 16px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 12px 16px; border-radius: var(--radius-lg); font-size: 13px; background: var(--text); color: white; box-shadow: var(--shadow-lg); animation: toast-in 200ms ease; max-width: 340px; }
.toast.success { background: var(--success); }
.toast.error { background: var(--error); }
.toast.warning { background: var(--warning); color: white; }
@keyframes toast-in { from{opacity:0;transform:translateY(-8px)} to{opacity:1;transform:translateY(0)} }

.spinner { width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to{transform:rotate(360deg)} }
@keyframes fadeIn { from{opacity:0;transform:translateY(6px)} to{opacity:1;transform:translateY(0)} }

/* ========== SECTION: Shimmer typing indicator ========== */
.typing-dots { display: inline-flex; gap: 4px; align-items: center; padding: 2px 0; }
.typing-dots .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border-hover); animation: shimmer-dot 1.4s ease-in-out infinite; }
.typing-dots .dot:nth-child(2) { animation-delay: .2s; }
.typing-dots .dot:nth-child(3) { animation-delay: .4s; }
@keyframes shimmer-dot {
  0%, 80%, 100% { background: var(--border-hover); transform: scale(1); box-shadow: none; }
  40% { background: var(--primary); transform: scale(1.15); box-shadow: 0 0 8px rgba(79,70,229,.35); }
}

.divider { height: 1px; background: var(--border); margin: 16px 0; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 12px; }
.flex { display: flex; }
.items-center { align-items: center; }
.gap-8 { gap: 8px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }

/* ========== SECTION: Login ========== */
#login-screen { position: fixed; inset: 0; background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.login-card { background: white; border: none; border-radius: 14px; padding: 36px; width: 380px; box-shadow: var(--shadow-lg); }
.login-card h2 { font-size: 20px; margin-bottom: 6px; color: var(--text); }
.login-card p { color: var(--text-muted); font-size: 13px; margin-bottom: 24px; }

/* ========== SECTION: Report ========== */
.verdict-card { padding: 24px; border-radius: var(--radius-lg); margin-bottom: 16px; box-shadow: var(--shadow-sm); }
.verdict-card.green { background: var(--success-bg); border: 1px solid #86EFAC; }
.verdict-card.orange { background: var(--warning-bg); border: 1px solid #FCD34D; }
.verdict-card.red { background: var(--error-bg); border: 1px solid #FCA5A5; }
.verdict-title { font-size: 20px; font-weight: 600; margin-bottom: 6px; }
.finding-card { padding: 16px; border: none; border-radius: var(--radius-lg); display: flex; gap: 12px; align-items: flex-start; box-shadow: var(--shadow-sm); background: white; transition: box-shadow 200ms; }
.finding-card:hover { box-shadow: var(--shadow-md); }
.finding-icon { font-size: 20px; flex-shrink: 0; color: var(--primary); }
.finding-value { font-size: 15px; font-weight: 600; color: var(--primary); }
.finding-interp { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.findings-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }

/* Network banner */
#network-banner { display: none; background: var(--error); color: white; text-align: center; padding: 8px; font-size: 13px; }
#network-banner.show { display: block; }

/* Pro badge */
.pro-tag { display:inline-block; background:#7c3aed; color:white; font-size:10px; font-weight:700; padding:2px 6px; border-radius:4px; margin-left:4px; vertical-align:middle; letter-spacing:.3px; }
.pro-section { border:none; border-radius:var(--radius-lg); padding:14px; margin-top:10px; background:rgba(124,58,237,.04); box-shadow: inset 0 0 0 1px rgba(124,58,237,.12); }
.pro-section .pro-section-title { font-weight:500; font-size:13px; color:#7c3aed; margin-bottom:10px; }
#mode-toggle { display:flex; align-items:center; gap:6px; color:#94a3b8; }

/* Heatmap */
.heatmap-cell { display:inline-block; width:14px; height:14px; border-radius:3px; margin:1px; }

/* Demo cards */
.demo-cards { display:grid; grid-template-columns:repeat(3,1fr); gap:12px; margin-top:16px; }
.demo-card { border:none; border-radius:var(--radius-lg); padding:14px; cursor:pointer; transition:all 200ms; background:white; box-shadow:var(--shadow-sm); }
.demo-card:hover { box-shadow:var(--shadow-md); transform:translateY(-2px); }
.demo-card-title { font-weight:500; font-size:13px; margin-bottom:4px; display:flex; align-items:center; gap:6px; }
.demo-card-desc { font-size:12px; color:var(--text-muted); }

/* ========== SECTION: Editable step cards ========== */
.step-edit-input { width:100%; padding:6px 10px; border:1px solid var(--primary); border-radius:var(--radius); font-size:13px; font-family:var(--font-sans); margin-bottom:4px; }
.step-card[draggable="true"] { cursor:grab; }
.step-card.drag-over { border-top:3px solid var(--primary); }

/* ========== SECTION: Module checkboxes ========== */
.module-checkbox { display:flex; align-items:flex-start; gap:8px; padding:10px 14px; border:none; border-radius:var(--radius-lg); margin-bottom:8px; cursor:pointer; transition:all 150ms; background:white; box-shadow:var(--shadow-sm); }
.module-checkbox:hover { box-shadow:var(--shadow-md); }
.module-checkbox.checked { box-shadow:0 0 0 2px var(--primary), var(--shadow-sm); background:var(--primary-light); }
.module-checkbox input[type="checkbox"] { margin-top:2px; accent-color:var(--primary); }
.module-sub { margin-left:28px; padding:4px 0; }

/* ========== SECTION: Diagnosis ========== */
.diag-card { border:none; border-radius:var(--radius-lg); padding:18px; margin-bottom:12px; box-shadow:var(--shadow-sm); background:white; }
.diag-card.overall-sig { box-shadow:0 0 0 1px var(--success), var(--shadow-sm); background:var(--success-bg); }
.diag-card.overall-insig { box-shadow:0 0 0 1px var(--warning), var(--shadow-sm); background:var(--warning-bg); }
.accordion-item { border:none; border-radius:var(--radius); margin-bottom:8px; overflow:hidden; box-shadow:var(--shadow-sm); }
.accordion-header { display:flex; align-items:center; gap:8px; padding:10px 14px; cursor:pointer; background:#f8fafc; transition:background 150ms; }
.accordion-header:hover { background:#f1f5f9; }
.accordion-body { padding:14px; border-top:1px solid var(--border); display:none; }
.accordion-body.open { display:block; }

/* ========== SECTION: User badge in topbar ========== */
#user-badge { background:rgba(255,255,255,.1); color:#cbd5e1; border:1px solid #334155; }
#user-badge:hover { background:rgba(255,255,255,.15); color:#f1f5f9; }

/* Lucide icon alignment */
[data-lucide] { vertical-align: middle; }
