:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-2: #f0f2f5;
  --border: #dde1e7;
  --text: #1a1d23;
  --text-dim: #667085;
  --accent: #4759c9;
  --green: #16794a;
  --red: #b6362c;
  --amber: #92620a;
  --purple: #6440b5;
  --orange: #a04a0d;
  --gray: #565e6d;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.top-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.brand {
  font-size: 15px;
  font-weight: 700;
  margin: 0;
  white-space: nowrap;
}

.provider-badge {
  font-size: 12px;
  color: var(--text-dim);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  width: fit-content;
  margin: 0;
  white-space: nowrap;
}

.top-bar-spacer { flex: 1; }

.history-wrap { position: relative; }

.history-btn {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border);
  font-weight: 600;
  font-size: 13px;
  padding: 7px 14px;
}
.history-btn:hover { background: var(--panel-2); filter: none; }

.history-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 320px;
  max-height: 60vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(16, 24, 40, 0.14);
  padding: 12px;
  z-index: 25;
}

#new-conversation-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

textarea {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 12px;
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
}

textarea:focus { outline: 1px solid var(--accent); }

button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

button:disabled { opacity: 0.5; cursor: default; }
button:not(:disabled):hover { filter: brightness(1.1); }

.text-btn {
  background: transparent;
  color: var(--text-dim);
  padding: 6px 4px;
  font-size: 13px;
  font-weight: 600;
}
.text-btn:hover { color: var(--text); filter: none; }

.hint {
  font-size: 12px;
  color: var(--text-dim);
  margin: 0;
}

.history {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.history li {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
  font-size: 13px;
}

.history li:hover { border-color: var(--accent); }
.history li.active { border-color: var(--accent); background: var(--panel-2); }

.history .h-query {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
  font-weight: 600;
}

.history .convo-title {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-dim);
  font-size: 12px;
}

.main {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.ask-view {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.ask-card {
  width: 100%;
  max-width: 560px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ask-card h2 {
  font-size: 22px;
  margin: 0 0 4px;
  text-align: center;
}

.ask-card .hint { text-align: center; }

.embed-banner {
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  background: rgba(71,89,201,0.08);
  border: 1px solid rgba(71,89,201,0.25);
  border-radius: 8px;
  padding: 8px 12px;
  margin: 0;
}

.hidden { display: none !important; }

.chat-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-header {
  padding: 24px 40px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.chat-header h2 {
  font-size: 20px;
  margin: 0;
  font-weight: 600;
}

.chat-thread {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 24px 40px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-turn {
  position: relative;
  border-bottom: 1px solid var(--border);
  padding-bottom: 24px;
  margin-bottom: 20px;
}
.chat-turn:last-child { border-bottom: none; margin-bottom: 0; }

.chat-question {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 10px;
  padding-right: 32px;
}

.turn-status-row { margin-bottom: 4px; }

.info-btn {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 999px;
  width: 26px;
  height: 26px;
  padding: 0;
  font-size: 15px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.info-btn:hover { background: var(--panel-2); color: var(--text); filter: none; }

.turn-info-btn {
  position: absolute;
  top: 0;
  right: 0;
}

.followup-form {
  display: flex;
  gap: 10px;
  padding: 16px 40px;
  border-top: 1px solid var(--border);
  background: var(--panel);
  flex-shrink: 0;
}

.followup-form textarea { flex: 1; }

.status-badge, .task-status, .block-tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 3px 8px;
  border-radius: 999px;
}

.status-RECEIVED, .status-PLANNING, .status-EXECUTING, .status-EVIDENCE_CHECK,
.status-VALUATION, .status-RISK, .status-REPORT_GENERATION, .status-REVIEW {
  background: rgba(71,89,201,0.13); color: var(--accent);
}
.status-COMPLETED { background: rgba(22,121,74,0.13); color: var(--green); }
.status-FAILED, .status-REJECTED { background: rgba(182,54,44,0.13); color: var(--red); }

.error-banner {
  background: rgba(182,54,44,0.08);
  border: 1px solid rgba(182,54,44,0.25);
  color: var(--red);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin: 12px 0;
}

.turn-tasks { margin: 12px 0 16px; }

.task-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.task-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 13px;
}

.task-list .task-name { flex: 1; }
.task-list .task-type { color: var(--text-dim); font-size: 12px; }

.task-status.PENDING { background: var(--panel-2); color: var(--text-dim); }
.task-status.RUNNING { background: rgba(71,89,201,0.13); color: var(--accent); animation: pulse 1.4s ease-in-out infinite; }
.task-status.COMPLETED { background: rgba(22,121,74,0.13); color: var(--green); }
.task-status.FAILED { background: rgba(182,54,44,0.13); color: var(--red); }

@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.5; } }

.trace-section {
  margin: 4px 0 28px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel);
}

.trace-section summary {
  cursor: pointer;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  list-style: none;
}

.trace-section summary::-webkit-details-marker { display: none; }
.trace-section summary::before { content: "▸ "; }
.trace-section[open] summary::before { content: "▾ "; }

.trace-list {
  list-style: none;
  margin: 0;
  padding: 0 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.trace-list li {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 12.5px;
  color: var(--text-dim);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.trace-list .trace-desc { color: var(--text); font-family: inherit; flex: 1; }
.trace-list .trace-status-ERROR { color: var(--red); }
.trace-list .trace-latency { font-size: 11px; }

.report-chart {
  width: 100%;
  max-width: 560px;
  height: 260px;
  margin: 12px 0;
}

.report-table {
  width: 100%;
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 13px;
}

.report-table th, .report-table td {
  border: 1px solid var(--border);
  padding: 6px 10px;
  text-align: left;
}

.report-table th {
  background: var(--panel-2);
  color: var(--text-dim);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.report-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}

.report-section-block {
  margin: 24px 0;
}

.report-section-block h4 {
  font-size: 15px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
  margin: 0 0 10px;
}

.block {
  margin: 10px 0;
  padding-left: 12px;
  border-left: 2px solid var(--border);
  font-size: 14px;
  line-height: 1.5;
}

.block-tag.FACT { background: rgba(71,89,201,0.13); color: var(--accent); }
.block-tag.CALCULATION { background: rgba(100,64,181,0.13); color: var(--purple); }
.block-tag.INTERPRETATION { background: rgba(86,94,109,0.13); color: var(--gray); }
.block-tag.ASSUMPTION { background: rgba(146,98,10,0.13); color: var(--amber); }
.block-tag.RISK { background: rgba(182,54,44,0.13); color: var(--red); }
.block-tag.UNKNOWN { background: rgba(160,74,13,0.13); color: var(--orange); }

.block-text { margin-left: 6px; }

.evidence-tags {
  margin-left: 8px;
  font-size: 11px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.evidence-tags a {
  color: var(--accent);
  text-decoration: none;
}
.evidence-tags a:hover { text-decoration: underline; }

.evidence-tags .evidence-no-link {
  color: var(--text-dim);
  cursor: help;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 22, 28, 0.35);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal-box {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(16, 24, 40, 0.18);
  padding: 24px;
  width: 360px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  background: transparent;
  color: var(--text-dim);
  border: none;
  font-size: 20px;
  line-height: 1;
  padding: 4px;
  cursor: pointer;
}
.modal-close:hover { color: var(--text); filter: none; }

.modal-body h3 {
  margin: 0 0 14px;
  font-size: 16px;
  font-weight: 600;
  padding-right: 20px;
}

.modal-stat-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.modal-stat-row:last-child { border-bottom: none; }

.modal-stat-label { color: var(--text-dim); }
.modal-stat-value { font-weight: 600; font-variant-numeric: tabular-nums; }

.modal-note {
  margin: 14px 0 0;
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.5;
}
