:root {
  color-scheme: dark;
  --bg: #0e1016;
  --bg-deep: #090a0f;
  --surface: #171a23;
  --surface-soft: #1f2330;
  --ink: #e8ebf2;
  --muted: #98a2b3;
  --line: #2a2f3d;
  --accent: #8b5cf6;
  --accent-dark: #7c3aed;
  --accent-soft: rgba(139, 92, 246, 0.16);
  --code: #cdd3e0;
  --warn: #f5b86b;
  --warn-soft: rgba(245, 184, 107, 0.15);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.16);
  --ok: #4ade80;
  --ok-soft: rgba(74, 222, 128, 0.16);
  --shadow: 0 16px 44px rgba(0, 0, 0, 0.5);
  --radius: 14px;
  --radius-sm: 10px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
}

.app-shell {
  display: grid;
  grid-template-columns: 268px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  border-right: 1px solid var(--line);
  background: var(--bg-deep);
  color: var(--ink);
  padding: 22px 16px;
}

.brand-block {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 34px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 11px;
  background: linear-gradient(135deg, #8b5cf6, #6d28d9);
  color: #fff;
  font-weight: 800;
  box-shadow: 0 6px 18px rgba(124, 58, 237, 0.4);
}

.brand-title {
  font-weight: 700;
  letter-spacing: -0.01em;
}

.brand-subtitle {
  color: var(--muted);
  font-size: 12.5px;
  margin-top: 2px;
}

.nav-stack {
  display: grid;
  gap: 8px;
}

.nav-item {
  width: 100%;
  min-height: 42px;
  border-radius: 10px;
  color: var(--muted);
  background: transparent;
  text-align: left;
  padding: 10px 12px;
  cursor: pointer;
  font-weight: 500;
  transition: background 0.15s ease, color 0.15s ease;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--ink);
}

.nav-item.active {
  background: var(--accent-soft);
  color: #fff;
  font-weight: 600;
}

.main-panel {
  min-width: 0;
  padding: 26px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  margin-bottom: 20px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.15;
  letter-spacing: 0;
}

h2 {
  font-size: 20px;
  letter-spacing: 0;
}

h3 {
  font-size: 15px;
  letter-spacing: 0;
}

.topbar p,
.modal-header p,
.provider-card p,
.empty-state {
  color: var(--muted);
  font-size: 14px;
  margin-top: 6px;
}

.icon-button,
.primary-button,
.secondary-button,
.ghost-button,
.danger-button {
  min-height: 38px;
  border-radius: 10px;
  padding: 9px 13px;
  cursor: pointer;
  white-space: nowrap;
}

.primary-button {
  color: #ffffff;
  background: var(--accent);
}

.primary-button:hover {
  background: var(--accent-dark);
}

.secondary-button,
.icon-button {
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
}

.secondary-button:hover,
.icon-button:hover {
  border-color: rgba(255, 255, 255, 0.22);
}

.ghost-button {
  color: var(--muted);
  background: transparent;
}

.ghost-button:hover {
  background: var(--surface-soft);
  color: var(--ink);
}

.danger-button {
  color: var(--danger);
  background: var(--danger-soft);
}

button:disabled,
.disabled-button {
  cursor: not-allowed;
  opacity: 0.55;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.metric {
  min-height: 86px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  padding: 14px;
}

.metric-label {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
}

.metric strong {
  display: block;
  font-size: 24px;
  line-height: 1.1;
  overflow-wrap: anywhere;
}

.view-panel {
  display: none;
}

.view-panel.active {
  display: block;
}

.provider-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
  gap: 14px;
}

.provider-card {
  display: grid;
  gap: 14px;
  min-height: 236px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  padding: 16px;
}

.provider-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.provider-title {
  display: flex;
  gap: 10px;
  align-items: center;
}

.provider-icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--surface-soft);
  color: var(--code);
  font-size: 13px;
  font-weight: 750;
}

.setup-note {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.setup-note strong {
  color: var(--code);
  font-size: 13px;
}

.setup-note.warn {
  border-color: rgba(245, 184, 107, 0.4);
  background: var(--warn-soft);
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 4px 9px;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 12px;
  font-weight: 680;
}

.badge.ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.badge.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.badge.error {
  background: var(--danger-soft);
  color: var(--danger);
}

.card-actions,
.form-actions,
.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.auto-ingest-cell {
  display: grid;
  gap: 7px;
  min-width: 190px;
}

.auto-ingest-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.inline-select {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  padding: 8px 10px;
}

.table-shell {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 960px;
}

th,
td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  font-size: 14px;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0;
}

tr:last-child td {
  border-bottom: 0;
}

.event-list {
  display: grid;
  gap: 10px;
}

.event-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  padding: 13px 14px;
}

.event-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 5px;
}

.workspace-toolbar {
  display: grid;
  grid-template-columns: minmax(130px, 0.7fr) minmax(150px, 0.9fr) minmax(220px, 1.4fr) auto;
  gap: 10px;
  margin-bottom: 14px;
}

.workspace-toolbar select,
.workspace-toolbar input {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  padding: 8px 10px;
}

.knowledge-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 12px;
}

.knowledge-item,
.tool-panel,
.reasoning-run {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  padding: 15px;
}

.knowledge-item {
  display: grid;
  gap: 11px;
}

.knowledge-item p,
.reasoning-run p {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.knowledge-head,
.event-item-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.select-row {
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
}

.select-row input {
  width: 18px;
  height: 18px;
}

.tag-row,
.knowledge-meta,
.action-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: center;
}

.tag {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  padding: 4px 8px;
  font-size: 12px;
  font-weight: 650;
}

.tag.subtle {
  background: var(--surface-soft);
  color: var(--muted);
}

.knowledge-meta {
  color: var(--muted);
  font-size: 13px;
}

.knowledge-meta a,
.secondary-link {
  color: var(--accent-dark);
  text-decoration: none;
  font-weight: 650;
}

.reasoning-layout,
.settings-layout {
  display: grid;
  grid-template-columns: minmax(280px, 0.8fr) minmax(0, 1.2fr);
  gap: 14px;
  align-items: start;
}

.tool-panel {
  display: grid;
  gap: 10px;
}

.reasoning-runs {
  display: grid;
  gap: 12px;
}

.reasoning-run {
  display: grid;
  gap: 11px;
}

.event-item-title span {
  color: var(--muted);
  font-size: 12px;
}

.finding-list {
  margin: 0;
  padding-left: 18px;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
}

.finding-list li + li {
  margin-top: 6px;
}

.action-strip span {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 7px 9px;
  background: var(--surface-soft);
  color: var(--code);
  font-size: 13px;
}

.modal {
  width: min(880px, calc(100vw - 32px));
  border: 0;
  border-radius: 10px;
  padding: 0;
  box-shadow: var(--shadow);
}

.modal::backdrop {
  background: rgba(16, 24, 32, 0.48);
}

.modal-frame {
  display: grid;
  max-height: min(760px, calc(100vh - 36px));
  background: var(--surface);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 20px;
  border-bottom: 1px solid var(--line);
}

.modal-body {
  overflow: auto;
  padding: 20px;
}

.dialog-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(260px, 0.8fr);
  gap: 18px;
}

.form-panel,
.guide-panel {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
  background: var(--surface-soft);
}

.panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.form-grid {
  display: grid;
  gap: 12px;
  margin: 14px 0;
}

.field {
  display: grid;
  gap: 6px;
}

.field label {
  color: var(--code);
  font-size: 13px;
  font-weight: 680;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  padding: 9px 10px;
  color: var(--ink);
}

.field textarea {
  min-height: 86px;
  resize: vertical;
}

.field-row {
  display: flex;
  align-items: center;
  gap: 9px;
}

.field-row input {
  width: 18px;
  height: 18px;
}

.hint,
.callback-url,
.guide-panel li,
.connection-note {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.callback-url {
  display: block;
  margin-top: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--code);
  overflow-wrap: anywhere;
}

.guide-panel ol {
  padding-left: 20px;
}

.setup-checklist {
  display: grid;
  gap: 8px;
  padding: 0;
  margin: 14px 0;
  list-style: none;
}

.check-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--code);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.setup-checklist .check-item + .check-item {
  margin-top: 0;
}

.guide-panel li + li {
  margin-top: 8px;
}

.guide-callout {
  margin: 12px 0 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  background: var(--accent-soft);
}

.guide-callout-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}

.guide-callout-head strong {
  color: var(--code);
  font-size: 13px;
}

.guide-callout p {
  margin: 0;
  color: var(--code);
  font-size: 13px;
  line-height: 1.5;
}

.guide-block {
  margin: 14px 0;
}

.guide-label {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
}

.guide-unlocks {
  margin: 0;
  padding-left: 18px;
}

.guide-unlocks li {
  list-style: disc;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  border-radius: 10px;
  padding: 12px 14px;
  background: #101820;
  color: #ffffff;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .main-panel {
    padding: 18px;
  }

  .topbar,
  .modal-header,
  .dialog-grid,
  .reasoning-layout,
  .settings-layout,
  .workspace-toolbar {
    display: grid;
    grid-template-columns: 1fr;
  }

  .metrics-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .sidebar {
    align-items: flex-start;
  }

  .brand-title {
    font-size: 14px;
  }

  .brand-subtitle {
    display: none;
  }

  .metrics-grid,
  .provider-grid,
  .knowledge-list {
    grid-template-columns: 1fr;
  }

  .knowledge-head,
  .event-item-title {
    display: grid;
  }

  .main-panel {
    padding: 14px;
  }

  h1 {
    font-size: 24px;
  }
}

/* ---- Ask (chat) + Notes ---- */
.ask-layout {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 220px);
  min-height: 420px;
}

.chat-thread {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 6px 2px 16px;
}

.chat-msg {
  max-width: 80%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  white-space: pre-wrap;
  line-height: 1.5;
}

.chat-msg.user {
  align-self: flex-end;
  background: var(--accent-soft);
  border-color: var(--accent-soft);
}

.chat-msg.assistant {
  align-self: flex-start;
  background: var(--surface);
}

.chat-msg.error {
  background: var(--warn-soft);
  border-color: var(--warn-soft);
  color: var(--warn);
}

.chat-thinking {
  color: var(--muted);
  font-style: italic;
}

.chat-trace {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}

.chat-citations {
  margin-top: 10px;
  border-top: 1px solid var(--line);
  padding-top: 8px;
  display: grid;
  gap: 6px;
}

.chat-citations-label {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--muted);
}

.chat-citation {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.chat-composer {
  display: flex;
  flex-direction: column;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  background: var(--surface-soft);
}

.chat-composer textarea {
  width: 100%;
  border: none;
  resize: none;
  background: transparent;
  color: var(--ink);
  font: inherit;
  outline: none;
  max-height: 160px;
}

.chat-composer-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.notes-layout {
  display: grid;
  gap: 18px;
}

.note-list {
  display: grid;
  gap: 10px;
}

.note-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  background: var(--surface);
}

.note-card p {
  margin: 0 0 8px;
  white-space: pre-wrap;
  line-height: 1.5;
}

.note-meta {
  font-size: 12px;
  color: var(--muted);
}

/* ---- Context + Evals ---- */
.context-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.9fr);
  gap: 18px;
  align-items: start;
}
.ctx-group { margin-bottom: 14px; }
.ctx-entry {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--surface);
  margin-bottom: 8px;
}
.ctx-entry p { margin: 4px 0 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
.ctx-alias { color: var(--accent); font-size: 12px; }
.ctx-question {
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--surface-soft);
  margin-top: 10px;
}
.ctx-question p { margin: 0 0 6px; font-weight: 600; }
.ctx-question textarea {
  width: 100%;
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  margin: 6px 0;
}
@media (max-width: 900px) {
  .context-layout { grid-template-columns: 1fr; }
}

/* ---- Voice onboarding (Context) ---- */
.onboard-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(300px, 0.7fr);
  gap: 18px;
  align-items: start;
}
.onboard-main {
  display: flex;
  flex-direction: column;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 18px;
  background: linear-gradient(180deg, #0f1820 0%, #14222b 100%);
  color: #eaf4f4;
  min-height: 60vh;
}
.onboard-phases {
  display: flex;
  align-items: center;
  gap: 10px;
}
.phase-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  color: #9fb4bd;
  font-size: 13px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.phase-chip b {
  display: grid;
  place-items: center;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: rgba(255,255,255,0.12);
  font-size: 11px;
}
.phase-chip.active {
  color: #fff;
  background: rgba(45, 212, 191, 0.18);
  border-color: rgba(45, 212, 191, 0.5);
  box-shadow: 0 0 18px rgba(45, 212, 191, 0.25);
}
.phase-chip.done b { background: var(--accent); color: #fff; }
.phase-line { flex: 0 0 28px; height: 2px; background: rgba(255,255,255,0.15); }

.onboard-thread {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 52vh;
  padding: 4px;
}
.onboard-thread .chat-msg {
  max-width: 88%;
  border: none;
}
.onboard-thread .chat-msg.assistant {
  background: rgba(255, 255, 255, 0.07);
  color: #eaf4f4;
  align-self: flex-start;
}
.onboard-thread .chat-msg.user {
  background: linear-gradient(135deg, var(--accent) 0%, #0ea5a0 100%);
  color: #04201d;
  align-self: flex-end;
  font-weight: 500;
}
.onboard-thread .chat-thinking { color: #9fb4bd; }
.onboard-thread .chat-msg.error { background: rgba(180, 35, 24, 0.25); color: #ffd9d3; }

.onboard-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.onboard-actions .hint { color: #9fb4bd; }

.onboard-composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 12px;
  padding: 8px;
  background: rgba(255,255,255,0.04);
}
.onboard-composer textarea {
  flex: 1;
  border: none;
  background: transparent;
  color: #fff;
  resize: none;
  outline: none;
  max-height: 140px;
  font: inherit;
}
.onboard-composer textarea::placeholder { color: #7e949d; }

.mic-button {
  flex: 0 0 auto;
  width: 46px; height: 46px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #2dd4bf, #0f766e);
  color: #04201d;
  font-size: 18px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.2s ease;
  box-shadow: 0 0 0 0 rgba(45, 212, 191, 0.5);
}
.mic-button:hover { transform: scale(1.05); }
.mic-button.listening {
  animation: mic-pulse 1.4s infinite;
  background: radial-gradient(circle at 30% 30%, #5eead4, #14b8a6);
}
@keyframes mic-pulse {
  0% { box-shadow: 0 0 0 0 rgba(45, 212, 191, 0.55); }
  70% { box-shadow: 0 0 0 16px rgba(45, 212, 191, 0); }
  100% { box-shadow: 0 0 0 0 rgba(45, 212, 191, 0); }
}

.onboard-side {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  background: var(--surface);
}
.onboard-side-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.onboard-advanced { margin-top: 14px; }
.onboard-advanced summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.onboard-advanced .form-grid { margin-top: 12px; }

@media (max-width: 900px) {
  .onboard-wrap { grid-template-columns: 1fr; }
}

/* ---- Project categorization ---- */
.ctx-categorize { margin-top: 14px; }
.proj-proposal {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  margin: 8px 0;
  background: var(--surface);
  cursor: pointer;
}
.proj-proposal input { margin-top: 3px; }
.proj-proposal strong { font-size: 14px; }

/* ---- Chat: markdown rendering, loader, meta ---- */
.chat-msg { overflow-wrap: anywhere; }
.chat-msg.assistant { max-width: 92%; }

.chat-text.md > *:first-child { margin-top: 0; }
.chat-text.md > *:last-child { margin-bottom: 0; }
.chat-text.md h3, .chat-text.md h4, .chat-text.md h5, .chat-text.md h6 { font-size: 15px; margin: 14px 0 6px; line-height: 1.3; }
.chat-text.md p { margin: 8px 0; line-height: 1.55; }
.chat-text.md ul, .chat-text.md ol { margin: 8px 0; padding-left: 22px; }
.chat-text.md li { margin: 3px 0; line-height: 1.5; }
.chat-text.md code { background: rgba(15, 118, 110, 0.10); color: var(--accent-dark); padding: 1px 5px; border-radius: 4px; font-size: 0.9em; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.chat-text.md pre { background: #0f1820; color: #e6f1f1; padding: 12px 14px; border-radius: 10px; overflow-x: auto; margin: 10px 0; }
.chat-text.md pre code { background: none; color: inherit; padding: 0; }
.chat-text.md blockquote { border-left: 3px solid var(--accent-soft); margin: 8px 0; padding: 2px 12px; color: var(--muted); }
.chat-text.md a { color: var(--accent-dark); text-decoration: underline; }
.chat-text.md hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }

.md-table-wrap { overflow-x: auto; margin: 10px 0; border: 1px solid var(--line); border-radius: 10px; }
.md-table { border-collapse: collapse; width: auto; min-width: 100%; font-size: 13px; }
.md-table th, .md-table td { border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); padding: 7px 11px; text-align: left; white-space: nowrap; }
.md-table th { background: var(--surface-soft); font-weight: 680; }
.md-table tr:last-child td { border-bottom: 0; }
.md-table th:last-child, .md-table td:last-child { border-right: 0; }

.chat-meta { margin-top: 9px; font-size: 12px; color: var(--muted); }

.chat-loader { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.chat-loader .dots { display: inline-flex; gap: 5px; }
.chat-loader .dots i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); display: inline-block; animation: chat-dot 1s infinite ease-in-out; }
.chat-loader .dots i:nth-child(2) { animation-delay: 0.15s; }
.chat-loader .dots i:nth-child(3) { animation-delay: 0.30s; }
@keyframes chat-dot { 0%, 80%, 100% { opacity: 0.3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }

/* onboarding (dark) markdown tweaks */
.onboard-thread .chat-text.md code { background: rgba(255,255,255,0.12); color: #d9f1ed; }
.onboard-thread .md-table-wrap { border-color: rgba(255,255,255,0.15); }
.onboard-thread .md-table th, .onboard-thread .md-table td { border-color: rgba(255,255,255,0.12); }
.onboard-thread .md-table th { background: rgba(255,255,255,0.06); }

/* ============ Ask view — premium dark surface ============ */
#askView { height: 100%; }
.ask-shell {
  position: relative;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 150px);
  min-height: 460px;
  border-radius: 18px;
  padding: 8px 8px 14px;
  overflow: hidden;
  background: linear-gradient(165deg, #16131f 0%, #15182a 52%, #0f1320 100%);
  border: 1px solid rgba(255, 255, 255, 0.07);
}
.ask-shell::before {
  content: '';
  position: absolute;
  top: -120px; left: 50%;
  width: 520px; height: 320px;
  transform: translateX(-50%);
  background: radial-gradient(closest-side, rgba(124, 58, 237, 0.28), transparent 70%);
  pointer-events: none;
}
.ask-shell .chat-thread {
  position: relative;
  flex: 1;
  overflow-y: auto;
  padding: 22px 20px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* hero / empty state */
.ask-hero {
  margin: auto;
  text-align: center;
  max-width: 620px;
  padding: 20px;
}
.ask-orb {
  width: 92px; height: 92px;
  margin: 0 auto 22px;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #d8c9ff, #7c3aed 46%, #4c1d95 82%);
  box-shadow: 0 0 60px rgba(124, 58, 237, 0.45), inset -8px -10px 22px rgba(0,0,0,0.45), inset 6px 8px 16px rgba(255,255,255,0.25);
  animation: ask-orb-float 6s ease-in-out infinite;
}
@keyframes ask-orb-float { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-9px); } }
.ask-hero-title { font-size: 30px; font-weight: 720; color: #f3f0fb; letter-spacing: -0.01em; }
.ask-hero-sub { margin-top: 10px; color: #98a2b3; font-size: 14px; line-height: 1.5; }
.ask-chips { margin-top: 26px; display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
.ask-chip {
  border-radius: 999px;
  padding: 10px 16px;
  font-size: 13px;
  color: #d7dbe6;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.10);
  cursor: pointer;
  transition: background 0.15s ease, transform 0.12s ease, border-color 0.15s ease;
}
.ask-chip:hover { background: rgba(124, 58, 237, 0.18); border-color: rgba(124, 58, 237, 0.5); transform: translateY(-1px); }

/* composer — compact, glassy, auto-growing */
.composer-wrap { padding: 6px 16px 2px; }
.composer-bar {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 8px 8px 8px 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.055);
  border: 1px solid rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(8px);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.composer-bar:focus-within {
  border-color: rgba(124, 58, 237, 0.55);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.15);
}
.composer-spark { color: #a78bfa; font-size: 16px; line-height: 38px; flex: 0 0 auto; }
.composer-bar textarea {
  flex: 1;
  border: 0;
  background: transparent;
  color: #f0f2f6;
  resize: none;
  outline: none;
  font: inherit;
  line-height: 1.5;
  padding: 9px 0;
  min-height: 22px;
  max-height: 160px;
}
.composer-bar textarea::placeholder { color: #7b8494; }
.composer-ghost {
  flex: 0 0 auto;
  background: transparent;
  color: #98a2b3;
  border: 0;
  font-size: 13px;
  padding: 8px 10px;
  border-radius: 9px;
  cursor: pointer;
  align-self: center;
}
.composer-ghost:hover { color: #fff; background: rgba(255, 255, 255, 0.06); }
.send-fab {
  flex: 0 0 auto;
  width: 38px; height: 38px;
  border-radius: 50%;
  display: grid; place-items: center;
  color: #fff; font-size: 18px; line-height: 1;
  background: linear-gradient(135deg, #8b5cf6, #6d28d9);
  cursor: pointer;
  border: 0;
  transition: transform 0.12s ease, box-shadow 0.15s ease;
  box-shadow: 0 4px 14px rgba(124, 58, 237, 0.45);
}
.send-fab:hover { transform: translateY(-1px) scale(1.04); }

/* messages on the dark surface */
.ask-shell .chat-msg { border: none; }
.ask-shell .chat-msg.assistant { background: rgba(255, 255, 255, 0.05); color: #e9edf3; border: 1px solid rgba(255, 255, 255, 0.07); }
.ask-shell .chat-msg.user { background: linear-gradient(135deg, #7c3aed, #6d28d9); color: #fff; }
.ask-shell .chat-msg.error { background: rgba(180, 35, 24, 0.22); color: #ffd9d3; }
.ask-shell .chat-text.md code { background: rgba(167, 139, 250, 0.18); color: #ddd6fe; }
.ask-shell .chat-text.md a { color: #c4b5fd; }
.ask-shell .chat-text.md blockquote { border-left-color: rgba(167,139,250,0.5); color: #b9c0cc; }
.ask-shell .md-table-wrap { border-color: rgba(255, 255, 255, 0.14); }
.ask-shell .md-table th, .ask-shell .md-table td { border-color: rgba(255, 255, 255, 0.12); }
.ask-shell .md-table th { background: rgba(255, 255, 255, 0.06); }
.ask-shell .chat-meta { color: #8b95a3; }
.ask-shell .chat-citations { border-top-color: rgba(255, 255, 255, 0.12); }
.ask-shell .chat-citations-label { color: #8b95a3; }
.ask-shell .chat-citation a { color: #c4b5fd; }
.ask-shell .chat-loader { color: #98a2b3; }
.ask-shell .chat-loader .dots i { background: #a78bfa; }
.ask-shell .tag.subtle { background: rgba(255, 255, 255, 0.08); color: #cbd5e1; }

/* ---- Ask: live loader status, history ---- */
.chat-loader .loader-status { color: #cbd2dd; }
.ask-shell .chat-loader .loader-status { color: #c9d0db; }
.chat-loader .loader-elapsed { margin-left: auto; font-variant-numeric: tabular-nums; opacity: 0.7; font-size: 12px; }

.ask-topbar {
  display: flex;
  justify-content: flex-end;
  padding: 4px 8px 0;
  position: relative;
  z-index: 3;
}
.ask-history { position: relative; }
.ask-top-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  color: #cdd4df;
  font-size: 12.5px;
  padding: 7px 12px;
  border-radius: 9px;
  cursor: pointer;
}
.ask-top-btn:hover { background: rgba(255, 255, 255, 0.12); color: #fff; }
.ask-history-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  width: 320px;
  max-height: 380px;
  overflow-y: auto;
  background: #161a26;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  padding: 6px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}
.ask-history-item {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 2px;
  align-items: flex-start;
  text-align: left;
  background: transparent;
  border: 0;
  color: #e6eaf0;
  padding: 9px 10px;
  border-radius: 10px;
  cursor: pointer;
}
.ask-history-item:hover { background: rgba(255, 255, 255, 0.07); }
.ask-history-item.current { background: rgba(124, 58, 237, 0.18); }
.ask-history-title { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 290px; }
.ask-history-time { font-size: 11px; color: #8b95a3; }
.ask-history-empty { color: #8b95a3; font-size: 13px; padding: 12px; }

/* ---- Chat streaming + action card ---- */
.chat-stream { white-space: pre-wrap; line-height: 1.55; margin-top: 8px; }
.chat-stream:empty { display: none; }
.chat-stream::after { content: '▌'; opacity: 0.5; animation: chat-dot 1s infinite; }

.action-card {
  align-self: flex-start;
  max-width: 92%;
  border: 1px solid rgba(139, 92, 246, 0.45);
  background: rgba(124, 58, 237, 0.10);
  border-radius: 14px;
  padding: 14px;
}
.action-card.done { opacity: 0.7; }
.action-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.action-badge { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: linear-gradient(135deg, #8b5cf6, #6d28d9); color: #fff; }
.action-head strong { color: #ece9f6; font-size: 14px; }
.action-target { color: #c4b5fd; font-size: 13px; margin-bottom: 4px; }
.action-reason { color: #9aa6b2; font-size: 12.5px; margin-bottom: 8px; }
.action-draft { width: 100%; border: 1px solid rgba(255,255,255,0.14); background: rgba(0,0,0,0.25); color: #f0f2f6; border-radius: 10px; padding: 9px 10px; resize: vertical; font: inherit; }
.action-buttons { display: flex; gap: 8px; margin-top: 10px; }
.action-status { margin-top: 8px; font-size: 12.5px; color: #9aa6b2; }

/* ============ Mobile app shell ============ */
.mobile-appbar, .bottom-nav, .nav-overlay { display: none; }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }

  /* Sidebar → slide-in drawer */
  .sidebar {
    position: fixed; top: 0; bottom: 0; left: 0;
    width: 84vw; max-width: 320px; z-index: 60;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    overflow-y: auto;
  }
  body.nav-open .sidebar { transform: translateX(0); box-shadow: 0 0 60px rgba(0,0,0,0.6); }
  .nav-overlay {
    display: block; position: fixed; inset: 0; z-index: 55;
    background: rgba(0,0,0,0.55); opacity: 0; pointer-events: none;
    transition: opacity 0.2s ease;
  }
  body.nav-open .nav-overlay { opacity: 1; pointer-events: auto; }

  /* Top app bar */
  .mobile-appbar {
    display: flex; align-items: center; gap: 12px;
    position: sticky; top: 0; z-index: 40;
    margin: -16px -16px 14px;
    padding: max(12px, env(safe-area-inset-top)) 16px 12px;
    background: rgba(14,16,22,0.88);
    -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--line);
  }
  .mobile-title { flex: 1; font-weight: 700; font-size: 17px; letter-spacing: -0.01em; }
  .nav-toggle { display: grid; gap: 4px; padding: 8px 6px; background: transparent; cursor: pointer; }
  .nav-toggle span { display: block; width: 20px; height: 2px; background: var(--ink); border-radius: 2px; }
  .appbar-icon { background: transparent; color: var(--muted); font-size: 19px; padding: 6px 8px; cursor: pointer; }

  .topbar { display: none; }
  .main-panel { padding: 16px 16px calc(80px + env(safe-area-inset-bottom)); }
  .metrics-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  h1 { font-size: 22px; }

  /* Bottom tab bar */
  .bottom-nav {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
    background: rgba(9,10,15,0.92);
    -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px);
    border-top: 1px solid var(--line);
    padding: 8px 6px calc(8px + env(safe-area-inset-bottom));
  }
  .bottom-item {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
    background: transparent; color: var(--muted); font-size: 11px; font-weight: 500;
    cursor: pointer; padding: 4px;
  }
  .bottom-item .bn-ico { font-size: 18px; line-height: 1; }
  .bottom-item.active { color: #c4b5fd; }

  /* Views adapt to one column / full width */
  .context-layout, .onboard-wrap { grid-template-columns: 1fr; }
  .ask-shell { height: calc(100dvh - 168px); border-radius: 16px; padding: 6px 6px 12px; }
  .ask-shell .chat-thread { padding: 16px 12px 8px; }
  .ask-hero-title { font-size: 24px; }
  .chat-msg { max-width: 94% !important; }
  .dialog-grid { grid-template-columns: 1fr; }
  .modal { width: 96vw; }
  .provider-grid { grid-template-columns: 1fr; }
  .onboard-main { min-height: 50vh; }
}

@media (min-width: 901px) {
  .mobile-appbar { display: none; }
}

/* ---- Chat UX polish (Claude-app feel) ---- */
/* Assistant reads as plain full-width text; user stays a pill */
.ask-shell .chat-msg.assistant {
  background: transparent;
  border: none;
  padding: 2px 2px 6px;
  max-width: 100%;
}
.ask-shell .chat-msg.assistant.error { background: rgba(248,113,113,0.12); border: 1px solid rgba(248,113,113,0.3); padding: 12px 14px; }
.ask-shell .chat-msg.user { max-width: 86%; }

/* Sources: collapsed by default, quiet disclosure */
.chat-sources { margin-top: 10px; }
.chat-sources > summary {
  list-style: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--muted);
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  user-select: none;
  width: fit-content;
}
.chat-sources > summary::-webkit-details-marker { display: none; }
.chat-sources > summary::before { content: '▸'; font-size: 10px; transition: transform 0.15s ease; }
.chat-sources[open] > summary::before { transform: rotate(90deg); }
.chat-sources > summary:hover { color: var(--ink); border-color: rgba(255,255,255,0.22); }
.chat-sources-list { display: grid; gap: 6px; margin-top: 8px; padding-left: 2px; }

/* Stop button while generating */
.send-fab.stopping {
  background: rgba(255,255,255,0.14);
  box-shadow: none;
  font-size: 13px;
}
.send-fab.stopping:hover { background: rgba(255,255,255,0.22); }

/* ---- Live toggle + Activity feed ---- */
.live-toggle {
  flex: 0 0 auto;
  align-self: center;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 999px;
  cursor: pointer;
}
.live-toggle.active {
  color: #fff;
  background: rgba(74, 222, 128, 0.18);
  border-color: rgba(74, 222, 128, 0.5);
}

.feed-filters {
  display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px;
}
.feed-filters select, .feed-filters input {
  min-height: 38px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--ink); padding: 8px 11px;
}
.feed-filters input { flex: 1; min-width: 160px; }
.feed-list { display: grid; gap: 10px; }
.feed-item {
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); padding: 13px 15px;
}
.feed-item.attention { border-left: 3px solid var(--warn); }
.feed-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 6px; }
.feed-project { font-size: 11.5px; color: #c4b5fd; background: var(--accent-soft); padding: 2px 8px; border-radius: 999px; }
.feed-flag { font-size: 11px; color: var(--warn); font-weight: 600; }
.feed-time { font-size: 11.5px; color: var(--muted); margin-left: auto; }
.feed-title { display: block; font-weight: 600; font-size: 14px; color: var(--ink); text-decoration: none; }
a.feed-title:hover { color: #c4b5fd; }
.feed-snippet { margin-top: 4px; color: var(--muted); font-size: 13px; line-height: 1.45; overflow-wrap: anywhere; }

/* ---- Briefs ---- */
.brief-time { color: var(--muted); font-size: 12.5px; margin-bottom: 10px; }
.brief-content { border: 1px solid var(--line); border-radius: 14px; background: var(--surface); padding: 16px 18px; }
.brief-md { color: var(--ink); }
.brief-share { display: flex; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.brief-recip { flex: 1; min-width: 200px; min-height: 38px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); padding: 8px 11px; }

/* ---- Floating menu (chat-immersive mobile only) ---- */
.float-menu { display: none; }

@media (max-width: 900px) {
  /* Chat full-screen: hide app bar + bottom tabs, float a hamburger */
  body.chat-immersive .mobile-appbar,
  body.chat-immersive .bottom-nav { display: none; }
  body.chat-immersive .main-panel { padding: 0; }
  body.chat-immersive .ask-shell { height: 100dvh; border-radius: 0; padding-bottom: max(12px, env(safe-area-inset-bottom)); }
  body.chat-immersive .ask-shell .chat-thread { padding-top: 58px; }
  body.chat-immersive .float-menu {
    display: grid; place-items: center;
    position: fixed; z-index: 60;
    top: max(12px, env(safe-area-inset-top)); left: 12px;
    width: 40px; height: 40px; border-radius: 50%;
    background: rgba(255,255,255,0.08);
    -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.14);
    color: var(--ink); font-size: 16px; cursor: pointer;
  }
}
