/* ============================================================
   SARAH Voice — Global Styles
   ============================================================ */

:root {
  --purple: #6c3ce0;
  --purple-hover: #7c4ff0;
  --purple-glow: rgba(108, 60, 224, 0.3);
  --bg-dark: #1a1a2e;
  --bg-card: #22223a;
  --bg-input: #2a2a44;
  --text-primary: #e8e8f0;
  --text-secondary: #8888a0;
  --text-muted: #555570;
  --success: #4ade80;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --warning: #f59e0b;
  --border: rgba(255,255,255,0.06);
  --radius: 14px;
  --radius-sm: 10px;
  --radius-lg: 20px;
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg-dark);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
}

body {
  position: fixed;
  width: 100%;
}

#app {
  height: 100%;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
}

@media (min-width: 768px) {
  #app {
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}

/* ============================================================
   Offline Banner
   ============================================================ */

.offline-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 9999;
  background: var(--warning);
  color: #1a1a2e;
  text-align: center;
  padding: 6px 16px;
  font-size: 13px;
  font-weight: 600;
  transform: translateY(0);
  transition: transform var(--transition);
}

.offline-banner.hidden {
  transform: translateY(-100%);
}

/* ============================================================
   Toast
   ============================================================ */

.toast-container {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  width: 90%;
  max-width: 400px;
}

.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 14px;
  color: var(--text-primary);
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  animation: toastIn 0.3s ease-out;
  pointer-events: auto;
}

.toast.toast-error { border-left: 3px solid var(--danger); }
.toast.toast-success { border-left: 3px solid var(--success); }
.toast.toast-info { border-left: 3px solid var(--purple); }

.toast.toast-out {
  animation: toastOut 0.25s ease-in forwards;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(-12px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes toastOut {
  to { opacity: 0; transform: translateY(-12px); }
}

/* ============================================================
   Auth Pages (Login / Signup)
   ============================================================ */

.auth-page {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: fadeIn 0.4s ease;
}

.auth-logo {
  font-size: 48px;
  margin-bottom: 8px;
}

.auth-title {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 4px;
  background: linear-gradient(135deg, var(--purple), #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.auth-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 32px;
}

.auth-form {
  width: 100%;
  max-width: 360px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.input-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.input-group label {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.input-group input {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-size: 16px;
  color: var(--text-primary);
  font-family: var(--font);
  outline: none;
  transition: border-color var(--transition);
  width: 100%;
}

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

.input-group input:focus {
  border-color: var(--purple);
  box-shadow: 0 0 0 3px var(--purple-glow);
}

.input-row {
  display: flex;
  gap: 10px;
}

.input-row .input-group {
  flex: 1;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 16px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}

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

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

.btn-primary:hover:not(:disabled) {
  background: var(--purple-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 20px var(--purple-glow);
}

.btn-primary:active:not(:disabled) {
  transform: translateY(0);
}

.btn-ghost {
  background: transparent;
  color: var(--purple);
  padding: 10px 16px;
  font-size: 14px;
}

.btn-ghost:hover {
  background: rgba(108, 60, 224, 0.1);
}

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

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

.btn-block {
  width: 100%;
}

.btn .spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

.auth-footer {
  margin-top: 20px;
  font-size: 14px;
  color: var(--text-secondary);
  text-align: center;
}

.auth-footer a, .link {
  color: var(--purple);
  text-decoration: none;
  cursor: pointer;
  font-weight: 500;
}

.auth-footer a:hover, .link:hover {
  text-decoration: underline;
}

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

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

/* ============================================================
   Verify / Magic Link Pages
   ============================================================ */

.verify-page {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  animation: fadeIn 0.4s ease;
}

.verify-icon {
  font-size: 64px;
  margin-bottom: 16px;
}

.verify-title {
  font-size: 22px;
  font-weight: 600;
  margin-bottom: 8px;
}

.verify-text {
  font-size: 14px;
  color: var(--text-secondary);
  max-width: 280px;
}

/* ============================================================
   Phone (Main App) Layout
   ============================================================ */

.phone-page {
  height: 100%;
  display: flex;
  flex-direction: column;
  animation: fadeIn 0.3s ease;
}

.phone-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  padding-top: max(16px, env(safe-area-inset-top));
  background: var(--bg-dark);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.phone-header-title {
  font-size: 20px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--purple), #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.phone-header-actions {
  display: flex;
  gap: 8px;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
}

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

.phone-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

.phone-nav {
  display: flex;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  flex-shrink: 0;
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 10px 0;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 11px;
  font-family: var(--font);
  font-weight: 500;
  cursor: pointer;
  transition: color var(--transition);
  position: relative;
}

.nav-item .nav-icon {
  font-size: 22px;
  transition: transform var(--transition);
}

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

.nav-item.active .nav-icon {
  transform: scale(1.1);
}

.nav-item::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%) scaleX(0);
  width: 32px;
  height: 3px;
  background: var(--purple);
  border-radius: 0 0 3px 3px;
  transition: transform var(--transition);
}

.nav-item.active::before {
  transform: translateX(-50%) scaleX(1);
}

/* ============================================================
   View Transitions
   ============================================================ */

.view-enter {
  animation: viewIn 0.3s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes viewIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   Dialpad View
   ============================================================ */

.dialpad-view {
  padding: 24px 20px;
}

.email-call-box {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 28px 20px;
  text-align: center;
  margin-bottom: 28px;
  border: 1px solid var(--border);
}

.email-call-box h2 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
}

.email-input-wrap {
  position: relative;
  margin-bottom: 16px;
}

.email-input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  font-size: 16px;
  color: var(--text-primary);
  font-family: var(--font);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  text-align: center;
}

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

.email-input:focus {
  border-color: var(--purple);
  box-shadow: 0 0 0 3px var(--purple-glow);
}

.call-btn {
  width: 100%;
  padding: 16px;
  font-size: 18px;
  border-radius: var(--radius);
  background: var(--purple);
  color: white;
  border: none;
  font-family: var(--font);
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}

.call-btn:hover:not(:disabled) {
  background: var(--purple-hover);
  transform: translateY(-2px);
  box-shadow: 0 8px 30px var(--purple-glow);
}

.call-btn:active:not(:disabled) {
  transform: translateY(0);
}

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

.call-btn .call-icon {
  font-size: 22px;
}

.interpreter-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-top: 14px;
  font-size: 13px;
  color: var(--text-secondary);
}

.toggle-switch {
  position: relative;
  width: 44px;
  height: 24px;
  cursor: pointer;
}

.toggle-switch input {
  display: none;
}

.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--bg-input);
  border-radius: 12px;
  transition: background var(--transition);
}

.toggle-switch input:checked + .toggle-track {
  background: var(--purple);
}

.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: white;
  border-radius: 50%;
  transition: transform var(--transition);
  pointer-events: none;
}

.toggle-switch input:checked ~ .toggle-thumb {
  transform: translateX(20px);
}

/* Recent calls section */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.section-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-secondary);
}

.section-action {
  font-size: 13px;
  color: var(--purple);
  cursor: pointer;
  border: none;
  background: none;
  font-family: var(--font);
  font-weight: 500;
}

/* ============================================================
   Call / Contact List Items
   ============================================================ */

.list-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.list-empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
  opacity: 0.4;
}

.list-empty-text {
  font-size: 14px;
}

.call-item, .contact-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 20px;
  cursor: pointer;
  transition: background var(--transition);
  border-bottom: 1px solid var(--border);
}

.call-item:hover, .contact-item:hover {
  background: rgba(108, 60, 224, 0.05);
}

.call-item:last-child, .contact-item:last-child {
  border-bottom: none;
}

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--bg-input);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 600;
  color: var(--purple);
  flex-shrink: 0;
  position: relative;
}

.avatar-online::after {
  content: '';
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 12px;
  height: 12px;
  background: var(--success);
  border: 2px solid var(--bg-dark);
  border-radius: 50%;
}

.item-info {
  flex: 1;
  min-width: 0;
}

.item-name {
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-sub {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.item-meta {
  text-align: right;
  flex-shrink: 0;
}

.item-time {
  font-size: 12px;
  color: var(--text-muted);
}

.item-duration {
  font-size: 12px;
  color: var(--text-secondary);
}

.call-direction {
  font-size: 16px;
}

.call-direction.outgoing { color: var(--success); }
.call-direction.incoming { color: var(--purple); }
.call-direction.missed { color: var(--danger); }

/* ============================================================
   Contacts View
   ============================================================ */

.contacts-view {
  padding-bottom: 80px;
}

.contacts-search {
  padding: 16px 20px;
}

.search-input {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px 12px 42px;
  font-size: 15px;
  color: var(--text-primary);
  font-family: var(--font);
  outline: none;
  transition: border-color var(--transition);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' fill='none' stroke='%238888a0' stroke-width='2' stroke-linecap='round'%3E%3Ccircle cx='8' cy='8' r='5'/%3E%3Cline x1='12' y1='12' x2='16' y2='16'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: 14px center;
}

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

.search-input:focus {
  border-color: var(--purple);
}

.fab {
  position: fixed;
  bottom: calc(72px + var(--safe-bottom));
  right: calc(50% - 210px);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--purple);
  color: white;
  font-size: 28px;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 20px var(--purple-glow);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  z-index: 50;
}

@media (max-width: 480px) {
  .fab { right: 20px; }
}

.fab:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px var(--purple-glow);
}

/* ============================================================
   History View
   ============================================================ */

.history-view {
  padding: 0;
}

.history-date-header {
  padding: 12px 20px 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ============================================================
   Settings View
   ============================================================ */

.settings-view {
  padding: 20px;
}

.settings-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  margin-bottom: 16px;
}

.settings-card-title {
  padding: 14px 18px 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.settings-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

.settings-item:last-child {
  border-bottom: none;
}

.settings-label {
  font-size: 15px;
}

.settings-value {
  font-size: 14px;
  color: var(--text-secondary);
}

.settings-value.verified {
  color: var(--success);
}

.settings-value.unverified {
  color: var(--warning);
}

.profile-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px 18px;
  border-bottom: 1px solid var(--border);
}

.profile-avatar {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--purple), #a78bfa);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}

.profile-info h3 {
  font-size: 18px;
  font-weight: 600;
}

.profile-info p {
  font-size: 14px;
  color: var(--text-secondary);
}

/* ============================================================
   Calling Screen Overlay
   ============================================================ */

.call-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: linear-gradient(180deg, #1a1a2e 0%, #16162a 50%, #121226 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 60px 24px calc(40px + var(--safe-bottom));
  transform: translateY(100%);
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.call-overlay.active {
  transform: translateY(0);
}

.call-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  text-align: center;
}

.call-avatar {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--purple), #a78bfa);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 42px;
  color: white;
  margin-bottom: 12px;
  position: relative;
}

.call-avatar.ringing::after {
  content: '';
  position: absolute;
  inset: -8px;
  border: 2px solid var(--purple);
  border-radius: 50%;
  animation: pulse-ring 1.5s ease-out infinite;
}

@keyframes pulse-ring {
  0% { transform: scale(1); opacity: 0.6; }
  100% { transform: scale(1.3); opacity: 0; }
}

.call-name {
  font-size: 26px;
  font-weight: 700;
}

.call-email {
  font-size: 14px;
  color: var(--text-secondary);
}

.call-status {
  font-size: 16px;
  color: var(--text-secondary);
  margin-top: 8px;
}

.call-timer {
  font-size: 38px;
  font-weight: 300;
  font-variant-numeric: tabular-nums;
  color: var(--text-primary);
  margin-top: 4px;
  letter-spacing: 2px;
}

.call-message {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 8px;
  max-width: 260px;
  text-align: center;
}

.call-controls {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
  justify-content: center;
}

.call-control-btn {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  flex-direction: column;
}

.call-control-btn span.control-label {
  font-size: 10px;
  margin-top: 2px;
  color: var(--text-muted);
}

.call-control-btn:hover {
  background: var(--bg-input);
}

.call-control-btn.active {
  background: var(--purple);
  border-color: var(--purple);
  color: white;
}

.call-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  width: 100%;
}

.end-call-btn {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--danger);
  border: none;
  color: white;
  font-size: 30px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  box-shadow: 0 4px 20px rgba(239, 68, 68, 0.3);
}

.end-call-btn:hover {
  background: var(--danger-hover);
  transform: scale(1.06);
}

/* ============================================================
   Modal (Add Contact, etc.)
   ============================================================ */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 500;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.modal-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 28px 24px calc(24px + var(--safe-bottom));
  width: 100%;
  max-width: 480px;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal-backdrop.active .modal {
  transform: translateY(0);
}

.modal-handle {
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: var(--text-muted);
  margin: 0 auto 20px;
}

.modal h3 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 20px;
}

.modal .input-group {
  margin-bottom: 14px;
}

.modal .btn {
  margin-top: 8px;
}

/* ============================================================
   Skeleton Loaders
   ============================================================ */

.skeleton {
  background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-input) 50%, var(--bg-card) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease infinite;
  border-radius: var(--radius-sm);
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 20px;
}

.skeleton-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
}

.skeleton-lines {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.skeleton-line {
  height: 14px;
  border-radius: 7px;
}

.skeleton-line.short { width: 60%; }
.skeleton-line.medium { width: 80%; }

/* ============================================================
   Scrollbar
   ============================================================ */

.phone-content::-webkit-scrollbar {
  width: 4px;
}

.phone-content::-webkit-scrollbar-track {
  background: transparent;
}

.phone-content::-webkit-scrollbar-thumb {
  background: var(--text-muted);
  border-radius: 2px;
}

/* ============================================================
   Utilities
   ============================================================ */

/* ============================================================
   Recording Indicator & Controls
   ============================================================ */

.call-control-btn#ctrl-record.active {
  background: var(--danger);
  color: #fff;
  animation: pulse-record 1.5s ease infinite;
}

@keyframes pulse-record {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.5); }
  50% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
}

.recording-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s ease;
}

.recording-item:hover {
  background: var(--bg-input);
}

.recording-item:active {
  background: rgba(108, 60, 224, 0.08);
}

.recordings-view .section-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.recordings-view .section-action {
  font-size: 14px;
}

/* Audio player styling */
audio {
  border-radius: var(--radius-md);
  background: var(--bg-input);
}

audio::-webkit-media-controls-panel {
  background: var(--bg-input);
}

/* ============================================================
   Utilities
   ============================================================ */

.hidden { display: none !important; }
.text-center { text-align: center; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }

/* ─── Incoming Call Controls ─────────────────── */
.incoming-controls {
  display: flex;
  gap: 24px;
  justify-content: center;
  align-items: center;
}

.answer-call-btn {
  background: linear-gradient(135deg, #10b981 0%, #059669 100%);
  color: white;
  border: none;
  border-radius: 50px;
  padding: 16px 32px;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(16, 185, 129, 0.4);
  transition: all 0.2s;
}
.answer-call-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 28px rgba(16, 185, 129, 0.5);
}

/* Incoming call pulse animation on avatar */
@keyframes incoming-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4); }
  50% { box-shadow: 0 0 0 20px rgba(16, 185, 129, 0); }
}
.call-avatar.incoming {
  animation: incoming-pulse 1.5s ease infinite;
}

/* ═══════════════════════════════════════════════════════════════
   Messaging Styles
   ═══════════════════════════════════════════════════════════════ */

/* Message badge on nav tab */
.msg-badge {
  position: absolute;
  top: 2px;
  right: 4px;
  background: #ef4444;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  line-height: 16px;
  border-radius: 8px;
  text-align: center;
  padding: 0 4px;
}

.nav-item { position: relative; }

/* Conversation list header */
.msg-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 8px;
}
.msg-header h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  color: #e0e0e0;
}

/* Conversation list */
.conv-list {
  padding: 8px 12px;
  overflow-y: auto;
  flex: 1;
}

.conv-item {
  display: flex;
  align-items: center;
  padding: 12px;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.15s;
  margin-bottom: 2px;
}
.conv-item:hover { background: rgba(139, 92, 246, 0.08); }
.conv-item:active { background: rgba(139, 92, 246, 0.15); }

.conv-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, #8b5cf6, #06b6d4);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  flex-shrink: 0;
  position: relative;
}
.conv-avatar.online::after {
  content: '';
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 12px;
  height: 12px;
  background: #10b981;
  border: 2px solid #12122a;
  border-radius: 50%;
}

.conv-body {
  flex: 1;
  min-width: 0;
  margin-left: 12px;
}

.conv-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 2px;
}
.conv-name {
  font-weight: 600;
  color: #e0e0e0;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-time {
  font-size: 12px;
  color: #888;
  flex-shrink: 0;
  margin-left: 8px;
}

.conv-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.conv-preview {
  font-size: 13px;
  color: #888;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-unread .conv-preview { color: #c0c0d0; font-weight: 500; }
.conv-unread .conv-name { color: #fff; }
.conv-unread .conv-time { color: #8b5cf6; }

.conv-badge {
  background: #8b5cf6;
  color: white;
  font-size: 11px;
  font-weight: 700;
  min-width: 20px;
  height: 20px;
  line-height: 20px;
  border-radius: 10px;
  text-align: center;
  padding: 0 6px;
  flex-shrink: 0;
  margin-left: 8px;
}

/* Chat view */
.chat-header {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  background: rgba(18, 18, 42, 0.95);
  border-bottom: 1px solid rgba(139, 92, 246, 0.15);
  gap: 10px;
}
.chat-back {
  background: none;
  border: none;
  color: #8b5cf6;
  font-size: 24px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
}
.chat-back:hover { background: rgba(139, 92, 246, 0.1); }

.chat-header-info { flex: 1; min-width: 0; }
.chat-header-name { font-weight: 600; color: #e0e0e0; font-size: 15px; }
.chat-header-email { font-size: 12px; color: #888; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Messages area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  scroll-behavior: smooth;
}

.chat-date-sep {
  text-align: center;
  font-size: 12px;
  color: #888;
  margin: 12px 0;
  display: flex;
  align-items: center;
  gap: 12px;
}
.chat-date-sep::before,
.chat-date-sep::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid rgba(139, 92, 246, 0.1);
}

.chat-empty, .chat-loading, .chat-error {
  text-align: center;
  color: #888;
  padding: 40px 20px;
  font-size: 14px;
}

/* Message bubbles */
.msg-bubble {
  max-width: 75%;
  padding: 8px 12px;
  border-radius: 16px;
  position: relative;
  word-wrap: break-word;
  line-height: 1.4;
}
.msg-mine {
  align-self: flex-end;
  background: linear-gradient(135deg, #8b5cf6 0%, #7c3aed 100%);
  color: white;
  border-bottom-right-radius: 4px;
}
.msg-theirs {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.08);
  color: #e0e0e0;
  border-bottom-left-radius: 4px;
}

.msg-text {
  font-size: 14px;
  white-space: pre-wrap;
}

.msg-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 2px;
}
.msg-time {
  font-size: 11px;
  opacity: 0.65;
}
.msg-status {
  font-size: 12px;
  opacity: 0.65;
}
.msg-status.read { color: #06b6d4; opacity: 1; }
.msg-edited {
  font-size: 11px;
  opacity: 0.5;
  font-style: italic;
}
.msg-deleted {
  font-style: italic;
  opacity: 0.5;
  font-size: 13px;
  padding: 8px 12px;
}
.msg-deleted-bubble {
  background: transparent !important;
  border: 1px dashed rgba(255,255,255,0.1);
}

/* Typing indicator */
.typing-indicator {
  padding: 4px 16px;
  font-size: 12px;
  color: #888;
  display: flex;
  align-items: center;
  gap: 6px;
}
.typing-dots span {
  animation: typingBounce 1.4s infinite;
  font-size: 18px;
  line-height: 1;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
  0%, 60%, 100% { opacity: 0.3; }
  30% { opacity: 1; }
}

/* Chat input bar */
.chat-input-bar {
  display: flex;
  align-items: flex-end;
  padding: 8px 12px;
  gap: 8px;
  border-top: 1px solid rgba(139, 92, 246, 0.1);
  background: rgba(18, 18, 42, 0.95);
}
.chat-input-bar textarea {
  flex: 1;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(139, 92, 246, 0.2);
  border-radius: 20px;
  padding: 10px 16px;
  color: #e0e0e0;
  font-size: 14px;
  resize: none;
  min-height: 40px;
  max-height: 120px;
  outline: none;
  font-family: inherit;
}
.chat-input-bar textarea:focus {
  border-color: rgba(139, 92, 246, 0.5);
}
.chat-send-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: linear-gradient(135deg, #8b5cf6, #06b6d4);
  color: white;
  border: none;
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s, opacity 0.15s;
}
.chat-send-btn:hover { transform: scale(1.05); }
.chat-send-btn:active { transform: scale(0.95); }

/* Attach button */
.chat-attach-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(139, 92, 246, 0.2);
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, transform 0.15s;
}
.chat-attach-btn:hover { background: rgba(139, 92, 246, 0.15); transform: scale(1.05); }
.chat-attach-btn:active { transform: scale(0.95); }

/* Attachment preview bar */
.attach-preview {
  border-top: 1px solid rgba(139, 92, 246, 0.15);
  background: rgba(18, 18, 42, 0.95);
  padding: 8px 12px;
}
.attach-preview-inner {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255,255,255,0.04);
  border-radius: 12px;
  padding: 8px 12px;
}
.attach-thumb {
  width: 60px;
  height: 60px;
  object-fit: cover;
  border-radius: 8px;
}
.attach-file-icon {
  font-size: 32px;
  flex-shrink: 0;
}
.attach-info {
  flex: 1;
  min-width: 0;
}
.attach-name {
  font-size: 13px;
  color: #e0e0e0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.attach-size {
  font-size: 11px;
  color: #888;
  margin-top: 2px;
}
.attach-cancel {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: rgba(239, 68, 68, 0.2);
  border: none;
  color: #ef4444;
  font-size: 14px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.attach-cancel:hover { background: rgba(239, 68, 68, 0.4); }

/* Message attachment rendering */
.msg-attachment { margin-bottom: 4px; }
.msg-image {
  cursor: pointer;
  border-radius: 8px;
  overflow: hidden;
  max-width: 280px;
}
.msg-image img {
  width: 100%;
  display: block;
  border-radius: 8px;
}
.msg-audio {
  min-width: 200px;
}
.msg-audio audio {
  width: 100%;
  height: 36px;
  border-radius: 18px;
}
.msg-audio .msg-file-name {
  font-size: 11px;
  color: #888;
  margin-top: 2px;
}
.msg-file .file-download {
  display: flex;
  align-items: center;
  gap: 8px;
  text-decoration: none;
  color: inherit;
  padding: 6px 0;
}
.msg-file .file-icon { font-size: 28px; flex-shrink: 0; }
.msg-file .file-info { flex: 1; min-width: 0; }
.msg-file .file-name {
  font-size: 13px;
  color: #8b5cf6;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.msg-file .file-size { font-size: 11px; color: #888; }
.msg-file .file-dl-icon { font-size: 16px; color: #06b6d4; flex-shrink: 0; }

/* Image viewer modal */
.image-viewer {
  padding: 20px;
  text-align: center;
}
.image-viewer img {
  max-width: 90vw;
  max-height: 80vh;
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

/* Make phone-content flex for chat layout */
.phone-content:has(.chat-header) {
  display: flex;
  flex-direction: column;
}

/* ============================================================
   Textarea in forms (matches .input-group input)
   ============================================================ */
.input-group textarea {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-size: 16px;
  color: var(--text-primary);
  font-family: var(--font);
  outline: none;
  transition: border-color var(--transition);
  width: 100%;
  resize: vertical;
  min-height: 80px;
  line-height: 1.5;
}
.input-group textarea::placeholder {
  color: var(--text-muted);
}
.input-group textarea:focus {
  border-color: var(--purple);
  box-shadow: 0 0 0 3px var(--purple-glow);
}

/* ============================================================
   Compose View — textarea matches email-input style
   ============================================================ */
.compose-textarea {
  text-align: left !important;
  resize: vertical;
  min-height: 100px;
  max-height: 200px;
  line-height: 1.5;
  font-size: 15px !important;
}

/* ============================================================
   Decline Call Button — pill style matching Answer button
   ============================================================ */
.decline-call-btn {
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
  color: white;
  border: none;
  border-radius: 50px;
  padding: 16px 32px;
  font-size: 18px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(239, 68, 68, 0.4);
  transition: all 0.2s;
}
.decline-call-btn:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 28px rgba(239, 68, 68, 0.5);
}
