/* ===================== ChatApp - Mobile App Shell ===================== */
:root {
    --primary-dark: #075E54;
    --primary: #128C7E;
    --accent: #25D366;
    --bubble-sent: #DCF8C6;
    --bubble-received: #FFFFFF;
    --bg-chat: #ECE5DD;
    --bg-app: #F7F7F7;
    --text-dark: #111B21;
    --text-muted: #667781;
    --border: #E9EDEF;
    --danger: #E53935;
}

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

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: #d9d9d9;
    -webkit-tap-highlight-color: transparent;
}

/* Phone frame: centers app at mobile width on desktop, fills screen on real phones */
.phone-shell {
    max-width: 480px;
    min-height: 100vh;
    margin: 0 auto;
    background: var(--bg-app);
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 0 40px rgba(0,0,0,0.25);
}
@media (min-width: 481px) {
    body { display: flex; justify-content: center; padding: 20px 0; background: #4a4a4a; }
    .phone-shell { min-height: 90vh; max-height: 900px; border-radius: 28px; border: 8px solid #1a1a1a; }
}

/* ---------- Top App Bar ---------- */
.app-bar {
    background: var(--primary-dark);
    color: #fff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 14px;
    flex-shrink: 0;
    z-index: 10;
}
.app-bar h1 { font-size: 20px; font-weight: 600; flex: 1; }
.app-bar .icon-btn { color: #fff; font-size: 20px; background: none; border: none; cursor: pointer; padding: 4px; }
.app-bar.chat-bar { gap: 10px; }
.app-bar .avatar { width: 38px; height: 38px; border-radius: 50%; object-fit: cover; }
.app-bar .chat-info { flex: 1; min-width: 0; }
.app-bar .chat-info .name { font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-bar .chat-info .status { font-size: 12px; opacity: 0.85; }
.app-bar .actions { display: flex; gap: 18px; }

/* ---------- Bottom Nav ---------- */
.bottom-nav {
    display: flex;
    background: #fff;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}
.bottom-nav a {
    flex: 1;
    text-align: center;
    padding: 10px 0 8px;
    text-decoration: none;
    color: var(--text-muted);
    font-size: 11px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
}
.bottom-nav a.active { color: var(--primary); }
.bottom-nav .nav-icon { font-size: 21px; }

/* ---------- Main scroll area ---------- */
.app-body { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }

/* ---------- Chat list ---------- */
.chat-list-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    text-decoration: none;
    color: var(--text-dark);
    border-bottom: 1px solid #f0f0f0;
}
.chat-list-item:active { background: #f0f0f0; }
.chat-list-item .avatar { width: 50px; height: 50px; border-radius: 50%; object-fit: cover; flex-shrink: 0; background: #ccc; }
.chat-list-item .meta { flex: 1; min-width: 0; }
.chat-list-item .row1 { display: flex; justify-content: space-between; align-items: baseline; }
.chat-list-item .row1 .name { font-weight: 600; font-size: 16px; }
.chat-list-item .row1 .time { font-size: 12px; color: var(--text-muted); }
.chat-list-item .row2 { display: flex; justify-content: space-between; align-items: center; }
.chat-list-item .row2 .preview { font-size: 13.5px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 85%; }
.chat-list-item .unread-badge { background: var(--accent); color: #fff; font-size: 11px; border-radius: 50%; min-width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; padding: 0 5px; }

.fab {
    position: absolute;
    bottom: 78px;
    right: 18px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    border: none;
    font-size: 24px;
    box-shadow: 0 3px 8px rgba(0,0,0,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

/* ---------- Chat window ---------- */
.chat-window { background: var(--bg-chat); background-image: linear-gradient(rgba(255,255,255,0.4), rgba(255,255,255,0.4)); padding: 10px 10px 6px; display: flex; flex-direction: column; gap: 2px; }
.msg-row { display: flex; margin: 3px 0; }
.msg-row.sent { justify-content: flex-end; }
.msg-row.received { justify-content: flex-start; }
.bubble {
    max-width: 78%;
    padding: 6px 9px 7px;
    border-radius: 8px;
    font-size: 14.5px;
    line-height: 1.35;
    position: relative;
    box-shadow: 0 1px 1px rgba(0,0,0,0.08);
    word-wrap: break-word;
}
.sent .bubble { background: var(--bubble-sent); border-top-right-radius: 0; }
.received .bubble { background: var(--bubble-received); border-top-left-radius: 0; }
.bubble .msg-text { white-space: pre-wrap; }
.bubble .msg-meta { font-size: 10.5px; color: var(--text-muted); text-align: right; margin-top: 3px; display: flex; justify-content: flex-end; gap: 4px; align-items: center; }
.bubble .ticks.seen { color: #34B7F1; }
.bubble img.msg-media, .bubble video.msg-media { max-width: 100%; border-radius: 6px; display: block; margin-bottom: 3px; }
.bubble .doc-chip { display: flex; align-items: center; gap: 8px; background: rgba(0,0,0,0.04); padding: 8px; border-radius: 6px; margin-bottom: 3px; }
.bubble .doc-chip .doc-icon { font-size: 26px; }
.bubble .location-chip { border-radius: 6px; overflow: hidden; margin-bottom: 3px; }
.bubble .location-chip iframe { width: 220px; height: 130px; border: none; display: block; }
.bubble audio { width: 220px; }
.day-divider { text-align: center; margin: 10px 0; }
.day-divider span { background: #E1F3FB; color: #54656F; font-size: 12px; padding: 4px 10px; border-radius: 6px; }

/* ---------- Chat input bar ---------- */
.chat-input-bar {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    padding: 8px;
    background: #F0F0F0;
    flex-shrink: 0;
}
.chat-input-bar textarea {
    flex: 1;
    border: none;
    border-radius: 20px;
    padding: 10px 14px;
    font-size: 14.5px;
    resize: none;
    max-height: 90px;
    background: #fff;
    font-family: inherit;
}
.chat-input-bar textarea:focus { outline: none; }
.round-btn {
    width: 42px; height: 42px;
    border-radius: 50%;
    border: none;
    background: var(--primary);
    color: #fff;
    font-size: 18px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    cursor: pointer;
}
.icon-btn-flat { background: none; border: none; font-size: 22px; color: #54656F; padding: 8px; flex-shrink: 0; }

/* Attach menu */
.attach-menu {
    position: absolute;
    bottom: 60px;
    left: 10px;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    display: none;
    padding: 10px;
    gap: 12px;
    z-index: 20;
}
.attach-menu.open { display: grid; grid-template-columns: repeat(3, 1fr); }
.attach-menu button { background: none; border: none; display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 11px; color: var(--text-dark); padding: 6px; }
.attach-menu .circle { width: 46px; height: 46px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 20px; }

/* ---------- Auth screens ---------- */
.auth-screen { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: 30px 28px; background: #fff; }
.auth-screen .logo { font-size: 46px; text-align: center; margin-bottom: 6px; }
.auth-screen h2 { text-align: center; margin-bottom: 4px; color: var(--text-dark); }
.auth-screen p.subtitle { text-align: center; color: var(--text-muted); font-size: 13.5px; margin-bottom: 26px; }
.form-group { margin-bottom: 16px; }
.form-group label { font-size: 13px; color: var(--text-muted); display: block; margin-bottom: 5px; }
.form-group input { width: 100%; padding: 12px 14px; border: 1px solid var(--border); border-radius: 8px; font-size: 15px; }
.form-group input:focus { outline: none; border-color: var(--primary); }
.btn-primary { width: 100%; padding: 13px; background: var(--primary); color: #fff; border: none; border-radius: 8px; font-size: 15.5px; font-weight: 600; cursor: pointer; }
.btn-primary:active { background: var(--primary-dark); }
.auth-switch { text-align: center; margin-top: 18px; font-size: 13.5px; color: var(--text-muted); }
.auth-switch a { color: var(--primary); font-weight: 600; text-decoration: none; }
.error-msg { background: #FDECEA; color: var(--danger); padding: 10px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 14px; }

/* ---------- Contacts / lists ---------- */
.search-bar { padding: 8px 12px; background: #fff; }
.search-bar input { width: 100%; padding: 9px 14px; border-radius: 20px; border: 1px solid var(--border); background: #F0F0F0; font-size: 14px; }
.section-label { padding: 10px 14px 4px; font-size: 12.5px; color: var(--primary); font-weight: 600; }
.contact-row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid #f2f2f2; }
.contact-row .avatar { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; background: #ccc; }
.contact-row .name { font-weight: 600; font-size: 15px; }
.contact-row .sub { font-size: 12.5px; color: var(--text-muted); }
.contact-row .add-btn { margin-left: auto; background: none; border: 1px solid var(--primary); color: var(--primary); border-radius: 16px; padding: 5px 12px; font-size: 12.5px; }
.contact-row .chat-btn { margin-left: auto; color: var(--primary); font-size: 20px; background: none; border: none; }
.empty-state { text-align: center; padding: 60px 30px; color: var(--text-muted); }
.empty-state .big-icon { font-size: 50px; margin-bottom: 12px; }

/* ---------- Calls tab ---------- */
.call-row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid #f2f2f2; }
.call-row .avatar { width: 46px; height: 46px; border-radius: 50%; object-fit: cover; background: #ccc; }
.call-row .name { font-weight: 600; font-size: 15px; }
.call-row .detail { font-size: 12.5px; display: flex; align-items: center; gap: 4px; }
.call-row .detail.missed { color: var(--danger); }
.call-row .detail.ok { color: var(--text-muted); }
.call-row .call-icons { margin-left: auto; display: flex; gap: 18px; color: var(--primary); font-size: 19px; }

/* ---------- Profile ---------- */
.profile-header { background: var(--primary-dark); padding: 30px 20px; text-align: center; color: #fff; }
.profile-header .avatar-lg { width: 110px; height: 110px; border-radius: 50%; object-fit: cover; border: 3px solid #fff; }
.profile-header h2 { margin-top: 12px; }
.profile-list-item { display: flex; align-items: center; gap: 16px; padding: 16px 18px; border-bottom: 1px solid var(--border); background: #fff; }
.profile-list-item .label { font-size: 12px; color: var(--text-muted); }
.profile-list-item .value { font-size: 15.5px; }

/* ---------- Call screen (voice/video) ---------- */
.call-screen {
    flex: 1;
    background: linear-gradient(180deg, #075E54, #1a1a1a);
    display: flex;
    flex-direction: column;
    align-items: center;
    color: #fff;
    position: relative;
    overflow: hidden;
}
.call-screen video#remoteVideo { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }
.call-screen video#localVideo { position: absolute; top: 16px; right: 16px; width: 100px; height: 140px; border-radius: 10px; object-fit: cover; background: #000; box-shadow: 0 2px 8px rgba(0,0,0,0.5); z-index: 5; }
.call-screen .call-info { margin-top: 60px; text-align: center; z-index: 2; }
.call-screen .call-info .avatar-lg { width: 130px; height: 130px; border-radius: 50%; object-fit: cover; margin-bottom: 16px; border: 3px solid rgba(255,255,255,0.3); }
.call-screen .call-status { font-size: 14px; opacity: 0.85; margin-top: 6px; }
.call-controls { margin-top: auto; margin-bottom: 40px; display: flex; gap: 30px; z-index: 5; }
.call-controls button { width: 58px; height: 58px; border-radius: 50%; border: none; font-size: 22px; display: flex; align-items: center; justify-content: center; }
.call-controls .btn-mute, .call-controls .btn-video { background: rgba(255,255,255,0.2); color: #fff; }
.call-controls .btn-hangup { background: var(--danger); color: #fff; }
.call-controls .btn-hangup.large { width: 64px; height: 64px; font-size: 26px; }
.incoming-actions { display: flex; gap: 60px; margin-bottom: 50px; z-index: 5; }
.incoming-actions button { width: 62px; height: 62px; border-radius: 50%; border: none; font-size: 24px; color: #fff; }
.incoming-actions .accept { background: var(--accent); }
.incoming-actions .reject { background: var(--danger); }

/* Toast */
.toast { position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%); background: rgba(0,0,0,0.8); color: #fff; padding: 9px 18px; border-radius: 20px; font-size: 13px; z-index: 100; max-width: 480px; }

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.15); }
