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

:root {
  --bg-app:        #111b21;
  --bg-sidebar:    #111b21;
  --bg-panel:      #0b141a;
  --bg-message-in: #202c33;
  --bg-message-out:#005c4b;
  --bg-input:      #2a3942;
  --bg-hover:      #2a3942;
  --bg-active:     #2a3942;
  --bg-header:     #202c33;

  --text-primary:  #e9edef;
  --text-secondary:#8696a0;
  --text-meta:     #667781;

  --accent:        #00a884;
  --accent-hover:  #02b891;
  --danger:        #f15c6d;
  --warn:          #ffd60a;

  --border:        rgba(134,150,160,.15);
  --radius-sm:     6px;
  --radius-md:     12px;
  --radius-lg:     18px;

  --font:          'Inter', system-ui, sans-serif;
  --sidebar-w:     380px;
  --header-h:      60px;
}

html, body { height: 100%; font-family: var(--font); background: var(--bg-app); color: var(--text-primary); }

/* ── Login Page ──────────────────────────────────────────────────────────── */
.login-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
  background: radial-gradient(ellipse at 60% 40%, #1a2f38 0%, #0b141a 70%);
}

.login-card {
  width: 100%; max-width: 400px;
  background: var(--bg-sidebar);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 48px 40px;
  box-shadow: 0 24px 80px rgba(0,0,0,.5);
  animation: fadeUp .4s ease;
}

.login-logo {
  text-align: center;
  margin-bottom: 36px;
}
.logo-icon { font-size: 3rem; margin-bottom: 12px; }
.login-logo h1 { font-size: 1.4rem; font-weight: 700; margin-bottom: 6px; }
.login-logo p  { font-size: .875rem; color: var(--text-secondary); }

.form-group { margin-bottom: 18px; }
.form-group label { display: block; font-size: .8rem; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; letter-spacing: .04em; text-transform: uppercase; }
.form-group input {
  width: 100%; padding: 12px 14px;
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-primary);
  font-family: var(--font); font-size: .95rem;
  transition: border-color .2s;
  outline: none;
}
.form-group input:focus { border-color: var(--accent); }

.btn-primary {
  width: 100%; padding: 13px; margin-top: 8px;
  background: var(--accent); color: #fff;
  border: none; border-radius: var(--radius-sm);
  font-family: var(--font); font-size: 1rem; font-weight: 600;
  cursor: pointer; transition: background .2s, transform .1s;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.btn-primary:hover  { background: var(--accent-hover); }
.btn-primary:active { transform: scale(.98); }

.error-msg { color: var(--danger); font-size: .875rem; margin-bottom: 10px; padding: 10px 12px; background: rgba(241,92,109,.1); border-radius: var(--radius-sm); }
.hidden    { display: none !important; }

.spinner {
  width: 18px; height: 18px; border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff; border-radius: 50%;
  animation: spin .7s linear infinite;
}

/* ── Chat Page Layout ────────────────────────────────────────────────────── */
.chat-page { display: flex; height: 100vh; overflow: hidden; }

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  height: 100vh;
}

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

.agent-info { display: flex; align-items: center; gap: 10px; }
.agent-avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .95rem;
}

.header-actions { display: flex; gap: 6px; }
.icon-btn {
  background: none; border: none; color: var(--text-secondary);
  width: 36px; height: 36px; border-radius: 50%;
  cursor: pointer; font-size: 1.1rem;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.search-wrap { padding: 8px 12px; }
.search-input {
  width: 100%; padding: 9px 14px;
  background: var(--bg-input); border: none;
  border-radius: 20px; color: var(--text-primary);
  font-family: var(--font); font-size: .9rem; outline: none;
}

.filter-tabs {
  display: flex; gap: 4px; padding: 4px 12px 8px;
}
.tab {
  flex: 1; padding: 6px; background: none; border: none;
  border-radius: 20px; color: var(--text-secondary);
  font-family: var(--font); font-size: .8rem; cursor: pointer;
  transition: background .15s, color .15s;
}
.tab.active { background: var(--accent); color: #fff; font-weight: 600; }
.tab:hover:not(.active) { background: var(--bg-hover); color: var(--text-primary); }

.conversation-list {
  flex: 1; overflow-y: auto; list-style: none;
}
.conversation-list::-webkit-scrollbar { width: 4px; }
.conversation-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

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

.conv-avatar {
  width: 48px; height: 48px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 1.1rem; flex-shrink: 0;
  color: #fff;
}

.conv-body { flex: 1; min-width: 0; }
.conv-top  { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 3px; }
.conv-name { font-weight: 600; font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: .72rem; color: var(--text-meta); white-space: nowrap; }
.conv-bottom { display: flex; justify-content: space-between; align-items: center; }
.conv-last { font-size: .8rem; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
.conv-badge {
  background: var(--accent); color: #fff;
  border-radius: 10px; font-size: .7rem; font-weight: 700;
  padding: 1px 6px; min-width: 18px; text-align: center;
}
.conv-mode-dot {
  width: 7px; height: 7px; border-radius: 50%;
  margin-left: 4px; flex-shrink: 0;
}
.conv-mode-dot.ai_auto { background: var(--warn); }
.conv-mode-dot.human   { background: var(--accent); }

.conv-placeholder { padding: 24px; text-align: center; color: var(--text-secondary); font-size: .9rem; }

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

.empty-state {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  color: var(--text-secondary); gap: 12px;
}
.empty-icon { font-size: 4rem; opacity: .3; }
.empty-state h2 { font-size: 1.2rem; color: var(--text-primary); }
.empty-state p  { font-size: .9rem; }

/* Chat header */
.chat-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; height: var(--header-h);
  background: var(--bg-header); border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.chat-contact { display: flex; align-items: center; gap: 12px; }
.contact-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 1rem; color: #fff;
}
.contact-name  { font-weight: 600; font-size: .95rem; }
.contact-phone { font-size: .78rem; color: var(--text-secondary); }

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

/* Mode toggle */
.mode-toggle {
  display: flex; align-items: center; gap: 8px;
  cursor: pointer; padding: 6px 10px;
  border-radius: 20px; border: 1px solid var(--border);
  transition: border-color .2s;
  user-select: none;
}
.mode-toggle:hover    { border-color: var(--accent); }
.mode-label           { font-size: .78rem; font-weight: 600; color: var(--text-secondary); min-width: 52px; }
.toggle-pill {
  width: 36px; height: 20px; border-radius: 10px;
  background: var(--bg-input); position: relative; transition: background .3s;
}
.toggle-pill::after {
  content: ''; position: absolute;
  width: 14px; height: 14px; border-radius: 50%;
  background: #fff; top: 3px; left: 3px;
  transition: transform .3s;
}
.toggle-pill.active              { background: var(--warn); }
.toggle-pill.active::after       { transform: translateX(16px); }

/* Assign */
.assign-select {
  background: var(--bg-input); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-primary);
  font-family: var(--font); font-size: .82rem; padding: 6px 10px;
  outline: none; cursor: pointer;
}
.assign-select:focus { border-color: var(--accent); }

/* Messages */
.messages-area {
  flex: 1; overflow-y: auto; padding: 16px;
  display: flex; flex-direction: column; gap: 4px;
}
.messages-area::-webkit-scrollbar { width: 5px; }
.messages-area::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.messages-list { display: flex; flex-direction: column; gap: 4px; }

.msg {
  max-width: 65%; padding: 8px 12px;
  border-radius: var(--radius-lg); font-size: .9rem; line-height: 1.5;
  position: relative; word-break: break-word;
  animation: msgIn .2s ease;
}
.msg.inbound   { background: var(--bg-message-in); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.outbound  { background: var(--bg-message-out); align-self: flex-end;  border-bottom-right-radius: 4px; }
.msg-meta      { font-size: .68rem; color: rgba(255,255,255,.45); margin-top: 4px; text-align: right; display: flex; gap: 6px; justify-content: flex-end; align-items: center; }
.msg-sender    { font-size: .72rem; color: var(--accent); font-weight: 600; margin-bottom: 2px; }
.msg-ai-badge  { font-size: .65rem; background: rgba(255,214,10,.2); color: var(--warn); padding: 1px 5px; border-radius: 4px; }

.date-divider  { text-align: center; margin: 10px 0; color: var(--text-meta); font-size: .75rem; }

/* AI Suggestion bar */
.suggestion-bar {
  background: #1d2d35; border-top: 1px solid rgba(255,214,10,.25);
  padding: 10px 16px; display: flex; align-items: center; justify-content: space-between;
  gap: 12px; animation: slideUp .2s ease;
}
.suggestion-content { display: flex; align-items: flex-start; gap: 10px; flex: 1; min-width: 0; }
.suggestion-icon    { font-size: 1rem; flex-shrink: 0; }
.suggestion-text    { font-size: .875rem; color: var(--text-primary); line-height: 1.5; }
.suggestion-actions { display: flex; gap: 8px; flex-shrink: 0; }
.btn-accept  { background: var(--accent); color: #fff; border: none; border-radius: var(--radius-sm); padding: 6px 14px; font-family: var(--font); font-size: .82rem; font-weight: 600; cursor: pointer; transition: background .15s; }
.btn-accept:hover   { background: var(--accent-hover); }
.btn-dismiss { background: none; border: 1px solid var(--border); color: var(--text-secondary); border-radius: var(--radius-sm); padding: 6px 10px; cursor: pointer; font-size: .85rem; transition: border-color .15s; }
.btn-dismiss:hover  { border-color: var(--text-secondary); }

/* Compose bar */
.compose-bar {
  background: var(--bg-header); border-top: 1px solid var(--border);
  padding: 10px 16px; display: flex; align-items: flex-end; gap: 10px;
}
.compose-input {
  flex: 1; background: var(--bg-input); border: none; border-radius: var(--radius-md);
  color: var(--text-primary); font-family: var(--font); font-size: .9rem;
  padding: 10px 14px; resize: none; outline: none; line-height: 1.5;
  max-height: 140px; overflow-y: auto;
}
.send-btn {
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--accent); border: none; color: #fff;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: background .15s, transform .1s;
}
.send-btn:hover  { background: var(--accent-hover); }
.send-btn:active { transform: scale(.92); }

.attach-btn {
  width: 42px; height: 42px; border-radius: 50%;
  background: transparent; border: none; color: var(--text-secondary);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: color .15s, background .15s;
}
.attach-btn:hover { color: var(--text-primary); background: rgba(255,255,255,.05); }

.attach-btn.uploading {
  pointer-events: none; opacity: .6;
  animation: spin 1s linear infinite;
}

/* ── Animations ──────────────────────────────────────────────────────────── */
@keyframes fadeUp   { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
@keyframes spin     { to { transform: rotate(360deg); } }
@keyframes msgIn    { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes slideUp  { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ── Media messages ──────────────────────────────────────────────────────── */
.msg-media-img {
  display: block; max-width: 260px; max-height: 200px;
  border-radius: var(--radius-sm); object-fit: cover;
  cursor: pointer; transition: opacity .15s;
}
.msg-media-img:hover { opacity: .88; }

.msg-video {
  display: block; max-width: 280px; max-height: 200px;
  border-radius: var(--radius-sm); background: #000;
}

.msg-audio {
  display: block; width: 240px;
  accent-color: var(--accent);
}

.msg-doc {
  display: flex; align-items: center; gap: 10px;
  background: rgba(255,255,255,.06); border-radius: var(--radius-sm);
  padding: 10px 14px; text-decoration: none; color: var(--text-primary);
  border: 1px solid var(--border); transition: background .15s;
  max-width: 240px;
}
.msg-doc:hover       { background: rgba(255,255,255,.1); }
.msg-doc-icon        { font-size: 1.4rem; flex-shrink: 0; }
.msg-doc-name        { font-size: .82rem; word-break: break-all; }

.msg-sticker         { width: 120px; height: 120px; object-fit: contain; }

.msg-caption {
  font-size: .82rem; color: rgba(255,255,255,.7);
  margin-top: 5px; line-height: 1.4;
}

/* ── Lightbox ────────────────────────────────────────────────────────────── */
#lightbox {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(0,0,0,.9);
  display: flex; align-items: center; justify-content: center;
  cursor: zoom-out;
  animation: fadeUp .2s ease;
}
#lightbox.hidden { display: none; }
#lightboxImg {
  max-width: 90vw; max-height: 90vh;
  border-radius: var(--radius-sm);
  object-fit: contain;
  box-shadow: 0 16px 80px rgba(0,0,0,.8);
}

