/* ============================================= */
/* Variables globales                            */
/* ============================================= */
:root {
  --bg: #0a0a1a;
  --bg-gradient: #0d1b2a;
  --primary: #00d4ff;
  --secondary: #ffd700;
  --success: #00ff88;
  --alert: #ff3333;
  --bubble-user: #1a2a3a;
  --bubble-jarvis: #0d2137;
  --text-primary: #ffffff;
  --text-secondary: rgba(255, 255, 255, 0.6);
  --text-muted: rgba(255, 255, 255, 0.35);
  --border-color: rgba(0, 212, 255, 0.15);
  --nav-height: 56px;
  --mic-panel-height: 140px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html { height: 100%; -webkit-text-size-adjust: 100%; }

body {
  min-height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--text-primary);
  background: var(--bg);
  background-image: radial-gradient(ellipse at 50% 50%, var(--bg-gradient) 0%, var(--bg) 70%);
  background-attachment: fixed;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ============================================= */
/* App container                                 */
/* ============================================= */
#app {
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ============================================= */
/* Screens                                       */
/* ============================================= */
.screen {
  display: none;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
}

.screen.active { display: flex; flex-direction: column; }

/* Home screen layout */
#screen-home {
  display: none;
  flex-direction: column;
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom));
}

#screen-home.active { display: flex; }

/* Settings screen */
#screen-settings {
  padding-top: calc(60px + var(--safe-top));
  padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 8px);
}

/* ============================================= */
/* Conversation area                             */
/* ============================================= */
.conversation {
  flex: 1;
  padding: 16px 16px 8px;
  padding-top: calc(16px + var(--safe-top));
  overflow-y: auto;
  scroll-behavior: smooth;
}

/* Burbuja base */
.bubble {
  max-width: 85%;
  padding: 12px 16px;
  margin-bottom: 10px;
  border-radius: 16px;
  font-size: 0.9rem;
  line-height: 1.5;
  animation: fadeInUp 0.3s ease;
  word-wrap: break-word;
}

.bubble.user {
  background: var(--bubble-user);
  margin-left: auto;
  border-bottom-right-radius: 4px;
}

.bubble.jarvis {
  background: var(--bubble-jarvis);
  border: 1px solid var(--border-color);
  margin-right: auto;
  border-bottom-left-radius: 4px;
}

.bubble-time {
  display: block;
  margin-top: 4px;
  font-size: 0.65rem;
  color: var(--text-muted);
  text-align: right;
}

.action-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  margin-top: 6px;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--success);
  background: rgba(0, 255, 136, 0.1);
  border: 1px solid rgba(0, 255, 136, 0.25);
  border-radius: 20px;
}

.action-badge::before { content: '\2713'; font-weight: 700; }

/* ============================================= */
/* Mic panel (fixed bottom of home)              */
/* ============================================= */
.mic-panel {
  flex-shrink: 0;
  padding: 8px 16px 4px;
  background: linear-gradient(to top, var(--bg) 60%, transparent);
}

.mic-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 0;
}

.mic-btn {
  position: relative;
  width: 80px;
  height: 80px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  background: radial-gradient(circle at 50% 50%, rgba(0, 212, 255, 0.1) 0%, transparent 70%);
  border: 2px solid rgba(0, 212, 255, 0.3);
  box-shadow: 0 0 15px rgba(0, 212, 255, 0.2), inset 0 0 15px rgba(0, 212, 255, 0.1);
  transition: all 0.3s ease;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}

.mic-btn::before {
  content: '';
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 1px solid rgba(0, 212, 255, 0.15);
  transform: scale(1.15);
}

.mic-btn::after {
  content: '';
  position: absolute;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 1px solid rgba(0, 212, 255, 0.08);
  transform: scale(1.3);
}

.mic-btn canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  border-radius: 50%;
  pointer-events: none;
}

.mic-icon {
  position: relative;
  z-index: 2;
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.3s ease;
}

.mic-status-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 4px;
  min-height: 16px;
  text-align: center;
}

/* States */
.mic-btn.idle { animation: pulse 3s ease-in-out infinite; }

.mic-btn.listening {
  animation: pulse 1s ease-in-out infinite;
  border-color: var(--primary);
  box-shadow: 0 0 30px rgba(0, 212, 255, 0.5), 0 0 60px rgba(0, 212, 255, 0.2), inset 0 0 20px rgba(0, 212, 255, 0.2);
}
.mic-btn.listening .mic-icon { color: #ffffff; }

.mic-btn.processing {
  animation: spin 1s linear infinite;
  border-color: transparent;
  border-top-color: var(--primary);
  border-right-color: var(--primary);
}
.mic-btn.processing .mic-icon { color: var(--text-secondary); }

.mic-btn.speaking {
  animation: none;
  border-color: var(--success);
  box-shadow: 0 0 20px rgba(0, 255, 136, 0.3), inset 0 0 15px rgba(0, 255, 136, 0.1);
}
.mic-btn.speaking::before { border-color: rgba(0, 255, 136, 0.3); animation: waveOut 1.5s ease-out infinite; }
.mic-btn.speaking::after { border-color: rgba(0, 255, 136, 0.15); animation: waveOut 1.5s ease-out infinite 0.3s; }
.mic-btn.speaking .mic-icon { color: var(--success); }

/* Continuous listening indicator */
.mic-btn.continuous-idle {
  animation: pulse 2s ease-in-out infinite;
  border-color: rgba(0, 255, 136, 0.3);
  box-shadow: 0 0 15px rgba(0, 255, 136, 0.15), inset 0 0 10px rgba(0, 255, 136, 0.05);
}
.mic-btn.continuous-idle .mic-icon { color: var(--success); }

/* ============================================= */
/* Interim text                                  */
/* ============================================= */
.interim-text {
  text-align: center;
  padding: 4px 24px;
  min-height: 20px;
  font-size: 0.85rem;
  font-style: italic;
  color: var(--text-muted);
}

/* ============================================= */
/* Status text                                   */
/* ============================================= */
.status-text {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 4px 16px;
  font-size: 0.68rem;
  color: var(--text-muted);
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--alert);
  transition: background 0.3s ease;
}

.status-dot.connected {
  background: var(--success);
  box-shadow: 0 0 6px rgba(0, 255, 136, 0.5);
}

/* ============================================= */
/* Bottom nav                                    */
/* ============================================= */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 200;
  display: flex;
  justify-content: space-around;
  align-items: center;
  height: calc(var(--nav-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: rgba(10, 10, 26, 0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border-color);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  flex: 1;
  padding: 8px 0;
  text-decoration: none;
  color: var(--text-muted);
  transition: color 0.25s ease;
  -webkit-tap-highlight-color: transparent;
}

.nav-item.active { color: var(--primary); }
.nav-item.active .nav-label { color: var(--primary); }

.nav-label {
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: inherit;
}

/* ============================================= */
/* Settings screen                               */
/* ============================================= */
.screen-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
  padding: calc(16px + var(--safe-top)) 20px 12px;
  background: linear-gradient(to bottom, var(--bg) 70%, transparent);
}

.screen-title {
  font-family: 'Orbitron', monospace;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: 3px;
  color: var(--primary);
  text-shadow: 0 0 10px rgba(0, 212, 255, 0.5);
}

.settings-content { padding: 0 16px 20px; }

.settings-section {
  margin-bottom: 24px;
  padding: 16px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-color);
  border-radius: 14px;
}

.settings-section-title {
  font-family: 'Orbitron', monospace;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--primary);
  margin-bottom: 14px;
}

.setting-item { margin-bottom: 14px; }
.setting-item:last-child { margin-bottom: 0; }
.setting-row { display: flex; align-items: center; justify-content: space-between; }

.setting-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.setting-row .setting-label { margin-bottom: 0; }

.setting-hint {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 8px;
  line-height: 1.4;
}

.setting-value {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--primary);
  font-family: 'Orbitron', monospace;
}

.setting-control { width: 100%; }

.setting-select {
  padding: 10px 14px;
  font-size: 0.85rem;
  font-family: 'Inter', sans-serif;
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}

.setting-input {
  padding: 10px 14px;
  font-size: 0.85rem;
  font-family: 'Inter', sans-serif;
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  outline: none;
  transition: border-color 0.3s ease;
}

.setting-input::placeholder { color: var(--text-muted); }
.setting-input:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(0, 212, 255, 0.1); }

.setting-slider {
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 2px;
  outline: none;
  margin-top: 4px;
}

.setting-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  box-shadow: 0 0 8px rgba(0, 212, 255, 0.4);
}

.setting-slider::-moz-range-thumb {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  border: none;
}

/* Toggle */
.toggle-switch { position: relative; display: inline-block; width: 46px; height: 26px; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: rgba(255,255,255,0.1); border-radius: 26px; cursor: pointer; transition: background 0.3s ease; }
.toggle-slider::before { content: ''; position: absolute; width: 20px; height: 20px; left: 3px; bottom: 3px; background: white; border-radius: 50%; transition: transform 0.3s ease; }
.toggle-switch input:checked + .toggle-slider { background: var(--primary); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(20px); }

/* Buttons */
.setting-btn {
  display: block;
  width: 100%;
  padding: 12px 16px;
  margin-top: 10px;
  font-size: 0.85rem;
  font-family: 'Inter', sans-serif;
  font-weight: 600;
  color: var(--primary);
  background: rgba(0, 212, 255, 0.08);
  border: 1px solid rgba(0, 212, 255, 0.2);
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.3s ease;
  -webkit-tap-highlight-color: transparent;
}
.setting-btn:active { background: rgba(0, 212, 255, 0.15); transform: scale(0.98); }
.setting-btn-danger { color: var(--alert); background: rgba(255,51,51,0.08); border-color: rgba(255,51,51,0.2); }

.connection-status { margin-top: 8px; font-size: 0.8rem; text-align: center; min-height: 20px; }
.connection-status.success { color: var(--success); }
.connection-status.error { color: var(--alert); }

/* About */
.about-info { text-align: center; }
.about-name { font-family: 'Orbitron', monospace; font-size: 1rem; font-weight: 700; color: var(--primary); margin-bottom: 4px; }
.about-version { font-size: 0.7rem; font-weight: 400; color: var(--text-muted); }
.about-desc { font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 2px; }
.about-powered { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 8px; }

/* ============================================= */
/* Animations                                    */
/* ============================================= */
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 15px rgba(0,212,255,0.2), inset 0 0 15px rgba(0,212,255,0.1); }
  50% { box-shadow: 0 0 30px rgba(0,212,255,0.4), inset 0 0 20px rgba(0,212,255,0.2); }
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@keyframes waveOut {
  0% { transform: scale(1.15); opacity: 0.6; }
  100% { transform: scale(1.8); opacity: 0; }
}

@keyframes fadeInUp {
  0% { opacity: 0; transform: translateY(10px); }
  100% { opacity: 1; transform: translateY(0); }
}

/* ============================================= */
/* Scrollbar                                     */
/* ============================================= */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,212,255,0.3); border-radius: 4px; }
* { scrollbar-width: thin; scrollbar-color: rgba(0,212,255,0.3) transparent; }

/* ============================================= */
/* Responsive                                    */
/* ============================================= */
@media (min-width: 600px) {
  .conversation { max-width: 540px; margin: 0 auto; }
  .settings-content { max-width: 540px; margin: 0 auto; }
  .bubble { max-width: 70%; }
}
