:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --sidebar: #0d1729;
  --sidebar-soft: #17243a;
  --text: #172033;
  --muted: #68748a;
  --border: #e3e9f2;
  --primary: #d92d4f;
  --primary-dark: #ad1737;
  --primary-soft: #fff0f3;
  --blue: #2563eb;
  --teal: #0f9b8e;
  --amber: #d88716;
  --danger: #c72a3c;
  --shadow: 0 18px 50px rgba(26, 39, 66, .10);
  --radius-lg: 24px;
  --radius-md: 16px;
  --radius-sm: 12px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
button, input, textarea { font: inherit; }
button { cursor: pointer; }

body.dark {
  --bg: #0c1422;
  --surface: #111d30;
  --surface-soft: #17243a;
  --text: #edf3ff;
  --muted: #a8b3c7;
  --border: #263650;
  --primary-soft: #321726;
  --shadow: 0 18px 50px rgba(0, 0, 0, .24);
}

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 280px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 28px 22px; background: linear-gradient(180deg, #0d1729 0%, #0a1221 100%); color: #fff; display: flex; flex-direction: column; gap: 26px; }
.brand { display: flex; align-items: center; gap: 13px; padding: 0 6px; }
.brand-mark { width: 46px; height: 46px; border-radius: 15px; background: linear-gradient(145deg, #f34263, #bd1537); display: grid; place-items: center; box-shadow: 0 12px 28px rgba(217, 45, 79, .35); }
.brand-mark svg { width: 28px; fill: white; }
.brand-mark .shine { fill: none; stroke: rgba(255,255,255,.75); stroke-width: 3; stroke-linecap: round; }
.brand strong { display: block; font-size: 17px; letter-spacing: .1px; }
.brand span { display: block; color: #aeb9ca; font-size: 11px; margin-top: 3px; }

.nav { display: grid; gap: 8px; }
.nav-item { border: 0; background: transparent; color: #aeb9ca; border-radius: 14px; padding: 13px 14px; display: flex; align-items: center; gap: 12px; text-align: left; transition: .18s ease; }
.nav-item:hover { color: #fff; background: rgba(255,255,255,.06); }
.nav-item.active { color: #fff; background: linear-gradient(90deg, rgba(217,45,79,.24), rgba(217,45,79,.08)); box-shadow: inset 3px 0 0 var(--primary); }
.nav-icon { width: 24px; height: 24px; display: grid; place-items: center; border-radius: 8px; background: rgba(255,255,255,.07); font-weight: 800; }
.sidebar-card { margin-top: auto; border: 1px solid rgba(255,255,255,.09); background: rgba(255,255,255,.05); border-radius: 16px; padding: 15px; }
.status-row { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: #47d69b; box-shadow: 0 0 0 5px rgba(71,214,155,.12); }
.sidebar-card p, .sidebar-note { margin: 9px 0 0; color: #aeb9ca; line-height: 1.55; font-size: 12px; }
.sidebar-note { padding: 0 5px; }

.main { min-width: 0; padding: 0 34px 34px; }
.topbar { min-height: 98px; display: flex; align-items: center; justify-content: space-between; gap: 24px; border-bottom: 1px solid var(--border); }
.topbar h1 { margin: 0; font-size: clamp(22px, 2vw, 30px); letter-spacing: -.5px; }
.topbar p { margin: 7px 0 0; color: var(--muted); font-size: 14px; }
.top-actions { display: flex; align-items: center; gap: 12px; }
.engine-pill { display: inline-flex; align-items: center; gap: 8px; padding: 9px 12px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--muted); font-size: 12px; box-shadow: 0 8px 25px rgba(31,48,82,.05); }
.engine-pill span { width: 8px; height: 8px; border-radius: 50%; background: #37c58b; }
.icon-button { width: 39px; height: 39px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); }

.tab-panel { display: none; padding-top: 26px; }
.tab-panel.active { display: block; }
.chat-layout { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(330px, .75fr); gap: 22px; height: calc(100vh - 150px); min-height: 610px; }
.chat-card, .insight-panel, .explorer-list-card, .graph-card, .quality-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow); }
.chat-card { display: grid; grid-template-rows: minmax(0,1fr) auto; overflow: hidden; }
.messages { padding: 26px; overflow-y: auto; scroll-behavior: smooth; }
.message { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 22px; }
.message.user { justify-content: flex-end; }
.avatar { flex: 0 0 auto; width: 38px; height: 38px; border-radius: 13px; display: grid; place-items: center; font-weight: 800; font-size: 11px; background: linear-gradient(145deg, var(--primary), var(--primary-dark)); color: white; box-shadow: 0 8px 20px rgba(217,45,79,.22); }
.message.user .avatar { background: #263750; box-shadow: none; }
.bubble { max-width: min(760px, 84%); padding: 16px 18px; border-radius: 6px 19px 19px 19px; background: var(--surface-soft); border: 1px solid var(--border); line-height: 1.65; }
.message.user .bubble { border-radius: 19px 6px 19px 19px; background: linear-gradient(145deg, var(--primary), var(--primary-dark)); color: white; border-color: transparent; }
.bubble h2 { margin: 0 0 6px; font-size: 18px; }
.bubble p { margin: 0; color: var(--muted); }
.message.user .bubble p { color: white; }
.message-text { white-space: pre-wrap; font-size: 14px; }
.message-meta { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; color: var(--muted); font-size: 11px; }
.quick-grid { margin-top: 15px; display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 9px; }
.quick-question { padding: 10px 12px; border-radius: 12px; border: 1px solid var(--border); color: var(--text); background: var(--surface); text-align: left; font-size: 12px; transition: .16s; }
.quick-question:hover { border-color: #f0a6b4; background: var(--primary-soft); transform: translateY(-1px); }
.answer-chips { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 12px; }
.answer-chip { border-radius: 999px; padding: 6px 9px; background: var(--surface); border: 1px solid var(--border); color: var(--muted); font-size: 11px; }
.answer-chip.strong { background: var(--primary-soft); color: var(--primary-dark); border-color: rgba(217,45,79,.2); }
.alternatives { margin-top: 12px; display: grid; gap: 7px; }
.alt-title { color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px; }
.alt-button { width: 100%; border: 1px solid var(--border); border-radius: 11px; padding: 9px 11px; background: var(--surface); color: var(--text); text-align: left; font-size: 12px; }
.alt-button:hover { background: var(--primary-soft); border-color: rgba(217,45,79,.25); }

.composer { border-top: 1px solid var(--border); padding: 16px 20px 13px; background: var(--surface); }
.composer-box { display: grid; grid-template-columns: 1fr 46px; align-items: end; gap: 10px; border: 1px solid var(--border); background: var(--surface-soft); border-radius: 17px; padding: 8px 8px 8px 14px; transition: .16s; }
.composer-box:focus-within { border-color: rgba(217,45,79,.45); box-shadow: 0 0 0 4px rgba(217,45,79,.08); }
.composer textarea { border: 0; outline: 0; resize: none; min-height: 34px; max-height: 130px; background: transparent; color: var(--text); line-height: 1.5; padding: 6px 0; }
.composer button { width: 42px; height: 42px; border: 0; border-radius: 13px; background: linear-gradient(145deg, var(--primary), var(--primary-dark)); display: grid; place-items: center; }
.composer button:disabled { opacity: .55; cursor: wait; }
.composer button svg { width: 20px; fill: white; }
.composer-hint { display: flex; justify-content: space-between; color: var(--muted); font-size: 10px; margin-top: 7px; padding: 0 4px; }

.insight-panel { padding: 22px; overflow-y: auto; }
.panel-header, .section-heading { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.eyebrow { display: block; text-transform: uppercase; letter-spacing: 1px; font-weight: 800; font-size: 10px; color: var(--primary); margin-bottom: 4px; }
.panel-header h3, .section-heading h2 { margin: 0; font-size: 17px; }
.confidence { border-radius: 999px; padding: 7px 9px; font-size: 10px; font-weight: 800; }
.confidence.neutral { color: var(--muted); background: var(--surface-soft); }
.confidence.high { color: #08765f; background: #e8fbf4; }
.confidence.medium { color: #9c5d00; background: #fff5df; }
.confidence.low { color: #a52337; background: #fff0f2; }
.graph-path { margin-top: 20px; display: grid; gap: 8px; }
.graph-step { position: relative; display: grid; grid-template-columns: 34px 1fr; align-items: center; gap: 10px; padding: 10px; border: 1px solid var(--border); border-radius: 13px; background: var(--surface-soft); }
.graph-step:not(:last-child)::after { content: ""; position: absolute; left: 26px; bottom: -9px; height: 9px; border-left: 2px dashed #c8d2e2; }
.graph-step-icon { width: 30px; height: 30px; border-radius: 10px; display: grid; place-items: center; background: #edf3ff; color: var(--blue); font-weight: 900; font-size: 11px; }
.graph-step.decision .graph-step-icon { background: var(--primary-soft); color: var(--primary); }
.graph-step.source .graph-step-icon { background: #e9faf7; color: var(--teal); }
.graph-step span { font-size: 12px; line-height: 1.35; }
.empty-state { min-height: 220px; align-content: center; justify-items: center; color: var(--muted); text-align: center; padding: 20px; }
.empty-icon { font-size: 38px; opacity: .5; }
.empty-state p { max-width: 250px; font-size: 12px; line-height: 1.6; }
.detail-divider { height: 1px; background: var(--border); margin: 22px 0 16px; }
.detail-list { display: grid; gap: 11px; }
.detail-list > div { display: flex; justify-content: space-between; gap: 12px; font-size: 12px; }
.detail-list span { color: var(--muted); }
.detail-list strong { text-align: right; max-width: 62%; }
.source-box { margin-top: 18px; padding: 13px; border-radius: 13px; background: var(--surface-soft); border: 1px solid var(--border); font-size: 11px; line-height: 1.55; }
.hidden { display: none !important; }

.dashboard-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 16px; }
.metric-card { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 18px; box-shadow: var(--shadow); }
.metric-card span { color: var(--muted); font-size: 12px; }
.metric-card strong { display: block; font-size: 30px; margin: 7px 0 3px; letter-spacing: -1px; }
.metric-card small { color: var(--muted); font-size: 10px; }
.explorer-layout { display: grid; grid-template-columns: 390px minmax(0,1fr); gap: 20px; margin-top: 20px; min-height: 610px; }
.explorer-list-card, .graph-card, .quality-card { padding: 20px; }
.search-field { margin-top: 16px; height: 42px; display: flex; align-items: center; gap: 8px; padding: 0 12px; background: var(--surface-soft); border: 1px solid var(--border); border-radius: 13px; }
.search-field input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text); }
.scenario-results { margin-top: 14px; display: grid; gap: 9px; max-height: 520px; overflow: auto; padding-right: 3px; }
.scenario-item { border: 1px solid var(--border); border-radius: 13px; padding: 12px; background: var(--surface-soft); text-align: left; color: var(--text); }
.scenario-item:hover, .scenario-item.active { border-color: rgba(217,45,79,.4); background: var(--primary-soft); }
.scenario-item strong { display: block; font-size: 12px; line-height: 1.45; }
.scenario-item span { display: inline-block; margin-top: 7px; color: var(--muted); font-size: 10px; }
.graph-card { overflow: hidden; }
#graph-svg { width: 100%; height: 520px; margin-top: 6px; background: radial-gradient(circle at center, rgba(37,99,235,.04), transparent 55%); }
.graph-link { stroke: #c7d1e0; stroke-width: 1.4; }
.graph-label { font-size: 10px; fill: var(--muted); pointer-events: none; }
.graph-node circle { stroke: white; stroke-width: 3; filter: drop-shadow(0 5px 8px rgba(34,49,78,.16)); }
.graph-node text { font-size: 10px; fill: var(--text); text-anchor: middle; pointer-events: none; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; color: var(--muted); font-size: 10px; }
.legend span { display: flex; align-items: center; gap: 5px; }
.legend-dot { width: 9px; height: 9px; border-radius: 50%; }
.legend-dot.scenario { background: var(--primary); }
.legend-dot.decision { background: var(--blue); }
.legend-dot.source { background: var(--teal); }
.legend-dot.metadata { background: #91a0b8; }

.evaluation-hero { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 24px; padding: 24px; border-radius: var(--radius-lg); background: linear-gradient(135deg, #111d30, #1e3151); color: white; box-shadow: var(--shadow); }
.evaluation-hero h2 { margin: 0; font-size: 25px; }
.evaluation-hero p { max-width: 820px; color: #c1ccdc; line-height: 1.65; font-size: 13px; }
.grade-ring { width: 112px; height: 112px; border-radius: 50%; border: 10px solid rgba(255,255,255,.14); display: grid; place-content: center; text-align: center; box-shadow: inset 0 0 0 3px rgba(255,255,255,.05); }
.grade-ring strong { font-size: 25px; }
.grade-ring span { font-size: 10px; color: #c1ccdc; }
.evaluation-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 15px; margin-top: 18px; }
.eval-card { background: var(--surface); border: 1px solid var(--border); border-radius: 17px; padding: 17px; box-shadow: var(--shadow); }
.eval-card span { color: var(--muted); font-size: 11px; }
.eval-card strong { display: block; margin: 7px 0; font-size: 25px; }
.eval-card small { color: var(--muted); font-size: 10px; line-height: 1.45; }
.evaluation-lower { display: grid; grid-template-columns: 1.2fr .8fr; gap: 18px; margin-top: 18px; }
.bar-list { display: grid; gap: 12px; margin-top: 18px; }
.bar-row { display: grid; grid-template-columns: minmax(150px, 1fr) 2fr 52px; align-items: center; gap: 10px; font-size: 11px; }
.bar-track { height: 8px; border-radius: 999px; background: var(--surface-soft); overflow: hidden; }
.bar-fill { height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--primary), #f06d86); }
.evaluation-notes { margin-top: 17px; display: grid; gap: 11px; }
.note-item { padding: 12px; border-radius: 13px; border: 1px solid var(--border); background: var(--surface-soft); font-size: 12px; line-height: 1.55; }
.note-item strong { display: block; margin-bottom: 4px; }

.loading-dots { display: inline-flex; gap: 4px; }
.loading-dots i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: pulse 1s infinite; }
.loading-dots i:nth-child(2) { animation-delay: .15s; }
.loading-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes pulse { 0%,100%{opacity:.25;transform:translateY(0)}50%{opacity:1;transform:translateY(-3px)} }

@media (max-width: 1180px) {
  .app-shell { grid-template-columns: 88px minmax(0,1fr); }
  .sidebar { padding: 24px 14px; align-items: center; }
  .brand > div:last-child, .nav-item span:last-child, .sidebar-card, .sidebar-note { display: none; }
  .nav-item { padding: 12px; }
  .chat-layout { grid-template-columns: 1fr; height: auto; }
  .chat-card { min-height: 640px; }
  .insight-panel { min-height: 400px; }
  .explorer-layout { grid-template-columns: 320px 1fr; }
}

@media (max-width: 820px) {
  .app-shell { display: block; }
  .sidebar { position: fixed; z-index: 20; bottom: 0; top: auto; width: 100%; height: 70px; flex-direction: row; justify-content: center; padding: 8px; }
  .brand, .sidebar-card, .sidebar-note { display: none; }
  .nav { display: flex; gap: 6px; }
  .nav-item { flex-direction: column; gap: 2px; padding: 7px 14px; font-size: 9px; }
  .nav-item span:last-child { display: inline; }
  .nav-icon { width: 22px; height: 22px; }
  .main { padding: 0 14px 92px; }
  .topbar { min-height: 82px; }
  .topbar p, .engine-pill { display: none; }
  .dashboard-grid, .evaluation-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .explorer-layout, .evaluation-lower { grid-template-columns: 1fr; }
  .graph-card { min-height: 560px; }
  .quick-grid { grid-template-columns: 1fr; }
  .bubble { max-width: 91%; }
}

@media (max-width: 520px) {
  .topbar h1 { font-size: 20px; }
  .messages { padding: 18px 14px; }
  .composer { padding: 12px; }
  .dashboard-grid, .evaluation-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .metric-card, .eval-card { padding: 14px; }
  .evaluation-hero { grid-template-columns: 1fr; }
  .grade-ring { width: 90px; height: 90px; }
  .bar-row { grid-template-columns: 1fr; gap: 5px; }
}

/* v2 - Data Graph visibility and controls */
.graph-primary-button { border: 0; border-radius: 13px; padding: 10px 15px; background: linear-gradient(135deg, var(--primary), #a7193b); color: #fff; font-weight: 800; display: inline-flex; align-items: center; gap: 8px; box-shadow: 0 8px 22px rgba(217,45,79,.22); cursor: pointer; }
.graph-primary-button:hover { transform: translateY(-1px); box-shadow: 0 11px 28px rgba(217,45,79,.28); }
.graph-primary-icon { font-size: 18px; }
.graph-toolbar { margin-top: 18px; padding: 15px 18px; border: 1px solid var(--border); border-radius: 16px; background: linear-gradient(135deg, rgba(217,45,79,.07), rgba(37,99,235,.05)); display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.graph-toolbar-copy { display: flex; flex-direction: column; gap: 3px; }
.graph-toolbar-copy strong { font-size: 15px; }
.graph-toolbar-copy span { color: var(--muted); font-size: 13px; }
.graph-toolbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.secondary-button { border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 9px 12px; border-radius: 11px; font-weight: 700; cursor: pointer; }
.secondary-button:hover { border-color: var(--primary); color: var(--primary); }
.graph-canvas-wrap { position: relative; min-height: 560px; border-radius: 16px; background: radial-gradient(circle at center, rgba(37,99,235,.06), transparent 58%); overflow: hidden; }
.graph-canvas-wrap:fullscreen { background: var(--surface); padding: 24px; }
.graph-canvas-wrap:fullscreen #graph-svg { width: 100%; height: calc(100vh - 70px); }
.graph-canvas-help { position: absolute; left: 14px; bottom: 10px; padding: 6px 9px; border-radius: 8px; background: rgba(16,24,40,.72); color: #fff; font-size: 11px; pointer-events: none; }
.graph-node { cursor: pointer; }
.graph-node circle { stroke: #fff; stroke-width: 3; filter: drop-shadow(0 5px 8px rgba(16,24,40,.16)); transition: .16s ease; }
.graph-node:hover circle { stroke-width: 5; transform: scale(1.08); }
.graph-node-detail { margin-top: 10px; border-top: 1px solid var(--border); padding-top: 12px; display: flex; gap: 10px; align-items: baseline; min-height: 36px; }
.graph-node-detail span { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
.graph-node-detail strong { font-size: 13px; overflow-wrap: anywhere; }
@media (max-width: 760px) {
  .graph-primary-button span:last-child { display: none; }
  .graph-toolbar { align-items: flex-start; flex-direction: column; }
  .graph-toolbar-actions { width: 100%; }
  .secondary-button { flex: 1; }
}
.status-dot.muted{background:#94a3b8;box-shadow:none}.llm-card{margin-top:12px}.llm-card button{width:100%;margin-top:8px}.settings-dialog{width:min(520px,92vw);border:0;border-radius:22px;padding:0;box-shadow:0 24px 80px rgba(15,23,42,.28);background:var(--surface,#fff);color:inherit}.settings-dialog::backdrop{background:rgba(15,23,42,.56);backdrop-filter:blur(4px)}.settings-dialog form{padding:24px;display:grid;gap:15px}.dialog-head,.dialog-actions,.setting-row{display:flex;align-items:center;justify-content:space-between;gap:12px}.settings-dialog label{display:grid;gap:7px;font-weight:650}.settings-dialog input[type=text],.settings-dialog input:not([type]),.settings-dialog select{width:100%;padding:12px 13px;border:1px solid var(--border,#dbe2ea);border-radius:12px;background:var(--surface,#fff);color:inherit}.settings-dialog p{margin:0;color:var(--muted,#64748b);line-height:1.55}.dialog-actions{justify-content:flex-end;margin-top:5px}.llm-chip{background:#eef2ff;color:#4338ca}.llm-chip.off{background:#f1f5f9;color:#64748b}
/* Production public mode: only expose the chatbot. Internal graph/evaluation tools stay server-side. */
.nav-item[data-tab="graph"],
.nav-item[data-tab="evaluation"],
.llm-card,
#open-graph-button,
#tab-graph,
#tab-evaluation,
#llm-dialog { display: none !important; }
