/* SOVRA Connect — voice + chat, SOVRA dark navy theme. Source panel is the hero. */
:root {
  --bg: #0b1424;
  --bg-elevated: #11203a;
  --bg-card: #15294a;
  --bg-card-2: #19305a;
  --border: #1f3a66;
  --border-strong: #2a4a82;
  --text: #e6ecf5;
  --text-dim: #8aa0c2;
  --text-dimmer: #5e7397;
  --accent: #4dd2c1;
  --accent-hover: #6fe0d2;
  --accent-soft: rgba(77, 210, 193, 0.15);
  --danger: #ff6b6b;
  --warn: #ffc857;
  --ok: #6fd49c;
  --radius: 10px;
  --radius-sm: 6px;
}

* { box-sizing: border-box; }

/* Honor the hidden attribute even when an element has a display rule. */
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

.app {
  display: grid;
  grid-template-rows: 56px 1fr;
  height: 100vh;
}

/* ---------- Header ---------- */

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}

.header h1 { margin: 0; font-size: 18px; font-weight: 600; }
.header h1 .accent { color: var(--accent); }
.header h1 .subtitle { color: var(--text-dim); font-weight: 400; font-size: 13px; margin-left: 10px; }

.header-right { display: flex; align-items: center; gap: 20px; }

.status { font-size: 12px; color: var(--text-dim); }
.health-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.health-dot.ok { background: var(--ok); }
.health-dot.degraded { background: var(--warn); }
.health-dot.error { background: var(--danger); }

.speaking-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
}

.speak-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: speak-pulse 1.0s ease-in-out infinite;
  box-shadow: 0 0 0 0 rgba(77, 210, 193, 0.7);
}

@keyframes speak-pulse {
  0%   { transform: scale(1);   box-shadow: 0 0 0 0   rgba(77, 210, 193, 0.7); }
  70%  { transform: scale(1.1); box-shadow: 0 0 0 8px rgba(77, 210, 193, 0); }
  100% { transform: scale(1);   box-shadow: 0 0 0 0   rgba(77, 210, 193, 0); }
}

/* ---------- Main grid: source panel (hero) | chat ---------- */

.main {
  display: grid;
  grid-template-columns: 1.7fr 1fr;  /* chat ~63% on the left (hero), sources ~37% on the right */
  gap: 16px;
  padding: 16px;
  height: calc(100vh - 56px);
  overflow: hidden;
}

@media (max-width: 880px) {
  .main { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
}

/* ---------- Source panel (the hero) ---------- */

.source-pane {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.source-pane-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.source-pane-header h2 {
  margin: 0;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-dim);
  font-weight: 700;
}

.source-count {
  font-size: 11px;
  color: var(--text-dimmer);
}

.source-cards {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.receipt-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.5;
}

.receipt-card .meta {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--accent);
  margin-bottom: 6px;
}

.receipt-card .question {
  color: var(--text);
  font-size: 13px;
  line-height: 1.45;
  margin-bottom: 10px;
}

/* Clickable citation chips — the headline of each turn card */

.citation-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}

.citation-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: var(--bg-card-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text);
  font-size: 12px;
  line-height: 1.3;
  transition: border-color 0.12s, background 0.12s, transform 0.08s;
}

.citation-chip:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.citation-chip:active { transform: scale(0.99); }

.citation-chip.no-url {
  opacity: 0.7;
  cursor: not-allowed;
}

.cit-icon {
  font-size: 14px;
  flex-shrink: 0;
}

.cit-body {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.cit-title {
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cit-sub {
  color: var(--text-dimmer);
  font-size: 10px;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.no-citations {
  font-size: 11px;
  color: var(--text-dimmer);
  font-style: italic;
  margin: 4px 0 10px;
}

.tool-footer {
  font-size: 10px;
  color: var(--text-dimmer);
  margin-top: 6px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
}

.tool-footer .tool-chip {
  font-size: 9px;
  padding: 2px 6px;
  margin-right: 0;
  margin-top: 0;
}

/* ---------- Playbook card (gong_playbook citation) ---------- */

.playbook-card {
  background: var(--bg-card-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 12px;
  margin-bottom: 6px;
}

.playbook-header {
  display: block;
  text-decoration: none;
  color: var(--text);
  margin-bottom: 8px;
}

.playbook-header:hover .pb-title { color: var(--accent); }

.pb-row1 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.pb-icon { font-size: 16px; }

.pb-title {
  font-weight: 600;
  font-size: 13px;
  transition: color 0.12s;
}

.pb-row2 {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.pb-pct {
  font-weight: 700;
  color: var(--accent);
}

.pb-bar {
  height: 4px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
}

.pb-bar-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.5s ease;
}

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

.pb-el {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  padding: 3px 0;
  line-height: 1.3;
}

.pb-el.covered { color: var(--text-dim); }
.pb-el.missed { color: var(--text); }
.pb-el.missed .pb-el-name { font-weight: 600; }

.pb-check { font-size: 11px; flex-shrink: 0; }

.pb-el-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pb-count {
  font-size: 10px;
  color: var(--text-dimmer);
  flex-shrink: 0;
}

/* ---------- Job card (gong_analysis_job citation) ---------- */

.job-card {
  background: var(--bg-card-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 12px;
  margin-bottom: 6px;
}

.job-card.done { border-color: var(--ok); }
.job-card.error { border-color: var(--danger); }

.job-row1 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.job-icon { font-size: 16px; }

.job-title {
  font-weight: 600;
  font-size: 13px;
}

.job-status {
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 6px;
  line-height: 1.3;
}

.job-bar {
  height: 4px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 8px;
}

.job-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-hover));
  transition: width 0.8s ease;
}

/* Source-panel job card now stays thin — just status + a done line. */
.job-final {
  margin-top: 6px;
  font-size: 11px;
  color: var(--ok);
  font-weight: 600;
}

/* ---------- Theme breakdown bubble in the CHAT thread (the value) ---------- */

.themes-bubble {
  max-width: 100%;  /* let the bubble use most of the chat width */
}

.themes-summary {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 10px;
  line-height: 1.4;
  font-style: italic;
}

.themes-list {
  list-style: decimal;
  margin: 0;
  padding-left: 22px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.theme-item {
  padding-bottom: 8px;
  border-bottom: 1px dashed var(--border);
}

.theme-item:last-child {
  border-bottom: none;
  padding-bottom: 0;
}

.theme-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
}

.theme-label {
  flex: 1;
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  line-height: 1.3;
}

.theme-count {
  font-size: 12px;
  color: var(--accent);
  font-weight: 700;
  flex-shrink: 0;
}

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

.theme-examples li {
  font-size: 12px;
  color: var(--text-dim);
  line-height: 1.45;
  padding-left: 4px;
}

.theme-example-link {
  display: block;
  color: var(--text-dim);
  text-decoration: none;
  border-left: 2px solid var(--border-strong);
  padding: 4px 8px;
  border-radius: 0 4px 4px 0;
  transition: border-color 0.12s, color 0.12s, background 0.12s;
}

.theme-example-link:hover {
  color: var(--text);
  border-left-color: var(--accent);
  background: var(--accent-soft);
}

.theme-example-link .quote-mark {
  color: var(--text-dimmer);
  font-style: normal;
  margin: 0 1px;
}

.theme-example-link .theme-open {
  display: inline-block;
  margin-left: 6px;
  font-size: 10px;
  color: var(--accent);
  opacity: 0.7;
  font-style: normal;
  white-space: nowrap;
}

.theme-example-link:hover .theme-open {
  opacity: 1;
}

.empty-state {
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  padding: 40px 24px;
  line-height: 1.6;
}

.empty-state strong { color: var(--text); display: block; margin-bottom: 8px; font-size: 14px; }

.tool-chip {
  display: inline-block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  margin-right: 6px;
  margin-top: 4px;
}

.tool-chip.stubbed { background: rgba(255, 200, 87, 0.15); color: var(--warn); }

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

.chat-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.chat-pane-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-pane-header h2 {
  margin: 0;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-dim);
  font-weight: 700;
}

.restart-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 11px;
  font-family: inherit;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  cursor: pointer;
  transition: color 0.12s, border-color 0.12s, background 0.12s;
}

.restart-btn:hover {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}

.restart-btn .restart-icon {
  font-size: 14px;
  line-height: 1;
}

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

.chat-empty {
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  padding: 30px 16px;
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.chat-empty strong { color: var(--text); font-size: 14px; }

.bubble {
  max-width: 92%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.bubble.user {
  align-self: flex-end;
  background: var(--accent);
  color: #062029;
  border-bottom-right-radius: 4px;
}

.bubble.sovra {
  align-self: flex-start;
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.bubble.sovra .meta {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dimmer);
  margin-bottom: 4px;
}

.bubble.sovra .play-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 6px;
  padding: 3px 8px;
  font-size: 11px;
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-dim);
  border-radius: 999px;
  cursor: pointer;
  font-family: inherit;
}

.bubble.sovra .play-btn:hover { color: var(--accent); border-color: var(--accent); }

.bubble.thinking {
  align-self: flex-start;
  color: var(--text-dim);
  font-style: italic;
  font-size: 12px;
  padding: 6px 12px;
  background: transparent;
  border: none;
}

.bubble.thinking .dots::after {
  content: "";
  display: inline-block;
  animation: dots 1.2s steps(4, end) infinite;
}

@keyframes dots {
  0%, 20%   { content: ""; }
  40%       { content: "."; }
  60%       { content: ".."; }
  80%, 100% { content: "..."; }
}

/* ---------- Composer ---------- */

.composer {
  border-top: 1px solid var(--border);
  background: var(--bg-elevated);
  padding: 10px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.live-transcript {
  background: var(--bg-card-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 12px;
  color: var(--text-dim);
  min-height: 32px;
  display: flex;
  align-items: center;
}

.live-transcript .listening { color: var(--accent); font-weight: 600; margin-right: 6px; }
.live-transcript .speaking { color: var(--warn); font-weight: 600; margin-right: 6px; }

.composer-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

#chat-input {
  flex: 1;
  resize: none;
  max-height: 120px;
  min-height: 38px;
  padding: 9px 12px;
  font-size: 14px;
  font-family: inherit;
  background: var(--bg-card-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  outline: none;
  line-height: 1.4;
}

#chat-input:focus { border-color: var(--accent); }
#chat-input::placeholder { color: var(--text-dimmer); }

.ptt-btn {
  background: var(--accent);
  color: #062029;
  border: none;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  cursor: pointer;
  user-select: none;
  transition: transform 0.08s, background 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.ptt-btn:hover { background: var(--accent-hover); }
.ptt-btn:active, .ptt-btn.recording {
  transform: scale(0.95);
  background: var(--danger);
  color: #fff;
}

.ptt-btn .mic-icon {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.85;
}

.ptt-btn.recording .mic-icon {
  animation: mic-pulse 1.0s ease-in-out infinite;
  opacity: 1;
}

@keyframes mic-pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.4); }
}

.send-btn {
  background: var(--bg-card-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 0 14px;
  height: 38px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
  flex-shrink: 0;
}

.send-btn:hover:not(:disabled) {
  background: var(--accent);
  color: #062029;
  border-color: var(--accent);
}

.send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.composer-hint {
  font-size: 11px;
  color: var(--text-dimmer);
  padding-left: 4px;
}

audio { display: none; }
