/* Enterprise AI Advisor - chat application.
   Tokens are shared with the public site (site.css): TBC navy #102B4B, action blue #007AFF, ink #292D32.
   Dark mode follows the system unless the visitor picked one (html[data-theme]). */
:root {
  --navy: #102B4B; --blue: #007AFF; --blue-ink: #034EA0; --blue-soft: #E8F1FF;
  --bg: #EDEEF3; --panel: #ffffff; --panel-2: #F6F7FA; --ink: #292D32; --muted: #919EB6; --slate: #647697;
  --line: #CED3DE; --line-soft: #E4E8EF;
  --brand: var(--navy); --brand-2: var(--blue); --accent: var(--blue); --warn: #C2410C; --ok: #00984A;
  --user: var(--blue-soft); --assist: #ffffff; --radius: 14px; --radius-sm: 8px;
  --display: "Exo 2", "Segoe UI", system-ui, sans-serif;
  --shadow-sm: 0 1px 2px rgba(16, 43, 75, .06), 0 2px 8px rgba(16, 43, 75, .05);
  --shadow: 0 2px 6px rgba(16, 43, 75, .06), 0 12px 32px rgba(16, 43, 75, .10);
  font-family: "Segoe UI", system-ui, -apple-system, "Noto Sans", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --bg: #0B1724; --panel: #112034; --panel-2: #0E1B2D; --ink: #E7ECF3; --muted: #8494AC; --slate: #A9B6CA;
    --line: #22344C; --line-soft: #1B2A3D; --user: #14283F; --assist: #112034; --blue-soft: #14283F;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.4); --shadow: 0 12px 32px rgba(0,0,0,.45); color-scheme: dark; }
}
:root[data-theme="dark"] { --bg: #0B1724; --panel: #112034; --panel-2: #0E1B2D; --ink: #E7ECF3; --muted: #8494AC; --slate: #A9B6CA;
  --line: #22344C; --line-soft: #1B2A3D; --user: #14283F; --assist: #112034; --blue-soft: #14283F;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4); --shadow: 0 12px 32px rgba(0,0,0,.45); color-scheme: dark; }

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
body { -webkit-font-smoothing: antialiased; }
#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
button { font: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 999px; padding: 7px 14px; transition: .15s ease; }
button:hover { border-color: var(--blue); }
button:focus-visible, textarea:focus-visible, input:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }
button.primary { background: var(--blue); color: #fff; border-color: var(--blue); }
button.primary:hover { background: var(--blue-ink); border-color: var(--blue-ink); }
button.primary:disabled { opacity: .6; cursor: default; }
button.ghost { background: transparent; }
button.wide { width: 100%; }
button.icon-btn { width: 36px; height: 36px; padding: 0; display: inline-flex; align-items: center; justify-content: center; font-size: 16px; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(0,122,255,.16); }
h1, h2, h3, .brand-name { font-family: var(--display); }
a { color: var(--brand-2); }
.muted { color: var(--muted); } .small { font-size: 12px; } .err { color: var(--warn); }
.pill { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: var(--blue-soft); color: var(--blue-ink); white-space: nowrap; }
.pill.warn { background: rgba(194,65,12,.12); color: var(--warn); }
.pill.ok { background: rgba(0,152,74,.12); color: var(--ok); }
.pill.neutral { background: var(--panel-2); color: var(--slate); border: 1px solid var(--line-soft); }
.only-sm { display: none !important; }

/* top bar */
.topbar { display: flex; align-items: center; gap: 14px; padding: 0 16px; height: 60px; background: var(--navy); color: #fff; flex: none; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; text-decoration: none; color: inherit; }
.topbar a, .topbar .brand { color: #fff; }
.topbar button { background: transparent; border-color: rgba(255,255,255,.25); color: #fff; }
.topbar button:hover { border-color: #fff; }
.brand-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-logo { height: 28px; max-width: 190px; object-fit: contain; display: block; }
.tabs { display: flex; gap: 4px; margin-left: auto; }
.tab { border: 1px solid transparent; background: transparent; padding: 7px 14px; border-radius: 999px; color: rgba(255,255,255,.72); }
.tab:hover { color: #fff; border-color: rgba(255,255,255,.25); }
.tab.active { background: rgba(255,255,255,.14); color: #fff; font-weight: 600; border-color: transparent; }
.topbar-right { display: flex; gap: 6px; align-items: center; }
.index-badge { font-size: 12px; color: rgba(255,255,255,.7); margin-right: 6px; white-space: nowrap; }
.settings { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; padding: 12px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.settings label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.settings input { min-width: 260px; }

/* layout */
.tabpane { display: none; flex: 1; min-height: 0; }
.tabpane.active { display: flex; }
#tab-chat.active { display: grid; grid-template-columns: 264px minmax(0, 1fr) 360px; position: relative; }

/* sessions sidebar */
.sidebar { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; background: var(--panel); }
.sidebar-top { padding: 12px 12px 8px; display: flex; flex-direction: column; gap: 8px; }
.session-search { padding: 8px 12px; border-radius: 10px; font-size: 13px; }
.session-groups { flex: 1; overflow: auto; padding: 0 8px 8px; }
.side-head { font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); padding: 10px 6px 4px; }
.session-list { list-style: none; margin: 0; padding: 0; }
.session-list li { position: relative; padding: 8px 64px 8px 10px; border-radius: 10px; cursor: pointer; display: flex; flex-direction: column; gap: 2px; }
.session-list li:hover, .session-list li.active { background: var(--bg); }
.session-list li.active { box-shadow: inset 3px 0 0 var(--blue); }
.s-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }
.s-meta { font-size: 11px; color: var(--muted); }
.s-actions { position: absolute; right: 6px; top: 7px; display: none; gap: 2px; }
.session-list li:hover .s-actions { display: flex; }
.s-actions button { width: 26px; height: 26px; padding: 0; font-size: 12px; border-color: transparent; background: var(--panel); }
.s-actions button:hover { border-color: var(--line); }
.sidebar-foot { border-top: 1px solid var(--line-soft); padding: 6px 8px 10px; max-height: 40%; overflow: auto; }
.examples { list-style: none; margin: 0; padding: 0; }
.examples li { padding: 6px 8px; font-size: 12px; color: var(--brand-2); cursor: pointer; border-radius: 6px; line-height: 1.4; }
.examples li:hover { background: var(--bg); }
.empty-sessions { padding: 12px 10px; font-size: 12px; color: var(--muted); }

/* chat column */
.chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.messages { flex: 1; overflow: auto; padding: 22px 24px; display: flex; flex-direction: column; gap: 18px; scroll-behavior: smooth; }
.welcome { max-width: 760px; margin: 28px auto 0; text-align: center; color: var(--slate); }
.welcome-mark { width: 52px; height: 52px; border-radius: 16px; background: var(--navy); color: #fff; font-family: var(--display); font-weight: 700; display: inline-flex; align-items: center; justify-content: center; margin-bottom: 12px; letter-spacing: .04em; }
.welcome h2 { color: var(--ink); font-size: 21px; margin: 0 0 8px; line-height: 1.35; }
.welcome p { margin: 0 auto 18px; max-width: 60ch; font-size: 14px; }
.welcome-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px; text-align: left; }
.wcard { background: var(--panel); border: 1px solid var(--line-soft); border-radius: 12px; padding: 12px 14px; box-shadow: var(--shadow-sm); }
.wcard h4 { margin: 0 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; }
.wcard button { display: block; width: 100%; text-align: left; border: none; background: transparent; padding: 5px 0; font-size: 13px; color: var(--blue-ink); border-radius: 6px; line-height: 1.4; }
.wcard button:hover { text-decoration: underline; }
.welcome-notes { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 16px; margin-top: 18px; font-size: 12px; color: var(--muted); }

.msg { display: flex; gap: 10px; max-width: 100%; }
.msg.user { justify-content: flex-end; }
.msg.system { justify-content: center; }
.avatar { flex: none; width: 30px; height: 30px; border-radius: 10px; background: var(--navy); color: #fff; font-size: 11px; font-weight: 700; font-family: var(--display); display: flex; align-items: center; justify-content: center; margin-top: 2px; }
.msg-col { display: flex; flex-direction: column; gap: 6px; min-width: 0; max-width: min(820px, 88%); }
.bubble { padding: 14px 18px; border-radius: var(--radius); background: var(--assist); border: 1px solid var(--line-soft); line-height: 1.6; box-shadow: var(--shadow-sm); overflow-wrap: anywhere; }
.msg.user .msg-col { align-items: flex-end; max-width: min(720px, 82%); }
.msg.user .bubble { background: var(--user); border-color: transparent; box-shadow: none; white-space: pre-wrap; }
.msg.system .bubble { background: transparent; border: none; color: var(--muted); font-size: 13px; box-shadow: none; }
.stamp { font-size: 11px; color: var(--muted); padding: 0 6px; }
.bubble p { margin: 0 0 8px; } .bubble p:last-child { margin-bottom: 0; }
.bubble h1, .bubble h2, .bubble h3, .bubble h4 { margin: 10px 0 6px; font-size: 15px; }
.bubble ul, .bubble ol { margin: 4px 0 8px; padding-left: 22px; }
.bubble li { margin: 2px 0; }
.bubble code { font: 12px/1.4 ui-monospace, "Cascadia Mono", Consolas, monospace; background: var(--bg); padding: 1px 5px; border-radius: 4px; }
.bubble table.md { border-collapse: collapse; margin: 8px 0; font-size: 13px; width: 100%; display: block; overflow: auto; }
.bubble table.md th, .bubble table.md td { border: 1px solid var(--line); padding: 5px 9px; text-align: left; vertical-align: top; }
.bubble table.md th { background: var(--panel-2); font-weight: 600; }
.bubble table.md td.num { text-align: right; font-variant-numeric: tabular-nums; }
button.cite { padding: 0 5px; font-size: 11px; border-radius: 6px; margin: 0 1px; color: var(--brand-2); border-color: var(--line); vertical-align: baseline; background: var(--panel); line-height: 1.5; }
button.cite:hover, button.cite.active { background: var(--blue-soft); border-color: var(--blue); }
.status { color: var(--muted); font-style: italic; }
.cursor::after { content: "▍"; color: var(--blue); animation: blink 1s steps(2) infinite; margin-left: 1px; }
@keyframes blink { to { visibility: hidden; } }

.stages { display: flex; flex-wrap: wrap; gap: 6px; }
.stage { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); padding: 3px 10px; border-radius: 999px; border: 1px solid var(--line-soft); background: var(--panel); }
.stage.active { color: var(--blue-ink); border-color: var(--blue); }
.stage.done { color: var(--ok); }
.stage .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.stage.active .dot { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .2; } }

.plan-note { font-size: 12px; color: var(--slate); background: var(--panel-2); border: 1px dashed var(--line); border-radius: 10px; padding: 6px 10px; display: flex; gap: 8px; align-items: baseline; }
.plan-note b { color: var(--ink); font-weight: 600; }
.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.src-row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.src-chip { display: inline-flex; align-items: center; gap: 6px; max-width: 280px; font-size: 12px; padding: 4px 10px 4px 6px; border-radius: 999px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; }
.src-chip:hover, .src-chip.active { border-color: var(--blue); background: var(--blue-soft); }
.src-chip .n { font-weight: 700; color: var(--brand-2); }
.src-chip .tt { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.src-chip .tier { font-size: 10px; color: var(--muted); }
/* research digest: the link that opens a cited document (entry lines, source chips, the drawer) */
a.doc-open { display: inline-block; font-size: 11px; line-height: 1.5; padding: 0 7px; margin-left: 2px; border-radius: 6px;
  border: 1px solid var(--line); background: var(--panel); color: var(--brand-2); text-decoration: none; white-space: nowrap; vertical-align: baseline; }
a.doc-open:hover { border-color: var(--blue); background: var(--blue-soft); }
.src-chip a.doc-open { padding: 0 5px; margin-left: 0; }
.bubble ol > li { margin: 6px 0; }
.bubble li > ul { margin: 2px 0 4px; }
.followups { display: flex; flex-wrap: wrap; gap: 6px; }
.followups button { font-size: 12px; padding: 5px 12px; background: var(--panel); border-color: var(--line); color: var(--blue-ink); }
.followups button::before { content: "↳ "; color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; font-size: 11px; color: var(--muted); }
.actions button { font-size: 11px; padding: 3px 9px; border-color: transparent; background: transparent; color: var(--slate); }
.actions button:hover { border-color: var(--line); background: var(--panel); }
.actions .sep { opacity: .5; }
.actions .meta-bits { margin-left: auto; display: flex; flex-wrap: wrap; gap: 4px 10px; }
.actions a { color: var(--slate); }
.meta { margin-top: 8px; font-size: 11px; color: var(--muted); }

/* composer */
.composer { padding: 10px 24px 6px; background: transparent; }
.composer-box { display: flex; flex-direction: column; gap: 6px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 8px 10px 8px 14px; box-shadow: var(--shadow-sm); transition: border-color .15s, box-shadow .15s; }
.composer-box:focus-within { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(0,122,255,.14); }
.composer textarea { border: none; padding: 6px 0; resize: none; min-height: 28px; max-height: 200px; background: transparent; line-height: 1.5; box-shadow: none !important; }
.composer-tools { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.script-hint { font-size: 11px; color: var(--blue-ink); background: var(--blue-soft); padding: 3px 9px; border-radius: 999px; margin-right: auto; }
button.send { width: 38px; height: 38px; padding: 0; display: inline-flex; align-items: center; justify-content: center; font-size: 15px; }
.chat-foot { padding: 4px 24px 10px; }
.disclaimer { font-size: 11px; color: var(--muted); }
.powered { text-align: center; font-size: 11px; margin-top: 4px; }
.powered a { color: var(--muted); text-decoration: none; }
.powered a:hover { text-decoration: underline; }

/* sources pane */
.citations-pane { border-left: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.pane-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line); font-weight: 600; }
.memory { border-bottom: 1px solid var(--line-soft); padding: 10px 12px; font-size: 12px; background: var(--panel-2); }
.memory .mh { display: flex; justify-content: space-between; align-items: center; font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin-bottom: 6px; }
.memory .mh button { font-size: 11px; padding: 1px 8px; }
.memory .topics { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 4px; }
.memory .summary { white-space: pre-wrap; color: var(--slate); max-height: 140px; overflow: auto; margin-top: 4px; line-height: 1.45; }
.sources-for { padding: 8px 12px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.citations { overflow: auto; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.sources-empty { padding: 20px 14px; text-align: center; }
.cite-card { display: flex; gap: 8px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; background: var(--panel); }
.cite-card:hover, .cite-card.active { border-color: var(--brand-2); background: var(--bg); }
.cite-card.uncited { opacity: .6; }
.cite-n { font-weight: 700; color: var(--brand-2); }
.cite-body { min-width: 0; }
.cite-title { font-size: 13px; }
.cite-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; }
.tag { font-size: 10px; padding: 1px 6px; border-radius: 6px; background: var(--panel-2); color: var(--slate); border: 1px solid var(--line-soft); }
.tag.primary { background: var(--blue-soft); color: var(--blue-ink); border-color: transparent; }
.tag.fallback { background: rgba(194,65,12,.12); color: var(--warn); border-color: transparent; }
.citation-detail { border-top: 1px solid var(--line); padding: 10px 12px; overflow: auto; max-height: 55%; font-size: 13px; }
.citation-detail .pane-head { padding: 0 0 8px; }
.passage { white-space: pre-wrap; font: 12px/1.45 ui-monospace, "Cascadia Mono", Consolas, monospace; background: var(--bg); padding: 8px; border-radius: 6px; max-height: 260px; overflow: auto; }
.passage.hl { border-left: 3px solid var(--accent); }
.passage mark { background: rgba(0,122,255,.18); color: inherit; border-radius: 2px; }
button.close { width: 26px; height: 26px; padding: 0; }

/* artifacts / system tabs */
#tab-artifacts.active, #tab-system.active { flex-direction: column; padding: 12px 16px; gap: 12px; overflow: auto; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.split { display: grid; grid-template-columns: 1.3fr 1fr; gap: 16px; min-height: 0; }
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); max-height: 70vh; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid th, table.grid td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
table.grid tbody tr { cursor: pointer; }
table.grid tbody tr:hover { background: var(--bg); }
.art-detail { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 12px; overflow: auto; max-height: 70vh; font-size: 13px; }
.art-detail h3 { margin: 0 0 6px; }
.kv { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 8px 0; font-size: 12px; }
.tree, .tree ul { list-style: none; padding-left: 14px; margin: 4px 0; border-left: 1px dashed var(--line); }
.out { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px; font-size: 12px; overflow: auto; max-height: 60vh; white-space: pre-wrap; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; font-size: 13px; }
.admin-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 8px 16px; border-radius: 999px; font-size: 13px; box-shadow: var(--shadow); z-index: 50; }
.scrim { position: fixed; inset: 0; background: rgba(10,28,51,.45); z-index: 29; }

@media (max-width: 1180px) { #tab-chat.active { grid-template-columns: 240px minmax(0, 1fr) 320px; } }
@media (max-width: 1000px) {
  .only-sm { display: inline-flex !important; }
  #tab-chat.active { grid-template-columns: minmax(0, 1fr); }
  .sidebar, .citations-pane { position: fixed; top: 60px; bottom: 0; width: min(86vw, 340px); z-index: 30; transform: translateX(-105%); transition: transform .2s ease; box-shadow: var(--shadow); }
  .citations-pane { right: 0; left: auto; transform: translateX(105%); border-left: 1px solid var(--line); }
  .sidebar.open, .citations-pane.open { transform: none; }
  .brand-name, .index-badge { display: none; }
  .tabs { margin-left: 0; }
  .msg-col { max-width: 94%; }
  .messages { padding: 14px 16px; }
  .composer { padding: 8px 12px 4px; }
  .chat-foot { padding: 2px 12px 8px; }
  .split { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .tab { padding: 6px 10px; font-size: 13px; }
  .welcome-cards { grid-template-columns: 1fr; }
  #theme-toggle { display: none; }
}
