/* ═══════════════════════════════════════════════════════════
   SmartBuy Care Portal — WhatsApp-style
   ═══════════════════════════════════════════════════════════ */

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif; -webkit-font-smoothing: antialiased; }

:root {
  --primary: #6366F1;
  --primary-dark: #4F46E5;
  --primary-light: #EEF2FF;
  --bg: #F9FAFB;
  --surface: #FFFFFF;
  --border: #E5E7EB;
  --text: #111827;
  --text-sec: #6B7280;
  --text-muted: #9CA3AF;
  --success: #10B981;
  --warning: #F59E0B;
  --danger: #EF4444;
  
  /* WhatsApp colors */
  --wa-header: #075E54;
  --wa-header-dark: #054C44;
  --wa-bg: #ECE5DD;
  --wa-outgoing: #DCF8C6;
  --wa-incoming: #FFFFFF;
  --wa-pattern: rgba(0,0,0,0.03);
  --wa-text: #111;
  --wa-time: #667781;
  --wa-check: #53BDEB;
  --wa-link: #039BE5;
  --wa-action: #00A884;
}

body { background: var(--bg); color: var(--text); font-size: 14px; }

/* ─── Login ───────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 20px;
}
.login-box {
  background: var(--surface);
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}
.login-logo { width: 72px; height: 72px; border-radius: 20px; background: var(--primary); display: flex; align-items: center; justify-content: center; color: white; font-size: 32px; margin: 0 auto 20px; }
.login-title { text-align: center; font-size: 24px; font-weight: 600; margin-bottom: 4px; }
.login-sub { text-align: center; color: var(--text-sec); font-size: 13px; margin-bottom: 28px; }
.login-field { margin-bottom: 16px; }
.login-field label { display: block; font-size: 13px; color: var(--text); margin-bottom: 6px; }
.login-field input { width: 100%; padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; font-size: 14px; background: #F3F4F6; }
.login-field input:focus { outline: none; border-color: var(--primary); background: white; }
.login-btn { width: 100%; padding: 12px; background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%); color: white; border: none; border-radius: 10px; font-size: 14px; font-weight: 500; cursor: pointer; margin-top: 8px; }
.login-btn:hover { opacity: 0.9; }
.login-btn:disabled { opacity: 0.6; cursor: not-allowed; }
.login-footer { text-align: center; color: var(--text-muted); font-size: 11px; margin-top: 20px; }
.login-error { background: #FEE2E2; color: #991B1B; padding: 10px; border-radius: 8px; font-size: 13px; margin-bottom: 10px; text-align: center; }

/* ─── App Layout ──────────────────────────── */
.app { display: grid; grid-template-columns: 240px 1fr; height: 100vh; background: var(--bg); }

/* ─── Sidebar ─────────────────────────────── */
.sidebar { background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; }
.sidebar-brand { padding: 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.brand-logo { width: 32px; height: 32px; border-radius: 8px; background: var(--primary); display: flex; align-items: center; justify-content: center; color: white; font-weight: 600; }
.brand-text { font-weight: 600; font-size: 15px; }
.brand-sub { font-size: 11px; color: var(--text-muted); }

.sidebar-section { padding: 12px 16px 4px; font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; font-weight: 500; }
.sidebar-items { padding: 0 8px; }
.sidebar-item { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; cursor: pointer; color: var(--text); font-size: 13.5px; margin-bottom: 1px; }
.sidebar-item:hover { background: var(--primary-light); }
.sidebar-item.active { background: var(--primary-light); color: var(--primary-dark); font-weight: 500; }
.sidebar-item .icon { font-size: 16px; }
.sidebar-item .count { margin-left: auto; background: var(--primary); color: white; font-size: 10px; padding: 2px 7px; border-radius: 10px; min-width: 22px; text-align: center; font-weight: 600; }

.sidebar-footer { margin-top: auto; padding: 12px 16px; border-top: 1px solid var(--border); }
.sidebar-user { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 8px; cursor: pointer; }
.sidebar-user:hover { background: var(--bg); }
.user-avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--primary); color: white; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 500; }
.user-name { font-size: 13px; font-weight: 500; }
.user-role { font-size: 11px; color: var(--text-muted); }

/* ─── Main ────────────────────────────────── */
.main { display: flex; flex-direction: column; overflow: hidden; }
.main-header { padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.main-title { font-size: 18px; font-weight: 600; }
.main-body { flex: 1; overflow: hidden; }

/* ─── Inbox View ──────────────────────────── */
.inbox-layout { display: grid; grid-template-columns: 340px 1fr; height: 100%; }
.conv-list { background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; }
.conv-list-header { padding: 14px 16px; border-bottom: 1px solid var(--border); }
.conv-list-title { font-size: 15px; font-weight: 600; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
.conv-list-title .platform-icon { font-size: 18px; }
.conv-count-badge { background: #DBEAFE; color: #1E40AF; font-size: 10px; padding: 2px 8px; border-radius: 10px; font-weight: 600; margin-left: auto; }
.conv-filters { display: flex; gap: 6px; }
.filter-chip { padding: 4px 10px; background: var(--bg); border-radius: 12px; font-size: 11px; cursor: pointer; color: var(--text-sec); border: 1px solid transparent; }
.filter-chip.active { background: var(--primary); color: white; }

.conv-list-items { flex: 1; overflow-y: auto; }
.conv-item { padding: 12px 16px; border-bottom: 1px solid var(--border); cursor: pointer; display: flex; gap: 10px; }
.conv-item:hover { background: var(--bg); }
.conv-item.active { background: var(--primary-light); border-left: 3px solid var(--primary); padding-left: 13px; }
.conv-avatar { width: 42px; height: 42px; border-radius: 50%; background: #25D366; color: white; display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 600; flex-shrink: 0; }
.conv-info { flex: 1; min-width: 0; }
.conv-header-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 2px; }
.conv-name { font-size: 13.5px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-time { font-size: 10px; color: var(--text-muted); flex-shrink: 0; margin-left: 8px; }
.conv-preview { font-size: 12px; color: var(--text-sec); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-badges { display: flex; gap: 4px; margin-top: 4px; }
.conv-badge { font-size: 9px; padding: 1px 7px; border-radius: 8px; font-weight: 500; }
.badge-category { background: #E0E7FF; color: #3730A3; }
.badge-mine { background: #FEF3C7; color: #92400E; }
.badge-bot { background: #F3E8FF; color: #6B21A8; }
.badge-paused { background: #FEE2E2; color: #991B1B; }

.conv-list-empty { padding: 60px 20px; text-align: center; color: var(--text-muted); }
.conv-list-empty .icon { font-size: 48px; margin-bottom: 12px; opacity: 0.4; }

/* ─── Chat Area (WhatsApp-style) ───────────── */
.chat-area { display: flex; flex-direction: column; background: var(--wa-bg); overflow: hidden; }

.chat-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--text-muted); background: var(--bg); }
.chat-empty .icon { font-size: 72px; margin-bottom: 16px; opacity: 0.3; }
.chat-empty h3 { font-size: 18px; margin-bottom: 6px; color: var(--text-sec); font-weight: 500; }
.chat-empty p { font-size: 13px; }

/* Chat header - WhatsApp green */
.chat-header { padding: 10px 16px; background: var(--wa-header); color: white; display: flex; align-items: center; justify-content: space-between; }
.chat-header-left { display: flex; align-items: center; gap: 10px; }
.chat-avatar { width: 40px; height: 40px; border-radius: 50%; background: rgba(255,255,255,0.2); display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 500; }
.chat-name { font-size: 15px; font-weight: 500; }
.chat-sub { font-size: 11px; opacity: 0.8; }
.chat-actions { display: flex; gap: 8px; align-items: center; }
.chat-btn { background: rgba(255,255,255,0.15); border: 1px solid rgba(255,255,255,0.2); color: white; padding: 7px 14px; border-radius: 8px; font-size: 12px; cursor: pointer; font-weight: 500; }
.chat-btn:hover { background: rgba(255,255,255,0.25); }
.chat-btn-icon { width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; background: transparent; border: none; color: white; cursor: pointer; border-radius: 50%; }
.chat-btn-icon:hover { background: rgba(255,255,255,0.15); }

/* Status banner */
.chat-banner { padding: 8px 16px; background: #FFF8E1; color: #78350F; font-size: 12px; display: flex; align-items: center; gap: 8px; border-bottom: 1px solid #FDE68A; }
.chat-banner.success { background: #D1FAE5; color: #065F46; border-color: #A7F3D0; }

/* Category/toolbar */
.chat-toolbar { padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; font-size: 12px; }
.chat-toolbar label { color: var(--text-sec); }
.chat-toolbar select { padding: 4px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 12px; background: white; }

/* Messages area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 8%;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--wa-bg);
  background-image: radial-gradient(circle, var(--wa-pattern) 1px, transparent 1px);
  background-size: 10px 10px;
}

/* Day separator */
.day-sep { text-align: center; margin: 10px 0 6px; }
.day-sep span { background: rgba(255,255,255,0.9); padding: 4px 12px; border-radius: 6px; font-size: 11px; color: #444; }

/* System event */
.sys-event { text-align: center; margin: 8px 0; }
.sys-event span { font-size: 11px; background: rgba(255,255,255,0.9); padding: 4px 12px; border-radius: 10px; color: var(--wa-time); display: inline-flex; align-items: center; gap: 6px; }

/* Message row */
.msg-row { display: flex; margin-bottom: 2px; }
.msg-row.left { justify-content: flex-start; }
.msg-row.right { justify-content: flex-end; }

/* Bubble */
.bubble {
  max-width: 68%;
  padding: 6px 9px 20px 9px;
  border-radius: 7.5px;
  position: relative;
  box-shadow: 0 1px 0.5px rgba(0,0,0,0.08);
  word-wrap: break-word;
}
.bubble-text { font-size: 13.5px; color: var(--wa-text); line-height: 1.4; white-space: pre-wrap; }
.bubble-rtl { direction: rtl; text-align: right; }
.bubble-meta { position: absolute; bottom: 3px; right: 7px; font-size: 10px; color: var(--wa-time); display: flex; align-items: center; gap: 3px; }
.bubble-meta .check { color: var(--wa-check); font-size: 13px; margin-left: 2px; }

/* Customer bubble (incoming - white, left) */
.bubble.customer { background: var(--wa-incoming); border-top-left-radius: 0; }

/* Bot bubble (outgoing - light green, right) */
.bubble.bot { background: var(--wa-outgoing); border-top-right-radius: 0; }
.bubble.bot .bubble-header { font-size: 10px; color: #06C167; font-weight: 500; margin-bottom: 2px; display: flex; align-items: center; gap: 4px; }

/* Agent bubble (outgoing - light green, right) */
.bubble.employee { background: var(--wa-outgoing); border-top-right-radius: 0; }
.bubble.employee .bubble-header { font-size: 10px; color: #00A884; font-weight: 500; margin-bottom: 2px; }

/* Interactive message */
.bubble-interactive { padding-bottom: 6px; }
.interactive-buttons {
  background: white;
  border-top: 1px solid rgba(0,0,0,0.08);
  margin: 6px -9px -3px;
  border-radius: 0 0 7.5px 7.5px;
  display: flex;
  flex-direction: column;
}
.interactive-btn {
  padding: 10px;
  text-align: center;
  color: var(--wa-action);
  font-size: 13px;
  font-weight: 500;
  border-top: 0.5px solid #E5E5E5;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.interactive-btn:first-child { border-top: none; }

/* Button click indicator (customer clicked a button) */
.btn-click-indicator {
  font-size: 10px;
  background: rgba(0,0,0,0.05);
  color: var(--wa-time);
  padding: 2px 7px;
  border-radius: 8px;
  display: inline-block;
  margin-bottom: 3px;
}

/* Internal note */
.msg-note {
  background: #FEF3C7;
  border-left: 3px solid #F59E0B;
  padding: 10px 12px;
  border-radius: 0 8px 8px 0;
  margin: 6px 0;
  font-size: 12px;
}
.msg-note-header { font-size: 10px; color: #92400E; font-weight: 500; margin-bottom: 2px; display: flex; align-items: center; gap: 4px; }
.msg-note-text { color: #78350F; }

/* Input area - WhatsApp style */
.chat-input-area { padding: 10px 14px; background: #F0F0F0; display: flex; align-items: center; gap: 8px; }
.chat-input-wrap { flex: 1; background: white; border-radius: 24px; padding: 8px 16px; display: flex; align-items: center; gap: 10px; }
.chat-input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 14px;
  background: transparent;
  min-height: 20px;
  max-height: 120px;
  resize: none;
  font-family: inherit;
}
.chat-input-icon { color: #54656F; font-size: 20px; cursor: pointer; background: transparent; border: none; padding: 0; }
.chat-send { width: 42px; height: 42px; border-radius: 50%; background: var(--wa-header); color: white; border: none; display: flex; align-items: center; justify-content: center; font-size: 18px; cursor: pointer; flex-shrink: 0; }
.chat-send:hover { background: var(--wa-header-dark); }
.chat-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* Canned replies dropdown */
.canned-dropdown {
  position: absolute;
  bottom: 70px;
  left: 20px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  max-width: 400px;
  max-height: 300px;
  overflow-y: auto;
  z-index: 10;
}
.canned-item { padding: 10px 14px; cursor: pointer; border-bottom: 1px solid var(--border); }
.canned-item:last-child { border-bottom: none; }
.canned-item:hover { background: var(--bg); }
.canned-shortcut { font-size: 11px; color: var(--primary); font-weight: 600; font-family: monospace; }
.canned-title { font-size: 13px; font-weight: 500; margin: 2px 0; }
.canned-text { font-size: 12px; color: var(--text-sec); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ─── Dashboard / Reports / Team / Canned pages ─── */
.page-content { padding: 24px; overflow-y: auto; height: 100%; }
.page-title { font-size: 20px; font-weight: 600; margin-bottom: 20px; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 20px; }
.stat-label { font-size: 12px; color: var(--text-sec); margin-bottom: 6px; }
.stat-value { font-size: 28px; font-weight: 600; color: var(--text); }
.stat-sub { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

.data-table { width: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.data-table th { padding: 12px 16px; background: var(--bg); font-size: 12px; color: var(--text-sec); text-align: left; font-weight: 500; }
.data-table td { padding: 12px 16px; font-size: 13px; border-top: 1px solid var(--border); }

.btn { padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border); background: white; cursor: pointer; font-size: 13px; }
.btn-primary { background: var(--primary); color: white; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }

/* ─── Modal ──────────────────────────────── */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.modal { background: white; border-radius: 12px; padding: 24px; max-width: 500px; width: 100%; max-height: 90vh; overflow-y: auto; }
.modal-title { font-size: 18px; font-weight: 600; margin-bottom: 16px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }

/* ─── Toast ──────────────────────────────── */
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: white; padding: 10px 20px; border-radius: 8px; font-size: 13px; z-index: 200; }

/* ─── Hidden utility ──────────────────────── */
.hidden { display: none !important; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #CBD5E0; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94A3B8; }
