/* ══════════════════════════════════════════════════════════════════════════
   WhatsApp Cloud Panel — UI
   Desktop = WhatsApp Web jaisa, mobile = WhatsApp app jaisa.
   Light + dark dono themes, system preference ya manual toggle se.
   ══════════════════════════════════════════════════════════════════════════ */

:root {
    /* Brand */
    --accent:        #00a884;
    --accent-strong: #008069;
    --accent-ink:    #ffffff;
    --tick-read:     #53bdeb;

    /* Surfaces */
    --bg:            #f0f2f5;
    --panel:         #ffffff;
    --panel-header:  #f0f2f5;
    --panel-hover:   #f5f6f6;
    --panel-active:  #f0f2f5;
    --chat-bg:       #efeae2;
    --bubble-in:     #ffffff;
    --bubble-out:    #d9fdd3;
    --overlay:       rgba(11, 20, 26, .5);
    --composer:      #f0f2f5;
    --input:         #ffffff;

    /* Ink */
    --text:          #111b21;
    --text-muted:    #667781;
    --text-faint:    #8696a0;
    --icon:          #54656f;
    --divider:       #e9edef;
    --danger:        #ea0038;

    --shadow-sm: 0 1px .5px rgba(11, 20, 26, .13);
    --shadow-md: 0 2px 5px rgba(11, 20, 26, .16);
    --shadow-lg: 0 12px 40px rgba(11, 20, 26, .22);

    --header-h: 60px;
    --radius:   7.5px;
}

:root[data-theme="dark"] {
    --accent:        #00a884;
    --accent-strong: #00a884;
    --accent-ink:    #111b21;

    --bg:            #0b141a;
    --panel:         #111b21;
    --panel-header:  #202c33;
    --panel-hover:   #202c33;
    --panel-active:  #2a3942;
    --chat-bg:       #0b141a;
    --bubble-in:     #202c33;
    --bubble-out:    #005c4b;
    --overlay:       rgba(0, 0, 0, .7);
    --composer:      #202c33;
    --input:         #2a3942;

    --text:          #e9edef;
    --text-muted:    #8696a0;
    --text-faint:    #8696a0;
    --icon:          #aebac1;
    --divider:       #222d34;

    --shadow-sm: 0 1px .5px rgba(0, 0, 0, .3);
    --shadow-md: 0 2px 5px rgba(0, 0, 0, .4);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, .6);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
    margin: 0; height: 100%; overflow: hidden;
    font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Helvetica, Arial, sans-serif;
    font-size: 14.5px; line-height: 1.45;
    color: var(--text); background: var(--bg);
    -webkit-font-smoothing: antialiased;
}
body { overscroll-behavior: none; }

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
a { color: var(--accent-strong); }
:root[data-theme="dark"] a { color: #53bdeb; }

.svg-sprite { display: none; }
.icon { width: 24px; height: 24px; fill: currentColor; flex: 0 0 auto; display: block; }
.icon.sm { width: 18px; height: 18px; }
.icon.xs { width: 15px; height: 15px; }
.hidden { display: none !important; }

/* Scrollbars — WhatsApp jaisi patli */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(11, 20, 26, .2); border-radius: 3px; }
:root[data-theme="dark"] ::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .16); }

/* ══ Buttons ══════════════════════════════════════════════════════════════ */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px 22px; border-radius: 24px;
    background: var(--accent); color: var(--accent-ink);
    font-size: 15px; font-weight: 500; transition: background .15s, opacity .15s;
}
.btn:hover:not(:disabled) { background: var(--accent-strong); }
:root[data-theme="dark"] .btn:hover:not(:disabled) { opacity: .88; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.block { width: 100%; }
.btn.small { padding: 7px 16px; font-size: 13.5px; }
.btn.ghost {
    background: transparent; color: var(--accent-strong);
    border: 1px solid var(--divider);
}
.btn.ghost:hover:not(:disabled) { background: var(--panel-hover); }
:root[data-theme="dark"] .btn.ghost { color: var(--text); }
.btn.danger { background: var(--danger); color: #fff; }
.btn.danger:hover:not(:disabled) { background: #c30030; }

.icon-btn {
    width: 40px; height: 40px; border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    color: var(--icon); transition: background .15s;
}
.icon-btn:hover { background: rgba(11, 20, 26, .06); }
:root[data-theme="dark"] .icon-btn:hover { background: rgba(255, 255, 255, .08); }
.icon-btn:disabled { opacity: .38; cursor: not-allowed; }
.icon-btn:disabled:hover { background: none; }

/* ══ Forms ════════════════════════════════════════════════════════════════ */
.field { margin-bottom: 18px; }
.field label {
    display: block; font-size: 12.5px; font-weight: 500;
    color: var(--accent-strong); margin-bottom: 6px;
}
:root[data-theme="dark"] .field label { color: var(--accent); }
.field input, .field select, .field textarea {
    width: 100%; padding: 9px 2px; border: none;
    border-bottom: 2px solid var(--divider);
    background: transparent; outline: none; color: var(--text);
    transition: border-color .15s;
}
.field input:focus, .field select:focus, .field textarea:focus { border-bottom-color: var(--accent); }
.field .help { font-size: 12px; color: var(--text-muted); margin-top: 5px; }

.alert {
    padding: 11px 14px; border-radius: 8px; font-size: 13.5px; margin-bottom: 16px;
    background: #fdeaea; color: #b3182f; border: 1px solid #f6cdd2;
}
.alert.ok { background: #e7f8ef; color: #06795c; border-color: #b6e8d3; }
:root[data-theme="dark"] .alert    { background: #3b1d24; color: #ff8fa3; border-color: #5c2a35; }
:root[data-theme="dark"] .alert.ok { background: #10322a; color: #7ee2c0; border-color: #1d5347; }

/* ══ Login ════════════════════════════════════════════════════════════════ */
.login-wrap {
    height: 100%; overflow-y: auto; padding: 24px;
    display: flex; align-items: center; justify-content: center;
    background: var(--bg);
}
.login-wrap::before {
    content: ''; position: fixed; top: 0; left: 0; right: 0; height: 222px;
    background: var(--accent-strong); z-index: 0;
}
.login-card {
    position: relative; z-index: 1;
    width: 100%; max-width: 420px; background: var(--panel);
    border-radius: 3px; padding: 40px 36px; box-shadow: var(--shadow-md);
}
.login-brand {
    display: flex; align-items: center; gap: 12px; margin-bottom: 28px;
    color: var(--text);
}
.login-brand .mark {
    width: 42px; height: 42px; border-radius: 50%; background: var(--accent);
    display: flex; align-items: center; justify-content: center; color: #fff;
}
.login-brand h1 { margin: 0; font-size: 19px; font-weight: 600; }
.login-brand p  { margin: 2px 0 0; font-size: 13px; color: var(--text-muted); }
.login-title { font-size: 15px; color: var(--text-muted); margin: 0 0 24px; }

/* ══ App shell ════════════════════════════════════════════════════════════ */
.shell {
    display: flex; height: 100%; background: var(--bg);
    max-width: 1600px; margin: 0 auto; box-shadow: var(--shadow-md);
}

/* ── Sidebar ─────────────────────────────────────────────────────────── */
.sidebar {
    width: 30%; min-width: 330px; max-width: 460px;
    background: var(--panel); border-right: 1px solid var(--divider);
    display: flex; flex-direction: column; position: relative;
}
.sidebar-head {
    height: var(--header-h); flex: 0 0 var(--header-h);
    background: var(--panel-header); padding: 0 16px;
    display: flex; align-items: center; gap: 4px;
}
.sidebar-head .me { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; }
.sidebar-head .me .txt { min-width: 0; }
.sidebar-head .me strong {
    display: block; font-size: 15px; font-weight: 500;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-head .me span {
    display: block; font-size: 12px; color: var(--text-muted);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.avatar {
    width: 40px; height: 40px; border-radius: 50%; flex: 0 0 40px;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-weight: 500; font-size: 15px; text-transform: uppercase;
    background: var(--accent); user-select: none; overflow: hidden;
}
.avatar.lg { width: 49px; height: 49px; flex-basis: 49px; font-size: 17px; }
.avatar.sm { width: 30px; height: 30px; flex-basis: 30px; font-size: 12px; }
.avatar .icon { width: 60%; height: 60%; }

.search-wrap {
    padding: 7px 12px; background: var(--panel);
    border-bottom: 1px solid var(--divider); display: flex; gap: 8px; align-items: center;
}
.search-box {
    flex: 1; display: flex; align-items: center; gap: 10px;
    background: var(--bg); border-radius: 8px; padding: 0 12px; height: 35px;
    transition: box-shadow .15s;
}
:root[data-theme="dark"] .search-box { background: var(--panel-header); }
.search-box:focus-within { box-shadow: 0 0 0 1.5px var(--accent); }
.search-box .icon { color: var(--text-faint); width: 18px; height: 18px; }
.search-box input {
    flex: 1; border: none; background: none; outline: none;
    font-size: 14px; min-width: 0;
}
.search-box input::placeholder { color: var(--text-faint); }

.chip-row { display: flex; gap: 6px; padding: 0 12px 8px; background: var(--panel); }
.chip {
    padding: 5px 13px; border-radius: 16px; font-size: 13px;
    background: var(--bg); color: var(--text-muted); transition: all .15s;
}
:root[data-theme="dark"] .chip { background: var(--panel-header); }
.chip.on { background: #d9fdd3; color: #027a5b; }
:root[data-theme="dark"] .chip.on { background: #0a3d31; color: #7ee2c0; }

.chat-list { flex: 1; overflow-y: auto; overflow-x: hidden; }

.chat-item {
    display: flex; gap: 15px; padding: 0 15px; height: 72px;
    align-items: center; cursor: pointer; position: relative;
    transition: background .12s;
}
.chat-item:hover  { background: var(--panel-hover); }
.chat-item.active { background: var(--panel-active); }
.chat-item .body {
    flex: 1; min-width: 0; height: 100%;
    display: flex; flex-direction: column; justify-content: center;
    border-bottom: 1px solid var(--divider);
}
.chat-item:last-child .body { border-bottom: none; }
.chat-item .line1 { display: flex; align-items: baseline; gap: 8px; }
.chat-item .nm {
    flex: 1; min-width: 0; font-size: 17px; font-weight: 400; letter-spacing: -.01em;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-item.unread .nm { font-weight: 500; }
.chat-item .tm { font-size: 12px; color: var(--text-muted); flex: 0 0 auto; }
.chat-item.unread .tm { color: var(--accent); font-weight: 500; }
.chat-item .line2 { display: flex; align-items: center; gap: 6px; margin-top: 3px; }
.chat-item .pv {
    flex: 1; min-width: 0; font-size: 14.2px; color: var(--text-muted);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    display: flex; align-items: center; gap: 4px;
}
/* Aapke bheje hue aakhri message pe list me bhi tick — WhatsApp jaisa */
.chat-item .pv .lt { flex: 0 0 auto; width: 16px; height: 11px; color: var(--text-faint); }
.chat-item .pv .lt.read { color: var(--tick-read); }
.chat-item.unread .pv { color: var(--text); }
.chat-item .pv .icon { color: var(--text-faint); }
.chat-item .assignee {
    font-size: 11px; color: var(--text-faint); flex: 0 0 auto;
    background: var(--bg); padding: 2px 7px; border-radius: 10px;
}
:root[data-theme="dark"] .chat-item .assignee { background: var(--panel-header); }
.badge {
    background: var(--accent); color: #fff; font-size: 12px; font-weight: 500;
    min-width: 20px; height: 20px; border-radius: 10px; padding: 0 6px;
    display: inline-flex; align-items: center; justify-content: center; flex: 0 0 auto;
}
:root[data-theme="dark"] .badge { color: #111b21; }

.list-empty {
    padding: 60px 32px; text-align: center; color: var(--text-muted); font-size: 14px;
}
.list-empty .icon { width: 44px; height: 44px; margin: 0 auto 14px; color: var(--divider); }

/* ── Chat pane ───────────────────────────────────────────────────────── */
.chat-pane {
    flex: 1; min-width: 0; display: flex; flex-direction: column;
    background: var(--chat-bg); position: relative;
}
/* Doodle wallpaper — halka, WhatsApp jaisa texture */
.chat-pane::before {
    content: ''; position: absolute; inset: 0; z-index: 0; opacity: .06;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='260' height='260' viewBox='0 0 260 260'%3E%3Cg fill='none' stroke='%23000' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M22 30h26a5 5 0 015 5v14a5 5 0 01-5 5H34l-7 7v-7h-5a5 5 0 01-5-5V35a5 5 0 015-5z'/%3E%3Ccircle cx='108' cy='40' r='11'/%3E%3Cpath d='M103 40l4 4 7-8'/%3E%3Cpath d='M170 28l10 18-20 0z'/%3E%3Cpath d='M212 34h22v16h-22z'/%3E%3Cpath d='M212 34l11 9 11-9'/%3E%3Cpath d='M40 106c0-8 6-14 14-14s14 6 14 14-6 14-14 14h-3l-8 6v-8c-2-3-3-7-3-12z'/%3E%3Cpath d='M116 100v18M107 109h18'/%3E%3Ccircle cx='180' cy='109' r='12'/%3E%3Cpath d='M180 101v9l6 4'/%3E%3Cpath d='M226 100l8 8-8 8-8-8z'/%3E%3Cpath d='M28 180h20v14H28z'/%3E%3Ccircle cx='34' cy='176' r='4'/%3E%3Cpath d='M96 172c6 0 10 4 10 9s-4 9-10 9-10-4-10-9 4-9 10-9z'/%3E%3Cpath d='M86 195c0-5 5-8 10-8s10 3 10 8'/%3E%3Cpath d='M158 174l14 0 4 8-11 14-11-14z'/%3E%3Cpath d='M214 178h20v18h-20zM214 184h20'/%3E%3Cpath d='M64 236l8-8 8 8M72 228v20'/%3E%3Ccircle cx='140' cy='240' r='10'/%3E%3Cpath d='M136 240h8M140 236v8'/%3E%3Cpath d='M200 232h24l-4 16h-16z'/%3E%3C/g%3E%3C/svg%3E");
}
:root[data-theme="dark"] .chat-pane::before { opacity: .045; filter: invert(1); }
.chat-pane > * { position: relative; z-index: 1; }

.chat-head {
    height: var(--header-h); flex: 0 0 var(--header-h);
    background: var(--panel-header); padding: 0 16px;
    display: flex; align-items: center; gap: 12px;
    border-left: 1px solid var(--divider);
}
.chat-head .who { flex: 1; min-width: 0; cursor: pointer; }
.chat-head .who strong {
    display: block; font-size: 16.5px; font-weight: 500; line-height: 1.25;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-head .who span {
    display: block; font-size: 12.8px; color: var(--text-muted); line-height: 1.3;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-head .avatar { width: 40px; height: 40px; flex-basis: 40px; font-size: 15px; }
.chat-head .icon-btn .icon { width: 21px; height: 21px; }

.pill {
    font-size: 11.5px; padding: 4px 11px; border-radius: 12px;
    font-weight: 500; white-space: nowrap;
}
.pill.ok   { background: #d9fdd3; color: #027a5b; }
.pill.warn { background: #fff3cd; color: #96690a; }
.pill.off  { background: #fdeaea; color: #b3182f; }
:root[data-theme="dark"] .pill.ok   { background: #0a3d31; color: #7ee2c0; }
:root[data-theme="dark"] .pill.warn { background: #453a13; color: #ffd679; }
:root[data-theme="dark"] .pill.off  { background: #3b1d24; color: #ff8fa3; }

/* ── Messages ────────────────────────────────────────────────────────── */
.messages {
    flex: 1; overflow-y: auto; overflow-x: hidden;
    padding: 12px 6% 8px; display: flex; flex-direction: column;
}
.day-sep { align-self: center; margin: 12px 0; }
.day-sep span {
    display: inline-block; background: var(--panel); color: var(--text-muted);
    padding: 5px 12px; border-radius: 7px; font-size: 12.5px;
    text-transform: uppercase; box-shadow: var(--shadow-sm);
}
:root[data-theme="dark"] .day-sep span { background: var(--panel-header); }

.bubble {
    position: relative; max-width: min(65%, 580px);
    margin-bottom: 2px; padding: 6px 9px 8px;
    border-radius: var(--radius); box-shadow: var(--shadow-sm);
    font-size: 14.2px; word-wrap: break-word; overflow-wrap: anywhere;
    white-space: pre-wrap; animation: pop .16s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .bubble { animation: none; } }

.bubble.in  { align-self: flex-start; background: var(--bubble-in);  border-top-left-radius: 0; }
.bubble.out { align-self: flex-end;   background: var(--bubble-out); border-top-right-radius: 0; }
/* Sirf group ke pehle bubble pe tail — WhatsApp jaisa */
.bubble.tail::after {
    content: ''; position: absolute; top: 0; width: 9px; height: 13px;
    background: inherit; clip-path: polygon(0 0, 100% 0, 100% 100%);
}
.bubble.in.tail::after  { left: -8px;  clip-path: polygon(100% 0, 0 0, 100% 100%); }
.bubble.out.tail::after { right: -8px; clip-path: polygon(0 0, 100% 0, 0 100%); }
.bubble:not(.tail) { border-radius: var(--radius); }
.bubble.grouped { margin-top: 0; }
.bubble.first-of-group { margin-top: 10px; }

.bubble .meta {
    float: right; display: inline-flex; align-items: center; gap: 3px;
    margin: 6px -3px -4px 10px; font-size: 11px; color: var(--text-faint);
    user-select: none;
}
.bubble .meta .icon { width: 16px; height: 11px; }
.bubble .meta .tick.read { color: var(--tick-read); }
.bubble .meta .spin { animation: spin 1.4s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.bubble.failed { background: #fdeaea; }
:root[data-theme="dark"] .bubble.failed { background: #3b1d24; }
.bubble .err {
    display: block; margin-top: 5px; font-size: 12px; color: var(--danger);
    display: flex; gap: 5px; align-items: flex-start;
}

.bubble .tpl-tag {
    display: inline-flex; align-items: center; gap: 5px; margin-bottom: 5px;
    font-size: 10.5px; font-weight: 600; letter-spacing: .04em;
    color: var(--accent-strong); text-transform: uppercase;
}
:root[data-theme="dark"] .bubble .tpl-tag { color: #7ee2c0; }

.bubble .quote {
    display: block; margin: -2px -4px 6px; padding: 6px 10px;
    background: rgba(0, 0, 0, .05); border-left: 4px solid var(--accent);
    border-radius: 5px; font-size: 13px; color: var(--text-muted);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
:root[data-theme="dark"] .bubble .quote { background: rgba(255, 255, 255, .07); }

.bubble img.media, .bubble video.media {
    display: block; max-width: 100%; width: 320px; border-radius: 6px;
    margin: -3px -6px 4px; cursor: pointer; background: rgba(0,0,0,.04);
}
.bubble.sticker { background: none !important; box-shadow: none; padding: 0; }
.bubble.sticker img.media { width: 160px; }
.bubble audio.media { display: block; width: 280px; max-width: 100%; margin: 2px 0 4px; }
.bubble .file {
    display: flex; align-items: center; gap: 12px; padding: 10px 12px;
    margin: -2px -4px 5px; border-radius: 6px; text-decoration: none;
    color: inherit; background: rgba(0, 0, 0, .045); transition: background .15s;
}
:root[data-theme="dark"] .bubble .file { background: rgba(255, 255, 255, .07); }
.bubble .file:hover { background: rgba(0, 0, 0, .08); }
.bubble .file .fi { color: var(--danger); flex: 0 0 auto; }
.bubble .file .ft { min-width: 0; }
.bubble .file .fname {
    display: block; font-size: 13.5px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 240px;
}
.bubble .file .fsize { font-size: 11.5px; color: var(--text-muted); }

.msg-empty { margin: auto; text-align: center; color: var(--text-muted); }
.msg-empty .box {
    display: inline-block; background: #ffeecd; color: #7a6224;
    padding: 8px 16px; border-radius: 8px; font-size: 13px; box-shadow: var(--shadow-sm);
}
:root[data-theme="dark"] .msg-empty .box { background: #443a26; color: #ffd679; }

/* ── Composer ────────────────────────────────────────────────────────── */
.composer {
    background: var(--composer); padding: 7px 12px 9px;
    display: flex; align-items: flex-end; gap: 8px; flex: 0 0 auto;
}
/* Pill ke andar hi emoji/template/attach/camera — WhatsApp jaisa */
.composer .input-wrap {
    flex: 1; background: var(--input); border-radius: 24px;
    padding: 2px 4px 2px 2px; display: flex; align-items: flex-end;
    min-height: 46px; max-height: 140px; gap: 2px;
}
.composer .icon-btn.in-pill {
    width: 40px; height: 40px; flex: 0 0 40px; border-radius: 50%;
    margin-bottom: 1px; color: var(--icon);
}
.composer .icon-btn.in-pill .icon { width: 22px; height: 22px; }
.composer .only-mobile { display: none; }
.composer textarea {
    flex: 1; resize: none; border: none; outline: none; background: none;
    max-height: 120px; font-size: 15.5px; line-height: 21px;
    padding: 11px 4px; align-self: center;
}
.composer textarea::placeholder { color: var(--text-faint); }
.composer .send-btn {
    width: 46px; height: 46px; border-radius: 50%; flex: 0 0 46px;
    display: flex; align-items: center; justify-content: center;
    background: var(--accent); color: #fff;
    transition: transform .12s, opacity .15s;
}
.composer .send-btn .icon { width: 22px; height: 22px; }
.composer .send-btn:active { transform: scale(.92); }
.composer .send-btn.ready { background: var(--accent); color: #fff; }
:root[data-theme="dark"] .composer .send-btn.ready { color: #111b21; }
.composer .send-btn:disabled { opacity: .4; cursor: not-allowed; }

.locked-bar {
    background: #fff3cd; color: #7a5c00; padding: 12px 16px;
    display: flex; align-items: center; gap: 12px; font-size: 13.5px; flex: 0 0 auto;
}
:root[data-theme="dark"] .locked-bar { background: #443a13; color: #ffd679; }
.locked-bar .icon { flex: 0 0 auto; }
.locked-bar .btn { margin-left: auto; flex: 0 0 auto; }

/* ── Intro (koi chat select nahi) ────────────────────────────────────── */
.intro {
    flex: 1; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 14px;
    background: var(--bg); text-align: center; padding: 40px;
    border-bottom: 6px solid var(--accent);
}
.intro .art { width: 220px; height: 160px; color: var(--divider); }
.intro h2 { margin: 0; font-size: 30px; font-weight: 300; color: var(--text-muted); }
.intro p  { margin: 0; font-size: 14px; color: var(--text-faint); max-width: 460px; }

/* ── FAB (mobile) ────────────────────────────────────────────────────── */
.fab {
    position: absolute; right: 16px; bottom: 16px; z-index: 5;
    width: 56px; height: 56px; border-radius: 28px;
    background: var(--accent); color: #fff;
    display: none; align-items: center; justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, .3);
}
:root[data-theme="dark"] .fab { color: #111b21; }

/* ══ Drawer (Settings / Team) ═════════════════════════════════════════ */
.drawer {
    position: absolute; inset: 0; z-index: 20; background: var(--panel);
    display: flex; flex-direction: column;
    transform: translateX(-102%); transition: transform .22s ease-out;
    box-shadow: var(--shadow-md);
}
.drawer.open { transform: none; }
.drawer-head {
    background: var(--accent-strong); color: #fff;
    padding: 0 16px; height: 108px; display: flex; align-items: flex-end;
    gap: 20px; padding-bottom: 18px; flex: 0 0 auto;
}
:root[data-theme="dark"] .drawer-head { background: var(--panel-header); color: var(--text); }
.drawer-head .icon-btn { color: #fff; }
:root[data-theme="dark"] .drawer-head .icon-btn { color: var(--text); }
.drawer-head h2 { margin: 0; font-size: 19px; font-weight: 500; }
.drawer-body { flex: 1; overflow-y: auto; }

.menu-item {
    display: flex; align-items: center; gap: 20px; padding: 14px 22px;
    width: 100%; text-align: left; color: var(--text); transition: background .12s;
    border-bottom: 1px solid var(--divider);
}
.menu-item:hover { background: var(--panel-hover); }
.menu-item .icon { color: var(--icon); }
.menu-item .mt { flex: 1; min-width: 0; }
.menu-item .mt strong { display: block; font-size: 15px; font-weight: 400; }
.menu-item .mt span { display: block; font-size: 12.5px; color: var(--text-muted); }
.menu-item.danger, .menu-item.danger .icon { color: var(--danger); }

.section-title {
    padding: 18px 22px 8px; font-size: 13px; font-weight: 600;
    color: var(--accent-strong); text-transform: uppercase; letter-spacing: .05em;
}
:root[data-theme="dark"] .section-title { color: var(--accent); }

.member {
    display: flex; align-items: center; gap: 14px; padding: 11px 22px;
    border-bottom: 1px solid var(--divider);
}
.member .mt { flex: 1; min-width: 0; }
.member .mt strong {
    display: block; font-size: 15px; font-weight: 400;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.member .mt span {
    display: block; font-size: 12.5px; color: var(--text-muted);
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.member .role {
    font-size: 11px; padding: 2px 9px; border-radius: 10px;
    background: var(--bg); color: var(--text-muted); flex: 0 0 auto;
}
:root[data-theme="dark"] .member .role { background: var(--panel-header); }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(104px, 1fr)); gap: 10px; padding: 12px 22px 22px; }
.stat {
    background: var(--bg); border-radius: 10px; padding: 14px;
}
:root[data-theme="dark"] .stat { background: var(--panel-header); }
.stat b { display: block; font-size: 22px; font-weight: 500; }
.stat span { font-size: 11.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }

.info-row { padding: 12px 22px; border-bottom: 1px solid var(--divider); }
.info-row .k { font-size: 12.5px; color: var(--text-muted); }
.info-row .v { font-size: 15px; word-break: break-all; }

/* ══ Modal ════════════════════════════════════════════════════════════ */
.modal-backdrop {
    position: fixed; inset: 0; background: var(--overlay); z-index: 60;
    display: flex; align-items: center; justify-content: center; padding: 20px;
    animation: fade .15s ease-out;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
    background: var(--panel); border-radius: 6px; box-shadow: var(--shadow-lg);
    width: 100%; max-width: 480px; max-height: 88vh;
    display: flex; flex-direction: column; overflow: hidden;
}
.modal.wide { max-width: 620px; }
.modal-head { padding: 22px 24px 6px; }
.modal-head h2 { margin: 0; font-size: 18px; font-weight: 500; }
.modal-head p  { margin: 6px 0 0; font-size: 13.5px; color: var(--text-muted); }
.modal-body { padding: 18px 24px; overflow-y: auto; flex: 1; }
.modal-actions {
    display: flex; gap: 10px; justify-content: flex-end;
    padding: 14px 24px 20px; flex: 0 0 auto;
}

.opt {
    display: flex; gap: 12px; align-items: flex-start; padding: 11px 12px;
    border-radius: 8px; cursor: pointer; transition: background .12s;
}
.opt:hover { background: var(--panel-hover); }
.opt input { margin-top: 3px; accent-color: var(--accent); width: 17px; height: 17px; flex: 0 0 auto; }
.opt .ot { min-width: 0; }
.opt .ot strong { display: block; font-size: 14.5px; font-weight: 400; }
.opt .ot span  { display: block; font-size: 12.5px; color: var(--text-muted); }

.tpl-card {
    border: 1px solid var(--divider); border-radius: 8px; padding: 13px;
    margin-bottom: 10px; cursor: pointer; transition: all .15s;
}
.tpl-card:hover { background: var(--panel-hover); }
.tpl-card.sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.tpl-card .tn { font-weight: 500; font-size: 14.5px; }
.tpl-card .tm { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.tpl-card .tb {
    font-size: 13.5px; margin-top: 9px; padding: 9px 11px; border-radius: 6px;
    background: var(--bubble-out); white-space: pre-wrap;
}

/* Lightbox */
.lightbox {
    position: fixed; inset: 0; z-index: 70; background: rgba(0, 0, 0, .92);
    display: flex; align-items: center; justify-content: center; padding: 24px;
}
.lightbox img, .lightbox video { max-width: 100%; max-height: 100%; border-radius: 4px; }
.lightbox .close { position: absolute; top: 16px; right: 20px; color: #fff; }

/* Toast */
.toast-wrap {
    position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
    z-index: 90; display: flex; flex-direction: column; gap: 8px; align-items: center;
    pointer-events: none; width: min(92vw, 420px);
}
.toast {
    background: #202c33; color: #e9edef; padding: 12px 18px; border-radius: 8px;
    font-size: 13.5px; box-shadow: var(--shadow-lg); animation: rise .18s ease-out;
    display: flex; gap: 10px; align-items: center;
}
.toast.err { background: #b3182f; color: #fff; }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

/* ══ Mobile — WhatsApp app jaisa ══════════════════════════════════════ */
@media (max-width: 820px) {
    :root { --header-h: 56px; }
    .shell { max-width: none; box-shadow: none; }

    .sidebar {
        width: 100%; min-width: 0; max-width: none; border-right: none;
        background: var(--panel);
    }
    .shell.chat-open .sidebar { display: none; }
    .shell:not(.chat-open) .chat-pane { display: none; }

    /* Green app-bar */
    .sidebar-head, .chat-head {
        background: var(--accent-strong); color: #fff; border-left: none;
        padding: 0 8px 0 14px;
    }
    :root[data-theme="dark"] .sidebar-head,
    :root[data-theme="dark"] .chat-head { background: var(--panel-header); color: var(--text); }
    .sidebar-head .icon-btn, .chat-head .icon-btn { color: #fff; }
    :root[data-theme="dark"] .sidebar-head .icon-btn,
    :root[data-theme="dark"] .chat-head .icon-btn { color: var(--icon); }
    .sidebar-head .me strong { font-size: 19px; font-weight: 500; }
    .sidebar-head .me span,
    .chat-head .who span { color: rgba(255, 255, 255, .78); }
    :root[data-theme="dark"] .sidebar-head .me span,
    :root[data-theme="dark"] .chat-head .who span { color: var(--text-muted); }
    .sidebar-head .me > .avatar { display: none; }
    .chat-head .who strong { font-size: 17px; font-weight: 500; }
    .chat-head { gap: 8px; }
    .chat-head .avatar { width: 38px; height: 38px; flex-basis: 38px; }
    .chat-head .who { margin-left: 2px; }
    .chat-head .pill { font-size: 10.5px; padding: 3px 8px; }
    .chat-item { padding: 0 14px; gap: 14px; }
    .chat-item .nm { font-size: 16.5px; }
    .chat-item .pv { font-size: 14px; }
    .sidebar-head .icon-btn:hover, .chat-head .icon-btn:hover { background: rgba(255, 255, 255, .15); }

    .search-wrap { padding: 8px 10px; }
    .fab { display: flex; }
    .messages { padding: 10px 4% 6px; }
    .bubble { max-width: 85%; font-size: 15px; }
    .bubble img.media, .bubble video.media { width: min(78vw, 320px); }
    .composer { padding: 6px 8px 10px; gap: 6px; }
    .composer .input-wrap { border-radius: 26px; }
    .composer .only-mobile { display: flex; }
    .composer textarea { font-size: 16px; }   /* iOS/Android zoom na kare */

    /* Attach = neeche se uthne wali sheet, bilkul WhatsApp jaisi */
    .attach-sheet {
        position: fixed; left: 0; right: 0; bottom: 0; top: auto;
        width: auto; max-width: none; border-radius: 18px 18px 0 0;
        padding: 10px 10px 26px; animation: sheetUp .2s ease-out;
    }
    .attach-sheet .sheet-grip {
        display: block; width: 38px; height: 4px; border-radius: 2px;
        background: var(--divider); margin: 2px auto 12px;
    }
    .attach-sheet .as-grid { grid-template-columns: repeat(4, 1fr); gap: 6px; }
    .attach-sheet .am-ic { width: 56px; height: 56px; }
    @keyframes sheetUp { from { transform: translateY(100%); } to { transform: none; } }

    .emoji-panel { position: fixed; left: 0; right: 0; bottom: 0; width: auto;
                   max-width: none; border-radius: 14px 14px 0 0; z-index: 45; }
    .ep-grid { grid-template-columns: repeat(8, 1fr); height: 42vh; }
    .drawer-head { height: 92px; }
    .modal { max-width: none; border-radius: 12px; }
    .intro { display: none; }
    .chat-item { height: 76px; }
}

/* Chhote phone */
@media (max-width: 380px) {
    .bubble { max-width: 90%; }
    .chat-item { padding: 0 12px; gap: 12px; }
}

/* ══ Admin console (aapke liye) ═══════════════════════════════════════ */
.admin-body { overflow: auto; height: 100%; background: var(--bg); }
.topbar {
    background: var(--accent-strong); color: #fff; padding: 0 24px; height: 60px;
    display: flex; align-items: center; gap: 14px; position: sticky; top: 0; z-index: 10;
}
:root[data-theme="dark"] .topbar { background: var(--panel-header); color: var(--text); }
.topbar h1 { margin: 0; font-size: 18px; font-weight: 500; flex: 1; }
.topbar .btn.ghost { color: #fff; border-color: rgba(255, 255, 255, .45); }
.topbar .btn.ghost:hover { background: rgba(255, 255, 255, .14); }
:root[data-theme="dark"] .topbar .btn.ghost { color: var(--text); border-color: var(--divider); }

.admin-wrap { max-width: 1200px; margin: 0 auto; padding: 24px; }
.tabs { display: flex; gap: 6px; margin-bottom: 22px; border-bottom: 1px solid var(--divider); }
.tab {
    padding: 12px 20px; border-bottom: 3px solid transparent;
    color: var(--text-muted); font-weight: 500; font-size: 14.5px;
}
.tab.active { color: var(--accent-strong); border-bottom-color: var(--accent); }
:root[data-theme="dark"] .tab.active { color: var(--accent); }

.card {
    background: var(--panel); border-radius: 10px; padding: 20px;
    box-shadow: var(--shadow-sm); margin-bottom: 16px;
}
.card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.card-head h2 { margin: 0; font-size: 16.5px; font-weight: 500; flex: 1; display: flex; align-items: center; gap: 10px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--divider); vertical-align: top; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); font-weight: 600; }
.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 12.5px; word-break: break-all; }

.copy-row { display: flex; gap: 8px; align-items: center; }
.copy-row code {
    flex: 1; background: var(--bg); padding: 8px 11px; border-radius: 6px;
    font-size: 12.5px; word-break: break-all; font-family: ui-monospace, Consolas, monospace;
}
:root[data-theme="dark"] .copy-row code { background: var(--panel-header); }

@media (max-width: 720px) {
    .admin-wrap { padding: 14px; }
    .card { padding: 15px; }
    table, thead, tbody, th, td, tr { display: block; }
    thead { display: none; }
    tr { border-bottom: 1px solid var(--divider); padding: 10px 0; }
    td { border: none; padding: 4px 0; }
    td[data-label]::before { content: attr(data-label) ": "; font-weight: 600; color: var(--text-muted); font-size: 12px; }
}

/* ── Superadmin: "kisi customer ka inbox" patti ──────────────────────── */
.tenant-bar {
    position: fixed; inset: 0 0 auto 0; z-index: 60;
    height: 38px; display: flex; align-items: center; gap: 10px;
    padding: 0 14px; font-size: 13.5px;
    background: var(--accent-strong); color: #fff;
    box-shadow: var(--shadow-sm);
}
.tenant-bar.suspended { background: #b23c3c; }
.tenant-bar .tb-eye { display: flex; opacity: .85; }
.tenant-bar .tb-eye .icon { fill: #fff; }
.tenant-bar .tb-txt { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tenant-bar .tb-txt em { opacity: .85; font-style: normal; }
.tenant-bar button {
    flex: none; cursor: pointer; font: inherit; font-size: 12.5px;
    padding: 4px 11px; border-radius: 13px;
    background: rgba(255, 255, 255, .16); color: #fff;
    border: 1px solid rgba(255, 255, 255, .28);
}
.tenant-bar button:hover { background: rgba(255, 255, 255, .28); }

/* Patti aane par pura app utna hi neeche khisak jaye */
html.has-tenant-bar body { padding-top: 38px; box-sizing: border-box; height: 100%; }
html.has-tenant-bar .shell { height: calc(100% - 38px); }

/* Customer switch modal */
.tenant-picker { display: flex; flex-direction: column; gap: 6px; max-height: 52vh; overflow-y: auto; }
.tp-row {
    display: flex; flex-direction: column; gap: 2px; text-align: left;
    padding: 10px 12px; border-radius: 8px; cursor: pointer;
    background: var(--panel-hover); border: 1px solid transparent; color: var(--text);
    font: inherit;
}
.tp-row:hover  { background: var(--panel-active); }
.tp-row.current { border-color: var(--accent); }
.tp-row span   { font-size: 12.5px; color: var(--text-muted); }

/* ══ Composer: reply strip, attach menu, emoji picker ═══════════════════ */
.reply-strip {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 12px 0; background: var(--panel-header);
}
.reply-strip .rs-bar { width: 4px; align-self: stretch; min-height: 34px; border-radius: 2px; background: var(--accent); }
.reply-strip .rs-body { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 4px 0; }
.reply-strip strong { font-size: 13px; color: var(--accent); }
.reply-strip .rs-body span { font-size: 13px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sheet-backdrop {
    position: fixed; inset: 0; z-index: 44; background: rgba(0, 0, 0, .35);
    animation: fade .15s ease-out;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.attach-sheet {
    position: absolute; bottom: 78px; left: 12px; z-index: 45;
    background: var(--panel); border-radius: 16px; padding: 14px 8px 8px;
    box-shadow: var(--shadow-lg); width: 320px; max-width: calc(100% - 24px);
    animation: rise .16s ease-out;
}
.attach-sheet .sheet-grip { display: none; }
.attach-sheet .as-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.attach-sheet button {
    display: flex; flex-direction: column; align-items: center; gap: 7px;
    padding: 12px 4px; border: 0; border-radius: 10px; cursor: pointer;
    background: none; color: var(--text-muted); font: inherit; font-size: 12.5px;
}
.attach-sheet button:hover { background: var(--panel-hover); }
.attach-sheet .am-ic {
    width: 52px; height: 52px; border-radius: 50%; flex: none;
    display: grid; place-items: center;
}
.attach-sheet .am-ic .icon { width: 24px; height: 24px; fill: #fff; color: #fff; }
.am-ic.gallery { background: #bf59cf; }
.am-ic.camera  { background: #d3396d; }
.am-ic.doc     { background: #5f66cd; }
.am-ic.loc     { background: #1fa855; }
.am-ic.person  { background: #0195a6; }
.am-ic.tpl     { background: #e9a13b; }

.emoji-panel {
    position: absolute; bottom: 74px; left: 12px; z-index: 40; width: 330px;
    max-width: calc(100% - 24px);
    background: var(--panel); border-radius: 12px; box-shadow: var(--shadow-md);
    overflow: hidden;
}
.ep-tabs { display: flex; gap: 2px; padding: 6px; overflow-x: auto; border-bottom: 1px solid var(--divider); }
.ep-tabs button {
    flex: none; padding: 5px 10px; border-radius: 12px; cursor: pointer;
    background: none; border: 0; color: var(--text-muted); font: inherit; font-size: 12.5px;
}
.ep-tabs button.on { background: var(--panel-active); color: var(--text); }
.ep-grid {
    display: grid; grid-template-columns: repeat(8, 1fr);
    gap: 2px; padding: 8px; height: 230px; overflow-y: auto;
}
.ep-e { font-size: 22px; line-height: 1; padding: 5px 0; border: 0; border-radius: 6px; background: none; cursor: pointer; }
.ep-e:hover { background: var(--panel-hover); }

/* ══ Bubble: quote, reactions, menu ═════════════════════════════════════ */
.bubble .quoted {
    display: flex; flex-direction: column; gap: 1px;
    margin: -2px 0 5px; padding: 5px 9px; border-radius: 5px;
    border-left: 4px solid var(--accent);
    background: rgba(0, 0, 0, .05); font-size: 13px;
}
html[data-theme="dark"] .bubble .quoted { background: rgba(255, 255, 255, .07); }
.bubble .quoted strong { color: var(--accent); font-size: 12.5px; }
.bubble .quoted span   { color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.bubble .rx-tag {
    position: absolute; bottom: -11px; left: 8px;
    background: var(--panel); border: 1px solid var(--divider);
    border-radius: 11px; padding: 1px 6px; font-size: 12.5px;
    box-shadow: var(--shadow-sm); white-space: nowrap;
}
.bubble.out .rx-tag { left: auto; right: 8px; }

.bubble .bub-menu {
    position: absolute; top: 2px; right: 4px; opacity: 0;
    width: 22px; height: 20px; border: 0; border-radius: 4px; cursor: pointer;
    background: none; color: var(--text-muted); font-size: 15px; line-height: 1;
    transition: opacity .12s;
}
.bubble:hover .bub-menu { opacity: .75; }
.bubble .bub-menu:hover { opacity: 1; background: rgba(0, 0, 0, .07); }

.bub-pop {
    position: fixed; z-index: 90; min-width: 172px;
    background: var(--panel); border-radius: 10px; box-shadow: var(--shadow-md);
    padding: 6px; font-size: 14px;
}
.bub-pop .bp-rx { display: flex; gap: 2px; padding: 2px 2px 6px; border-bottom: 1px solid var(--divider); margin-bottom: 4px; }
.bub-pop .bp-rx button { flex: 1; font-size: 20px; padding: 4px 0; border: 0; border-radius: 6px; background: none; cursor: pointer; }
.bub-pop .bp-rx button:hover { background: var(--panel-hover); transform: scale(1.15); }
.bub-pop .bp-item {
    display: flex; align-items: center; gap: 10px; width: 100%;
    padding: 8px 10px; border: 0; border-radius: 6px; cursor: pointer;
    background: none; color: var(--text); font: inherit;
}
.bub-pop .bp-item:hover { background: var(--panel-hover); }
.bub-pop .icon { fill: var(--text-muted); }

/* Location + contact card */
.loc-card { display: flex; gap: 10px; align-items: center; text-decoration: none; color: inherit; min-width: 220px; }
.loc-card .loc-map {
    width: 46px; height: 46px; flex: none; border-radius: 8px; display: grid; place-items: center;
    background: linear-gradient(145deg, #cfe9d4, #9fd6ae);
}
.loc-card .loc-map .icon { fill: #1fa855; width: 24px; height: 24px; }
.loc-card .ft { display: flex; flex-direction: column; min-width: 0; }
.loc-card .loc-open { font-size: 12px; color: var(--accent); margin-top: 2px; }
.contact-card { min-width: 200px; }

#locStatus.ok  { color: var(--accent); font-weight: 600; }
#locStatus.bad { color: #d9534f; }

@media (max-width: 820px) {
    .emoji-panel, .attach-menu { bottom: 64px; }
    .ep-grid { grid-template-columns: repeat(7, 1fr); height: 200px; }
}

/* ── Location sheet ──────────────────────────────────────────────────── */
.loc-btn {
    display: flex; align-items: center; gap: 14px; width: 100%; text-align: left;
    padding: 13px 14px; border: 1px solid var(--divider); border-radius: 10px;
    background: var(--panel-hover); color: var(--text); font: inherit; cursor: pointer;
}
.loc-btn:hover { background: var(--panel-active); }
.loc-btn .lb-ic {
    width: 44px; height: 44px; flex: none; border-radius: 50%; font-size: 21px;
    display: grid; place-items: center; background: #1fa855;
}
.loc-btn .lb-txt { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.loc-btn .lb-txt strong { font-size: 15px; }
.loc-btn .lb-txt span { font-size: 12.5px; color: var(--text-muted); }
.loc-btn .lb-txt span.ok  { color: var(--accent); font-weight: 600; }
.loc-btn .lb-txt span.bad { color: #d9534f; }

.loc-or { display: flex; align-items: center; gap: 10px; margin: 14px 0 4px; color: var(--text-faint); font-size: 12.5px; }
.loc-or::before, .loc-or::after { content: ''; flex: 1; height: 1px; background: var(--divider); }

.loc-found {
    margin: 4px 0 10px; padding: 9px 12px; border-radius: 8px;
    background: var(--panel-hover); font-size: 13px; line-height: 1.5;
}
.loc-found strong { font-family: ui-monospace, Consolas, monospace; }
.loc-found span { color: var(--text-muted); }
.loc-found a { color: var(--accent); display: block; margin-top: 2px; }

/* ── Template allowlist ──────────────────────────────────────────────── */
.tpl-allow { max-height: 260px; overflow-y: auto; }
.tpl-allow #tplList { margin-left: 18px; border-left: 2px solid var(--divider); padding-left: 10px; }
.tpl-allow #tplList.dimmed { opacity: .45; pointer-events: none; }
.tpl-allow .opt strong { font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
