/* Mobile-first CSS for LiveFusion PTT */

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg-primary: #1A1A1A;
  --bg-secondary: #242424;
  --bg-tertiary: #333333;
  --text-primary: #eaeaea;
  --text-secondary: #a0a0a0;
  --accent: #0D99FF;
  --accent-glow: rgba(13, 153, 255, 0.6);
  --accent-lime: #CCFF00;
  --success: #4ade80;
  --warning: #fbbf24;
  --border-radius: 12px;
  --safe-area-top: env(safe-area-inset-top, 0px);
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  touch-action: manipulation;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding-top: var(--safe-area-top);
  padding-bottom: var(--safe-area-bottom);
}

/* Status Bar */
#status-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border-bottom: 2px solid var(--accent-lime);
}

.status-bar-brand {
  margin-left: auto;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.brand-live,
.brand-fusion {
  color: #fff;
}

.brand-dot {
  color: var(--accent-lime);
}

.status-indicators {
  display: flex;
  gap: 14px;
}

.status-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

.status-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  transition: background-color 0.3s, box-shadow 0.3s;
}

.status-dot.disconnected {
  background: #ef4444;
}

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

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

/* Connection quality indicators */
.status-dot.quality-good {
  background: #22c55e;
  box-shadow: 0 0 8px #22c55e;
}

.status-dot.quality-warning {
  background: #eab308;
  box-shadow: 0 0 8px #eab308;
}

.status-dot.quality-poor {
  background: #ef4444;
  box-shadow: 0 0 8px #ef4444;
}

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

/* Connection Panel */
#connect-panel {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.connect-form {
  width: 100%;
  max-width: 300px;
  text-align: center;
}

.connect-logo {
  width: 80px;
  height: auto;
  margin-bottom: 16px;
}

.connect-form h2 {
  margin-bottom: 24px;
  font-size: 24px;
  font-weight: 600;
}

/* Auth buttons */
.auth-btn {
  width: 100%;
  padding: 14px;
  font-size: 16px;
  font-weight: 600;
  border: none;
  border-radius: var(--border-radius);
  cursor: pointer;
  transition: transform 0.1s, opacity 0.2s;
  margin-bottom: 10px;
}

.auth-btn:active { transform: scale(0.98); }
.auth-btn:disabled { opacity: 0.6; cursor: not-allowed; }

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

.auth-btn-secondary {
  background: transparent;
  color: var(--text-primary);
  border: 2px solid var(--bg-tertiary);
}

.auth-btn-secondary:hover {
  border-color: var(--accent);
}

.auth-btn-text {
  background: transparent;
  color: var(--text-secondary);
  padding: 8px;
  font-size: 14px;
  font-weight: 400;
}

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

.auth-divider {
  display: flex;
  align-items: center;
  margin: 16px 0;
  color: var(--text-secondary);
  font-size: 13px;
}

.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--bg-tertiary);
}

.auth-divider span { padding: 0 12px; }

/* Guest form inputs */
#guest-token-input,
#guest-name-input {
  width: 100%;
  padding: 14px 16px;
  font-size: 16px;
  border: 2px solid var(--bg-tertiary);
  border-radius: var(--border-radius);
  background: var(--bg-secondary);
  color: var(--text-primary);
  margin-bottom: 12px;
  outline: none;
  transition: border-color 0.2s;
}

#guest-token-input {
  text-align: center;
  font-family: monospace;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

#guest-token-input::placeholder {
  text-transform: none;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  font-weight: 400;
  letter-spacing: normal;
}

#guest-token-input:focus,
#guest-name-input:focus {
  border-color: var(--accent);
}

#guest-name-input::placeholder {
  color: var(--text-secondary);
}

.guest-name-hint {
  font-size: 11px;
  color: var(--text-secondary);
  opacity: 0.6;
  margin: -4px 0 8px 0;
  text-align: center;
}

/* Auth loading spinner */
.auth-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--bg-tertiary);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: auth-spin 0.8s linear infinite;
  margin: 20px auto 12px;
}

@keyframes auth-spin { to { transform: rotate(360deg); } }

#auth-loading p {
  color: var(--text-secondary);
  font-size: 14px;
}

/* Auth error */
#auth-error p {
  color: #ef4444;
  font-size: 14px;
  margin-bottom: 12px;
}

.hidden { display: none !important; }

/* Main Panel */
#main-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 16px;
  gap: 16px;
  overflow: hidden;
}

#main-panel.hidden {
  display: none;
}

/* Channel Section */
#channel-section {
  background: var(--bg-secondary);
  border-radius: var(--border-radius);
  padding: 12px 16px;
  flex-shrink: 0;
  position: relative;
  z-index: 10;
}

#channel-header {
  margin-bottom: 8px;
}

#channel-select {
  width: 100%;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 600;
  border: 1px solid var(--bg-tertiary);
  border-radius: 8px;
  background: var(--bg-primary);
  color: var(--text-secondary);
  outline: none;
  cursor: pointer;
}

#channel-select:focus {
  border-color: var(--accent);
}

#user-list-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

#user-list-summary {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
}

.chevron {
  font-size: 10px;
  color: var(--text-secondary);
  transition: transform 0.2s;
}

.chevron.open {
  transform: rotate(180deg);
}

#user-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  background: var(--bg-secondary);
  border-radius: 0 0 var(--border-radius) var(--border-radius);
  padding: 0 16px 12px;
  max-height: 180px;
  overflow-y: auto;
  transition: max-height 0.3s ease, opacity 0.2s ease, padding 0.3s ease;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
}

#user-list.collapsed {
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  padding-bottom: 0;
}

.user-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  font-size: 14px;
  border-radius: 8px;
  transition: background 0.2s;
}

.user-item.speaking {
  background: rgba(74, 222, 128, 0.1);
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.user-item.self .user-avatar {
  background: var(--accent);
  color: white;
}

.user-item.speaking .user-avatar {
  background: var(--success);
  color: var(--bg-primary);
  box-shadow: 0 0 8px rgba(74, 222, 128, 0.4);
}

.user-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-item.speaking .user-name {
  color: var(--success);
  font-weight: 500;
}

.user-item.self .user-name {
  font-weight: 600;
}

/* Animated speaking bars */
.speaking-bars {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-left: auto;
  flex-shrink: 0;
}

.speaking-bars .bar {
  width: 3px;
  background: var(--success);
  border-radius: 2px;
  animation: speakBar 0.8s ease-in-out infinite;
}

.speaking-bars .bar:nth-child(1) {
  height: 8px;
  animation-delay: 0s;
}

.speaking-bars .bar:nth-child(2) {
  height: 14px;
  animation-delay: 0.15s;
}

.speaking-bars .bar:nth-child(3) {
  height: 10px;
  animation-delay: 0.3s;
}

@keyframes speakBar {
  0%, 100% { transform: scaleY(0.5); opacity: 0.5; }
  50% { transform: scaleY(1); opacity: 1; }
}

/* GPS Section */
#gps-section {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-secondary);
  border-radius: var(--border-radius);
  padding: 10px 16px;
  flex-shrink: 0;
}

.gps-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.gps-label {
  font-size: 14px;
  font-weight: 600;
}

.gps-toggle input {
  display: none;
}

.gps-slider {
  width: 40px;
  height: 22px;
  background: var(--bg-tertiary);
  border-radius: 11px;
  position: relative;
  transition: background 0.2s;
}

.gps-slider::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  background: var(--text-secondary);
  border-radius: 50%;
  transition: transform 0.2s, background 0.2s;
}

.gps-toggle input:checked + .gps-slider {
  background: var(--success);
}

.gps-toggle input:checked + .gps-slider::after {
  transform: translateX(18px);
  background: white;
}

.gps-status {
  font-size: 12px;
  color: var(--text-secondary);
  margin-left: auto;
}

.gps-status.sending {
  color: var(--success);
}

.gps-status.no-permission {
  color: var(--warning);
}

.gps-note {
  font-size: 11px;
  color: var(--text-secondary);
  opacity: 0.6;
  margin-left: 8px;
}

/* Device Section */
#device-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
}

.device-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.device-icon {
  font-size: 18px;
  width: 24px;
  text-align: center;
}

.device-row select {
  flex: 1;
  padding: 10px 12px;
  font-size: 14px;
  border: 1px solid var(--bg-tertiary);
  border-radius: 8px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  outline: none;
  cursor: pointer;
}

.device-row select:focus {
  border-color: var(--accent);
}

/* PTT Section */
#ptt-section {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
}

#ptt-button {
  width: 100%;
  max-width: 280px;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 4px solid var(--bg-tertiary);
  background: linear-gradient(145deg, var(--bg-secondary), var(--bg-primary));
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.15s ease;
  user-select: none;
  -webkit-user-select: none;
  box-shadow:
    0 4px 15px rgba(0, 0, 0, 0.3),
    inset 0 2px 10px rgba(255, 255, 255, 0.05);
}

#ptt-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#ptt-button.listen-only {
  opacity: 0.5;
  background: #666;
  cursor: not-allowed;
  border-color: #555;
}

#ptt-button:not(:disabled):active,
#ptt-button.transmitting {
  border-color: var(--accent);
  background: linear-gradient(145deg, var(--accent), #0B80D4);
  box-shadow:
    0 0 30px var(--accent-glow),
    0 0 60px var(--accent-glow),
    inset 0 2px 10px rgba(255, 255, 255, 0.1);
  transform: scale(0.96);
}

.ptt-label {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 1px;
}

.ptt-hint {
  font-size: 12px;
  color: var(--text-secondary);
  opacity: 0.8;
}

#ptt-button.transmitting .ptt-hint {
  color: rgba(255, 255, 255, 0.8);
}

/* Inline TX/RX Radio Badges */
.radio-badges {
  margin-left: auto;
  display: none;
  gap: 6px;
}

.radio-badges.visible {
  display: flex;
}

.radio-badge {
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  transition: all 0.2s ease;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  opacity: 0.4;
}

.radio-badge.tx-active {
  background: var(--accent);
  color: white;
  opacity: 1;
  box-shadow: 0 0 8px var(--accent-glow);
  animation: badgePulse 1s ease-in-out infinite;
}

.radio-badge.rx-active {
  background: var(--success);
  color: var(--bg-primary);
  opacity: 1;
  box-shadow: 0 0 8px rgba(74, 222, 128, 0.5);
  animation: badgePulse 1s ease-in-out infinite;
}

@keyframes badgePulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* RX Audio Level (optional visual) */
#ptt-button.receiving {
  border-color: var(--success);
  box-shadow: 0 0 20px rgba(74, 222, 128, 0.4);
}

/* Disconnect Button */
#disconnect-btn {
  padding: 12px;
  font-size: 14px;
  font-weight: 500;
  border: 1px solid var(--text-secondary);
  border-radius: var(--border-radius);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

#disconnect-btn:active {
  background: rgba(255, 255, 255, 0.1);
}

/* Scrollbar styling */
::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--bg-tertiary);
  border-radius: 2px;
}

/* Prevent text selection on buttons */
button, select {
  -webkit-user-select: none;
  user-select: none;
}

/* Error toast */
.toast {
  position: fixed;
  bottom: calc(20px + var(--safe-area-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: #ef4444;
  color: white;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  z-index: 1000;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

/* Mobile GPS Map (collapsible) */
#mobile-map-section {
  background: var(--bg-secondary);
  border-radius: var(--border-radius);
  overflow: hidden;
  flex-shrink: 0;
}

#mobile-map-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}

.mobile-map-title {
  font-size: 14px;
  font-weight: 600;
}

#mobile-map-body {
  max-height: 250px;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

#mobile-map-body.collapsed {
  max-height: 0;
}

#mobile-map-container {
  width: 100%;
  height: 250px;
}

/* Shrink PTT when mobile map is expanded */
#main-panel.mobile-map-open {
  overflow-y: auto;
}

#main-panel.mobile-map-open #ptt-section {
  min-height: 120px;
}

#main-panel.mobile-map-open #ptt-button {
  max-width: 160px;
}

/* Map panel - hidden on mobile */
#map-panel {
  display: none;
}

#map-container {
  width: 100%;
  height: 100%;
}

.dark-tiles {
  filter: invert(1) hue-rotate(180deg) brightness(0.9) contrast(0.9);
}

.gps-layer-control select {
  appearance: none;
  -webkit-appearance: none;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23333'/%3E%3C/svg%3E") no-repeat right 8px center;
  border: none;
  border-radius: 4px;
  padding: 6px 24px 6px 10px;
  font-size: 12px;
  font-weight: 600;
  color: #333;
  cursor: pointer;
  min-width: 90px;
}

/* Tablet/Desktop layout */
@media (min-width: 768px) {
  #app {
    display: grid;
    grid-template-columns: 380px 1fr;
    grid-template-rows: auto 1fr;
  }

  #status-bar {
    grid-column: 1 / -1;
  }

  #connect-panel {
    grid-column: 1 / -1;
    grid-row: 2;
    z-index: 10;
  }

  #main-panel {
    grid-column: 1;
    overflow-y: auto;
  }

  #mobile-map-section {
    display: none;
  }

  #map-panel {
    display: block;
    grid-column: 2;
    grid-row: 2;
    position: relative;
    background: var(--bg-primary);
    min-height: 0;
  }

  #map-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
  }
}

/* Map overlays */
#map-overlays {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  z-index: 500;
}

.map-overlay {
  pointer-events: auto;
  background: rgba(26, 26, 26, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 13px;
}

#status-cards {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 280px;
  max-height: calc(100% - 24px);
  overflow: hidden;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.status-cards-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.status-cards-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
}

.status-cards-chevron {
  font-size: 10px;
  color: var(--text-secondary);
  transition: transform 0.2s;
}

#status-cards.collapsed .status-cards-chevron {
  transform: rotate(-90deg);
}

.status-cards-body {
  padding: 6px 10px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  transition: max-height 0.25s ease, padding 0.25s ease, opacity 0.2s ease;
}

#status-cards.collapsed .status-cards-body {
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  opacity: 0;
  overflow: hidden;
}

#status-cards.collapsed {
  max-height: none;
}

#status-cards.collapsed .status-cards-header {
  border-bottom: none;
}

.status-card-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 2px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  font-size: 13px;
}

.status-card-row:last-child {
  border-bottom: none;
}

.status-card-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-card-dot.online {
  background: var(--success);
}

.status-card-dot.offline {
  background: #666;
}

.status-card-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

.status-card-speed {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
}

.status-card-time {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
}

/* Reconnect Banner */
#reconnect-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 16px;
  background: rgba(251, 191, 36, 0.15);
  border: 1px solid var(--warning);
  border-radius: var(--border-radius);
  color: var(--warning);
  font-size: 14px;
  font-weight: 500;
  animation: reconnect-pulse 1.5s ease-in-out infinite;
  flex-shrink: 0;
}

#reconnect-banner.failed {
  background: rgba(239, 68, 68, 0.15);
  border-color: #ef4444;
  color: #ef4444;
  animation: none;
}

#reconnect-banner button {
  padding: 6px 14px;
  border: 1px solid currentColor;
  border-radius: 8px;
  background: transparent;
  color: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

#reconnect-banner button:active {
  opacity: 0.7;
}

.reconnect-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--warning);
  border-top-color: transparent;
  border-radius: 50%;
  animation: auth-spin 0.8s linear infinite;
  flex-shrink: 0;
}

@keyframes reconnect-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* Landscape adjustments */
@media (orientation: landscape) and (max-height: 500px) {
  #ptt-section {
    min-height: 150px;
  }

  #ptt-button {
    max-width: 150px;
  }

  #user-list {
    max-height: 80px;
  }
}
