:root {
  --bg-primary: #090B0E;
  --bg-surface: #111620;
  --bg-surface-elevated: #161D2B;
  --bg-glass: rgba(17, 22, 32, 0.85);
  --border-subtle: #1E293B;
  --border-highlight: #334155;

  --text-primary: #F0F6FC;
  --text-secondary: #94A3B8;
  --text-muted: #64748B;

  --accent: #10B981;
  --accent-glow: rgba(16, 185, 129, 0.35);
  --accent-hover: #059669;

  --danger: #EF4444;
  --danger-glow: rgba(239, 68, 68, 0.4);
  --danger-hover: #DC2626;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

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

html, body {
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-sans);
  overflow-x: hidden;
  font-size: 16px;
  line-height: 1.5;
}

/* Container & Layout */
.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  max-width: 560px;
  margin: 0 auto;
  padding: max(env(safe-area-inset-top), 16px) 16px max(env(safe-area-inset-bottom), 20px) 16px;
  position: relative;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0 16px 0;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 20px;
}

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

.brand-icon {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, #10B981 0%, #059669 100%);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #FFFFFF;
  box-shadow: 0 4px 14px var(--accent-glow);
}

.brand-name {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.brand-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  background: rgba(16, 185, 129, 0.15);
  color: var(--accent);
  border-radius: var(--radius-full);
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #64748B;
  transition: background-color 0.3s ease;
}

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

.status-dot.connecting {
  background-color: #F59E0B;
  box-shadow: 0 0 8px #F59E0B;
}

/* Card Surfaces */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 18px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Contact ID Box */
.id-display-box {
  background: var(--bg-primary);
  border: 1px solid var(--border-highlight);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.id-text {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--accent);
  word-break: break-all;
  user-select: all;
}

.action-buttons {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 18px;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  outline: none;
}

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

.btn-primary {
  background: var(--accent);
  color: #090B0E;
  flex: 1;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

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

.btn-secondary:hover {
  background: #1F293D;
}

.btn-icon-only {
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: var(--radius-md);
}

.btn-danger {
  background: var(--danger);
  color: #FFFFFF;
}

.btn-danger:hover {
  background: var(--danger-hover);
}

/* Form Inputs */
.input-group {
  margin-bottom: 14px;
}

.input-label {
  display: block;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.text-input {
  width: 100%;
  min-height: 48px;
  background: var(--bg-primary);
  border: 1px solid var(--border-highlight);
  border-radius: var(--radius-md);
  padding: 0 14px;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  user-select: text;
}

.text-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.25);
}

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

.call-buttons-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 10px;
}

/* Contacts List */
.contacts-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 240px;
  overflow-y: auto;
}

.contact-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.contact-info {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.contact-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

.contact-id-snippet {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}

.contact-actions {
  display: flex;
  gap: 6px;
}

.contact-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  cursor: pointer;
  background: var(--bg-surface);
  color: var(--text-secondary);
  transition: all 0.2s ease;
}

.contact-btn:hover {
  color: var(--accent);
  background: rgba(16, 185, 129, 0.15);
}

.contact-btn.delete-btn:hover {
  color: var(--danger);
  background: rgba(239, 68, 68, 0.15);
}

/* iOS PWA Install Banner */
.install-banner {
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.15) 0%, rgba(6, 78, 59, 0.2) 100%);
  border: 1px solid rgba(16, 185, 129, 0.35);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.install-text {
  font-size: 13px;
  color: var(--text-primary);
  line-height: 1.4;
}

.install-text strong {
  color: var(--accent);
}

/* Active Call Overlay (Fullscreen) */
.call-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background-color: #000000;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
}

.video-container {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.remote-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #090B0E;
  image-rendering: -webkit-optimize-contrast;
}

.local-video-pip {
  position: absolute;
  top: max(env(safe-area-inset-top), 20px);
  right: 16px;
  width: 110px;
  height: 160px;
  border-radius: var(--radius-md);
  object-fit: cover;
  background: #111620;
  border: 2px solid rgba(16, 185, 129, 0.6);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  z-index: 1010;
  cursor: pointer;
  transition: transform 0.25s ease, opacity 0.25s ease;
  image-rendering: -webkit-optimize-contrast;
}

.local-video-pip:active {
  transform: scale(0.95);
}

.local-video-pip.mirror {
  transform: scaleX(-1);
}

.local-video-pip.mirror:active {
  transform: scaleX(-1) scale(0.95);
}

/* Tap-to-Swap video feeds */
.video-container.swapped .remote-video {
  position: absolute;
  top: max(env(safe-area-inset-top), 20px);
  right: 16px;
  width: 110px;
  height: 160px;
  border-radius: var(--radius-md);
  border: 2px solid rgba(16, 185, 129, 0.6);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  z-index: 1010;
}

.video-container.swapped .local-video-pip {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border-radius: 0;
  border: none;
  box-shadow: none;
  z-index: 1;
}

.video-container.swapped .local-video-pip.mirror {
  transform: scaleX(-1);
}

/* Call Top Bar */
.call-header {
  position: relative;
  z-index: 1020;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: max(env(safe-area-inset-top), 20px) 20px 0 20px;
  pointer-events: none;
}

.call-timer-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 6px 14px;
  border-radius: var(--radius-full);
  font-size: 14px;
  font-weight: 600;
  color: #FFFFFF;
}

.recording-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--accent);
  box-shadow: 0 0 8px var(--accent);
  animation: pulse 1.5s infinite;
}

/* Floating Call Controls */
.call-controls-bar {
  position: relative;
  z-index: 1020;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding-bottom: max(env(safe-area-inset-bottom), 24px);
}

.controls-pill {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(17, 22, 32, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-full);
  padding: 10px 18px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
}

.control-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  cursor: pointer;
  background: var(--bg-surface-elevated);
  color: var(--text-primary);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  outline: none;
}

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

.control-btn.active {
  background: #334155;
  color: var(--danger);
}

.control-btn.end-btn {
  background: var(--danger);
  color: #FFFFFF;
  box-shadow: 0 4px 16px var(--danger-glow);
}

.control-btn.end-btn:hover {
  background: var(--danger-hover);
}

/* Incoming Call Modal */
.incoming-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1100;
  background: rgba(9, 11, 14, 0.88);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.incoming-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-surface);
  border: 1px solid var(--border-highlight);
  border-radius: var(--radius-lg);
  padding: 32px 24px;
  text-align: center;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.8);
}

.incoming-avatar {
  width: 80px;
  height: 80px;
  margin: 0 auto 18px auto;
  border-radius: 50%;
  background: linear-gradient(135deg, #10B981 0%, #059669 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #FFFFFF;
  box-shadow: 0 0 0 10px rgba(16, 185, 129, 0.2);
  animation: incomingPulse 2s infinite;
}

.incoming-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.incoming-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  margin-bottom: 24px;
}

.incoming-actions {
  display: flex;
  justify-content: center;
  gap: 20px;
}

.incoming-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  cursor: pointer;
  color: #FFFFFF;
  transition: transform 0.2s ease;
}

.incoming-btn:active {
  transform: scale(0.92);
}

.incoming-btn.accept {
  background: var(--accent);
  box-shadow: 0 4px 20px var(--accent-glow);
}

.incoming-btn.decline {
  background: var(--danger);
  box-shadow: 0 4px 20px var(--danger-glow);
}

/* Toast Message */
.toast {
  position: fixed;
  bottom: max(env(safe-area-inset-bottom), 30px);
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--accent);
  color: var(--text-primary);
  padding: 10px 20px;
  border-radius: var(--radius-full);
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  z-index: 2000;
  opacity: 0;
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
  pointer-events: none;
}

.toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* Animations */
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.9); }
}

@keyframes incomingPulse {
  0% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.5); }
  70% { box-shadow: 0 0 0 18px rgba(16, 185, 129, 0); }
  100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.hidden {
  display: none !important;
}

/* Header Install Button */
.btn-install-header {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid var(--accent);
  color: var(--accent);
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-install-header:hover {
  background: var(--accent);
  color: #090B0E;
}

/* iOS Safari Guide Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1200;
  background: rgba(9, 11, 14, 0.88);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-surface);
  border: 1px solid var(--border-highlight);
  border-radius: var(--radius-lg);
  padding: 28px 24px;
  text-align: center;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.8);
  position: relative;
}

.modal-close-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--bg-surface-elevated);
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.guide-step {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
  text-align: left;
  background: var(--bg-surface-elevated);
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.step-badge {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #090B0E;
  font-weight: 700;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.step-content {
  font-size: 14px;
  color: var(--text-primary);
  line-height: 1.4;
}

.step-content strong {
  color: var(--accent);
}

/* Header Token Settings Button */
.btn-token-header {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  min-width: 34px;
  min-height: 34px;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all 0.2s ease;
  padding: 0;
}

.btn-token-header:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(16, 185, 129, 0.12);
}

.btn-token-header:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Token Setup Modal */
.token-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.token-input-wrapper .text-input {
  padding-right: 44px;
  font-family: var(--font-mono);
  font-size: 13px;
}

.token-visibility-btn {
  position: absolute;
  right: 6px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: color 0.15s ease;
}

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

.token-error-msg {
  font-size: 13px;
  color: var(--danger);
  margin-top: 8px;
  text-align: left;
}

/* Background Audio Stream (iOS WebKit Keep-Alive) */
.background-audio-stream {
  position: fixed;
  top: -100px;
  left: -100px;
  width: 1px;
  height: 1px;
  opacity: 0.001;
  pointer-events: none;
}

/* Background Standby Toggle Switch (iOS WebKit Keep-Alive) */
.toggle-switch-btn {
  position: relative;
  width: 52px;
  height: 32px;
  min-width: 52px;
  min-height: 32px;
  background-color: var(--border-subtle);
  border: 1px solid var(--border-highlight);
  border-radius: var(--radius-full);
  cursor: pointer;
  padding: 0;
  display: inline-flex;
  align-items: center;
  transition: background-color 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
  outline: none;
  touch-action: manipulation;
}

/* 44x44px minimum touch target expansion for WCAG 2.2 / iOS HIG */
.toggle-switch-btn::after {
  content: '';
  position: absolute;
  top: -8px;
  bottom: -8px;
  left: -8px;
  right: -8px;
}

.toggle-switch-btn:focus-visible {
  box-shadow: 0 0 0 2px var(--accent);
}

.toggle-switch-btn.active,
.toggle-switch-btn[aria-pressed="true"] {
  background-color: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
}

.toggle-switch-knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  background-color: #FFFFFF;
  border-radius: 50%;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.35);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
}

.toggle-switch-btn.active .toggle-switch-knob,
.toggle-switch-btn[aria-pressed="true"] .toggle-switch-knob {
  transform: translateX(20px);
}

/* Pull to Refresh & Reload Animations */
@keyframes spinReload {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.spinning-icon {
  animation: spinReload 0.8s linear infinite;
}

.pull-refresh-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  margin-bottom: 12px;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-highlight);
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}


