/* ============================================================
   Baat — Chat UI
   Mobile-first dark theme
   ============================================================ */

:root {
    --bg:            #0b141a;   /* app background (deep navy) */
    --panel:         #111b21;   /* sidebar / headers */
    --panel-2:       #202c33;   /* inputs, hover */
    --panel-3:       #2a3942;   /* elevated */
    --line:          #22303a;   /* borders */
    --accent:        #00a884;   /* primary green */
    --accent-2:      #06cf9c;
    --accent-dark:   #008069;
    --bubble-me:     #005c4b;   /* my message */
    --bubble-them:   #202c33;   /* their message */
    --text:          #e9edef;
    --text-dim:      #8696a0;
    --text-dim2:     #667781;
    --tick-blue:     #53bdeb;
    --danger:        #f15c6d;
    --shadow:        0 6px 24px rgba(0,0,0,.35);
    --radius:        14px;

    --safe-top:    env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { margin: 0; padding: 0; box-sizing: border-box;
    font-family: 'Inter', 'Segoe UI', Roboto, system-ui, sans-serif;
    -webkit-tap-highlight-color: transparent; }

html, body { height: 100%; }
body {
    background: var(--bg); color: var(--text);
    overscroll-behavior: none;
}

/* hidden attribute + .hide class ko har jagah kaam karwane ke liye
   (display:flex/grid inhe override na kar sake) */
[hidden] { display: none !important; }
.hide    { display: none !important; }

/* ===================== Auth (login / register) ===================== */
.auth-body {
    display: flex; align-items: center; justify-content: center;
    min-height: 100vh; min-height: 100dvh; padding: 24px;
    background:
        radial-gradient(120% 90% at 50% -10%, #0f2a25 0%, var(--bg) 55%);
}
.auth-box {
    background: var(--panel); padding: 40px 30px 32px;
    border: 1px solid var(--line);
    border-radius: 20px; width: 360px; max-width: 100%;
    box-shadow: var(--shadow); text-align: center;
    animation: rise .5s cubic-bezier(.2,.8,.2,1) both;
}
@keyframes rise { from{opacity:0; transform:translateY(16px);} to{opacity:1; transform:none;} }
.auth-logo {
    width: 66px; height: 66px; margin: 0 auto 16px;
    display: grid; place-items: center; border-radius: 20px;
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
    color: #fff; box-shadow: 0 8px 22px rgba(0,168,132,.35);
}
.auth-box h2 { margin-bottom: 4px; font-size: 22px; font-weight: 700; }
.auth-box .sub { color: var(--text-dim); font-size: 14px; margin-bottom: 24px; }
.auth-box .field { position: relative; margin-bottom: 14px; }
.auth-box input {
    width: 100%; padding: 14px 16px; font-size: 15px; color: var(--text);
    border: 1px solid var(--line); border-radius: 12px;
    background: var(--panel-2); transition: border-color .18s, background .18s;
}
.auth-box input::placeholder { color: var(--text-dim2); }
.auth-box input:focus {
    outline: none; border-color: var(--accent); background: #16232b;
}
.auth-box button {
    width: 100%; padding: 14px; margin-top: 6px;
    background: var(--accent); color: #04231c;
    border: none; border-radius: 12px; font-size: 16px; font-weight: 700;
    cursor: pointer; transition: background .18s, transform .06s;
}
.auth-box button:hover { background: var(--accent-2); }
.auth-box button:active { transform: scale(.98); }
.switch { margin-top: 20px; font-size: 14px; color: var(--text-dim); }
.switch a { color: var(--accent-2); text-decoration: none; font-weight: 600; }
.error {
    color: #ffd7d7; background: rgba(241,92,109,.14);
    border: 1px solid rgba(241,92,109,.3);
    padding: 10px 12px; border-radius: 10px;
    margin-bottom: 16px; font-size: 13.5px;
}

/* ===================== App layout ===================== */
.app {
    display: flex; height: 100vh; height: 100dvh;
    overflow: hidden; max-width: 1500px; margin: 0 auto;
    background: var(--bg);
}

/* ===================== Avatar ===================== */
.avatar {
    width: 46px; height: 46px; border-radius: 50%;
    background: linear-gradient(135deg, #2a9d8f, #14746a);
    color: #fff; display: grid; place-items: center;
    font-weight: 600; font-size: 18px; flex-shrink: 0;
    text-transform: uppercase; user-select: none;
}

/* ===================== Sidebar ===================== */
.sidebar {
    width: 380px; background: var(--panel);
    border-right: 1px solid var(--line);
    display: flex; flex-direction: column; height: 100%;
    padding-top: var(--safe-top);
}
.sidebar-header {
    padding: 12px 16px; display: flex; align-items: center; gap: 12px;
    flex-shrink: 0; border-bottom: 1px solid var(--line);
}
.me-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.me-name { font-weight: 600; font-size: 16px; }
.me-status { font-size: 12px; color: var(--accent-2); }

.icon-round {
    width: 42px; height: 42px; border-radius: 50%;
    display: grid; place-items: center; color: var(--text-dim);
    background: transparent; border: none; cursor: pointer;
    text-decoration: none; transition: background .16s, color .16s;
}
.icon-round:hover { background: var(--panel-2); color: var(--text); }
.icon-round:active { transform: scale(.94); }

.search-wrap {
    position: relative; padding: 10px 12px; flex-shrink: 0;
}
.search-icon {
    position: absolute; left: 26px; top: 50%; transform: translateY(-50%);
    color: var(--text-dim2); pointer-events: none;
}
#searchInput {
    width: 100%; padding: 11px 14px 11px 42px; font-size: 14.5px;
    color: var(--text); background: var(--panel-2);
    border: 1px solid transparent; border-radius: 22px; outline: none;
    transition: border-color .18s;
}
#searchInput::placeholder { color: var(--text-dim2); }
#searchInput:focus { border-color: var(--accent); }

.user-list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.user-item {
    padding: 11px 16px; cursor: pointer; display: flex; gap: 14px;
    align-items: center; position: relative;
    transition: background .14s;
}
.user-item:hover { background: var(--panel-2); }
.user-item.active { background: var(--panel-2); }
.user-item .u-info { flex: 1; min-width: 0; }
.user-item .u-top {
    display: flex; justify-content: space-between; align-items: baseline; gap: 8px;
}
.user-item .name {
    font-weight: 500; font-size: 16px; color: var(--text);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-item .u-time { font-size: 12px; color: var(--text-dim2); flex-shrink: 0; }
.user-item.has-unread .u-time { color: var(--accent-2); }
.user-item .u-bottom {
    display: flex; justify-content: space-between; align-items: center;
    margin-top: 3px; gap: 8px;
}
.user-item .preview {
    font-size: 14px; color: var(--text-dim);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1;
}
.badge {
    background: var(--accent); color: #04231c; font-size: 12px; font-weight: 700;
    min-width: 20px; height: 20px; padding: 0 6px; border-radius: 12px;
    display: grid; place-items: center; flex-shrink: 0;
}
.loading { padding: 30px 20px; color: var(--text-dim2); text-align: center; font-size: 14px; }

/* ===================== Chat panel ===================== */
.chat {
    flex: 1; display: flex; flex-direction: column;
    height: 100%; min-width: 0; position: relative;
    background-color: #0b141a;
    background-image:
        linear-gradient(rgba(11,20,26,.94), rgba(11,20,26,.94)),
        url("data:image/svg+xml,%3Csvg width='80' height='80' viewBox='0 0 80 80' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='%23ffffff' fill-opacity='0.02'%3E%3Cpath d='M40 8c-4 6-10 8-14 14 4 3 10 4 14 8 4-4 10-5 14-8-4-6-10-8-14-14z'/%3E%3Ccircle cx='16' cy='60' r='4'/%3E%3Ccircle cx='64' cy='58' r='3'/%3E%3C/g%3E%3C/svg%3E");
}

.empty-state {
    flex: 1; display: flex; flex-direction: column;
    align-items: center; justify-content: center; text-align: center;
    color: var(--text-dim); padding: 30px; gap: 6px;
}
.empty-logo {
    width: 96px; height: 96px; border-radius: 50%;
    display: grid; place-items: center; margin-bottom: 14px;
    background: var(--panel); color: var(--accent);
    border: 1px solid var(--line);
}
.empty-state h2 { color: var(--text); font-weight: 600; font-size: 20px; }
.empty-state p { font-size: 14px; }

.chat-inner { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.chat-header {
    padding: 10px 12px; display: flex; align-items: center; gap: 10px;
    background: var(--panel); border-bottom: 1px solid var(--line);
    flex-shrink: 0; padding-top: calc(10px + var(--safe-top));
}
.chat-head-info { display: flex; flex-direction: column; min-width: 0; }
.chat-header #chatTitle { font-weight: 600; font-size: 16.5px; }
.chat-sub { font-size: 12.5px; color: var(--text-dim); }
.chat-sub.typing { color: var(--accent-2); }
.back-btn { display: none; }

/* ===================== Messages ===================== */
.messages {
    flex: 1; overflow-y: auto; padding: 16px 7% 10px;
    display: flex; flex-direction: column; gap: 3px;
    -webkit-overflow-scrolling: touch;
}
.day-sep {
    align-self: center; margin: 10px 0; padding: 5px 12px;
    background: var(--panel-3); color: var(--text-dim);
    font-size: 12px; border-radius: 8px;
}
.msg {
    max-width: 68%; padding: 6px 9px 7px; border-radius: 12px;
    position: relative; font-size: 14.7px; line-height: 1.4;
    box-shadow: 0 1px 1px rgba(0,0,0,.18);
    animation: pop .22s cubic-bezier(.2,.9,.3,1) both;
}
@keyframes pop { from{opacity:0; transform:translateY(6px) scale(.98);} to{opacity:1; transform:none;} }
.msg.them {
    background: var(--bubble-them); align-self: flex-start;
    border-top-left-radius: 4px;
}
.msg.me {
    background: var(--bubble-me); align-self: flex-end;
    border-top-right-radius: 4px;
}
.msg .text { word-wrap: break-word; white-space: pre-wrap; color: var(--text); }
.msg .meta {
    display: inline-flex; align-items: center; gap: 4px;
    float: right; margin: 6px 0 -2px 10px;
    font-size: 11px; color: rgba(233,237,239,.55);
    user-select: none;
}
.msg.me .meta { color: rgba(233,237,239,.6); }
.tick { display: inline-flex; }
.tick svg { width: 16px; height: 16px; }
.tick.read { color: var(--tick-blue); }

.msg audio {
    max-width: 240px; height: 42px; filter: invert(.92) hue-rotate(180deg);
    margin-top: 2px;
}
.msg .chat-img {
    max-width: 250px; width: 100%; border-radius: 10px; display: block;
    cursor: pointer; margin-bottom: 2px;
}
.msg.img-msg { padding: 4px; max-width: 260px; }
.msg.img-msg .meta {
    position: absolute; right: 10px; bottom: 8px; float: none; margin: 0;
    background: rgba(0,0,0,.4); padding: 2px 6px; border-radius: 8px;
    color: #fff;
}

/* typing dots bubble */
.msg.typing-bubble { padding: 12px 14px; }
.typing-dots { display: inline-flex; gap: 4px; }
.typing-dots span {
    width: 7px; height: 7px; border-radius: 50%; background: var(--text-dim);
    animation: blink 1.2s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: .2s; }
.typing-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%,60%,100%{opacity:.3;} 30%{opacity:1;} }

/* scroll-to-bottom */
.scroll-down {
    position: absolute; right: 16px; bottom: 84px; z-index: 5;
    width: 44px; height: 44px; border-radius: 50%;
    background: var(--panel-3); color: var(--text);
    border: 1px solid var(--line); cursor: pointer;
    display: grid; place-items: center; box-shadow: var(--shadow);
    animation: rise .2s both;
}

/* ===================== Input bar ===================== */
.input-bar {
    display: flex; align-items: center; gap: 6px;
    padding: 8px 10px; background: var(--panel);
    position: relative; flex-shrink: 0;
    padding-bottom: calc(8px + var(--safe-bottom));
}
.input-field {
    flex: 1; min-width: 0; background: var(--panel-2);
    border-radius: 22px; display: flex; align-items: center;
}
#messageInput {
    flex: 1; min-width: 0; padding: 12px 16px; border: none;
    font-size: 16px; outline: none; color: var(--text);
    background: transparent;
}
#messageInput::placeholder { color: var(--text-dim2); }
.icon-btn {
    background: none; border: none; cursor: pointer; flex-shrink: 0;
    width: 44px; height: 44px; border-radius: 50%;
    display: grid; place-items: center; color: var(--text-dim);
    transition: background .16s, color .16s;
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.icon-btn:active { transform: scale(.92); }

.send-btn {
    background: var(--accent); color: #04231c; border: none;
    width: 48px; height: 48px; border-radius: 50%;
    display: grid; place-items: center; cursor: pointer; flex-shrink: 0;
    transition: background .16s, transform .06s;
}
.send-btn:hover { background: var(--accent-2); }
.send-btn:active { transform: scale(.92); }
.send-btn .ic-send { display: none; }
.send-btn .ic-mic  { display: block; }
.send-btn.can-send .ic-send { display: block; }
.send-btn.can-send .ic-mic  { display: none; }

/* ===================== Emoji picker ===================== */
.emoji-picker {
    display: none; position: absolute; bottom: calc(66px + var(--safe-bottom)); left: 10px;
    background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
    padding: 12px; width: 320px; max-width: calc(100vw - 20px);
    max-height: 240px; overflow-y: auto;
    box-shadow: var(--shadow);
    grid-template-columns: repeat(8, 1fr); gap: 4px; z-index: 10;
}
.emoji-picker.show { display: grid; animation: rise .18s both; }
.emoji-picker span {
    font-size: 24px; text-align: center; cursor: pointer;
    padding: 5px; border-radius: 8px; transition: background .12s;
}
.emoji-picker span:hover { background: var(--panel-2); }

/* ===================== Recording bar ===================== */
.rec-bar {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 16px; background: var(--panel);
    position: absolute; left: 0; right: 0; bottom: 0; z-index: 12;
    padding-bottom: calc(10px + var(--safe-bottom));
    animation: rise .18s both;
}
.rec-dot {
    width: 12px; height: 12px; border-radius: 50%; background: var(--danger);
    animation: pulse 1s infinite;
}
@keyframes pulse { 0%,100%{opacity:1;} 50%{opacity:.3;} }
.rec-time { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--text); }
.rec-hint { flex: 1; color: var(--text-dim); font-size: 13px; }
.rec-cancel {
    background: none; border: none; color: var(--danger);
    font-size: 20px; cursor: pointer; width: 40px; height: 40px; border-radius: 50%;
}
.rec-cancel:hover { background: var(--panel-2); }
.rec-stop {
    background: var(--accent); color: #04231c; border: none;
    width: 46px; height: 46px; border-radius: 50%;
    display: grid; place-items: center; cursor: pointer;
}
.rec-stop:active { transform: scale(.92); }

/* ===================== Call button (header) ===================== */
.chat-header .call-btn { margin-left: 2px; }
.chat-header .call-btn:first-of-type { margin-left: auto; }

/* ===================== Call overlay ===================== */
.call-overlay {
    position: fixed; inset: 0; z-index: 200;
    background: linear-gradient(160deg, #0e2a24 0%, #0b141a 60%);
    display: flex; flex-direction: column; align-items: center;
    padding: calc(40px + var(--safe-top)) 20px calc(30px + var(--safe-bottom));
    color: var(--text); overflow: hidden;
    animation: rise .2s both;
}
.cv-remote-video {
    position: absolute; inset: 0; width: 100%; height: 100%;
    object-fit: cover; z-index: 0; background: #000;
}
.call-overlay.video-mode { background: #000; }

.cv-top {
    position: relative; z-index: 2; text-align: center;
    display: flex; flex-direction: column; align-items: center; gap: 8px;
    margin-top: 20px;
}
.cv-avatar {
    width: 110px; height: 110px; border-radius: 50%; font-size: 44px;
    box-shadow: 0 8px 30px rgba(0,0,0,.4);
}
.call-overlay.video-mode .cv-avatar { display: none; }
.cv-name   { font-size: 26px; font-weight: 600; }
.cv-status { font-size: 15px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.call-overlay.video-mode .cv-name,
.call-overlay.video-mode .cv-status {
    text-shadow: 0 1px 6px rgba(0,0,0,.7);
}

.cv-local-video {
    position: absolute; z-index: 3; top: calc(20px + var(--safe-top)); right: 16px;
    width: 100px; height: 140px; object-fit: cover;
    border-radius: 14px; border: 2px solid rgba(255,255,255,.5);
    box-shadow: var(--shadow); background: #111;
}

.cv-controls {
    position: relative; z-index: 2; margin-top: auto;
    display: flex; align-items: center; justify-content: center; gap: 26px;
}
.cv-btn {
    width: 66px; height: 66px; border-radius: 50%; border: none;
    display: grid; place-items: center; cursor: pointer; color: #fff;
    background: rgba(255,255,255,.18); transition: transform .08s, background .16s;
    position: relative;
}
.cv-btn:active { transform: scale(.92); }
.cv-btn.small  { width: 58px; height: 58px; background: rgba(255,255,255,.16); }
.cv-btn.small.off { background: #fff; color: #111; }
.cv-btn.accept { background: var(--accent); }
.cv-btn.reject, .cv-btn.hangup { background: var(--danger); }
.cv-btn .lbl {
    position: absolute; bottom: -22px; left: 50%; transform: translateX(-50%);
    font-size: 12px; color: var(--text-dim); white-space: nowrap;
}
.call-overlay.video-mode .cv-btn .lbl { color: rgba(255,255,255,.85); }

/* ===================== Image modal ===================== */
    display: none; position: fixed; inset: 0; z-index: 100;
    background: rgba(0,0,0,.94); align-items: center; justify-content: center;
    padding: env(safe-area-inset-top) 12px env(safe-area-inset-bottom);
}
.img-modal.show { display: flex; animation: rise .18s both; }
.img-modal img { max-width: 100%; max-height: 100%; border-radius: 8px; }
.img-close {
    position: absolute; top: calc(16px + var(--safe-top)); right: 18px;
    width: 44px; height: 44px; border-radius: 50%;
    background: rgba(255,255,255,.12); color: #fff; border: none;
    font-size: 22px; cursor: pointer;
}

/* ===================== Scrollbars ===================== */
.user-list::-webkit-scrollbar, .messages::-webkit-scrollbar,
.emoji-picker::-webkit-scrollbar { width: 7px; }
.user-list::-webkit-scrollbar-thumb, .messages::-webkit-scrollbar-thumb,
.emoji-picker::-webkit-scrollbar-thumb {
    background: var(--panel-3); border-radius: 4px;
}

/* ===================== Mobile ===================== */
@media (max-width: 820px) {
    .sidebar {
        width: 100%; position: absolute; inset: 0; z-index: 20;
        transition: transform .28s cubic-bezier(.2,.8,.2,1);
    }
    .app.chat-open .sidebar { transform: translateX(-24%); pointer-events: none; }
    .chat {
        position: absolute; inset: 0; z-index: 25;
        transform: translateX(100%);
        transition: transform .28s cubic-bezier(.2,.8,.2,1);
    }
    .app.chat-open .chat { transform: translateX(0); }
    .back-btn { display: grid; }
    .empty-state { display: none; }
    .messages { padding: 14px 4% 8px; }
    .msg { max-width: 82%; }
    .msg.img-msg, .msg audio { max-width: 78vw; }
    .emoji-picker { grid-template-columns: repeat(7, 1fr); }
    .avatar { width: 44px; height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
    * { animation: none !important; transition: none !important; }
}
