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

:root {
  --green: #25D366;
  --green-dark: #128C7E;
  --bg: #f0f2f5;
  --sidebar-bg: #fff;
  --chat-bg: #e5ddd5;
  --header-bg: #128C7E;
  --bubble-in: #fff;
  --bubble-out: #dcf8c6;
  --text: #111;
  --text-muted: #667781;
  --border: #e9edef;
  --radius: 8px;
}

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

.app { display: flex; height: 100vh; }

/* Sidebar */
.sidebar { width: 360px; min-width: 280px; display: flex; flex-direction: column; background: var(--sidebar-bg); border-right: 1px solid var(--border); }

.sidebar-header { background: var(--header-bg); padding: 12px 16px; color: #fff; }

.logo { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.logo-icon { font-size: 22px; }
.logo-text { font-size: 18px; font-weight: 600; }

.tenant-selector select { width: 100%; padding: 6px 10px; border-radius: var(--radius); border: none; font-size: 13px; background: rgba(255,255,255,0.15); color: #fff; cursor: pointer; }
.tenant-selector select option { color: var(--text); background: #fff; }

.search-box { padding: 8px 12px; background: #f0f2f5; }
.search-box input { width: 100%; padding: 8px 12px; border-radius: 20px; border: none; background: #fff; font-size: 14px; outline: none; }

.contacts-list { flex: 1; overflow-y: auto; }

.contact-item { display: flex; align-items: center; gap: 12px; padding: 12px 16px; cursor: pointer; border-bottom: 1px solid var(--border); transition: background 0.1s; }
.contact-item:hover, .contact-item.active { background: #f0f2f5; }

.avatar { width: 42px; height: 42px; border-radius: 50%; background: var(--green-dark); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 16px; font-weight: 600; flex-shrink: 0; }

.contact-info { flex: 1; min-width: 0; }
.contact-name { font-size: 15px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-last-msg { font-size: 13px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }

.empty-state { padding: 40px 20px; text-align: center; color: var(--text-muted); font-size: 14px; }

.sidebar-footer { padding: 10px 16px; display: flex; gap: 8px; border-top: 1px solid var(--border); justify-content: flex-end; }

/* Chat area */
.chat-area { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.no-chat { flex: 1; display: flex; align-items: center; justify-content: center; background: var(--chat-bg); }
.no-chat-inner { text-align: center; color: var(--text-muted); }
.no-chat-icon { font-size: 64px; margin-bottom: 16px; }
.no-chat h2 { font-size: 22px; font-weight: 300; margin-bottom: 8px; color: #41525d; }

.chat-view { flex: 1; display: flex; flex-direction: column; }

.chat-header { background: var(--header-bg); color: #fff; padding: 10px 16px; display: flex; align-items: center; justify-content: space-between; }
.chat-contact-info { display: flex; align-items: center; gap: 12px; }
.chat-header .avatar { background: rgba(255,255,255,0.3); }
.contact-name { font-size: 16px; font-weight: 500; }
.contact-number { font-size: 13px; opacity: 0.8; }

.messages-container { flex: 1; overflow-y: auto; padding: 16px; background: var(--chat-bg); display: flex; flex-direction: column; gap: 4px; }

.message-bubble { max-width: 65%; padding: 8px 12px; border-radius: 8px; font-size: 14px; line-height: 1.4; position: relative; word-break: break-word; }
.message-bubble.inbound { background: var(--bubble-in); align-self: flex-start; border-top-left-radius: 0; }
.message-bubble.outbound { background: var(--bubble-out); align-self: flex-end; border-top-right-radius: 0; }
.message-time { font-size: 11px; color: var(--text-muted); text-align: right; margin-top: 4px; }

.message-input-area { display: flex; align-items: flex-end; gap: 8px; padding: 10px 16px; background: #f0f2f5; }
.message-input-area textarea { flex: 1; padding: 10px 14px; border-radius: 22px; border: none; font-size: 15px; resize: none; outline: none; max-height: 120px; background: #fff; font-family: inherit; line-height: 1.4; }

.btn-send { width: 44px; height: 44px; border-radius: 50%; background: var(--green-dark); border: none; color: #fff; font-size: 18px; cursor: pointer; display: flex; align-items: center; justify-content: center; flex-shrink: 0; transition: background 0.2s; }
.btn-send:hover { background: var(--green); }

.btn-icon { background: none; border: none; font-size: 18px; cursor: pointer; padding: 6px; border-radius: var(--radius); transition: background 0.1s; }
.btn-icon:hover { background: rgba(0,0,0,0.06); }

/* Modal */
.modal { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; }
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.5); }
.modal-content { position: relative; background: #fff; border-radius: 12px; width: 480px; max-width: 95vw; max-height: 90vh; overflow-y: auto; z-index: 1; }
.modal-header { padding: 20px 24px 16px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border); }
.modal-header h3 { font-size: 18px; }
.btn-close { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--text-muted); padding: 4px; }
.modal-body { padding: 20px 24px 24px; }
.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 5px; color: var(--text-muted); }
.form-group input, .form-group select { width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 14px; outline: none; }
.form-group input:focus, .form-group select:focus { border-color: var(--green-dark); }
.form-group h4 { font-size: 15px; color: var(--text); }

.btn-primary { background: var(--green-dark); color: #fff; border: none; padding: 10px 20px; border-radius: var(--radius); font-size: 14px; cursor: pointer; transition: background 0.2s; }
.btn-primary:hover { background: var(--green); }

/* Toast */
.toast { position: fixed; bottom: 24px; right: 24px; background: #323232; color: #fff; padding: 12px 20px; border-radius: var(--radius); font-size: 14px; z-index: 2000; animation: slideIn 0.3s ease; }
@keyframes slideIn { from { transform: translateY(10px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.hidden { display: none !important; }
.loading { text-align: center; color: var(--text-muted); padding: 40px; }

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

@media (max-width: 640px) {
  .sidebar { width: 100%; position: absolute; z-index: 10; height: 100%; }
  .chat-area { display: none; }
  .app.chat-open .sidebar { display: none; }
  .app.chat-open .chat-area { display: flex; }
}
