/* ============================================================
   Headless360 Voice
   Aesthetic: editorial dark UI · serif+mono typography · slate/indigo
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

:root {
  /* Surfaces — cool near-black with blue undertone */
  --bg-app: #0b0d12;
  --bg-panel: #10131a;
  --bg-elevated: #161a23;
  --bg-hover: #1c2130;
  --bg-inset: #0d1016;

  /* Strokes */
  --stroke: rgba(255, 255, 255, 0.06);
  --stroke-strong: rgba(255, 255, 255, 0.12);
  --stroke-accent: rgba(99, 145, 255, 0.28);

  /* Text */
  --ink: #e8ebf3;
  --ink-muted: #9aa3b2;
  --ink-dim: #6b7280;
  --ink-faint: #4b5161;

  /* Accent — cerulean/indigo */
  --accent: #6391ff;
  --accent-soft: #8aabff;
  --accent-dim: rgba(99, 145, 255, 0.12);
  --accent-glow: rgba(99, 145, 255, 0.22);

  /* Signals */
  --positive: #6ad388;
  --positive-dim: rgba(106, 211, 136, 0.14);
  --warn: #e4b660;
  --danger: #ef6770;
  --danger-dim: rgba(239, 103, 112, 0.12);

  /* Typography */
  --font-display: 'Instrument Serif', 'Times New Roman', serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', Menlo, Consolas, monospace;

  /* Motion */
  --ease-spring: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-gentle: cubic-bezier(0.4, 0, 0.2, 1);

  /* Layout */
  --sidebar-width: 380px;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 18px;
}

body {
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg-app);
  height: 100vh;
  overflow: hidden;
  font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11';
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Ambient background — subtle radial fog */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 12% 18%, rgba(99, 145, 255, 0.08), transparent 40%),
    radial-gradient(circle at 88% 92%, rgba(138, 171, 255, 0.05), transparent 45%);
  z-index: 0;
}

.app {
  position: relative;
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  height: 100vh;
  z-index: 1;
}

/* ------------------------------------------------------------
   Typography primitives
   ------------------------------------------------------------ */
.eyebrow {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  color: var(--accent-soft);
  background: var(--bg-inset);
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid var(--stroke);
}

em {
  font-family: var(--font-display);
  font-style: italic;
  color: var(--accent-soft);
  font-weight: 400;
}

/* ------------------------------------------------------------
   Sidebar
   ------------------------------------------------------------ */
.sidebar {
  display: grid;
  grid-template-rows: auto auto auto 1fr auto;
  height: 100vh;
  padding: 16px 18px 0;
  background: var(--bg-panel);
  border-right: 1px solid var(--stroke);
  overflow: hidden;
}

/* Brand */
.brand {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 4px 4px 18px;
  border-bottom: 1px solid var(--stroke);
}

.brand-mark {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  color: var(--accent);
  background: var(--bg-elevated);
  border: 1px solid var(--stroke-accent);
  border-radius: 8px;
  animation: brand-spin 18s linear infinite;
}
.brand-mark svg { width: 16px; height: 16px; }
@keyframes brand-spin { to { transform: rotate(360deg); } }

.brand-text { line-height: 1.15; }
.brand-name {
  font-family: var(--font-display);
  font-size: 20px;
  letter-spacing: -0.01em;
  color: var(--ink);
}
.brand-tag {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
.brand-settings {
  appearance: none;
  border: 1px solid var(--stroke);
  background: var(--bg-elevated);
  color: var(--ink-muted);
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: color 0.2s var(--ease-gentle), border-color 0.2s var(--ease-gentle), background 0.2s var(--ease-gentle);
}
.brand-settings:hover { color: var(--ink); border-color: var(--stroke-accent); background: var(--bg-hover); }
.brand-settings svg { width: 14px; height: 14px; }

/* Status pills (compact horizontal bar) */
.status-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 12px 0;
  border-bottom: 1px solid var(--stroke);
}
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border-radius: 100px;
  background: var(--bg-elevated);
  border: 1px solid var(--stroke);
  font-size: 11px;
  color: var(--ink-muted);
}
.status-pill-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

/* Legacy status-row (kept for compatibility) */
.status-row {
  display: grid;
  grid-template-columns: auto auto 1fr;
  align-items: center;
  gap: 10px;
  padding: 6px 4px;
  font-size: 12.5px;
  color: var(--ink-muted);
}

.status-label {
  color: var(--ink);
  font-weight: 500;
}

.status-meta {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--ink-dim);
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ink-faint);
  box-shadow: 0 0 0 3px transparent;
  transition: background 0.4s var(--ease-gentle), box-shadow 0.4s var(--ease-gentle);
}
.status-dot[data-state="connecting"] {
  background: var(--warn);
  box-shadow: 0 0 0 3px rgba(228, 182, 96, 0.14);
  animation: dot-breathe 1.4s ease-in-out infinite;
}
.status-dot[data-state="connected"] {
  background: var(--positive);
  box-shadow: 0 0 0 3px var(--positive-dim);
}
.status-dot[data-state="error"] {
  background: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-dim);
}
@keyframes dot-breathe {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.85); }
}

/* Agent-install button */
.install-group {
  padding: 14px 0;
  border-bottom: 1px solid var(--stroke);
}
.install-btn {
  width: 100%;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--stroke-accent);
  background: linear-gradient(135deg, var(--accent-dim), transparent 70%);
  color: var(--ink);
  cursor: pointer;
  font: 500 12.5px/1 var(--font-body);
  letter-spacing: 0.01em;
  text-align: left;
  transition: background 0.2s var(--ease-gentle), border-color 0.2s var(--ease-gentle), transform 0.15s var(--ease-spring), box-shadow 0.2s var(--ease-gentle);
  position: relative;
  overflow: hidden;
}
.install-btn::before {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 0% 0%, var(--accent-glow), transparent 50%);
  opacity: 0.6;
  pointer-events: none;
}
.install-btn:hover {
  border-color: var(--accent);
  transform: translateY(-0.5px);
  box-shadow: 0 6px 22px -8px var(--accent-glow);
}
.install-btn:active { transform: translateY(0); }
.install-icon { width: 14px; height: 14px; color: var(--accent-soft); position: relative; z-index: 1; }
.install-label { color: var(--ink); position: relative; z-index: 1; }
.install-hint {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-dim);
  position: relative;
  z-index: 1;
}
.install-btn.is-copied {
  border-color: rgba(106, 211, 136, 0.45);
  background: linear-gradient(135deg, var(--positive-dim), transparent 70%);
}
.install-btn.is-copied .install-icon,
.install-btn.is-copied .install-hint { color: var(--positive); }

/* API key group */
.api-key-group {
  display: grid;
  gap: 8px;
  padding: 14px 0;
  border-bottom: 1px solid var(--stroke);
}
.api-key-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 0 4px;
}
.api-key-status {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.api-key-status[data-state="saved"] { color: var(--positive); }
.api-key-status[data-state="dirty"] { color: var(--warn); }
.api-key-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  padding: 0 4px;
}
.api-key-input {
  height: 32px;
  padding: 0 10px;
  border-radius: 6px;
  border: 1px solid var(--stroke);
  background: var(--bg-inset);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 11.5px;
  letter-spacing: 0.02em;
  transition: border-color 0.2s var(--ease-gentle), background 0.2s var(--ease-gentle);
  min-width: 0;
}
.api-key-input:focus {
  outline: none;
  border-color: var(--stroke-accent);
  background: var(--bg-panel);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.api-key-input::placeholder { color: var(--ink-faint); }
.api-key-btn {
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--stroke);
  background: var(--bg-elevated);
  color: var(--ink);
  border-radius: 6px;
  font: 500 11.5px/1 var(--font-body);
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background 0.2s var(--ease-gentle), border-color 0.2s var(--ease-gentle), color 0.2s var(--ease-gentle);
}
.api-key-btn:hover { background: var(--bg-hover); border-color: var(--stroke-strong); }
.api-key-btn.is-saved {
  color: var(--positive);
  border-color: rgba(106, 211, 136, 0.24);
  background: var(--positive-dim);
}
.api-key-hint {
  font-family: var(--font-mono);
  font-size: 10px;
  line-height: 1.4;
  color: var(--ink-faint);
  padding: 0 4px;
}
.api-key-hint a { color: var(--accent-soft); text-decoration: none; }
.api-key-hint a:hover { text-decoration: underline; }

/* Control well (mic + actions) */
.control-well {
  padding: 14px 4px 14px;
  border-bottom: 1px solid var(--stroke);
}

.mic-stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding-bottom: 8px;
}

.mic-btn {
  position: relative;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 1px solid var(--stroke-strong);
  background: linear-gradient(180deg, var(--bg-elevated), var(--bg-panel));
  color: var(--ink-muted);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: color 0.25s var(--ease-gentle),
              border-color 0.25s var(--ease-gentle),
              transform 0.18s var(--ease-spring),
              box-shadow 0.3s var(--ease-gentle);
  overflow: visible;
}
.mic-btn:hover:not(:disabled) {
  color: var(--accent-soft);
  border-color: var(--stroke-accent);
  transform: translateY(-1px);
  box-shadow: 0 10px 30px -10px var(--accent-glow);
}
.mic-btn:active:not(:disabled) { transform: translateY(0) scale(0.97); }
.mic-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.mic-icon {
  width: 22px;
  height: 22px;
  position: relative;
  z-index: 2;
  transition: color 0.2s var(--ease-gentle);
}

.mic-ring {
  position: absolute;
  inset: -1px;
  border-radius: 50%;
  border: 1px solid var(--accent);
  opacity: 0;
  pointer-events: none;
}
.mic-btn.active {
  color: var(--accent-soft);
  border-color: var(--accent);
  background: linear-gradient(180deg, var(--bg-elevated), rgba(99, 145, 255, 0.06));
  box-shadow: 0 0 0 1px var(--accent-glow), 0 12px 34px -12px var(--accent-glow);
}
.mic-btn.active .mic-ring { animation: mic-pulse 2.4s var(--ease-gentle) infinite; }
.mic-btn.active .ring-2 { animation-delay: 0.8s; }
.mic-btn.active .ring-3 { animation-delay: 1.6s; }

@keyframes mic-pulse {
  0%   { transform: scale(1);   opacity: 0.6; }
  100% { transform: scale(1.9); opacity: 0; }
}

.waveform {
  width: 240px;
  height: 28px;
  opacity: 0.55;
  transition: opacity 0.3s var(--ease-gentle);
}
.mic-btn.active ~ .waveform { opacity: 1; }

.voice-status {
  font-size: 12px;
  color: var(--ink-muted);
  text-align: center;
  letter-spacing: 0.01em;
  min-height: 16px;
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  font: 500 12.5px/1 var(--font-body);
  letter-spacing: 0.01em;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  transition: background 0.2s var(--ease-gentle), border-color 0.2s var(--ease-gentle), color 0.2s var(--ease-gentle), transform 0.15s var(--ease-spring);
  font-family: var(--font-body);
}
.btn:hover { transform: translateY(-0.5px); }
.btn:active { transform: translateY(0); }
.btn svg { width: 12px; height: 12px; }
.btn[hidden] { display: none !important; }

.btn-primary {
  background: var(--accent);
  color: #0a0d18;
  box-shadow: 0 4px 18px -6px var(--accent-glow);
}
.btn-primary:hover { background: var(--accent-soft); }

.btn-ghost {
  background: var(--bg-elevated);
  color: var(--ink);
  border-color: var(--stroke);
}
.btn-ghost:hover { background: var(--bg-hover); border-color: var(--stroke-strong); }
.btn-ghost:disabled { opacity: 0.55; cursor: wait; }
.btn-ghost.is-done {
  color: var(--positive);
  background: var(--positive-dim);
  border-color: rgba(106, 211, 136, 0.24);
  cursor: default;
}

/* ------------------------------------------------------------
   Transcript — now the dominant sidebar surface
   ------------------------------------------------------------ */
.transcript {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
  padding: 14px 0 10px;
}

.transcript-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 0 4px 10px;
}
.transcript-hint {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-faint);
}

.transcript-scroll {
  overflow-y: auto;
  overflow-x: hidden;
  padding: 2px 4px 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--stroke-strong) transparent;
}
.transcript-scroll::-webkit-scrollbar { width: 6px; }
.transcript-scroll::-webkit-scrollbar-thumb { background: var(--stroke-strong); border-radius: 3px; }
.transcript-scroll::-webkit-scrollbar-track { background: transparent; }

.transcript-entry {
  position: relative;
  padding: 10px 12px 11px;
  margin-bottom: 8px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  line-height: 1.55;
  word-break: break-word;
  overflow-wrap: anywhere;
  animation: bubble-rise 0.38s var(--ease-spring) both;
}
@keyframes bubble-rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.transcript-entry .role {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-dim);
  margin-bottom: 4px;
}

.transcript-entry.user {
  background: var(--accent-dim);
  border: 1px solid var(--stroke-accent);
  color: var(--ink);
}
.transcript-entry.user .role { color: var(--accent-soft); }

.transcript-entry.assistant {
  background: var(--bg-elevated);
  border: 1px solid var(--stroke);
  color: var(--ink);
}

.transcript-entry.interrupted { opacity: 0.55; }
.transcript-entry.interrupted::after {
  content: ' — interrupted';
  color: var(--warn);
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  margin-left: 4px;
}

.transcript-entry.live::after {
  content: '';
  display: inline-block;
  width: 5px;
  height: 12px;
  margin-left: 3px;
  vertical-align: -2px;
  background: currentColor;
  opacity: 0.45;
  animation: caret-blink 0.9s steps(2) infinite;
}
@keyframes caret-blink { 50% { opacity: 0; } }

/* Sidebar footer (activity — collapsed by default) */
.sidebar-footer {
  padding: 0 0 10px;
  border-top: 1px solid var(--stroke);
  min-height: 0;
}

.activity-toggle {
  width: 100%;
  appearance: none;
  background: transparent;
  border: 0;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 10px 4px;
  cursor: pointer;
  color: var(--ink-muted);
  transition: color 0.18s var(--ease-gentle);
}
.activity-toggle:hover { color: var(--ink); }
.activity-toggle .eyebrow { text-align: left; }
.activity-count {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--ink-dim);
  padding: 2px 6px;
  background: var(--bg-inset);
  border-radius: 100px;
  min-width: 20px;
  text-align: center;
}
.activity-chevron {
  width: 12px;
  height: 12px;
  color: var(--ink-dim);
  transition: transform 0.2s var(--ease-gentle);
}
.activity-toggle[aria-expanded="true"] .activity-chevron { transform: rotate(180deg); }

.tool-log {
  max-height: 160px;
  overflow-y: auto;
  padding: 2px 4px 6px;
  scrollbar-width: thin;
  scrollbar-color: var(--stroke-strong) transparent;
}
.tool-log[hidden] { display: none; }
.tool-log::-webkit-scrollbar { width: 6px; }
.tool-log::-webkit-scrollbar-thumb { background: var(--stroke-strong); border-radius: 3px; }

.tool-entry {
  display: grid;
  grid-template-columns: 14px 1fr auto;
  gap: 8px;
  align-items: baseline;
  padding: 6px 4px;
  font-size: 11.5px;
  font-family: var(--font-mono);
  color: var(--ink-muted);
  border-bottom: 1px solid var(--stroke);
  animation: bubble-rise 0.3s var(--ease-spring) both;
}
.tool-entry:last-child { border-bottom: none; }
.tool-entry .tool-icon { font-size: 10px; color: var(--accent); }
.tool-entry .tool-name { color: var(--ink); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool-entry .tool-text { font-size: 10.5px; color: var(--ink-dim); }
.tool-entry.is-error .tool-icon { color: var(--danger); }
.tool-entry.is-system .tool-icon { color: var(--positive); }
.tool-entry-empty {
  color: var(--ink-faint);
  text-align: center;
  font-family: var(--font-mono);
  font-size: 10.5px;
  border: none !important;
  padding: 14px 0;
}

/* ------------------------------------------------------------
   Canvas (main)
   ------------------------------------------------------------ */
.canvas {
  overflow: hidden;
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100vh;
}

.canvas-header {
  padding: 26px 40px 18px;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 1px solid var(--stroke);
  background: linear-gradient(180deg, var(--bg-app), transparent);
}

.canvas-title { display: grid; gap: 6px; }
.canvas-heading {
  font-family: var(--font-display);
  font-size: 36px;
  line-height: 1;
  font-weight: 400;
  letter-spacing: -0.02em;
  color: var(--ink);
  margin: 0;
}

.canvas-hints {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
  max-width: 50%;
}
.hint-chip {
  font-size: 11.5px;
  color: var(--ink-muted);
  padding: 4px 10px;
  border: 1px solid var(--stroke);
  border-radius: 100px;
  background: var(--bg-panel);
}
.hint-chip code { background: transparent; border: none; padding: 0; }

.canvas-grid {
  overflow-y: auto;
  overflow-x: hidden;
  padding: 24px 40px 40px;
  scrollbar-width: thin;
  scrollbar-color: var(--stroke-strong) transparent;
}
.canvas-grid::-webkit-scrollbar { width: 10px; }
.canvas-grid::-webkit-scrollbar-thumb { background: var(--stroke-strong); border-radius: 5px; }

/* Empty state */
.empty-state {
  max-width: 480px;
  margin: 80px auto 0;
  text-align: center;
  animation: fade-up 0.7s var(--ease-spring) both;
}
@keyframes fade-up { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: translateY(0); } }

.empty-visual {
  position: relative;
  width: 120px;
  height: 120px;
  margin: 0 auto 28px;
}
.empty-core {
  position: absolute;
  inset: calc(50% - 4px);
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 24px var(--accent-glow);
}
.empty-orbit {
  position: absolute;
  inset: 0;
  border: 1px solid var(--stroke-accent);
  border-radius: 50%;
  animation: orbit-spin 14s linear infinite;
}
.empty-orbit:nth-child(2) { inset: 14px; border-color: rgba(99, 145, 255, 0.18); animation-duration: 9s; animation-direction: reverse; }
.empty-orbit:nth-child(3) { inset: 28px; border-color: rgba(99, 145, 255, 0.1); animation-duration: 6s; }
@keyframes orbit-spin { to { transform: rotate(360deg); } }

.empty-title {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 400;
  letter-spacing: -0.01em;
  color: var(--ink);
  margin: 0 0 10px;
}
.empty-body {
  color: var(--ink-muted);
  font-size: 14px;
  line-height: 1.6;
  margin: 0 0 24px;
}
.empty-meta {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
  text-transform: uppercase;
}

/* ------------------------------------------------------------
   Data cards
   ------------------------------------------------------------ */
.data-card {
  background: var(--bg-panel);
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  margin-bottom: 14px;
  overflow: hidden;
  animation: card-in 0.5s var(--ease-spring) both;
  transform-origin: right center;
}
@keyframes card-in {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

.data-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--stroke);
  background: var(--bg-inset);
}

.data-card-title {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
  flex: 1;
}
.data-card-title .title-name {
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.data-card-title .title-badge {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-dim);
}

.data-card-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}
.data-card-server {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 3px 8px;
  background: var(--accent-dim);
  color: var(--accent-soft);
  border: 1px solid var(--stroke-accent);
  border-radius: 100px;
}

.data-card-body { padding: 0; position: relative; }
.data-card-pane[hidden] { display: none; }

/* Segmented view/JSON toggle */
.view-toggle {
  display: inline-flex;
  background: var(--bg-inset);
  border: 1px solid var(--stroke);
  border-radius: 7px;
  padding: 2px;
  gap: 2px;
}
.view-toggle-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--ink-dim);
  font: 500 10.5px/1 var(--font-mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 5px 10px;
  border-radius: 5px;
  cursor: pointer;
  transition: background 0.18s var(--ease-gentle), color 0.18s var(--ease-gentle);
}
.view-toggle-btn:hover { color: var(--ink); }
.view-toggle-btn.is-active {
  background: var(--bg-elevated);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--stroke-strong);
}

/* JSON pane */
.json-pane {
  padding: 14px 16px 18px;
}
.json-block {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--ink-muted);
  background: var(--bg-inset);
  border: 1px solid var(--stroke);
  border-radius: 8px;
  padding: 12px 14px;
  max-height: 420px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  scrollbar-width: thin;
  scrollbar-color: var(--stroke-strong) transparent;
}
.json-block::-webkit-scrollbar { width: 6px; height: 6px; }
.json-block::-webkit-scrollbar-thumb { background: var(--stroke-strong); border-radius: 3px; }
.json-block .k { color: var(--accent-soft); }
.json-block .s { color: var(--positive); }
.json-block .n { color: var(--warn); }

/* Table variant */
.data-table-wrap {
  max-height: 420px;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--stroke-strong) transparent;
}
.data-table-wrap::-webkit-scrollbar { height: 8px; width: 8px; }
.data-table-wrap::-webkit-scrollbar-thumb { background: var(--stroke-strong); border-radius: 4px; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}
.data-table thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  text-align: left;
  padding: 10px 14px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--stroke);
  font: 500 10px/1 var(--font-mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
.data-table tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--stroke);
  color: var(--ink);
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: background 0.15s var(--ease-gentle);
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--bg-hover); }
.data-table td[title] { cursor: help; }
.data-table tfoot td {
  padding: 10px 14px;
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--ink-dim);
  border-top: 1px solid var(--stroke);
  background: var(--bg-inset);
}

/* Status card */
.status-card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 16px;
  align-items: center;
  padding: 18px 20px;
}
.status-card .status-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 18px;
}
.status-card .status-icon.success {
  background: var(--positive-dim);
  color: var(--positive);
  border: 1px solid rgba(106, 211, 136, 0.22);
}
.status-card .status-icon.error {
  background: var(--danger-dim);
  color: var(--danger);
  border: 1px solid rgba(239, 103, 112, 0.22);
}
.status-card .status-icon.info {
  background: var(--accent-dim);
  color: var(--accent-soft);
  border: 1px solid var(--stroke-accent);
}

.status-card-text .primary {
  font-size: 14px;
  font-weight: 500;
  color: var(--ink);
  margin-bottom: 3px;
}
.status-card-text .secondary {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--ink-muted);
  word-break: break-word;
}

/* Chart card */
.chart-card {
  padding: 22px;
  display: grid;
  gap: 14px;
}
.chart-card .chart-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
.chart-card .chart-json {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--ink-muted);
  background: var(--bg-inset);
  border: 1px solid var(--stroke);
  border-radius: 8px;
  padding: 12px 14px;
  max-height: 320px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.55;
  scrollbar-width: thin;
  scrollbar-color: var(--stroke-strong) transparent;
}
.chart-card .chart-json::-webkit-scrollbar { width: 6px; height: 6px; }
.chart-card .chart-json::-webkit-scrollbar-thumb { background: var(--stroke-strong); border-radius: 3px; }
.chart-card .chart-json .k { color: var(--accent-soft); }
.chart-card .chart-json .s { color: var(--positive); }
.chart-card .chart-json .n { color: var(--warn); }

/* Dashboard card (Tableau rendering) */
.dash-card {
  padding: 22px 24px 18px;
  display: grid;
  gap: 22px;
}
.dash-head { display: grid; gap: 4px; }
.dash-eyebrow {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent-soft);
}
.dash-title {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 400;
  letter-spacing: -0.01em;
  color: var(--ink);
  line-height: 1.15;
}
.dash-updated {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--ink-faint);
  letter-spacing: 0.04em;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
}
.metric-card {
  background: var(--bg-inset);
  border: 1px solid var(--stroke);
  border-radius: 10px;
  padding: 14px 14px 12px;
  display: grid;
  gap: 4px;
  position: relative;
  overflow: hidden;
  transition: border-color 0.2s var(--ease-gentle), transform 0.2s var(--ease-spring);
}
.metric-card:hover { border-color: var(--stroke-accent); transform: translateY(-1px); }
.metric-card::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 100% 0%, var(--accent-dim), transparent 60%);
  pointer-events: none;
  opacity: 0.5;
}
.metric-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
.metric-value {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 400;
  line-height: 1.1;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.metric-delta {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-muted);
}
.metric-delta.pos { color: var(--positive); }
.metric-delta.neg { color: var(--danger); }

.stage-chart { display: grid; gap: 10px; }
.stage-chart-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}
.stage-chart-sub {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
  text-transform: uppercase;
}
.stage-svg { display: block; }
.stage-svg .stage-label {
  font-family: var(--font-body);
  font-size: 11.5px;
  fill: var(--ink-muted);
}
.stage-svg .stage-bar-bg { fill: rgba(255, 255, 255, 0.04); }
.stage-svg .stage-bar {
  fill: url(#stage-gradient);
  fill: var(--accent);
  opacity: 0.82;
}
.stage-svg .stage-value {
  font-family: var(--font-mono);
  font-size: 11px;
  fill: var(--ink);
  font-variant-numeric: tabular-nums;
}

/* Empty / fallback pane (shown when visual can't render) */
.empty-pane {
  padding: 32px 24px;
  text-align: center;
  display: grid;
  gap: 8px;
  justify-items: center;
}
.empty-pane-title {
  font-family: var(--font-display);
  font-size: 18px;
  color: var(--ink);
  letter-spacing: -0.01em;
}
.empty-pane-body {
  font-size: 13px;
  color: var(--ink-muted);
  max-width: 360px;
  line-height: 1.55;
}
.empty-pane-body strong {
  color: var(--accent-soft);
  font-weight: 500;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: var(--bg-inset);
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid var(--stroke);
}

/* Text card */
.text-card {
  padding: 18px 22px;
  font-size: 13px;
  line-height: 1.65;
  color: var(--ink);
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

/* Tool call card (in-flight) */
.tool-call-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 14px 18px;
  background: var(--bg-panel);
  border: 1px dashed var(--stroke-accent);
  border-radius: var(--radius);
  margin-bottom: 14px;
  animation: card-in 0.4s var(--ease-spring) both;
}
.tool-call-card .call-spinner {
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--stroke-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.tool-call-card .call-name {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink);
  font-weight: 500;
}
.tool-call-card .call-meta {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--ink-dim);
  margin-top: 2px;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tool-call-card .call-label {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-soft);
}
.tool-call-card.done {
  border-style: solid;
  border-color: var(--stroke);
  opacity: 0.6;
}
.tool-call-card.done .call-spinner {
  border-color: var(--positive);
  border-top-color: var(--positive);
  animation: none;
}

/* ------------------------------------------------------------
   Responsive fallback
   ------------------------------------------------------------ */
@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--stroke); height: auto; max-height: 60vh; }
  .canvas-header { padding: 20px 20px 14px; }
  .canvas-heading { font-size: 28px; }
  .canvas-grid { padding: 16px 20px 24px; }
}

/* ------------------------------------------------------------
   Settings modal
   ------------------------------------------------------------ */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 12, 0.72);
  backdrop-filter: blur(6px);
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  animation: modal-fade 0.22s var(--ease-gentle);
}
.modal-backdrop[hidden] { display: none; }
@keyframes modal-fade { from { opacity: 0; } to { opacity: 1; } }

.modal {
  width: 100%;
  max-width: 560px;
  max-height: calc(100vh - 48px);
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: var(--bg-panel);
  border: 1px solid var(--stroke-strong);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px -20px rgba(0, 0, 0, 0.6);
  overflow: hidden;
  animation: modal-rise 0.3s var(--ease-spring);
}
@keyframes modal-rise { from { opacity: 0; transform: translateY(10px) scale(0.98); } to { opacity: 1; transform: none; } }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 22px 14px;
  border-bottom: 1px solid var(--stroke);
}
.modal-title {
  font-family: var(--font-display);
  font-size: 24px;
  margin: 4px 0 0;
  letter-spacing: -0.01em;
  font-weight: 400;
  color: var(--ink);
}
.modal-close {
  appearance: none;
  border: 1px solid var(--stroke);
  background: var(--bg-elevated);
  color: var(--ink-muted);
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: color 0.2s var(--ease-gentle), border-color 0.2s var(--ease-gentle);
}
.modal-close:hover { color: var(--ink); border-color: var(--stroke-strong); }
.modal-close svg { width: 12px; height: 12px; }

.modal-body {
  overflow-y: auto;
  padding: 18px 22px 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--stroke-strong) transparent;
}
.modal-body::-webkit-scrollbar { width: 6px; }
.modal-body::-webkit-scrollbar-thumb { background: var(--stroke-strong); border-radius: 3px; }

.settings-section {
  padding: 12px 0 16px;
  border-bottom: 1px solid var(--stroke);
  display: grid;
  gap: 12px;
}
.settings-section:last-child { border-bottom: none; }
.settings-section-head h3 {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 400;
  color: var(--ink);
  margin: 0 0 4px;
  letter-spacing: -0.01em;
}
.settings-section-head p {
  font-size: 12.5px;
  color: var(--ink-muted);
  margin: 0;
  line-height: 1.5;
}

.field {
  display: grid;
  gap: 5px;
}
.field-label {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
.field-label .optional {
  font-family: var(--font-display);
  font-style: italic;
  font-size: 11px;
  color: var(--ink-faint);
  text-transform: none;
  letter-spacing: 0;
  margin-left: 4px;
}
.field input {
  height: 34px;
  padding: 0 12px;
  border-radius: 7px;
  border: 1px solid var(--stroke);
  background: var(--bg-inset);
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 12px;
  transition: border-color 0.2s var(--ease-gentle), background 0.2s var(--ease-gentle), box-shadow 0.2s var(--ease-gentle);
}
.field input:focus {
  outline: none;
  border-color: var(--stroke-accent);
  background: var(--bg-panel);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.field input::placeholder { color: var(--ink-faint); }
.field-hint {
  font-size: 11px;
  color: var(--ink-dim);
}
.field-hint a { color: var(--accent-soft); text-decoration: none; }
.field-hint a:hover { text-decoration: underline; }
.field-hint code {
  font-size: 0.95em;
  padding: 0 4px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 22px 18px;
  border-top: 1px solid var(--stroke);
  background: var(--bg-panel);
}
.modal-footer .btn { padding: 8px 16px; }
