:root {
  --bg: #0d1117;
  --bg-soft: #121822;
  --panel: #10161f;
  --surface: #182030;
  --surface-2: #1e2836;
  --line: #242f3e;
  --line-soft: #1c2532;
  --text: #e7edf5;
  --muted: #9aa7b8;
  --faint: #6c7a8c;
  --accent: #4c8dd8;
  --accent-dim: #2f6db5;
  --accent-soft: rgba(76, 141, 216, 0.14);
  --ok: #45b07a;
  --warn: #d6a13a;
  --bad: #db5b56;
  --radius: 10px;
  --radius-sm: 7px;
  --rail: 68px;
  --panel-w: 272px;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14.5px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow: hidden;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
::selection { background: rgba(76, 141, 216, 0.3); }

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: #2b3646 transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #2b3646; border-radius: 6px; border: 2px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }

.hidden { display: none !important; }

/* --------------------------------------------------------------------- */
/* Buttons + controls                                                     */
/* --------------------------------------------------------------------- */

.btn {
  display: inline-flex; align-items: center; gap: 7px; justify-content: center;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: var(--radius-sm); padding: 7px 13px; font-size: 13.5px;
  transition: background .12s, border-color .12s, opacity .12s;
  white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--surface-2); border-color: #31405280; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent-dim); border-color: var(--accent-dim); color: #fff; }
.btn.primary:hover { background: var(--accent); border-color: var(--accent); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface); color: var(--text); }
.btn.danger { border-color: #48282a; color: #e98b87; background: #1d1417; }
.btn.danger:hover { background: #2a1a1d; }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }
.btn.block { width: 100%; }

input[type="text"], input[type="password"], input[type="search"], select, textarea {
  background: var(--bg-soft); border: 1px solid var(--line); color: var(--text);
  border-radius: var(--radius-sm); padding: 8px 11px; width: 100%; outline: none;
  transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent-dim); box-shadow: 0 0 0 3px var(--accent-soft);
}
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }

.chip {
  display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px;
  border: 1px solid var(--line); background: var(--bg-soft); color: var(--muted);
  border-radius: 999px; padding: 2px 9px;
}
.chip.ok { color: #8fd8b0; border-color: #24463a; background: #14231d; }
.chip.warn { color: #e8c67d; border-color: #4a3d1f; background: #221c10; }
.chip.bad { color: #eda09c; border-color: #4a2a29; background: #221415; }
.chip.accent { color: #a9cbef; border-color: #2b3f59; background: #14202e; }

.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12.5px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* --------------------------------------------------------------------- */
/* Auth screen                                                            */
/* --------------------------------------------------------------------- */

#auth {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: radial-gradient(1100px 620px at 50% -10%, #1a2740 0%, var(--bg) 62%);
  padding: 24px;
}
.auth-card {
  width: 100%; max-width: 384px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 30px 28px 26px; box-shadow: 0 24px 60px rgba(0, 0, 0, .45);
}
.auth-card .brand { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.auth-card h1 { font-size: 20px; margin: 14px 0 6px; }
.auth-card p.lead { color: var(--muted); font-size: 13.5px; margin: 0 0 22px; }
.mark {
  width: 30px; height: 30px; border-radius: 9px; flex: none; display: grid; place-items: center;
  background: linear-gradient(145deg, var(--accent), #2a5f9e); color: #fff;
  font-weight: 700; font-size: 14px; letter-spacing: -.5px;
}
.form-error {
  background: #201416; border: 1px solid #47282a; color: #eda09c; border-radius: var(--radius-sm);
  padding: 9px 12px; font-size: 13px; margin-bottom: 14px;
}

/* --------------------------------------------------------------------- */
/* Shell                                                                  */
/* --------------------------------------------------------------------- */

#app { display: grid; grid-template-columns: var(--rail) var(--panel-w) 1fr; height: 100vh; }
#app.no-panel { grid-template-columns: var(--rail) 1fr; }
#app.no-panel > .panel { display: none; }

.rail {
  background: #0a0e14; border-right: 1px solid var(--line-soft);
  display: flex; flex-direction: column; align-items: center; padding: 14px 0 12px; gap: 6px;
}
.rail .mark { margin-bottom: 12px; }
.rail button {
  width: 44px; height: 42px; border: 0; background: transparent; color: var(--faint);
  border-radius: 9px; display: grid; place-items: center; position: relative;
}
.rail button:hover { background: var(--surface); color: var(--text); }
.rail button.active { background: var(--accent-soft); color: #a9cbef; }
.rail button.active::before {
  content: ""; position: absolute; left: -14px; top: 9px; bottom: 9px; width: 3px;
  background: var(--accent); border-radius: 0 3px 3px 0;
}
.rail .spacer { flex: 1; }
.rail svg { width: 19px; height: 19px; }

.panel {
  background: var(--panel); border-right: 1px solid var(--line-soft);
  display: flex; flex-direction: column; min-height: 0;
}
.panel-head {
  padding: 14px 14px 12px; border-bottom: 1px solid var(--line-soft);
  display: flex; flex-direction: column; gap: 10px;
}
.panel-head h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .1em; color: var(--faint); margin: 0; }
.panel-list { flex: 1; overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 3px; }
.panel-foot { padding: 10px; border-top: 1px solid var(--line-soft); }

.list-item {
  text-align: left; width: 100%; border: 1px solid transparent; background: transparent;
  border-radius: var(--radius-sm); padding: 9px 11px; color: var(--text); display: block;
}
.list-item:hover { background: var(--surface); }
.list-item.active { background: var(--surface); border-color: #2b3a4e; }
.list-item .title {
  font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  display: block; margin-bottom: 3px;
}
.list-item .sub { font-size: 11.5px; color: var(--faint); display: flex; gap: 8px; align-items: center; }
.empty { padding: 22px 14px; color: var(--faint); font-size: 13px; text-align: center; line-height: 1.6; }

main { min-width: 0; display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.view { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.view-head {
  padding: 13px 22px; border-bottom: 1px solid var(--line-soft); display: flex;
  align-items: center; gap: 12px; min-height: 57px; flex: none;
}
.view-head h1 {
  font-size: 15.5px; margin: 0; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.view-head .sub { font-size: 12px; color: var(--faint); margin-top: 2px; }
.view-body { flex: 1; overflow-y: auto; min-height: 0; }
.pad { padding: 22px; }
.narrow { max-width: 880px; margin: 0 auto; }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; margin-bottom: 16px;
}
.card h3 { margin: 0 0 4px; font-size: 14.5px; }
.card p.hint { margin: 0 0 16px; color: var(--muted); font-size: 13px; }

.banner {
  border: 1px solid #4a3d1f; background: #1d1810; color: #e8c67d;
  border-radius: var(--radius-sm); padding: 10px 14px; font-size: 13px; margin-bottom: 16px;
  display: flex; gap: 10px; align-items: flex-start;
}
.banner.bad { border-color: #47282a; background: #1e1416; color: #eda09c; }

table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--faint); font-weight: 600; padding: 0 12px 9px; border-bottom: 1px solid var(--line);
}
table.data td { padding: 10px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data td.right, table.data th.right { text-align: right; white-space: nowrap; }
table.data .name { display: flex; align-items: center; gap: 9px; }

/* --------------------------------------------------------------------- */
/* Chat                                                                   */
/* --------------------------------------------------------------------- */

.chat-stream { flex: 1; overflow-y: auto; min-height: 0; padding: 26px 0 8px; }
.stream-inner { max-width: 812px; margin: 0 auto; padding: 0 22px; }

.msg { margin-bottom: 24px; }
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .bubble {
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px 14px 4px 14px;
  padding: 10px 15px; max-width: 78%; white-space: pre-wrap; word-break: break-word;
}
.msg.assistant .who {
  display: flex; align-items: center; gap: 8px; font-size: 11.5px; color: var(--faint);
  text-transform: uppercase; letter-spacing: .09em; margin-bottom: 9px;
}
.msg.assistant .who .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.prose { word-break: break-word; }
.prose > *:first-child { margin-top: 0; }
.prose > *:last-child { margin-bottom: 0; }
.prose p { margin: 0 0 12px; }
.prose ul, .prose ol { margin: 0 0 12px; padding-left: 22px; }
.prose li { margin: 0 0 5px; }
.prose h3, .prose h4 { margin: 20px 0 8px; font-size: 15px; }
.prose code {
  background: var(--surface); border: 1px solid var(--line); border-radius: 5px;
  padding: 1px 5px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px;
}
.prose pre {
  background: #0a0f17; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 13px 15px; overflow-x: auto; margin: 0 0 14px;
}
.prose pre code { background: none; border: 0; padding: 0; font-size: 12.5px; line-height: 1.55; }
.prose blockquote {
  margin: 0 0 12px; padding-left: 14px; border-left: 2px solid var(--line); color: var(--muted);
}
.prose table { border-collapse: collapse; font-size: 13.5px; margin: 0 0 14px; }
.prose th, .prose td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }

.cite-ref {
  display: inline-block; min-width: 17px; padding: 0 4px; margin: 0 1px; border-radius: 5px;
  background: var(--accent-soft); border: 1px solid #2b3f59; color: #a9cbef;
  font-size: 11px; font-weight: 600; text-align: center; cursor: pointer; vertical-align: 1px;
}
.cite-ref:hover { background: #1d2e44; color: #c8def5; }

.trace { margin: 0 0 14px; display: flex; flex-direction: column; gap: 5px; }
.trace-line {
  display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted);
  background: var(--bg-soft); border: 1px solid var(--line-soft); border-radius: 999px;
  padding: 4px 12px; align-self: flex-start; max-width: 100%;
}
.trace-line .glyph { color: var(--accent); flex: none; }
.trace-line.bad { color: #eda09c; border-color: #3a2426; }
.trace-line span.txt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

details.reasoning {
  margin: 0 0 14px; border: 1px solid var(--line-soft); border-radius: var(--radius-sm);
  background: var(--bg-soft); font-size: 13px;
}
details.reasoning summary {
  cursor: pointer; padding: 7px 12px; color: var(--faint); font-size: 12.5px; list-style: none;
}
details.reasoning summary::-webkit-details-marker { display: none; }
details.reasoning summary::before { content: "▸ "; }
details.reasoning[open] summary::before { content: "▾ "; }
details.reasoning .inner {
  padding: 2px 13px 11px; color: var(--muted); white-space: pre-wrap;
  max-height: 320px; overflow-y: auto; font-size: 12.5px; line-height: 1.6;
}

.sources { margin-top: 16px; border-top: 1px solid var(--line-soft); padding-top: 12px; }
.sources h4 {
  margin: 0 0 9px; font-size: 11px; text-transform: uppercase; letter-spacing: .09em; color: var(--faint);
}
.source-item {
  display: flex; gap: 10px; padding: 7px 9px; border-radius: var(--radius-sm); font-size: 13px;
  border: 1px solid transparent;
}
.source-item:hover { background: var(--bg-soft); }
.source-item.flash { border-color: var(--accent-dim); background: var(--accent-soft); }
.source-item .num {
  flex: none; width: 20px; height: 20px; border-radius: 5px; background: var(--surface-2);
  color: var(--muted); font-size: 11px; font-weight: 600; display: grid; place-items: center;
}
.source-item .file { color: var(--text); }
.source-item .meta { color: var(--faint); font-size: 12px; }
.source-item .excerpt {
  color: var(--muted); font-size: 12.5px; margin-top: 3px; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.source-item .source-open { flex: none; align-self: flex-start; text-decoration: none; }

.artifact-card {
  display: flex; align-items: center; gap: 12px; margin: 12px 0 0; padding: 12px 14px;
  border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius);
}
.artifact-card .icon {
  width: 34px; height: 34px; flex: none; border-radius: 8px; display: grid; place-items: center;
  background: var(--accent-soft); color: #a9cbef; font-size: 10.5px; font-weight: 700;
}
.artifact-card .icon.deck { background: rgba(214, 161, 58, .14); color: #e8c67d; }
.artifact-card .icon.chart { background: rgba(62, 142, 126, .16); color: #8fd1c1; }
.artifact-chart img {
  display: block; width: 100%; margin: 8px 0 0; border: 1px solid var(--line);
  border-radius: var(--radius); background: #fff;
}
.choice-card {
  margin: 12px 0 0; padding: 12px 14px; border: 1px solid var(--line); background: var(--panel);
  border-radius: var(--radius);
}
.choice-card h4 {
  margin: 0 0 10px; font-size: 11px; text-transform: uppercase; letter-spacing: .09em; color: var(--faint);
}
.choice-card .choice-row {
  display: flex; align-items: center; gap: 12px; padding: 7px 0; border-top: 1px solid var(--line-soft);
}
.choice-card .choice-row:first-of-type { border-top: 0; }
.choice-card .choice-row img {
  flex: none; width: 112px; height: 64px; object-fit: contain; background: #fff;
  border: 1px solid var(--line); border-radius: var(--radius-sm);
}
.choice-card .choice-row.skipped img { opacity: .35; }
.choice-card .choice-row .grow { min-width: 0; flex: 1; font-size: 13.5px; }
.choice-card .toggle { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.choice-card .toggle button {
  border: 0; background: transparent; color: var(--muted); padding: 4px 11px; font-size: 12.5px; cursor: pointer;
}
.choice-card .toggle button.on { background: var(--accent-soft); color: #a9cbef; }
.choice-card .actions { display: flex; gap: 8px; margin-top: 12px; }
.choice-card .choice-marking:not(:first-child) {
  margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line-soft);
}
.choice-card .choice-option {
  display: flex; align-items: center; gap: 10px; padding: 6px 0; min-height: 34px;
}
.choice-card .choice-option input[type="radio"] { flex: none; margin: 0; accent-color: var(--accent); }
.choice-card .choice-option label { min-width: 0; flex: 1; font-size: 13.5px; cursor: pointer; }
.choice-card .choice-option:not(.selected) label { color: var(--muted); }
.choice-card.busy { opacity: .7; pointer-events: none; }
.choice-card.done .toggle, .choice-card.done .actions,
.choice-card.done .choice-option input, .choice-card.done .choice-option button { display: none; }
/* A card answered just now keeps only the marking that was picked. */
.choice-card.done .choice-marking.answered .choice-option:not(.selected) { display: none; }
.artifact-banner { margin-top: 4px; }
.msg.user .chip {
  display: inline-block; margin-top: 6px; padding: 1px 8px; border-radius: 999px; font-size: 11.5px;
  background: rgba(62, 142, 126, .16); color: #8fd1c1;
}
.artifact-card .grow { min-width: 0; }
.artifact-card .name { font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.composer { flex: none; padding: 12px 22px 18px; background: linear-gradient(to top, var(--bg) 62%, transparent); }
.composer-inner { max-width: 812px; margin: 0 auto; }
.composer-box {
  border: 1px solid var(--line); background: var(--panel); border-radius: 14px; padding: 10px 12px 10px 14px;
  display: flex; gap: 10px; align-items: flex-end; transition: border-color .12s, box-shadow .12s;
}
.composer-box:focus-within { border-color: var(--accent-dim); box-shadow: 0 0 0 3px var(--accent-soft); }
.composer textarea {
  border: 0; background: transparent; padding: 5px 0; resize: none; max-height: 208px;
  min-height: 24px; line-height: 1.5;
}
.composer textarea:focus { box-shadow: none; }
.composer .send {
  width: 34px; height: 34px; border-radius: 9px; flex: none; display: grid; place-items: center;
  background: var(--accent-dim); border: 0; color: #fff; padding: 0;
}
.composer .send:hover { background: var(--accent); }
.composer .send:disabled { background: var(--surface-2); color: var(--faint); }
.composer .hint { font-size: 11.5px; color: var(--faint); text-align: center; margin: 8px 0 0; }

.typing { display: inline-flex; gap: 4px; align-items: center; height: 18px; }
.typing i {
  width: 5px; height: 5px; border-radius: 50%; background: var(--faint);
  animation: blink 1.25s infinite ease-in-out;
}
.typing i:nth-child(2) { animation-delay: .18s; }
.typing i:nth-child(3) { animation-delay: .36s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

/* Store picker dropdown */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 20; width: 292px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 18px 44px rgba(0, 0, 0, .5); padding: 8px; max-height: 340px; overflow-y: auto;
}
.dropdown-menu .head {
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--faint);
  padding: 6px 8px 8px;
}
.check {
  display: flex; gap: 10px; align-items: flex-start; padding: 7px 8px; border-radius: var(--radius-sm);
  cursor: pointer; font-size: 13.5px;
}
.check:hover { background: var(--surface); }
.check input { width: auto; margin: 3px 0 0; accent-color: var(--accent); }
.check .sub { font-size: 11.5px; color: var(--faint); }

/* Drop zone */
.dropzone {
  border: 1.5px dashed var(--line); border-radius: var(--radius); padding: 26px 20px;
  text-align: center; color: var(--muted); background: var(--bg-soft); transition: all .12s;
}
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); color: var(--text); }
.dropzone strong { color: var(--text); font-weight: 600; }

.spinner {
  width: 13px; height: 13px; border: 2px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast-wrap {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 90;
  display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none;
}
.toast {
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 9px 15px; font-size: 13px; box-shadow: 0 12px 30px rgba(0, 0, 0, .45);
  animation: rise .18s ease-out;
}
.toast.bad { border-color: #47282a; color: #eda09c; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

.marking-notice {
  height: var(--notice-h); box-sizing: border-box; padding: 0 14px;
  display: flex; align-items: center; justify-content: center; gap: 12px;
  background: #2b2414; border-bottom: 1px solid #5a4a22; color: #f0d08a; font-size: 12.5px;
  white-space: nowrap; overflow: hidden;
}
:root { --notice-h: 38px; }
body:has(#marking-notice:not(.hidden)) #app { height: calc(100vh - var(--notice-h)); }
.marking-notice.hidden { display: none; }
.marking-notice button { flex: none; }

dialog.ask {
  background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px 20px; width: min(420px, calc(100vw - 32px));
  box-shadow: 0 18px 48px rgba(0, 0, 0, .5);
}
dialog.ask::backdrop { background: rgba(4, 7, 12, .6); }
dialog.ask p { margin: 0 0 14px; font-size: 14px; line-height: 1.5; white-space: pre-line; }
.ask-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.banner-chip {
  display: inline-block; padding: 1px 7px; border-radius: 5px; font-size: 11px; font-weight: 600;
  letter-spacing: .02em; background: rgba(214, 161, 58, .14); color: #f0d08a;
  border: 1px solid rgba(214, 161, 58, .35); white-space: nowrap; max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; vertical-align: middle;
}
/* DoD classification banner colors */
.banner-chip[class*="level-"] { border-color: transparent; font-weight: 700; }
.banner-chip.level-u { background: #007a33; color: #fff; }
.banner-chip.level-cui { background: #502b85; color: #fff; }
.banner-chip.level-c { background: #0033a0; color: #fff; }
.banner-chip.level-s { background: #c8102e; color: #fff; }
.banner-chip.level-ts { background: #ff8c00; color: #000; }
.banner-chip.level-ts-sci { background: #fce83a; color: #000; }
.banner-chip.none { background: transparent; color: var(--faint); border-color: var(--line); font-weight: 500; }

@media (max-width: 1020px) {
  :root { --panel-w: 234px; }
}
@media (max-width: 820px) {
  #app { grid-template-columns: var(--rail) 1fr; }
  #app > .panel { position: fixed; left: var(--rail); top: 0; bottom: 0; width: 272px; z-index: 30; }
  #app:not(.panel-open) > .panel { display: none; }
}
