:root {
    --accent: #007fff;
    --accent-2: #2AABEE;
    --accent-3: #2AABEE;
    --bg: #ffffff;
    --bg-2: #f4f4f5;
    --bg-3: #e4e6eb;
    --bg-chat: #d9eef9;
    --bubble-in: #ffffff;
    --bubble-out: #effdde;
    --text: #000000;
    --text-2: #707579;
    --border: #e4e6eb;
    --danger: #e53935;
    --header-bg: #ffffff;
    --composer-bg: #ffffff;
    --hover: #f0f0f0;
    --shadow: 0 1px 2px rgba(0,0,0,.10);
}

[data-theme="dark"] {
    --accent: #64b5ef;
    --accent-2: #79c0ff;
    --accent-3: #00ffea;
    --bg: #17212b;
    --bg-2: #0e1621;
    --bg-3: #242f3d;
    --bg-chat: #0e1621;
    --bubble-in: #182533;
    --bubble-out: #2b5278;
    --text: #ffffff;
    --text-2: #8b98a9;
    --border: #101921;
    --header-bg: #17212b;
    --composer-bg: #17212b;
    --hover: #202b36;
    --shadow: 0 1px 2px rgba(0,0,0,.4);
}

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

html, body {
    height: 100%;
    width: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 15px;
    background: var(--bg-2);
    color: var(--text);
    -webkit-tap-highlight-color: transparent;
}

button, input, textarea {
    font-family: inherit;
    cursor: pointer;
    border: none;
    background: none;
    outline: none;
    color: inherit;
}
input, textarea { cursor: text; }
a { text-decoration: none; color: inherit; }

/* ========== APP ========== */
.app {
    position: fixed;
    inset: 0;
    display: flex;
    max-width: 1500px;
    margin: 0 auto;
    background: var(--bg);
    box-shadow: 0 0 24px rgba(0,0,0,.08);
    transition: background .2s;
}

/* ========== SIDEBAR ========== */
.sidebar {
    width: 380px;
    min-width: 300px;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    background: var(--bg);
    min-height: 0;
}
.sidebar-header {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    background: var(--header-bg);
    flex-shrink: 0;
}
.search {
    flex: 1;
    background: var(--bg-2);
    padding: 9px 14px;
    border-radius: 20px;
    font-size: 14px;
    color: var(--text);
    transition: background .15s, box-shadow .15s;
    min-width: 0;
}
.search::placeholder { color: var(--text-2); }
.search:focus { background: var(--bg-3); box-shadow: 0 0 0 2px var(--accent-2); }

.chat-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
}

.chat-item-wrap { position: relative; overflow: hidden; }
.chat-item-actions {
    position: absolute;
    top: 0; right: 0; bottom: 0;
    display: flex;
    align-items: stretch;
}
.act-btn {
    width: 84px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    background: var(--danger);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    user-select: none;
}
.act-btn:active { filter: brightness(1.15); }
.act-settings { background: #43a047; }

.chat-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    cursor: pointer;
    background: var(--bg);
    transition: background .15s, transform .2s ease;
}
.chat-item:hover { background: var(--hover); }
.chat-item.active { background: var(--accent); color: #fff; }
.chat-item.active .name,
.chat-item.active .preview,
.chat-item.active .time { color: #fff; }
.chat-item.active .badge { background: #fff; color: var(--accent); }

.avatar {
    width: 50px; height: 50px;
    border-radius: 50%;
    background: #ccc center/cover no-repeat;
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-weight: 600; font-size: 18px;
    overflow: hidden;
}

.chat-body { flex: 1; min-width: 0; }
.chat-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.chat-row + .chat-row { margin-top: 4px; }
.name { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.time { font-size: 12px; color: var(--text-2); flex-shrink: 0; }
.preview { font-size: 14px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.badge {
    background: var(--accent); color: #fff;
    font-size: 12px; font-weight: 600;
    min-width: 22px; height: 22px; border-radius: 11px;
    display: inline-flex; align-items: center; justify-content: center;
    padding: 0 6px; flex-shrink: 0;
}

/* ========== CHAT ========== */
.chat {
    flex: 1;
    min-height: 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-chat);
    overflow: hidden;
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    min-height: 58px;
    background: var(--header-bg);
    border-bottom: 1px solid var(--border);
    z-index: 2;
    flex-shrink: 0;
}
.chat-header .avatar { width: 42px; height: 42px; font-size: 16px; }
.chat-meta { line-height: 1.2; min-width: 0; }
.chat-title { font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-sub { font-size: 13px; color: var(--accent); }
.spacer { flex: 1; }

/* MESSAGES — iOS-safe scroller */
.messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 14px 4% 20px;
    scrollbar-width: thin;
    display: block;
}

/* ========== BUBBLES ========== */
.msg-row {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    margin-bottom: 6px;
}
.msg-row.in + .msg-row.in { margin-bottom: 2px; }
.msg-avatar-spacer { width: 34px; flex-shrink: 0; margin-bottom: 2px; }
.msg-row.out { justify-content: flex-end; }
.msg-avatar {
    width: 34px; height: 34px;
    border-radius: 50%;
    background: #ccc center/cover no-repeat;
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-weight: 600; font-size: 13px;
    overflow: hidden;
    margin-bottom: 2px;
}

.bubble {
    max-width: 68%;
    padding: 8px 12px 22px;
    border-radius: 12px;
    font-size: 15px;
    line-height: 1.4;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    box-shadow: var(--shadow);
    position: relative;
    animation: pop .16s ease-out;
}
@keyframes pop {
    from { transform: scale(.96); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

/* Block selection ONLY on the bubble when not in text-select mode */
.bubble:not(.text-selecting),
.bubble:not(.text-selecting) * {
    -webkit-user-select: none;
    user-select: none;
}

/* Text-select mode: enable full native selection */
.bubble.text-selecting,
.bubble.text-selecting * {
    -webkit-user-select: text !important;
    user-select: text !important;
    -webkit-touch-callout: default !important;
}

.bubble.in  { align-self: flex-start; background: var(--bubble-in);  border-bottom-left-radius: 4px;  color: var(--text); }
.bubble.out { align-self: flex-end;   background: var(--bubble-out); border-bottom-right-radius: 4px; color: var(--text); }

.bubble-text {
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}
.bubble-text p { margin: 0 0 6px; }
.bubble-text p:last-child { margin-bottom: 0; }
.bubble-text br { line-height: 1; }
.bubble-text a { color: var(--accent); text-decoration: underline; }
.bubble-text code {
    background: rgba(0,0,0,.08);
    padding: 1px 5px;
    border-radius: 4px;
    font-family: ui-monospace, Menlo, monospace;
    font-size: 13px;
}
[data-theme="dark"] .bubble-text code { background: rgba(255,255,255,.1); }
.bubble-text pre {
    background: rgba(0,0,0,.06);
    padding: 8px 10px;
    border-radius: 8px;
    overflow-x: auto;
    font-size: 13px;
    font-family: ui-monospace, Menlo, monospace;
    margin: 4px 0;
}
[data-theme="dark"] .bubble-text pre { background: rgba(0,0,0,.35); }
.bubble-text ul, .bubble-text ol { padding-left: 20px; margin: 4px 0; }
.bubble-text img { max-width: 100%; border-radius: 8px; }
.bubble-text b, .bubble-text strong { font-weight: 700; }
.bubble-text i, .bubble-text em { font-style: italic; }

/* ===== Telegram-style blockquote ===== */
.bubble-text blockquote {
    position: relative;
    margin: 6px 0;
    padding: 4px 0 4px 14px;
    border-left: 3px solid var(--accent);
    background: rgba(34,158,217,.06);
    border-radius: 0 6px 6px 0;
    color: inherit;
    font-style: normal;
    font-size: inherit;
    line-height: 1.45;
}
.bubble-text blockquote + blockquote {
    margin-top: 4px;
}
.bubble-text blockquote p {
    margin: 0 0 4px;
}
.bubble-text blockquote p:last-child {
    margin-bottom: 0;
}
.bubble-text blockquote strong,
.bubble-text blockquote b {
    color: var(--text);
    font-weight: 700;
}
.bubble-text blockquote code {
    background: rgba(34,158,217,.15);
    color: var(--accent);
    padding: 1px 6px;
    border-radius: 5px;
    font-size: 12.5px;
    font-family: ui-monospace, Menlo, monospace;
}
[data-theme="dark"] .bubble-text blockquote {
    background: rgba(100,181,239,.10);
    border-left-color: var(--accent);
}
[data-theme="dark"] .bubble-text blockquote code {
    background: rgba(100,181,239,.20);
    color: var(--accent-2);
}
.bubble.out .bubble-text blockquote {
    background: rgba(77,139,61,.08);
    border-left-color: #4d8b3d;
}
.bubble.out .bubble-text blockquote code {
    background: rgba(77,139,61,.18);
    color: #4d8b3d;
}
[data-theme="dark"] .bubble.out .bubble-text blockquote {
    background: rgba(100,200,150,.10);
    border-left-color: #a0c8a0;
}
[data-theme="dark"] .bubble.out .bubble-text blockquote code {
    background: rgba(100,200,150,.20);
    color: #a0c8a0;
}
.bubble-text blockquote blockquote {
    background: rgba(34,158,217,.10);
    border-left-color: var(--accent-2);
    margin-top: 4px;
    margin-bottom: 4px;
}
[data-theme="dark"] .bubble-text blockquote blockquote {
    background: rgba(100,181,239,.15);
}

/* ===== Copy tag: <copy>...</copy> ===== */
.bubble-text .copyable {
    color: var(--accent);
    cursor: pointer;
    letter-spacing: .5px;
    padding: 0 3px;
/*    border-radius: 4px; */
    transition: background .15s, color .15s;
}
.bubble-text .copyable:active {
    transform: scale(.94);
}
.bubble-text .copyable.copied {
background: var(--accent); color: #fff;
}

[data-theme="dark"] .bubble-text .copyable {
    color: var(--accent-2);
}
[data-theme="dark"] .bubble-text .copyable.copied {
    background: none !important;
    color: var(--text) !important;        
}

/* ===== Auto-link URLs ===== */
.bubble-text .auto-link {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 2px;
    word-break: break-all;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.bubble-text .auto-link:active {
    opacity: 0.65;
}
.bubble-text .auto-link:hover {
    color: var(--accent-2);
}

.bubble-img {
    display: block;
    max-width: 100%;
    border-radius: 10px;
    margin: -4px -6px 6px;
    max-height: 320px;
    object-fit: cover;
}

.bubble .ts {
    position: absolute;
    right: 10px; bottom: 5px;
    font-size: 11px;
    color: var(--text-2);
    user-select: none;
}
.bubble.out .ts { color: #4d8b3d; }
[data-theme="dark"] .bubble.out .ts { color: #a0c8a0; }

.bubble-tags {
    position: absolute;
    left: 10px; bottom: 4px;
    display: inline-flex;
    gap: 3px;
    background: rgba(255,255,255,.92);
    padding: 2px 6px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
[data-theme="dark"] .bubble-tags { background: rgba(0,0,0,.5); }
.bubble.out .bubble-tags { background: rgba(255,255,255,.75); }
.tag-pill { user-select: none; }

.bubble .card {
    color: var(--accent-3);
    cursor: pointer;
    letter-spacing: .5px;
    padding: 0 3px;
    border-radius: 4px;
    transition: background .15s, color .15s;
}
.bubble .card:hover { background: rgba(34,158,217,.10); }
.bubble .card.copied {
    background: var(--accent); color: #fff;

    }



.bubble.selected { outline: 2px solid var(--accent); outline-offset: 2px; }
body.select-mode .bubble { cursor: pointer; }
.bubble.flash { animation: flash 1.4s ease-out; }
@keyframes flash {
    0% { box-shadow: 0 0 0 0 rgba(34,158,217,.7); }
    50% { box-shadow: 0 0 0 8px rgba(34,158,217,0); }
    100% { box-shadow: 0 0 0 0 rgba(34,158,217,0); }
}

/* ========== COMPOSER ========== */
.composer {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    padding: 8px 12px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    background: var(--composer-bg);
    border-top: 1px solid var(--border);
    z-index: 2;
    flex-shrink: 0;
}
#composerInput {
    flex: 1;
    font-size: 15px;
    font-family: inherit;
    line-height: 1.4;
    padding: 11px 16px;
    background: var(--bg-2);
    border-radius: 22px;
    color: var(--text);
    cursor: text;
    resize: none;
    border: none;
    outline: none;
    min-height: 44px;
    max-height: 140px;
    overflow-y: auto;
    transition: background .15s, box-shadow .15s;
    -webkit-appearance: none;
    box-sizing: border-box;
    min-width: 0;
}
#composerInput::placeholder { color: var(--text-2); }
#composerInput:focus { background: var(--bg); box-shadow: 0 0 0 2px var(--accent-2); }

.icon-btn {
    width: 42px; height: 42px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    color: var(--text-2);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background .15s, color .15s, transform .1s;
    flex-shrink: 0;
    background: none;
    border: none;
    padding: 0;
}
.icon-btn:hover { background: var(--hover); color: var(--accent); }
.icon-btn:active { transform: scale(.92); }
/* send button: see TELEGRAM SEND BUTTON block below */

.theme-toggle svg { transition: transform .3s; }
.theme-toggle:active svg { transform: rotate(30deg); }

/* ========== CONTEXT MENU ========== */
.ctx-menu {
    position: fixed;
    background: var(--bg);
    border-radius: 12px;
    box-shadow: 0 6px 32px rgba(0,0,0,.28);
    padding: 6px;
    z-index: 9999;
    display: none;
    min-width: 230px;
    font-size: 14px;
    user-select: none;
    border: 1px solid var(--border);
}
.ctx-menu button {
    display: flex; align-items: center; gap: 12px;
    width: 100%; text-align: left;
    padding: 9px 12px; border-radius: 8px;
    cursor: pointer; font-size: 14px;
    color: var(--text);
    transition: background .12s;
    background: none; border: none;
}
.ctx-menu button svg { flex-shrink: 0; color: var(--text-2); }
.ctx-menu button:hover { background: var(--hover); color: var(--accent); }
.ctx-menu button:hover svg { color: var(--accent); }
.ctx-menu button.danger { color: var(--danger); }
.ctx-menu button.danger svg { color: var(--danger); }
.ctx-menu button.danger:hover { background: rgba(229,57,53,.1); }
.ctx-menu hr { border: none; border-top: 1px solid var(--border); margin: 4px 6px; }

/* ========== REACTION BAR ========== */
.tag-picker {
    position: fixed;
    display: flex;
    align-items: center;
    gap: 4px;
    background: var(--bg);
    padding: 6px 8px;
    border-radius: 30px;
    box-shadow: 0 8px 32px rgba(0,0,0,.30);
    z-index: 10000;
    animation: pop .15s ease-out;
    border: 1px solid var(--border);
}
.tag-picker button {
    font-size: 22px;
    line-height: 1;
    padding: 4px 6px;
    border-radius: 50%;
    cursor: pointer;
    transition: background .12s, transform .12s;
    background: none; border: none;
}
.tag-picker button:hover { background: var(--hover); transform: scale(1.20); }
.tag-picker button.selected { background: rgba(34,158,217,.15); box-shadow: inset 0 0 0 2px var(--accent); }
.tag-picker .more {
    background: var(--bg-2);
    border-radius: 50%;
    width: 26px; height: 26px;
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer; font-size: 12px; color: var(--text-2);
    flex-shrink: 0;
}

/* ========== SELECTION BAR ========== */
.sel-bar {
    position: fixed; left: 50%; bottom: 24px;
    transform: translate(-50%, 100px);
    background: var(--accent); color: #fff;
    padding: 10px 14px;
    border-radius: 30px;
    display: flex; align-items: center; gap: 10px;
    box-shadow: 0 8px 32px rgba(34,158,217,.4);
    transition: transform .25s;
    z-index: 9998;
    font-size: 14px;
}
.sel-bar.show { transform: translate(-50%, 0); }
.sel-bar span { padding: 0 8px; font-weight: 500; }
.sel-bar button {
    background: rgba(255,255,255,.2);
    color: #fff;
    padding: 8px 14px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    border: none;
}
.sel-bar button:hover { background: rgba(255,255,255,.35); }

/* ========== TOAST ========== */
#toast {
    position: fixed; left: 50%; bottom: 40px;
    transform: translate(-50%, 60px);
    background: rgba(0,0,0,.85);
    color: #fff;
    padding: 10px 18px;
    border-radius: 20px;
    font-size: 13px;
    opacity: 0;
    transition: opacity .2s, transform .2s;
    pointer-events: none;
    z-index: 10000;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ========== TEXT SELECT BAR ========== */
.seltext-bar {
    position: fixed; left: 50%; bottom: 84px;
    transform: translate(-50%, 120px);
    background: var(--bg); color: var(--text);
    border: 1px solid var(--border);
    padding: 7px 10px 7px 16px;
    border-radius: 26px;
    display: flex; align-items: center; gap: 8px;
    box-shadow: 0 8px 30px rgba(0,0,0,.20);
    transition: transform .2s;
    z-index: 9999;
    font-size: 13px;
    max-width: calc(100vw - 24px);
}
.seltext-bar.show { transform: translate(-50%, 0); }
.seltext-bar span { color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 110px; }
.seltext-bar button {
    background: var(--accent); color: #fff;
    padding: 8px 16px; border-radius: 18px;
    font-size: 13px; font-weight: 600; flex-shrink: 0;
    border: none;
}
.seltext-bar #selTextDone { background: var(--bg-2); color: var(--text); }

/* ========== BOTFATHER POPUP ========== */
.bot-overlay {
    position: fixed; inset: 0;
    display: flex; align-items: center; justify-content: center;
    z-index: 10001;
    opacity: 0; pointer-events: none;
    transition: opacity .2s;
    padding: 16px;
}
.bot-overlay.show { opacity: 1; pointer-events: auto; }
.bot-overlay-card {
    background: #f4f4f5;
    border-radius: 12px;
    width: 100%; max-width: 395px;
    height: min(660px, 92dvh);
    position: relative;
    overflow: hidden;
    box-shadow: 0 16px 60px rgba(0,0,0,.5);
    transform: translateY(14px) scale(.97);
    transition: transform .2s;
    display: flex; flex-direction: column;
}
.bot-overlay.show .bot-overlay-card { transform: none; }
.bot-overlay-card iframe { flex: 1; width: 100%; border: 0; background: transparent; }
.bot-overlay-close {
    position: absolute; top: 10px; right: 10px; z-index: 2;
    width: 36px; height: 36px; border-radius: 50%;
    background: rgba(128,128,128,.25);
    color: var(--text); font-size: 20px; line-height: 1;
    cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    border: none;
}
.bot-overlay-close:hover { background: rgba(128,128,128,.4); }



/* ============================================================
   MERGED FROM admin.css (admin pages share this one file now)
   ============================================================ */
button, input, select { font-family: inherit; }

/* ============================================================
   TELEGRAM SEND BUTTON + COMPOSER
   ============================================================ */
.composer { align-items: flex-end; gap: 8px; padding: 8px 10px; }
#composerInput { border-radius: 22px; padding: 11px 16px; background: var(--bg-2); }
.icon-btn.send {
    width: 44px; height: 44px;
    background: var(--accent);
    color: #fff;
    border: none;
    box-shadow: 0 2px 8px rgba(0,0,0,.18);
    opacity: .55;
    transform: scale(.94);
    transition: opacity .18s, transform .18s, background .15s, box-shadow .15s;
}
.icon-btn.send svg { width: 24px; height: 24px; margin-left: -2px; transform: rotate(0deg); }
.icon-btn.send.ready { opacity: 1; transform: scale(1); }
.icon-btn.send:hover { background: var(--accent); color: #fff; filter: brightness(1.08); }
.icon-btn.send:active { transform: scale(.9); }

/* ============================================================
   LOGOUT BUTTON
   ============================================================ */
.logout-form { display: inline-flex; margin: 0; }
.logout-form .icon-btn:hover { color: var(--danger); background: rgba(229,57,53,.10); }

/* ============================================================
   WELCOME / EMPTY STATE inside #messages
   ============================================================ */
.messages.is-empty {
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
}
.welcome {
    display: flex; flex-direction: column; align-items: center;
    text-align: center;
    max-width: 340px; width: 100%;
    margin: auto;
    padding: 24px 20px;
    background: rgba(0,0,0,.18);
    border-radius: 18px;
    color: #fff;
    -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
[data-theme="light"] .welcome { background: rgba(255,255,255,.55); color: var(--text); }
.welcome-logo {
    width: 84px; height: 84px; border-radius: 50%;
    background: var(--accent); color: #fff;
    display: flex; align-items: center; justify-content: center;
    overflow: hidden; margin-bottom: 14px;
    box-shadow: 0 6px 20px rgba(0,0,0,.2);
}
.welcome-logo img { width: 100%; height: 100%; object-fit: cover; }
.welcome-logo svg { width: 62%; height: 62%; }
.welcome-title { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.welcome-sub { font-size: 14px; opacity: .8; margin-bottom: 14px; }
.welcome-list { list-style: none; width: 100%; text-align: left; display: flex; flex-direction: column; gap: 8px; }
.welcome-list li { display: flex; flex-direction: column; font-size: 13px; line-height: 1.35; }
.welcome-list li b { font-size: 13px; color: var(--accent-2); }
.welcome-list li span { opacity: .85; }
.welcome:has(.welcome-sub:only-child) { background: none; backdrop-filter: none; -webkit-backdrop-filter: none; }



/* avatars: gradient set from JS, keep text crisp */
.avatar, .msg-avatar { text-shadow: 0 1px 2px rgba(0,0,0,.2); }


/* ============================================================================
   BOTFATHER PAGES (admin.php + settings.php) — shared theme: light + dark
   Follows the app theme: <html data-theme="light|dark"> (localStorage "tg-theme")
   ============================================================================ */
body.page-bf {
    --bf-w: 420px;
    --bf-bg: #f4f4f5;      --bf-header: #ffffff;   --bf-text: #1a1a1a;     --bf-muted: #707579;
    --bf-input: #ffffff;   --bf-border: #dadce0;   --bf-border-2: #c3c8cf; --bf-card: #ffffff;
    --bf-chev: #a0a8b3;    --bf-ph: #8b98a9;       --bf-token-text: #3b4754;
    --bf-hover: rgba(0,0,0,.04); --bf-hover-2: rgba(0,0,0,.08);
    --bf-err-bg: #fdecea;  --bf-err-text: #c62828; --bf-ok-bg: #d1f4d8;    --bf-ok-text: #1b5e20;
}
html[data-theme="dark"] body.page-bf {
    --bf-bg: #0e1621;      --bf-header: #17212b;   --bf-text: #ffffff;     --bf-muted: #8b98a9;
    --bf-input: #242f3d;   --bf-border: #2b3a4a;   --bf-border-2: #3a4a5a; --bf-card: #1c2733;
    --bf-chev: #4d6275;    --bf-ph: #6b7d8f;       --bf-token-text: #b8c6d4;
    --bf-hover: rgba(255,255,255,.04); --bf-hover-2: rgba(255,255,255,.08);
    --bf-err-bg: #3a1c1c;  --bf-err-text: #ff8a80; --bf-ok-bg: #1c3a2a;    --bf-ok-text: #7ee2a8;
}

/* ============================================================================
   LOGIN PAGE (login.php)
   ============================================================================ */
body.page-login {
    --accent-soft: color-mix(in srgb, var(--accent) 10%, transparent);
    --accent-soft-hover: color-mix(in srgb, var(--accent) 18%, transparent);
    --bg: #ffffff;  --bg-2: #f4f4f5;
    --text: #1a1a1a; --text-2: #707579; --text-3: #8b98a9;
    --border: #dadce0; --border-hover: var(--accent);
    --input-bg: #ffffff; --input-bg-focus: #ffffff; --input-border: #dadce0;
    --label-bg: #ffffff; --label-color: #707579; --label-active: var(--accent);
    --logo-shadow: 0 4px 20px color-mix(in srgb, var(--accent) 25%, transparent);
    --error-bg: #fdecea; --error-text: #c62828;
    --ok-bg: #d1f4d8;    --ok-text: #1b5e20;
}

html[data-theme="dark"] body.page-login {
    --bg: #0e1621; --bg-2: #17212b;
    --text: #ffffff; --text-2: #8b98a9; --text-3: #6b7d8f;
    --border: #2b3a4a; --border-hover: var(--accent);
    --input-bg: #242f3d; --input-bg-focus: #242f3d; --input-border: #2b3a4a;
    --label-bg: #0e1621; --label-color: #8b98a9; --label-active: var(--accent);
    --logo-shadow: 0 4px 20px rgba(0,0,0,.45);
    --error-bg: #3a1c1c; --error-text: #ff8a80;
    --ok-bg: #1c3a2a;    --ok-text: #7ee2a8;
}

body.page-login {
    height: 100%; width: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg); color: var(--text);
    -webkit-tap-highlight-color: transparent;
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
    transition: background .25s ease, color .25s ease;
}

body.page-login .login-wrap {
    position: fixed; inset: 0;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    padding: 24px; overflow-y: auto;
}

body.page-login .login-box {
    width: 100%; max-width: 380px;
    display: flex; flex-direction: column; align-items: center;
}

body.page-login .theme-btn {
    position: fixed;
    top: calc(16px + env(safe-area-inset-top, 0px));
    right: 16px;
    width: 42px; height: 42px; border-radius: 50%;
    background: var(--bg-2); border: 1px solid var(--border);
    color: var(--text-2);
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer; z-index: 100;
    transition: background .15s, color .15s, transform .15s, border-color .15s;
    -webkit-appearance: none;
}

body.page-login .theme-btn:hover { background: var(--accent-soft); color: var(--accent); border-color: var(--accent);
}

body.page-login .theme-btn:active { transform: scale(.92);
}

body.page-login .theme-btn svg { display: block; pointer-events: none;
}

body.page-login .tg-logo {
    width: 120px; height: 120px; border-radius: 50%;
    background: var(--accent);
    display: flex; align-items: center; justify-content: center;
    margin-bottom: 24px;
    box-shadow: var(--logo-shadow);
    overflow: hidden;
}

body.page-login .tg-logo img { width: 100%; height: 100%; object-fit: cover;
}

body.page-login .tg-logo svg { width: 62%; height: 62%; color: #fff;
}

body.page-login .login-title {
    font-size: 26px; font-weight: 700; color: var(--text);
    margin-bottom: 10px; letter-spacing: -.4px; text-align: center;
}

body.page-login .login-sub {
    font-size: 14px; color: var(--text-2); text-align: center;
    line-height: 1.45; margin-bottom: 28px; max-width: 300px;
}

body.page-login .field { position: relative; width: 100%; margin-bottom: 14px;
}

body.page-login .field input {
    width: 100%;
    padding: 18px 16px 8px;
    border: 1px solid var(--input-border);
    border-radius: 100px;
    font-size: 16px; font-family: inherit;
    background: var(--input-bg); color: var(--text);
    outline: none;
    transition: border-color .15s, box-shadow .15s, background .15s, color .15s;
    -webkit-appearance: none;
    height: 56px;
}

body.page-login .field input::placeholder { color: transparent;
}

body.page-login .field label {
    position: absolute; left: 12px; top: 50%;
    transform: translateY(-50%);
    padding: 0 5px; background: var(--label-bg);
    color: var(--label-color); font-size: 16px;
    pointer-events: none; white-space: nowrap;
    transition: top .12s ease, font-size .12s ease, color .12s ease;
}

body.page-login .field input:focus + label,
body.page-login .field input:not(:placeholder-shown) + label {
    top: 0; font-size: 12px; color: var(--label-active); font-weight: 500;
}

body.page-login .field input:focus { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent);
}

body.page-login .field input:-webkit-autofill,
body.page-login .field input:-webkit-autofill:hover,
body.page-login .field input:-webkit-autofill:focus {
    -webkit-box-shadow: 0 0 0 30px var(--input-bg) inset !important;
    -webkit-text-fill-color: var(--text) !important;
    transition: background-color 9999s ease-in-out 0s;
}

body.page-login .login-btn {
    width: 100%; padding: 14px; margin-top: 8px;
    background: transparent; color: var(--accent);
    border: 1px solid var(--accent); border-radius: 100px;
    font-size: 16px; font-weight: 600; font-family: inherit;
    cursor: pointer; letter-spacing: .2px;
    transition: filter .15s, transform .08s, background .15s, color .15s;
    -webkit-appearance: none;
}

body.page-login .login-btn:hover { background: var(--accent-soft-hover); color: var(--accent);
}

body.page-login .login-btn:active { transform: scale(.985);
}

body.page-login .alert {
    width: 100%; padding: 12px 16px; border-radius: 10px;
    background: var(--error-bg); color: var(--error-text);
    font-size: 13px; margin-bottom: 16px;
    text-align: center; font-weight: 500;
}

body.page-login .alert.ok { background: var(--ok-bg); color: var(--ok-text);
}

body.page-login .login-foot {
    position: absolute;
    bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    left: 0; right: 0;
    text-align: center; font-size: 12px;
    color: var(--text-3); padding: 0 24px;
}

body.page-login .login-foot a { color: var(--accent); text-decoration: none;
}

@media (max-width: 420px) {
body.page-login .login-wrap { padding: 20px;
}

body.page-login .tg-logo { width: 100px; height: 100px; margin-bottom: 20px;
}

body.page-login .login-title { font-size: 24px;
}
}



/* ---------- BotFather / Settings overlay (opened from index.php) ---------- */
html[data-theme="dark"] .bot-overlay-card { background: #0e1621; }
@media (max-width: 760px) {
    .bot-overlay { padding: 0; }
    .bot-overlay-card { max-width: none; height: 100%; height: 100dvh; border-radius: 0; }
}
@media (min-width: 761px) {
    .bot-overlay-card { max-width: 460px; height: min(720px, 92dvh); }
}

/* ============================================================================
   v2 — SHELL: one flex layout for phone + desktop
   --vvh / --vvt come from core.js (visual viewport: the area NOT covered by the keyboard)
   ============================================================================ */
[hidden] { display: none !important; }
.app { inset: auto; left: 0; right: 0; top: var(--vvt, 0px); height: var(--vvh, 100%); }
.sidebar { position: relative; }
.messages { overscroll-behavior: contain; display: block; }
.avatar.online { overflow: visible; position: relative; }
.avatar.online::after { content: ''; position: absolute; right: 0; bottom: 1px; width: 12px; height: 12px; border-radius: 50%; background: #4cd964; border: 2px solid var(--bg); }
.chat-header .avatar.online::after { border-color: var(--header-bg); }
.avatar, .msg-avatar { text-shadow: 0 1px 2px rgba(0,0,0,.2); }

/* empty state of the desktop chat pane */
.chat-empty { display: none; flex: 1; align-items: center; justify-content: center; padding: 20px; }
.chat.is-empty .chat-empty { display: flex; }
.chat.is-empty .chat-header, .chat.is-empty .messages, .chat.is-empty .composer { display: none; }

@media (max-width: 760px) {
    html, body { overflow: hidden; }
    .app { display: block; overflow: hidden; max-width: none; box-shadow: none; }
    .sidebar { position: absolute; inset: 0; width: 100%; min-width: 0; border-right: none; overflow: hidden; }
    .app:not(.chat-only) .chat { display: none; }
    .app.chat-only .sidebar { display: none; }
    .app.chat-only .chat { position: absolute; inset: 0; display: flex; }
    .sidebar-header { padding-top: calc(8px + env(safe-area-inset-top, 0px)); }
    .chat-header { padding-top: calc(8px + env(safe-area-inset-top, 0px)); min-height: calc(58px + env(safe-area-inset-top, 0px)); }
    .messages { padding: 12px 10px 16px; }
    .bubble { max-width: 84%; }
    #composerInput { font-size: 16px; max-height: 100px; }     /* 16px: iOS never zooms into the field */
    body.kb-open .composer { padding-bottom: 8px; }             /* no home-indicator gap above the keyboard */
    .ctx-menu { min-width: 200px; max-width: calc(100vw - 16px); }
}
@media (min-width: 761px) {
    .app:not(.chat-only) #chatBack { display: none; }
    .app.chat-only .sidebar { display: none; }
    .app.chat-only .chat { max-width: 920px; margin: 0 auto; border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
    .bubble { max-width: 70%; }
}

/* ---------- sidebar header, FAB, badges ---------- */
.sidebar-header { gap: 6px; }
.has-badge { position: relative; }
.dot-badge { position: absolute; top: 3px; right: 1px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.fab { position: absolute; right: 18px; bottom: calc(18px + env(safe-area-inset-bottom, 0px)); width: 56px; height: 56px; border-radius: 50%; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; box-shadow: 0 4px 14px rgba(0,0,0,.28); cursor: pointer; z-index: 5; transition: transform .12s, filter .15s; }
.fab:hover { filter: brightness(1.08); }
.fab:active { transform: scale(.92); }
.list-empty { text-align: center; color: var(--text-2); padding: 40px 24px; line-height: 1.6; font-size: 14px; }
.chat-list { padding-bottom: 90px; }

/* ---------- chat list items ---------- */
.chat-item .name { display: flex; align-items: center; gap: 5px; min-width: 0; font-weight: 600; }
.chat-item .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .kind, .chat-item .pin, .chat-item .muted-ico { display: inline-flex; color: var(--text-2); flex-shrink: 0; }
.chat-item .kind svg, .chat-item .pin svg { width: 15px; height: 15px; }
.chat-item .muted-ico svg { width: 16px; height: 16px; }
.chat-item.active .kind, .chat-item.active .pin, .chat-item.active .muted-ico { color: #fff; }
.badge.muted { background: var(--text-2); }
.act-mute { background: #7a8a99; }

/* ---------- chat header ---------- */
.chat-sub { color: var(--text-2); }
.chat-sub.is-online { color: var(--accent); }
.chat-header .chat-meta { flex: 1 1 auto; }
.chat-header .spacer { flex: 0; }
.chat-header > .icon-btn:last-child { margin-left: auto; }

/* ---------- messages: day separators, system lines, group sender names ---------- */
.day-sep { text-align: center; margin: 12px 0 8px; position: sticky; top: 4px; z-index: 1; }
.day-sep span, .sys-msg span { display: inline-block; background: rgba(0,0,0,.30); color: #fff; font-size: 12.5px; padding: 3px 12px; border-radius: 14px; backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.sys-msg { text-align: center; margin: 8px 0; }
.sys-msg span { font-size: 12.5px; max-width: 90%; }
.sender-name { font-size: 13px; font-weight: 600; margin-bottom: 2px; }
.bubble.pending { opacity: .65; }
.load-older { display: block; margin: 4px auto 10px; padding: 7px 16px; border-radius: 16px; background: rgba(0,0,0,.28); color: #fff; font-size: 13px; }
.empty-note { text-align: center; color: var(--text-2); padding: 60px 20px; font-size: 14px; }
.chat-empty .welcome { background: rgba(0,0,0,.12); }
[data-theme="light"] .chat-empty .welcome { background: rgba(255,255,255,.6); }

/* ---------- popover menu (hamburger, FAB, chat menu) ---------- */
.pop-menu { position: fixed; z-index: 10000; min-width: 230px; max-width: calc(100vw - 16px); background: var(--bg); color: var(--text); border-radius: 14px; box-shadow: 0 8px 30px rgba(0,0,0,.28); padding: 6px; border: 1px solid var(--border); animation: popin .12s ease-out; }
@keyframes popin { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: none; } }
.pop-menu hr { border: 0; border-top: 1px solid var(--border); margin: 5px 0; }
.pop-menu button { display: flex; align-items: center; gap: 12px; width: 100%; padding: 11px 12px; border-radius: 9px; font-size: 15px; text-align: left; color: var(--text); }
.pop-menu button:hover { background: var(--hover); }
.pop-menu button svg { color: var(--text-2); flex-shrink: 0; }
.pop-menu button.danger, .pop-menu button.danger svg { color: var(--danger); }
.pop-badge { margin-left: auto; font-style: normal; background: var(--danger); color: #fff; font-size: 12px; font-weight: 700; min-width: 20px; padding: 1px 6px; border-radius: 10px; text-align: center; }
.pop-profile { display: flex; align-items: center; gap: 12px; padding: 8px 8px 4px; }
.pop-profile .avatar { width: 46px; height: 46px; font-size: 17px; }
.pp-name { font-weight: 700; font-size: 16px; }
.pp-sub { font-size: 13px; color: var(--text-2); }
.pop-menu .pop-chatid { margin: 4px 6px 2px; width: calc(100% - 12px); padding: 8px 10px; background: var(--bg-2); border-radius: 9px; font-size: 13px; color: var(--text-2); justify-content: space-between; }
.pop-menu .pop-chatid b { color: var(--text); letter-spacing: .5px; }

/* ---------- sign-in pages ---------- */
body.page-login .login-wrap { justify-content: flex-start; }
body.page-login .login-box { margin: auto 0; padding-bottom: 8px; }
body.page-login .login-foot { position: static; margin-top: 18px; padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px)); }
body.page-login .login-alt { margin-top: 18px; font-size: 14px; color: var(--text-2); text-align: center; }
body.page-login .login-alt a { color: var(--accent); font-weight: 600; text-decoration: none; }
body.page-login .login-btn.ghost { border-color: var(--border); color: var(--text-2); margin-top: 4px; }
body.page-login .code-input { text-align: center; letter-spacing: 8px; font-size: 24px; font-weight: 700; }

/* ============================================================================
   TOOL PAGES (people, group, my bots, settings) — theme variables --bf-* are defined above
   ============================================================================ */
body.page-tool { overflow: hidden; background: var(--bf-bg); color: var(--bf-text); }
.tl-wrap { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--bf-bg); color: var(--bf-text); }
.tl-header { display: flex; align-items: center; gap: 6px; padding: 8px 10px; padding-top: calc(8px + env(safe-area-inset-top, 0px)); background: var(--bf-header); border-bottom: 1px solid var(--bf-border); flex-shrink: 0; }
.tl-header h1 { flex: 1; min-width: 0; font-size: 18px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tl-back { width: 42px; height: 42px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; color: var(--bf-muted); text-decoration: none; cursor: pointer; flex-shrink: 0; }
.tl-back:hover { background: var(--bf-hover-2); }
.tl-scroll { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.tl-body { max-width: 560px; margin: 0 auto; padding: 14px 14px calc(34px + env(safe-area-inset-bottom, 0px)); }
.tl-body .avatar { font-size: 17px; }
.tl-body .avatar.big { width: 96px; height: 96px; font-size: 36px; margin: 0 auto 10px; }

.tl-tabs { display: flex; gap: 4px; background: var(--bf-header); border: 1px solid var(--bf-border); border-radius: 12px; padding: 4px; margin-bottom: 12px; }
.tl-tabs button { flex: 1; padding: 9px 6px; border-radius: 9px; font-size: 14px; font-weight: 600; color: var(--bf-muted); display: flex; align-items: center; justify-content: center; gap: 6px; }
.tl-tabs button.on { background: var(--accent); color: #fff; }
.tl-tabs em { font-style: normal; background: var(--danger); color: #fff; font-size: 11px; min-width: 18px; padding: 1px 5px; border-radius: 9px; }

.tl-row { display: flex; align-items: center; gap: 12px; padding: 10px 4px; border-bottom: 1px solid var(--bf-border); color: var(--bf-text); text-decoration: none; }
.tl-row:last-child { border-bottom: 0; }
.tl-row .avatar { width: 46px; height: 46px; }
.tl-row-main { flex: 1; min-width: 0; }
.tl-row-name { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tl-row-sub { font-size: 13px; color: var(--bf-muted); margin-top: 1px; }
.tl-row-btns { display: flex; gap: 6px; flex-shrink: 0; flex-wrap: wrap; justify-content: flex-end; }
.tl-link:hover { background: var(--bf-hover); }
.tl-chev { color: var(--bf-chev); font-size: 24px; }
.tl-check { cursor: pointer; }
.tl-check input { width: 20px; height: 20px; accent-color: var(--accent); flex-shrink: 0; }

.tl-btn { display: inline-flex; align-items: center; justify-content: center; padding: 8px 15px; border-radius: 18px; border: 1px solid var(--bf-border); background: var(--bf-header); color: var(--bf-text); font-size: 14px; font-weight: 600; cursor: pointer; text-decoration: none; transition: filter .15s, transform .08s; }
.tl-btn:hover { filter: brightness(.97); }
.tl-btn:active { transform: scale(.97); }
.tl-btn:disabled { opacity: .55; cursor: default; }
.tl-btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.tl-btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.tl-btn.wide { display: flex; width: 100%; margin-top: 10px; padding: 13px; border-radius: 14px; font-size: 15px; }
form + form .tl-btn.wide, .tl-btn.wide + .tl-btn.wide { margin-top: 10px; }

.tl-input { width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--bf-border); background: var(--bf-input); color: var(--bf-text); font-size: 16px; margin-bottom: 8px; outline: none; font-family: inherit; }
.tl-input:focus { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.tl-input::placeholder { color: var(--bf-ph); }
input[type="color"] { width: 48px; height: 46px; border: 1px solid var(--bf-border); border-radius: 12px; background: var(--bf-input); padding: 3px; cursor: pointer; }
.tl-label { display: block; font-size: 13px; font-weight: 600; color: var(--bf-muted); margin: 12px 2px 6px; }
.tl-section { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--bf-muted); margin: 20px 4px 8px; }
.tl-hint, .tl-hint-inline { font-size: 12.5px; color: var(--bf-muted); line-height: 1.5; font-weight: 400; text-transform: none; letter-spacing: 0; }
.tl-hint { margin: 4px 2px 8px; }
.tl-card { background: var(--bf-header); border: 1px solid var(--bf-border); border-radius: 16px; padding: 14px; margin-bottom: 12px; }
.tl-profile { text-align: center; }
.tl-profile h2 { font-size: 20px; margin: 4px 0 2px; }
.tl-profile-btns { display: flex; gap: 8px; justify-content: center; margin-top: 14px; flex-wrap: wrap; }
.tl-empty { text-align: center; color: var(--bf-muted); padding: 28px 12px; line-height: 1.6; font-size: 14px; }
.tl-alert { background: var(--bf-err-bg); color: var(--bf-err-text); padding: 11px 14px; border-radius: 12px; margin-bottom: 12px; font-size: 14px; }
.tl-pill { display: inline-block; font-style: normal; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 10px; background: var(--bf-hover-2); color: var(--bf-muted); text-transform: none; letter-spacing: 0; vertical-align: middle; }
.tl-pill.ok { background: var(--bf-ok-bg); color: var(--bf-ok-text); }
.tl-pill.off { background: var(--bf-err-bg); color: var(--bf-err-text); }
.tl-copy { display: block; width: 100%; text-align: left; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13.5px; padding: 11px 13px; border-radius: 12px; background: var(--bf-card); border: 1px dashed var(--bf-border-2); color: var(--bf-token-text); word-break: break-all; cursor: pointer; margin-bottom: 4px; }
.tl-copy.small { display: inline-block; width: auto; padding: 4px 9px; margin: 0; }
.tl-copy:active { background: var(--bf-hover-2); }
.tl-code { background: var(--bf-card); border: 1px solid var(--bf-border); border-radius: 12px; padding: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; white-space: pre-wrap; word-break: break-all; color: var(--bf-token-text); }
.tl-inline { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.tl-inline .tl-input { margin-bottom: 0; flex: 1; }
.tl-kv { display: flex; justify-content: space-between; align-items: center; padding: 11px 2px; border-top: 1px solid var(--bf-border); font-size: 14px; }
.tl-kv span { color: var(--bf-muted); }
.tl-spacer { height: 16px; }
.tl-form .tl-btn.wide { margin-top: 14px; }
.tl-check-inline { display: flex; gap: 8px; align-items: center; font-size: 14px; margin: 8px 2px; }
.tl-profile-edit { display: flex; align-items: center; gap: 16px; margin-bottom: 6px; }
.tl-profile-edit .avatar.big { margin: 0; }
.tl-profile-edit-btns { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--bf-hover-2); padding: 1px 5px; border-radius: 5px; font-size: .92em; }

.tl-switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 2px; border-bottom: 1px solid var(--bf-border); cursor: pointer; position: relative; }
.tl-switch-row small { display: block; color: var(--bf-muted); font-size: 12.5px; margin-top: 2px; }
.tl-switch-row.is-disabled { opacity: .55; cursor: default; }
.tl-switch-row input { position: absolute; opacity: 0; pointer-events: none; }
.tl-switch { width: 46px; height: 28px; border-radius: 14px; background: var(--bf-border-2); position: relative; flex-shrink: 0; transition: background .18s; }
.tl-switch::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .18s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.tl-switch-row input:checked + .tl-switch { background: var(--accent); }
.tl-switch-row input:checked + .tl-switch::after { transform: translateX(18px); }

@media (min-width: 761px) { .tl-body { padding-top: 24px; } .tl-header { padding-left: 18px; } }
@media (max-width: 420px) { .tl-row-btns .tl-btn { padding: 7px 12px; } .tl-profile-edit { flex-direction: column; align-items: flex-start; } }

/* ---------- "turn on notifications" bar ---------- */
.push-banner { position: fixed; top: calc(env(safe-area-inset-top, 0px) + 8px); left: 8px; right: 8px; max-width: 520px; margin: 0 auto; z-index: 9000; display: flex; align-items: center; gap: 10px; padding: 10px 10px 10px 14px; border-radius: 14px; background: var(--accent); color: #fff; box-shadow: 0 6px 22px rgba(0,0,0,.3); font-size: 14px; line-height: 1.35; animation: popin .2s ease-out; }
.push-banner span { flex: 1; }
.push-banner button { flex-shrink: 0; color: #fff; font-weight: 700; }
.push-banner .pb-go { background: rgba(255,255,255,.22); border-radius: 12px; padding: 7px 14px; }
.push-banner .pb-x { font-size: 24px; line-height: 1; padding: 0 6px; opacity: .85; }


/* ============================================================================
   Telegram-like BotFather + Settings pages (scoped; chat styles remain untouched)
   ============================================================================ */
body.page-tool {
    --bf-bg:#0e1621; --bf-header:#212d3b; --bf-text:#f5f7fa; --bf-muted:#8b98a9;
    --bf-input:#242f3d; --bf-border:#263544; --bf-border-2:#3a4a5a; --bf-card:#1c2733;
    --bf-chev:#607486; --bf-ph:#8b98a9; --bf-token-text:#dce6ef;
    --bf-hover:rgba(255,255,255,.045); --bf-hover-2:rgba(255,255,255,.085);
    --bf-err-bg:#3a1c1c; --bf-err-text:#ff8a80; --bf-ok-bg:#1c3a2a; --bf-ok-text:#7ee2a8;
    background:#d8edf8; color:var(--bf-text); overflow:hidden;
}
body.page-tool .tl-wrap {
    background:var(--bf-bg); color:var(--bf-text); border-radius:8px; overflow:hidden;
    box-shadow:0 2px 10px rgba(0,0,0,.22);
}
body.page-tool .tl-header {
    min-height:62px; padding:8px 12px; background:var(--bf-header); color:var(--bf-text);
    border-bottom:1px solid var(--bf-border); gap:8px;
}
body.page-tool .tl-header h1 { font-size:17px; font-weight:600; }
body.page-tool .tl-scroll { background:var(--bf-bg); scrollbar-width:thin; scrollbar-color:var(--bf-border-2) transparent; }
body.page-tool .tl-body { width:100%; max-width:420px; padding:0 16px calc(26px + env(safe-area-inset-bottom,0px)); }
body.page-tool .tl-section { color:var(--bf-text); text-transform:none; letter-spacing:0; font-size:16px; margin:22px 4px 10px; }
body.page-tool .tl-card { background:var(--bf-card); border:0; border-radius:10px; padding:14px; box-shadow:none; }
body.page-tool .tl-input { background:var(--bf-input); border:1px solid transparent; border-radius:8px; color:var(--bf-text); padding:12px 13px; }
body.page-tool .tl-input:focus { border-color:#2aabee; box-shadow:0 0 0 1px #2aabee; }
body.page-tool .tl-input::placeholder { color:var(--bf-ph); }
body.page-tool .tl-btn { border:0; border-radius:8px; background:var(--bf-input); color:var(--bf-text); min-height:42px; padding:9px 14px; }
body.page-tool .tl-btn.primary { background:#248bd2; color:#fff; }
body.page-tool .tl-btn.danger { background:#e5655b; color:#fff; }
body.page-tool .tl-btn.wide { border-radius:8px; margin-top:12px; }
body.page-tool .tl-row { padding:9px 10px; border-bottom:1px solid var(--bf-border); border-radius:0; color:var(--bf-text); }
body.page-tool .tl-row:hover, body.page-tool .tl-link:hover { background:var(--bf-hover); }
body.page-tool .tl-row .avatar { width:42px; height:42px; }
body.page-tool .tl-label { color:var(--bf-muted); }
body.page-tool .tl-hint, body.page-tool .tl-hint-inline { color:var(--bf-muted); }
body.page-tool .tl-kv { border-color:var(--bf-border); }
body.page-tool .tl-switch-row { border-color:var(--bf-border); }
body.page-tool .tl-empty { background:var(--bf-card); color:var(--bf-muted); border-radius:10px; }
body.page-tool .tl-alert { background:var(--bf-err-bg); color:var(--bf-err-text); }
body.page-tool .tl-copy, body.page-tool .tl-code { background:var(--bf-input); border:0; border-radius:8px; color:var(--bf-token-text); }
body.page-tool .tl-profile h2 { color:var(--bf-text); }

/* BotFather home */
.bf-botfather-page { color:var(--bf-text); padding-bottom:8px; }
.bf-intro { text-align:center; padding:30px 8px 20px; }
.bf-brand-avatar { width:64px; height:64px; border-radius:50%; margin:0 auto 16px; display:flex; align-items:center; justify-content:center; background:radial-gradient(circle at 30% 20%,#48c4f5,#248bd2); font-size:34px; box-shadow:none; }
.bf-intro h2 { font-size:21px; line-height:1.25; margin:0 0 7px; color:var(--bf-text); font-weight:700; }
.bf-verified { display:inline-flex; vertical-align:middle; width:15px; height:15px; align-items:center; justify-content:center; border-radius:50%; background:#2aabee; color:#fff; font-size:10px; }
.bf-intro p { color:var(--bf-muted); font-size:12.5px; line-height:1.45; max-width:300px; margin:0 auto; }
.bf-learn-link, .bf-token-note a { color:#2aabee; text-decoration:none; font-weight:500; }
.bf-search { display:flex; align-items:center; gap:10px; background:#212d3b; border-radius:9px; padding:0 14px; height:43px; margin:0 0 24px; color:var(--bf-muted); }
.bf-search span { font-size:23px; line-height:1; }
.bf-search input { min-width:0; flex:1; height:100%; color:var(--bf-text); background:transparent; border:0; outline:0; font-size:14px; }
.bf-search input::placeholder { color:var(--bf-muted); }
.bf-list-heading { color:var(--bf-text); font-size:16px; margin:0 0 13px 12px; }
.bf-bot-list { border-radius:9px 9px 0 0; overflow:hidden; background:var(--bf-card); }
.bf-create-btn { display:flex; align-items:center; gap:13px; min-height:43px; padding:10px 16px; color:#2aabee; font-size:14px; font-weight:500; text-decoration:none; background:#1c2733; border-bottom:1px solid #17212b; }
.bf-create-btn:hover { background:#243342; }
.bf-create-btn > span { display:inline-flex; align-items:center; justify-content:center; width:20px; height:20px; border:2px solid #2aabee; border-radius:50%; font-size:17px; line-height:1; }
.bf-bot-row { background:#1c2733; margin:0; padding:9px 13px !important; min-height:53px; }
.bf-bot-row + .bf-bot-row { border-top:1px solid #17212b; }
.bf-bot-row .tl-row-name { color:var(--bf-text); font-size:14px; }
.bf-bot-row .tl-row-sub { color:var(--bf-muted); font-size:12px; }
.bf-bot-row .tl-chev { font-size:26px; }
.bf-no-results { padding:18px; color:var(--bf-muted); text-align:center; background:var(--bf-card); }
.bf-no-results[hidden] { display:none !important; }

/* New bot form */
.bf-subpage-heading { padding:22px 0 10px; }
.bf-subpage-heading h2 { margin:0 0 6px; font-size:20px; }
.bf-subpage-heading p { color:var(--bf-muted); font-size:13px; line-height:1.45; }
.bf-create-form { padding-bottom:12px; }
.bf-file-input { font-size:13px !important; }

/* Bot detail: avatar, token actions, and Telegram settings rows */
.bf-bot-profile { text-align:center; padding:30px 0 17px; }
.bf-bot-profile .avatar.big { width:64px; height:64px; font-size:28px; margin:0 auto 16px; }
.bf-bot-profile h2 { font-size:20px; line-height:1.25; margin:0 0 4px; font-weight:700; color:var(--bf-text); overflow-wrap:anywhere; }
.bf-username { font-size:13px; color:var(--bf-muted); }
.bf-token-card { padding:13px; border-radius:10px; background:#212d3b; }
.bf-token-line { display:flex; align-items:center; gap:9px; min-width:0; border-radius:7px; background:#2a3644; padding:10px 11px; }
.bf-key-icon { flex-shrink:0; color:#fff; font-size:20px; }
.bf-token-value { flex:1; min-width:0; display:block; text-align:left; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; padding:0; background:transparent !important; border:0 !important; color:#dce6ef !important; font-family:ui-monospace,SFMono-Regular,Menlo,monospace; font-size:12.5px; cursor:pointer; }
.bf-token-actions { display:flex; gap:10px; margin-top:9px; }
.bf-token-actions > * { flex:1; min-width:0; }
.bf-token-actions form { display:flex; margin:0; }
.bf-token-actions button { width:100%; min-height:44px; border:0; border-radius:7px; color:#fff; font-weight:700; font-size:13px; }
.bf-copy-button { background:#248bd2; }
.bf-revoke-button { background:#e5655b; }
.bf-token-note { color:var(--bf-muted); font-size:12.5px; line-height:1.5; margin:10px 1px 0; }
.bf-section-title { margin:32px 10px 12px; font-size:16px; font-weight:700; color:var(--bf-text); }
.bf-settings-list { overflow:hidden; border-radius:9px; background:#212d3b; }
.bf-option-row { display:flex; width:100%; min-height:43px; align-items:center; gap:13px; padding:10px 13px; border:0; border-bottom:1px solid #17212b; background:#212d3b; color:var(--bf-text); text-align:left; font:inherit; font-size:14px; cursor:pointer; }
.bf-option-row:last-child { border-bottom:0; }
.bf-option-row:hover { background:#273544; }
.bf-option-icon { display:inline-flex; align-items:center; justify-content:center; width:18px; height:20px; flex-shrink:0; color:#d7e0e8; text-align:center; }
.bf-option-icon svg { width:18px; height:18px; fill:none; stroke:currentColor; stroke-width:1.7; stroke-linecap:round; stroke-linejoin:round; }
.bf-option-title { flex:1; min-width:0; }
.bf-option-row .tl-chev { font-size:25px; color:#607486; }
.bf-reveal-panel { margin-top:14px; padding:14px; border-radius:10px; background:#1c2733; scroll-margin-top:10px; }
.bf-reveal-panel[hidden] { display:none !important; }
.bf-panel-heading { display:flex; align-items:center; gap:10px; margin:0 0 12px; }
.bf-panel-heading h3 { flex:1; font-size:16px; margin:0; }
.bf-panel-close { width:30px; height:30px; border-radius:50%; color:var(--bf-muted); font-size:23px; line-height:1; }
.bf-edit-form .tl-label { margin-top:8px; }
.bf-edit-form .tl-btn.wide { margin-top:9px; }
.bf-reveal-panel .tl-kv { border-color:var(--bf-border); }
.bf-reveal-panel .tl-code { max-height:240px; overflow:auto; line-height:1.5; font-size:12px; }
.bf-reveal-panel .tl-copy { margin-bottom:8px; }

/* Settings intentionally uses Telegram's light Settings layout, not the BotFather dark theme. */
body.page-tool:has(.tg-settings-page) {
    --bf-bg:#ffffff; --bf-header:#ffffff; --bf-text:#212121; --bf-muted:#8b929a;
    --bf-input:#f2f3f5; --bf-border:#e4e6e8; --bf-border-2:#cfd4da; --bf-card:#ffffff;
    --bf-chev:#9aa1a8; --bf-ph:#9aa1a8; --bf-token-text:#313b45;
    --bf-hover:#f4f5f6; --bf-hover-2:#eceff1; --bf-err-bg:#fdecea; --bf-err-text:#c62828;
    background:#d8edf8; color:#212121;
}
body.page-tool:has(.tg-settings-page) .tl-wrap,
body.page-tool:has(.tg-settings-page) .tl-scroll { background:#fff; color:#212121; }
body.page-tool:has(.tg-settings-page) .tl-header { background:#fff; color:#212121; border-bottom:1px solid #e6e8eb; }
body.page-tool:has(.tg-settings-page) .tl-body { max-width:none; padding:0; }
.tg-settings-page { min-height:100%; background:#fff; color:#212121; padding:0 20px 24px; }
.tg-profile-strip { display:flex; align-items:center; gap:14px; min-height:104px; padding:17px 2px 19px; border-bottom:1px solid #e6e8eb; margin:0 -20px 8px; padding-left:22px; padding-right:22px; }
.tg-profile-avatar { width:66px !important; height:66px !important; flex:0 0 66px; font-size:22px !important; }
.tg-profile-copy { flex:1; min-width:0; }
.tg-profile-name { color:#202124; font-size:16px; font-weight:600; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.tg-profile-username { margin-top:4px; color:#8c9299; font-size:13px; }
.tg-profile-mark { color:#3390ec; font-size:25px; padding-right:1px; }
.tg-menu-group { margin:0 -20px; padding:0 20px; border-bottom:8px solid #f1f2f3; }
.tg-menu-row { width:100%; min-height:40px; display:flex; align-items:center; gap:18px; padding:8px 2px; border:0; background:#fff; color:#222; text-align:left; font-family:inherit; font-size:14px; cursor:pointer; }
.tg-menu-row:hover { background:#f5f6f7; }
.tg-menu-icon { display:inline-flex; align-items:center; justify-content:center; width:20px; height:22px; flex:0 0 20px; color:#666e76; }
.tg-menu-icon svg { width:20px; height:20px; fill:none; stroke:currentColor; stroke-width:1.6; stroke-linecap:round; stroke-linejoin:round; }
.tg-menu-row > span:nth-child(2) { flex:1; }
.tg-menu-chev { color:#a6adb4; font-size:22px; opacity:0; }
.tg-menu-row:hover .tg-menu-chev { opacity:1; }
.tg-menu-footer { padding:18px 2px 8px; color:#a0a5aa; font-size:12px; text-align:center; }
.tg-settings-menu[hidden], .tg-profile-strip[hidden], .tg-settings-panel[hidden], .tg-settings-save[hidden] { display:none !important; }
.tg-settings-panel { padding:8px 0 2px; }
.tg-panel-heading { display:flex; align-items:center; gap:10px; margin:0 -5px 17px; padding:0 0 9px; border-bottom:1px solid #e8eaec; }
.tg-panel-heading h2 { flex:1; margin:0; color:#222; font-size:18px; font-weight:600; }
.tg-panel-back { width:32px; height:32px; color:#3390ec; font-size:29px; line-height:1; border-radius:50%; }
.tg-panel-back:hover { background:#eef6ff; }
.tg-panel-card { background:#fff; border-radius:0; padding:0 0 8px; }
.tg-panel-caption { margin:6px 2px 12px; color:#8a9097; font-size:12px; font-weight:700; text-transform:uppercase; letter-spacing:.4px; }
body.page-tool:has(.tg-settings-page) .tl-label { color:#7d858d; font-size:13px; margin:14px 2px 6px; }
body.page-tool:has(.tg-settings-page) .tl-input { background:#f4f5f6; color:#222; border:1px solid #e2e5e8; border-radius:8px; }
body.page-tool:has(.tg-settings-page) .tl-input:focus { border-color:#3390ec; box-shadow:0 0 0 1px #3390ec; }
body.page-tool:has(.tg-settings-page) .tl-btn { background:#f1f3f5; color:#2a2d30; border-radius:8px; }
body.page-tool:has(.tg-settings-page) .tl-btn.primary { background:#3390ec; color:#fff; }
body.page-tool:has(.tg-settings-page) .tl-btn.wide { margin-top:11px; }
body.page-tool:has(.tg-settings-page) .tl-kv { border-color:#e9ebed; color:#282b2e; }
body.page-tool:has(.tg-settings-page) .tl-kv span { color:#858c93; }
body.page-tool:has(.tg-settings-page) .tl-copy { background:#f4f5f6; color:#38424b; border:0; }
.tg-account-avatar-row { display:flex; align-items:center; gap:15px; padding:4px 0 15px; border-bottom:1px solid #e7e9eb; }
.tg-account-avatar { width:58px !important; height:58px !important; flex:0 0 58px; }
.tg-account-avatar-actions { display:flex; gap:16px; flex-wrap:wrap; }
.tg-text-action { display:inline-block; color:#3390ec; font-size:14px; cursor:pointer; }
.tg-remove-action { color:#e05252; }
.tg-settings-save { position:sticky; bottom:0; padding:12px 0 calc(4px + env(safe-area-inset-bottom,0px)); background:linear-gradient(180deg,rgba(255,255,255,0),#fff 20%); }
.tg-settings-save .tl-btn { margin-top:0 !important; }
.tg-field-half { min-width:0; flex:1; }
body.page-tool:has(.tg-settings-page) .tl-switch-row { color:#333; border-color:#e6e8ea; }
body.page-tool:has(.tg-settings-page) .tl-switch-row small { color:#8a9097; }
body.page-tool:has(.tg-settings-page) .tl-switch { background:#ccd2d8; }
body.page-tool:has(.tg-settings-page) .tl-switch-row input:checked + .tl-switch { background:#3390ec; }
body.page-tool:has(.tg-settings-page) .tl-hint { color:#8a9097; }
body.page-tool:has(.tg-settings-page) .tl-pill { background:#edf0f2; color:#6f777f; }
body.page-tool:has(.tg-settings-page) .tl-pill.ok { background:#d1f4d8; color:#1b5e20; }
body.page-tool:has(.tg-settings-page) .tl-pill.off { background:#fdecea; color:#c62828; }

@media (min-width:761px) {
    body.page-tool .tl-body { padding-top:0; }
}
@media (max-width:420px) {
    body.page-tool .tl-body { padding-left:14px; padding-right:14px; }
    .bf-intro { padding-top:24px; }
    .tg-settings-page { padding-left:16px; padding-right:16px; }
    .tg-profile-strip { margin-left:-16px; margin-right:-16px; padding-left:18px; padding-right:18px; }
    .tg-menu-group { margin-left:-16px; margin-right:-16px; padding-left:18px; padding-right:18px; }
    body.page-tool:has(.tg-settings-page) .tl-body { padding-left:0; padding-right:0; }
}


/* ---------------------------------------------------------------------------
   Responsive image pickers + Telegram-like New Bot creation form (v4)
   Scoped to tool pages; chat styles outside these selectors are untouched.
   --------------------------------------------------------------------------- */
.bf-accessible-file {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
    opacity: 0 !important;
}
.bf-accessible-file:focus-visible + .bf-upload-focus,
.bf-avatar-camera-picker:focus-within,
.tg-avatar-photo-picker:focus-within {
    outline: 2px solid #3390ec;
    outline-offset: 3px;
}
.bf-avatar-has-image { color: transparent !important; }

/* The New bot screen follows the reference's centered camera icon and grouped fields. */
.bf-create-page {
    margin: 0 -9px;
    min-height: calc(100dvh - 108px);
    display: flex;
    flex-direction: column;
}
.bf-create-form {
    display: flex;
    flex-direction: column;
    flex: 1 0 auto;
    min-height: calc(100dvh - 112px);
    padding: 0 0 calc(4px + env(safe-area-inset-bottom, 0px));
}
.bf-create-avatar-stage {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 0 20px;
}
.bf-create-avatar-trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    flex: 0 0 64px;
    overflow: hidden;
    border-radius: 50%;
    background-color: #242f3d;
    background-position: center;
    background-size: cover;
    background-repeat: no-repeat;
    color: #f5f7fa;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.bf-create-avatar-trigger:active { transform: scale(.97); }
.bf-create-avatar-trigger svg {
    width: 28px; height: 28px; fill: none; stroke: currentColor;
    stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round;
}
.bf-create-avatar-trigger.bf-avatar-has-image svg { display: none; }
.bf-subpage-heading { text-align: center; padding: 0 8px 20px; }
.bf-subpage-heading h2 { color: var(--bf-text); font-size: 21px; margin: 0 0 7px; }
.bf-subpage-heading p { color: var(--bf-muted); font-size: 12.5px; line-height: 1.45; }
.bf-create-input-group {
    overflow: hidden;
    border-radius: 8px;
    margin: 0 0 16px;
    background: #212d3b;
}
.bf-create-input-group .tl-input {
    display: block;
    width: 100%;
    height: 43px;
    min-height: 43px;
    margin: 0;
    padding: 0 14px;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--bf-text);
    font-size: 14px;
    box-shadow: none;
}
.bf-create-input-group .tl-input:focus { box-shadow: inset 0 0 0 1px #3390ec; }
.bf-username-field {
    display: flex;
    align-items: center;
    gap: 0;
    min-height: 43px;
    padding: 0 14px;
    border-radius: 8px;
    background: #212d3b;
    color: #f5f7fa;
}
.bf-username-field > span { flex: 0 0 auto; font-size: 14px; white-space: nowrap; }
.bf-username-field .tl-input {
    min-width: 0;
    width: 100%;
    min-height: 43px;
    margin: 0;
    padding: 0 0 0 1px;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--bf-text);
    font-size: 14px;
    box-shadow: none;
}
.bf-username-field .tl-input:focus { box-shadow: none; }
.bf-username-help { margin: 9px 14px 14px; color: var(--bf-muted); font-size: 12.5px; line-height: 1.45; }
.bf-create-submit {
    position: sticky;
    bottom: 0;
    z-index: 3;
    margin-top: auto;
    padding: 10px 0 calc(4px + env(safe-area-inset-bottom, 0px));
    background: linear-gradient(to bottom, rgba(14,22,33,0), #0e1621 20%);
}
.bf-create-submit .tl-btn.wide {
    min-height: 40px;
    margin: 0;
    padding: 10px 14px;
    border-radius: 6px;
    background: #248bd2;
    font-size: 13px;
    font-weight: 600;
}

/* Reusable circular photo picker with the camera badge sitting on the image. */
.bf-edit-avatar-row { display: flex; justify-content: center; margin: 4px 0 12px; }
.bf-avatar-camera-picker,
.tg-avatar-photo-picker {
    position: relative;
    display: inline-flex;
    flex: 0 0 auto;
    border-radius: 50%;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.bf-avatar-camera-picker .avatar.big { width: 72px; height: 72px; margin: 0; font-size: 26px; }
.bf-camera-badge,
.tg-camera-badge {
    position: absolute;
    right: -1px;
    bottom: -1px;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 25px;
    height: 25px;
    border: 2px solid var(--bf-card, #fff);
    border-radius: 50%;
    background: #38434f;
    color: #fff;
    pointer-events: none;
}
.bf-camera-badge svg, .tg-camera-badge svg {
    width: 15px; height: 15px; fill: none; stroke: currentColor;
    stroke-width: 1.65; stroke-linecap: round; stroke-linejoin: round;
}

/* Settings profile photo: camera badge overlays the current image, like Telegram. */
.tg-profile-avatar-form { flex: 0 0 66px; width: 66px; margin: 0; position: relative; }
.tg-avatar-photo-picker { width: 100%; height: 100%; }
.tg-avatar-photo-picker .avatar { display: flex; }
.tg-avatar-photo-picker .tg-camera-badge { right: -2px; bottom: -1px; width: 24px; height: 24px; background: rgba(35,40,46,.88); border-color: #fff; }
.tg-profile-avatar-form .bf-accessible-file,
.tg-account-avatar-form .bf-accessible-file { left: 0; bottom: 0; }
.tg-account-avatar-form { position: relative; flex: 0 0 58px; width: 58px; margin: 0; }
.tg-avatar-photo-picker-small { width: 58px; height: 58px; }
.tg-avatar-photo-picker-small .tg-camera-badge { width: 22px; height: 22px; right: -2px; bottom: -1px; }
.tg-account-avatar-row { align-items: center; }
.tg-account-avatar-actions { min-width: 0; }

@media (max-width: 420px) {
    .bf-create-page { margin-left: -9px; margin-right: -9px; min-height: calc(100dvh - 106px); }
    .bf-create-form { min-height: calc(100dvh - 110px); }
    .bf-create-avatar-stage { padding-top: 23px; padding-bottom: 20px; }
    .bf-create-submit { padding-bottom: calc(4px + env(safe-area-inset-bottom, 0px)); }
    .tg-profile-avatar-form { flex-basis: 66px; }
}
@media (min-width: 700px) {
    .bf-create-page { min-height: min(760px, calc(100dvh - 110px)); }
    .bf-create-form { min-height: min(760px, calc(100dvh - 112px)); }
}

/* ============================================================================
   POLISHED FILE PICKER — desktop + iPhone/iPad Safari
   Styles visible native file inputs without touching the hidden avatar pickers.
   ============================================================================ */
input[type="file"]:not(.bf-accessible-file):not([hidden]) {
    display: block;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    min-height: 52px;
    margin: 6px 0 12px;
    padding: 6px 8px;
    border: 1px solid var(--bf-border, var(--border, #d8dee5)) !important;
    border-radius: 12px !important;
    background: var(--bf-input, var(--bg-2, #f4f5f6)) !important;
    color: var(--bf-muted, var(--text-2, #707984)) !important;
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.4;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    transition: border-color .16s ease, box-shadow .16s ease, background-color .16s ease;
    overflow: hidden;
}

input[type="file"]:not(.bf-accessible-file):not([hidden]):hover {
    border-color: #3390ec !important;
}

input[type="file"]:not(.bf-accessible-file):not([hidden]):focus,
input[type="file"]:not(.bf-accessible-file):not([hidden]):focus-visible {
    outline: none;
    border-color: #3390ec !important;
    box-shadow: 0 0 0 3px rgba(51, 144, 236, .16) !important;
}

/* Chromium, Firefox and current Safari */
input[type="file"]:not(.bf-accessible-file):not([hidden])::file-selector-button {
    margin: 0 12px 0 0;
    padding: 9px 15px;
    min-height: 36px;
    border: 0;
    border-radius: 8px;
    background: #3390ec;
    color: #fff;
    font-family: inherit;
    font-size: 13px;
    font-weight: 650;
    line-height: 1.2;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    box-shadow: 0 1px 2px rgba(24, 75, 125, .14);
    transition: background-color .16s ease, transform .12s ease;
}

/* WebKit fallback for older Safari versions, including older iOS Safari */
input[type="file"]:not(.bf-accessible-file):not([hidden])::-webkit-file-upload-button {
    margin: 0 12px 0 0;
    padding: 9px 15px;
    min-height: 36px;
    border: 0;
    border-radius: 8px;
    background: #3390ec;
    color: #fff;
    font-family: inherit;
    font-size: 13px;
    font-weight: 650;
    line-height: 1.2;
    cursor: pointer;
    -webkit-appearance: none;
    box-shadow: 0 1px 2px rgba(24, 75, 125, .14);
}

@media (hover: hover) {
    input[type="file"]:not(.bf-accessible-file):not([hidden])::file-selector-button:hover {
        background: #2483df;
    }
    input[type="file"]:not(.bf-accessible-file):not([hidden])::-webkit-file-upload-button:hover {
        background: #2483df;
    }
}

input[type="file"]:not(.bf-accessible-file):not([hidden]):active::file-selector-button {
    transform: scale(.98);
}

/* Light Telegram settings panel */
body.page-tool:has(.tg-settings-page) input[type="file"]:not(.bf-accessible-file):not([hidden]) {
    background: #f4f6f8 !important;
    border-color: #dce2e8 !important;
    color: #737e89 !important;
}
body.page-tool:has(.tg-settings-page) input[type="file"]:not(.bf-accessible-file):not([hidden]):focus,
body.page-tool:has(.tg-settings-page) input[type="file"]:not(.bf-accessible-file):not([hidden]):focus-visible {
    border-color: #3390ec !important;
    box-shadow: 0 0 0 3px rgba(51, 144, 236, .14) !important;
}

@media (max-width: 600px) {
    input[type="file"]:not(.bf-accessible-file):not([hidden]) {
        min-height: 50px;
        padding: 5px 6px;
        border-radius: 11px !important;
        font-size: 12px;
    }
    input[type="file"]:not(.bf-accessible-file):not([hidden])::file-selector-button,
    input[type="file"]:not(.bf-accessible-file):not([hidden])::-webkit-file-upload-button {
        min-height: 36px;
        margin-right: 9px;
        padding: 9px 12px;
        border-radius: 8px;
        font-size: 12px;
    }
}

@media (prefers-reduced-motion: reduce) {
    input[type="file"]:not(.bf-accessible-file):not([hidden]),
    input[type="file"]:not(.bf-accessible-file):not([hidden])::file-selector-button,
    input[type="file"]:not(.bf-accessible-file):not([hidden])::-webkit-file-upload-button {
        transition: none;
    }
}


/* Reliable, full-hit-area image pickers on touch screens and desktop browsers.
   The transparent native input is layered over the visible avatar, so tapping
   anywhere on the circle opens the OS file/photo picker (Windows, iOS Safari,
   Android and desktop browsers). */
.bf-create-avatar-trigger,
.bf-avatar-camera-picker,
.tg-avatar-photo-picker {
    position: relative;
    isolation: isolate;
}
.bf-photo-file-overlay {
    position: absolute !important;
    inset: 0 !important;
    display: block !important;
    width: 100% !important;
    height: 100% !important;
    min-width: 100% !important;
    min-height: 100% !important;
    max-width: none !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: hidden !important;
    clip: auto !important;
    clip-path: none !important;
    white-space: normal !important;
    opacity: 0 !important;
    border: 0 !important;
    border-radius: 50% !important;
    cursor: pointer !important;
    z-index: 5 !important;
    pointer-events: auto !important;
}
/* Keep the camera centered over the photo in Edit Info and Settings. */
.bf-avatar-camera-picker .bf-camera-badge,
.tg-avatar-photo-picker .tg-camera-badge {
    left: 50% !important;
    top: 50% !important;
    right: auto !important;
    bottom: auto !important;
    transform: translate(-50%, -50%) !important;
    width: 34px;
    height: 34px;
    border: 1px solid rgba(255,255,255,.34);
    border-radius: 50%;
    background: rgba(14,22,33,.68);
    box-shadow: 0 1px 4px rgba(0,0,0,.14);
}
.bf-avatar-camera-picker .bf-camera-badge svg,
.tg-avatar-photo-picker .tg-camera-badge svg {
    width: 18px;
    height: 18px;
}
.tg-avatar-photo-picker-small .tg-camera-badge {
    width: 30px;
    height: 30px;
}
.bf-create-avatar-trigger:focus-within,
.bf-avatar-camera-picker:focus-within,
.tg-avatar-photo-picker:focus-within {
    outline: 2px solid #3390ec;
    outline-offset: 3px;
}

/* Bot logo camera is placed directly on the avatar at the top of the BotFather detail page.
   Image upload is submitted by that avatar; Edit Info remains for name/username only. */
.bf-bot-profile-avatar-form {
    width: 64px;
    height: 64px;
    margin: 0 auto 16px;
    padding: 0;
    position: relative;
}
.bf-bot-logo-picker {
    display: block;
    width: 64px;
    height: 64px;
    margin: 0;
    overflow: visible;
}
.bf-bot-logo-picker .avatar.big {
    display: flex;
    width: 64px;
    height: 64px;
    margin: 0;
    border-radius: 50%;
    overflow: hidden;
}
.bf-bot-logo-picker .bf-camera-badge {
    z-index: 2;
}
.bf-bot-logo-picker .bf-photo-file-overlay {
    z-index: 5;
}

/* ============================================================================
   Telegram-like People and Group pages
   Scoped only to people.php and group.php; chat layout remains untouched.
   ============================================================================ */
body.page-tool:has(.tg-people-page),
body.page-tool:has(.tg-group-page) {
    --bf-bg: #ffffff;
    --bf-header: #ffffff;
    --bf-text: #212121;
    --bf-muted: #858d95;
    --bf-input: #f2f4f6;
    --bf-border: #e5e8eb;
    --bf-border-2: #cbd2d9;
    --bf-card: #ffffff;
    --bf-chev: #a1aab3;
    --bf-ph: #929aa2;
    --bf-token-text: #303943;
    --bf-hover: #f3f6f8;
    --bf-hover-2: #e9eef2;
    --bf-err-bg: #fdeeee;
    --bf-err-text: #c83e3e;
    --bf-ok-bg: #e2f7e8;
    --bf-ok-text: #168345;
    background: #d8edf8;
    color: var(--bf-text);
}
html[data-theme="dark"] body.page-tool:has(.tg-people-page),
html[data-theme="dark"] body.page-tool:has(.tg-group-page) {
    --bf-bg: #0e1621;
    --bf-header: #17212b;
    --bf-text: #f5f7fa;
    --bf-muted: #8b98a9;
    --bf-input: #242f3d;
    --bf-border: #263544;
    --bf-border-2: #3a4a5a;
    --bf-card: #17212b;
    --bf-chev: #607486;
    --bf-ph: #8b98a9;
    --bf-token-text: #dce6ef;
    --bf-hover: rgba(255,255,255,.055);
    --bf-hover-2: rgba(255,255,255,.09);
    --bf-err-bg: #3a1c1c;
    --bf-err-text: #ff8a80;
    --bf-ok-bg: #1c3a2a;
    --bf-ok-text: #7ee2a8;
    background: #0e1621;
}
body.page-tool:has(.tg-people-page) .tl-wrap,
body.page-tool:has(.tg-people-page) .tl-scroll,
body.page-tool:has(.tg-group-page) .tl-wrap,
body.page-tool:has(.tg-group-page) .tl-scroll {
    background: var(--bf-bg);
    color: var(--bf-text);
}
body.page-tool:has(.tg-people-page) .tl-header,
body.page-tool:has(.tg-group-page) .tl-header {
    background: var(--bf-header);
    color: var(--bf-text);
    border-bottom: 1px solid var(--bf-border);
}
body.page-tool:has(.tg-people-page) .tl-header h1,
body.page-tool:has(.tg-group-page) .tl-header h1 { color: var(--bf-text); }
body.page-tool:has(.tg-people-page) .tl-body,
body.page-tool:has(.tg-group-page) .tl-body {
    width: 100%;
    max-width: 560px;
    padding: 0 0 calc(24px + env(safe-area-inset-bottom, 0px));
}
.tg-people-page, .tg-group-page {
    min-height: 100%;
    width: 100%;
    background: var(--bf-bg);
    color: var(--bf-text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

/* People: native Telegram-like tabs and people rows */
.tg-people-page { padding-bottom: 14px; }
.tg-people-page .tl-tabs {
    position: sticky;
    top: 0;
    z-index: 3;
    display: flex;
    gap: 0;
    margin: 0 0 4px;
    padding: 0 8px;
    border: 0;
    border-bottom: 1px solid var(--bf-border);
    border-radius: 0;
    background: var(--bf-header);
}
.tg-people-page .tl-tabs button {
    position: relative;
    min-width: 0;
    min-height: 46px;
    flex: 1 1 0;
    gap: 6px;
    padding: 10px 6px 9px;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: var(--bf-muted);
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}
.tg-people-page .tl-tabs button::after {
    position: absolute;
    right: 10px;
    bottom: -1px;
    left: 10px;
    height: 3px;
    border-radius: 3px 3px 0 0;
    background: transparent;
    content: "";
}
.tg-people-page .tl-tabs button.on,
.tg-people-page .tl-tabs button[aria-selected="true"] {
    color: #3390ec;
    background: transparent;
}
.tg-people-page .tl-tabs button.on::after,
.tg-people-page .tl-tabs button[aria-selected="true"]::after { background: #3390ec; }
.tg-people-page .tl-tabs em {
    min-width: 18px;
    padding: 1px 5px;
    border-radius: 10px;
    background: #e64b55;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
}
.tg-people-page .tl-panel { padding: 0; background: var(--bf-bg); }
.tg-people-page #panel-find { padding: 12px 14px 4px; }
.tg-people-page #q {
    display: block;
    width: 100%;
    min-height: 43px;
    margin: 0 0 8px;
    padding: 10px 15px;
    border: 1px solid transparent;
    border-radius: 22px;
    background: var(--bf-input);
    color: var(--bf-text);
    font-size: 16px;
    -webkit-appearance: none;
    appearance: none;
}
.tg-people-page #q:focus { border-color: #3390ec; box-shadow: 0 0 0 1px #3390ec; }
.tg-people-page #q::-webkit-search-cancel-button { cursor: pointer; }
.tg-people-page #panel-find > .tl-hint { margin: 3px 3px 12px; line-height: 1.45; }
.tg-people-page .tl-row,
.tg-people-page a.tl-link {
    min-height: 67px;
    padding: 9px 14px;
    gap: 12px;
    border: 0;
    border-bottom: 1px solid var(--bf-border);
    border-radius: 0;
    background: var(--bf-bg);
    color: var(--bf-text);
    text-decoration: none;
    transition: background .12s ease;
}
.tg-people-page .tl-row:hover,
.tg-people-page a.tl-link:hover { background: var(--bf-hover); }
.tg-people-page .tl-row .avatar,
.tg-people-page a.tl-link .avatar { width: 48px; height: 48px; flex: 0 0 48px; font-size: 17px; }
.tg-people-page .tl-row-main { flex: 1; min-width: 0; }
.tg-people-page .tl-row-name { color: var(--bf-text); font-size: 15px; font-weight: 600; line-height: 1.25; }
.tg-people-page .tl-row-sub { color: var(--bf-muted); font-size: 13px; margin-top: 3px; }
.tg-people-page .tl-chev { color: var(--bf-chev); font-size: 24px; }
.tg-people-page .tl-row-btns { gap: 6px; align-items: center; }
.tg-people-page .tl-row-btns .tl-btn { min-height: 34px; padding: 6px 11px; border-radius: 18px; font-size: 13px; }
.tg-people-page .tl-btn { border-color: var(--bf-border); background: var(--bf-header); color: var(--bf-text); border-radius: 20px; }
.tg-people-page .tl-btn.primary { border-color: #3390ec; background: #3390ec; color: #fff; }
.tg-people-page .tl-empty { margin: 14px; padding: 28px 16px; border-radius: 12px; background: var(--bf-card); color: var(--bf-muted); }
.tg-people-page #profile.tl-card {
    margin: 0;
    padding: 25px 18px 20px;
    border: 0;
    border-bottom: 8px solid var(--bf-hover-2);
    border-radius: 0;
    background: var(--bf-header);
    color: var(--bf-text);
    box-shadow: none;
}
.tg-people-page #profile .avatar.big { width: 88px; height: 88px; margin: 0 auto 12px; font-size: 31px; }
.tg-people-page #profile h2 { margin: 0 0 4px; color: var(--bf-text); font-size: 20px; font-weight: 700; }
.tg-people-page #profile .tl-row-sub { color: var(--bf-muted); }
.tg-people-page #profile .tl-profile-btns { margin-top: 16px; gap: 8px; }
.tg-people-page #profile .tl-profile-btns .tl-btn { min-width: 120px; }

/* Group details / create group: unified rows, cards, forms, and action buttons */
.tg-group-page { padding-bottom: 16px; }
.tg-group-page #app { min-height: 100%; color: var(--bf-text); background: var(--bf-bg); }
.tg-group-page #app > .tl-empty { margin: 0; padding: 34px 14px; border-radius: 0; background: transparent; color: var(--bf-muted); }
.tg-group-page #app .tl-card {
    margin: 0 0 8px;
    padding: 14px;
    border: 0;
    border-bottom: 1px solid var(--bf-border);
    border-radius: 0;
    background: var(--bf-header);
    color: var(--bf-text);
    box-shadow: none;
}
.tg-group-page #app .tl-profile { padding: 24px 16px 20px; text-align: center; }
.tg-group-page #app .tl-profile .avatar.big { width: 88px; height: 88px; margin: 0 auto 12px; font-size: 31px; }
.tg-group-page #app .tl-profile h2 { margin: 0 0 4px; color: var(--bf-text); font-size: 20px; font-weight: 700; }
.tg-group-page #app .tl-section { margin: 20px 15px 8px; color: var(--bf-muted); font-size: 13px; text-transform: uppercase; letter-spacing: .35px; }
.tg-group-page #app .tl-row {
    min-height: 62px;
    padding: 8px 14px;
    gap: 12px;
    border: 0;
    border-bottom: 1px solid var(--bf-border);
    border-radius: 0;
    background: var(--bf-bg);
    color: var(--bf-text);
}
.tg-group-page #app .tl-row:hover { background: var(--bf-hover); }
.tg-group-page #app .tl-row .avatar { width: 44px; height: 44px; flex: 0 0 44px; }
.tg-group-page #app .tl-row-name { color: var(--bf-text); font-size: 15px; }
.tg-group-page #app .tl-row-sub { color: var(--bf-muted); }
.tg-group-page #app .tl-form { padding: 10px 14px 18px; }
.tg-group-page #app .tl-label { margin: 13px 2px 6px; color: var(--bf-muted); font-size: 13px; }
.tg-group-page #app .tl-input { min-height: 44px; padding: 11px 13px; border: 1px solid var(--bf-border); border-radius: 9px; background: var(--bf-input); color: var(--bf-text); font-size: 16px; }
.tg-group-page #app textarea.tl-input { min-height: 96px; resize: vertical; }
.tg-group-page #app .tl-input:focus { border-color: #3390ec; box-shadow: 0 0 0 1px #3390ec; }
.tg-group-page #app .tl-btn { min-height: 40px; padding: 9px 15px; border: 0; border-radius: 20px; background: var(--bf-input); color: var(--bf-text); }
.tg-group-page #app .tl-btn.primary { background: #3390ec; color: #fff; }
.tg-group-page #app .tl-btn.danger { background: #e05252; color: #fff; }
.tg-group-page #app .tl-btn.wide { min-height: 44px; border-radius: 8px; margin-top: 12px; }
.tg-group-page #app .tl-row-btns { gap: 6px; }
.tg-group-page #app .tl-hint { color: var(--bf-muted); }
.tg-group-page #app .tl-empty:not(:first-child) { margin: 10px 14px; padding: 24px 14px; background: var(--bf-card); border-radius: 10px; }

@media (max-width: 420px) {
    body.page-tool:has(.tg-people-page) .tl-body,
    body.page-tool:has(.tg-group-page) .tl-body { padding-left: 0; padding-right: 0; }
    .tg-people-page #panel-find { padding: 10px 12px 4px; }
    .tg-people-page .tl-row-btns { max-width: 48%; }
    .tg-people-page .tl-row-btns .tl-btn { padding: 6px 9px; font-size: 12px; }
    .tg-group-page #app .tl-form { padding-left: 12px; padding-right: 12px; }
    .tg-group-page #app .tl-card { padding-left: 12px; padding-right: 12px; }
}


/* ============================================================================
   Group page polish — V9
   Cleaner Telegram-like spacing, styled selection controls, and a bottom action.
   Only active on the group tool; chat and BotFather screens remain unchanged.
   ============================================================================ */
.tg-group-create #app {
    min-height: 100%;
    padding: 8px 0 calc(72px + env(safe-area-inset-bottom, 0px));
    box-sizing: border-box;
}
.tg-group-create #app form {
    margin: 0;
}
.tg-group-create #app .tl-label {
    margin: 8px 14px 6px;
    padding: 0;
    color: var(--bf-muted);
    font-size: 13px;
    font-weight: 500;
    line-height: 1.35;
}
.tg-group-create #app input.tl-input,
.tg-group-create #app textarea.tl-input,
.tg-group-create #app select.tl-input {
    display: block;
    width: calc(100% - 16px);
    min-height: 44px;
    margin: 0 8px 8px;
    padding: 11px 14px;
    border: 1px solid transparent;
    border-radius: 9px;
    background: var(--bf-input);
    color: var(--bf-text);
    box-shadow: none;
    font-size: 16px;
}
.tg-group-create #app input.tl-input:focus,
.tg-group-create #app textarea.tl-input:focus,
.tg-group-create #app select.tl-input:focus {
    border-color: #3390ec;
    box-shadow: 0 0 0 1px #3390ec;
}
.tg-group-create #app .tl-section {
    margin: 20px 14px 8px;
    color: var(--bf-muted);
    font-size: 13px;
    line-height: 1.4;
    letter-spacing: .25px;
}
.tg-group-create #app .tl-empty {
    margin: 0 8px 8px;
    padding: 19px 12px;
    min-height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    border-radius: 9px;
    background: var(--bf-card);
    color: var(--bf-muted);
    font-size: 14px;
    line-height: 1.45;
}
.tg-group-create #app .tl-row {
    min-height: 62px;
    padding: 8px 14px;
    gap: 11px;
    border-bottom: 1px solid var(--bf-border);
    background: transparent;
}
.tg-group-create #app .tl-row .avatar {
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
}
.tg-group-create #app input[type="checkbox"] {
    width: 20px;
    height: 20px;
    flex: 0 0 20px;
    margin: 0 1px 0 0;
    accent-color: #3390ec;
    cursor: pointer;
}
.tg-group-create #app .tl-row-name {
    color: var(--bf-text);
    font-size: 15px;
    font-weight: 600;
}
.tg-group-create #app .tl-row-sub {
    color: var(--bf-muted);
    font-size: 13px;
    margin-top: 3px;
}
.tg-group-create #app button.tl-btn.primary.wide,
.tg-group-create #app input.tl-btn.primary.wide {
    position: fixed;
    z-index: 20;
    left: 50%;
    bottom: calc(8px + env(safe-area-inset-bottom, 0px));
    transform: translateX(-50%);
    width: min(calc(100% - 16px), 544px);
    min-height: 46px;
    margin: 0;
    padding: 12px 16px;
    border: 0;
    border-radius: 8px;
    background: #3390ec;
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(0,0,0,.12);
}
.tg-group-create #app button.tl-btn.primary.wide:active { filter: brightness(.96); }

@media (max-width: 420px) {
    .tg-group-create #app .tl-section { margin-left: 14px; margin-right: 14px; }
    .tg-group-create #app .tl-row { padding-left: 12px; padding-right: 12px; }
    .tg-group-create #app button.tl-btn.primary.wide,
    .tg-group-create #app input.tl-btn.primary.wide {
        width: calc(100% - 8px);
        bottom: calc(4px + env(safe-area-inset-bottom, 0px));
    }
}


/* ============================================================================
   Telegram UI refinement — V10
   Scoped only to People and Group tools. Chat, inbox, BotFather and settings
   functionality/layout are intentionally left intact.
   ============================================================================ */

/* Follow the app's selected theme on People and Group pages. */
html[data-theme="light"] body.page-tool:has(.tg-group-page),
html[data-theme="light"] body.page-tool:has(.tg-people-page) {
    --bf-bg: #ffffff;
    --bf-header: #ffffff;
    --bf-text: #212121;
    --bf-muted: #8b929a;
    --bf-input: #f1f3f5;
    --bf-border: #e5e7eb;
    --bf-border-2: #d0d4da;
    --bf-card: #f4f5f6;
    --bf-chev: #a6acb3;
    --bf-ph: #9299a1;
    --bf-token-text: #303843;
    --bf-hover: #f3f5f7;
    --bf-hover-2: #e9edf1;
    background: #d9eef9;
    color: #212121;
}
html[data-theme="dark"] body.page-tool:has(.tg-group-page),
html[data-theme="dark"] body.page-tool:has(.tg-people-page) {
    --bf-bg: #0e1621;
    --bf-header: #17212b;
    --bf-text: #f5f7fa;
    --bf-muted: #8b98a9;
    --bf-input: #242f3d;
    --bf-border: #263544;
    --bf-border-2: #3a4a5a;
    --bf-card: #1c2733;
    --bf-chev: #607486;
    --bf-ph: #8b98a9;
    --bf-token-text: #dce6ef;
    --bf-hover: rgba(255,255,255,.045);
    --bf-hover-2: rgba(255,255,255,.085);
    background: #d9eef9;
    color: #f5f7fa;
}

/* The iframe page has its own close control. Avoid rendering the second one
   supplied by the parent overlay for these two tools only. */
.bot-overlay.tg-tool-has-close .bot-overlay-close { display: none !important; }

.tg-people-page, .tg-group-page {
    color: var(--bf-text);
    background: var(--bf-bg);
    -webkit-font-smoothing: antialiased;
}

/* ------------------------------ People */
.tg-people-page { padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }
.tg-people-page .tl-tabs { border-bottom-color: var(--bf-border); }
.tg-people-page .tl-tabs button { min-height: 48px; touch-action: manipulation; }
.tg-people-page .tl-tabs button:focus-visible,
.tg-people-page .tl-btn:focus-visible,
.tg-people-page #q:focus-visible { outline: 2px solid #3390ec; outline-offset: 2px; }
.tg-people-page .tg-people-row { min-width: 0; }
.tg-people-page .tg-people-row .tl-row-main { min-width: 0; }
.tg-people-page .tg-people-row .tl-row-main[role="link"] { border-radius: 5px; }
.tg-people-page .tg-people-row .tl-row-main[role="link"]:focus-visible { outline: 2px solid #3390ec; outline-offset: 3px; }
.tg-people-page .tg-people-row .tl-row-btns { flex: 0 0 auto; }
.tg-people-page .tl-profile-btns .tl-btn { touch-action: manipulation; }
.tg-people-page .tl-empty { margin-top: 12px; }

/* ------------------------------ Group: create flow */
.tg-group-create #app {
    position: relative;
    min-height: 100%;
    padding: 0 0 calc(86px + env(safe-area-inset-bottom, 0px));
    box-sizing: border-box;
}
.tg-group-create .tg-group-create-form { width: 100%; max-width: 560px; margin: 0 auto; }
.tg-group-create .tg-group-name-area { padding: 6px 12px 0; }
.tg-group-create #app .tl-label {
    display: block;
    margin: 8px 1px 6px;
    color: var(--bf-muted);
    font-size: 13px;
    font-weight: 500;
    line-height: 1.35;
}
.tg-group-create #app input.tl-input {
    display: block;
    width: 100%;
    min-height: 45px;
    margin: 0;
    padding: 11px 14px;
    border: 1px solid transparent;
    border-radius: 9px;
    background: var(--bf-input);
    color: var(--bf-text);
    font-size: 16px;
    line-height: 1.35;
    box-shadow: none;
    -webkit-appearance: none;
    appearance: none;
}
.tg-group-create #app input.tl-input::placeholder { color: var(--bf-ph); opacity: 1; }
.tg-group-create #app input.tl-input:focus { border-color: #3390ec; box-shadow: 0 0 0 1px #3390ec; }
.tg-group-create #app .tg-group-section { margin-top: 19px; }
.tg-group-create #app .tl-section {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 6px;
    margin: 0 14px 8px;
    color: var(--bf-muted);
    font-size: 13px;
    font-weight: 700;
    line-height: 1.4;
    text-transform: uppercase;
    letter-spacing: .3px;
}
.tg-group-create #app .tg-section-note {
    color: var(--bf-muted);
    font-size: 12px;
    font-weight: 400;
    text-transform: none;
    letter-spacing: 0;
}
.tg-group-create #app .tg-picker-list { width: 100%; }
.tg-group-create #app .tg-picker-row {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: 62px;
    padding: 9px 14px;
    border: 0;
    border-bottom: 1px solid var(--bf-border);
    background: transparent;
    color: var(--bf-text);
    cursor: pointer;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    transition: background .12s ease;
}
.tg-group-create #app .tg-picker-row:hover { background: var(--bf-hover); }
.tg-group-create #app .tg-picker-row.is-selected { background: rgba(51,144,236,.10); }
.tg-group-create #app .tg-picker-row .tl-row-main { flex: 1; min-width: 0; }
.tg-group-create #app .tg-picker-avatar { width: 44px; height: 44px; flex: 0 0 44px; font-size: 16px; }
.tg-group-create #app .tg-picker-row .tl-row-name { color: var(--bf-text); font-size: 15px; font-weight: 600; line-height: 1.25; }
.tg-group-create #app .tg-picker-row .tl-row-sub { color: var(--bf-muted); font-size: 13px; margin-top: 3px; }
.tg-group-create #app .tg-picker-checkbox {
    -webkit-appearance: none;
    appearance: none;
    display: block;
    width: 22px;
    height: 22px;
    flex: 0 0 22px;
    margin: 0;
    border: 2px solid var(--bf-chev);
    border-radius: 50%;
    background: transparent center / 14px 14px no-repeat;
    cursor: pointer;
    transition: background-color .12s ease, border-color .12s ease;
}
.tg-group-create #app .tg-picker-checkbox:checked {
    border-color: #3390ec;
    background-color: #3390ec;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath d='m4 10 4 4 8-8' fill='none' stroke='white' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
.tg-group-create #app .tg-picker-checkbox:focus-visible { outline: 2px solid #3390ec; outline-offset: 3px; }
.tg-group-create #app .tg-group-empty {
    margin: 0 10px;
    padding: 13px 12px;
    min-height: 54px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    border-radius: 9px;
    background: var(--bf-card);
    text-align: center;
    box-sizing: border-box;
}
.tg-group-create #app .tg-group-empty-title { color: var(--bf-muted); font-size: 14px; line-height: 1.35; }
.tg-group-create #app .tg-group-empty-detail { color: var(--bf-muted); opacity: .86; font-size: 12px; line-height: 1.4; }
.tg-group-create #app .tg-group-loading { padding: 26px 14px; text-align: center; color: var(--bf-muted); font-size: 14px; }
.tg-group-create #app .tg-selection-summary { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.tg-group-create .tg-group-create-footer {
    position: fixed;
    z-index: 30;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--bf-border);
    background: var(--bf-header);
    box-sizing: border-box;
    -webkit-backdrop-filter: blur(12px);
    backdrop-filter: blur(12px);
}
.tg-group-create .tg-group-create-footer .tl-btn.primary.wide {
    display: flex;
    width: 100%;
    min-height: 46px;
    margin: 0;
    padding: 12px 16px;
    border: 0;
    border-radius: 8px;
    background: #3390ec;
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    box-shadow: none;
    transform: none;
}
.tg-group-create .tg-group-create-footer .tl-btn.primary.wide:active { filter: brightness(.95); }
.tg-group-create .tg-group-create-footer .tl-btn.primary.wide:disabled { opacity: .65; }

/* ------------------------------ Group info / management */
.tg-group-info #app { padding: 0 0 calc(18px + env(safe-area-inset-bottom, 0px)); }
.tg-group-info .tg-group-info-layout { width: 100%; max-width: 560px; margin: 0 auto; }
.tg-group-info #app .tg-group-overview {
    padding: 25px 16px 20px;
    margin: 0 0 8px;
    border: 0;
    border-bottom: 8px solid var(--bf-hover-2);
    border-radius: 0;
    background: var(--bf-header);
    box-shadow: none;
    text-align: center;
}
.tg-group-info #app .tg-group-overview .avatar.big { width: 88px; height: 88px; margin: 0 auto 12px; font-size: 30px; }
.tg-group-info #app .tg-group-overview h2 { margin: 0 0 4px; color: var(--bf-text); font-size: 20px; line-height: 1.25; overflow-wrap: anywhere; }
.tg-group-info #app .tg-group-overview .tl-row-sub { color: var(--bf-muted); font-size: 13px; }
.tg-group-info #app .tg-group-settings {
    margin: 10px 12px 20px;
    padding: 12px 14px;
    border-radius: 10px;
    background: var(--bf-card);
}
.tg-group-info #app .tg-group-setting-field + .tg-group-setting-field { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--bf-border); }
.tg-group-info #app .tl-label { display: block; margin: 0 0 6px; color: var(--bf-muted); font-size: 13px; }
.tg-group-info #app .tl-input { min-width: 0; min-height: 42px; border-radius: 8px; background: var(--bf-input); color: var(--bf-text); font-size: 16px; }
.tg-group-info #app .tl-inline { align-items: center; gap: 8px; }
.tg-group-info #app .tl-inline .tl-input { margin-bottom: 0; }
.tg-group-info #app .tl-copy { display: block; width: 100%; min-width: 0; padding: 11px 12px; text-align: left; overflow-wrap: anywhere; background: var(--bf-input); border: 0; border-radius: 8px; color: var(--bf-text); font-size: 13px; }
.tg-group-info #app .tg-group-section { margin-top: 18px; }
.tg-group-info #app .tl-section { margin: 0 14px 8px; color: var(--bf-muted); font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .3px; }
.tg-group-info #app .tg-manage-list { background: var(--bf-bg); }
.tg-group-info #app .tg-group-member-row { min-height: 62px; padding: 9px 13px; gap: 11px; border-bottom: 1px solid var(--bf-border); }
.tg-group-info #app .tg-group-member-row .avatar { width: 44px; height: 44px; flex: 0 0 44px; }
.tg-group-info #app .tg-group-member-row .tl-row-main { flex: 1; min-width: 0; }
.tg-group-info #app .tg-group-member-row .tl-row-name { color: var(--bf-text); font-size: 14px; }
.tg-group-info #app .tg-group-member-row .tl-row-sub { color: var(--bf-muted); font-size: 12px; }
.tg-group-info #app .tg-group-member-row .tl-row-btns { gap: 5px; max-width: 48%; }
.tg-group-info #app .tg-group-member-row .tl-row-btns .tl-btn { min-height: 33px; padding: 6px 10px; border-radius: 18px; font-size: 12px; white-space: nowrap; }
.tg-group-info #app .tg-group-member-row .tl-row-btns .tl-btn.primary { background: #3390ec; color: #fff; }
.tg-group-info #app .tg-group-member-row .tl-row-btns .tl-btn.danger { background: #e05252; color: #fff; }
.tg-group-info #app .tg-group-section .tg-group-empty { margin: 0 12px; padding: 20px 14px; text-align: center; color: var(--bf-muted); background: var(--bf-card); border-radius: 9px; font-size: 14px; }
.tg-group-info #app .tg-group-empty-detail { font-size: 12px; margin-top: 4px; }
.tg-group-info #app #gAdd .tl-section { margin-top: 20px; }
.tg-group-info #app .tg-group-danger { margin: 24px 12px 6px; padding-top: 14px; border-top: 1px solid var(--bf-border); }
.tg-group-info #app .tg-group-danger .tl-btn.wide { margin: 0; min-height: 44px; border-radius: 8px; background: #e05252; color: #fff; border: 0; }

@media (max-width: 420px) {
    .tg-group-create .tg-group-name-area { padding-left: 8px; padding-right: 8px; }
    .tg-group-create #app .tl-section { margin-left: 12px; margin-right: 12px; }
    .tg-group-create #app .tg-picker-row { padding-left: 11px; padding-right: 11px; gap: 10px; }
    .tg-group-info #app .tg-group-member-row { padding-left: 10px; padding-right: 10px; gap: 9px; }
    .tg-group-info #app .tg-group-member-row .tl-row-btns { max-width: 46%; }
    .tg-group-info #app .tg-group-member-row .tl-row-btns .tl-btn { padding: 6px 8px; font-size: 11px; }
}

@media (prefers-reduced-motion: reduce) {
    .tg-group-create #app .tg-picker-row,
    .tg-group-create #app .tg-picker-checkbox { transition: none; }
}
