:root {
  --primary: #4a3f8a;
  --primary-light: #6c5eb5;
  --primary-dark: #2d2660;
  --accent: #e8a838;
  --accent-warm: #d4763c;
  --bg: #f4f3f8;
  --card: #ffffff;
  --text: #2c2c3e;
  --text-muted: #6b6b80;
  --border: #e0dfe8;
  --green: #22a867;
  --amber: #e8a838;
  --red: #d44040;
  --blue: #3b82f6;
  --tag-bg: #edeaff;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Segoe UI', system-ui, -apple-system, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }

/* Top Nav */
.topnav {
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  color: white; display: flex; align-items: center; padding: 0 16px; height: 38px; gap: 0;
}
.topnav .brand { font-weight: 700; font-size: 15px; letter-spacing: .5px; margin-right: 24px; white-space: nowrap; cursor: pointer; }
.topnav .brand span { color: var(--accent); }
.topnav nav { display: flex; gap: 0; height: 100%; }
.topnav nav a {
  color: rgba(255,255,255,.7); text-decoration: none; padding: 0 12px; height: 100%;
  display: flex; align-items: center; font-size: 12px; font-weight: 500;
  border-bottom: 2px solid transparent; transition: all .15s; cursor: pointer;
}
.topnav nav a:hover { color: white; background: rgba(255,255,255,.08); }
.topnav nav a.active { color: white; border-bottom-color: var(--accent); background: rgba(255,255,255,.06); }

/* Page container */
.page { display: none; }
.page.active { display: block; }

/* CRUD page styles */
.crud-page { padding: 20px; max-width: 1400px; }
.crud-page h2 { font-size: 18px; font-weight: 800; color: var(--primary-dark); margin-bottom: 4px; }
.crud-page .page-desc { color: var(--text-muted); font-size: 12px; margin-bottom: 16px; }
.crud-toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.crud-toolbar input[type="search"] { padding: 5px 10px; border: 1px solid var(--border); border-radius: 4px; font-size: 12px; min-width: 200px; }

.btn { padding: 5px 14px; border: none; border-radius: 4px; font-size: 12px; font-weight: 600; cursor: pointer; transition: all .15s; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-light); }
.btn-danger { background: var(--red); color: white; }
.btn-danger:hover { opacity: .85; }
.btn-sm { padding: 3px 8px; font-size: 11px; }
.btn-outline { background: white; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: #f8f7fc; }
.btn-success { background: var(--green); color: white; }
.btn-success:hover { opacity: .85; }
.btn-amber { background: var(--amber); color: white; }
.btn-amber:hover { opacity: .85; }

.crud-table { width: 100%; border-collapse: collapse; background: white; border-radius: 6px; overflow: hidden; border: 1px solid var(--border); }
.crud-table th {
  text-align: left; padding: 8px 12px; font-size: 11px; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: .5px; background: #f8f7fc; border-bottom: 1px solid var(--border);
}
.crud-table td { padding: 7px 12px; font-size: 13px; border-bottom: 1px solid #f0eff5; }
.crud-table tr:hover td { background: #faf9ff; }
.crud-table .actions { white-space: nowrap; }
.crud-table .actions .btn { margin-left: 4px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.badge-green { background: #e6f7ee; color: var(--green); }
.badge-amber { background: #fff4de; color: #a67000; }
.badge-red { background: #fde8e8; color: var(--red); }
.badge-blue { background: #e8f0fe; color: var(--blue); }
.badge-gray { background: #f0f0f0; color: var(--text-muted); }

/* Modal */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 1000; align-items: center; justify-content: center; }
.modal-overlay.open { display: flex; }
.modal { background: white; border-radius: 8px; padding: 20px; min-width: 500px; max-width: 700px; max-height: 80vh; overflow-y: auto; box-shadow: 0 8px 30px rgba(0,0,0,.2); }
.modal:has(.playbook-content) { max-width: 900px; }
.playbook-content { font-size: 13px; line-height: 1.7; }
.playbook-content h1 { font-size: 18px; margin: 0 0 12px; }
.playbook-content h2 { font-size: 15px; margin: 20px 0 8px; border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.playbook-content h3 { font-size: 13px; margin: 16px 0 6px; color: var(--primary); }
.playbook-content ul, .playbook-content ol { margin: 8px 0; padding-left: 20px; }
.playbook-content li { margin-bottom: 4px; }
.playbook-content table { width: 100%; border-collapse: collapse; margin: 12px 0; font-size: 12px; }
.playbook-content th { background: var(--bg); font-weight: 600; text-align: left; padding: 6px 8px; border: 1px solid var(--border); }
.playbook-content td { padding: 6px 8px; border: 1px solid var(--border); }
.playbook-content blockquote { border-left: 3px solid var(--primary); margin: 12px 0; padding: 8px 12px; background: var(--bg); }
.playbook-content code { background: var(--bg); padding: 1px 4px; border-radius: 3px; font-size: 12px; }
.playbook-content pre { background: var(--bg); padding: 12px; border-radius: 6px; overflow-x: auto; }
.playbook-content p { margin: 8px 0; }
.playbook-content .mermaid { margin: 16px 0; background: var(--bg); border-radius: 6px; padding: 16px; overflow-x: auto; }
.playbook-content .mermaid svg { max-width: 100%; height: auto; }
.modal h3 { font-size: 16px; font-weight: 700; color: var(--primary-dark); margin-bottom: 16px; }
.modal label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 4px; margin-top: 12px; }
.modal input, .modal select, .modal textarea { width: 100%; padding: 6px 10px; border: 1px solid var(--border); border-radius: 4px; font-size: 13px; font-family: inherit; }
.modal textarea { min-height: 80px; resize: vertical; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }

/* Status indicators */
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.status-dot.active { background: var(--green); }
.status-dot.paused { background: var(--amber); }
.status-dot.archived { background: var(--text-muted); }

/* Dashboard / FRIMB analysis page */
.frimb-subtitle { background: white; border-bottom: 1px solid var(--border); padding: 10px 20px 0 20px; }
.frimb-subtitle h1 { font-size: 18px; font-weight: 800; color: var(--primary-dark); letter-spacing: -.3px; }
.frimb-subtitle p { color: var(--text-muted); font-size: 12px; margin-top: 1px; }

.frimb-tabs { background: white; border-bottom: 1px solid var(--border); display: flex; padding: 0 20px; gap: 0; margin-top: 6px; }
.frimb-tabs button {
  background: none; border: none; padding: 7px 14px; font-size: 12px; font-weight: 500;
  color: var(--text-muted); cursor: pointer; border-bottom: 2px solid transparent; transition: all .15s;
}
.frimb-tabs button:hover { color: var(--primary); }
.frimb-tabs button.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

.frimb-controls {
  display: flex; align-items: center; gap: 12px; padding: 6px 20px; background: white; border-bottom: 1px solid var(--border);
}
.frimb-controls select, .frimb-controls input {
  padding: 4px 8px; border: 1px solid var(--border); border-radius: 4px; font-size: 12px; background: white;
}
.frimb-controls select { min-width: 140px; }
.frimb-controls .spacer { flex: 1; }
.frimb-controls label { font-size: 11px; color: var(--text-muted); font-weight: 500; }

.hint-bar { padding: 4px 20px; font-size: 11px; color: var(--text-muted); background: #faf9ff; border-bottom: 1px solid var(--border); }

.frimb-main { display: flex; height: calc(100vh - 185px); overflow: hidden; }

/* Question list */
.q-list { width: 420px; min-width: 350px; border-right: 1px solid var(--border); overflow-y: auto; background: white; }
.q-list table { width: 100%; border-collapse: collapse; }
.q-list th {
  position: sticky; top: 0; background: #f8f7fc; text-align: left; padding: 8px 12px;
  font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px;
  border-bottom: 1px solid var(--border);
}
.q-list td { padding: 8px 12px; border-bottom: 1px solid #f0eff5; font-size: 13px; cursor: pointer; }
.q-list tr:hover td { background: #f8f7fc; }
.q-list tr.selected td { background: var(--tag-bg); }
.q-list .q-num { color: var(--primary); font-weight: 600; width: 40px; font-size: 12px; }
.q-list .q-text { color: var(--text); line-height: 1.4; }
.q-list .q-cluster { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

/* Detail panel */
.detail-panel { flex: 1; overflow-y: auto; padding: 20px; background: var(--bg); }

.intel-card {
  background: var(--card); border-radius: 10px; box-shadow: 0 2px 12px rgba(0,0,0,.06);
  border: 1px solid var(--border); max-width: 780px; margin: 0 auto;
}
.intel-header { padding: 16px 20px; border-bottom: 1px solid var(--border); }
.intel-header .query-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 4px; }
.intel-header h2 { font-size: 15px; font-weight: 700; color: var(--primary-dark); }
.intel-meta { display: flex; gap: 12px; margin-top: 8px; flex-wrap: wrap; }
.meta-tag {
  display: inline-flex; align-items: center; gap: 6px; background: var(--tag-bg);
  padding: 3px 10px; border-radius: 20px; font-size: 11px; color: var(--primary); font-weight: 500;
}
.meta-tag.cluster { background: #e6f7ee; color: var(--green); }

/* RAG scores */
.rag-section { padding: 16px 20px; border-bottom: 1px solid var(--border); }
.rag-section h3 { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; margin-bottom: 10px; }
.rag-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.rag-box { border: 1px solid var(--border); border-radius: 8px; padding: 12px; background: #faf9ff; }
.rag-box.on { border-left: 4px solid var(--green); }
.rag-box.off { border-left: 4px solid var(--amber); }
.rag-box .rag-title { font-size: 11px; font-weight: 600; color: var(--text-muted); margin-bottom: 4px; }
.rag-box .rag-score { font-size: 22px; font-weight: 700; margin-bottom: 6px; }
.rag-box .rag-score.green { color: var(--green); }
.rag-box .rag-score.amber { color: var(--amber); }
.rag-box .rag-score.red { color: var(--red); }
.rag-box .rag-score.none { color: var(--text-muted); }
.model-row { display: flex; justify-content: space-between; font-size: 12px; padding: 2px 0; }
.model-score { font-weight: 600; }
.model-score.high { color: var(--green); }
.model-score.mid { color: var(--amber); }
.model-score.low { color: var(--red); }

/* Injections in detail */
.inj-section { padding: 16px 20px; border-bottom: 1px solid var(--border); }
.inj-section h3 { font-size: 12px; font-weight: 700; color: var(--accent-warm); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 10px; }
.inj-card { border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin-bottom: 10px; background: white; }
.inj-card .inj-title { font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.inj-card .inj-meta { font-size: 11px; color: var(--text-muted); margin-bottom: 6px; }
.inj-card .inj-body { font-size: 12px; color: var(--text-muted); line-height: 1.5; }

/* Empty state */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; color: var(--text-muted); text-align: center; padding: 40px;
}
.empty-state .empty-icon { font-size: 48px; margin-bottom: 16px; opacity: .4; }
.empty-state h3 { font-size: 16px; margin-bottom: 8px; color: var(--text); }
.empty-state p { font-size: 13px; max-width: 320px; }

/* Heatmap */
.heatmap-col {
  width: 280px; min-width: 280px; border-left: 1px solid var(--border); background: white;
  overflow-y: auto; overflow-x: hidden; padding: 0;
}
.heatmap-col .hm-header {
  position: sticky; top: 0; background: #f8f7fc; padding: 8px 6px;
  font-size: 10px; font-weight: 600; color: var(--text-muted); border-bottom: 1px solid var(--border);
  display: flex; gap: 0;
}
.heatmap-col .hm-header span {
  flex: 1; text-align: center; writing-mode: vertical-lr; transform: rotate(180deg);
  height: 52px; display: flex; align-items: center; justify-content: center;
}
.heatmap-row { display: flex; padding: 6px 6px; border-bottom: 1px solid #f5f4fa; align-items: center; min-height: 34px; }
.heatmap-row .hm-cell { flex: 1; display: flex; gap: 2px; justify-content: center; flex-wrap: wrap; }
.hm-dot { width: 7px; height: 7px; border-radius: 50%; }
.hm-dot.g { background: var(--green); }
.hm-dot.a { background: var(--amber); }
.hm-dot.r { background: var(--red); }
.hm-dot.empty { background: #e8e7ef; }

/* Run progress */
.run-progress { padding: 16px 20px; background: white; border: 1px solid var(--border); border-radius: 8px; margin: 12px 20px; }
.run-progress h3 { font-size: 14px; font-weight: 700; margin-bottom: 8px; }
.progress-bar { height: 8px; background: var(--border); border-radius: 4px; overflow: hidden; margin-bottom: 8px; }
.progress-bar .fill { height: 100%; background: var(--primary); transition: width .3s; border-radius: 4px; }
.run-log { font-size: 11px; color: var(--text-muted); max-height: 200px; overflow-y: auto; font-family: 'Consolas', monospace; }
.run-log .log-entry { padding: 2px 0; }
.run-log .log-error { color: var(--red); }
.run-log .log-success { color: var(--green); }

/* Toast */
.toast { position: fixed; bottom: 20px; right: 20px; padding: 10px 16px; border-radius: 6px; font-size: 13px; font-weight: 500; color: white; z-index: 2000; opacity: 0; transition: opacity .3s; }
.toast.show { opacity: 1; }
.toast.success { background: var(--green); }
.toast.error { background: var(--red); }
