/* ═══════════════════════════════════════════════════════════════
   WA INBOX — MASRI.CLOUD
   Dark-first, WhatsApp-inspired, production-grade
═══════════════════════════════════════════════════════════════ */

/* ── DESIGN TOKENS ── */
:root {
  --bg-base:        #0d1117;
  --bg-sidebar:     #111820;
  --bg-chat:        #0d1117;
  --bg-bubble-out:  #005c4b;
  --bg-bubble-in:   #1e2a35;
  --bg-header:      #161f2a;
  --bg-input:       #1e2a35;
  --bg-hover:       #1a2535;
  --bg-active:      #1e2f40;
  --bg-card:        #161f2a;
  --bg-overlay:     rgba(0,0,0,0.6);

  --accent:         #00a884;
  --accent-dim:     #007a60;
  --accent-glow:    rgba(0,168,132,0.15);
  --accent-soft:    rgba(0,168,132,0.08);

  --text-primary:   #e9edef;
  --text-secondary: #8696a0;
  --text-muted:     #556570;
  --text-bubble-out: #e9edef;

  --border:         rgba(255,255,255,0.06);
  --border-input:   rgba(255,255,255,0.1);

  --unread-bg:      #00a884;
  --unread-text:    #fff;

  --status-sent:    #8696a0;
  --status-read:    #53bdeb;

  --radius-bubble:  10px;
  --radius-md:      12px;
  --radius-lg:      16px;
  --radius-xl:      20px;
  --radius-full:    9999px;

  --font-body:      'Plus Jakarta Sans', sans-serif;
  --font-mono:      'Geist Mono', monospace;

  --shadow-sm:      0 1px 4px rgba(0,0,0,0.3);
  --shadow-md:      0 4px 20px rgba(0,0,0,0.4);
  --shadow-lg:      0 12px 40px rgba(0,0,0,0.6);

  --trans-fast:     120ms ease;
  --trans-med:      220ms ease;
  --trans-slow:     350ms ease;

  --sidebar-w:      340px;
  --header-h:       60px;
  --input-h:        64px;
}

/* ── RESET & BASE ── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html { font-size: 16px; }

body {
  font-family: var(--font-body);
  background: var(--bg-base);
  color: var(--text-primary);
  height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ════════════════════════════════════
   LOGIN SCREEN
════════════════════════════════════ */
.login-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-base);
  z-index: 100;
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 40px 32px;
  text-align: center;
  box-shadow: var(--shadow-lg), 0 0 60px rgba(0,168,132,0.08);
  animation: fadeUp 0.4s ease;
}

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

.login-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
}

.logo-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dim));
  border-radius: var(--radius-md);
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 15px;
  color: #fff;
  letter-spacing: 0.05em;
  box-shadow: 0 4px 16px rgba(0,168,132,0.35);
}

.logo-mark.small {
  width: 32px;
  height: 32px;
  font-size: 11px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,168,132,0.3);
  flex-shrink: 0;
}

.login-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.login-sub {
  font-size: 12.5px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  margin-bottom: 32px;
}

.input-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  margin-bottom: 8px;
  text-align: left;
}

.login-input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 13px;
  outline: none;
  transition: border-color var(--trans-fast), box-shadow var(--trans-fast);
  margin-bottom: 16px;
}

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

.login-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  padding: 13px 20px;
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--trans-fast), transform var(--trans-fast), box-shadow var(--trans-fast);
}

.login-btn:hover {
  background: var(--accent-dim);
  box-shadow: 0 4px 20px rgba(0,168,132,0.3);
}

.login-btn:active { transform: scale(0.98); }

.login-error {
  margin-top: 10px;
  color: #f44336;
  font-size: 13px;
}

/* ════════════════════════════════════
   APP LAYOUT
════════════════════════════════════ */
.app {
  display: flex;
  height: 100dvh;
  overflow: hidden;
}

/* ════════════════════════════════════
   SIDEBAR
════════════════════════════════════ */
.sidebar {
  width: 100%;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  flex-shrink: 0;
  transition: transform var(--trans-med);
  z-index: 10;
}

.sidebar-header {
  height: var(--header-h);
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

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

.brand-text {
  display: flex;
  flex-direction: column;
}

.brand-name {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.2;
}

.brand-domain {
  font-size: 10.5px;
  font-family: var(--font-mono);
  color: var(--accent);
  line-height: 1;
  opacity: 0.8;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-badge {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  background: var(--bg-active);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  border: 1px solid var(--border);
  cursor: default;
  font-family: var(--font-mono);
  overflow: hidden;
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: color var(--trans-fast), background var(--trans-fast);
}

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

/* Search */
.search-wrap {
  position: relative;
  padding: 10px 12px;
  flex-shrink: 0;
  background: var(--bg-sidebar);
}

.search-icon {
  position: absolute;
  left: 24px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.search-input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 9px 16px 9px 38px;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 13.5px;
  outline: none;
  transition: border-color var(--trans-fast);
}

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

/* Status */
.conv-status {
  padding: 6px 16px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  flex-shrink: 0;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: var(--radius-full);
  background: var(--text-muted);
  flex-shrink: 0;
  transition: background var(--trans-med);
}

.status-dot.live {
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent);
  animation: pulse 2s infinite;
}

.status-dot.error { background: #f44336; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.5; }
}

/* Conversation List */
.conv-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
}

.conv-list::-webkit-scrollbar { width: 3px; }
.conv-list::-webkit-scrollbar-track { background: transparent; }
.conv-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }

/* Skeleton */
.conv-skeleton-list { padding: 8px 0; }

.conv-skeleton {
  height: 68px;
  margin: 2px 8px;
  border-radius: var(--radius-md);
  background: linear-gradient(90deg, var(--bg-hover) 25%, var(--bg-active) 50%, var(--bg-hover) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}

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

/* Conv Item */
.conv-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  margin: 1px 4px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--trans-fast);
  position: relative;
  user-select: none;
}

.conv-item:hover    { background: var(--bg-hover); }
.conv-item.active   { background: var(--bg-active); }
.conv-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 25%;
  bottom: 25%;
  width: 3px;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
}

.conv-avatar {
  width: 46px;
  height: 46px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--bg-active), var(--bg-hover));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
  flex-shrink: 0;
  border: 1.5px solid var(--border);
  text-transform: uppercase;
}

.conv-body { flex: 1; min-width: 0; }

.conv-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 3px;
}

.conv-name {
  font-size: 14.5px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
}

.conv-time {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  flex-shrink: 0;
}

.conv-item.has-unread .conv-time { color: var(--accent); }

.conv-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.conv-last {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.unread-badge {
  min-width: 20px;
  height: 20px;
  background: var(--unread-bg);
  color: var(--unread-text);
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  flex-shrink: 0;
}

/* Divider */
.conv-divider {
  padding: 6px 16px 2px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

/* Empty Search */
.conv-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 13.5px;
}

/* ════════════════════════════════════
   CHAT PANEL
════════════════════════════════════ */
.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-chat);
  position: relative;
  overflow: hidden;
}

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

/* Empty State */
.empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 1;
  animation: fadeIn 0.3s ease;
}

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

.empty-icon {
  width: 80px;
  height: 80px;
  border-radius: var(--radius-full);
  background: var(--accent-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  margin-bottom: 20px;
  border: 1px solid rgba(0,168,132,0.15);
}

.empty-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.empty-sub {
  font-size: 13.5px;
  color: var(--text-secondary);
  text-align: center;
  max-width: 260px;
  line-height: 1.5;
}

/* Chat View */
.chat-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
  z-index: 1;
}

/* Chat Header */
.chat-header {
  height: var(--header-h);
  background: var(--bg-header);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 10px;
  flex-shrink: 0;
}

.back-btn { display: none; }

.chat-avatar-wrap {
  position: relative;
  flex-shrink: 0;
}

.chat-avatar {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--bg-active), var(--accent-dim));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  text-transform: uppercase;
  border: 1.5px solid var(--border);
}

.online-dot {
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 9px;
  height: 9px;
  background: var(--accent);
  border-radius: var(--radius-full);
  border: 1.5px solid var(--bg-header);
}

.chat-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

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

.chat-phone {
  font-size: 11.5px;
  color: var(--text-secondary);
  font-family: var(--font-mono);
}

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

/* Messages Area */
.messages-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 12px 8px;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
}

.messages-area::-webkit-scrollbar { width: 3px; }
.messages-area::-webkit-scrollbar-track { background: transparent; }
.messages-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }

.messages-container {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-height: 100%;
  justify-content: flex-end;
}

/* Date Separator */
.date-separator {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 12px 0;
}

.date-chip {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  padding: 4px 14px;
  font-size: 11.5px;
  color: var(--text-secondary);
  font-family: var(--font-mono);
}

/* Message Bubbles */
.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  max-width: 80%;
  animation: msgIn 0.2s ease;
}

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

.msg-row.incoming {
  align-self: flex-start;
  margin-right: auto;
}

.msg-row.outgoing {
  align-self: flex-end;
  margin-left: auto;
  flex-direction: row-reverse;
}

.bubble {
  padding: 8px 12px 6px;
  border-radius: var(--radius-bubble);
  max-width: 100%;
  position: relative;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.msg-row.incoming .bubble {
  background: var(--bg-bubble-in);
  border-bottom-left-radius: 2px;
}

.msg-row.outgoing .bubble {
  background: var(--bg-bubble-out);
  border-bottom-right-radius: 2px;
}

.bubble-text {
  font-size: 14.5px;
  line-height: 1.5;
  color: var(--text-primary);
  white-space: pre-wrap;
}

.bubble-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 3px;
}

.bubble-time {
  font-size: 10.5px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.msg-row.outgoing .bubble-time { color: rgba(255,255,255,0.55); }

/* Status ticks */
.tick-icon {
  flex-shrink: 0;
  opacity: 0.8;
}

.tick-icon.read   { color: var(--status-read); opacity: 1; }
.tick-icon.sent   { color: var(--status-sent); }

/* Image message */
.bubble-image {
  max-width: 220px;
  max-height: 220px;
  border-radius: 8px;
  display: block;
  cursor: pointer;
  transition: opacity var(--trans-fast);
}
.bubble-image:hover { opacity: 0.9; }

/* Document message */
.bubble-doc {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255,255,255,0.05);
  border-radius: 8px;
  padding: 10px 12px;
  text-decoration: none;
  color: var(--text-primary);
  transition: background var(--trans-fast);
}
.bubble-doc:hover { background: rgba(255,255,255,0.1); }

.doc-icon {
  width: 36px;
  height: 36px;
  background: var(--accent-soft);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  flex-shrink: 0;
}

.doc-info { min-width: 0; }
.doc-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-sub  { font-size: 11px; color: var(--text-muted); margin-top: 1px; }

/* Typing / Loading */
.msg-loading {
  display: flex;
  justify-content: flex-start;
  padding: 4px 0;
}

.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-bubble-in);
  border-radius: var(--radius-bubble);
  border-bottom-left-radius: 2px;
  padding: 10px 14px;
}

.typing-indicator span {
  width: 7px;
  height: 7px;
  background: var(--text-secondary);
  border-radius: var(--radius-full);
  animation: bounce 1.2s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.15s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.30s; }

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40%           { transform: translateY(-5px); }
}

/* ── INPUT BAR ── */
.input-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 12px 12px;
  background: var(--bg-header);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.input-wrap {
  flex: 1;
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: 22px;
  display: flex;
  align-items: center;
  padding: 0 16px;
  transition: border-color var(--trans-fast), box-shadow var(--trans-fast);
}

.input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.msg-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font-body);
  font-size: 15px;
  padding: 11px 0;
  resize: none;
  max-height: 120px;
  overflow-y: auto;
  line-height: 1.5;
}

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

.msg-input::-webkit-scrollbar { width: 2px; }
.msg-input::-webkit-scrollbar-thumb { background: var(--border); }

.send-btn {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: var(--radius-full);
  background: var(--accent);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--trans-fast), transform var(--trans-fast), box-shadow var(--trans-fast);
  box-shadow: 0 2px 10px rgba(0,168,132,0.3);
}

.send-btn:hover {
  background: var(--accent-dim);
  box-shadow: 0 4px 16px rgba(0,168,132,0.4);
}

.send-btn:active { transform: scale(0.93); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

/* ════════════════════════════════════
   TOAST
════════════════════════════════════ */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 10px 20px;
  border-radius: var(--radius-full);
  font-size: 13.5px;
  font-weight: 500;
  z-index: 9999;
  box-shadow: var(--shadow-md);
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  white-space: nowrap;
}

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

.toast.success { border-color: var(--accent); color: var(--accent); }
.toast.error   { border-color: #f44336; color: #f44336; }

/* ════════════════════════════════════
   DESKTOP (≥768px) — SPLIT LAYOUT
════════════════════════════════════ */
@media (min-width: 768px) {
  .sidebar {
    width: var(--sidebar-w);
    min-width: 280px;
    max-width: 380px;
  }

  .chat-panel {
    flex: 1;
  }

  .chat-panel.mobile-hidden {
    display: flex !important;
  }

  .back-btn { display: none !important; }

  .msg-row { max-width: 68%; }
}

/* ════════════════════════════════════
   MOBILE (<768px)
════════════════════════════════════ */
@media (max-width: 767px) {
  .app {
    position: relative;
    overflow: hidden;
  }

  .sidebar {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    transform: translateX(0);
    transition: transform var(--trans-med);
    z-index: 20;
  }

  .sidebar.mobile-hidden {
    transform: translateX(-100%);
  }

  .chat-panel {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    transform: translateX(100%);
    transition: transform var(--trans-med);
    z-index: 21;
    display: flex !important;
  }

  .chat-panel.mobile-visible {
    transform: translateX(0);
  }

  .back-btn {
    display: flex !important;
  }

  .msg-row { max-width: 85%; }

  .empty-state {
    display: none !important;
  }
}

/* ════════════════════════════════════
   UTILITIES
════════════════════════════════════ */
.fade-in {
  animation: fadeIn 0.25s ease;
}

/* Scrollbar for messages */
.messages-area::-webkit-scrollbar { width: 4px; }

/* Hover effect for message links */
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
