* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --primary: #075e54; --primary-dark: #054d44; --primary-light: #128c7e;
  --secondary: #25d366; --bg: #f0f2f5; --chat-bg: #efeae2;
  --white: #fff; --text: #111b21; --text-secondary: #667781;
  --border: #e9edef; --hover: #f5f6f6; --bubble-out: #d9fdd3;
  --bubble-in: #fff; --danger: #ea0038; --blue: #53bdeb;
}
body { font-family: 'Inter', -apple-system, sans-serif; background: var(--bg); color: var(--text); height: 100vh; overflow: hidden; }
input, button, textarea { font-family: inherit; }
button { cursor: pointer; border: none; background: none; }
a { text-decoration: none; color: inherit; }
.hidden { display: none !important; }
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }

/* AUTH SCREEN */
.auth-screen { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%); }
.auth-card { background: var(--white); border-radius: 16px; padding: 40px; width: 400px; max-width: 90vw; box-shadow: 0 20px 60px rgba(0,0,0,0.3); }
.auth-logo { text-align: center; margin-bottom: 30px; }
.auth-logo h1 { font-size: 32px; color: var(--primary); font-weight: 700; }
.auth-logo p { color: var(--text-secondary); margin-top: 5px; font-size: 14px; }
.auth-form .form-group { margin-bottom: 16px; }
.auth-form label { display: block; font-size: 13px; font-weight: 500; color: var(--text-secondary); margin-bottom: 6px; }
.auth-form input { width: 100%; padding: 12px 16px; border: 2px solid var(--border); border-radius: 10px; font-size: 15px; transition: border 0.2s; outline: none; }
.auth-form input:focus { border-color: var(--primary); }
.auth-btn { width: 100%; padding: 14px; background: var(--primary); color: var(--white); border-radius: 10px; font-size: 16px; font-weight: 600; transition: background 0.2s; margin-top: 10px; }
.auth-btn:hover { background: var(--primary-dark); }
.auth-switch { text-align: center; margin-top: 20px; font-size: 14px; color: var(--text-secondary); }
.auth-switch a { color: var(--primary); font-weight: 600; cursor: pointer; }
.auth-error { background: #ffeaea; color: var(--danger); padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 16px; display: none; }

/* MAIN LAYOUT */
.app-container { display: flex; height: 100vh; max-width: 100vw; }
.sidebar { width: 420px; min-width: 350px; background: var(--white); border-right: 1px solid var(--border); display: flex; flex-direction: column; }
.chat-area { flex: 1; display: flex; flex-direction: column; background: var(--chat-bg); position: relative; }

/* SIDEBAR HEADER */
.sidebar-header { display: flex; align-items: center; justify-content: space-between; padding: 10px 16px; background: var(--bg); height: 60px; }
.sidebar-header .user-info { display: flex; align-items: center; gap: 12px; cursor: pointer; }
.sidebar-header .user-avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--primary); display: flex; align-items: center; justify-content: center; color: var(--white); font-weight: 600; font-size: 16px; overflow: hidden; }
.sidebar-header .user-avatar img { width: 100%; height: 100%; object-fit: cover; }
.sidebar-header .user-name { font-weight: 600; font-size: 15px; }
.sidebar-actions { display: flex; gap: 8px; }
.sidebar-actions button { width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--text-secondary); font-size: 18px; transition: background 0.2s; }
.sidebar-actions button:hover { background: var(--border); }

/* SEARCH */
.search-box { padding: 8px 12px; background: var(--bg); }
.search-box input { width: 100%; padding: 8px 16px 8px 40px; border: none; border-radius: 8px; background: var(--white); font-size: 14px; outline: none; }
.search-box { position: relative; }
.search-box i { position: absolute; left: 26px; top: 50%; transform: translateY(-50%); color: var(--text-secondary); font-size: 14px; }

/* TABS */
.sidebar-tabs { display: flex; border-bottom: 1px solid var(--border); background: var(--white); }
.sidebar-tabs button { flex: 1; padding: 12px; font-size: 13px; font-weight: 500; color: var(--text-secondary); border-bottom: 3px solid transparent; transition: all 0.2s; }
.sidebar-tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }

/* CONVERSATION LIST */
.conversation-list { flex: 1; overflow-y: auto; }
.conv-item { display: flex; align-items: center; padding: 12px 16px; gap: 14px; cursor: pointer; transition: background 0.15s; border-bottom: 1px solid var(--border); }
.conv-item:hover, .conv-item.active { background: var(--hover); }
.conv-avatar { width: 50px; height: 50px; min-width: 50px; border-radius: 50%; background: var(--primary-light); display: flex; align-items: center; justify-content: center; color: var(--white); font-weight: 600; font-size: 20px; overflow: hidden; position: relative; }
.conv-avatar img { width: 100%; height: 100%; object-fit: cover; }
.conv-avatar .online-dot { position: absolute; bottom: 2px; right: 2px; width: 12px; height: 12px; background: var(--secondary); border-radius: 50%; border: 2px solid var(--white); }
.conv-info { flex: 1; min-width: 0; }
.conv-info-top { display: flex; justify-content: space-between; align-items: center; }
.conv-name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: 12px; color: var(--text-secondary); white-space: nowrap; }
.conv-info-bottom { display: flex; justify-content: space-between; align-items: center; margin-top: 3px; }
.conv-last-msg { font-size: 13px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.conv-unread { background: var(--secondary); color: var(--white); border-radius: 50%; min-width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 600; padding: 0 5px; margin-left: 8px; }

/* CHAT HEADER */
.chat-header { display: flex; align-items: center; padding: 10px 16px; background: var(--bg); height: 60px; gap: 14px; border-bottom: 1px solid var(--border); }
.chat-header .back-btn { display: none; width: 36px; height: 36px; border-radius: 50%; align-items: center; justify-content: center; font-size: 18px; color: var(--text-secondary); }
.chat-header-info { flex: 1; cursor: pointer; }
.chat-header-info h3 { font-size: 16px; font-weight: 600; }
.chat-header-info p { font-size: 12px; color: var(--text-secondary); }
.chat-header-actions { display: flex; gap: 4px; }
.chat-header-actions button { width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--text-secondary); font-size: 18px; }
.chat-header-actions button:hover { background: rgba(0,0,0,0.05); }

/* MESSAGES */
.messages-container { flex: 1; overflow-y: auto; padding: 20px 60px; display: flex; flex-direction: column; gap: 2px; background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23d4cfc6' fill-opacity='0.15'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E"); }
.message { display: flex; max-width: 65%; }
.message.sent { align-self: flex-end; }
.message.received { align-self: flex-start; }
.msg-bubble { padding: 6px 8px 4px; border-radius: 8px; position: relative; min-width: 100px; word-wrap: break-word; box-shadow: 0 1px 0.5px rgba(0,0,0,0.13); }
.message.sent .msg-bubble { background: var(--bubble-out); border-top-right-radius: 0; }
.message.received .msg-bubble { background: var(--bubble-in); border-top-left-radius: 0; }
.msg-sender { font-size: 12px; color: var(--primary); font-weight: 600; margin-bottom: 2px; }
.msg-text { font-size: 14.2px; line-height: 1.4; padding-right: 50px; white-space: pre-wrap; }
.msg-meta { display: flex; align-items: center; justify-content: flex-end; gap: 4px; margin-top: -14px; float: right; position: relative; top: 8px; }
.msg-time { font-size: 11px; color: var(--text-secondary); }
.msg-status { font-size: 14px; color: var(--blue); }
.msg-image { max-width: 330px; border-radius: 6px; margin-bottom: 4px; cursor: pointer; }
.msg-image img { width: 100%; border-radius: 6px; }
.msg-reply { background: rgba(0,0,0,0.06); border-left: 4px solid var(--primary); border-radius: 4px; padding: 4px 8px; margin-bottom: 4px; font-size: 12px; cursor: pointer; }
.msg-reply .reply-name { font-weight: 600; color: var(--primary); }
.msg-reply .reply-text { color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-deleted { font-style: italic; color: var(--text-secondary); font-size: 13px; }
.msg-system { align-self: center; max-width: none; }
.msg-system .msg-bubble { background: rgba(255,255,255,0.9); border-radius: 8px; text-align: center; font-size: 12px; color: var(--text-secondary); padding: 4px 12px; box-shadow: none; }
.date-separator { text-align: center; margin: 10px 0; }
.date-separator span { background: rgba(255,255,255,0.9); padding: 4px 12px; border-radius: 8px; font-size: 12px; color: var(--text-secondary); box-shadow: 0 1px 0.5px rgba(0,0,0,0.13); }
.typing-indicator { font-size: 13px; color: var(--primary); font-style: italic; padding: 4px 16px; }

/* MESSAGE INPUT */
.message-input-area { display: flex; align-items: flex-end; padding: 8px 16px; background: var(--bg); gap: 8px; }
.msg-input-wrapper { flex: 1; display: flex; align-items: flex-end; background: var(--white); border-radius: 8px; padding: 4px 8px; min-height: 42px; }
.msg-input-wrapper .emoji-btn { width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; color: var(--text-secondary); font-size: 20px; }
.msg-input-wrapper textarea { flex: 1; border: none; outline: none; font-size: 15px; max-height: 120px; min-height: 20px; resize: none; padding: 8px; line-height: 1.4; }
.msg-input-wrapper .attach-btn { width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; color: var(--text-secondary); font-size: 20px; position: relative; }
.msg-input-wrapper .attach-btn input { position: absolute; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.send-btn { width: 48px; height: 48px; border-radius: 50%; background: var(--primary); color: var(--white); display: flex; align-items: center; justify-content: center; font-size: 20px; transition: background 0.2s; }
.send-btn:hover { background: var(--primary-dark); }
.reply-preview { display: flex; align-items: center; padding: 8px 16px; background: var(--bg); border-top: 1px solid var(--border); }
.reply-preview-content { flex: 1; background: var(--white); border-left: 4px solid var(--primary); border-radius: 4px; padding: 6px 10px; }
.reply-preview-close { width: 30px; height: 30px; display: flex; align-items: center; justify-content: center; color: var(--text-secondary); margin-left: 8px; }

/* EMPTY CHAT */
.empty-chat { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; background: var(--bg); }
.empty-chat i { font-size: 80px; color: var(--border); margin-bottom: 20px; }
.empty-chat h2 { font-size: 28px; font-weight: 300; color: var(--text); }
.empty-chat p { color: var(--text-secondary); margin-top: 10px; font-size: 14px; }

/* NEW CHAT PANEL */
.new-chat-panel { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: var(--white); z-index: 10; display: flex; flex-direction: column; }
.panel-header { display: flex; align-items: center; padding: 16px; background: var(--primary); color: var(--white); gap: 16px; }
.panel-header button { color: var(--white); font-size: 20px; }
.panel-header h3 { font-size: 18px; font-weight: 600; }
.user-list { flex: 1; overflow-y: auto; }
.user-item { display: flex; align-items: center; padding: 12px 16px; gap: 14px; cursor: pointer; transition: background 0.15s; }
.user-item:hover { background: var(--hover); }
.user-item-info h4 { font-size: 15px; font-weight: 500; }
.user-item-info p { font-size: 13px; color: var(--text-secondary); }

/* PROFILE PANEL */
.profile-panel { position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: var(--white); z-index: 10; display: flex; flex-direction: column; }
.profile-section { padding: 30px; text-align: center; background: var(--bg); }
.profile-avatar-large { width: 200px; height: 200px; border-radius: 50%; margin: 0 auto 20px; background: var(--primary); display: flex; align-items: center; justify-content: center; color: var(--white); font-size: 70px; font-weight: 600; overflow: hidden; }
.profile-avatar-large img { width: 100%; height: 100%; object-fit: cover; }
.profile-detail { padding: 20px; }
.profile-detail-item { padding: 14px 0; border-bottom: 1px solid var(--border); }
.profile-detail-item label { font-size: 12px; color: var(--primary); font-weight: 500; }
.profile-detail-item p { font-size: 15px; margin-top: 4px; }

/* CALL SCREEN */
.call-screen { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%); z-index: 100; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--white); }
.call-screen .call-avatar { width: 120px; height: 120px; border-radius: 50%; background: var(--primary); display: flex; align-items: center; justify-content: center; font-size: 48px; font-weight: 600; margin-bottom: 20px; overflow: hidden; }
.call-screen .call-avatar img { width: 100%; height: 100%; object-fit: cover; }
.call-screen .call-name { font-size: 28px; font-weight: 600; }
.call-screen .call-status { font-size: 16px; opacity: 0.7; margin-top: 8px; }
.call-actions { display: flex; gap: 30px; margin-top: 60px; }
.call-action-btn { width: 60px; height: 60px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 24px; color: var(--white); }
.call-action-btn.end { background: var(--danger); }
.call-action-btn.accept { background: var(--secondary); }
.call-action-btn.mute { background: rgba(255,255,255,0.2); }

/* ADMIN PANEL */
.admin-panel { padding: 20px; overflow-y: auto; flex: 1; }
.admin-panel h2 { margin-bottom: 20px; font-size: 20px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 30px; }
.stat-card { background: var(--white); border-radius: 12px; padding: 20px; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
.stat-card .stat-value { font-size: 32px; font-weight: 700; color: var(--primary); }
.stat-card .stat-label { font-size: 13px; color: var(--text-secondary); margin-top: 4px; }
.admin-users-table { width: 100%; border-collapse: collapse; background: var(--white); border-radius: 12px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
.admin-users-table th { background: var(--primary); color: var(--white); padding: 12px 16px; text-align: left; font-size: 13px; font-weight: 600; }
.admin-users-table td { padding: 10px 16px; border-bottom: 1px solid var(--border); font-size: 14px; }
.admin-users-table tr:hover td { background: var(--hover); }
.admin-btn { padding: 6px 14px; border-radius: 6px; font-size: 12px; font-weight: 600; }
.admin-btn.block { background: #ffeaea; color: var(--danger); }
.admin-btn.unblock { background: #e8f5e9; color: #2e7d32; }
.admin-btn.delete { background: var(--danger); color: var(--white); }

/* MODAL */
.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 50; display: flex; align-items: center; justify-content: center; }
.modal { background: var(--white); border-radius: 12px; padding: 24px; width: 440px; max-width: 90vw; max-height: 80vh; overflow-y: auto; }
.modal h3 { font-size: 18px; margin-bottom: 16px; }
.modal input, .modal textarea { width: 100%; padding: 10px 14px; border: 2px solid var(--border); border-radius: 8px; font-size: 14px; outline: none; margin-bottom: 12px; }
.modal input:focus, .modal textarea:focus { border-color: var(--primary); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.modal-actions button { padding: 10px 24px; border-radius: 8px; font-size: 14px; font-weight: 600; }
.modal-actions .cancel { color: var(--text-secondary); }
.modal-actions .confirm { background: var(--primary); color: var(--white); }

/* MOBILE */
@media (max-width: 768px) {
  .sidebar { width: 100%; min-width: 100%; }
  .chat-area { position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: 20; display: none; }
  .chat-area.mobile-show { display: flex; }
  .chat-header .back-btn { display: flex; }
  .messages-container { padding: 10px 16px; }
  .message { max-width: 85%; }
}
