/* Luna Voice Agent - Minimal UI */

:root {
  --bg-primary: #0a0a0f;
  --bg-secondary: #14141f;
  --text-primary: #ffffff;
  --text-secondary: #8888aa;
  --accent: #6366f1;
  --accent-glow: rgba(99, 102, 241, 0.4);
  --success: #22c55e;
  --warning: #f59e0b;
  --error: #ef4444;
  --border: #2a2a3f;
}

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

html, body {
  /* Prevent overscroll bounce on iOS */
  overscroll-behavior: none;
  -webkit-overflow-scrolling: touch;
}

/* Nova Circle WebGL2 Canvas */
#nova-canvas {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  height: 100dvh; /* Dynamic viewport height for mobile browsers */
  z-index: -1;
  pointer-events: none;
}

/* Fallback when WebGL2 is not available */
.nova-fallback .state-icon {
  display: flex;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  min-height: 100dvh; /* Dynamic viewport height for mobile */
  overflow: hidden;
  /* Prevent text selection on touch */
  -webkit-user-select: none;
  user-select: none;
  /* Prevent callout on long press */
  -webkit-touch-callout: none;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh; /* Dynamic viewport height for mobile */
  max-width: 600px;
  margin: 0 auto;
  padding: 2rem;
  padding-top: max(2rem, env(safe-area-inset-top));
  padding-bottom: max(2rem, env(safe-area-inset-bottom));
  padding-left: max(2rem, env(safe-area-inset-left));
  padding-right: max(2rem, env(safe-area-inset-right));
}

/* Header */
header {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 2rem;
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-profile-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.profile-name {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.btn-header {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-secondary);
  text-decoration: none;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-header:hover {
  background: var(--border);
  color: var(--text-primary);
}

.btn-header svg {
  flex-shrink: 0;
}

/* Status Indicator */
.status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-secondary);
}

.status.connected .status-dot {
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
}

.status.connecting .status-dot {
  background: var(--warning);
  animation: pulse 1s infinite;
}

.status.error .status-dot {
  background: var(--error);
}

.status.disconnected .status-dot {
  background: var(--text-secondary);
}

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

/* Main Content */
main {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

/* Agent State Visualization - Fixed center to match Nova circle */
.agent-state {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  z-index: 1;
  pointer-events: none;
}

/* Hide state-icon when Nova is active (WebGL2 available) */
.state-icon {
  width: 120px;
  height: 120px;
  margin: 0 auto 1.5rem;
  border-radius: 50%;
  background: var(--bg-secondary);
  border: 2px solid var(--border);
  display: none; /* Hidden by default when Nova is active */
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
}

/* Show state-icon only as fallback */
.nova-fallback .state-icon {
  display: flex;
}

.state-icon.listening {
  border-color: var(--accent);
  box-shadow: 0 0 30px var(--accent-glow);
  animation: listening-pulse 2s infinite;
}

.state-icon.speaking {
  border-color: var(--success);
  box-shadow: 0 0 30px rgba(34, 197, 94, 0.4);
  animation: speaking-wave 0.5s infinite;
}

.state-icon.processing {
  border-color: var(--warning);
  animation: processing-spin 1s linear infinite;
}

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

@keyframes speaking-wave {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.02); }
}

@keyframes processing-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.state-label {
  font-size: 1.1rem;
  color: var(--text-secondary);
  white-space: nowrap;
  padding: 0 1rem;
}

/* Footer Controls */
footer {
  padding-top: 2rem;
}

.controls {
  display: flex;
  gap: 1rem;
  justify-content: center;
}

.btn {
  padding: 0.75rem 2rem;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-stop {
  background: var(--error);
  color: white;
}

.btn-stop:hover:not(:disabled) {
  background: #dc2626;
}

.btn-secondary {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--border);
}

.btn-secondary.active {
  background: var(--accent);
  border-color: var(--accent);
}

.btn-icon {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.25rem;
  line-height: 1;
}

.btn-icon:hover {
  color: var(--text-primary);
}

/* Debug Panel */
.debug-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 40vh;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transform: translateY(0);
  transition: transform 0.3s ease;
  z-index: 100;
}

.debug-panel.hidden {
  transform: translateY(100%);
}

.debug-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.debug-log {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 0.75rem;
  line-height: 1.4;
  /* Allow text selection in debug panel */
  -webkit-user-select: text;
  user-select: text;
}

.log-entry {
  padding: 0.25rem 0.5rem;
  border-bottom: 1px solid var(--border);
}

.log-entry:last-child {
  border-bottom: none;
}

.log-entry.debug { color: var(--text-secondary); }
.log-entry.info { color: var(--text-primary); }
.log-entry.warn { color: var(--warning); }
.log-entry.error { color: var(--error); }

.log-timestamp {
  color: var(--text-secondary);
  margin-right: 0.5rem;
}

.log-component {
  color: var(--accent);
  margin-right: 0.5rem;
}

/* Start Overlay */
.start-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #000;
  z-index: 1000;
  opacity: 1;
  transition: opacity 0.3s ease;
}

.start-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

#start-button-canvas {
  display: block;
  width: 100%;
  height: 100%;
  height: 100dvh;
}

/* Start Text Overlay - Centered text above the circle */
.start-text-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 10;
}

#start-text {
  font-size: 1.5rem;
  font-weight: 500;
  color: rgba(255, 255, 255, 0.9);
  text-transform: uppercase;
  letter-spacing: 0.15em;
  text-shadow: 0 0 20px rgba(99, 102, 241, 0.5);
  transition: opacity 0.5s ease, transform 0.5s ease;
  cursor: pointer;
  pointer-events: auto;
}

/* Initial loading state - fades in */
#start-text.loading {
  opacity: 0;
  animation: text-fade-in 0.8s ease-out forwards;
  cursor: default;
  pointer-events: none;
}

@keyframes text-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Fading state - for transition from Caricamento to Avvia */
#start-text.fading {
  opacity: 0;
  transition: opacity 0.4s ease-out;
  pointer-events: none;
}

/* Hover */
#start-text:hover:not(.loading):not(.countdown):not(.connecting) {
  color: #fff;
  text-shadow: 0 0 30px rgba(99, 102, 241, 0.8);
}

/* Countdown state - larger numbers */
#start-text.countdown {
  font-size: 4rem;
  font-weight: 300;
  letter-spacing: 0;
  color: rgba(255, 255, 255, 0.95);
  text-shadow: 0 0 40px rgba(255, 255, 255, 0.4);
  cursor: default;
  pointer-events: none;
}

/* Connecting state */
#start-text.connecting {
  font-size: 1.2rem;
  font-weight: 400;
  letter-spacing: 0.1em;
  color: rgba(255, 255, 255, 0.8);
  text-shadow: 0 0 20px rgba(255, 255, 255, 0.3);
  cursor: default;
  pointer-events: none;
  animation: pulse-connecting 1.5s infinite;
}

@keyframes pulse-connecting {
  0%, 100% { opacity: 0.8; }
  50% { opacity: 0.5; }
}

/* Fade out for final transition */
#start-text.fade-out {
  opacity: 0;
  transform: scale(0.8);
  transition: all 0.4s ease;
}

/* App visibility */
.app-hidden {
  opacity: 0;
  pointer-events: none;
}

#app {
  transition: opacity 0.3s ease;
}

#app:not(.app-hidden) {
  opacity: 1;
  pointer-events: auto;
}

/* Admin Login Modal */
.login-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.login-modal.hidden {
  display: none;
}

.login-modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  max-width: 340px;
  width: 90%;
}

.login-modal-content h3 {
  margin-bottom: 1.25rem;
  font-size: 1.1rem;
  color: var(--text-primary);
}

.login-form-group {
  margin-bottom: 1rem;
}

.login-form-group label {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.login-form-group input {
  width: 100%;
  padding: 0.65rem 0.75rem;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-primary);
  font-size: 0.9rem;
}

.login-form-group input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.login-error {
  color: var(--error);
  font-size: 0.85rem;
  margin-bottom: 1rem;
  text-align: center;
}

.login-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 1.25rem;
}

.login-actions .btn {
  padding: 0.6rem 1.25rem;
  border: none;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
}

.login-actions .btn-secondary {
  background: var(--bg-primary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.login-actions .btn-secondary:hover {
  background: var(--border);
}

.login-actions .btn-primary {
  background: var(--accent);
  color: white;
}

.login-actions .btn-primary:hover {
  background: #4f46e5;
}

/* Utility */
.hidden {
  display: none !important;
}

/* Responsive - Mobile First Approach */

/* Small phones (up to 360px) */
@media (max-width: 360px) {
  #app {
    padding: 0.75rem;
    padding-top: max(0.75rem, env(safe-area-inset-top));
    padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
  }

  .profile-name {
    font-size: 1rem;
  }

  .state-icon {
    width: 80px;
    height: 80px;
  }

  .state-label {
    font-size: 0.95rem;
  }

  .btn {
    padding: 0.6rem 1.25rem;
    font-size: 0.85rem;
  }

  .debug-panel {
    height: 50vh;
  }
}

/* Standard phones (361px - 480px) */
@media (min-width: 361px) and (max-width: 480px) {
  #app {
    padding: 1rem;
    padding-top: max(1rem, env(safe-area-inset-top));
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
  }

  .state-icon {
    width: 100px;
    height: 100px;
  }

  .btn {
    padding: 0.6rem 1.5rem;
    font-size: 0.9rem;
  }

  .debug-panel {
    height: 45vh;
  }
}

/* Large phones / Small tablets (481px - 768px) */
@media (min-width: 481px) and (max-width: 768px) {
  #app {
    padding: 1.5rem;
    padding-top: max(1.5rem, env(safe-area-inset-top));
    padding-bottom: max(1.5rem, env(safe-area-inset-bottom));
  }

  .profile-name {
    font-size: 1.35rem;
  }

  .state-label {
    font-size: 1.15rem;
  }

  .btn-header {
    width: 40px;
    height: 40px;
  }

  .btn-header svg {
    width: 20px;
    height: 20px;
  }
}

/* Tablets / iPad (769px - 1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
  #app {
    max-width: 700px;
    padding: 2.5rem;
  }

  .profile-name {
    font-size: 1.5rem;
  }

  .state-icon {
    width: 140px;
    height: 140px;
  }

  .state-label {
    font-size: 1.25rem;
  }

  .btn {
    padding: 0.875rem 2.5rem;
    font-size: 1.1rem;
  }

  .debug-panel {
    height: 35vh;
  }
}

/* Desktop (1025px+) */
@media (min-width: 1025px) {
  #app {
    max-width: 800px;
    padding: 3rem;
  }

  .profile-name {
    font-size: 1.5rem;
  }

  .state-icon {
    width: 150px;
    height: 150px;
  }

  .state-label {
    font-size: 1.3rem;
  }

  .btn-header {
    width: 42px;
    height: 42px;
  }

  .debug-panel {
    height: 30vh;
    max-height: 300px;
  }
}

/* Landscape mode for phones */
@media (max-height: 500px) and (orientation: landscape) {
  #app {
    padding: 0.5rem 1.5rem;
    padding-left: max(1.5rem, env(safe-area-inset-left));
    padding-right: max(1.5rem, env(safe-area-inset-right));
  }

  header {
    margin-bottom: 0.5rem;
  }

  .header-top {
    flex-wrap: nowrap;
  }

  .state-icon {
    width: 60px;
    height: 60px;
    margin-bottom: 0.5rem;
  }

  .state-label {
    font-size: 0.9rem;
  }

  footer {
    padding-top: 0.5rem;
  }

  .btn {
    padding: 0.5rem 1.5rem;
  }

  .debug-panel {
    height: 60vh;
  }
}

/* Touch-friendly tap targets for mobile */
@media (hover: none) and (pointer: coarse) {
  .btn-header {
    min-width: 44px;
    min-height: 44px;
  }

  .btn {
    min-height: 44px;
  }

  .btn-icon {
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
}

/* High DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  .status-dot {
    border: 0.5px solid rgba(255, 255, 255, 0.1);
  }
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
