/* ═══════════════════════════════════════════
   JARVIS — Immersive Orb Interface
   ═══════════════════════════════════════════ */

:root {
  --blue: rgba(14, 165, 233, 1);
  --blue-50: rgba(14, 165, 233, 0.5);
  --blue-30: rgba(14, 165, 233, 0.3);
  --blue-15: rgba(14, 165, 233, 0.15);
  --blue-08: rgba(14, 165, 233, 0.08);
  --blue-05: rgba(14, 165, 233, 0.05);
  --red-50: rgba(239, 68, 68, 0.5);
  --bg: #050508;
  --font: 'Outfit', -apple-system, sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

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

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  background: var(--bg);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
}

.screen { display: none; height: 100%; width: 100%; position: fixed; inset: 0; }
.screen.active { display: flex; flex-direction: column; }

/* ─── Auth ──────────────────────────────── */

#auth-screen { align-items: center; justify-content: center; background: var(--bg); }

.auth-container { display: flex; flex-direction: column; align-items: center; gap: 20px; position: relative; }
.auth-glow { position: absolute; top: -80px; width: 200px; height: 200px; border-radius: 50%; background: radial-gradient(circle, var(--blue-15) 0%, transparent 70%); filter: blur(40px); pointer-events: none; animation: glow-pulse 4s ease-in-out infinite; }
@keyframes glow-pulse { 0%,100%{opacity:.4;transform:scale(1)} 50%{opacity:.7;transform:scale(1.1)} }

.auth-title { font-size: 28px; font-weight: 500; letter-spacing: 8px; color: var(--blue); text-shadow: 0 0 30px var(--blue-30); }
.auth-subtitle { font-size: 14px; color: var(--blue-50); font-weight: 300; }
.pin-display { display: flex; gap: 12px; margin: 8px 0; }
.pin-dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid rgba(255,255,255,0.15); transition: all .2s; }
.pin-dot.filled { background: var(--blue); border-color: var(--blue); box-shadow: 0 0 12px var(--blue-30); }
.pin-pad { display: grid; grid-template-columns: repeat(3,72px); gap: 12px; margin-top: 8px; }
.pin-key { width: 72px; height: 56px; border: 1px solid rgba(255,255,255,0.08); border-radius: 8px; background: rgba(255,255,255,0.03); color: rgba(255,255,255,0.7); font-family: var(--font); font-size: 20px; font-weight: 400; cursor: pointer; transition: all .15s; -webkit-tap-highlight-color: transparent; }
.pin-key:active { background: rgba(255,255,255,0.08); transform: scale(.95); }
.pin-key-fn { font-size: 13px; color: rgba(255,255,255,0.35); }
.auth-error { color: var(--red-50); font-size: 13px; min-height: 20px; }

@keyframes shake { 0%,100%{transform:translateX(0)} 20%{transform:translateX(-10px)} 40%{transform:translateX(10px)} 60%{transform:translateX(-6px)} 80%{transform:translateX(6px)} }

/* ─── Main Screen ───────────────────────── */

#main-screen { position: relative; }

#orb-canvas { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 0; }

/* ─── Top Controls ──────────────────────── */

#controls { position: fixed; top: calc(16px + var(--safe-top)); right: 16px; display: flex; gap: 8px; z-index: 20; }

#controls button {
  width: 36px; height: 36px;
  border: 1px solid var(--blue-15); border-radius: 8px;
  background: var(--blue-05); color: var(--blue-50);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all .2s; -webkit-tap-highlight-color: transparent;
}
#controls button:active { background: var(--blue-08); color: var(--blue); border-color: var(--blue-30); }
#controls button.muted { color: var(--red-50); border-color: rgba(239,68,68,0.2); }

/* ─── Menu Dropdown ─────────────────────── */

#menu-dropdown {
  position: fixed; top: calc(58px + var(--safe-top)); right: 16px;
  background: rgba(10,10,15,0.95); border: 1px solid var(--blue-15);
  border-radius: 8px; padding: 4px; z-index: 20;
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  display: none;
}
#menu-dropdown button {
  display: block; width: 100%; padding: 8px 16px;
  border: none; background: none; color: var(--blue-50);
  font-size: 12px; letter-spacing: 1px; text-align: left;
  cursor: pointer; border-radius: 4px; transition: all .15s;
  font-family: var(--font);
}
#menu-dropdown button:active { background: var(--blue-08); color: var(--blue); }

/* ─── Status Text ───────────────────────── */

#status-text {
  position: fixed; bottom: calc(80px + var(--safe-bottom)); left: 50%; transform: translateX(-50%);
  color: var(--blue-50); font-size: 13px; letter-spacing: 2px;
  text-transform: lowercase; font-weight: 300;
  transition: opacity .5s; pointer-events: none; z-index: 10;
}

#jarvis-label {
  position: fixed; bottom: calc(62px + var(--safe-bottom)); left: 50%; transform: translateX(-50%);
  color: rgba(14,165,233,0.2); font-size: 10px; letter-spacing: 4px;
  text-transform: uppercase; font-weight: 300;
  pointer-events: none; z-index: 10;
}

#error-text {
  position: fixed; top: calc(40px + var(--safe-top)); left: 50%; transform: translateX(-50%);
  color: var(--red-50); font-size: 13px; letter-spacing: 1px; font-weight: 300;
  transition: opacity .5s; pointer-events: none; z-index: 10; opacity: 0;
}

/* ─── Response Overlay ──────────────────── */

#response-overlay {
  position: fixed; top: 20%; left: 50%; transform: translateX(-50%);
  max-width: 400px; width: 90%;
  text-align: center; z-index: 10; pointer-events: none;
  opacity: 0; transition: opacity .4s;
}
#response-overlay.visible { opacity: 1; }

#transcription {
  font-size: 13px; color: rgba(255,255,255,0.3);
  font-style: italic; margin-bottom: 12px; line-height: 1.5;
}
#reply-text {
  font-size: 16px; color: rgba(255,255,255,0.8);
  font-weight: 300; line-height: 1.6; letter-spacing: 0.3px;
}
#full-text {
  font-size: 11px; color: rgba(255,255,255,0.25);
  font-family: 'JetBrains Mono', monospace;
  line-height: 1.5; margin-top: 16px;
  white-space: pre-wrap; word-break: break-word;
  max-height: 200px; overflow-y: auto;
  text-align: left; display: none;
}

/* ─── Bottom Bar ────────────────────────── */

#bottom-bar {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex; gap: 8px; padding: 12px 16px calc(var(--safe-bottom) + 12px);
  z-index: 15; background: linear-gradient(transparent, rgba(5,5,8,0.9) 30%);
}

#text-input {
  flex: 1; padding: 10px 16px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 24px; color: rgba(255,255,255,0.8);
  font-family: var(--font); font-size: 14px; outline: none;
  transition: border-color .2s;
}
#text-input::placeholder { color: rgba(255,255,255,0.2); }
#text-input:focus { border-color: var(--blue-30); }

#ptt-button {
  width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid var(--blue-30); background: var(--blue-05);
  color: var(--blue-50); display: flex; align-items: center; justify-content: center;
  cursor: pointer; flex-shrink: 0; transition: all .15s;
  -webkit-tap-highlight-color: transparent;
}
#ptt-button:active, #ptt-button.recording {
  background: var(--blue); color: var(--bg); border-color: var(--blue);
  box-shadow: 0 0 20px var(--blue-30);
}

/* ─── Side Panels ───────────────────────── */

.side-panel {
  position: fixed; top: 0; right: -100%; width: 320px; max-width: 85%;
  height: 100%; z-index: 30;
  background: rgba(8,10,18,0.95); border-left: 1px solid var(--blue-08);
  backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px);
  transition: right .3s cubic-bezier(.4,0,.2,1);
  overflow-y: auto; display: flex; flex-direction: column;
}
.side-panel.open { right: 0; }

.panel-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 20px; border-bottom: 1px solid var(--blue-08);
}
.panel-header h3 {
  font-size: 14px; font-weight: 400; letter-spacing: 2px;
  text-transform: uppercase; color: var(--blue-50);
}
.panel-close {
  width: 32px; height: 32px; border: 1px solid var(--blue-15);
  border-radius: 6px; background: var(--blue-05); color: var(--blue-50);
  font-size: 18px; cursor: pointer; display: flex; align-items: center; justify-content: center;
}

.actions-grid {
  display: grid; grid-template-columns: repeat(2,1fr);
  gap: 10px; padding: 16px;
}
.action-card {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 16px 8px; background: rgba(255,255,255,0.02);
  border: 1px solid rgba(255,255,255,0.05); border-radius: 8px;
  color: rgba(255,255,255,0.4); font-size: 11px; font-family: var(--font);
  cursor: pointer; transition: all .2s; -webkit-tap-highlight-color: transparent;
}
.action-card span { font-size: 24px; }
.action-card:active { background: var(--blue-08); border-color: var(--blue-15); color: var(--blue); }

/* ─── Tasks ─────────────────────────────── */

.tasks-list { padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.tasks-empty { text-align: center; color: rgba(255,255,255,0.2); font-size: 13px; padding: 40px 0; }
.task-item {
  padding: 12px; background: rgba(255,255,255,0.02);
  border: 1px solid rgba(255,255,255,0.05); border-radius: 8px;
}
.task-header { display: flex; align-items: center; gap: 8px; }
.task-status-icon { font-size: 14px; }
.task-name { font-size: 12px; color: rgba(255,255,255,0.6); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-time { font-size: 10px; color: rgba(255,255,255,0.2); font-family: monospace; }
.task-progress { font-size: 11px; color: var(--blue-50); margin-top: 4px; font-family: monospace; }
.task-result { font-size: 11px; color: rgba(255,255,255,0.25); margin-top: 4px; font-family: monospace; white-space: pre-wrap; max-height: 80px; overflow-y: auto; }

/* ─── Modal ─────────────────────────────── */

.modal-overlay {
  position: fixed; inset: 0; background: rgba(5,5,8,0.8);
  backdrop-filter: blur(8px); display: flex; align-items: center;
  justify-content: center; z-index: 100; padding: 24px;
}
.modal {
  background: rgba(15,17,25,0.95); border: 1px solid var(--blue-15);
  border-radius: 12px; padding: 24px; max-width: 340px; width: 100%;
}
.modal p { font-size: 15px; color: rgba(255,255,255,0.7); line-height: 1.5; margin-bottom: 20px; }
.modal-actions { display: flex; gap: 12px; }
.modal-btn {
  flex: 1; padding: 12px; border: none; border-radius: 8px;
  font-family: var(--font); font-size: 14px; cursor: pointer;
}
.modal-btn.cancel { background: rgba(255,255,255,0.05); color: rgba(255,255,255,0.4); }
.modal-btn.confirm { background: var(--blue-15); color: var(--blue); }

/* ─── Dashboard ────────────────────────── */

#dashboard {
  position: fixed; inset: 0; z-index: 12;
  background: rgba(5, 5, 8, 0.92);
  backdrop-filter: blur(24px); -webkit-backdrop-filter: blur(24px);
  overflow-y: auto; overflow-x: hidden;
  padding: calc(60px + var(--safe-top)) 16px calc(70px + var(--safe-bottom)) 16px;
  transition: opacity 0.3s, visibility 0.3s;
}
#dashboard.dashboard-hidden {
  opacity: 0; visibility: hidden; pointer-events: none;
}
#dashboard.dashboard-visible {
  opacity: 1; visibility: visible; pointer-events: auto;
}

#dash-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  max-width: 500px;
  margin: 0 auto;
}

.dash-card {
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid rgba(14, 165, 233, 0.08);
  border-radius: 10px;
  padding: 12px;
  min-height: 70px;
  transition: border-color 0.3s;
}
.dash-card:hover {
  border-color: rgba(14, 165, 233, 0.15);
}

.dash-label {
  font-size: 9px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: rgba(14, 165, 233, 0.4);
  margin-bottom: 8px;
  font-weight: 400;
}

.dash-body {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.5);
  line-height: 1.5;
}

.dash-body .dash-empty {
  color: rgba(255, 255, 255, 0.15);
  font-style: italic;
}

/* Clock card spans full width */
.dash-clock {
  grid-column: 1 / -1;
  text-align: center;
  padding: 16px 12px;
  background: none;
  border: none;
  min-height: auto;
}
.dash-clock .dash-time {
  font-size: 42px;
  font-weight: 300;
  color: rgba(14, 165, 233, 0.7);
  letter-spacing: 4px;
  line-height: 1;
}
.dash-clock .dash-date {
  font-size: 12px;
  color: rgba(14, 165, 233, 0.3);
  letter-spacing: 3px;
  text-transform: uppercase;
  margin-top: 4px;
}
.dash-clock .dash-tone {
  font-size: 10px;
  color: rgba(14, 165, 233, 0.5);
  letter-spacing: 2px;
  text-transform: uppercase;
  margin-top: 6px;
  padding: 2px 10px;
  border: 1px solid rgba(14, 165, 233, 0.15);
  border-radius: 10px;
  display: inline-block;
}

/* Todo items in dashboard */
.dash-todo-item {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}
.dash-todo-dot {
  width: 5px; height: 5px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dash-todo-dot.p-critical { background: #ef4444; }
.dash-todo-dot.p-high { background: #f59e0b; }
.dash-todo-dot.p-medium { background: #3b82f6; }
.dash-todo-dot.p-low { background: #6b7280; }
.dash-todo-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
}
.dash-todo-pct {
  font-size: 10px;
  color: rgba(14, 165, 233, 0.4);
  font-family: monospace;
  flex-shrink: 0;
}

/* Spotify progress bar */
.dash-spotify-bar {
  width: 100%;
  height: 3px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 2px;
  margin-top: 6px;
  overflow: hidden;
}
.dash-spotify-fill {
  height: 100%;
  background: #1db954;
  border-radius: 2px;
  transition: width 1s linear;
}

/* Orchestrator progress */
.dash-orch-bar {
  width: 100%;
  height: 4px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 2px;
  margin-top: 6px;
  overflow: hidden;
}
.dash-orch-fill {
  height: 100%;
  background: var(--blue);
  border-radius: 2px;
  transition: width 0.5s;
}

/* Status indicators */
.dash-status {
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  margin-right: 6px;
}
.dash-status.green { background: #22c55e; box-shadow: 0 0 6px rgba(34, 197, 94, 0.4); }
.dash-status.yellow { background: #eab308; box-shadow: 0 0 6px rgba(234, 179, 8, 0.4); }
.dash-status.red { background: #ef4444; box-shadow: 0 0 6px rgba(239, 68, 68, 0.4); }
.dash-status.off { background: rgba(255, 255, 255, 0.15); }

/* Note items */
.dash-note {
  margin-bottom: 6px;
  font-size: 11px;
  line-height: 1.4;
}
.dash-note-text {
  color: rgba(255, 255, 255, 0.45);
}
.dash-note-ago {
  font-size: 9px;
  color: rgba(255, 255, 255, 0.15);
  margin-left: 4px;
}

/* Habit items */
.dash-habit {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
  font-size: 11px;
}
.dash-habit-icon {
  flex-shrink: 0;
  font-size: 12px;
  width: 16px;
  text-align: center;
}
.dash-habit-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: rgba(255, 255, 255, 0.45);
}
.dash-habit-streak {
  font-size: 9px;
  color: rgba(14, 165, 233, 0.4);
  font-family: monospace;
  flex-shrink: 0;
}

/* Dashboard toggle button active state */
#btn-dashboard.active {
  background: var(--blue-15);
  color: var(--blue);
  border-color: var(--blue-30);
}

/* ─── Scrollbar ─────────────────────────── */
::-webkit-scrollbar { width: 3px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 2px; }

/* ─── Orb Click Target ─────────────────── */
#orb-canvas { cursor: pointer; -webkit-tap-highlight-color: transparent; }

/* ─── Activation Ring ──────────────────── */
#orb-ring {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 200px; height: 200px; border-radius: 50%;
  border: 1px solid transparent;
  pointer-events: none; z-index: 5;
  transition: all 0.8s cubic-bezier(0.4, 0, 0.2, 1);
  opacity: 0;
}
#orb-ring.active {
  opacity: 1;
  border-color: var(--blue-30);
  box-shadow: 0 0 40px var(--blue-08), 0 0 80px rgba(14,165,233,0.03), inset 0 0 30px var(--blue-05);
  animation: ring-breathe 3s ease-in-out infinite;
}
@keyframes ring-breathe {
  0%, 100% { transform: translate(-50%, -50%) scale(1); border-color: rgba(14,165,233,0.2); box-shadow: 0 0 30px var(--blue-08), inset 0 0 20px var(--blue-05); }
  50% { transform: translate(-50%, -50%) scale(1.04); border-color: rgba(14,165,233,0.35); box-shadow: 0 0 50px var(--blue-15), inset 0 0 35px var(--blue-08); }
}

/* Pulse ring on activation */
#orb-pulse-ring {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%) scale(0.5);
  width: 250px; height: 250px; border-radius: 50%;
  border: 2px solid var(--blue);
  pointer-events: none; z-index: 4; opacity: 0;
}
#orb-pulse-ring.pulse {
  animation: orb-activate 0.8s ease-out forwards;
}
@keyframes orb-activate {
  0% { transform: translate(-50%, -50%) scale(0.6); opacity: 0.8; border-width: 2px; }
  100% { transform: translate(-50%, -50%) scale(1.5); opacity: 0; border-width: 0.5px; }
}

/* Deactivation shrink */
#orb-pulse-ring.depulse {
  animation: orb-deactivate 0.6s ease-out forwards;
}
@keyframes orb-deactivate {
  0% { transform: translate(-50%, -50%) scale(1.2); opacity: 0.5; border-color: rgba(255,255,255,0.3); }
  100% { transform: translate(-50%, -50%) scale(0.3); opacity: 0; }
}

/* Status text when listening */
#jarvis-label.listening-mode {
  color: var(--blue-50);
  animation: label-breathe 3s ease-in-out infinite;
}
@keyframes label-breathe {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 0.8; }
}
