/* ═══════════════════════════════════════════════════════════════
   GroupChat — style.css  v1.5
   Mobile-first. Dark/Light themes. WhatsApp-style formatting.
   ═══════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@300;400;500;600;700&family=Space+Mono:wght@400;700&display=swap');

/* ── Dark theme variables (default) ──────────────────────────── */
:root {
    --bg-primary:      #111b21;
    --bg-secondary:    #1f2c34;
    --bg-panel:        #202c33;
    --bg-input:        #2a3942;
    --bg-message-in:   #202c33;
    --bg-message-out:  #005c4b;
    --bg-hover:        #2a3942;
    --accent:          #00a884;
    --accent-hover:    #06cf9c;
    --accent-danger:   #ff453a;
    --accent-warn:     #ffb340;
    --text-primary:    #e9edef;
    --text-secondary:  #8696a0;
    --text-muted:      #54656f;
    --border:          #2a3942;
    --border-light:    #3b4a54;
    --shadow:          rgba(0,0,0,0.35);
    --radius-sm:       6px;
    --radius-md:       12px;
    --radius-lg:       18px;
    --radius-xl:       24px;
    --font-main:       'DM Sans', system-ui, sans-serif;
    --font-mono:       'Space Mono', monospace;
    --transition:      0.15s ease;
    --sidebar-width:   360px;
    --header-height:   60px;
    --input-height:    44px;
}

/* ── Light theme — applied via html.light-mode ────────────────── */
html.light-mode {
    --bg-primary:      #f0f2f5;
    --bg-secondary:    #ffffff;
    --bg-panel:        #e9edef;
    --bg-input:        #ffffff;
    --bg-message-in:   #ffffff;
    --bg-message-out:  #d9fdd3;
    --bg-hover:        #f5f6f6;
    --text-primary:    #111b21;
    --text-secondary:  #667781;
    --text-muted:      #8696a0;
    --border:          #e9edef;
    --border-light:    #d1d7db;
    --shadow:          rgba(0,0,0,0.08);
}

/* ── Reset ────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html {
    -webkit-text-size-adjust: 100%;
    touch-action: manipulation;
    /* CRITICAL: tells mobile browser to resize content when keyboard opens */
    /* This makes the input stay visible on Android Chrome */
}
html, body {
    height: 100%;
    font-family: var(--font-main);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
    overscroll-behavior: none;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
img { max-width: 100%; display: block; object-fit: cover; background: var(--bg-input); }
input, textarea, select, button {
    font-family: var(--font-main);
    font-size: 16px; /* prevents iOS auto-zoom */
}

/* ═══════════════════════════════════════════════════════════════
   AUTH PAGES
   ═══════════════════════════════════════════════════════════════ */
.auth-wrap {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(ellipse at top, #1a2a36 0%, var(--bg-primary) 70%);
    padding: 16px;
}
.auth-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-xl);
    padding: 32px 28px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 24px 64px var(--shadow);
}
.auth-logo { text-align: center; margin-bottom: 28px; }
.auth-logo .logo-icon {
    width: 60px; height: 60px; background: var(--accent);
    border-radius: 50%; display: flex; align-items: center;
    justify-content: center; margin: 0 auto 10px; font-size: 26px;
}
.auth-logo h1 { font-size: 22px; font-weight: 700; color: var(--text-primary); }
.auth-logo p  { color: var(--text-secondary); font-size: 13px; margin-top: 3px; }

/* ═══════════════════════════════════════════════════════════════
   FORM CONTROLS
   ═══════════════════════════════════════════════════════════════ */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block; font-size: 12px; font-weight: 600;
    text-transform: uppercase; letter-spacing: .06em;
    color: var(--text-secondary); margin-bottom: 6px;
}
.form-control {
    width: 100%; background: var(--bg-input);
    border: 1px solid var(--border-light); border-radius: var(--radius-sm);
    color: var(--text-primary); padding: 10px 14px;
    min-height: var(--input-height); outline: none;
    -webkit-appearance: none; appearance: none;
    transition: border-color var(--transition);
}
.form-control:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(0,168,132,.15);
}
.form-control::placeholder { color: var(--text-muted); }
textarea.form-control { resize: vertical; min-height: 80px; }
select.form-control {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%238696a0' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14L2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px;
}

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    gap: 6px; padding: 10px 18px; border-radius: var(--radius-sm);
    border: none; cursor: pointer; font-weight: 600; font-size: 14px;
    min-height: var(--input-height); transition: all var(--transition);
    white-space: nowrap; -webkit-tap-highlight-color: transparent;
}
.btn-primary    { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary  { background: var(--bg-input); color: var(--text-primary); border: 1px solid var(--border-light); }
.btn-secondary:hover { background: var(--bg-hover); }
.btn-danger     { background: var(--accent-danger); color: #fff; }
.btn-danger:hover { opacity: .9; }
.btn-sm  { padding: 6px 12px; font-size: 13px; min-height: 32px; }
.btn-full{ width: 100%; }
.btn-icon{ padding: 8px; width: 36px; height: 36px; border-radius: 50%; min-height: auto; }

/* Alerts */
.alert { padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 14px; font-size: 13px; font-weight: 500; line-height: 1.5; }
.alert-error   { background: rgba(255,69,58,.15);  color: #ff6b6b; border: 1px solid rgba(255,69,58,.3); }
.alert-success { background: rgba(0,168,132,.15);  color: var(--accent-hover); border: 1px solid rgba(0,168,132,.3); }
.alert-warn    { background: rgba(255,179,64,.15); color: var(--accent-warn); border: 1px solid rgba(255,179,64,.3); }

/* ═══════════════════════════════════════════════════════════════
   APP LAYOUT — DESKTOP
   ═══════════════════════════════════════════════════════════════ */
.app-container {
    display: flex;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

/* ── Sidebar ──────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    flex-shrink: 0;
}
.sidebar-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 14px; background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    min-height: var(--header-height); gap: 8px; flex-shrink: 0;
}
.sidebar-header .user-avatar {
    width: 38px; height: 38px; border-radius: 50%;
    cursor: pointer; object-fit: cover; flex-shrink: 0;
}
.sidebar-actions { display: flex; gap: 2px; flex-shrink: 0; }
.icon-btn {
    width: 40px; height: 40px; background: transparent; border: none;
    border-radius: 50%; color: var(--text-secondary); cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; -webkit-tap-highlight-color: transparent;
    transition: background var(--transition); flex-shrink: 0;
    min-width: 40px; min-height: 40px;
}
.icon-btn:hover, .icon-btn:active { background: var(--bg-hover); color: var(--text-primary); }

/* Search */
.search-box { padding: 6px 12px; background: var(--bg-panel); border-bottom: 1px solid var(--border); flex-shrink: 0; }
.search-input-wrap { position: relative; display: flex; align-items: center; }
.search-input-wrap svg { position: absolute; left: 10px; color: var(--text-muted); pointer-events: none; }
.search-input {
    width: 100%; background: var(--bg-input); border: none;
    border-radius: 8px; color: var(--text-primary);
    padding: 8px 12px 8px 36px; outline: none;
    font-size: 14px; min-height: 36px;
}
.search-input::placeholder { color: var(--text-muted); }

/* Group list */
.group-list {
    flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
    scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
.group-list::-webkit-scrollbar { width: 3px; }
.group-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.group-item {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 14px; cursor: pointer;
    border-bottom: 1px solid var(--border); text-decoration: none; color: inherit;
    transition: background var(--transition); -webkit-tap-highlight-color: transparent;
}
.group-item:hover, .group-item:active, .group-item.active { background: var(--bg-hover); }
.group-icon { width: 46px; height: 46px; border-radius: 50%; object-fit: cover; flex-shrink: 0; background: var(--bg-input); }
.group-item-info { flex: 1; min-width: 0; }
.group-item-top { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; margin-bottom: 2px; }
.group-item-name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.group-item-time { font-size: 11px; color: var(--text-muted); flex-shrink: 0; }
.group-item-preview { font-size: 13px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Chat Area ────────────────────────────────────────────────── */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    height: 100%;
    overflow: hidden;
    position: relative;
    min-width: 0;
}
.chat-area::before {
    content: ''; position: absolute; inset: 0;
    background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none'%3E%3Cg fill='%232a3942' fill-opacity='0.15'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
    pointer-events: none; z-index: 0;
}

/* Chat header */
.chat-header {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 12px; background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    min-height: var(--header-height); z-index: 10;
    position: relative; flex-shrink: 0;
}
.chat-header-info { flex: 1; cursor: pointer; min-width: 0; }
.chat-header-name { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-header-meta { font-size: 12px; color: var(--text-secondary); }
.chat-header-actions { display: flex; gap: 2px; flex-shrink: 0; }

/* Messages */
.messages-container {
    flex: 1; overflow-y: auto; min-height: 0;
    -webkit-overflow-scrolling: touch;
    padding: 12px 8%;
    display: flex; flex-direction: column; gap: 3px;
    position: relative; z-index: 1;
    scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
.messages-container::-webkit-scrollbar { width: 3px; }
.messages-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Date separator */
.date-separator { text-align: center; margin: 12px 0 6px; }
.date-separator span {
    background: var(--bg-panel); color: var(--text-secondary);
    font-size: 11px; padding: 3px 10px; border-radius: 20px; border: 1px solid var(--border);
}

/* Message wrapper */
.msg-wrapper { display: flex; flex-direction: column; max-width: 70%; margin-bottom: 2px; }
.msg-wrapper.outgoing { align-self: flex-end; align-items: flex-end; }
.msg-wrapper.incoming { align-self: flex-start; align-items: flex-start; }
.msg-wrapper.system   { align-self: center; max-width: 85%; }
.msg-sender { font-size: 12px; font-weight: 600; color: var(--accent-hover); margin-bottom: 2px; padding-left: 12px; }

/* Bubble */
.msg-bubble {
    position: relative; padding: 7px 11px 20px;
    border-radius: var(--radius-md); word-break: break-word;
    font-size: 14px; line-height: 1.55;
    box-shadow: 0 1px 2px rgba(0,0,0,.2);
}
.incoming .msg-bubble { background: var(--bg-message-in); border-top-left-radius: 4px; }
.outgoing .msg-bubble { background: var(--bg-message-out); border-top-right-radius: 4px; }
.system   .msg-bubble { background: rgba(42,57,66,.7); border-radius: 8px; font-size: 11px; color: var(--text-secondary); text-align: center; padding: 4px 10px; }
.msg-bubble.deleted { background: transparent; border: 1px solid var(--border); font-style: italic; color: var(--text-muted); }
.msg-time { position: absolute; bottom: 4px; right: 8px; font-size: 10px; color: var(--text-muted); white-space: nowrap; }
.outgoing .msg-time { color: rgba(233,237,239,.5); }
.msg-edited { font-size: 10px; color: var(--text-muted); font-style: italic; margin-right: 4px; }

/* ── WhatsApp Text Formatting ─────────────────────────────────── */
/* These are applied by JS formatMessage() before inserting HTML */
.fmt-bold      { font-weight: 700; }
.fmt-italic    { font-style: italic; }
.fmt-strike    { text-decoration: line-through; }
.fmt-underline { text-decoration: underline; }
.fmt-mono      { font-family: var(--font-mono); font-size: 13px; background: rgba(0,0,0,.15); padding: 1px 4px; border-radius: 3px; }

/* Formatting toolbar */
.fmt-toolbar {
    display: none;
    gap: 2px;
    padding: 4px 6px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    flex-shrink: 0;
}
.fmt-toolbar.visible { display: flex; }
.fmt-btn {
    padding: 4px 8px; border: 1px solid var(--border);
    border-radius: 4px; background: var(--bg-input);
    color: var(--text-primary); cursor: pointer;
    font-size: 13px; min-width: 28px; min-height: 28px;
    display: flex; align-items: center; justify-content: center;
    transition: all var(--transition); -webkit-tap-highlight-color: transparent;
}
.fmt-btn:hover, .fmt-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.fmt-btn-b  { font-weight: 700; }
.fmt-btn-i  { font-style: italic; }
.fmt-btn-s  { text-decoration: line-through; }
.fmt-btn-u  { text-decoration: underline; }
.fmt-btn-m  { font-family: monospace; font-size: 12px; }

/* Reply preview */
.reply-preview { background: rgba(0,0,0,.2); border-left: 3px solid var(--accent); padding: 5px 9px; border-radius: 5px; margin-bottom: 5px; font-size: 12px; }
.reply-preview .reply-author { color: var(--accent-hover); font-weight: 600; font-size: 11px; margin-bottom: 2px; }
.reply-preview .reply-text { color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Context menu */
.msg-actions {
    display: none; position: absolute; right: 0; top: 4px;
    background: var(--bg-panel); border: 1px solid var(--border);
    border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.4);
    z-index: 50; min-width: 130px; overflow: hidden;
}
.msg-bubble:hover .msg-actions, .msg-bubble:focus-within .msg-actions { display: block; }
.msg-actions button { display: block; width: 100%; background: none; border: none; color: var(--text-primary); padding: 8px 13px; text-align: left; cursor: pointer; font-size: 13px; transition: background var(--transition); }
.msg-actions button:hover { background: var(--bg-hover); }
.msg-actions button.danger { color: var(--accent-danger); }

/* Media */
.msg-image { max-width: 260px; border-radius: 8px; margin-bottom: 4px; cursor: pointer; }
.msg-video { max-width: 260px; border-radius: 8px; margin-bottom: 4px; width: 100%; }
.msg-audio { width: 200px; max-width: 100%; }
.msg-doc { display: flex; align-items: center; gap: 8px; background: rgba(0,0,0,.2); padding: 8px 12px; border-radius: 8px; margin-bottom: 4px; }
.msg-doc-icon { font-size: 24px; flex-shrink: 0; }
.msg-doc-info { flex: 1; min-width: 0; }
.msg-doc-name { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-doc-size { font-size: 10px; color: var(--text-muted); }

/* Reply bar */
.reply-bar { display: none; background: var(--bg-panel); border-left: 4px solid var(--accent); margin: 0 12px 5px; padding: 6px 10px; border-radius: 0 5px 5px 0; align-items: center; gap: 8px; flex-shrink: 0; }
.reply-bar.visible { display: flex; }
.reply-bar-text { flex: 1; font-size: 12px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reply-bar-close { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 18px; line-height: 1; padding: 2px 4px; }

/* ── CHAT INPUT — MOBILE KEYBOARD FIX ────────────────────────── */
.chat-input-area {
    background: var(--bg-panel);
    border-top: 1px solid var(--border);
    padding: 8px 10px;
    /* CRITICAL: safe-area for iPhone home bar */
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    position: relative;
    z-index: 10;
    flex-shrink: 0; /* never shrink — always visible */
}
.chat-input-row { display: flex; align-items: flex-end; gap: 6px; }
.input-attach { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
#messageInput {
    flex: 1; background: var(--bg-input); border: none;
    border-radius: var(--radius-lg); color: var(--text-primary);
    padding: 10px 14px; outline: none; resize: none;
    max-height: 120px; min-height: 42px; line-height: 1.5;
    overflow-y: auto; font-size: 15px;
    scrollbar-width: thin;
}
#messageInput::placeholder { color: var(--text-muted); }
.send-btn {
    width: 44px; height: 44px; min-width: 44px; min-height: 44px;
    background: var(--accent); border: none; border-radius: 50%;
    color: #fff; cursor: pointer; display: flex; align-items: center;
    justify-content: center; flex-shrink: 0;
    transition: background var(--transition), transform var(--transition);
    -webkit-tap-highlight-color: transparent;
}
.send-btn:hover { background: var(--accent-hover); transform: scale(1.05); }
.send-btn svg { width: 20px; height: 20px; }

/* Typing indicator */
#typingIndicator {
    display: none; padding: 4px 16px 2px;
    font-size: 12px; color: var(--text-muted);
    font-style: italic; background: var(--bg-panel);
    border-top: 1px solid var(--border); flex-shrink: 0;
}

/* Emoji picker */
.emoji-picker-wrap { position: absolute; bottom: 70px; left: 10px; z-index: 200; display: none; }
.emoji-picker-wrap.open { display: block; }

/* Pinned banner */
.pinned-banner {
    background: var(--bg-panel); border-left: 3px solid var(--accent);
    padding: 6px 12px; font-size: 12px; color: var(--text-secondary);
    display: flex; align-items: center; gap: 8px;
    cursor: pointer; flex-shrink: 0; position: relative; z-index: 10;
}
.pinned-banner:hover { background: var(--bg-hover); }
.pinned-banner .pin-icon { font-size: 14px; flex-shrink: 0; }
.pinned-banner .pin-text { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Slow mode */
.slow-mode-badge { display: inline-flex; align-items: center; gap: 4px; background: rgba(255,179,64,.15); color: var(--accent-warn); border-radius: 20px; padding: 2px 8px; font-size: 11px; font-weight: 600; }
.send-btn.slow-countdown { background: var(--bg-input); color: var(--text-muted); cursor: not-allowed; font-size: 12px; font-family: var(--font-mono); }

/* Empty state */
.empty-state { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; color: var(--text-muted); user-select: none; position: relative; z-index: 1; padding: 24px; text-align: center; }
.empty-state svg { width: 64px; height: 64px; opacity: .15; }
.empty-state h2 { font-size: 18px; font-weight: 600; color: var(--text-secondary); }

/* ═══════════════════════════════════════════════════════════════
   MODALS
   ═══════════════════════════════════════════════════════════════ */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.65); z-index: 500; align-items: flex-end; justify-content: center; backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
.modal-overlay.open { display: flex; }
.modal { background: var(--bg-secondary); border: 1px solid var(--border-light); border-radius: var(--radius-xl) var(--radius-xl) 0 0; padding: 20px 20px max(20px, env(safe-area-inset-bottom)); width: 100%; max-height: 92dvh; overflow-y: auto; -webkit-overflow-scrolling: touch; box-shadow: 0 -8px 40px rgba(0,0,0,.5); animation: slideUp .22s cubic-bezier(.4,0,.2,1); }
.modal::before { content: ''; display: block; width: 40px; height: 4px; background: var(--border-light); border-radius: 4px; margin: 0 auto 16px; }
@keyframes slideUp { from { opacity:0; transform:translateY(40px); } to { opacity:1; transform:translateY(0); } }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.modal-title { font-size: 17px; font-weight: 700; }
.modal-close { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 22px; line-height: 1; width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; flex-wrap: wrap; }

/* ═══════════════════════════════════════════════════════════════
   ADMIN LAYOUT
   ═══════════════════════════════════════════════════════════════ */
.admin-layout { display: flex; min-height: 100vh; min-height: 100dvh; }
.admin-sidebar { width: 220px; background: var(--bg-secondary); border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; }
.admin-sidebar .brand { padding: 16px 18px; font-size: 16px; font-weight: 700; color: var(--accent); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 8px; min-height: var(--header-height); }
.admin-nav { flex: 1; overflow-y: auto; }
.admin-nav a { display: flex; align-items: center; gap: 10px; padding: 12px 18px; color: var(--text-secondary); font-size: 14px; font-weight: 500; transition: all var(--transition); border-right: 3px solid transparent; -webkit-tap-highlight-color: transparent; }
.admin-nav a:hover, .admin-nav a.active { color: var(--text-primary); background: var(--bg-hover); border-right-color: var(--accent); }
.admin-content { flex: 1; padding: 24px; overflow-y: auto; -webkit-overflow-scrolling: touch; min-width: 0; }
.admin-topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; gap: 12px; flex-wrap: wrap; }
.page-title { font-size: 20px; font-weight: 700; }
.admin-menu-toggle { display: none; background: none; border: none; color: var(--text-primary); font-size: 24px; cursor: pointer; padding: 8px; -webkit-tap-highlight-color: transparent; }
.admin-mobile-header { display: none; align-items: center; justify-content: space-between; padding: 12px 16px; background: var(--bg-panel); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 50; }
.admin-sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 49; }
.admin-sidebar-overlay.open { display: block; }

/* Stat cards */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px,1fr)); gap: 12px; margin-bottom: 24px; }
.stat-card { background: var(--bg-secondary); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 16px; }
.stat-card .stat-value { font-size: 28px; font-weight: 700; color: var(--accent); font-family: var(--font-mono); line-height: 1; }
.stat-card .stat-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; margin-top: 6px; }

/* Data table */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: var(--radius-md); border: 1px solid var(--border); }
.data-table { width: 100%; border-collapse: collapse; background: var(--bg-secondary); min-width: 500px; }
.data-table th { padding: 10px 14px; background: var(--bg-panel); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table td { padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 13px; vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg-hover); }

/* Badges */
.badge { display: inline-block; padding: 2px 7px; border-radius: 20px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.badge-green  { background: rgba(0,168,132,.15); color: var(--accent-hover); }
.badge-red    { background: rgba(255,69,58,.15);  color: var(--accent-danger); }
.badge-yellow { background: rgba(255,179,64,.15); color: var(--accent-warn); }
.badge-gray   { background: rgba(134,150,160,.15); color: var(--text-secondary); }
.online-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); display: inline-block; margin-right: 4px; box-shadow: 0 0 5px var(--accent); }

/* Toast */
#toast-container { position: fixed; bottom: max(20px, env(safe-area-inset-bottom)); right: 16px; z-index: 9999; display: flex; flex-direction: column; gap: 6px; max-width: calc(100vw - 32px); }
.toast { background: var(--bg-panel); border: 1px solid var(--border-light); border-radius: var(--radius-sm); padding: 10px 16px; color: var(--text-primary); font-size: 13px; box-shadow: 0 6px 20px var(--shadow); animation: toastIn .25s ease; max-width: 300px; word-break: break-word; }
.toast.success { border-left: 3px solid var(--accent); }
.toast.error   { border-left: 3px solid var(--accent-danger); }
.toast.warn    { border-left: 3px solid var(--accent-warn); }
@keyframes toastIn { from { opacity:0; transform:translateX(16px); } to { opacity:1; transform:translateX(0); } }

/* Lightbox */
#lightbox { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 800; align-items: center; justify-content: center; padding: 16px; }
#lightbox.open { display: flex; }
#lightbox img { max-width: 100%; max-height: 90dvh; object-fit: contain; border-radius: 6px; }
#lightbox-close { position: fixed; top: 16px; right: 16px; background: rgba(0,0,0,.5); border: none; color: #fff; font-size: 28px; cursor: pointer; z-index: 801; width: 44px; height: 44px; border-radius: 50%; display: flex; align-items: center; justify-content: center; }

/* Reactions */
.reaction-bar { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; padding: 0 4px; }
.rx-pill { display: inline-flex; align-items: center; gap: 3px; background: var(--bg-panel); border: 1px solid var(--border-light); border-radius: 20px; padding: 2px 8px; font-size: 13px; cursor: pointer; transition: all var(--transition); color: var(--text-primary); font-family: var(--font-main); line-height: 1.4; min-height: 26px; -webkit-tap-highlight-color: transparent; }
.rx-pill:hover { background: var(--bg-hover); border-color: var(--accent); transform: scale(1.06); }
.rx-pill.rx-active { background: rgba(0,168,132,.18); border-color: var(--accent); color: var(--accent-hover); }
.rx-count { font-size: 11px; font-weight: 700; color: var(--text-secondary); }
.rx-picker { position: fixed; display: flex; gap: 3px; background: var(--bg-secondary); border: 1px solid var(--border-light); border-radius: 30px; padding: 5px 8px; box-shadow: 0 8px 32px rgba(0,0,0,.45); z-index: 400; animation: rxPickerIn .15s cubic-bezier(.34,1.56,.64,1); flex-wrap: wrap; max-width: 280px; }
@keyframes rxPickerIn { from { opacity:0; transform:scale(.7) translateY(6px); } to { opacity:1; transform:scale(1) translateY(0); } }
.rx-picker-btn { background: none; border: none; font-size: 22px; cursor: pointer; border-radius: 50%; width: 38px; height: 38px; display: flex; align-items: center; justify-content: center; transition: all var(--transition); -webkit-tap-highlight-color: transparent; }
.rx-picker-btn:hover { background: var(--bg-hover); transform: scale(1.22); }

/* Ad bubble */
.ad-bubble { background: linear-gradient(135deg, var(--bg-input), var(--bg-panel)); border: 1px solid var(--border-light); border-radius: 10px; padding: 10px; max-width: 260px; font-size: 13px; }
.ad-label { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 6px; font-weight: 700; }
.ad-title { font-weight: 700; font-size: 14px; margin-bottom: 4px; }
.ad-link { color: var(--accent); font-size: 12px; margin-top: 6px; display: block; }

/* Poll */
.poll-bubble { background: var(--bg-input); border-radius: 10px; padding: 12px; min-width: 220px; max-width: 280px; }
.poll-question { font-weight: 700; font-size: 14px; margin-bottom: 10px; }
.poll-option { display: flex; align-items: center; gap: 8px; background: var(--bg-panel); border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; margin-bottom: 6px; cursor: pointer; font-size: 13px; transition: all var(--transition); position: relative; overflow: hidden; }
.poll-option:hover { border-color: var(--accent); }
.poll-option.voted { border-color: var(--accent); background: rgba(0,168,132,.08); }
.poll-bar { position: absolute; left:0; top:0; bottom:0; background: rgba(0,168,132,.12); transition: width .4s ease; border-radius: 6px 0 0 6px; }
.poll-label { position: relative; flex: 1; }
.poll-pct { position: relative; font-size: 11px; color: var(--text-muted); font-weight: 700; }
.poll-footer { font-size: 11px; color: var(--text-muted); margin-top: 8px; }

/* Theme toggle */
.theme-toggle { background: none; border: none; cursor: pointer; font-size: 20px; line-height: 1; padding: 4px; border-radius: 50%; transition: transform .2s, background .15s; color: var(--text-secondary); min-width: 40px; min-height: 40px; display: flex; align-items: center; justify-content: center; }
.theme-toggle:hover { background: var(--bg-hover); transform: rotate(20deg); }

/* Light mode overrides */
html.light-mode .msg-time { color: rgba(17,27,33,.4); }
html.light-mode .outgoing .msg-time { color: rgba(17,27,33,.5); }
html.light-mode .rx-pill { background: #f0f2f5; border-color: #d1d7db; }
html.light-mode code { background: #f0f2f5; }
html.light-mode .data-table { background: #fff; }
html.light-mode .data-table th { background: #f0f2f5; }
html.light-mode .fmt-btn { background: #e9edef; }

/* Utility */
.text-center { text-align: center; }
.text-muted  { color: var(--text-muted); }
.text-sm     { font-size: 13px; }
.d-none      { display: none !important; }
.no-copy     { user-select: none; -webkit-user-select: none; }
.flex        { display: flex; }
.gap-8       { gap: 8px; }
.mt-12       { margin-top: 12px; }
code { background: rgba(0,0,0,.15); padding: 1px 5px; border-radius: 3px; font-family: var(--font-mono); font-size: 13px; }

/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE — TABLET (≤1024px)
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 1024px) {
    :root { --sidebar-width: 300px; }
    .admin-content { padding: 20px 16px; }
    .messages-container { padding: 12px 5%; }
}

/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE — MOBILE (≤768px)
   KEY FIX: input stays visible when Android keyboard opens.
   Strategy: app-container is position:fixed, sidebar and chat-area
   are position:absolute inside it. Flex column ensures input never
   goes below the visible area — the messages-container shrinks.
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    /* Contain everything in the visual viewport */
    .app-container {
        position: fixed;
        inset: 0;
        height: 100%;
        overflow: hidden;
    }

    /* Sidebar: full width, behind chat */
    .sidebar {
        position: absolute;
        inset: 0;
        width: 100%;
        min-width: 100%;
        z-index: 10;
    }

    /* Chat: slides in from right, absolute so keyboard resize works */
    .chat-area {
        position: absolute;
        inset: 0;
        z-index: 20;
        height: 100%;
        transform: translateX(100%);
        transition: transform .25s cubic-bezier(.4,0,.2,1);
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }
    .chat-area.open { transform: translateX(0); }

    /* Messages shrink when keyboard opens — CRITICAL */
    .messages-container {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        padding: 10px 3%;
    }

    /* Input area: always at bottom, above keyboard */
    .chat-input-area {
        flex-shrink: 0;
        position: relative;
        z-index: 21;
        padding-bottom: max(8px, env(safe-area-inset-bottom));
    }

    /* Formatting toolbar on mobile */
    .fmt-toolbar { overflow-x: auto; flex-wrap: nowrap; }

    /* Emoji picker: full width above keyboard */
    .emoji-picker-wrap {
        position: fixed;
        inset: auto 0 0 0;
        bottom: 0;
        z-index: 300;
        background: var(--bg-secondary);
        border-top: 1px solid var(--border);
    }

    /* Message bubbles */
    .msg-wrapper { max-width: 86%; }
    .msg-image, .msg-video { max-width: 220px; }

    /* Admin: stacked layout */
    .admin-layout { flex-direction: column; }
    .admin-sidebar { width: 100%; border-right: none; border-bottom: 1px solid var(--border); max-height: 0; overflow: hidden; transition: max-height .3s ease; }
    .admin-sidebar.open { max-height: 500px; }
    .admin-menu-toggle { display: flex; align-items: center; }
    .admin-mobile-header { display: flex; }
    .admin-content { padding: 14px 12px; }
    .admin-topbar { flex-direction: column; align-items: flex-start; gap: 10px; margin-bottom: 14px; }
    .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .page-title { font-size: 17px; }

    /* Touch targets */
    .icon-btn, .send-btn { min-width: 44px; min-height: 44px; }
}

/* ═══════════════════════════════════════════════════════════════
   RESPONSIVE — SMALL PHONE (≤640px)
   ═══════════════════════════════════════════════════════════════ */
@media (max-width: 640px) {
    .auth-card { padding: 24px 18px; border-radius: var(--radius-lg); }
    .chat-header { gap: 6px; padding: 6px 8px; }
    .chat-header-name { font-size: 14px; }
    .chat-input-area { padding: 6px 8px; padding-bottom: max(6px, env(safe-area-inset-bottom)); }
    .chat-input-row { gap: 4px; }
    #messageInput { min-height: 38px; padding: 8px 12px; }
    .send-btn { width: 42px; height: 42px; }
    .group-item { padding: 10px 12px; gap: 10px; }
    .group-icon { width: 42px; height: 42px; }
    .msg-wrapper { max-width: 90%; }
    .msg-bubble { font-size: 13.5px; padding: 6px 10px 18px; }
    .modal { padding: 16px 16px max(24px, env(safe-area-inset-bottom)); }
    .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
    .stat-card { padding: 12px; }
    .stat-card .stat-value { font-size: 24px; }
    #toast-container { right: 12px; left: 12px; max-width: 100%; }
    .toast { max-width: 100%; }
    .rx-picker { max-width: calc(100vw - 24px); }
}

/* ── Undo/Redo button states ───────────────────────────────── */
#undoBtn, #redoBtn { opacity: 0.3; transition: opacity .15s; }
#undoBtn:not([disabled]):hover, #redoBtn:not([disabled]):hover { background: var(--bg-hover); }

/* ── Poll bubble in messages ───────────────────────────────── */
.poll-bubble {
    background: var(--bg-input);
    border: 1px solid var(--border-light);
    border-radius: 10px;
    padding: 12px 14px;
    min-width: 200px;
    max-width: 280px;
    transition: background var(--transition);
}
.poll-bubble:hover { background: var(--bg-hover); }
.poll-question { font-weight: 700; font-size: 14px; margin-bottom: 10px; line-height: 1.4; }
.poll-option {
    display: flex; align-items: center; gap: 8px;
    background: var(--bg-panel); border: 1px solid var(--border);
    border-radius: 6px; padding: 8px 10px; margin-bottom: 6px;
    cursor: pointer; font-size: 13px; transition: all var(--transition);
    position: relative; overflow: hidden;
}
.poll-option:hover { border-color: var(--accent); }
.poll-option.voted { border-color: var(--accent); background: rgba(0,168,132,.08); }
.poll-bar { position: absolute; left:0; top:0; bottom:0; background: rgba(0,168,132,.12); transition: width .4s ease; }
.poll-label { position: relative; flex: 1; }
.poll-pct   { position: relative; font-size: 11px; color: var(--text-muted); font-weight: 700; white-space: nowrap; }
.poll-footer { font-size: 11px; color: var(--text-muted); margin-top: 8px; }

/* Light mode poll */
html.light-mode .poll-bubble { background: #f0f2f5; border-color: #d1d7db; }
html.light-mode .poll-option { background: #fff; }
html.light-mode .poll-option.voted { background: rgba(0,168,132,.06); }
