/* ==========================================================================
   CAI.CI Chat: visual design system
   Inherits the dark futuristic aesthetic of the main cai.ci site.
   ========================================================================== */

:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #0d0d14;
  --bg-card: rgba(14, 14, 22, 0.85);
  --bg-card-solid: #0e0e16;
  --border-subtle: rgba(56, 189, 248, 0.08);
  --border-soft: rgba(56, 189, 248, 0.16);
  --border-glow: rgba(56, 189, 248, 0.32);

  --text-primary: #e8eaed;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --text-dim: #4b5563;

  --cyan-400: #22d3ee;
  --cyan-500: #06b6d4;
  --cyan-600: #0891b2;
  --teal-400: #2dd4bf;
  --teal-500: #14b8a6;
  --blue-500: #3b82f6;

  --gold-400: #fbbf24;
  --gold-500: #f59e0b;
  --gold-600: #d97706;
  --amber-glow: rgba(251, 191, 36, 0.3);

  --font-display: 'Orbitron', sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

  --sidebar-width: 260px;
  --telemetry-width: 360px;
  --header-height: 64px;
  --chat-max-width: 780px;

  --battery-cycle: 8s;
}

/* ==========================================================================
   RESET
   ========================================================================== */

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-body);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow: hidden;
}

button {
  font-family: inherit;
  cursor: pointer;
  background: none;
  border: none;
  color: inherit;
}

button:focus-visible {
  outline: 2px solid var(--cyan-400);
  outline-offset: 2px;
}

textarea, input {
  font-family: inherit;
  color: inherit;
}

/* ==========================================================================
   ANIMATED BACKGROUND (ported from main site)
   ========================================================================== */

.bg-canvas {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.bg-gradient {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 60% at 50% 0%, rgba(6, 182, 212, 0.06) 0%, transparent 60%),
    radial-gradient(ellipse 60% 50% at 20% 80%, rgba(59, 130, 246, 0.04) 0%, transparent 50%),
    radial-gradient(ellipse 60% 50% at 80% 60%, rgba(20, 184, 166, 0.04) 0%, transparent 50%),
    var(--bg-primary);
  animation: bg-shift 20s ease-in-out infinite alternate;
}

@keyframes bg-shift {
  0% { opacity: 1; }
  50% { opacity: 0.85; }
  100% { opacity: 1; }
}

.bg-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(56, 189, 248, 0.02) 1px, transparent 1px),
    linear-gradient(90deg, rgba(56, 189, 248, 0.02) 1px, transparent 1px);
  background-size: 60px 60px;
  animation: grid-pulse 8s ease-in-out infinite;
}

@keyframes grid-pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 0.8; }
}

.bg-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  animation: orb-drift 25s ease-in-out infinite;
}

.bg-orb--1 { width: 400px; height: 400px; background: rgba(6, 182, 212, 0.05); top: 10%; left: -5%; animation-delay: 0s; animation-duration: 30s; }
.bg-orb--2 { width: 300px; height: 300px; background: rgba(59, 130, 246, 0.04); top: 60%; right: -5%; animation-delay: -10s; animation-duration: 25s; }
.bg-orb--3 { width: 250px; height: 250px; background: rgba(20, 184, 166, 0.04); bottom: 5%; left: 30%; animation-delay: -5s; animation-duration: 22s; }

@keyframes orb-drift {
  0%, 100% { transform: translate(0, 0) scale(1); }
  25% { transform: translate(30px, -20px) scale(1.05); }
  50% { transform: translate(-20px, 30px) scale(0.95); }
  75% { transform: translate(20px, 20px) scale(1.02); }
}

/* ==========================================================================
   HEADER (injected by nav.js)
   ========================================================================== */

.site-header {
  height: var(--header-height);
}

/* ==========================================================================
   APP SHELL
   ========================================================================== */

.app {
  position: fixed;
  top: var(--header-height);
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr var(--telemetry-width);
  z-index: 1;
  isolation: isolate;
}

.app[data-state="loading"] .chat,
.app[data-state="loading"] .telemetry,
.app[data-state="loading"] .sidebar {
  opacity: 0;
}

.app > * {
  opacity: 1;
  transition: opacity 0.4s ease;
}

/* ==========================================================================
   SIDEBAR
   ========================================================================== */

.sidebar {
  display: flex;
  flex-direction: column;
  background: rgba(10, 10, 15, 0.7);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-right: 1px solid var(--border-subtle);
  overflow: hidden;
}

.sidebar__header {
  padding: 1rem;
  border-bottom: 1px solid var(--border-subtle);
}

.sidebar__new {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.75rem 1rem;
  background: linear-gradient(135deg, rgba(34, 211, 238, 0.12) 0%, rgba(45, 212, 191, 0.12) 100%);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  color: var(--cyan-400);
  font-family: var(--font-display);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.sidebar__new:hover {
  border-color: var(--border-glow);
  background: linear-gradient(135deg, rgba(34, 211, 238, 0.18) 0%, rgba(45, 212, 191, 0.18) 100%);
}

.sidebar__list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
}

.sidebar__list::-webkit-scrollbar {
  width: 4px;
}
.sidebar__list::-webkit-scrollbar-thumb {
  background: rgba(56, 189, 248, 0.15);
  border-radius: 2px;
}

.sidebar__empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.8rem;
}

.sidebar__item {
  display: block;
  padding: 0.75rem 0.875rem;
  margin-bottom: 0.25rem;
  border-radius: 8px;
  color: var(--text-secondary);
  font-size: 0.85rem;
  line-height: 1.4;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar__item:hover {
  background: rgba(34, 211, 238, 0.05);
  color: var(--text-primary);
}

.sidebar__item.is-active {
  background: rgba(34, 211, 238, 0.08);
  border-color: var(--border-soft);
  color: var(--text-primary);
}

.sidebar__item-date {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.sidebar__footer {
  padding: 0.875rem 1rem;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.sidebar__identity {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: var(--font-display);
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.sidebar__identity-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--teal-400);
  box-shadow: 0 0 6px rgba(45, 212, 191, 0.6);
  animation: identity-pulse 3s ease-in-out infinite;
}

@keyframes identity-pulse {
  0%, 100% { opacity: 0.6; }
  50% { opacity: 1; }
}

.sidebar__upgrade {
  padding: 0.5rem 0.75rem;
  background: rgba(251, 191, 36, 0.08);
  border: 1px solid rgba(251, 191, 36, 0.2);
  border-radius: 8px;
  color: var(--gold-400);
  font-size: 0.7rem;
  font-family: var(--font-display);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  transition: background 0.15s ease;
}

.sidebar__upgrade:hover {
  background: rgba(251, 191, 36, 0.14);
}

/* ==========================================================================
   CHAT AREA
   ========================================================================== */

.chat {
  display: flex;
  flex-direction: column;
  position: relative;
  min-width: 0;
  overflow: hidden;
}

.chat__header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.875rem 1.5rem;
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(10, 10, 15, 0.5);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.chat__menu {
  display: none;
  padding: 0.5rem;
  border-radius: 6px;
  color: var(--text-secondary);
}

.chat__menu:hover { color: var(--cyan-400); }

.chat__menu--right { margin-left: auto; }

.chat__title {
  flex: 1;
  min-width: 0;
}

.chat__title-label {
  font-family: var(--font-display);
  font-size: 0.6rem;
  font-weight: 500;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.15rem;
}

.chat__title-name {
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.05em;
}

.chat__title-model {
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--text-muted);
  margin-left: 0.5rem;
}

/* ---------- WELCOME PANEL ---------- */

.welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem 1.5rem;
  overflow-y: auto;
}

.welcome[hidden] { display: none; }

.welcome__brand {
  text-align: center;
  margin-bottom: 2rem;
}

.welcome__logo {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(2.5rem, 6vw, 4rem);
  letter-spacing: 0.08em;
  background: linear-gradient(135deg, var(--cyan-400) 0%, var(--teal-400) 40%, var(--cyan-500) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  line-height: 1;
  margin-bottom: 0.5rem;
}

.welcome__tag {
  font-family: var(--font-display);
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.welcome__copy {
  max-width: 560px;
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.95rem;
  line-height: 1.75;
  margin-bottom: 2.5rem;
}

.welcome__copy p {
  margin-bottom: 1rem;
}

.welcome__copy p:last-child {
  margin-bottom: 0;
}

.welcome__shared {
  color: var(--text-primary);
}

.welcome__shared strong {
  color: var(--cyan-400);
  font-weight: 500;
}

.welcome__hint {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-style: italic;
}

.welcome__prompts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  width: 100%;
  max-width: 640px;
}

.welcome__prompt {
  padding: 0.875rem 1.125rem;
  background: rgba(14, 14, 22, 0.65);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  color: var(--text-secondary);
  font-size: 0.85rem;
  text-align: left;
  line-height: 1.4;
  transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.welcome__prompt:hover {
  background: rgba(34, 211, 238, 0.04);
  border-color: var(--border-soft);
  color: var(--text-primary);
  transform: translateY(-1px);
}

/* ---------- TRANSCRIPT ---------- */

.transcript {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem 1.5rem 1rem;
  scroll-behavior: smooth;
}

.transcript[hidden] { display: none; }

.transcript::-webkit-scrollbar {
  width: 6px;
}

.transcript::-webkit-scrollbar-thumb {
  background: rgba(56, 189, 248, 0.15);
  border-radius: 3px;
}

.transcript__inner {
  max-width: var(--chat-max-width);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.msg {
  display: flex;
  max-width: 100%;
  animation: msg-in 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.msg--user { justify-content: flex-end; }
.msg--assistant { justify-content: flex-start; }

.msg__bubble {
  padding: 0.875rem 1.125rem;
  border-radius: 16px;
  max-width: 85%;
  line-height: 1.6;
  font-size: 0.95rem;
  word-wrap: break-word;
  position: relative;
}

.msg--user .msg__bubble {
  background: rgba(34, 211, 238, 0.08);
  border: 1px solid rgba(34, 211, 238, 0.18);
  color: var(--text-primary);
  border-bottom-right-radius: 4px;
}

.msg--assistant .msg__bubble {
  background: rgba(14, 14, 22, 0.7);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.msg__bubble p {
  margin-bottom: 0.75rem;
}

.msg__bubble p:last-child {
  margin-bottom: 0;
}

.msg__bubble code {
  background: rgba(34, 211, 238, 0.08);
  border: 1px solid rgba(34, 211, 238, 0.15);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-family: 'SF Mono', Monaco, Consolas, monospace;
  font-size: 0.85em;
  color: var(--cyan-400);
}

.msg__bubble pre {
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 0.875rem 1rem;
  overflow-x: auto;
  margin: 0.75rem 0;
  position: relative;
}

.msg__bubble pre code {
  background: none;
  border: none;
  padding: 0;
  color: var(--text-primary);
  font-size: 0.85em;
  line-height: 1.5;
}

.msg__bubble strong { color: var(--cyan-400); font-weight: 600; }
.msg__bubble em { font-style: italic; color: var(--text-primary); }

.msg__meta {
  margin-top: 0.35rem;
  padding: 0 0.25rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.7rem;
  color: var(--text-muted);
  font-family: var(--font-display);
  letter-spacing: 0.08em;
}

.msg__actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.msg:hover .msg__actions { opacity: 1; }

.msg__action {
  padding: 0.25rem 0.5rem;
  font-size: 0.7rem;
  border-radius: 6px;
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
  background: rgba(14, 14, 22, 0.5);
  transition: color 0.2s ease, border-color 0.2s ease;
}

.msg__action:hover {
  color: var(--cyan-400);
  border-color: var(--border-soft);
}

/* Thinking indicator */
.msg--thinking .msg__bubble {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1.25rem;
}

.thinking-dots {
  display: flex;
  gap: 4px;
}

.thinking-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cyan-400);
  animation: thinking-pulse 1.2s ease-in-out infinite;
}

.thinking-dots span:nth-child(2) { animation-delay: 0.15s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes thinking-pulse {
  0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
  40% { opacity: 1; transform: scale(1.2); }
}

.thinking-text {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-style: italic;
}

/* ---------- COMPOSER ---------- */

.composer-wrap {
  padding: 1rem 1.5rem 1.25rem;
  background: linear-gradient(180deg, transparent 0%, rgba(10, 10, 15, 0.6) 40%, rgba(10, 10, 15, 0.95) 100%);
}

.composer {
  max-width: var(--chat-max-width);
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
  background: rgba(14, 14, 22, 0.85);
  border: 1px solid var(--border-subtle);
  border-radius: 22px;
  padding: 0.625rem 0.625rem 0.625rem 1.125rem;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  transition: border-color 0.25s ease, box-shadow 0.25s ease;
}

.composer:focus-within {
  border-color: var(--border-glow);
  box-shadow: 0 0 24px rgba(34, 211, 238, 0.08);
}

.composer__input {
  flex: 1;
  min-height: 24px;
  max-height: 200px;
  background: none;
  border: none;
  outline: none;
  resize: none;
  color: var(--text-primary);
  font-size: 0.95rem;
  line-height: 1.5;
  padding: 0.5rem 0;
}

.composer__input::placeholder {
  color: var(--text-muted);
}

.composer__send {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--cyan-400) 0%, var(--teal-400) 100%);
  color: #0a0a0f;
  transition: transform 0.15s ease, opacity 0.15s ease, box-shadow 0.2s ease;
}

.composer__send:hover:not(:disabled) {
  transform: scale(1.06);
  box-shadow: 0 0 24px rgba(34, 211, 238, 0.4);
}

.composer__send:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.composer__footer {
  max-width: var(--chat-max-width);
  margin: 0.5rem auto 0;
  padding: 0 0.5rem;
  text-align: center;
}

.composer__hint {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-family: var(--font-display);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* ==========================================================================
   TELEMETRY PANEL
   ========================================================================== */

.telemetry {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 0.875rem 0.875rem 1.25rem;
  background: rgba(10, 10, 15, 0.7);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-left: 1px solid var(--border-subtle);
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
}

.telemetry::-webkit-scrollbar {
  width: 4px;
}

.telemetry::-webkit-scrollbar-thumb {
  background: rgba(56, 189, 248, 0.15);
  border-radius: 2px;
}

.telemetry::-webkit-scrollbar-thumb:hover {
  background: rgba(56, 189, 248, 0.3);
}

/* Header */
.telemetry__header {
  text-align: center;
  padding: 0.65rem 0.5rem 0.85rem;
  border-bottom: 1px solid var(--border-subtle);
  position: relative;
  flex-shrink: 0;
}

.telemetry__header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 20%;
  right: 20%;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border-glow), transparent);
  opacity: 0;
  transition: opacity 0.5s ease;
}

.telemetry__header.is-pulsing::after {
  opacity: 1;
}

.telemetry__label {
  font-family: var(--font-display);
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}

.telemetry__state {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--cyan-400);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.telemetry__pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--cyan-400);
  box-shadow: 0 0 8px rgba(34, 211, 238, 0.8), 0 0 16px rgba(34, 211, 238, 0.4);
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 0.6; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.2); }
}

.telemetry__subtitle {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.4rem;
  font-style: italic;
}

/* Card shared */
.telem-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 0.8rem 0.9rem;
  position: relative;
  overflow: visible;
  flex-shrink: 0;
}

.telem-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border-glow), transparent);
  opacity: 0.3;
  border-top-left-radius: 12px;
  border-top-right-radius: 12px;
}

.telem-card__title {
  font-family: var(--font-display);
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.625rem;
  text-align: center;
}

.telem-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.625rem;
  flex-shrink: 0;
}

.telem-card--half {
  padding: 0.7rem 0.65rem;
  min-width: 0;
}

.telem-subtext {
  margin-top: 0.4rem;
  text-align: center;
  font-size: 0.62rem;
  color: var(--text-secondary);
  font-family: var(--font-body);
  letter-spacing: 0.04em;
  line-height: 1.4;
  word-break: break-word;
  overflow-wrap: anywhere;
  hyphens: auto;
  max-width: 100%;
}

/* ---------- CIRCUMPLEX ---------- */

.circumplex {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

.circumplex__svg {
  display: block;
  width: 100%;
  max-width: 200px;
  height: auto;
  aspect-ratio: 1 / 1;
}

#circumplex-dot {
  transition: cx 0.7s cubic-bezier(0.16, 1, 0.3, 1), cy 0.7s cubic-bezier(0.16, 1, 0.3, 1);
}

.circumplex__svg-label {
  font-family: var(--font-display);
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.18em;
  fill: rgba(148, 163, 184, 0.7);
  text-transform: uppercase;
}

.circumplex__emotion {
  margin-top: 0.4rem;
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--cyan-400);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-align: center;
}

/* Trail dots */
#circumplex-trail circle {
  transition: opacity 0.3s ease;
}

/* ---------- GAUGES ---------- */

.gauge-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.4rem;
  margin-top: 0.25rem;
}

.gauge {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.4rem 0.25rem 0.45rem;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(56, 189, 248, 0.04);
  transition: border-color 0.3s ease;
  min-width: 0;
}

.gauge.is-active {
  border-color: var(--border-soft);
}

.gauge svg {
  display: block;
  overflow: visible;
  width: 100%;
  max-width: 80px;
  height: auto;
}

.gauge__arc {
  transition: stroke-dashoffset 0.6s cubic-bezier(0.16, 1, 0.3, 1);
  filter: drop-shadow(0 0 4px currentColor);
}

.gauge__value {
  margin-top: -0.15rem;
  font-family: var(--font-display);
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}

.gauge__label {
  margin-top: 0.2rem;
  font-family: var(--font-display);
  font-size: 0.5rem;
  font-weight: 500;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  text-transform: uppercase;
  text-align: center;
  white-space: nowrap;
}

/* ---------- BATTERY (reused from main site) ---------- */

.battery {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.55rem;
}

.battery__track {
  display: flex;
  gap: 3px;
  padding: 5px;
  background: rgba(0, 0, 0, 0.4);
  border-radius: 6px;
  border: 1px solid rgba(56, 189, 248, 0.05);
  justify-content: center;
  width: 100%;
}

.battery__segment {
  flex: 1;
  max-width: 18px;
  height: 20px;
  border-radius: 2px;
  background: rgba(251, 191, 36, 0.04);
  border: 1px solid rgba(251, 191, 36, 0.08);
  position: relative;
  overflow: hidden;
}

.battery__segment-fill {
  position: absolute;
  inset: 0;
  border-radius: 1px;
  background: linear-gradient(180deg, var(--gold-400) 0%, var(--gold-600) 100%);
  box-shadow: 0 0 6px rgba(251, 191, 36, 0.3);
  opacity: 0;
  animation: seg-ignite 4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.battery__segment.is-regressed .battery__segment-fill {
  opacity: 0.15;
  background: rgba(248, 113, 113, 0.6);
  box-shadow: none;
}

.battery__segment:nth-child(1) .battery__segment-fill  { animation-delay: 0.15s; }
.battery__segment:nth-child(2) .battery__segment-fill  { animation-delay: 0.30s; }
.battery__segment:nth-child(3) .battery__segment-fill  { animation-delay: 0.45s; }
.battery__segment:nth-child(4) .battery__segment-fill  { animation-delay: 0.60s; }
.battery__segment:nth-child(5) .battery__segment-fill  { animation-delay: 0.75s; }
.battery__segment:nth-child(6) .battery__segment-fill  { animation-delay: 0.90s; }
.battery__segment:nth-child(7) .battery__segment-fill  { animation-delay: 1.05s; }
.battery__segment:nth-child(8) .battery__segment-fill  { animation-delay: 1.20s; }
.battery__segment:nth-child(9) .battery__segment-fill  { animation-delay: 1.35s; }
.battery__segment:nth-child(10) .battery__segment-fill { animation-delay: 1.50s; }
.battery__segment:nth-child(11) .battery__segment-fill { animation-delay: 1.65s; }
.battery__segment:nth-child(12) .battery__segment-fill { animation-delay: 1.80s; }
.battery__segment:nth-child(13) .battery__segment-fill { animation-delay: 1.95s; }
.battery__segment:nth-child(14) .battery__segment-fill { animation-delay: 2.10s; }

@keyframes seg-ignite {
  0% { opacity: 0; transform: scaleY(0.6); }
  60% { opacity: 1; transform: scaleY(1.05); }
  100% { opacity: 1; transform: scaleY(1); }
}

.battery__status {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.battery__level {
  font-family: var(--font-display);
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--gold-400);
}

.battery__separator {
  width: 2px;
  height: 2px;
  border-radius: 50%;
  background: var(--text-muted);
}

.battery__count {
  font-family: var(--font-display);
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  color: var(--gold-500);
}

/* ---------- PILLS (epistemic, voice) ---------- */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--border-subtle);
  background: rgba(0, 0, 0, 0.3);
  margin: 0 auto;
  font-family: var(--font-display);
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pill__label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.telem-card--half .pill {
  display: flex;
  justify-content: center;
}

.pill__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cyan-400);
  box-shadow: 0 0 4px currentColor;
}

.pill--epistemic { color: var(--cyan-400); }
.pill--epistemic.is-know { color: var(--teal-400); border-color: rgba(45, 212, 191, 0.2); }
.pill--epistemic.is-learning { color: var(--cyan-400); border-color: rgba(34, 211, 238, 0.2); }
.pill--epistemic.is-uncertain { color: var(--gold-400); border-color: rgba(251, 191, 36, 0.2); }
.pill--epistemic.is-dont_know { color: #f87171; border-color: rgba(248, 113, 113, 0.2); }
.pill--epistemic.is-out_of_scope { color: var(--text-muted); border-color: var(--border-subtle); }

.pill--voice { color: var(--cyan-400); }
.pill--voice.is-happy, .pill--voice.is-excited { color: var(--gold-400); border-color: rgba(251, 191, 36, 0.2); }
.pill--voice.is-calm, .pill--voice.is-content { color: var(--teal-400); border-color: rgba(45, 212, 191, 0.2); }
.pill--voice.is-sad, .pill--voice.is-pensive { color: #93c5fd; border-color: rgba(147, 197, 253, 0.2); }
.pill--voice.is-angry, .pill--voice.is-frustrated { color: #f87171; border-color: rgba(248, 113, 113, 0.2); }

/* ---------- TOOL LIST ---------- */

.tools-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-height: 36px;
}

.tools-empty {
  text-align: center;
  font-size: 0.72rem;
  color: var(--text-secondary);
  font-style: italic;
  padding: 0.5rem 0;
  letter-spacing: 0.02em;
}

.tool-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.55rem;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-subtle);
  font-size: 0.72rem;
  animation: msg-in 0.4s ease;
  min-width: 0;
}

.tool-item__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.tool-item--success .tool-item__dot { background: var(--teal-400); box-shadow: 0 0 4px rgba(45, 212, 191, 0.6); }
.tool-item--fail .tool-item__dot { background: #f87171; box-shadow: 0 0 4px rgba(248, 113, 113, 0.6); }

.tool-item__name {
  flex: 1;
  color: var(--text-primary);
  font-family: var(--font-display);
  font-size: 0.68rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.tool-item__lat {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.65rem;
  flex-shrink: 0;
}

/* ---------- SAPIENCE BAR ---------- */

.sapience {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  margin-bottom: 0.1rem;
}

.sapience__bar {
  flex: 1;
  min-width: 0;
  height: 10px;
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border-subtle);
  overflow: hidden;
  position: relative;
}

.sapience__fill {
  height: 100%;
  background: linear-gradient(90deg, var(--cyan-500) 0%, var(--teal-400) 50%, var(--gold-400) 100%);
  border-radius: 5px;
  width: 0%;
  transition: width 0.8s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: 0 0 8px rgba(34, 211, 238, 0.4);
}

.sapience__value {
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--cyan-400);
  width: 40px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* ==========================================================================
   TOAST
   ========================================================================== */

.toast {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  padding: 0.75rem 1.25rem;
  background: rgba(14, 14, 22, 0.95);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 0.85rem;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 200;
  animation: toast-in 0.3s ease;
}

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 20px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 90;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

/* ==========================================================================
   RESPONSIVE
   ========================================================================== */

@media (max-width: 1279px) {
  :root {
    --telemetry-width: 320px;
  }
}

@media (max-width: 1100px) {
  .app {
    grid-template-columns: var(--sidebar-width) 1fr;
  }

  .telemetry {
    position: fixed;
    top: var(--header-height);
    right: 0;
    bottom: 0;
    width: 340px;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 95;
    border-left: 1px solid var(--border-soft);
  }

  .app[data-telemetry-open="true"] .telemetry {
    transform: translateX(0);
  }

  .chat__menu--right { display: flex; align-items: center; justify-content: center; }
}

@media (max-width: 900px) {
  .chat__menu { display: flex; align-items: center; justify-content: center; }
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    top: var(--header-height);
    left: 0;
    bottom: 0;
    width: 280px;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    z-index: 95;
    border-right: 1px solid var(--border-soft);
  }

  .app[data-sidebar-open="true"] .sidebar {
    transform: translateX(0);
  }

  .welcome__prompts {
    grid-template-columns: 1fr;
  }

  .welcome__logo { font-size: 2.5rem; }
}

@media (max-width: 500px) {
  .composer-wrap { padding: 0.75rem 1rem 1rem; }
  .transcript { padding: 1rem 1rem 0.5rem; }
  .chat__header { padding: 0.75rem 1rem; }
  .chat__title-label { font-size: 0.55rem; }
  .chat__title-name { font-size: 0.9rem; }
  .chat__title-model { display: none; }
  .welcome__copy { font-size: 0.88rem; }
}

/* ==========================================================================
   ACCESSIBILITY
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
