:root {
  --blue: #0C71C3;
  --blue-dark: #063B6D;
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-input: #334155;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --border: #334155;
  --green: #10b981;
  --red: #ef4444;
  --radius: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

.hidden { display: none !important; }
* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

/* ── Layout ── */

.app-container {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 16px;
  padding-bottom: calc(80px + var(--safe-bottom));
  min-height: 100dvh;
}

/* ── Header ── */

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 110;
  margin: 0 -16px 12px;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(51, 65, 85, 0.5);
}

.header-logo-container {
  display: flex;
  align-items: center;
  gap: 14px;
}

.header-logo {
  width: 44px;
  height: 44px;
  object-fit: contain;
  border-radius: 12px;
  background: var(--bg-card);
  padding: 4px;
}

.page-header h1 {
  font-size: 20px;
  font-weight: 900;
  letter-spacing: 1.5px;
  margin: 0;
  line-height: 1;
  text-transform: uppercase;
}

.status-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(16, 185, 129, 0.1);
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid rgba(16, 185, 129, 0.2);
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
}

.status-text {
  font-size: 11px;
  font-weight: 700;
  color: var(--green);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ── Bottom Nav ── */

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  padding: 8px 0 calc(8px + var(--safe-bottom));
  z-index: 150;
}

.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 16px;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  text-decoration: none;
  transition: color 0.2s;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.nav-btn.active, .nav-btn:active { color: var(--blue); }
.nav-btn svg { width: 24px; height: 24px; }

/* ── Search ── */

.search-bar {
  position: relative;
  margin-bottom: 16px;
}

.search-bar input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px 12px 44px;
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
}

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

.search-bar svg {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  color: var(--text-muted);
}

/* ── Contact List ── */

.contact-list { display: flex; flex-direction: column; gap: 2px; }

.contact-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg-card);
  border-radius: 12px;
  transition: background 0.15s;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.contact-item:active { background: var(--bg-input); }

.contact-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--blue);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  color: white;
  flex-shrink: 0;
}

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

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

.contact-phone {
  font-size: 13px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.contact-call-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--green);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

.contact-call-btn svg { width: 20px; height: 20px; color: white; }

/* ── Dialer ── */

.dialer-wrap {
  max-width: 340px;
  margin: 0 auto;
}

.dialer-display {
  text-align: center;
  padding: 24px 16px 20px;
}

.dialer-number {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--text);
  min-height: 44px;
  font-variant-numeric: tabular-nums;
  word-break: break-all;
}

.dialer-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  padding: 0 24px;
  max-width: 360px;
  margin: 0 auto;
}

.dial-key {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: var(--bg-input);
  border: none;
  color: var(--text);
  font-size: 28px;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.1s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.dial-key:active { background: var(--blue); }

.dial-key small {
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 2px;
  font-weight: 500;
}

.dial-actions {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 48px;
  padding: 24px 0 16px;
  position: relative;
  z-index: 100;
}

.call-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: var(--green);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.call-btn:active { transform: scale(0.9); }
.call-btn svg { width: 28px; height: 28px; color: white; }

.backspace-btn {
  width: 48px;
  height: 48px;
  border: none;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

.backspace-btn svg { width: 24px; height: 24px; }

/* ── Dialer Recents ── */

.recents-section {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.recents-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
  padding: 0 4px;
}

/* ── Modal Overlay ── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(6px);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  /* Bloque le scroll natif du viewport en dessous sur Android/iOS */
  overscroll-behavior: contain;
  touch-action: none;
}

/* Réautoriser le scroll à l'intérieur de la modale */
.modal-content {
  touch-action: pan-y;
}

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

@keyframes slideUp {
  from { transform: translateY(100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ── Detail Modal Compact ── */

.modal-content {
  background: var(--bg-card);
  border-radius: 24px 24px 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 88dvh;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border-top: 1px solid rgba(255,255,255,0.07);
}

/* Hero ligne horizontale : avatar + nom + badge */
.modal-hero {
  position: relative;
  padding: 20px 56px 16px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}

.modal-close-top {
  position: absolute;
  top: 14px;
  right: 16px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-input);
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.detail-avatar {
  width: 52px;
  height: 52px;
  background: linear-gradient(135deg, var(--blue), var(--blue-dark));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 800;
  color: white;
  flex-shrink: 0;
}

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

.detail-main-info h2 {
  font-size: 18px;
  font-weight: 800;
  margin-bottom: 5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Grille 2 colonnes compacte */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 12px 20px;
  flex-shrink: 0;
}

.detail-pill {
  background: var(--bg-input);
  padding: 10px 12px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.detail-pill.wide { grid-column: span 3; }

.detail-pill-label {
  font-size: 9px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.detail-pill-value {
  font-size: 13px;
  font-weight: 600;
}

/* Lecteur custom intégré au thème */
.custom-player {
  background: var(--bg-input);
  margin: 0 20px 12px;
  padding: 12px 16px;
  border-radius: 16px;
  flex-shrink: 0;
}

.player-controls {
  display: flex;
  align-items: center;
  gap: 14px;
}

.play-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--blue);
  border: none;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}

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

.player-progress-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.progress-bar-bg {
  width: 100%;
  height: 5px;
  background: rgba(255,255,255,0.1);
  border-radius: 3px;
  position: relative;
  cursor: pointer;
}

.progress-bar-fill {
  position: absolute;
  left: 0; top: 0;
  height: 100%;
  background: var(--blue);
  border-radius: 3px;
  width: 0%;
}

.player-time {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* Transcription : seule zone scrollable */
.transcription-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 0 20px 12px;
  min-height: 0;
}

.transcription-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  font-size: 9px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}

/* Zone chat — remplace transcription-bubble */
.chat-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 5px;
  padding: 4px 0 6px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  min-height: 40px;
}

.chat-container.loading {
  align-items: center;
  justify-content: center;
}

.chat-bubble {
  max-width: 80%;
  padding: 8px 13px;
  border-radius: 18px;
  font-size: 13.5px;
  line-height: 1.5;
  word-break: break-word;
  animation: bubbleIn 0.2s ease both;
}

.chat-bubble.left {
  align-self: flex-start;
  background: #95FFA3;
  color: #0a2e0d;
  border-bottom-left-radius: 4px;
}

.chat-bubble.right {
  align-self: flex-end;
  background: #A6CAFF;
  color: #0a1f3d;
  border-bottom-right-radius: 4px;
}

@keyframes bubbleIn {
  from { opacity: 0; transform: scale(0.92) translateY(4px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.transcription-loading {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 13px;
  font-style: italic;
}

.transcription-loading span {
  display: block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.15);
  border-top-color: var(--primary-blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

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

/* Actions horizontales compactes */
.detail-actions {
  padding: 12px 20px calc(20px + var(--safe-bottom));
  display: flex;
  gap: 10px;
  flex-shrink: 0;
}

.detail-actions .btn {
  height: 52px;
  border-radius: 16px;
  flex: 1;
}

.detail-actions .btn-primary { flex: 2; }

/* ── Contacts Modal ── */

.contact-modal-content {
  background: var(--bg-card);
  border-radius: 24px 24px 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 85dvh;
  overflow-y: auto;
  padding: 0 20px 32px;
  animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border-top: 1px solid rgba(255,255,255,0.07);
  -webkit-overflow-scrolling: touch;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 0 16px;
  margin-bottom: 4px;
  position: sticky;
  top: 0;
  background: var(--bg-card);
  z-index: 1;
}

.modal-header h2 { font-size: 18px; font-weight: 700; }

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-input);
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ── Forms ── */

.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.form-group input,
.form-group textarea {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus,
.form-group textarea:focus { border-color: var(--blue); }

.form-group textarea { resize: vertical; min-height: 80px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: 10px;
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
  width: 100%;
}

.btn:active { opacity: 0.8; }
.btn-primary { background: var(--blue); color: white; }
.btn-danger { background: var(--red); color: white; }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }

/* ── Login ── */

.login-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 300;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px;
}

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

.login-box { width: 100%; max-width: 360px; text-align: center; }

.login-logo {
  width: 80px;
  height: 80px;
  object-fit: contain;
  border-radius: 20px;
  margin-bottom: 16px;
}

.login-box h1 {
  font-size: 28px;
  font-weight: 800;
  margin-bottom: 24px;
  letter-spacing: 2px;
}

.login-error {
  color: var(--red);
  font-size: 13px;
  margin-top: 8px;
  min-height: 20px;
}

/* ── FAB ── */

.fab {
  position: fixed;
  right: 20px;
  bottom: calc(80px + var(--safe-bottom) + 16px);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--blue);
  border: none;
  color: white;
  font-size: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 4px 20px rgba(12, 113, 195, 0.4);
  z-index: 40;
  -webkit-tap-highlight-color: transparent;
}

/* ── Toast ── */

#toastContainer {
  position: fixed;
  top: 16px;
  left: 16px;
  right: 16px;
  z-index: 400;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

/* ── History List ── */

.history-list { display: flex; flex-direction: column; gap: 2px; }

.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg-card);
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.history-item:active { background: var(--bg-input); }

.history-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.history-icon.inbound { background: rgba(16, 185, 129, 0.15); color: var(--green); }
.history-icon.outbound { background: rgba(12, 113, 195, 0.15); color: var(--blue); }

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

.history-name { font-weight: 600; font-size: 15px; }

.history-meta {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  gap: 8px;
  align-items: center;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}

.badge.inbound { background: rgba(16, 185, 129, 0.15); color: var(--green); }
.badge.outbound { background: rgba(12, 113, 195, 0.15); color: var(--blue); }

/* ── Filter Tabs ── */

.filter-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  overflow-x: auto;
  scrollbar-width: none;
}

.filter-tab {
  padding: 8px 16px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.filter-tab.active {
  background: var(--blue);
  color: white;
  border-color: var(--blue);
}

/* ── Pagination Pill ── */

.pagination {
  display: flex;
  justify-content: center;
  padding: 24px 0 16px;
}

.pagination-pill {
  display: flex;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 30px;
  padding: 4px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.pagination-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.pagination-btn:active:not(:disabled) { background: var(--bg-input); }
.pagination-btn:disabled { opacity: 0.2; cursor: not-allowed; }
.pagination-btn svg { width: 20px; height: 20px; }

.page-info {
  padding: 0 12px;
  font-size: 12px;
  font-weight: 800;
  color: var(--text-muted);
  letter-spacing: 1px;
  text-transform: uppercase;
  min-width: 90px;
  text-align: center;
}

.page-info span { color: var(--blue); }

/* ── Empty State ── */

.empty-state { text-align: center; padding: 48px 16px; color: var(--text-muted); }
.empty-state svg { width: 48px; height: 48px; margin: 0 auto 16px; opacity: 0.4; }
.empty-state p { font-size: 15px; }

/* ── Calling Overlay ── */

.calling-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 500;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 24px;
}

.calling-overlay.hidden { display: none; }

.calling-pulse {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: var(--green);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(16,185,129,0.4); }
  50% { transform: scale(1.05); box-shadow: 0 0 0 20px rgba(16,185,129,0); }
}

.calling-pulse svg { width: 40px; height: 40px; color: white; }
.calling-text { text-align: center; }
.calling-text .name { font-size: 24px; font-weight: 700; margin-bottom: 4px; }
.calling-text .status { color: var(--text-muted); font-size: 15px; }

.calling-cancel {
  margin-top: 48px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--red);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.calling-cancel svg { width: 24px; height: 24px; color: white; transform: rotate(135deg); }
