/* ============================================================
   WhatsApp Dark Mode Clone — style.css
   ============================================================ */

:root {
  --bg-primary:      #111b21;
  --bg-secondary:    #1f2c34;
  --bg-hover:        #2a3942;
  --bg-input:        #2a3942;
  --bg-message-in:   #1f2c34;
  --bg-message-out:  #005c4b;
  --bg-chat-bg:      #0d1418;
  --accent:          #25d366;
  --accent-dark:     #128c7e;
  --text-primary:    #e9edef;
  --text-secondary:  #8696a0;
  --text-muted:      #667781;
  --border:          #2a3942;
  --unread-badge:    #25d366;
  --panel-w:         380px;
  --header-h:        59px;
  --radius:          8px;
  --radius-msg:      7.5px;
  --transition:      .18s ease;
  --safe-top:        env(safe-area-inset-top, 0px);
  --safe-bottom:     env(safe-area-inset-bottom, 0px);
}

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

html { height: 100%; font-size: 15px; }

body {
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  height: 100%;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ── Utility ── */
.hidden         { display: none !important; }
.hidden-mobile  { display: flex; }
.clickable      { cursor: pointer; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #374248; border-radius: 3px; }

/* ─────────────────────────────────────────────────────────────
   AUTH SCREEN
───────────────────────────────────────────────────────────── */
.screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-primary);
  padding: calc(var(--safe-top) + 20px) 20px calc(var(--safe-bottom) + 20px);
  overflow-y: auto;
  z-index: 100;
}

.auth-wrap {
  width: 100%; max-width: 360px;
  display: flex; flex-direction: column; align-items: center; gap: 16px;
  animation: fadeUp .35s ease;
}

.auth-logo svg { width: 72px; height: 72px; }

.auth-wrap h1 {
  font-size: 28px; font-weight: 300; letter-spacing: -.5px;
  color: var(--text-primary);
}

.auth-tagline { color: var(--text-secondary); font-size: 13px; }

.auth-tabs {
  display: flex; width: 100%;
  border-bottom: 1px solid var(--border);
}
.auth-tab {
  flex: 1; padding: 10px; background: none; border: none;
  color: var(--text-secondary); font-size: 14px; font-weight: 500;
  cursor: pointer; transition: color var(--transition);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.auth-tab.active { color: var(--accent); border-color: var(--accent); }

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

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; color: var(--text-secondary); }
.field input, .field textarea, textarea {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  padding: 11px 14px;
  font-size: 15px;
  outline: none;
  transition: border-color var(--transition);
  font-family: inherit;
}
.field input:focus, .field textarea:focus, textarea:focus {
  border-color: var(--accent);
}
.field input::placeholder, textarea::placeholder {
  color: var(--text-muted);
}

.form-error { color: #f15c6d; font-size: 13px; min-height: 18px; }

.btn-primary {
  background: var(--accent);
  color: #111b21;
  border: none;
  border-radius: 24px;
  padding: 12px 24px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), transform .1s;
}
.btn-primary:hover  { background: #22c15e; }
.btn-primary:active { transform: scale(.97); }
.btn-full           { width: 100%; }

/* ─────────────────────────────────────────────────────────────
   APP LAYOUT
───────────────────────────────────────────────────────────── */
#app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ─────────────────────────────────────────────────────────────
   PANEL (sidebar / chat list)
───────────────────────────────────────────────────────────── */
.panel {
  width: var(--panel-w);
  min-width: var(--panel-w);
  display: flex; flex-direction: column;
  background: var(--bg-primary);
  border-right: 1px solid var(--border);
  position: relative;
  height: 100%;
}

.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px;
  height: var(--header-h);
  background: var(--bg-secondary);
  padding-top: calc(10px + var(--safe-top));
  flex-shrink: 0;
}
.header-left { display: flex; align-items: center; gap: 12px; }
.panel-title  { font-size: 20px; font-weight: 600; color: var(--text-primary); }
.header-actions { display: flex; gap: 6px; }

.icon-btn {
  background: none; border: none;
  color: var(--text-secondary);
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  flex-shrink: 0;
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

/* Search */
.search-bar {
  padding: 8px 12px;
  background: var(--bg-primary);
  flex-shrink: 0;
}
.search-inner {
  background: var(--bg-secondary);
  border-radius: 8px;
  display: flex; align-items: center;
  padding: 0 12px;
  gap: 10px;
}
.search-icon { width: 16px; height: 16px; color: var(--text-muted); flex-shrink: 0; }
.search-inner input {
  flex: 1; background: none; border: none;
  color: var(--text-primary); font-size: 14px;
  padding: 8px 0; outline: none;
}
.search-inner input::placeholder { color: var(--text-muted); }

/* Filters */
.filters-row {
  display: flex; gap: 8px;
  padding: 6px 12px 10px;
  overflow-x: auto; flex-shrink: 0;
  scrollbar-width: none;
}
.filters-row::-webkit-scrollbar { display: none; }

.filter-chip {
  white-space: nowrap;
  background: var(--bg-secondary);
  color: var(--text-secondary);
  border: none; border-radius: 14px;
  padding: 5px 14px; font-size: 13px; font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.filter-chip.active, .filter-chip:hover {
  background: #1d4b3e; color: var(--accent);
}

/* Chat list */
.chat-list {
  flex: 1; overflow-y: auto;
}

.loading-state {
  display: flex; justify-content: center; padding: 32px;
}
.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

.chat-item {
  display: flex; align-items: center;
  padding: 12px 16px; gap: 12px;
  cursor: pointer;
  transition: background var(--transition);
  border-bottom: 1px solid var(--border);
  position: relative;
}
.chat-item:hover { background: var(--bg-hover); }
.chat-item.active { background: var(--bg-hover); }

.chat-item-content {
  flex: 1; min-width: 0;
}
.chat-item-top {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 3px;
}
.chat-item-name {
  font-size: 16px; font-weight: 400;
  color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-item-time {
  font-size: 12px; color: var(--text-muted); flex-shrink: 0; margin-left: 8px;
}
.chat-item-time.unread { color: var(--accent); }

.chat-item-bottom {
  display: flex; align-items: center; justify-content: space-between;
}
.chat-item-preview {
  font-size: 13.5px; color: var(--text-secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  flex: 1;
}
.unread-badge {
  background: var(--accent); color: #111b21;
  border-radius: 12px; font-size: 11.5px; font-weight: 600;
  min-width: 20px; height: 20px; padding: 0 6px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; margin-left: 8px;
}

/* Avatar */
.avatar {
  border-radius: 50%;
  background: var(--bg-hover);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-secondary);
  font-size: 16px; font-weight: 600;
  flex-shrink: 0;
  overflow: hidden;
  user-select: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-xs { width: 28px; height: 28px; font-size: 11px; }
.avatar-sm { width: 38px; height: 38px; font-size: 14px; }
.avatar-md { width: 46px; height: 46px; font-size: 17px; }
.avatar-lg { width: 60px; height: 60px; font-size: 22px; }
.avatar-xl { width: 80px; height: 80px; font-size: 30px; }

/* Bottom nav */
.bottom-nav {
  display: flex;
  background: var(--bg-secondary);
  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: 2px; padding: 10px 4px 8px;
  background: none; border: none; cursor: pointer;
  color: var(--text-muted);
  transition: color var(--transition);
  font-size: 10px;
}
.nav-item svg { width: 22px; height: 22px; }
.nav-item.active { color: var(--accent); }
.nav-item:hover  { color: var(--text-primary); }

/* ─────────────────────────────────────────────────────────────
   CHAT VIEW
───────────────────────────────────────────────────────────── */
.chat-view {
  flex: 1; display: flex; flex-direction: column;
  position: relative; overflow: hidden;
  background: var(--bg-chat-bg);
  background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23182229' fill-opacity='0.6'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}

.chat-placeholder {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px;
  color: var(--text-secondary);
}
.chat-placeholder h3 { font-size: 18px; font-weight: 300; color: var(--text-primary); }
.chat-placeholder p  { font-size: 14px; }

#active-chat {
  display: flex; flex-direction: column; height: 100%;
}

.chat-header {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  height: var(--header-h);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding-top: calc(8px + var(--safe-top));
  flex-shrink: 0;
}
.chat-header-avatar { flex-shrink: 0; }
.chat-header-info   { flex: 1; min-width: 0; }
.chat-header-name   { font-size: 16px; font-weight: 500; color: var(--text-primary); }
.chat-header-status { font-size: 12px; color: var(--text-secondary); }
.chat-header-actions { display: flex; gap: 4px; }
.back-btn { display: none; }

/* Messages */
.messages-container {
  flex: 1; overflow-y: auto; padding: 12px 8px;
}
.messages-list { display: flex; flex-direction: column; gap: 2px; }

.msg-bubble {
  max-width: min(68%, 480px);
  padding: 6px 9px 4px;
  border-radius: var(--radius-msg);
  font-size: 14.5px; line-height: 1.5;
  position: relative;
  word-break: break-word;
  animation: fadeUp .12s ease;
}
.msg-bubble.in {
  background: var(--bg-message-in);
  color: var(--text-primary);
  align-self: flex-start;
  border-top-left-radius: 0;
  margin-left: 4px;
}
.msg-bubble.out {
  background: var(--bg-message-out);
  color: var(--text-primary);
  align-self: flex-end;
  border-top-right-radius: 0;
  margin-right: 4px;
}
.msg-meta {
  display: flex; align-items: center; justify-content: flex-end;
  gap: 4px; margin-top: 2px;
}
.msg-time { font-size: 11px; color: rgba(134,150,160,.85); }
.msg-ticks { font-size: 13px; color: #53bdeb; }

.msg-date-divider {
  text-align: center; color: var(--text-muted);
  font-size: 12px; padding: 8px 0;
}
.msg-date-label {
  background: var(--bg-secondary);
  padding: 4px 12px; border-radius: 8px; display: inline-block;
}

/* Input */
.message-input-bar {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 8px calc(8px + var(--safe-bottom));
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.input-grow {
  flex: 1; background: var(--bg-input);
  border-radius: 22px;
  display: flex; align-items: flex-end;
  padding: 4px 4px 4px 8px;
  min-height: 44px;
}
.input-grow textarea {
  flex: 1; background: none; border: none;
  color: var(--text-primary); font-size: 15px;
  resize: none; outline: none; max-height: 120px;
  padding: 8px 8px 8px 4px;
  font-family: inherit; line-height: 1.5;
}
.send-btn {
  width: 44px; height: 44px;
  background: var(--accent);
  color: #111b21;
  border-radius: 50%;
  flex-shrink: 0;
}
.send-btn:hover { background: #22c15e; }
.send-btn svg { width: 22px; height: 22px; }

/* ─────────────────────────────────────────────────────────────
   STATUS PANEL
───────────────────────────────────────────────────────────── */
.status-panel, .settings-panel {
  position: absolute; inset: 0;
  background: var(--bg-primary);
  display: flex; flex-direction: column; z-index: 10;
}

.status-panel .panel-header,
.settings-panel .panel-header {
  padding: 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding-top: calc(16px + var(--safe-top));
}
.status-panel .panel-header h2,
.settings-panel .panel-header h2 {
  font-size: 20px; font-weight: 600;
}

.status-my {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.status-my:hover { background: var(--bg-hover); }

.status-avatar-ring { position: relative; }
.status-add-btn {
  position: absolute; bottom: 0; right: -2px;
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--accent); color: #111b21;
  border: 2px solid var(--bg-primary);
  font-size: 16px; line-height: 1; font-weight: 700;
  cursor: pointer;
}
.status-name { font-size: 16px; font-weight: 500; }
.status-hint { font-size: 13px; color: var(--text-secondary); }

.status-section-label {
  padding: 10px 16px 6px;
  font-size: 12px; font-weight: 600;
  color: var(--text-secondary); text-transform: uppercase; letter-spacing: .6px;
}

.status-list { overflow-y: auto; }
.status-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.status-item:hover { background: var(--bg-hover); }
.status-ring {
  border-radius: 50%;
  border: 2px solid var(--accent);
  padding: 2px;
}
.status-channels-empty {
  padding: 16px; font-size: 14px; color: var(--text-muted);
}

/* ─────────────────────────────────────────────────────────────
   MODAL
───────────────────────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; padding: 20px;
}
.modal-box {
  background: var(--bg-secondary);
  border-radius: 12px;
  width: 100%; max-width: 420px;
  max-height: 80vh;
  display: flex; flex-direction: column;
  animation: fadeUp .2s ease;
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 17px; font-weight: 500; }
.modal-search { padding: 12px 16px; border-bottom: 1px solid var(--border); }
.modal-search input {
  width: 100%; background: var(--bg-input);
  border: 1px solid var(--border); border-radius: 8px;
  color: var(--text-primary); padding: 9px 12px;
  font-size: 14px; outline: none;
}
.modal-box .field { padding: 16px; }
.modal-box .btn-full { margin: 0 16px 16px; width: calc(100% - 32px); }

.contacts-list { overflow-y: auto; flex: 1; }
.contact-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.contact-item:hover { background: var(--bg-hover); }
.contact-name  { font-size: 15px; font-weight: 500; }
.contact-phone { font-size: 12.5px; color: var(--text-secondary); }

/* ─────────────────────────────────────────────────────────────
   SETTINGS
───────────────────────────────────────────────────────────── */
.settings-profile {
  display: flex; align-items: center; gap: 16px;
  padding: 20px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.settings-profile:hover { background: var(--bg-hover); }
.settings-name  { font-size: 18px; font-weight: 500; }
.settings-phone { font-size: 13px; color: var(--text-secondary); }
.settings-list  { overflow-y: auto; }
.settings-item  {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  cursor: pointer; font-size: 15px;
}
.settings-item:hover { background: var(--bg-hover); }
.settings-item.danger { color: #f15c6d; }

/* ─────────────────────────────────────────────────────────────
   DROPDOWN MENU
───────────────────────────────────────────────────────────── */
.dropdown-menu {
  position: fixed; top: var(--header-h); right: 8px;
  background: var(--bg-secondary);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
  z-index: 300; overflow: hidden; min-width: 180px;
  animation: fadeUp .15s ease;
}
.menu-item {
  padding: 13px 20px; font-size: 15px;
  cursor: pointer; transition: background var(--transition);
}
.menu-item:hover { background: var(--bg-hover); }

/* ─────────────────────────────────────────────────────────────
   EMPTY STATES
───────────────────────────────────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  gap: 12px; padding: 40px 20px; color: var(--text-muted);
  text-align: center;
}
.empty-state svg { opacity: .4; }

/* ─────────────────────────────────────────────────────────────
   ANIMATIONS
───────────────────────────────────────────────────────────── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ─────────────────────────────────────────────────────────────
   RESPONSIVE — Mobile first (< 700px)
───────────────────────────────────────────────────────────── */
@media (max-width: 700px) {
  .panel {
    width: 100%; min-width: 0;
    position: fixed; inset: 0; z-index: 20;
  }
  .chat-view {
    position: fixed; inset: 0; z-index: 30;
    transform: translateX(100%);
    transition: transform .25s cubic-bezier(.4,0,.2,1);
  }
  .chat-view.mobile-open {
    transform: translateX(0);
  }
  .hidden-mobile { display: none; }
  .back-btn      { display: flex !important; }
  .status-panel, .settings-panel { z-index: 25; }
}
