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

:root {
  --green: #25D366;
  --green-dark: #1da851;
  --bg: #f0f2f5;
  --sidebar-bg: #ffffff;
  --chat-bg: #e5ddd5;
  --header-bg: #075E54;
  --text: #111b21;
  --text-muted: #667781;
  --border: #e9edef;
  --bubble-in: #ffffff;
  --bubble-out: #d9fdd3;
  --danger: #dc3545;
  --warning: #fd7e14;
  --info: #0dcaf0;
}

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); height: 100vh; overflow: hidden; }

/* ── LOGIN ── */
.login-page { display: flex; align-items: center; justify-content: center; height: 100vh; background: linear-gradient(135deg, #075E54 0%, #128C7E 100%); overflow: auto; }
.login-card { background: #fff; border-radius: 12px; padding: 40px 36px; width: 100%; max-width: 380px; box-shadow: 0 8px 32px rgba(0,0,0,.15); }
.login-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.login-logo h1 { font-size: 1.5rem; color: var(--header-bg); }
.login-subtitle { color: var(--text-muted); font-size: .875rem; margin-bottom: 28px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: .8rem; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; text-transform: uppercase; letter-spacing: .5px; }
.form-group input, .form-group select, .form-group textarea { width: 100%; padding: 10px 12px; border: 1.5px solid var(--border); border-radius: 8px; font-size: .95rem; transition: border-color .15s; outline: none; }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { border-color: var(--green); }
.error-msg { color: var(--danger); font-size: .85rem; padding: 8px 12px; background: #fff5f5; border-radius: 6px; margin-bottom: 12px; }
.success-msg { color: #155724; font-size: .85rem; padding: 8px 12px; background: #d4edda; border-radius: 6px; margin-bottom: 12px; }

/* ── BUTTONS ── */
.btn-primary { background: var(--green); color: #fff; border: none; border-radius: 8px; padding: 10px 20px; font-size: .95rem; font-weight: 600; cursor: pointer; transition: background .15s; }
.btn-primary:hover { background: var(--green-dark); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1.5px solid var(--border); border-radius: 8px; padding: 8px 16px; font-size: .9rem; cursor: pointer; }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: var(--danger); color: #fff; border: none; border-radius: 8px; padding: 8px 16px; font-size: .9rem; cursor: pointer; }
.btn-full { width: 100%; }
button:disabled { opacity: .6; cursor: not-allowed; }

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

.sidebar { width: 360px; min-width: 280px; background: var(--sidebar-bg); border-right: 1px solid var(--border); display: flex; flex-direction: column; }
.sidebar-header { background: var(--header-bg); color: #fff; padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; min-height: 60px; }
.sidebar-header h2 { font-size: 1.1rem; }
.sidebar-tabs { display: flex; border-bottom: 1px solid var(--border); }
.sidebar-tab { flex: 1; padding: 10px; text-align: center; font-size: .8rem; font-weight: 600; cursor: pointer; color: var(--text-muted); border-bottom: 2px solid transparent; transition: all .15s; }
.sidebar-tab.active { color: var(--green); border-bottom-color: var(--green); }
.chat-list { flex: 1; overflow-y: auto; }
.chat-item { display: flex; align-items: center; padding: 12px 16px; cursor: pointer; border-bottom: 1px solid var(--border); gap: 12px; transition: background .1s; }
.chat-item:hover, .chat-item.active { background: var(--bg); }
.chat-avatar { width: 44px; height: 44px; border-radius: 50%; background: var(--green); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 1.1rem; flex-shrink: 0; }
.chat-info { flex: 1; overflow: hidden; }
.chat-name { font-weight: 600; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-preview { font-size: .8rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.chat-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.chat-time { font-size: .72rem; color: var(--text-muted); }
.badge { background: var(--green); color: #fff; border-radius: 10px; font-size: .7rem; padding: 2px 8px; font-weight: 700; white-space: nowrap; }
.badge-pending { background: var(--warning); }
.badge-attended { background: var(--info); }
.badge-quoted { background: #6f42c1; }
.badge-resolved { background: #6c757d; }

/* ── MAIN CHAT AREA ── */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.chat-header { background: var(--header-bg); color: #fff; padding: 10px 16px; display: flex; align-items: center; gap: 12px; min-height: 60px; }
.chat-header-info { flex: 1; }
.chat-header-info h3 { font-size: 1rem; }
.chat-header-info p { font-size: .78rem; opacity: .8; }
.chat-header-actions { display: flex; gap: 8px; }
.chat-header-actions button { background: rgba(255,255,255,.15); color: #fff; border: none; border-radius: 6px; padding: 6px 12px; font-size: .8rem; cursor: pointer; }
.chat-header-actions button:hover { background: rgba(255,255,255,.25); }

.messages-area { flex: 1; overflow-y: auto; padding: 16px; background: var(--chat-bg); display: flex; flex-direction: column; gap: 6px; }
.msg-bubble { max-width: 65%; padding: 8px 12px; border-radius: 8px; font-size: .9rem; line-height: 1.4; position: relative; }
.msg-bubble.inbound { background: var(--bubble-in); align-self: flex-start; border-top-left-radius: 2px; }
.msg-bubble.outbound { background: var(--bubble-out); align-self: flex-end; border-top-right-radius: 2px; }
.msg-time { font-size: .7rem; color: var(--text-muted); margin-top: 4px; text-align: right; }
.msg-sender { font-size: .72rem; color: var(--green); font-weight: 700; margin-bottom: 2px; }
.msg-date-divider { text-align: center; font-size: .75rem; color: var(--text-muted); background: rgba(255,255,255,.7); padding: 4px 12px; border-radius: 10px; align-self: center; }

.reply-area { padding: 10px 16px; background: #fff; border-top: 1px solid var(--border); display: flex; gap: 10px; align-items: flex-end; }
.reply-area textarea { flex: 1; border: 1.5px solid var(--border); border-radius: 20px; padding: 10px 16px; resize: none; font-size: .9rem; max-height: 120px; outline: none; line-height: 1.4; }
.reply-area textarea:focus { border-color: var(--green); }
.send-btn { background: var(--green); color: #fff; border: none; width: 44px; height: 44px; border-radius: 50%; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.send-btn:hover { background: var(--green-dark); }
.send-btn svg { width: 20px; height: 20px; }

.icon-btn { background: none; border: none; font-size: 1.4rem; cursor: pointer; padding: 6px 8px; border-radius: 50%; flex-shrink: 0; transition: background .15s; }
.icon-btn:hover { background: var(--bg); }

/* ── EMOJI PICKER ── */
.emoji-picker { display: none; position: absolute; bottom: 70px; left: 10px; background: #fff; border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 4px 16px rgba(0,0,0,.15); padding: 10px; width: 320px; max-height: 280px; overflow-y: auto; z-index: 100; }
.emoji-picker.open { display: block; }
.emoji-picker .emoji-row { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; }
.emoji-picker .emoji-item { font-size: 1.4rem; padding: 6px; border-radius: 6px; cursor: pointer; text-align: center; border: none; background: none; }
.emoji-picker .emoji-item:hover { background: var(--bg); }
.emoji-picker .emoji-category-title { font-size: .72rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; margin: 8px 4px 4px; }

/* ── FILE PREVIEW MODAL ── */
.file-preview { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.file-preview-inner { background: #fff; border-radius: 12px; padding: 20px; max-width: 500px; width: 90%; max-height: 80vh; display: flex; flex-direction: column; }
.file-preview-inner img { max-width: 100%; max-height: 400px; object-fit: contain; margin-bottom: 14px; border-radius: 8px; }
.file-preview-inner .doc-icon { text-align: center; padding: 30px; background: var(--bg); border-radius: 8px; margin-bottom: 14px; }
.file-preview-inner .doc-icon .doc-emoji { font-size: 3rem; }
.file-preview-inner .doc-icon .doc-name { font-weight: 600; margin-top: 8px; word-break: break-all; }
.file-preview-inner .doc-icon .doc-size { font-size: .8rem; color: var(--text-muted); }
.file-preview-inner input[type=text] { border: 1.5px solid var(--border); border-radius: 8px; padding: 10px 14px; font-size: .9rem; outline: none; }
.file-preview-inner input[type=text]:focus { border-color: var(--green); }

/* Message bubble media */
.msg-bubble img.msg-media { max-width: 100%; border-radius: 6px; margin-bottom: 4px; cursor: pointer; }
.msg-bubble .msg-doc { display: flex; align-items: center; gap: 10px; padding: 8px; background: rgba(0,0,0,.05); border-radius: 6px; text-decoration: none; color: inherit; }
.msg-bubble .msg-doc-icon { font-size: 1.8rem; }
.msg-bubble .msg-doc-name { font-weight: 600; font-size: .88rem; }
.msg-bubble .msg-doc-type { font-size: .75rem; color: var(--text-muted); }

.reply-area { position: relative; }

.empty-chat { flex: 1; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 12px; color: var(--text-muted); background: var(--chat-bg); }
.empty-chat svg { opacity: .3; }

/* ── RIGHT PANEL ── */
.right-panel { width: 300px; background: var(--sidebar-bg); border-left: 1px solid var(--border); display: flex; flex-direction: column; overflow-y: auto; }
.panel-section { padding: 16px; border-bottom: 1px solid var(--border); }
.panel-section h4 { font-size: .8rem; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); margin-bottom: 12px; }
.info-row { display: flex; justify-content: space-between; font-size: .85rem; margin-bottom: 8px; }
.info-row span:first-child { color: var(--text-muted); }
.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.dot-online { background: var(--green); }
.dot-offline { background: #ccc; }

/* ── NAV TABS (top) ── */
.top-nav { background: var(--header-bg); display: flex; align-items: center; padding: 0 16px; min-height: 60px; gap: 8px; }
.top-nav h1 { color: #fff; font-size: 1.1rem; margin-right: 16px; }
.nav-tab { color: rgba(255,255,255,.7); padding: 8px 14px; border-radius: 6px; cursor: pointer; font-size: .9rem; border: none; background: none; }
.nav-tab:hover, .nav-tab.active { background: rgba(255,255,255,.15); color: #fff; }
.nav-right { margin-left: auto; display: flex; align-items: center; gap: 10px; color: #fff; font-size: .85rem; }
.wa-status { display: flex; align-items: center; gap: 6px; font-size: .8rem; padding: 4px 10px; border-radius: 12px; background: rgba(255,255,255,.1); }

/* ── VIEWS ── */
.view { display: none; flex: 1; overflow: hidden; }
.view.active { display: flex; }
.view-scroll { flex: 1; overflow-y: auto; padding: 24px; }

/* ── REPORTS ── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { background: #fff; border-radius: 10px; padding: 20px; box-shadow: 0 1px 4px rgba(0,0,0,.06); }
.stat-card .stat-value { font-size: 2rem; font-weight: 700; color: var(--header-bg); }
.stat-card .stat-label { font-size: .8rem; color: var(--text-muted); margin-top: 4px; }
.report-section { background: #fff; border-radius: 10px; padding: 20px; margin-bottom: 20px; box-shadow: 0 1px 4px rgba(0,0,0,.06); }
.report-section h3 { font-size: 1rem; margin-bottom: 16px; display: flex; align-items: center; justify-content: space-between; }
.report-filters { display: flex; gap: 10px; margin-bottom: 20px; align-items: flex-end; flex-wrap: wrap; }
.report-filters .form-group { margin-bottom: 0; min-width: 140px; }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
th { text-align: left; padding: 10px 12px; font-size: .75rem; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); border-bottom: 2px solid var(--border); }
td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }
.time-bar { height: 6px; background: var(--bg); border-radius: 3px; margin-top: 4px; }
.time-bar-fill { height: 100%; background: var(--green); border-radius: 3px; transition: width .3s; }

/* ── ADMIN USERS ── */
.user-card { background: #fff; border-radius: 10px; padding: 16px; margin-bottom: 12px; display: flex; align-items: center; gap: 14px; box-shadow: 0 1px 4px rgba(0,0,0,.06); }
.user-avatar { width: 44px; height: 44px; border-radius: 50%; background: var(--header-bg); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 1.1rem; flex-shrink: 0; }
.user-info { flex: 1; }
.user-info h4 { font-size: .95rem; }
.user-info p { font-size: .8rem; color: var(--text-muted); }
.user-actions { display: flex; gap: 6px; }
.role-badge { font-size: .72rem; padding: 2px 8px; border-radius: 10px; font-weight: 600; }
.role-admin { background: #ffe0e0; color: #c00; }
.role-supervisor { background: #e0f0ff; color: #0066cc; }
.role-vendor { background: #e0ffe8; color: #006622; }

/* ── MODAL ── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.modal { background: #fff; border-radius: 12px; padding: 28px; width: 100%; max-width: 440px; max-height: 90vh; overflow-y: auto; }
.modal h3 { margin-bottom: 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ── VENDOR ONLINE TOGGLE ── */
.online-toggle { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: rgba(255,255,255,.1); border-radius: 8px; color: #fff; cursor: pointer; border: none; font-size: .85rem; }
.toggle-switch { width: 36px; height: 20px; border-radius: 10px; background: #ccc; position: relative; transition: background .2s; }
.toggle-switch.on { background: var(--green); }
.toggle-switch::after { content: ''; position: absolute; width: 16px; height: 16px; background: #fff; border-radius: 50%; top: 2px; left: 2px; transition: left .2s; }
.toggle-switch.on::after { left: 18px; }

/* ── MOBILE RESPONSIVE ── */
@media (max-width: 768px) {
  body { font-size: 14px; }
  #app { flex-direction: column; }

  .sidebar { width: 100%; min-width: unset; border-right: none; border-bottom: 1px solid var(--border); max-height: 35vh; }
  .chat-list { max-height: 20vh; }

  .main { flex: 1; display: flex; flex-direction: column; }

  .chat-header { min-height: 50px; padding: 8px 12px; }
  .chat-header-info h3 { font-size: .95rem; }
  .chat-header-info p { font-size: .7rem; }
  .chat-header-actions button { padding: 5px 10px; font-size: .75rem; }

  .right-panel { width: 100%; border-left: none; border-top: 1px solid var(--border); max-height: 25vh; overflow-y: auto; }
  .right-panel .panel-section { padding: 12px; border-bottom: 1px solid var(--border); }
  .right-panel .panel-section h4 { font-size: .7rem; }
  .right-panel .info-row { font-size: .8rem; }

  .reply-area { padding: 8px 10px; gap: 6px; }
  .reply-area textarea { padding: 8px 10px; font-size: .9rem; }
  .send-btn { width: 40px; height: 40px; }
  .send-btn svg { width: 18px; height: 18px; }
  .icon-btn { font-size: 1.2rem; padding: 4px 6px; }

  .msg-bubble { max-width: 85%; padding: 6px 10px; font-size: .85rem; }
  .msg-time { font-size: .65rem; }

  .top-nav { padding: 0 10px; gap: 4px; min-height: 50px; }
  .top-nav h1 { font-size: 1rem; margin-right: 8px; }
  .nav-tab { padding: 6px 10px; font-size: .75rem; }
  .nav-right { font-size: .75rem; gap: 6px; }

  .sidebar-header { min-height: 50px; padding: 8px 12px; }
  .sidebar-header h2 { font-size: 1rem; }

  .chat-item { padding: 10px 12px; gap: 10px; }
  .chat-avatar { width: 40px; height: 40px; font-size: .95rem; }
  .chat-name { font-size: .85rem; }
  .chat-preview { font-size: .75rem; margin-top: 1px; }
  .chat-time { font-size: .65rem; }

  .form-group { margin-bottom: 12px; }
  .form-group label { font-size: .7rem; margin-bottom: 4px; }
  .form-group input, .form-group select, .form-group textarea { padding: 8px 10px; font-size: .85rem; }

  .btn-primary, .btn-secondary, .btn-danger { padding: 8px 14px; font-size: .85rem; }
  .btn-full { width: 100%; }

  .stat-card { padding: 14px; }
  .stat-card .stat-value { font-size: 1.6rem; }
  .stat-card .stat-label { font-size: .75rem; }

  .report-section { padding: 14px; margin-bottom: 12px; }
  .report-section h3 { font-size: .95rem; margin-bottom: 12px; }
  table { font-size: .75rem; }
  th, td { padding: 8px; }

  .user-card { padding: 12px; margin-bottom: 10px; }
  .user-avatar { width: 40px; height: 40px; font-size: .95rem; }
  .user-info h4 { font-size: .85rem; }
  .user-info p { font-size: .75rem; }

  .modal { padding: 20px; max-width: 100%; width: 95%; }
  .modal h3 { margin-bottom: 16px; font-size: 1rem; }
  .modal-actions { gap: 8px; }

  .emoji-picker { width: 100%; max-width: 300px; left: 50%; transform: translateX(-50%); }
  .emoji-picker .emoji-item { font-size: 1.2rem; padding: 4px; }

  .file-preview-inner { width: 95%; padding: 16px; }
  .file-preview-inner img { max-height: 300px; }

  .empty-chat svg { width: 60px; height: 60px; }
  .empty-chat p { font-size: .85rem; }

  .online-toggle { font-size: .8rem; padding: 8px 12px; }
  .toggle-switch { width: 32px; height: 18px; }
  .toggle-switch::after { width: 14px; height: 14px; }

  /* Sidebar drawer on mobile - can be toggled */
  .sidebar-toggle-btn { display: block; position: absolute; top: 10px; left: 10px; background: none; border: none; font-size: 1.5rem; cursor: pointer; z-index: 999; }
  .sidebar.drawer-hidden { position: fixed; left: -100%; top: 0; width: 80vw; height: 100vh; z-index: 998; transition: left .3s; }
  .sidebar.drawer-visible { left: 0; }
}

@media (max-width: 480px) {
  .top-nav { flex-wrap: wrap; min-height: auto; }
  .nav-tab { padding: 5px 8px; font-size: .7rem; }
  .nav-right { order: 2; width: 100%; justify-content: flex-end; margin-top: 4px; }

  .sidebar-tabs { font-size: .75rem; }
  .sidebar-tab { padding: 8px 6px; }

  .chat-item { padding: 8px 10px; }
  .chat-avatar { width: 36px; height: 36px; }

  .msg-bubble { max-width: 90%; padding: 5px 8px; font-size: .8rem; }
  .msg-bubble .msg-sender { font-size: .65rem; }

  .stat-card { padding: 12px; }
  .stat-card .stat-value { font-size: 1.4rem; }

  .report-filters { flex-direction: column; }
  .report-filters .form-group { width: 100%; min-width: unset; }

  table { font-size: .7rem; }
  th, td { padding: 6px; }

  .emoji-picker { max-width: 280px; }
  .emoji-picker .emoji-row { grid-template-columns: repeat(6, 1fr); }
}

/* ── SCROLLBARS ── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #ccc; border-radius: 2px; }

/* ── TOAST ── */
.toast-container { position: fixed; top: 20px; right: 20px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #333; color: #fff; padding: 12px 18px; border-radius: 8px; font-size: .875rem; box-shadow: 0 4px 12px rgba(0,0,0,.2); animation: slideIn .2s ease; max-width: 300px; }
.toast.toast-success { background: #198754; }
.toast.toast-error { background: var(--danger); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── LOADING ── */
.spinner { border: 2px solid var(--border); border-top-color: var(--green); border-radius: 50%; width: 20px; height: 20px; animation: spin .6s linear infinite; }

/* ── FOOTER ── */
.app-footer { margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--border); text-align: center; font-size: 0.75rem; color: var(--text-muted); }
.app-footer p { margin-bottom: 8px; }
.app-footer .links { display: flex; justify-content: center; gap: 12px; }
.app-footer a { color: var(--header-bg); text-decoration: none; font-weight: 600; }
.app-footer a:hover { text-decoration: underline; }
