/* ── Design Tokens ── */
:root {
  --bg:            #0a0c10;
  --bg-subtle:     #0f1218;
  --surface:       rgba(17, 20, 28, 0.72);
  --surface-hover: rgba(22, 26, 36, 0.85);
  --border:        rgba(255, 255, 255, 0.06);
  --border-focus:  rgba(110, 231, 208, 0.35);
  --text:          #e4e7ec;
  --text-secondary:#8b93a1;
  --text-muted:    #565d6b;
  --accent:        #6ee7d0;
  --accent-glow:   rgba(110, 231, 208, 0.12);
  --accent-2:      #4f8ff7;
  --warn:          #f0b75a;
  --danger:        #ef6b6b;
  --success:       #6ee7d0;
  --radius-sm:     8px;
  --radius:        14px;
  --radius-lg:     18px;
  --shadow:        0 2px 24px rgba(0, 0, 0, 0.35), 0 0 0 1px var(--border);
  --transition:    180ms cubic-bezier(0.4, 0, 0.2, 1);
  --font:          'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono:          'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
::selection { background: var(--accent); color: var(--bg); }

/* ── Global ── */
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

.app-shell {
  max-width: 1320px;
  margin: 0 auto;
  padding: 20px 28px 32px;
}

/* ── Glass Card ── */
.glass-card {
  background: var(--surface);
  backdrop-filter: blur(20px) saturate(1.4);
  -webkit-backdrop-filter: blur(20px) saturate(1.4);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  transition: border-color var(--transition);
}
.glass-card:hover { border-color: rgba(255,255,255,0.09); }

/* ── Top Bar ── */
.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 12px; }
.logo-mark { flex-shrink: 0; }
.brand h1 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.tagline {
  font-size: 12.5px;
  color: var(--text-secondary);
  margin-top: 1px;
  letter-spacing: -0.01em;
}

.session-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

/* ── User Picker ── */
.user-picker {
  display: flex;
  align-items: center;
  gap: 8px;
}
.user-picker label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}
.select-wrap {
  position: relative;
}
.select-wrap select {
  appearance: none;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 30px 7px 12px;
  font-size: 13px;
  font-family: var(--font);
  font-weight: 500;
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.select-wrap select:hover { border-color: rgba(255,255,255,0.12); }
.select-wrap select:focus { outline: none; border-color: var(--border-focus); box-shadow: 0 0 0 3px var(--accent-glow); }
.select-wrap .chevron {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn:disabled { opacity: 0.35; cursor: not-allowed; pointer-events: none; }

.btn-primary {
  background: linear-gradient(135deg, #3a6b61 0%, #2a5f6e 100%);
  color: var(--accent);
  border-color: rgba(110, 231, 208, 0.18);
}
.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #457a6f 0%, #33707f 100%);
  box-shadow: 0 0 20px var(--accent-glow);
  transform: translateY(-1px);
}
.btn-primary:active:not(:disabled) { transform: translateY(0); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border);
}
.btn-ghost:hover:not(:disabled) {
  background: rgba(255,255,255,0.04);
  color: var(--text);
  border-color: rgba(255,255,255,0.12);
}

.btn-send {
  width: 38px;
  height: 38px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #3a6b61 0%, #2a5f6e 100%);
  color: var(--accent);
  border: 1px solid rgba(110, 231, 208, 0.18);
  border-radius: 10px;
  flex-shrink: 0;
}
.btn-send:hover:not(:disabled) {
  box-shadow: 0 0 16px var(--accent-glow);
  transform: scale(1.06);
}

.btn-next {
  width: 100%;
  justify-content: center;
  margin-top: 10px;
  background: transparent;
  color: var(--accent);
  border: 1px dashed rgba(110, 231, 208, 0.25);
  border-radius: var(--radius-sm);
  padding: 10px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}
.btn-next:hover {
  background: var(--accent-glow);
  border-style: solid;
  transform: translateY(-1px);
}

/* ── Status Pill ── */
.status-pill {
  padding: 5px 12px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: rgba(255,255,255,0.04);
  color: var(--text-muted);
  border: 1px solid var(--border);
  transition: all var(--transition);
}
.status-pill.live {
  background: var(--accent-glow);
  color: var(--accent);
  border-color: rgba(110, 231, 208, 0.2);
  animation: pulse-glow 2s ease-in-out infinite;
}
@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 0 0 rgba(110, 231, 208, 0); }
  50%      { box-shadow: 0 0 12px 2px rgba(110, 231, 208, 0.15); }
}

/* ── Workspace Grid ── */
.workspace {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 20px;
  align-items: start;
}
@media (max-width: 960px) { .workspace { grid-template-columns: 1fr; } }

/* ── Chat Panel ── */
.chat-panel { padding: 0; display: flex; flex-direction: column; }

.card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.card-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.chat-icon { background: rgba(79, 143, 247, 0.12); color: var(--accent-2); }
.skill-icon { background: var(--accent-glow); color: var(--accent); }
.debt-icon { background: rgba(239, 107, 107, 0.12); color: var(--danger); }
.history-icon { background: rgba(240, 183, 90, 0.12); color: var(--warn); }
.arch-icon { background: rgba(110, 231, 208, 0.08); color: var(--accent); }
.card-header h2 { font-size: 14px; font-weight: 600; letter-spacing: -0.01em; }
.card-label { margin-left: auto; font-size: 11px; color: var(--text-muted); font-weight: 500; }

.topic-badge {
  margin-left: auto;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  font-family: var(--mono);
  background: rgba(79, 143, 247, 0.1);
  color: var(--accent-2);
  border: 1px solid rgba(79, 143, 247, 0.15);
  animation: badge-in 300ms ease-out;
}
@keyframes badge-in {
  from { opacity: 0; transform: scale(0.85); }
  to   { opacity: 1; transform: scale(1); }
}

/* ── Chat Log ── */
.chat-log {
  height: 400px;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  scroll-behavior: smooth;
}
.chat-log::-webkit-scrollbar { width: 5px; }
.chat-log::-webkit-scrollbar-track { background: transparent; }
.chat-log::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 10px; }

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 14px;
  color: var(--text-muted);
  text-align: center;
}
.empty-icon { color: var(--text-muted); opacity: 0.4; }
.empty-state p { font-size: 13px; max-width: 260px; line-height: 1.5; }
.empty-state strong { color: var(--text-secondary); }

/* ── Message Bubbles ── */
.msg {
  max-width: 82%;
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  animation: msg-in 300ms ease-out both;
}
@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.msg.agent {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, rgba(110, 231, 208, 0.15) 0%, rgba(79, 143, 247, 0.12) 100%);
  border: 1px solid rgba(110, 231, 208, 0.12);
  color: #d0f5ec;
  border-bottom-right-radius: 4px;
}
.msg .cite {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 8px;
  font-size: 11px;
  color: var(--text-muted);
  font-style: normal;
  flex-wrap: wrap;
}
.cite-dot {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent-2);
  opacity: 0.6;
}
.cite-link {
  color: var(--accent-2);
  text-decoration: none;
  font-family: var(--mono);
  font-size: 10.5px;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(79, 143, 247, 0.08);
  border: 1px solid rgba(79, 143, 247, 0.12);
  cursor: pointer;
  transition: all var(--transition);
}
.cite-link:hover {
  background: rgba(79, 143, 247, 0.18);
  border-color: rgba(79, 143, 247, 0.3);
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(79, 143, 247, 0.15);
}

/* ── Typing Indicator ── */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 18px 6px;
}
.typing-indicator span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.3;
  animation: typing-dot 1.2s ease-in-out infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing-dot {
  0%, 60%, 100% { opacity: 0.2; transform: scale(0.85); }
  30%           { opacity: 0.8; transform: scale(1.15); }
}
.typing-indicator em {
  font-size: 11px;
  color: var(--text-muted);
  margin-left: 6px;
  font-style: normal;
}

/* ── Chat Input ── */
.chat-input-bar {
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
}
.chat-input-bar input {
  flex: 1;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 14px;
  font-size: 13.5px;
  font-family: var(--font);
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.chat-input-bar input::placeholder { color: var(--text-muted); }
.chat-input-bar input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.chat-input-bar input:disabled { opacity: 0.3; }

/* ── Side Column ── */
.side-col { display: flex; flex-direction: column; gap: 16px; }
.skill-panel, .debt-panel, .history-panel, .arch-panel { padding: 0; }
.skill-panel .card-header, .debt-panel .card-header, .history-panel .card-header, .arch-panel .card-header { padding: 14px 18px; border-bottom: 1px solid var(--border); }

.skill-graph, .doc-debt { padding: 14px 18px; }
.empty-text { color: var(--text-muted); font-size: 12.5px; line-height: 1.5; }

.debt-hint {
  padding: 10px 18px 0;
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.45;
}

/* ── Radar Chart / Skill Graph ── */
.skill-graph {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 60px;
}
.skill-graph canvas {
  max-width: 100%;
}
.skill-legend {
  padding: 0 18px 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  animation: node-in 400ms ease-out both;
}
.legend-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}
.legend-dot.high { background: var(--success); }
.legend-dot.mid { background: var(--warn); }
.legend-dot.low { background: var(--danger); }
.legend-label {
  color: var(--text-secondary);
  font-family: var(--mono);
  font-size: 10px;
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.legend-val {
  font-weight: 600;
  font-family: var(--mono);
  font-size: 10px;
}
.legend-val.high { color: var(--success); }
.legend-val.mid { color: var(--warn); }
.legend-val.low { color: var(--danger); }

@keyframes node-in {
  from { opacity: 0; transform: translateX(-8px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ── Doc Debt Rows ── */
.doc-debt-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  animation: node-in 400ms ease-out both;
}
.doc-debt-row:last-child { border-bottom: none; }
.debt-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.doc-debt-row .concept {
  font-size: 12px;
  font-family: var(--mono);
  color: var(--text-secondary);
}
.debt-badges {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.doc-debt-row .score-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(239, 107, 107, 0.1);
  color: var(--danger);
  border: 1px solid rgba(239, 107, 107, 0.12);
}
.doc-debt-row .people-count {
  font-size: 10.5px;
  color: var(--text-muted);
  font-family: var(--mono);
}
.debt-action {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  font-size: 11.5px;
  color: var(--warn);
  line-height: 1.4;
  padding: 6px 10px;
  background: rgba(240, 183, 90, 0.06);
  border: 1px solid rgba(240, 183, 90, 0.1);
  border-radius: var(--radius-sm);
}
.debt-action svg {
  flex-shrink: 0;
  margin-top: 1px;
  color: var(--warn);
}

/* ── Session History ── */
.session-history {
  padding: 10px 18px 14px;
  max-height: 200px;
  overflow-y: auto;
}
.session-history::-webkit-scrollbar { width: 4px; }
.session-history::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.06); border-radius: 10px; }

.history-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  animation: node-in 400ms ease-out both;
}
.history-row:last-child { border-bottom: none; }
.history-time {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
}
.history-time svg { color: var(--warn); }
.history-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding-left: 16px;
}
.history-topics {
  font-size: 11px;
  font-family: var(--mono);
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 180px;
}
.history-turns {
  font-size: 10px;
  color: var(--text-muted);
  font-family: var(--mono);
  flex-shrink: 0;
}

/* ── Architecture Panel ── */
.clickable { cursor: pointer; }
.clickable:hover { background: rgba(255,255,255,0.02); }
.arch-chevron {
  margin-left: auto;
  color: var(--text-muted);
  transition: transform var(--transition);
}
.arch-chevron.open { transform: rotate(180deg); }

.arch-content {
  overflow: hidden;
  transition: max-height 350ms ease, opacity 250ms ease;
  max-height: 600px;
  opacity: 1;
}
.arch-content.collapsed {
  max-height: 0;
  opacity: 0;
}

.arch-diagram {
  padding: 16px 18px;
}
.arch-flow {
  display: flex;
  flex-direction: column;
  gap: 0;
}
.arch-agent {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.02);
  animation: node-in 400ms ease-out both;
  transition: border-color var(--transition), background var(--transition);
}
.arch-agent:hover {
  border-color: rgba(110, 231, 208, 0.2);
  background: rgba(110, 231, 208, 0.04);
}
.arch-agent-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.01em;
}
.arch-agent-role {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent-2);
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.arch-agent-detail {
  font-size: 11.5px;
  color: var(--text-secondary);
  line-height: 1.45;
  margin-top: 6px;
}
.arch-arrow {
  display: flex;
  justify-content: center;
  padding: 4px 0;
  color: var(--text-muted);
  opacity: 0.4;
}
.arch-stack {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.arch-tech {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--accent-glow);
  color: var(--accent);
  border: 1px solid rgba(110, 231, 208, 0.12);
}

/* ── Citation Modal ── */
.citation-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: modal-in 200ms ease-out;
}
@keyframes modal-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.citation-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
}
.citation-modal-content {
  position: relative;
  z-index: 1;
  width: 90%;
  max-width: 560px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  animation: modal-slide 250ms ease-out;
}
@keyframes modal-slide {
  from { opacity: 0; transform: translateY(16px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.citation-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.citation-modal-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent-2);
}
.citation-modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  padding: 0 4px;
  line-height: 1;
  transition: color var(--transition);
}
.citation-modal-close:hover { color: var(--text); }
.citation-modal-body {
  padding: 16px 18px;
  overflow-y: auto;
  flex: 1;
}
.citation-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.citation-kind {
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.citation-kind.doc { background: rgba(79, 143, 247, 0.12); color: var(--accent-2); }
.citation-kind.code { background: rgba(110, 231, 208, 0.12); color: var(--accent); }
.citation-path {
  font-size: 11px;
  font-family: var(--mono);
  color: var(--text-muted);
}
.citation-title {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 600;
}
.citation-text {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.6;
  color: var(--text);
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-y: auto;
  max-height: 300px;
}
.citation-loading {
  display: flex;
  align-items: center;
  gap: 4px;
  color: var(--text-muted);
  font-size: 12px;
}
.citation-loading span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.3;
  animation: typing-dot 1.2s ease-in-out infinite;
}
.citation-loading span:nth-child(2) { animation-delay: 0.15s; }
.citation-loading span:nth-child(3) { animation-delay: 0.3s; }

/* ── Footer ── */
.footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 28px;
  font-size: 11.5px;
  color: var(--text-muted);
}
.footer-tech {
  padding: 2px 8px;
  border-radius: 4px;
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  font-weight: 500;
  color: var(--text-secondary);
}
.footer-sep { opacity: 0.3; }

/* ── Responsive ── */
@media (max-width: 960px) {
  .app-shell { padding: 16px; }
  .top-bar { flex-direction: column; align-items: flex-start; gap: 12px; }
  .session-controls { width: 100%; }
  .chat-log { height: 320px; }
}
