/* ════════════════════════════════════════
   NexChat — Design System & Styles
════════════════════════════════════════ */

:root {
  --font: 'Plus Jakarta Sans', sans-serif;
  --font-display: 'Syne', sans-serif;
  --primary: #6C63FF;
  --primary-2: #A78BFA;
  --primary-glow: rgba(108,99,255,0.18);
  --bg: #F4F6FB;
  --bg-2: #FFFFFF;
  --sidebar-bg: #1A1730;
  --sidebar-text: #F0EEFF;
  --sidebar-muted: rgba(240,238,255,0.45);
  --sidebar-hover: rgba(255,255,255,0.07);
  --sidebar-active: rgba(108,99,255,0.25);
  --text: #1A1730;
  --text-2: #6B7280;
  --text-3: #9CA3AF;
  --border: #E5E7EB;
  --input-bg: #F9FAFB;
  --msg-out: #6C63FF;
  --msg-out-text: #FFFFFF;
  --msg-in: #FFFFFF;
  --msg-in-text: #1A1730;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 40px rgba(0,0,0,0.16);
  --transition: all 0.18s ease;
}

body.dark {
  --bg: #0F0E1A;
  --bg-2: #1A1730;
  --sidebar-bg: #0A0916;
  --text: #F0EEFF;
  --text-2: #9CA3AF;
  --text-3: #6B7280;
  --border: rgba(255,255,255,0.08);
  --input-bg: rgba(255,255,255,0.05);
  --msg-in: #252240;
  --msg-in-text: #F0EEFF;
  --shadow: 0 2px 12px rgba(0,0,0,0.3);
  --shadow-lg: 0 8px 40px rgba(0,0,0,0.4);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body { font-family: var(--font); background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
button { border: none; background: none; cursor: pointer; font-family: var(--font); }
input, textarea { font-family: var(--font); outline: none; border: none; background: none; }
a { text-decoration: none; color: inherit; }
.hidden { display: none !important; }

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.screen { position: fixed; inset: 0; z-index: 10; }

/* ── Buttons ── */
.btn { display: inline-flex; align-items: center; justify-content: center; padding: 10px 20px; border-radius: 12px; font-size: 0.9rem; font-weight: 600; transition: var(--transition); cursor: pointer; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-2); transform: translateY(-1px); box-shadow: 0 4px 16px var(--primary-glow); }
.btn-primary:active { transform: translateY(0); }
.btn-outline { background: transparent; border: 1.5px solid var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-full { width: 100%; }
.icon-btn { width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center; justify-content: center; color: var(--text-2); transition: var(--transition); flex-shrink: 0; }
.icon-btn:hover { background: var(--input-bg); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn.sidebar { color: var(--sidebar-muted); }
.icon-btn.sidebar:hover { background: var(--sidebar-hover); color: var(--sidebar-text); }

/* ── Inputs ── */
.input-wrap { display: flex; align-items: center; gap: 10px; background: var(--input-bg); border: 1.5px solid var(--border); border-radius: 12px; padding: 10px 14px; transition: var(--transition); }
.input-wrap:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-glow); }
.input-wrap svg { width: 16px; height: 16px; color: var(--text-3); flex-shrink: 0; }
.input-wrap input { flex: 1; font-size: 0.9rem; color: var(--text); background: transparent; }
.input-wrap input::placeholder { color: var(--text-3); }
.input-field { width: 100%; background: var(--input-bg); border: 1.5px solid var(--border); border-radius: 12px; padding: 10px 14px; font-size: 0.9rem; color: var(--text); transition: var(--transition); }
.input-field:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-glow); }
.input-field::placeholder { color: var(--text-3); }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-3); }
.form-error { color: #f87171; font-size: 0.82rem; font-weight: 500; }

/* ── Avatar ── */
.avatar { border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; color: #fff; flex-shrink: 0; font-family: var(--font-display); }
.avatar.sm { width: 38px; height: 38px; font-size: 0.85rem; }
.avatar.large { width: 64px; height: 64px; font-size: 1.3rem; position: relative; cursor: pointer; }
.avatar.editable:hover .avatar-edit-overlay { opacity: 1; }
.avatar-edit-overlay { position: absolute; inset: 0; border-radius: 50%; background: rgba(0,0,0,0.45); display: flex; align-items: center; justify-content: center; opacity: 0; transition: var(--transition); }
.avatar-edit-overlay svg { width: 20px; height: 20px; color: #fff; }
.chat-header-avatar { width: 38px; height: 38px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; color: #fff; font-size: 0.85rem; flex-shrink: 0; background: var(--primary); }

/* ── Lock icon ── */
.lock-icon-wrap { border-radius: 50%; display: flex; align-items: center; justify-content: center; background: var(--primary-glow); color: var(--primary); }
.lock-icon-wrap.large { width: 80px; height: 80px; }
.lock-icon-wrap.large svg { width: 36px; height: 36px; }
.lock-icon-wrap svg { width: 24px; height: 24px; }

/* ── AUTH ── */
.auth-container { display: flex; align-items: center; justify-content: center; min-height: 100%; background: linear-gradient(135deg, #0F0E1A 0%, #1A1730 50%, #0F0E1A 100%); padding: 20px; overflow-y: auto; }
.auth-card { width: 100%; max-width: 420px; background: rgba(255,255,255,0.04); border: 1px solid rgba(255,255,255,0.08); border-radius: 24px; padding: 36px; backdrop-filter: blur(20px); box-shadow: var(--shadow-lg); }
.auth-brand { text-align: center; margin-bottom: 28px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.auth-logo { width: 56px; height: 56px; }
.auth-logo svg { width: 100%; height: 100%; }
.auth-brand h1 { font-family: var(--font-display); font-size: 1.8rem; font-weight: 800; color: #fff; }
.auth-brand p { color: rgba(255,255,255,0.45); font-size: 0.88rem; }
.auth-tabs { display: flex; background: rgba(255,255,255,0.06); border-radius: 12px; padding: 4px; margin-bottom: 24px; gap: 4px; }
.auth-tab { flex: 1; padding: 9px; border-radius: 9px; font-size: 0.88rem; font-weight: 600; color: rgba(255,255,255,0.45); transition: var(--transition); }
.auth-tab.active { background: var(--primary); color: #fff; box-shadow: 0 2px 8px var(--primary-glow); }
.auth-form { display: flex; flex-direction: column; gap: 16px; }
.auth-form .input-wrap { background: rgba(255,255,255,0.06); border-color: rgba(255,255,255,0.1); }
.auth-form .input-wrap input { color: #fff; }
.auth-form .input-wrap input::placeholder { color: rgba(255,255,255,0.3); }
.auth-form .input-wrap svg { color: rgba(255,255,255,0.3); }
.auth-form .input-wrap:focus-within { border-color: var(--primary); }
.auth-form label { color: rgba(255,255,255,0.5); }
.auth-hint { text-align: center; font-size: 0.78rem; color: rgba(255,255,255,0.3); }

/* ── APP LAYOUT ── */
.app-layout { display: flex; height: 100vh; overflow: hidden; }

/* ── SIDEBAR ── */
.sidebar { width: 300px; min-width: 300px; background: var(--sidebar-bg); display: flex; flex-direction: column; height: 100%; overflow: hidden; }
.sidebar-header { display: flex; align-items: center; justify-content: space-between; padding: 18px 16px 14px; }
.sidebar-brand { display: flex; align-items: center; gap: 10px; }
.sidebar-logo { width: 32px; height: 32px; flex-shrink: 0; }
.sidebar-logo svg { width: 100%; height: 100%; }
.sidebar-app-name { font-family: var(--font-display); font-size: 1.1rem; font-weight: 800; color: var(--sidebar-text); }
.search-bar { display: flex; align-items: center; gap: 8px; background: rgba(255,255,255,0.07); border-radius: 12px; padding: 9px 14px; margin: 0 12px 12px; }
.search-bar svg { width: 15px; height: 15px; color: var(--sidebar-muted); flex-shrink: 0; }
.search-bar input { flex: 1; font-size: 0.85rem; color: var(--sidebar-text); background: transparent; }
.search-bar input::placeholder { color: var(--sidebar-muted); }
.chat-list { flex: 1; overflow-y: auto; padding: 4px 8px; }
.chat-item { display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: 14px; cursor: pointer; transition: var(--transition); }
.chat-item:hover { background: var(--sidebar-hover); }
.chat-item.active { background: var(--sidebar-active); }
.chat-item-info { flex: 1; min-width: 0; }
.chat-item-top { display: flex; align-items: center; justify-content: space-between; gap: 4px; }
.chat-item-name { font-size: 0.88rem; font-weight: 600; color: var(--sidebar-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item-time { font-size: 0.72rem; color: var(--sidebar-muted); flex-shrink: 0; }
.chat-item-preview { font-size: 0.78rem; color: var(--sidebar-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 4px; margin-top: 2px; }
.chat-item-lock { width: 11px; height: 11px; flex-shrink: 0; }
.sidebar-footer { padding: 12px; border-top: 1px solid rgba(255,255,255,0.06); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.user-profile-mini { display: flex; align-items: center; gap: 10px; cursor: pointer; flex: 1; min-width: 0; padding: 6px 8px; border-radius: 12px; transition: var(--transition); }
.user-profile-mini:hover { background: var(--sidebar-hover); }
.user-info-mini { display: flex; flex-direction: column; min-width: 0; }
.user-name-mini { font-size: 0.85rem; font-weight: 600; color: var(--sidebar-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-status { font-size: 0.72rem; color: #4ade80; }
.footer-actions { display: flex; gap: 2px; }

/* ── CHAT AREA ── */
.chat-area { flex: 1; display: flex; flex-direction: column; background: var(--bg); overflow: hidden; position: relative; }
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; gap: 16px; padding: 40px; text-align: center; }
.empty-icon { width: 120px; height: 120px; }
.empty-icon svg { width: 100%; height: 100%; }
.empty-state h3 { font-family: var(--font-display); font-size: 1.3rem; font-weight: 700; color: var(--text); }
.empty-state p { color: var(--text-2); font-size: 0.88rem; max-width: 280px; }
.chat-locked-state { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; gap: 16px; padding: 40px; text-align: center; }
.chat-locked-state h3 { font-family: var(--font-display); font-size: 1.2rem; font-weight: 700; color: var(--text); }
.chat-locked-state p { color: var(--text-2); font-size: 0.88rem; }
.chat-lock-input-wrap { display: flex; gap: 10px; width: 100%; max-width: 320px; }
.chat-lock-input-wrap input { flex: 1; background: var(--input-bg); border: 1.5px solid var(--border); border-radius: 12px; padding: 10px 14px; font-size: 0.9rem; color: var(--text); transition: var(--transition); }
.chat-lock-input-wrap input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-glow); }
.active-chat { display: flex; flex-direction: column; height: 100%; }
.chat-header { display: flex; align-items: center; gap: 12px; padding: 14px 20px; background: var(--bg-2); border-bottom: 1px solid var(--border); box-shadow: var(--shadow); }
.chat-header-info { flex: 1; min-width: 0; }
.chat-header-info h3 { font-size: 0.95rem; font-weight: 700; color: var(--text); }
.chat-header-info span { font-size: 0.75rem; color: #4ade80; }
.chat-header-actions { display: flex; gap: 4px; }
.back-btn { display: none; }
#chat-lock-btn.locked svg { color: var(--primary); }
.messages-container { flex: 1; overflow-y: auto; padding: 20px 20px 8px; display: flex; flex-direction: column; gap: 4px; }
.msg-date-divider { text-align: center; margin: 12px 0; }
.msg-date-divider span { font-size: 0.72rem; color: var(--text-3); background: var(--bg); padding: 3px 12px; border-radius: 20px; border: 1px solid var(--border); }
.msg-row { display: flex; }
.msg-row.out { justify-content: flex-end; }
.msg-row.in { justify-content: flex-start; }
.msg-bubble { max-width: 68%; padding: 10px 14px; border-radius: 18px; font-size: 0.9rem; line-height: 1.5; word-break: break-word; }
.msg-row.out .msg-bubble { background: var(--msg-out); color: var(--msg-out-text); border-bottom-right-radius: 4px; }
.msg-row.in .msg-bubble { background: var(--msg-in); color: var(--msg-in-text); border-bottom-left-radius: 4px; box-shadow: var(--shadow); }
.msg-meta { display: flex; align-items: center; gap: 4px; justify-content: flex-end; margin-top: 4px; }
.msg-time { font-size: 0.68rem; opacity: 0.65; }
.msg-status { font-size: 0.72rem; opacity: 0.8; }
.emoji-picker { position: absolute; bottom: 72px; left: 16px; background: var(--bg-2); border: 1px solid var(--border); border-radius: 16px; padding: 12px; display: flex; flex-wrap: wrap; gap: 4px; max-width: 320px; box-shadow: var(--shadow-lg); z-index: 50; max-height: 200px; overflow-y: auto; }
.emoji-btn-item { font-size: 1.3rem; width: 36px; height: 36px; border-radius: 8px; display: flex; align-items: center; justify-content: center; transition: var(--transition); }
.emoji-btn-item:hover { background: var(--input-bg); transform: scale(1.2); }
.message-input-area { display: flex; align-items: center; gap: 10px; padding: 12px 16px; background: var(--bg-2); border-top: 1px solid var(--border); }
.message-input-wrap { flex: 1; display: flex; align-items: center; gap: 8px; background: var(--input-bg); border: 1.5px solid var(--border); border-radius: 24px; padding: 8px 14px; transition: var(--transition); }
.message-input-wrap:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-glow); }
.emoji-btn { width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; color: var(--text-3); transition: var(--transition); flex-shrink: 0; }
.emoji-btn:hover { color: var(--primary); }
.emoji-btn svg { width: 20px; height: 20px; }
#message-input { flex: 1; font-size: 0.9rem; color: var(--text); background: transparent; }
#message-input::placeholder { color: var(--text-3); }
.send-btn { width: 42px; height: 42px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; transition: var(--transition); flex-shrink: 0; }
.send-btn:hover { background: var(--primary-2); transform: scale(1.05); box-shadow: 0 4px 12px var(--primary-glow); }
.send-btn svg { width: 18px; height: 18px; }

/* ── LOCK SCREEN ── */
.lock-screen { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%; background: var(--sidebar-bg); gap: 24px; padding: 40px; }
.lock-logo { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.lock-logo h2 { font-family: var(--font-display); font-size: 1.4rem; font-weight: 700; color: var(--sidebar-text); }
.lock-logo p { color: var(--sidebar-muted); font-size: 0.88rem; }
.pin-dots { display: flex; gap: 16px; }
.pin-dots span { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--sidebar-muted); transition: var(--transition); }
.pin-dots span.filled { background: var(--primary); border-color: var(--primary); transform: scale(1.1); }
.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; width: 240px; }
.pin-btn { height: 64px; border-radius: 16px; background: rgba(255,255,255,0.07); color: var(--sidebar-text); font-size: 1.4rem; font-weight: 600; transition: var(--transition); font-family: var(--font); }
.pin-btn:hover { background: rgba(108,99,255,0.25); color: #fff; }
.pin-btn:active { transform: scale(0.94); background: var(--primary); }
.pin-btn-empty { background: transparent !important; cursor: default; }
.pin-btn-del { font-size: 1.1rem; }
.pin-error { color: #f87171; font-size: 0.85rem; font-weight: 500; text-align: center; }

/* ── SETTINGS PANEL ── */
.panel { position: fixed; inset: 0; z-index: 200; display: flex; }
.panel-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.5); backdrop-filter: blur(4px); }
.panel-content { position: relative; z-index: 1; width: 420px; max-width: 100%; background: var(--bg-2); height: 100%; overflow-y: auto; box-shadow: var(--shadow-lg); margin-left: auto; display: flex; flex-direction: column; }
.panel-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--bg-2); z-index: 1; }
.panel-header h2 { font-family: var(--font-display); font-size: 1.2rem; font-weight: 700; color: var(--text); }
.settings-sections { padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.settings-section { background: var(--bg); border-radius: var(--radius); padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.settings-section-title { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-3); }
.profile-edit { display: flex; gap: 16px; align-items: flex-start; }
.profile-edit-fields { flex: 1; display: flex; flex-direction: column; gap: 12px; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.setting-info { display: flex; flex-direction: column; gap: 2px; }
.setting-label { font-size: 0.9rem; font-weight: 600; color: var(--text); }
.setting-desc { font-size: 0.78rem; color: var(--text-2); }

/* ── TOGGLE ── */
.toggle { position: relative; display: inline-block; width: 44px; height: 24px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; inset: 0; background: var(--border); border-radius: 24px; transition: var(--transition); cursor: pointer; }
.toggle-slider::before { content: ''; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: var(--transition); }
.toggle input:checked + .toggle-slider { background: var(--primary); }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); }

/* ── ICON & COLOR PICKERS ── */
.icon-picker { display: flex; gap: 10px; flex-wrap: wrap; }
.icon-option { width: 48px; height: 48px; border-radius: 14px; border: 2px solid transparent; padding: 4px; transition: var(--transition); }
.icon-option:hover { border-color: var(--primary); background: var(--primary-glow); }
.icon-option.active { border-color: var(--primary); background: var(--primary-glow); }
.icon-option svg { width: 100%; height: 100%; }
.theme-colors { display: flex; gap: 10px; flex-wrap: wrap; }
.color-swatch { width: 32px; height: 32px; border-radius: 50%; border: 3px solid transparent; transition: var(--transition); }
.color-swatch:hover { transform: scale(1.15); }
.color-swatch.active { border-color: var(--text); box-shadow: 0 0 0 2px var(--bg-2), 0 0 0 4px var(--text); }

/* ── MODALS ── */
.modal { position: fixed; inset: 0; z-index: 300; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.5); backdrop-filter: blur(4px); }
.modal-box { position: relative; z-index: 1; background: var(--bg-2); border-radius: var(--radius); padding: 24px; width: 100%; max-width: 400px; box-shadow: var(--shadow-lg); display: flex; flex-direction: column; gap: 16px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; }
.modal-header h3 { font-family: var(--font-display); font-size: 1.1rem; font-weight: 700; color: var(--text); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }
.contact-results { display: flex; flex-direction: column; gap: 4px; max-height: 300px; overflow-y: auto; }
.contact-item { display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: 12px; cursor: pointer; transition: var(--transition); }
.contact-item:hover { background: var(--input-bg); }
.contact-item-info { flex: 1; }
.contact-item-name { font-size: 0.9rem; font-weight: 600; color: var(--text); }
.contact-item-email { font-size: 0.78rem; color: var(--text-2); }

/* ── TOAST ── */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #1A1730; color: #fff; padding: 12px 24px; border-radius: 24px; font-size: 0.88rem; font-weight: 500; z-index: 9999; box-shadow: var(--shadow-lg); animation: toastIn 0.3s ease; }
@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(12px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }

/* ── RESPONSIVE ── */
@media (max-width: 768px) {
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 50; transform: translateX(-100%); transition: transform 0.3s ease; width: 280px; min-width: 280px; }
  .sidebar.open { transform: translateX(0); }
  .chat-area { width: 100%; }
  .back-btn { display: flex !important; }
  .panel-content { width: 100%; }
  .emoji-picker { left: 8px; right: 8px; max-width: none; }
}