/* ============================================================
   ZALO CLONE - CSS STYLESHEET
   ============================================================ */

/* --- RESET & BASE --- */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --primary: #0068ff;
    --primary-dark: #0050cc;
    --primary-light: #e5efff;
    --bg: #e8ecf1;
    --surface: #ffffff;
    --text: #1a1a2e;
    --text-muted: #8b8fa3;
    --border: #e4e6eb;
    --danger: #ff3b30;
    --success: #28a745;
    --warning: #f0ad4e;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 2px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
    --font: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    overflow: hidden;
    height: 100vh;
}

input[type="text"], input[type="password"] {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-family: var(--font);
    transition: border-color 0.2s;
    outline: none;
}
input[type="text"]:focus, input[type="password"]:focus {
    border-color: var(--primary);
}

/* ============================================================
   LOGIN SCREEN
   ============================================================ */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #0068ff 0%, #00c6ff 100%);
    padding: 20px;
}

.login-box {
    background: var(--surface);
    padding: 40px 35px;
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 420px;
    text-align: center;
}

.login-logo {
    width: 70px; height: 70px;
    background: var(--primary);
    border-radius: 20px;
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 15px;
    font-size: 30px; color: white;
}

.login-title {
    font-size: 28px; font-weight: 700; color: var(--primary); margin-bottom: 5px;
}
.login-subtitle {
    color: var(--text-muted); font-size: 14px; margin-bottom: 25px;
}

.auth-tabs {
    display: flex; gap: 0; margin-bottom: 25px;
    background: #f1f3f5; border-radius: var(--radius-sm); overflow: hidden;
}
.auth-tab {
    flex: 1; padding: 10px; border: none; background: transparent;
    font-weight: 600; font-size: 14px; color: var(--text-muted); cursor: pointer;
    transition: all 0.2s; font-family: var(--font);
}
.auth-tab.active {
    background: var(--primary); color: white; border-radius: var(--radius-sm);
}

.auth-form { display: none; }
.auth-form.active { display: flex; flex-direction: column; gap: 12px; }

.btn-primary, .btn-success {
    width: 100%; padding: 12px; border: none; border-radius: var(--radius-sm);
    font-weight: 700; font-size: 15px; cursor: pointer; transition: all 0.2s;
    font-family: var(--font);
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #229b3b; }

/* ============================================================
   MAIN APP LAYOUT
   ============================================================ */
.main-app {
    display: flex;
    height: 100vh;
    max-width: 1400px;
    margin: 0 auto;
    background: var(--surface);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

/* --- SIDEBAR --- */
.sidebar {
    width: 340px;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    background: var(--surface);
    flex-shrink: 0;
}

.user-header {
    height: 64px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
}

.user-info-header {
    display: flex; align-items: center; gap: 10px; position: relative;
}

.avatar-circle {
    width: 42px; height: 42px; border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), #00c6ff);
    display: flex; align-items: center; justify-content: center;
    color: white; font-weight: 700; font-size: 16px;
    flex-shrink: 0; position: relative; overflow: hidden;
}
.avatar-circle.small { width: 36px; height: 36px; font-size: 14px; }

.avatar-img {
    width: 100%; height: 100%; object-fit: cover; border-radius: 50%;
    position: absolute; top: 0; left: 0;
}

.avatar-edit {
    position: absolute; bottom: -2px; right: -2px; z-index: 2;
    background: var(--primary); color: white; border-radius: 50%;
    width: 20px; height: 20px;
    display: flex; align-items: center; justify-content: center;
    font-size: 9px; cursor: pointer; border: 2px solid white;
}
.avatar-edit:hover { background: var(--primary-dark); }

.user-name {
    font-weight: 600; font-size: 15px; color: var(--text);
}

.logout-btn {
    background: none; border: none; color: var(--danger);
    font-size: 18px; cursor: pointer; padding: 8px;
    border-radius: 50%; transition: background 0.2s;
}
.logout-btn:hover { background: #fff0f0; }

/* --- Add Friend Area --- */
.add-friend-area {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    display: flex;
    gap: 8px;
}
.add-friend-area input {
    flex: 1; padding: 8px 12px; font-size: 13px;
    border: 1px solid var(--border); border-radius: 20px;
}
.add-friend-area button {
    background: var(--primary); color: white; border: none;
    border-radius: 50%; width: 36px; height: 36px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; flex-shrink: 0;
}

/* --- Search Result --- */
#search-result {
    padding: 0 12px;
}
.search-result-box {
    margin: 8px 0;
    padding: 10px 12px;
    background: #f8f9fa;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: space-between;
    animation: slideDown 0.2s ease;
}
.search-result-info {
    display: flex; align-items: center; gap: 10px;
}
.search-result-name { font-weight: 600; font-size: 14px; }

.btn-action-sm {
    padding: 5px 12px; border-radius: 15px;
    font-size: 12px; font-weight: 600; cursor: pointer;
    border: 1px solid var(--primary); background: var(--primary-light);
    color: var(--primary); transition: all 0.2s;
}
.btn-action-sm:hover { background: var(--primary); color: white; }
.btn-action-sm.accept { background: var(--success); color: white; border-color: var(--success); }
.btn-action-sm.deny { background: var(--danger); color: white; border-color: var(--danger); }

.status-badge { font-size: 11px; color: var(--success); font-weight: 600; }
.status-badge.pending { color: var(--text-muted); font-style: italic; }

/* --- Friend Requests --- */
#friend-requests-section {
    background: #fffbeb; border-bottom: 1px solid #fde68a;
    max-height: 160px; overflow-y: auto;
}
.req-header {
    padding: 8px 14px; font-size: 11px; font-weight: 700;
    color: var(--warning); text-transform: uppercase; letter-spacing: 0.5px;
}
.req-item {
    padding: 8px 14px;
    display: flex; align-items: center; gap: 10px;
    border-bottom: 1px solid #fef3c7;
}
.req-item-name { flex: 1; font-weight: 600; font-size: 13px; }
.req-actions { display: flex; gap: 5px; }
.req-btn {
    padding: 4px 10px; border: none; border-radius: 4px;
    font-size: 11px; font-weight: 600; cursor: pointer;
}
.req-btn.accept { background: var(--success); color: white; }
.req-btn.deny { background: var(--danger); color: white; }

/* --- Friend List --- */
.friend-list {
    flex: 1; overflow-y: auto;
}
.empty-friends {
    text-align: center; padding: 40px 20px; color: var(--text-muted);
}
.empty-friends i { font-size: 40px; margin-bottom: 10px; opacity: 0.3; }
.empty-friends p { font-size: 14px; }

.friend-item {
    padding: 12px 14px;
    display: flex; align-items: center;
    cursor: pointer; transition: background 0.15s;
    border-bottom: 1px solid #f5f5f5;
    position: relative;
}
.friend-item:hover { background: #f7f8fa; }
.friend-item.active { background: var(--primary-light); border-left: 3px solid var(--primary); }

.friend-item .friend-info { flex: 1; margin-left: 12px; min-width: 0; }
.friend-item .friend-name { font-weight: 600; font-size: 14px; display: block; }
.friend-item .friend-last-msg {
    font-size: 12px; color: var(--text-muted);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    display: block; max-width: 180px;
}
.friend-item .friend-meta {
    display: flex; flex-direction: column; align-items: flex-end; gap: 4px;
}
.friend-item .friend-time { font-size: 11px; color: var(--text-muted); }

.badge-notify {
    background: var(--danger);
    color: white; font-size: 11px; font-weight: 700;
    padding: 2px 7px; border-radius: 10px;
    min-width: 20px; text-align: center;
}

.online-dot {
    position: absolute; bottom: 0; right: 0;
    width: 12px; height: 12px; border-radius: 50%;
    background: var(--success); border: 2px solid white;
}

/* ============================================================
   CHAT AREA
   ============================================================ */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #e8ecf1;
    height: 100vh;
    overflow: hidden;
    position: relative;
}

.chat-placeholder {
    flex: 1;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    color: var(--text-muted);
}
.chat-placeholder i { font-size: 60px; margin-bottom: 15px; opacity: 0.2; }
.chat-placeholder h3 { font-weight: 400; font-size: 16px; }

#active-chat {
    display: flex; flex-direction: column; height: 100%;
}

/* Chat Header */
.chat-header {
    height: 64px; background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center;
    padding: 0 16px; flex-shrink: 0;
}
.chat-partner-info {
    display: flex; align-items: center; gap: 10px; flex: 1;
}
.chat-partner-info > div:last-child { display: flex; flex-direction: column; }
#partner-name { font-weight: 600; font-size: 15px; }
.online-status { font-size: 11px; color: var(--success); }

.chat-actions button {
    background: none; border: none; color: var(--primary);
    font-size: 18px; cursor: pointer; padding: 8px 10px;
    border-radius: 50%; transition: background 0.2s;
}
.chat-actions button:hover { background: var(--primary-light); }

.btn-mobile-back {
    display: none;
    background: none; border: none; font-size: 18px;
    color: var(--text); cursor: pointer; padding: 8px;
    margin-right: 8px;
}

/* Messages Container */
.messages-container {
    flex: 1;
    padding: 16px 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* Message Bubbles */
.msg-row { display: flex; width: 100%; }
.msg-row.right { justify-content: flex-end; }
.msg-row.left { justify-content: flex-start; }

.msg-bubble {
    max-width: 65%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.msg-row.right .msg-bubble {
    background: var(--primary-light);
    color: var(--text);
    border-bottom-right-radius: 4px;
}
.msg-row.left .msg-bubble {
    background: var(--surface);
    color: var(--text);
    border-bottom-left-radius: 4px;
}

.msg-time {
    font-size: 10px; color: var(--text-muted);
    margin-top: 4px; text-align: right;
}

/* Media in Messages */
.msg-image {
    max-width: 220px; max-height: 220px;
    border-radius: var(--radius-sm); cursor: zoom-in;
    display: block;
}
.msg-image:hover { opacity: 0.9; }

.msg-video {
    max-width: 300px; max-height: 250px;
    border-radius: var(--radius-sm); background: #000;
    display: block;
}

.msg-audio { max-width: 260px; height: 42px; }

.msg-sticker { width: 120px; display: block; }
.msg-gif { max-width: 250px; border-radius: var(--radius-sm); display: block; }

.msg-file-box {
    display: flex; align-items: center;
    padding: 10px 12px; background: rgba(0,0,0,0.04);
    border-radius: var(--radius-sm); text-decoration: none;
    color: var(--text); min-width: 200px;
    border: 1px solid rgba(0,0,0,0.08);
}
.msg-file-box:hover { background: rgba(0,0,0,0.07); }
.msg-file-box .file-icon { font-size: 22px; color: var(--primary); margin-right: 10px; }
.msg-file-box .file-name { font-size: 13px; word-break: break-all; }
.msg-file-box .file-hint { font-size: 10px; color: var(--text-muted); }

/* YouTube Embed */
.msg-youtube {
    width: 300px; max-width: 100%; border-radius: var(--radius-sm);
    overflow: hidden; background: #000;
}
.msg-youtube .yt-wrapper {
    position: relative; padding-bottom: 56.25%; height: 0;
}
.msg-youtube .yt-wrapper iframe {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: 0;
}
.msg-youtube .yt-link {
    padding: 5px 10px; font-size: 11px;
}
.msg-youtube .yt-link a { color: var(--primary); text-decoration: none; }

/* Google Meet */
.msg-meet-box {
    text-align: center; padding: 15px;
    background: #e0f2f1; border-radius: var(--radius-sm);
    min-width: 200px;
}
.msg-meet-box .meet-icon { font-size: 28px; color: #00796b; margin-bottom: 5px; }
.msg-meet-box .meet-title { font-weight: 700; margin-bottom: 3px; }
.msg-meet-box .meet-desc { font-size: 12px; color: var(--text-muted); margin-bottom: 10px; }
.btn-join-meet {
    background: #00796b; color: white; border: none;
    padding: 7px 18px; border-radius: 20px; font-weight: 700;
    cursor: pointer; font-size: 13px;
}
.btn-join-meet:hover { background: #00695c; }

/* ============================================================
   MEDIA PANEL (Emoji/Sticker/GIF)
   ============================================================ */
.media-panel {
    position: absolute; bottom: 70px; left: 16px;
    width: 360px; height: 320px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    display: flex; flex-direction: column;
    z-index: 100;
    animation: slideUp 0.2s ease;
}

.picker-tabs {
    display: flex; border-bottom: 1px solid var(--border);
}
.picker-tab {
    flex: 1; padding: 10px; text-align: center;
    cursor: pointer; font-weight: 600; font-size: 13px;
    color: var(--text-muted); background: none; border: none;
    border-bottom: 2px solid transparent; transition: all 0.2s;
    font-family: var(--font);
}
.picker-tab:hover, .picker-tab.active {
    color: var(--primary); border-bottom-color: var(--primary);
}

.picker-content { flex: 1; overflow-y: auto; padding: 10px; }
.panel-section { display: none; }
.panel-section.active { display: block; }

.emoji-grid {
    display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px;
}
.emoji-item {
    font-size: 22px; text-align: center; cursor: pointer;
    padding: 4px; border-radius: 4px; transition: background 0.15s;
}
.emoji-item:hover { background: #f1f1f1; }

.sticker-grid {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px;
}
.sticker-item {
    width: 100%; cursor: pointer; transition: transform 0.2s; border-radius: 4px;
}
.sticker-item:hover { transform: scale(1.08); }

.gif-search { display: flex; gap: 5px; margin-bottom: 8px; }
.gif-search input { flex: 1; padding: 6px 10px; font-size: 13px; border: 1px solid var(--border); border-radius: 20px; }
.gif-search button {
    background: var(--primary); color: white; border: none;
    border-radius: 50%; width: 30px; height: 30px; cursor: pointer;
    font-size: 12px;
}
.gif-grid {
    display: grid; grid-template-columns: repeat(2, 1fr); gap: 5px;
}
.gif-item {
    width: 100%; height: 100px; object-fit: cover;
    cursor: pointer; border-radius: 4px;
}

/* ============================================================
   INPUT AREA
   ============================================================ */
.input-area {
    height: 64px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 12px;
    gap: 6px;
    flex-shrink: 0;
}

.input-btn {
    background: none; border: none;
    color: var(--primary); font-size: 20px;
    cursor: pointer; padding: 8px;
    border-radius: 50%; transition: background 0.2s;
    display: flex; align-items: center; justify-content: center;
}
.input-btn:hover { background: var(--primary-light); }

#msg-input {
    flex: 1; border: 1px solid var(--border);
    border-radius: 20px; padding: 10px 16px;
    font-size: 14px; background: #f4f5f7;
    outline: none;
}
#msg-input:focus { border-color: var(--primary); background: white; }

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

/* Recording Active */
.recording-active {
    color: var(--danger) !important;
    animation: pulse-red 1.5s infinite;
    background: #ffe5e5 !important;
}
@keyframes pulse-red {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255,59,48,0.7); }
    70% { transform: scale(1.1); box-shadow: 0 0 0 10px rgba(255,59,48,0); }
    100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(255,59,48,0); }
}

/* ============================================================
   DRAG & DROP OVERLAY
   ============================================================ */
.chat-area.drag-active::after {
    content: 'Thả file vào đây để gửi';
    position: absolute; top: 0; left: 0;
    width: 100%; height: 100%;
    background: rgba(0,104,255,0.85);
    color: white; font-size: 22px; font-weight: 700;
    display: flex; align-items: center; justify-content: center;
    z-index: 9999;
    border: 4px dashed white;
    box-sizing: border-box;
    pointer-events: none;
}

/* ============================================================
   MODALS
   ============================================================ */
.modal-overlay {
    position: fixed; top: 0; left: 0;
    width: 100vw; height: 100vh;
    background: rgba(0,0,0,0.9);
    display: flex; align-items: center; justify-content: center;
    z-index: 10000;
}
.modal-close {
    position: absolute; top: 20px; right: 25px;
    background: none; border: none; color: white;
    font-size: 28px; cursor: pointer; z-index: 10001;
    opacity: 0.7;
}
.modal-close:hover { opacity: 1; transform: scale(1.1); }

#modal-image {
    max-width: 95vw; max-height: 95vh; object-fit: contain;
    box-shadow: 0 0 30px rgba(0,0,0,0.5);
}

/* Meet Dialog */
.meet-dialog {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 30px;
    max-width: 450px; width: 90%;
    text-align: center;
}
.meet-dialog h3 { margin-bottom: 20px; color: #00796b; }
.meet-steps { text-align: left; margin: 15px 0; }
.meet-steps p { margin-bottom: 10px; }
.meet-steps hr { margin: 15px 0; border-color: var(--border); }
.meet-steps input { margin-top: 5px; }
.btn-meet-create {
    display: inline-block; background: var(--warning); color: white;
    padding: 10px 20px; border-radius: var(--radius-sm);
    text-decoration: none; font-weight: 700;
}
.meet-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }
.btn-cancel {
    padding: 10px 20px; border: 1px solid var(--border);
    border-radius: var(--radius-sm); background: white;
    cursor: pointer; font-weight: 600; font-family: var(--font);
}

/* ============================================================
   TOAST NOTIFICATIONS
   ============================================================ */
#toast-container {
    position: fixed; top: 20px; right: 20px; z-index: 99999;
    display: flex; flex-direction: column; gap: 8px;
}
.toast {
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    color: white; font-size: 14px; font-weight: 500;
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s ease, fadeOut 0.3s 2.7s ease forwards;
    max-width: 350px;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: var(--primary); }
.toast.warning { background: var(--warning); }

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes slideDown { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes slideIn { from { opacity: 0; transform: translateX(60px); } to { opacity: 1; transform: translateX(0); } }
@keyframes fadeOut { to { opacity: 0; transform: translateX(60px); } }

/* ============================================================
   RESPONSIVE MOBILE
   ============================================================ */
@media (max-width: 768px) {
    .login-container { padding: 10px; }
    .login-box { padding: 25px 20px; }

    .main-app { height: 100vh; max-width: 100%; }

    .sidebar { width: 100% !important; }
    .chat-area { display: none !important; width: 100% !important; }

    .main-app.mobile-chat-active .sidebar { display: none !important; }
    .main-app.mobile-chat-active .chat-area { display: flex !important; }

    .btn-mobile-back { display: inline-block !important; }

    .chat-header { padding-left: 8px; }
    .input-area { padding: 0 8px; }
    .messages-container { padding: 10px; }

    .media-panel { width: calc(100vw - 32px); left: 8px; }
    .msg-bubble { max-width: 80%; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c4c4c4; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #aaa; }
