/* Copyright (c) 2026 Marco Peereboom. All rights reserved. */

/* ---- Custom properties ---- */
:root {
  --bg:             #0e1216;
  --bg-sidebar:     #0a0e12;
  --bg-surface:     #151b21;
  --bg-surface-h:   #1e262e;
  --bg-input:       #10161c;

  --fg:             #e6edf3;
  --fg-secondary:   #9ba8b4;
  --fg-muted:       #6b7783;

  --accent:         #0e7490;
  --accent-h:       #22d3ee;
  --accent-dim:     rgba(34, 211, 238, 0.14);

  --msg-user:       #0e7490;
  --msg-user-fg:    #ecfeff;
  --msg-assist:     #171f26;

  --border:         #253039;
  --border-l:       #1a222a;

  --ok:             #34d399;
  --err:            #f87171;
  --warn:           #fbbf24;

  --r-lg: 16px;
  --r-md: 12px;
  --r-sm: 8px;
  --r-pill: 999px;

  --font: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --speed: 150ms ease;
}

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

body {
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

/* ---- Scrollbar ---- */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--fg-muted); }

/* ---- App shell ---- */
#app { display: flex; height: 100vh; width: 100vw; }

/* ---- Sidebar ---- */
#sidebar {
  width: 76px; min-width: 76px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center;
  padding: 12px 0; gap: 4px;
}

.sidebar-logo {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent); color: #fff;
  font-weight: 700; font-size: 16px;
  border-radius: var(--r-sm);
  margin-bottom: 12px; user-select: none;
}

.nav-btn {
  width: 64px; min-height: 46px; padding: 6px 0; gap: 3px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: none; border: none; border-radius: var(--r-sm);
  color: var(--fg-secondary); cursor: pointer;
  transition: all var(--speed); position: relative;
}
.nav-label { font-size: 9.5px; letter-spacing: 0.02em; line-height: 1; }
.nav-btn:hover { background: var(--bg-surface); color: var(--fg-secondary); }
.nav-btn.active { background: var(--accent-dim); color: var(--accent); }
.nav-btn.active::before {
  content: ''; position: absolute; left: 0; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 20px;
  background: var(--accent); border-radius: 0 3px 3px 0;
}

.sidebar-spacer { flex: 1; }

.status-dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--fg-muted);
  margin: 8px 0 4px; transition: background var(--speed);
}
.status-dot.ready { background: var(--ok); }
.status-dot.down  { background: var(--err); }

/* ---- Main ---- */
#main {
  flex: 1; display: flex; flex-direction: column;
  overflow: hidden; min-width: 0;
}

/* ---- Panels ---- */
.panel {
  display: none; flex-direction: column;
  height: 100%; overflow: hidden;
}
.panel.active { display: flex; }

.panel-header {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 24px; border-bottom: 1px solid var(--border);
  min-height: 56px; flex-shrink: 0;
}
.panel-header h2 { font-size: 16px; font-weight: 600; letter-spacing: .01em; }

.panel-body {
  flex: 1; overflow-y: auto; padding: 24px;
}

/* ---- Messages container ---- */
.messages {
  flex: 1; overflow-y: auto; padding: 20px 24px;
  display: flex; flex-direction: column; gap: 6px;
}

/* ---- Bubbles ---- */
.message {
  display: flex; flex-direction: column;
  max-width: 72%; animation: msg-in .2s ease-out;
}
.message.user      { align-self: flex-end; align-items: flex-end; }
.message.assistant  { align-self: flex-start; align-items: flex-start; }

.bubble {
  padding: 10px 16px; border-radius: 18px;
  line-height: 1.55; font-size: 14px;
  white-space: pre-wrap; word-break: break-word;
}
.message.user .bubble {
  background: var(--msg-user); color: var(--msg-user-fg);
  border-bottom-right-radius: 6px;
}
.message.assistant .bubble {
  background: var(--msg-assist); color: var(--fg);
  border-bottom-left-radius: 6px;
  border: 1px solid var(--border-l);
}

/* streaming cursor */
.bubble.streaming::after {
  content: ''; display: inline-block;
  width: 2px; height: 1.1em;
  background: var(--fg); margin-left: 2px;
  vertical-align: text-bottom;
  animation: cursor-blink 1s steps(1) infinite;
}

/* ---- Session tag ---- */
.session-tag {
  font-size: 11px; color: var(--fg-muted);
  font-family: ui-monospace, 'SF Mono', Consolas, monospace;
  align-self: flex-start; padding: 0 4px; margin: 4px 0 2px;
}

/* ---- Tool chips ---- */
.tool-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 12px; background: var(--accent-dim);
  color: var(--accent-h); border-radius: var(--r-pill);
  font-size: 11px; font-weight: 500; letter-spacing: .02em;
  align-self: flex-start; margin: 2px 0;
  animation: fade-in .2s ease-out;
}
.tool-chip .tool-dot {
  width: 4px; height: 4px; border-radius: 50%; background: var(--accent);
}

/* ---- Validation badges ---- */
.validation-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 10px; border-radius: var(--r-pill);
  font-size: 11px; font-weight: 500;
  align-self: flex-start; margin: 2px 0;
  animation: fade-in .2s ease-out;
}
.validation-badge.pass { background: rgba(34,197,94,.12); color: var(--ok); }
.validation-badge.fail { background: rgba(239,68,68,.12); color: var(--err); }
.validation-badge.skip { background: rgba(251,191,36,.12); color: var(--warn); }

/* ---- Generic badges ---- */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 10px; border-radius: var(--r-pill);
  font-size: 11px; font-weight: 600; letter-spacing: .02em;
}
.badge-accent { background: var(--accent-dim); color: var(--accent-h); }
.badge-muted  { background: rgba(148,163,184,.1); color: var(--fg-secondary); }

.header-meta { display: flex; gap: 8px; align-items: center; }

/* ---- Connected folders (chat panel) ---- */
.folders-bar { flex-wrap: wrap; padding-top: 10px; padding-bottom: 10px; }
.folder-list { list-style: none; flex-wrap: wrap; }
.folder-list li { display: flex; gap: 6px; align-items: center; }
.folders-bar input { padding: 6px 10px; font-size: 13px; width: 160px; }

/* ---- Input bar ---- */
.input-bar {
  padding: 12px 24px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0; background: var(--bg);
}
.input-bar form { display: flex; gap: 8px; align-items: flex-end; }

.input-bar input[type="text"] {
  flex: 1; padding: 11px 18px;
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: 24px; color: var(--fg);
  font-size: 14px; font-family: var(--font); outline: none;
  transition: border-color var(--speed);
}
.input-bar input[type="text"]::placeholder { color: var(--fg-muted); }
.input-bar input[type="text"]:focus { border-color: var(--accent); }

.input-bar textarea {
  flex: 1; padding: 11px 18px; resize: none;
  min-height: 44px; max-height: 200px; overflow-y: auto;
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--r-md); color: var(--fg);
  font: 14px/1.5 var(--font); outline: none;
  transition: border-color var(--speed);
}
.input-bar textarea::placeholder { color: var(--fg-muted); }
.input-bar textarea:focus { border-color: var(--accent-h); }

.btn-round {
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  border: none; border-radius: 50%; cursor: pointer;
  background: var(--accent); color: #fff;
  flex-shrink: 0; transition: all var(--speed);
}
.btn-round:hover { background: var(--accent-h); }
.btn-stop { background: var(--err); }
.btn-stop:hover { opacity: .85; }

/* ---- Setup cards ---- */
.setup-card {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 28px;
  max-width: 560px; margin: 0 auto;
  display: flex; flex-direction: column; gap: 20px;
}
.setup-card h3 { font-size: 18px; font-weight: 600; }
.setup-desc { color: var(--fg-secondary); font-size: 13px; margin-top: -8px; }

.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-group {
  flex: 1; min-width: 130px;
  display: flex; flex-direction: column; gap: 4px;
}
.fg-wide { flex: 2; }

.form-group label, .form-group .group-label {
  font-size: 11px; font-weight: 600; color: var(--fg-secondary);
  text-transform: uppercase; letter-spacing: .06em;
}

input, select {
  padding: 10px 14px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--r-sm); color: var(--fg);
  font-size: 14px; font-family: var(--font); outline: none;
  transition: border-color var(--speed);
}
input::placeholder { color: var(--fg-muted); }
input:focus, select:focus { border-color: var(--accent); }
select { cursor: pointer; }
select option { background: var(--bg-surface); color: var(--fg); }

/* ---- Buttons ---- */
.btn-primary {
  padding: 10px 22px; background: var(--accent); color: #fff;
  border: none; border-radius: var(--r-sm);
  font-size: 14px; font-weight: 500; cursor: pointer;
  transition: background var(--speed); align-self: flex-start;
}
.btn-primary:hover { background: var(--accent-h); }

.btn-danger {
  padding: 6px 14px;
  background: rgba(239,68,68,.12); color: var(--err);
  border: 1px solid rgba(239,68,68,.25); border-radius: var(--r-sm);
  font-size: 13px; font-weight: 500; cursor: pointer;
  margin-left: auto; transition: all var(--speed);
}
.btn-danger:hover { background: rgba(239,68,68,.22); }

.btn-ghost {
  padding: 6px 14px; background: none; color: var(--fg-secondary);
  border: 1px solid var(--border); border-radius: var(--r-sm);
  font-size: 13px; cursor: pointer; transition: all var(--speed);
}
.btn-ghost:hover { background: var(--bg-surface); color: var(--fg); }

button[disabled], button[disabled]:hover {
  opacity: .4; cursor: not-allowed;
}

/* ---- Settings ---- */
.settings-body {
  display: flex; flex-direction: column; gap: 20px; max-width: 640px;
}
.settings-card {
  background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 24px;
  display: flex; flex-direction: column; gap: 16px;
}
.settings-card h3 { font-size: 15px; font-weight: 600; }
.settings-card form {
  display: flex; flex-direction: column; gap: 14px;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
}

.status-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.status-item {
  display: flex; flex-direction: column; gap: 2px;
  padding: 10px 14px; background: var(--bg-input);
  border-radius: var(--r-sm);
}
.status-label {
  font-size: 11px; color: var(--fg-muted);
  text-transform: uppercase; letter-spacing: .06em; font-weight: 500;
}
.status-value { font-size: 14px; font-weight: 500; }

/* ---- Notes ---- */
.note { font-size: 13px; min-height: 1.4em; padding: 2px 0; }
.note.ok  { color: var(--ok); }
.note.err { color: var(--err); }

/* ---- Progress bar ---- */
.progress-wrap {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 0;
}
.progress-track {
  flex: 1; height: 6px; background: var(--bg-input);
  border-radius: 3px; overflow: hidden;
}
.progress-fill {
  height: 100%; width: 0%; background: var(--accent);
  border-radius: 3px; transition: width .3s ease;
}
.progress-text {
  font-size: 12px; color: var(--fg-secondary);
  white-space: nowrap; min-width: 90px; text-align: right;
}

/* ---- Event log (migrate) ---- */
.event-log {
  display: flex; flex-direction: column; gap: 4px;
  padding: 8px 0;
}

/* ---- Result / error blocks ---- */
.result-msg {
  padding: 12px 16px;
  background: rgba(34,197,94,.08); border: 1px solid rgba(34,197,94,.2);
  border-radius: var(--r-md); color: var(--ok); font-size: 13px;
  align-self: flex-start; margin: 4px 0;
  animation: fade-in .25s ease-out;
}
.error-msg {
  padding: 10px 16px;
  background: rgba(239,68,68,.08); border: 1px solid rgba(239,68,68,.2);
  border-radius: var(--r-md); color: var(--err); font-size: 13px;
  align-self: flex-start; margin: 4px 0;
  animation: fade-in .25s ease-out;
}
.summary-box {
  padding: 12px 16px;
  background: var(--bg-raised, rgba(255,255,255,.03));
  border: 1px solid var(--border, rgba(255,255,255,.08));
  border-radius: var(--r-md); font-size: 13px;
  display: flex; flex-direction: column; gap: 6px;
  align-self: stretch; margin: 4px 0;
  animation: fade-in .25s ease-out;
}
.summary-title { font-weight: 600; }
.interview-flag {
  padding: 8px 12px;
  background: rgba(245,158,11,.08); border: 1px solid rgba(245,158,11,.25);
  border-radius: var(--r-md); color: #f59e0b;
}

/* ---- Animations ---- */
@keyframes msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes cursor-blink {
  50% { opacity: 0; }
}

/* ---- Ask ---- */
.ask-body { padding: 24px; max-width: 900px; margin: 0 auto; width: 100%; overflow-y: auto; }
.ask-card { background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 16px; }
.ask-textarea { width: 100%; min-height: 150px; resize: vertical;
  background: var(--bg-input); color: var(--fg); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 14px; font: inherit; line-height: 1.6; }
.ask-textarea:focus { outline: none; border-color: var(--accent-h); }
.ask-actions { display: flex; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.btn-secondary { padding: 10px 18px; background: var(--accent-dim);
  color: var(--accent-h); border: 1px solid var(--accent-h);
  border-radius: var(--r-sm); font: inherit; font-weight: 600; cursor: pointer;
  transition: background var(--speed); }
.btn-secondary:hover { background: rgba(34, 211, 238, 0.2); }
.ask-result { margin-top: 20px; background: var(--bg-surface);
  border: 1px solid var(--border); border-left: 3px solid var(--accent-h);
  border-radius: var(--r-md); padding: 16px; animation: fade-in var(--speed); }
.ask-result-label { font-size: 12px; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--fg-muted); margin-bottom: 8px; }
.ask-result-body { color: var(--fg); line-height: 1.6; }

/* ---- Persona ---- */
.persona-doc { padding: 24px; max-width: 820px; margin: 0 auto; width: 100%; overflow-y: auto; }
.persona-section { margin-bottom: 22px; }
.persona-section h3 { color: var(--accent-h); font-size: 13px;
  text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 10px; }
.persona-identity { color: var(--fg); line-height: 1.7; background: var(--bg-surface);
  border: 1px solid var(--border); border-radius: var(--r-md); padding: 14px; }
.persona-bullets { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.persona-bullets li { position: relative; padding-left: 18px;
  color: var(--fg-secondary); line-height: 1.5; }
.persona-bullets li::before { content: ""; position: absolute; left: 2px; top: 9px;
  width: 6px; height: 6px; border-radius: 50%; background: var(--accent-h); }

/* ---- Signals ---- */
.signals-groups { padding: 24px; max-width: 900px; margin: 0 auto; width: 100%; overflow-y: auto; }
.signal-group { margin-bottom: 24px; }
.signal-group-title { color: var(--accent-h); font-size: 13px;
  text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 10px; }
.signal-card { background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--r-md); padding: 12px 14px; margin-bottom: 8px; }
.signal-content { color: var(--fg); line-height: 1.5; margin-bottom: 10px; }
.signal-badges { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.badge.conf-high { background: rgba(52, 211, 153, 0.14); color: var(--ok); }
.badge.conf-medium { background: rgba(251, 191, 36, 0.14); color: var(--warn); }
.badge.conf-low { background: rgba(248, 113, 113, 0.14); color: var(--err);
  border: 1px solid rgba(248, 113, 113, 0.4); }
.badge.dur-trait { background: var(--accent-dim); color: var(--accent-h); }
.badge.dur-situational { background: rgba(148, 163, 184, 0.1); color: var(--fg-muted); }
.sig-vote { margin-left: auto; display: flex; gap: 4px; }
.vote-btn { width: 26px; height: 26px; border-radius: 6px; border: 1px solid var(--border);
  background: transparent; color: var(--fg-secondary); cursor: pointer; font-size: 13px;
  line-height: 1; transition: all var(--speed); }
.vote-btn:hover { color: var(--fg); border-color: var(--fg-muted); }

/* ---- A11y helper ---- */
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---- Chat empty (first-run) state ---- */
.chat-empty {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 10px; text-align: center; padding: 24px;
}
.chat-empty-title { font-size: 20px; font-weight: 650; color: var(--fg); }
.chat-empty-sub { color: var(--fg-secondary); max-width: 460px; line-height: 1.6; }
.chat-empty-examples {
  display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 8px;
}
.example-chip {
  padding: 8px 14px; background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: var(--r-pill); color: var(--fg-secondary); font: inherit;
  cursor: pointer; transition: all var(--speed);
}
.example-chip:hover { color: var(--accent-h); border-color: var(--accent-h); }

/* ---- Signals legend + persona synthesis note ---- */
.signals-legend {
  color: var(--fg-muted); font-size: 12px; line-height: 1.6; margin-bottom: 18px;
  padding-bottom: 14px; border-bottom: 1px solid var(--border-l);
}
.persona-note {
  background: rgba(251, 191, 36, 0.08); border: 1px solid rgba(251, 191, 36, 0.28);
  border-radius: var(--r-md); color: var(--warn); padding: 10px 14px;
  font-size: 13px; line-height: 1.5; margin-top: 14px;
}

/* ---- Write-consent dialog (model B) ---- */
.consent::backdrop { background: rgba(0, 0, 0, 0.5); }
.consent {
  border: 1px solid var(--border-l); border-radius: var(--r-md);
  background: var(--bg); color: var(--fg); padding: 0; max-width: 520px;
}
.consent-card { padding: 20px 22px; }
.consent-card h3 { margin: 0 0 10px; font-size: 15px; }
.consent-card p { font-size: 13px; line-height: 1.5; margin: 0 0 12px; }
/* Isolate the path's bidi so a hostile RTL-override in a brain-supplied
   name cannot visually reorder what the user is approving. */
.consent-card code {
  color: var(--accent-h); word-break: break-all;
  unicode-bidi: isolate; direction: ltr;
}
/* .btn-danger carries margin-left:auto elsewhere; keep the consent actions
   grouped at the right instead of split to opposite edges. */
.consent-actions .btn-danger { margin-left: 0; }
.consent-preview {
  background: var(--bg-alt, rgba(127, 127, 127, 0.08));
  border: 1px solid var(--border-l); border-radius: var(--r-sm);
  padding: 10px 12px; margin: 0 0 16px; font-size: 12px; line-height: 1.5;
  max-height: min(50vh, 420px); overflow: auto; white-space: pre-wrap; word-break: break-word;
}
.consent-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; }

/* ---- Ask dialog (a chat's plan approval and questions) ---- */
.ask { max-width: 640px; width: calc(100vw - 32px); }
/* Model text: each piece in its own bidi isolate, so a hostile direction
   override cannot reorder the dialog's own words around it. */
.ask-text { unicode-bidi: isolate; }
.ask-input {
  width: 100%; box-sizing: border-box; margin: 0 0 12px; padding: 8px 10px;
  background: var(--bg-input); color: var(--fg); border: 1px solid var(--border);
  border-radius: var(--r-sm); font: inherit; font-size: 13px; resize: vertical;
}
.ask-plan-edit { min-height: 240px; font-family: ui-monospace, monospace; }
.ask-q { border: 1px solid var(--border-l); border-radius: var(--r-sm);
  padding: 10px 12px; margin: 0 0 12px; }
.ask-q legend { font-size: 13px; padding: 0 4px; }
.ask-chip { display: inline-block; margin-right: 6px; padding: 0 8px;
  border-radius: var(--r-pill); background: var(--accent-dim); color: var(--accent-h);
  font-size: 11px; }
.ask-opt { display: flex; gap: 8px; align-items: baseline; margin: 6px 0;
  font-size: 13px; cursor: pointer; }
.ask-opt-text { display: flex; flex-direction: column; }
.ask-desc { color: var(--fg-secondary); font-size: 12px; }
.ask-preview { white-space: pre-wrap; word-break: break-word; font-size: 12px;
  background: var(--bg-surface); border: 1px solid var(--border-l);
  border-radius: var(--r-sm); padding: 8px 10px; margin: 4px 0 8px;
  max-height: 240px; overflow: auto; }
.ask-other, .ask-notes { margin: 4px 0 0; }
.ask-preview-withheld { margin: 4px 0 8px; }
.chat-note { color: var(--fg-secondary); font-size: 12px; margin: 4px 0; }

/* On an online hub the Claude sign-in lives on minime-client: the page
   holds no credential of its own. */
body.online #cred-card {
  display: none;
}

/* The sign-in of an online hub (#signin): one column, nothing else. */
main.signin {
  max-width: 22rem;
  margin: 18vh auto 0;
  padding: 0 1.5rem;
}
main.signin form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 1.5rem;
}
main.signin a.btn-primary {
  text-align: center;
  text-decoration: none;
}
main.signin .error-msg:empty {
  display: none;
}
/* 16px keeps a phone from zooming in on a focused input; the page scrolls
   while the sign-in shows, so the keyboard cannot hide its button. */
main.signin input {
  font-size: 16px;
}
body.signin-open {
  overflow: auto;
}

/* A plain chat: no persona, no memories, no tools. */
.badge-warn { background: rgba(251, 191, 36, 0.14); color: var(--warn); }
