/* ── Chat header ──────────────────────────── */
#chat-header {
    height: var(--header-h);
    background: var(--bg-header);
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 12px;
    flex-shrink: 0;
    z-index: var(--z-header);
}
#chat-header .avatar {
    width: 40px; height: 40px;
    border-radius: 50%;
    background: rgba(255,255,255,.25);
    display: flex; align-items: center; justify-content: center;
    color: #fff;
    font-size: 16px;
    font-weight: 600;
    flex-shrink: 0;
    overflow: hidden;
}
#chat-header .info,
#chat-header .chat-header-info { flex: 1; min-width: 0; }
#chat-header .conv-title,
#chat-header .chat-name {
    font-size: 16px;
    font-weight: 600;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
#chat-header .conv-status,
#chat-header .chat-status {
    font-size: 12px;
    color: rgba(255,255,255,.75);
    margin-top: 1px;
}
#chat-header .actions,
#chat-header .chat-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
    flex-shrink: 0;
}
#chat-header .icon-btn {
    width: 34px; height: 34px;
    min-width: 34px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    color: #fff;
    font-size: 17px;
    background: rgba(255,255,255,.18);
    border: 1.5px solid rgba(255,255,255,.3);
    transition: var(--transition);
    flex-shrink: 0;
    cursor: pointer;
}
#chat-header .icon-btn:hover {
    background: rgba(255,255,255,.35);
    border-color: rgba(255,255,255,.6);
    transform: scale(1.08);
}

/* ── Typing indicator ─────────────────────── */
#typing-bar {
    height: 22px;
    padding: 0 16px;
    font-size: 12px;
    color: var(--text-muted);
    font-style: italic;
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-chat);
    flex-shrink: 0;
}
#typing-bar .dots span {
    display: inline-block;
    width: 5px; height: 5px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: dot-bounce 1.2s infinite;
}
#typing-bar .dots span:nth-child(2) { animation-delay: .2s; }
#typing-bar .dots span:nth-child(3) { animation-delay: .4s; }
@keyframes dot-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-4px); }
}

/* ── Date separator ───────────────────────── */
.date-separator {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 12px 0;
}
.date-separator::before,
.date-separator::after {
    content: '';
    flex: 1;
    height: 1px;
    background: rgba(0,0,0,.12);
}
.date-separator span {
    font-size: 12px;
    color: var(--text-secondary);
    background: rgba(255,255,255,.7);
    border-radius: var(--radius-full);
    padding: 2px 10px;
    white-space: nowrap;
}

/* ── Reply bar ────────────────────────────── */
#reply-bar {
    display: none;
    padding: 8px 12px;
    background: var(--bg-input);
    border-top: 2px solid var(--color-primary);
    border-bottom: 1px solid var(--border-light);
    gap: 10px;
    align-items: center;
    flex-shrink: 0;
}
#reply-bar.show { display: flex; }
#reply-bar .reply-preview {
    flex: 1;
    border-left: 3px solid var(--color-primary);
    padding-left: 8px;
    min-width: 0;
}
#reply-bar .reply-name { font-size: 12px; font-weight: 600; color: var(--color-primary); }
#reply-bar .reply-text {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
#reply-bar .close-reply {
    color: var(--text-muted);
    font-size: 20px;
    line-height: 1;
    padding: 4px;
}

/* ── Input area ───────────────────────────── */
.input-area {
    background: var(--bg-input);
    border-top: 1px solid var(--border-light);
    padding: 8px 12px;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    flex-shrink: 0;
}
#msg-input,
#chat-input {
    flex: 1;
    background: var(--bg-app);
    border-radius: 22px;
    padding: 10px 16px;
    font-size: 15px;
    color: var(--text-primary);
    max-height: 120px;
    overflow-y: auto;
    resize: none;
    line-height: 1.45;
    scrollbar-width: none;
    border: none;
    outline: none;
}
#msg-input::-webkit-scrollbar,
#chat-input::-webkit-scrollbar { display: none; }
.input-area .icon-btn,
.input-btn {
    width: 42px; height: 42px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    color: var(--text-muted);
    font-size: 20px;
    transition: var(--transition);
    flex-shrink: 0;
}
.input-area .icon-btn:hover,
.input-btn:hover { color: var(--color-primary); background: var(--bg-app); }
#btn-send {
    background: var(--color-primary);
    color: #fff;
    width: 42px; height: 42px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px;
    transition: var(--transition);
    flex-shrink: 0;
}
#btn-send:hover { background: var(--color-primary-dark); }

/* ── Context menu ─────────────────────────── */
#context-menu {
    position: fixed;
    background: #fff;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 6px 0;
    z-index: var(--z-modal);
    min-width: 160px;
    display: none;
}
#context-menu.show { display: block; }
.ctx-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 16px;
    font-size: 14px;
    color: var(--text-primary);
    cursor: pointer;
    transition: var(--transition);
}
.ctx-item:hover { background: var(--bg-hover); }
.ctx-item.danger { color: var(--color-danger); }

/* ── Emoji picker ─────────────────────────── */
#emoji-picker {
    position: fixed;
    z-index: var(--z-modal);
    background: #fff;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 10px;
    display: none;
    flex-wrap: wrap;
    gap: 4px;
    width: 220px;
}
#emoji-picker.show { display: flex; }
.emoji-btn {
    font-size: 22px;
    padding: 4px;
    border-radius: 6px;
    cursor: pointer;
    transition: var(--transition);
    line-height: 1;
}
.emoji-btn:hover { background: var(--bg-app); transform: scale(1.2); }

/* ── Pinned messages banner ───────────────── */
#pinned-bar {
    display: none;
    padding: 8px 16px;
    background: var(--color-primary-light);
    border-bottom: 1px solid rgba(41,128,185,.2);
    font-size: 13px;
    color: var(--color-primary);
    cursor: pointer;
    flex-shrink: 0;
    align-items: center;
    gap: 8px;
}
#pinned-bar.show { display: flex; }

/* ── Search overlay ───────────────────────── */
#search-overlay {
    position: absolute;
    inset: 0;
    background: var(--bg-sidebar);
    z-index: 50;
    display: none;
    flex-direction: column;
}
#search-overlay.show { display: flex; }
.so-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-light);
    background: var(--surface-1);
    flex-shrink: 0;
}
.so-input-wrap {
    display: flex;
    align-items: center;
    flex: 1;
    background: var(--bg-app);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0 10px;
    gap: 6px;
    height: 36px;
}
.so-input-wrap:focus-within {
    border-color: var(--brand);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--brand) 15%, transparent);
}
.so-icon { font-size: 13px; flex-shrink: 0; opacity: .6; }
.so-input-wrap input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 13px;
    padding: 0;
    outline: none;
    color: var(--text-primary);
    min-width: 0;
}
.so-input-wrap input::placeholder { color: var(--text-muted); }
.so-close-btn {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-app);
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s, color .15s;
}
.so-close-btn:hover { background: #fee2e2; color: #dc2626; border-color: #fca5a5; }
#search-results { flex: 1; overflow-y: auto; }
.search-result-item {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-light);
    cursor: pointer;
}
.search-result-item:hover { background: var(--bg-hover); }
.search-result-item .sr-conv { font-size: 11px; font-weight: 600; color: var(--brand); margin-bottom: 3px; }
.search-result-item .sr-body { font-size: 14px; color: var(--text-primary); }
.search-result-item .sr-body mark { background: #fff3cd; }

/* ── New conversation — type grid ────────────── */
.type-step-hint { font-size: 12px; color: var(--text-secondary); margin: 0 0 8px; }
.type-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 5px;
    max-height: calc(88vh - 170px);
    min-height: 120px;
    overflow-y: auto;
    overflow-x: hidden;
    padding-right: 2px;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}
.type-grid::-webkit-scrollbar { width: 4px; }
.type-grid::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.type-card {
    border: 1.5px solid var(--border);
    border-radius: 8px;
    padding: 8px 4px 7px;
    cursor: pointer;
    text-align: center;
    transition: border-color .15s, background .15s, box-shadow .12s, transform .1s;
    user-select: none;
    background: var(--surface-1);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
.type-card:hover {
    border-color: var(--brand);
    background: #e8f1fd;
    box-shadow: 0 2px 6px rgba(21,101,192,.13);
    transform: translateY(-1px);
}
.type-card:active { transform: translateY(0); box-shadow: none; background: #d6e8fc; }
.type-card .type-icon { font-size: 18px; margin-bottom: 4px; display: block; line-height: 1; }
.type-card .type-title { font-size: 10px; font-weight: 600; line-height: 1.25; color: var(--text-primary); word-break: break-word; }
.type-card .type-desc { display: none; }

/* ── New conversation — inquiry form ─────────── */
.btn-back-type { background: none; border: none; color: var(--brand); font-size: 13px; cursor: pointer; padding: 0 0 12px 0; display: flex; align-items: center; gap: 4px; }
.selected-type-header { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; padding-bottom: 12px; border-bottom: 1px solid var(--border); }
.selected-type-header .type-icon { font-size: 28px; }
.selected-type-header .type-title { font-size: 15px; font-weight: 600; }
.inquiry-field { display: block; margin-bottom: 12px; font-size: 13px; font-weight: 500; color: var(--text-primary); }
.inquiry-field label, .inquiry-field > span { display: block; margin-bottom: 4px; }
.inquiry-field input:not([type=radio]):not([type=checkbox]),
.inquiry-field select,
.inquiry-field textarea {
    display: block; width: 100%; padding: 8px 10px; border: 1px solid var(--border);
    border-radius: 6px; font-size: 13px; background: var(--surface-2); color: var(--text-primary);
    box-sizing: border-box; font-family: inherit;
}
.inquiry-field textarea { resize: vertical; min-height: 72px; }
.radio-opt, .check-opt { display: flex; align-items: center; gap: 6px; font-size: 13px; margin: 5px 0; font-weight: 400; cursor: pointer; }

/* ── Session expiry warning banner ────────────── */
.session-warn-bar { display: none; position: fixed; top: 0; left: 0; right: 0; z-index: 9999; background: #fff3cd; border-bottom: 2px solid #ffc107; padding: 10px 16px; align-items: center; gap: 12px; font-size: 13px; color: #7a5800; }
.session-warn-bar.active { display: flex; }
.session-warn-btn { padding: 5px 14px; border-radius: 6px; border: none; background: #e65100; color: #fff; cursor: pointer; font-size: 12px; font-weight: 600; white-space: nowrap; }
.session-warn-btn:hover { background: #bf360c; }
.session-warn-close { width: 28px; height: 28px; border-radius: 50%; background: rgba(0,0,0,.12); border: none; cursor: pointer; font-size: 16px; margin-left: auto; color: #555; display: flex; align-items: center; justify-content: center; flex-shrink: 0; transition: background .15s; }
.session-warn-close:hover { background: rgba(0,0,0,.22); color: #000; }

/* ── New conversation button ──────────────────── */
.btn-new-conv-icon {
    font-size: 20px !important;
    font-weight: 400 !important;
}

/* ── PWA install banner inside chat ──────────── */
.pwa-install-bar { display: none; align-items: center; gap: 10px; padding: 10px 14px; background: #e3f2fd; border-top: 1px solid #90caf9; font-size: 12px; color: #0d47a1; }
.pwa-install-bar.active { display: flex; }
.pwa-install-bar .pwa-install-btn { padding: 5px 12px; background: #1565c0; color: #fff; border: none; border-radius: 6px; cursor: pointer; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pwa-install-bar .pwa-install-dismiss { background: none; border: none; font-size: 18px; cursor: pointer; color: #666; margin-left: auto; line-height: 1; }

/* ── Admin types CRUD ─────────────────────────── */
.type-row { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.type-row-icon { font-size: 20px; width: 28px; text-align: center; flex-shrink: 0; }
.type-row-info { flex: 1; min-width: 0; }
.type-row-name { font-weight: 600; }
.type-row-desc { font-size: 11px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.type-row-actions { display: flex; gap: 4px; flex-shrink: 0; }
.type-badge { font-size: 10px; padding: 1px 5px; border-radius: 99px; font-weight: 700; background: #e8f5e9; color: #2e7d32; }
.type-badge.inactive { background: #fce4ec; color: #c62828; }
.inline-form { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin: 8px 0; font-size: 13px; }
.inline-form label { display: flex; flex-direction: column; gap: 3px; margin-bottom: 8px; font-weight: 500; }
.inline-form input, .inline-form select, .inline-form textarea { padding: 6px 8px; border: 1px solid var(--border); border-radius: 5px; font-size: 13px; background: var(--surface-1); color: var(--text-primary); font-family: inherit; }
.inline-form textarea { resize: vertical; min-height: 56px; }
.inline-form-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; font-weight: 500; font-size: 13px; }
.field-options-list { display: flex; flex-direction: column; gap: 4px; margin-top: 4px; }
.field-opt-row { display: flex; gap: 4px; }
.field-opt-row input { flex: 1; }
.sm-btn { padding: 4px 10px; font-size: 12px; border-radius: 5px; border: 1px solid var(--border); background: var(--surface-1); cursor: pointer; }
.sm-btn.primary { background: var(--brand); color: #fff; border-color: transparent; }
.sm-btn.danger { color: #c62828; border-color: #ffcdd2; }
.search-result-item .sr-meta { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
