/* James Therapist — Voice-First UI */

:root {
  --bg-primary: #0f1117;
  --bg-secondary: #1a1d25;
  --bg-tertiary: #242830;
  --bg-elevated: #2c313b;
  --text-primary: #eaedf2;
  --text-secondary: #8b919e;
  --text-muted: #555c6b;
  --accent: #7c6bf0;
  --accent-hover: #6a58e0;
  --accent-soft: rgba(124, 107, 240, 0.12);
  --accent-glow: rgba(124, 107, 240, 0.3);
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #22c55e;
  --warning: #eab308;
  --border-color: rgba(255, 255, 255, 0.06);
  --border-color-strong: rgba(255, 255, 255, 0.1);
  --header-height: 56px;
  --disclaimer-height: 32px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-full: 9999px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.25);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.3);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;

  /* Glassmorphism */
  --glass-bg: rgba(26, 29, 37, 0.6);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-blur: 20px;
  --glass-shadow: 0 8px 32px rgba(0,0,0,0.25), inset 0 1px 0 rgba(255,255,255,0.05);

  /* Ambient backgrounds */
  --ambient-idle: radial-gradient(ellipse at 50% 40%, #1a1d40 0%, #0f1117 70%);
  --ambient-active: radial-gradient(ellipse at 50% 40%, #1a1d40 0%, #111428 50%, #0f1117 100%);
  --ambient-wrapup: radial-gradient(ellipse at 50% 40%, #2a1f10 0%, #1a150d 50%, #0f1117 100%);
  --ambient-overtime: radial-gradient(ellipse at 50% 40%, #2a1010 0%, #1a0d0d 50%, #0f1117 100%);

  /* Orb sizing */
  --orb-size: 300px;
  --orb-core-size: 120px;
  --ring-1-size: 170px;
  --ring-2-size: 220px;
  --ring-3-size: 280px;
}

/* Light theme */
html.light-theme {
  --bg-primary: #f8f9fb;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f0f1f4;
  --bg-elevated: #ffffff;
  --text-primary: #1a1d25;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --accent: #6d5ce7;
  --accent-hover: #5b4bd5;
  --accent-soft: rgba(109, 92, 231, 0.08);
  --accent-glow: rgba(109, 92, 231, 0.2);
  --border-color: rgba(0, 0, 0, 0.06);
  --border-color-strong: rgba(0, 0, 0, 0.1);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.08);

  --glass-bg: rgba(255, 255, 255, 0.6);
  --glass-border: rgba(0, 0, 0, 0.06);
  --glass-shadow: 0 8px 32px rgba(0,0,0,0.06), inset 0 1px 0 rgba(255,255,255,0.8);

  --ambient-idle: radial-gradient(ellipse at 50% 40%, #e8e6f8 0%, #f8f9fb 70%);
  --ambient-active: radial-gradient(ellipse at 50% 40%, #e0ddf5 0%, #ececf8 50%, #f8f9fb 100%);
  --ambient-wrapup: radial-gradient(ellipse at 50% 40%, #f5ece0 0%, #f8f3ec 50%, #f8f9fb 100%);
  --ambient-overtime: radial-gradient(ellipse at 50% 40%, #f5e0e0 0%, #f8ecec 50%, #f8f9fb 100%);
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
}

/* Reusable glass panel */
.glass-panel {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  border-radius: var(--radius-lg);
}

/* ========================================================================
   Ambient Animated Background
   ======================================================================== */

#ambient-bg {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  transition: background 2s ease;
}

#ambient-bg.ambient-idle { background: var(--ambient-idle); }
#ambient-bg.ambient-active { background: var(--ambient-active); }
#ambient-bg.ambient-wrapup { background: var(--ambient-wrapup); }
#ambient-bg.ambient-overtime { background: var(--ambient-overtime); }

#ambient-bg::after {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(ellipse at 30% 50%, rgba(124, 107, 240, 0.03) 0%, transparent 50%),
              radial-gradient(ellipse at 70% 50%, rgba(167, 139, 250, 0.02) 0%, transparent 50%);
  animation: ambient-drift 20s ease-in-out infinite;
  pointer-events: none;
}

@keyframes ambient-drift {
  0%, 100% { transform: translate(0, 0) rotate(0deg); }
  33% { transform: translate(2%, -1%) rotate(1deg); }
  66% { transform: translate(-1%, 2%) rotate(-1deg); }
}

/* All content above ambient */
#disclaimer,
#header,
#main,
#sidebar {
  position: relative;
  z-index: 1;
}

/* ========================================================================
   Disclaimer
   ======================================================================== */

#disclaimer {
  height: var(--disclaimer-height);
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border-bottom: 1px solid var(--glass-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.02em;
  flex-shrink: 0;
}

#disclaimer a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
}

/* ========================================================================
   Header
   ======================================================================== */

#header {
  height: var(--header-height);
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border-bottom: 1px solid var(--glass-border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  flex-shrink: 0;
}

#header-center {
  flex: 1;
  text-align: center;
}

#header h1 {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

#session-timer {
  font-size: 13px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  transition: color 0.3s ease;
}

#session-timer.countdown {
  color: var(--accent);
  font-weight: 500;
}

#session-timer.phase-wrapping-up {
  color: var(--warning);
}

#session-timer.phase-overtime {
  color: var(--danger);
  font-weight: 600;
}

#session-timer.paused {
  opacity: 0.5;
  animation: timer-blink 1.5s ease-in-out infinite;
}

@keyframes timer-blink {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 0.2; }
}

.hidden { display: none !important; }

/* ========================================================================
   Buttons
   ======================================================================== */

.icon-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

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

.icon-btn.small { padding: 4px; }

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 13px;
  font-family: var(--font);
  padding: 4px 0;
}

.link-btn:hover { text-decoration: underline; }

/* ========================================================================
   Main
   ======================================================================== */

#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-y: auto;
  padding: 24px;
  gap: 24px;
}

/* Safe vertical centering: spacers collapse when content overflows */
#main::before,
#main::after {
  content: '';
  flex: 1 0 0px;
}

/* ========================================================================
   Voice Area
   ======================================================================== */

#voice-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
}

/* ========================================================================
   Orb — Enlarged (300px)
   ======================================================================== */

#orb-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

#orb {
  width: var(--orb-size);
  height: var(--orb-size);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.orb-core {
  width: var(--orb-core-size);
  height: var(--orb-core-size);
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 60px var(--accent-glow), 0 0 120px rgba(124, 107, 240, 0.15);
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.orb-ring {
  position: absolute;
  border-radius: 50%;
  border: 1.5px solid var(--accent);
  opacity: 0.15;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.ring-1 { width: var(--ring-1-size); height: var(--ring-1-size); opacity: 0.2; }
.ring-2 { width: var(--ring-2-size); height: var(--ring-2-size); opacity: 0.12; }
.ring-3 { width: var(--ring-3-size); height: var(--ring-3-size); opacity: 0.06; }

/* Countdown Ring */
.countdown-ring {
  position: absolute;
  width: 100%;
  height: 100%;
  z-index: 1;
  opacity: 0;
  transition: opacity 0.6s ease;
  pointer-events: none;
}

.countdown-ring.visible {
  opacity: 1;
}

.countdown-track {
  fill: none;
  stroke: var(--border-color-strong);
  stroke-width: 3;
}

.countdown-progress {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3;
  stroke-linecap: round;
  transition: stroke-dashoffset 1s linear, stroke 0.5s ease;
}

.countdown-ring.phase-wrapping-up .countdown-progress {
  stroke: var(--warning);
  animation: countdown-pulse 2s ease-in-out infinite;
}

.countdown-ring.phase-overtime .countdown-progress {
  stroke: var(--danger);
  animation: countdown-pulse 1s ease-in-out infinite;
}

.countdown-ring.phase-overtime .countdown-track {
  stroke: rgba(239, 68, 68, 0.15);
}

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

/* Orb states */
#orb.idle .orb-core {
  background: var(--bg-elevated);
  box-shadow: 0 0 20px rgba(124, 107, 240, 0.1);
}

#orb.idle .orb-ring { opacity: 0.05; }

#orb.listening .orb-core {
  background: var(--accent);
  box-shadow: 0 0 60px var(--accent-glow), 0 0 120px rgba(124, 107, 240, 0.15);
  animation: pulse-listen 2s ease-in-out infinite;
}

#orb.listening .ring-1 { animation: ring-pulse 2s ease-in-out infinite; }
#orb.listening .ring-2 { animation: ring-pulse 2s ease-in-out infinite 0.3s; }
#orb.listening .ring-3 { animation: ring-pulse 2s ease-in-out infinite 0.6s; }

#orb.speaking .orb-core {
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  box-shadow: 0 0 80px var(--accent-glow), 0 0 140px rgba(124, 107, 240, 0.2);
  animation: pulse-speak 0.8s ease-in-out infinite;
}

#orb.speaking .ring-1 { animation: ring-expand 0.8s ease-in-out infinite; }
#orb.speaking .ring-2 { animation: ring-expand 0.8s ease-in-out infinite 0.15s; }
#orb.speaking .ring-3 { animation: ring-expand 0.8s ease-in-out infinite 0.3s; }

#orb.connecting .orb-core {
  background: var(--warning);
  box-shadow: 0 0 30px rgba(234, 179, 8, 0.3);
  animation: pulse-connect 1s ease-in-out infinite;
}

#orb-label {
  font-size: 15px;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

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

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

@keyframes pulse-connect {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(0.95); opacity: 0.7; }
}

@keyframes ring-pulse {
  0%, 100% { transform: scale(1); opacity: 0.15; }
  50% { transform: scale(1.05); opacity: 0.25; }
}

@keyframes ring-expand {
  0%, 100% { transform: scale(1); opacity: 0.2; }
  50% { transform: scale(1.08); opacity: 0.35; }
}

/* ========================================================================
   Controls — Glass Circular Buttons
   ======================================================================== */

#controls {
  display: flex;
  gap: 12px;
  align-items: center;
}

.control-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 32px;
  border: none;
  border-radius: var(--radius-full);
  font-family: var(--font);
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s, box-shadow 0.2s;
}

.control-btn:active { transform: scale(0.97); }

.control-btn.primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 4px 20px var(--accent-glow), 0 0 40px rgba(124, 107, 240, 0.1);
}

.control-btn.primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 6px 28px var(--accent-glow), 0 0 50px rgba(124, 107, 240, 0.15);
}

.control-btn.danger {
  background: var(--danger);
  color: #fff;
  box-shadow: 0 4px 20px rgba(239, 68, 68, 0.2);
}

.control-btn.danger:hover {
  background: var(--danger-hover);
  box-shadow: 0 6px 28px rgba(239, 68, 68, 0.25);
}

.control-btn.secondary {
  width: 52px;
  height: 52px;
  padding: 0;
  border-radius: 50%;
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  color: var(--text-primary);
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  display: flex;
  align-items: center;
  justify-content: center;
}

.control-btn.secondary:hover {
  background: rgba(124, 107, 240, 0.12);
  border-color: rgba(124, 107, 240, 0.2);
}

/* ========================================================================
   Transcript — Glass Panel
   ======================================================================== */

#transcript-area {
  width: 100%;
  max-width: 640px;
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

#transcript-header {
  display: flex;
  align-items: center;
  padding: 10px 16px;
  border-bottom: 1px solid var(--glass-border);
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.transcript-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

#transcript-messages {
  max-height: 240px;
  overflow-y: auto;
  padding: 20px;
}

.transcript-msg {
  margin-bottom: 8px;
  font-size: 15px;
  line-height: 1.6;
  opacity: 0.8;
}

.transcript-msg.user {
  color: var(--text-secondary);
}

.transcript-msg.user::before {
  content: 'You: ';
  font-weight: 600;
  color: var(--text-primary);
}

.transcript-msg.assistant {
  color: var(--accent);
}

.transcript-msg.assistant::before {
  content: 'James: ';
  font-weight: 600;
}

.transcript-msg.latest {
  opacity: 1;
  font-weight: 400;
}

/* Copy button */
#copy-transcript-btn {
  color: var(--text-muted);
  transition: color 0.2s;
}

#copy-transcript-btn:hover {
  color: var(--accent);
}

#copy-transcript-btn.copied {
  color: var(--success);
}

/* ========================================================================
   Session Stats Overlay
   ======================================================================== */

#stats-overlay {
  width: 100%;
  max-width: 640px;
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  -webkit-backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  border-radius: var(--radius-lg);
  padding: 16px 20px;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.4s ease, transform 0.4s ease;
}

#stats-overlay.visible {
  opacity: 1;
  transform: translateY(0);
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  text-align: center;
}

.stat-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-value {
  font-size: 22px;
  font-weight: 600;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

/* ========================================================================
   Text Input — Glass
   ======================================================================== */

#text-input-area {
  width: 100%;
  max-width: 600px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.input-row {
  display: flex;
  width: 100%;
  gap: 8px;
}

#text-input {
  flex: 1;
  padding: 12px 16px;
  background: var(--glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-full);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

#text-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(124, 107, 240, 0.15);
}

#text-input::placeholder { color: var(--text-muted); }

#text-send-btn {
  width: 44px;
  height: 44px;
  background: var(--accent);
  color: #fff;
  border-radius: 50%;
}

#text-send-btn:hover { background: var(--accent-hover); }

/* ========================================================================
   Sidebar — Glass Panel
   ======================================================================== */

#sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 320px;
  height: 100%;
  background: var(--glass-bg);
  backdrop-filter: blur(28px);
  -webkit-backdrop-filter: blur(28px);
  border-right: 1px solid var(--glass-border);
  box-shadow: var(--glass-shadow);
  z-index: 100;
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

#sidebar.visible {
  display: flex !important;
  transform: translateX(0);
}

#sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--glass-border);
}

#sidebar-header h2 {
  font-size: 16px;
  font-weight: 600;
}

#sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

#sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--glass-border);
  text-align: center;
}

#sidebar-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 99;
}

#sidebar-overlay.visible { display: block !important; }

.session-item {
  padding: 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s;
  margin-bottom: 4px;
}

.session-item:hover { background: var(--bg-tertiary); }

.session-item .session-date {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}

.session-item .session-summary {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.session-item .session-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ========================================================================
   Responsive
   ======================================================================== */

@media (max-width: 768px) {
  :root {
    --orb-size: 240px;
    --orb-core-size: 100px;
    --ring-1-size: 140px;
    --ring-2-size: 180px;
    --ring-3-size: 230px;
  }
}

@media (max-width: 480px) {
  :root {
    --orb-size: 220px;
    --orb-core-size: 90px;
    --ring-1-size: 130px;
    --ring-2-size: 165px;
    --ring-3-size: 210px;
  }

  .control-btn { padding: 12px 24px; font-size: 15px; }
  .control-btn.secondary { width: 46px; height: 46px; }
  #main { padding: 16px; }

  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .stat-value { font-size: 20px; }
}

@media (max-width: 360px) {
  :root {
    --orb-size: 180px;
    --orb-core-size: 75px;
    --ring-1-size: 105px;
    --ring-2-size: 135px;
    --ring-3-size: 170px;
  }
}
