@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@300;400;500;600&display=swap');

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

:root {
  --bg-dark:        #111b21;
  --bg-panel:       #202c33;
  --bg-chat:        #0b141a;
  --bg-bubble-in:   #202c33;
  --bg-bubble-out:  #5c4400;
  --accent:         #c46f00;
  --accent-dim:     #796128;
  --text-primary:   #e9edef;
  --text-secondary: #8696a0;
  --text-meta:      #667781;
  --divider:        #2a3942;
  --online:         #00a884;
  --recording:      #ef4444;
  --font:           'DM Sans', sans-serif;
  --radius-bubble:  7.5px;
  --header-h:       60px;
  --input-h:        70px;
  --safe-bottom:    env(safe-area-inset-bottom, 0px);
}



/* ── APP SHELL ──────────────────────────────────── */
/* Mobile: single column, views slide in/out        */
#voieover {
  display: flex;
  height: 100dvh;  /* dynamic viewport for mobile browsers */
  width: 100vw;
  position: relative;
  overflow: hidden;
}

/* ══ SIDEBAR (contacts list — full screen on mobile) */
#sidebar {
  width: 100%;
  min-width: 100%;
  background: var(--bg-panel);
  display: flex;
  flex-direction: column;
  position: absolute;
  inset: 0;
  z-index: 10;
  transform: translateX(0);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

/* When a chat is open, slide sidebar off-screen left */
#sidebar.hidden {
  transform: translateX(-100%);
}

/* ── Sidebar header */
#sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--bg-panel);
  height: var(--header-h);
  flex-shrink: 0;
}

#sidebar-header .header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

#my-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
}

#sidebar-header .header-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-primary);
}

#sidebar-header .header-actions {
  display: flex;
  gap: 4px;
}

/* ── Latency widget */
#net-widget {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  width: 28px;
  padding: 4px 0;
}

#net-bars {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 16px;
}

.net-bar {
  width: 4px;
  border-radius: 1px;
  background: var(--accent);
  display: none;
}
#li-1 { height: 38%; }
#li-2 { height: 65%; }
#li-3 { height: 100%; }

#net-dots {
  display: flex;
  gap: 3px;
}

#wab-out,
#wab-in {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: none;
}
#wab-out { background: var(--text-meta); animation: blink 0.8s infinite; }
#wab-in  { background: var(--accent); }
#wab-in.net-err { background: #ef4444; }

/* ── Icon button (generic) */
.icon-btn {
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: background 0.15s, color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn:active { background: var(--divider); color: var(--text-primary); }

/* ── Search bar */
.search-bar {
  padding: 8px 12px;
  background: var(--bg-panel);
  flex-shrink: 0;
}

.search-input-wrap {
  display: flex;
  align-items: center;
  background: var(--bg-dark);
  border-radius: 10px;
  padding: 8px 14px;
  gap: 10px;
}

.search-input-wrap i { color: var(--text-secondary); font-size: 0.9rem; }

.search-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 0.95rem;
  font-family: var(--font);
}
.search-input::placeholder { color: var(--text-meta); }

/* ── Contact list */
#contact-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.contact-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  gap: 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--divider);
  transition: background 0.12s;
  position: relative;
  user-select: none;
}
.contact-item:active { background: rgba(255,255,255,0.05); }
.contact-item.active { background: var(--bg-dark); }

.contact-delete-btn {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  border: none;
  background: transparent;
  color: var(--text-meta);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}
.contact-item:hover .contact-delete-btn,
.contact-item:focus-within .contact-delete-btn { opacity: 1; }
.contact-delete-btn:active { color: #ef4444; }

.contact-avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--bg-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
  position: relative;
}

.contact-avatar .online-dot {
  position: absolute;
  bottom: 2px;
  right: 2px;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--online);
  border: 2px solid var(--bg-panel);
  display: none;
}
.contact-avatar.is-online .online-dot { display: block; }

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

.contact-name-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 3px;
}

.contact-name {
  font-size: 0.97rem;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-time {
  font-size: 0.72rem;
  color: var(--text-meta);
  white-space: nowrap;
  margin-left: 8px;
  flex-shrink: 0;
}

.contact-last {
  font-size: 0.83rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 5px;
}
.contact-last i { color: var(--text-meta); font-size: 0.78rem; }

.unread-badge {
  background: var(--accent);
  color: #fff;
  border-radius: 10px;
  font-size: 0.7rem;
  min-width: 19px;
  height: 19px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  font-weight: 600;
  flex-shrink: 0;
}

/* ══ CHAT AREA ────────────────────────────────────── */
#chat-area {
  width: 100%;
  min-width: 100%;
  display: flex;
  flex-direction: column;
  background: var(--bg-chat);
  position: absolute;
  inset: 0;
  z-index: 60;
  transform: translateX(100%);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
}

/* When chat is open */
#chat-area.visible {
  transform: translateX(0);
}

/* Subtle chat wallpaper */
#chat-area::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image: radial-gradient(circle, rgba(255,255,255,0.015) 1px, transparent 1px);
  background-size: 24px 24px;
  pointer-events: none;
  z-index: 0;
}

/* ── Chat header */
#chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px 0 4px;
  background: var(--bg-panel);
  height: var(--header-h);
  border-bottom: 1px solid var(--divider);
  z-index: 10;
  position: relative;
  flex-shrink: 0;
}

#chat-header .chat-header-left {
  display: flex;
  align-items: center;
  gap: 4px;
}

#btn-back {
  width: 40px;
  height: 40px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  flex-shrink: 0;
}
#btn-back:active { background: var(--divider); }

#chat-contact-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--accent-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  cursor: pointer;
  flex-shrink: 0;
}

#chat-contact-name {
  font-size: 0.97rem;
  font-weight: 600;
  color: var(--text-primary);
}

#chat-contact-status {
  font-size: 0.72rem;
  color: var(--text-secondary);
  margin-top: 1px;
}

#chat-header-actions {
  display: flex;
  gap: 0;
}

/* ── Message window */
#message-window {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  position: relative;
  z-index: 1;
}

/* ── Date divider */
.date-divider {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 10px 0;
}

.date-divider span {
  background: var(--bg-panel);
  color: var(--text-secondary);
  font-size: 0.72rem;
  padding: 4px 12px;
  border-radius: 6px;
  font-weight: 500;
}

/* ── Message bubbles */
.msg {
  display: flex;
  margin-bottom: 2px;
}
.msg.incoming { justify-content: flex-start; }
.msg.outgoing { justify-content: flex-end; }

.bubble {
  max-width: 78%;
  padding: 7px 10px;
  border-radius: var(--radius-bubble);
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.msg.incoming .bubble {
  background: var(--bg-bubble-in);
  border-top-left-radius: 0;
}
.msg.outgoing .bubble {
  background: var(--bg-bubble-out);
  border-top-right-radius: 0;
}

/* ── Voice bubble */
.voice-bubble {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 185px;
}

.play-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  flex-shrink: 0;
  transition: background 0.15s;
}
.play-btn:active { background: var(--accent-dim); }
.play-btn.playing { background: var(--accent-dim); }

.waveform {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 2px;
  height: 28px;
  cursor: pointer;
}

.waveform-bar {
  width: 3px;
  border-radius: 2px;
  background: rgba(255,255,255,0.28);
  transition: background 0.2s;
  flex-shrink: 0;
}
.waveform-bar.played { background: rgba(255,255,255,0.75); }

.voice-duration {
  font-size: 0.73rem;
  color: var(--text-secondary);
  white-space: nowrap;
  min-width: 30px;
  text-align: right;
}

/* ── Message delete/download button */
.msg-delete-btn {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: rgba(255,255,255,0.3);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  flex-shrink: 0;
  transition: color 0.15s, background 0.15s;
  padding: 0;
}
.msg-delete-btn:active { color: #ef4444; background: rgba(239,68,68,0.12); }

/* ── Bubble footer */
.bubble-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
}

.bubble-time {
  font-size: 0.67rem;
  color: rgba(255,255,255,0.4);
}

.tick-icon          { font-size: 0.7rem; }
.tick-icon.read     { color: #53bdeb; }
.tick-icon.sent     { color: rgba(255,255,255,0.4); }

/* ── Call event bubble */
.call-event-bubble {
  display: flex;
  align-items: center;
  gap: 10px;
}

.call-icon-wrap {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  flex-shrink: 0;
}
.call-icon-wrap.missed   { background: rgba(239,68,68,0.15);  color: #ef4444; }
.call-icon-wrap.received { background: rgba(0,168,132,0.15); color: var(--accent); }

.call-event-label {
  font-size: 0.85rem;
  color: var(--text-primary);
  font-weight: 500;
}
.call-event-sub {
  font-size: 0.72rem;
  color: var(--text-secondary);
  margin-top: 1px;
}

/* ══ INPUT BAR (voice + call only) ───────────────── */
#input-bar {
  padding: 10px 20px calc(10px + var(--safe-bottom));
  background: var(--bg-panel);
  border-top: 1px solid var(--divider);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  z-index: 10;
  position: relative;
  flex-shrink: 0;
  border-radius: 0px 24px 0px 0px;
}

/* Voice call button */
#btn-call {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 1.25rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  box-shadow: 0 2px 12px rgba(0,168,132,0.35);
  flex-shrink: 0;
}
#btn-call:active { background: var(--accent-dim); transform: scale(0.96); }

/* Record button */
#btn-record {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 1.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, box-shadow 0.2s;
  box-shadow: 0 2px 16px rgba(0,168,132,0.4);
  flex-shrink: 0;
}
#btn-record:active { background: var(--accent-dim); }
#btn-record.recording {
  background: var(--recording);
  box-shadow: 0 0 0 8px rgba(239,68,68,0.2);
  animation: pulse-record 1.2s infinite;
}

@keyframes pulse-record {
  0%   { box-shadow: 0 0 0 6px rgba(239,68,68,0.25); }
  50%  { box-shadow: 0 0 0 16px rgba(239,68,68,0.06); }
  100% { box-shadow: 0 0 0 6px rgba(239,68,68,0.25); }
}

/* Recording indicator */
#recording-bar {
  display: none;
  align-items: center;
  gap: 8px;
  background: var(--bg-dark);
  border-radius: 24px;
  padding: 8px 14px;
  flex: 1;
}
#recording-bar.visible { display: flex; }

#recording-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--recording);
  flex-shrink: 0;
  animation: blink 1s infinite;
}
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0.15} }

#recording-timer {
  font-size: 0.88rem;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  min-width: 36px;
}

#recording-waveform {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 2px;
  height: 22px;
  overflow: hidden;
}

.rec-bar {
  width: 3px;
  border-radius: 2px;
  background: var(--recording);
  opacity: 0.65;
  animation: wave-anim 0.6s ease-in-out infinite alternate;
}
@keyframes wave-anim { from { height: 3px; } to { height: 18px; } }

#btn-cancel-record {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--divider);
  color: var(--text-secondary);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
#btn-cancel-record:active { background: rgba(239,68,68,0.2); color: var(--recording); }

/* Video call button */
#btn-video {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: none;
  background: var(--bg-dark);
  color: var(--text-secondary);
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
#btn-video:active { background: var(--divider); color: var(--text-primary); }

/* ══ EMPTY STATE ──────────────────────────────────── */
#empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  position: relative;
  z-index: 1;
  padding: 32px;
}
#empty-state i  { font-size: 3.2rem; color: var(--text-meta); }
#empty-state h2 { font-size: 1.3rem; font-weight: 500; color: var(--text-primary); }
#empty-state p  { font-size: 0.85rem; color: var(--text-meta); text-align: center; max-width: 260px; line-height: 1.5; }

/* ══ ACTIVE CALL OVERLAY ──────────────────────────── */
#call-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(11,20,26,0.94);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 200;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding-bottom: var(--safe-bottom);
}
#call-overlay.visible { display: flex; }

#call-overlay-avatar {
  width: 110px;
  height: 110px;
  border-radius: 50%;
  background: var(--accent-dim);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3rem;
  position: relative;
  margin-bottom: 8px;
}
#call-overlay-avatar::after {
  content: '';
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  border: 2px solid rgba(0,168,132,0.3);
  animation: ring-pulse 1.8s infinite;
}
@keyframes ring-pulse {
  0%   { transform: scale(1);    opacity: 0.8; }
  100% { transform: scale(1.28); opacity: 0;   }
}

#call-overlay-name   { font-size: 1.6rem; font-weight: 600; }
#call-overlay-status { font-size: 0.92rem; color: var(--text-secondary); }
#call-overlay-timer  { font-size: 1.15rem; color: var(--accent); font-variant-numeric: tabular-nums; letter-spacing: 0.03em; }

#call-overlay-actions {
  display: flex;
  gap: 28px;
  margin-top: 28px;
}

.call-action-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  color: #fff;
  transition: transform 0.12s;
  gap: 6px;
}
.call-action-btn:active { transform: scale(0.92); }
.call-action-btn span {
  font-size: 0.65rem;
  color: var(--text-secondary);
  margin-top: 2px;
  font-family: var(--font);
}
#btn-mute     { background: var(--bg-panel); }
#btn-speaker  { background: var(--bg-panel); }
#btn-end-call { background: #ef4444; }

/* ── Scrollbar (webkit) */
::-webkit-scrollbar       { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--divider); border-radius: 2px; }

/* ══ KEYBAR — bottom tab bar ══════════════════════ */
#keybar {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 100vw;
  height: 58px;
  background: var(--bg-panel);
  border-top: 1px solid var(--divider);
  display: flex;
  align-items: stretch;
  z-index: 50;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.keybar-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: var(--text-meta);
  font-size: 0.68rem;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
  border-radius: 0;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.keybar-tab i {
  font-size: 1.2rem;
  transition: transform 0.15s;
}

.keybar-tab:active {
  background: rgba(255,255,255,0.04);
}

.keybar-tab:active i {
  transform: scale(0.9);
}

.keybar-tab.active {
  color: var(--accent);
}

.keybar-tab.active i {
  transform: scale(1.08);
}

/* Push sidebar contact-list up so keybar doesn't overlap last item */
#contact-list {
  padding-bottom: 64px;
}

