:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --sidebar-bg: #1a1d2e;
  --sidebar-hover: #252840;
  --sidebar-active: #2d3153;
  --accent: #25D366;
  --accent-dark: #1da851;
  --accent-light: #e9fdf0;
  --danger: #ef4444;
  --warning: #f59e0b;
  --info: #3b82f6;
  --text-primary: #111827;
  --text-secondary: #6b7280;
  --text-sidebar: #c9cfe0;
  --border: #e5e7eb;
  --message-out: #dcf8c6;
  --message-in: #ffffff;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
  --radius: 12px;
  --font: 'DM Sans', sans-serif;
  --mono: 'DM Mono', monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text-primary); height: 100vh; overflow: hidden; }

/* ── Login ─────────────────────────────── */
.login-screen {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; background: linear-gradient(135deg, #1a1d2e 0%, #252840 50%, #1da851 150%);
}
.login-box {
  background: var(--surface); border-radius: 20px; padding: 40px;
  width: 380px; box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-logo {
  display: flex; align-items: center; gap: 10px;
  font-size: 18px; font-weight: 600; margin-bottom: 28px; color: var(--text-primary);
}
.logo-icon { width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; }
.login-box h2 { font-size: 22px; font-weight: 600; margin-bottom: 24px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; color: var(--text-secondary); margin-bottom: 6px; }
.form-group input {
  width: 100%; padding: 11px 14px; border: 1.5px solid var(--border);
  border-radius: 8px; font-family: var(--font); font-size: 14px; outline: none; transition: .2s;
}
.form-group input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,211,102,0.15); }
.error-msg { color: var(--danger); font-size: 13px; margin-bottom: 12px; }
.btn-primary {
  background: var(--accent); color: white; border: none; padding: 12px 20px;
  border-radius: 8px; font-family: var(--font); font-size: 14px; font-weight: 600;
  cursor: pointer; transition: .2s;
}
.btn-primary:hover { background: var(--accent-dark); }
.btn-block { width: 100%; }

/* ── App Layout ─────────────────────────── */
.app { display: flex; height: 100vh; overflow: hidden; }

/* ── Left Sidebar ─────────────────────────── */
.sidebar {
  width: 320px; flex-shrink: 0; background: var(--sidebar-bg);
  display: flex; flex-direction: column; border-right: 1px solid rgba(255,255,255,0.05);
}
.sidebar-header {
  padding: 16px; display: flex; align-items: center;
  justify-content: space-between; border-bottom: 1px solid rgba(255,255,255,0.05);
}
.sidebar-logo { display: flex; align-items: center; gap: 8px; color: white; font-weight: 600; font-size: 15px; }
.agent-status-dot {
  width: 10px; height: 10px; border-radius: 50%; background: var(--accent);
  box-shadow: 0 0 0 2px rgba(37,211,102,0.3); animation: pulse 2s infinite;
}
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 2px rgba(37,211,102,0.3); } 50% { box-shadow: 0 0 0 5px rgba(37,211,102,0.1); } }

.queue-tabs { display: flex; padding: 8px; gap: 4px; border-bottom: 1px solid rgba(255,255,255,0.05); }
.queue-tab {
  flex: 1; padding: 8px 6px; border: none; background: transparent;
  color: var(--text-sidebar); font-family: var(--font); font-size: 12px; font-weight: 500;
  border-radius: 8px; cursor: pointer; transition: .2s; display: flex; align-items: center; justify-content: center; gap: 5px;
}
.queue-tab.active { background: var(--sidebar-active); color: white; }
.queue-tab:hover:not(.active) { background: var(--sidebar-hover); }
.badge {
  background: var(--accent); color: white; border-radius: 50px;
  padding: 1px 6px; font-size: 10px; font-weight: 700; min-width: 16px; text-align: center;
}
.badge.zero { background: rgba(255,255,255,0.15); }

.sidebar-search { padding: 10px 12px; border-bottom: 1px solid rgba(255,255,255,0.05); }
.sidebar-search input {
  width: 100%; background: rgba(255,255,255,0.07); border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px; padding: 8px 12px; color: white; font-family: var(--font);
  font-size: 13px; outline: none;
}
.sidebar-search input::placeholder { color: rgba(255,255,255,0.35); }

.conv-list { flex: 1; overflow-y: auto; }
.conv-list::-webkit-scrollbar { width: 4px; }
.conv-list::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }

.conv-item {
  padding: 12px 14px; cursor: pointer; transition: .15s;
  border-bottom: 1px solid rgba(255,255,255,0.04); position: relative;
}
.conv-item:hover { background: var(--sidebar-hover); }
.conv-item.active { background: var(--sidebar-active); }
.conv-item.has-unread::after {
  content: ''; position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  width: 8px; height: 8px; border-radius: 50%; background: var(--accent);
}
.conv-item-top { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 4px; }
.conv-item-name { color: white; font-size: 13px; font-weight: 600; flex: 1; truncate: ellipsis; white-space: nowrap; overflow: hidden; }
.conv-item-time { color: rgba(255,255,255,0.35); font-size: 11px; flex-shrink: 0; margin-left: 8px; }
.conv-item-preview { color: rgba(255,255,255,0.45); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-item-meta { display: flex; gap: 6px; margin-top: 4px; flex-wrap: wrap; }
.conv-item-number { font-size: 10px; color: var(--accent); background: rgba(37,211,102,0.12); padding: 1px 6px; border-radius: 4px; }
.conv-item-status { font-size: 10px; }
.status-waiting { color: var(--warning); }
.status-active { color: var(--accent); }
.status-closed { color: rgba(255,255,255,0.3); }
.conv-item-agent { font-size: 10px; color: rgba(255,255,255,0.3); }
.conv-wait-time { font-size: 10px; color: var(--warning); }

.sidebar-footer {
  padding: 12px 14px; border-top: 1px solid rgba(255,255,255,0.07);
  display: flex; align-items: center; justify-content: space-between;
}
.agent-info { display: flex; align-items: center; gap: 10px; }
.agent-avatar {
  width: 34px; height: 34px; border-radius: 50%; background: var(--accent);
  display: flex; align-items: center; justify-content: center; color: white;
  font-weight: 700; font-size: 14px; flex-shrink: 0;
}
.agent-name { display: block; color: white; font-size: 13px; font-weight: 600; }
.agent-role { display: block; color: rgba(255,255,255,0.4); font-size: 11px; }
.footer-actions { display: flex; gap: 4px; }
.icon-btn {
  width: 32px; height: 32px; border: none; background: rgba(255,255,255,0.07);
  border-radius: 8px; cursor: pointer; display: flex; align-items: center;
  justify-content: center; font-size: 15px; transition: .2s; color: white;
}
.icon-btn:hover { background: rgba(255,255,255,0.15); }

/* ── Main Area ─────────────────────────── */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; position: relative; }

.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 100%; color: var(--text-secondary); gap: 12px;
}
.empty-icon { font-size: 64px; opacity: 0.5; }
.empty-state h3 { font-size: 18px; font-weight: 600; color: var(--text-primary); }

.conv-view { display: flex; flex-direction: column; height: 100%; }

.conv-header {
  padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-shrink: 0;
}
.conv-header-info { display: flex; align-items: center; gap: 12px; }
.contact-avatar {
  width: 40px; height: 40px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), var(--info));
  display: flex; align-items: center; justify-content: center; color: white;
  font-weight: 700; font-size: 16px; flex-shrink: 0;
}
.contact-name { font-size: 15px; font-weight: 600; }
.contact-sub { font-size: 12px; color: var(--text-secondary); }
.conv-header-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.number-badge-bar {
  padding: 6px 16px; background: #f8f9fa; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 8px; flex-shrink: 0;
}
.number-badge { font-size: 12px; background: rgba(37,211,102,0.1); color: var(--accent-dark); padding: 2px 10px; border-radius: 50px; font-weight: 500; border: 1px solid rgba(37,211,102,0.2); }
.conv-status-badge { font-size: 11px; color: var(--text-secondary); }

.btn-sm {
  padding: 5px 10px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface); font-size: 12px; cursor: pointer; font-family: var(--font);
  transition: .2s; color: var(--text-primary);
}
.btn-sm:hover { background: var(--bg); }
.btn-sm.btn-danger { border-color: #fecaca; color: var(--danger); }
.btn-sm.btn-danger:hover { background: #fef2f2; }
.btn-sm.btn-primary { background: var(--accent); border-color: var(--accent); color: white; }
.btn-sm.btn-primary:hover { background: var(--accent-dark); }
.tags-container { display: flex; gap: 4px; flex-wrap: wrap; }
.tag-chip { font-size: 11px; padding: 2px 8px; border-radius: 50px; background: var(--bg); border: 1px solid var(--border); }

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

.msg-wrapper { display: flex; flex-direction: column; max-width: 70%; }
.msg-wrapper.inbound { align-self: flex-start; }
.msg-wrapper.outbound { align-self: flex-end; }
.msg-wrapper.note { align-self: center; max-width: 85%; }

.msg-bubble {
  padding: 8px 12px; border-radius: 12px; font-size: 14px; line-height: 1.5;
  word-break: break-word; box-shadow: var(--shadow);
}
.msg-wrapper.inbound .msg-bubble { background: var(--message-in); border-bottom-left-radius: 4px; }
.msg-wrapper.outbound .msg-bubble { background: var(--message-out); border-bottom-right-radius: 4px; }
.msg-wrapper.note .msg-bubble { background: #fef9c3; border: 1px solid #fde68a; border-radius: 8px; font-size: 13px; color: #92400e; }

.msg-meta { font-size: 10px; color: var(--text-secondary); margin-top: 2px; display: flex; gap: 4px; }
.msg-wrapper.outbound .msg-meta { justify-content: flex-end; }
.msg-status { font-size: 11px; }

.msg-media { max-width: 100%; border-radius: 8px; cursor: pointer; }
.msg-media-audio { width: 100%; }
.msg-media-video { max-width: 280px; border-radius: 8px; }
.msg-doc { display: flex; align-items: center; gap: 8px; padding: 4px 0; color: var(--info); text-decoration: none; font-size: 13px; }

.date-separator {
  text-align: center; color: var(--text-secondary); font-size: 11px;
  margin: 12px 0; position: relative;
}
.date-separator::before, .date-separator::after {
  content: ''; position: absolute; top: 50%; width: 30%; height: 1px; background: var(--border);
}
.date-separator::before { left: 0; }
.date-separator::after { right: 0; }

/* ── Input Area ─────────────────────────── */
.input-area {
  padding: 12px 16px; background: var(--surface); border-top: 1px solid var(--border);
  flex-shrink: 0; position: relative;
}
.input-mode-bar { display: flex; gap: 8px; margin-bottom: 10px; }
.mode-btn {
  padding: 5px 12px; border: 1.5px solid var(--border); border-radius: 20px;
  background: transparent; font-size: 12px; cursor: pointer; font-family: var(--font);
  color: var(--text-secondary); transition: .2s;
}
.mode-btn.active { background: var(--accent-light); border-color: var(--accent); color: var(--accent-dark); font-weight: 500; }
.mode-btn.active.note-mode { background: #fef9c3; border-color: #fde68a; color: #92400e; }

.input-row { display: flex; align-items: flex-end; gap: 8px; }
#msgInput {
  flex: 1; border: 1.5px solid var(--border); border-radius: 10px;
  padding: 10px 14px; font-family: var(--font); font-size: 14px; resize: none;
  outline: none; max-height: 120px; transition: .2s; line-height: 1.5;
}
#msgInput:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,211,102,0.1); }
.btn-send {
  width: 42px; height: 42px; border-radius: 10px; background: var(--accent);
  border: none; color: white; font-size: 18px; cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; transition: .2s;
}
.btn-send:hover { background: var(--accent-dark); transform: scale(1.05); }

.file-preview {
  margin-top: 8px; padding: 8px 12px; background: var(--bg); border-radius: 8px;
  display: flex; align-items: center; justify-content: space-between; font-size: 13px;
}
.file-preview button { border: none; background: none; cursor: pointer; color: var(--text-secondary); font-size: 16px; }

.recording-bar {
  margin-top: 8px; padding: 8px 12px; background: #fef2f2; border-radius: 8px;
  display: flex; align-items: center; gap: 12px; font-size: 13px;
}
.rec-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; }
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

.quick-replies-dropdown {
  position: absolute; bottom: 100%; left: 16px; right: 16px; z-index: 100;
  background: var(--surface); border: 1.5px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.12); overflow: hidden; max-height: 240px; overflow-y: auto;
}
.qr-item { padding: 10px 14px; cursor: pointer; transition: .15s; }
.qr-item:hover { background: var(--bg); }
.qr-shortcut { font-family: var(--mono); font-size: 12px; color: var(--accent); font-weight: 500; }
.qr-title { font-size: 13px; font-weight: 500; }
.qr-preview { font-size: 12px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.waiting-bar {
  padding: 14px 16px; background: #fffbeb; border-top: 1.5px solid #fde68a;
  display: flex; align-items: center; justify-content: space-between;
  font-size: 14px; color: #92400e; flex-shrink: 0;
}

/* ── Right Panel ─────────────────────────── */
.right-panel {
  width: 280px; flex-shrink: 0; background: var(--surface);
  border-left: 1px solid var(--border); display: flex; flex-direction: column; overflow-y: auto;
}
.right-panel-header {
  padding: 14px 16px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; flex-shrink: 0;
}
.right-panel-header h3 { font-size: 14px; font-weight: 600; }
.right-panel-header button { border: none; background: none; cursor: pointer; font-size: 16px; color: var(--text-secondary); }
.contact-card { padding: 20px 16px; text-align: center; border-bottom: 1px solid var(--border); }
.contact-big-avatar {
  width: 60px; height: 60px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), var(--info));
  display: flex; align-items: center; justify-content: center; color: white;
  font-weight: 700; font-size: 24px; margin: 0 auto 10px;
}
.contact-big-name { font-weight: 600; font-size: 16px; }
.contact-big-phone { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }
.right-section { padding: 14px 16px; border-bottom: 1px solid var(--border); }
.right-section label { display: block; font-size: 12px; font-weight: 600; color: var(--text-secondary); margin-bottom: 8px; text-transform: uppercase; letter-spacing: .5px; }
.right-section textarea {
  width: 100%; border: 1.5px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font-family: var(--font); font-size: 13px; resize: vertical; outline: none; min-height: 80px;
}
.right-section textarea:focus { border-color: var(--accent); }

/* ── Modals ─────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center; z-index: 1000;
}
.modal { background: var(--surface); border-radius: var(--radius); width: 400px; max-height: 80vh; display: flex; flex-direction: column; overflow: hidden; }
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-header button { border: none; background: none; font-size: 20px; cursor: pointer; color: var(--text-secondary); }
.modal-body { padding: 16px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.modal-body input { width: 100%; padding: 8px 12px; border: 1.5px solid var(--border); border-radius: 8px; font-family: var(--font); font-size: 14px; outline: none; }
.modal-body input:focus { border-color: var(--accent); }
.agent-list { display: flex; flex-direction: column; gap: 4px; }
.agent-list-item {
  padding: 10px 12px; border-radius: 8px; cursor: pointer; transition: .15s;
  display: flex; align-items: center; gap: 10px; border: 1px solid transparent;
}
.agent-list-item:hover { background: var(--bg); border-color: var(--border); }
.agent-list-item .agent-avatar { width: 32px; height: 32px; font-size: 12px; background: var(--info); }
.agent-list-item .agent-status { font-size: 11px; color: var(--text-secondary); }
.agent-list-item .online-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); display: inline-block; margin-right: 3px; }
.tag-options { display: flex; flex-direction: column; gap: 8px; }
.tag-opt { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; }
.tag-opt input { width: auto; }

/* Scrollbar global */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }

/* ── Responsive tweaks ─────────────────── */
@media (max-width: 900px) {
  .right-panel { display: none !important; }
  .sidebar { width: 260px; }
}
@media (max-width: 600px) {
  .sidebar { width: 100%; position: absolute; z-index: 50; }
}
