:root {
    --bg: #f7f7f8;
    --surface: #ffffff;
    --border: #e3e3e8;
    --muted: #888;
    --accent: #2b6cff;
    --bubble-in: #f1f0ee;
    --bubble-out: #d6e7ff;
    --topbar-h: 50px;
    --sidebar-w: 320px;
    --panel-w: 320px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: #222;
    overflow: hidden;
}

.topbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.5rem 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    height: var(--topbar-h);
}

.topbar .user { color: var(--muted); margin-left: auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar a { color: var(--accent); text-decoration: none; }
.topbar .nav-link { flex: 0 0 auto; }
/* Icons are mobile-only; desktop shows the text label. */
.topbar .nav-icon { display: none; }
.topbar .nav-icon svg { display: block; }

/* Login */
.login-page {
    display: grid;
    place-items: center;
    min-height: calc(100dvh - var(--topbar-h));
}

.login-form {
    background: var(--surface);
    padding: 2rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    width: min(320px, 100% - 2rem);
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.login-form label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.85rem; }
.login-form input { padding: 0.5rem; border: 1px solid var(--border); border-radius: 4px; }
.login-form button { padding: 0.6rem; background: var(--accent); color: white; border: 0; border-radius: 4px; cursor: pointer; }
.login-form .error { background: #ffe8e8; padding: 0.5rem; border-radius: 4px; color: #a00; font-size: 0.85rem; }

/* ===== Chat layout — desktop ===== */

.chat-layout {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    height: calc(100dvh - var(--topbar-h));
    min-height: 0;
}
.chat-layout.has-active {
    grid-template-columns: var(--sidebar-w) 1fr var(--panel-w);
}

/* ===== Sidebar ===== */

.chat-sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    grid-column: 1;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-bottom: 1px solid var(--border);
    flex: 0 0 auto;
}
.sidebar-header h2 { margin: 0; font-size: 1rem; flex: 0 0 auto; }
.sidebar-close { display: none; margin-left: auto; }

/* Geo filter, pinned left of the search box */
.sidebar-geo { position: relative; flex: 0 0 auto; }
.sidebar-geo .filter-dropdown { left: 0; }

/* Live search box */
.sidebar-search { position: relative; flex: 1 1 auto; min-width: 0; }
.sidebar-search-input {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.3rem 0.3rem 0.3rem 0.7rem;
    font-size: 0.8rem;
    background: var(--bg);
    color: #222;
}
.sidebar-search-input:focus { outline: none; border-color: var(--accent); }
.sidebar-search-clear {
    position: absolute;
    right: 0.35rem;
    top: 50%;
    transform: translateY(-50%);
    border: none;
    background: none;
    cursor: pointer;
    font-size: 1.1rem;
    line-height: 1;
    color: var(--muted);
    padding: 0 0.25rem;
}
.sidebar-search-clear:hover { color: #222; }
.sidebar-search-clear[hidden] { display: none; }

/* Filters bar */
.sidebar-filters {
    display: flex;
    flex-direction: column;
    padding: 0.5rem 1rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    position: relative;
    flex: 0 0 auto;
}

/* Meta-filter (preset) buttons — compact but with a large-enough tap target
   for mobile. Selected preset is highlighted; see conversation_filter_controller.js#renderMetaButtons. */
.meta-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}
.meta-filter-btn {
    flex: 1 1 calc(50% - 0.2rem);
    min-width: 7rem;
    border: 1px solid var(--border);
    background: var(--bg);
    border-radius: 8px;
    padding: 0.45rem 0.5rem;
    font-size: 0.78rem;
    line-height: 1.1;
    text-align: center;
    cursor: pointer;
    color: #222;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.meta-filter-btn.is-active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

/* Manual-filters expand/collapse toggle + panel. The toggle is a plain
   chevron stack, centered at the bottom of the block and gray — it's a
   secondary affordance, not a labeled action. */
.manual-filters-toggle {
    display: flex;
    justify-content: center;
    align-self: stretch;
    border: none;
    background: none;
    padding: 0.05rem 0;
    cursor: pointer;
}
.manual-filters-toggle span {
    font-size: 0.85rem;
}
.manual-filters-toggle-chevrons span:first-child { margin-left: 0; }
.manual-filters-toggle:hover .manual-filters-toggle-chevrons { color: #888; }
.manual-filters-toggle[aria-expanded="true"] .manual-filters-toggle-chevrons { transform: rotate(180deg); }
.manual-filters {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
    padding-top: 0.4rem;
    margin: 0.4rem 0;
    border-top: 1px solid var(--border);
}
.manual-filters[hidden] { display: none; }
.filter-toggle {
    border: 1px solid var(--border);
    background: var(--bg);
    border-radius: 999px;
    padding: 0.25rem 0.65rem;
    font-size: 0.8rem;
    cursor: pointer;
    color: #222;
}
.filter-toggle.has-selection { background: #eef3ff; border-color: var(--accent); color: var(--accent); }
.filter-toggle .caret { font-size: 0.65rem; margin-left: 0.15rem; }

.filter-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.5rem 0.75rem;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    z-index: 30;
    min-width: 180px;
}
.filter-dropdown[hidden] { display: none; }
.filter-dropdown label { font-size: 0.85rem; display: flex; gap: 0.4rem; align-items: center; cursor: pointer; }
.filter-checkbox { font-size: 0.8rem; display: flex; gap: 0.35rem; align-items: center; cursor: pointer; color: #444; }

/* Tri-state status options: neutral (☐) → include (✓) → exclude (✕). */
.filter-dropdown-tri { min-width: 210px; }
.tri-option {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    width: 100%;
    border: none;
    background: none;
    padding: 0.2rem 0.15rem;
    font-size: 0.85rem;
    text-align: left;
    cursor: pointer;
    color: #222;
    border-radius: 4px;
}
.tri-option:hover { background: var(--bg); }
.tri-box {
    flex: 0 0 auto;
    width: 1.1em;
    text-align: center;
    font-size: 0.95rem;
    line-height: 1;
    color: #999;
}
.tri-box::before { content: '☐'; }
.tri-option.is-include .tri-box { color: #1a7f37; }
.tri-option.is-include .tri-box::before { content: '✓'; }
.tri-option.is-exclude .tri-box { color: #b22222; }
.tri-option.is-exclude .tri-box::before { content: '✕'; }
.tri-option.is-exclude .tri-label { color: #999; text-decoration: line-through; }
.tri-legend {
    margin-top: 0.3rem;
    padding-top: 0.35rem;
    border-top: 1px solid var(--border);
    font-size: 0.7rem;
    color: #888;
}
.tri-legend .tri-inc { color: #1a7f37; }
.tri-legend .tri-exc { color: #b22222; }

/* Red-flag filter: icon-only checkbox, bright when active, dim otherwise. */
.filter-red-flag input { display: none; }
.filter-red-flag .red-flag-filter-icon {
    font-size: 1rem;
    line-height: 1;
    filter: grayscale(1);
    opacity: 1;
    transition: filter 0.12s, opacity 0.12s;
}
.filter-red-flag.is-active .red-flag-filter-icon { filter: none; opacity: 1; }
.filter-red-flag.is-active { color: #b22222; }

/* Conversation list */
.conversation-list {
    list-style: none;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1 1 auto;
    min-height: 0;
}
.conversation-item.is-filtered-out { display: none; }
.conversation-item a {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    text-decoration: none;
    color: inherit;
}
.conversation-item.is-active a { background: #eef3ff; }
.conversation-item .title { display: flex; align-items: center; gap: 0.35rem; min-width: 0; }
.conversation-item .title .contact-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-item .title small { color: var(--muted); font-weight: normal; flex: 0 0 auto; }
.conversation-item .preview {
    display: flex;
    align-items: baseline;
    gap: 0.25rem;
    min-width: 0;
    font-size: 0.8rem;
    color: var(--muted);
}
.conversation-item .preview .preview-marker { color: var(--accent); flex: 0 0 auto; font-weight: 600; }
.conversation-item .preview .preview-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
    flex: 1 1 auto;
}
.conversation-item .preview.is-incoming .preview-text { color: #333; }
/* Unread: newest message is an incoming one the chatter hasn't opened yet. */
.conversation-item.is-unviewed .preview-text { font-weight: 700; color: #111; }
.conversation-item.is-unviewed .preview-marker { font-weight: 700; }
.conversation-item .meta { display: flex; gap: 0.5rem; color: var(--muted); font-size: 0.75rem; }
.conversation-item .red-flag-badge { flex: 0 0 auto; font-size: 0.9rem; line-height: 1; }

/* Infinite-scroll loading placeholder (next page of conversations) */
.conversation-list-loading { list-style: none; padding: 0.5rem 1rem; }
.skeleton-item {
    height: 3.1rem;
    border-radius: 6px;
    margin-bottom: 0.5rem;
    background: linear-gradient(90deg, #eee 25%, #f5f5f5 37%, #eee 63%);
    background-size: 400% 100%;
    animation: skeleton-shimmer 1.4s ease infinite;
}
.skeleton-item:last-child { margin-bottom: 0; }
@keyframes skeleton-shimmer {
    0% { background-position: 100% 50%; }
    100% { background-position: 0 50%; }
}

/* Tenant badge */
.tenant-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    padding: 0 0.3rem;
    height: 16px;
    border-radius: 4px;
    font-size: 0.65rem;
    font-weight: 700;
    background: #eef3ff;
    color: var(--accent);
    border: 1px solid #d8e2ff;
    flex: 0 0 auto;
    line-height: 1;
    letter-spacing: 0.02em;
    vertical-align: middle;
}

/* Channel icon */
.channel-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    flex: 0 0 auto;
    vertical-align: middle;
}
.channel-icon svg { display: block; width: 16px; height: 16px; }
.channel-fallback {
    width: 16px; height: 16px;
    border-radius: 50%;
    background: var(--muted);
    color: #fff;
    font-size: 0.65rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* ===== Chat detail frame ===== */

.chat-detail-frame {
    display: contents;
}

.chat-main {
    grid-column: 2;
    display: flex;
    flex-direction: column;
    min-height: 0;
    min-width: 0;
    background: var(--bg);
}

.chat-header {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    padding: 0.75rem 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex: 0 0 auto;
}
.header-identity { display: flex; flex-direction: column; gap: 0.25rem; min-width: 0; flex: 1 1 auto; }
.header-identity strong { font-size: 0.95rem; display: flex; align-items: center; gap: 0.35rem; min-width: 0; }
.header-identity strong .contact-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.header-identity strong small { color: var(--muted); font-weight: normal; flex: 0 0 auto; }
.header-chips { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; }

.chat-header .badge,
.chat-header .status,
.chat-header .price,
.chat-header .ai-mode {
    font-size: 0.75rem;
    color: var(--muted);
    background: var(--bg);
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
}

/* Editable chips (status / price popovers) */
.chip-editor { position: relative; }
.chip-trigger {
    border: 1px solid var(--border);
    cursor: pointer;
    font-family: inherit;
    font-size: 0.75rem;
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    line-height: 1.2;
}
.chip-trigger:hover { background: #eef3ff; color: var(--accent); border-color: var(--accent); }
.chip-trigger .caret { font-size: 0.6rem; }

.chip-popover {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 6px 18px rgba(0,0,0,0.10);
    padding: 0.5rem;
    z-index: 40;
    min-width: 220px;
    max-width: min(320px, calc(100vw - 24px));
}
.chip-popover[hidden] { display: none; }

.status-options {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}
.status-option {
    width: 100%;
    text-align: left;
    border: 0;
    background: transparent;
    padding: 0.4rem 0.6rem;
    border-radius: 4px;
    cursor: pointer;
    font: inherit;
    color: #222;
}
.status-option:hover { background: var(--bg); }
.status-option.is-current { background: #eef3ff; color: var(--accent); font-weight: 600; }

.chip-price-form { display: flex; flex-direction: column; gap: 0.5rem; }
.chip-price-form .price-row {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    font-size: 0.75rem;
    color: var(--muted);
}
.chip-price-form input,
.chip-price-form select {
    padding: 0.35rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font: inherit;
    color: #222;
}
.chip-price-form .price-actions { display: flex; justify-content: flex-end; }
/* Submit button of every header chip popover (price, requisites, ...). */
.chip-price-form button.primary {
    padding: 0.25rem 0.6rem;
    background: var(--accent);
    color: #fff;
    border: 0;
    border-radius: 4px;
    cursor: pointer;
    font: inherit;
    font-size: 0.75rem;
}

.header-back, .header-info, .sidebar-close, .sidebar-logout, .panel-close { display: none; }
.icon-btn {
    width: 32px;
    height: 32px;
    border: 0;
    background: transparent;
    border-radius: 6px;
    font-size: 1.2rem;
    cursor: pointer;
    color: #555;
    line-height: 1;
}
.icon-btn:hover { background: var(--bg); }
.sidebar-logout svg { width: 1.3rem; height: 1.3rem; }

.ai-toggle-form { flex: 0 0 auto; }
.ai-toggle-form button { border: 0; cursor: pointer; }
.ai-mode { font-size: 1em; }
.ai-mode.is-on { background: #e8f6e8; color: #1c6b2c; }
.ai-mode.is-off { background: #ffe8e8; color: #b22222; }

/* Header red-flag toggle: filled red when raised, dim when clear. */
.red-flag-form { flex: 0 0 auto; }
.red-flag-toggle {
    border: 1px solid var(--border);
    background: var(--bg);
    border-radius: 999px;
    padding: 0.15rem 0.5rem;
    font-size: 0.9rem;
    line-height: 1;
    cursor: pointer;
}
.red-flag-toggle.is-clear { filter: grayscale(1); opacity: 1; }
.red-flag-toggle.is-flagged { background: #ffe8e8; border-color: #b22222; opacity: 1; filter: none; }

.activity-feed {
    flex: 1 1 auto;
    overflow-y: auto;
    /* Feed scrolls vertically only; explicit so overflow-y:auto doesn't
       implicitly promote overflow-x to auto and show a stray h-scrollbar. */
    overflow-x: hidden;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-height: 0;
}

.message { display: flex; flex-direction: column; max-width: 70%; }
.message.is-incoming { align-self: flex-start; }
.message.is-outgoing { align-self: flex-end; }

.message .bubble {
    padding: 0.5rem 0.75rem;
    border-radius: 12px;
    background: var(--bubble-in);
    word-wrap: break-word;
}

.message.is-outgoing .bubble { background: var(--bubble-out); }

.message time {
    font-size: 0.7rem;
    color: var(--muted);
    margin-top: 0.15rem;
    text-align: center;
}

.message .author { font-size: 0.7rem; color: var(--muted); }
.message.is-outgoing time,
.message.is-outgoing .author { align-self: flex-end; }

.message-event {
    align-self: center;
    color: var(--muted);
    font-size: 0.8rem;
    background: var(--surface);
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    border: 1px dashed var(--border);
}

.message-event.message-tool {
    font-size: 0.7rem;
    font-style: italic;
    color: #aaa;
    background: transparent;
    border: 0;
    padding: 0.1rem 0.5rem;
}

.message-event-meta { display: block; text-align: center; }
.message-event-meta time { margin: 0; font-size: inherit; }

.message-event.message-red-flag.is-raised {
    color: #b22222;
    background: #ffecec;
    border-color: #e6a3a3;
    border-style: solid;
}
.message-event.message-red-flag.is-cleared { color: #1c6b2c; }

.message-chat img { max-width: 200px; max-height: 400px; border-radius: 6px; }
.message-event.message-tool time { margin-left: 0.4rem; }

/* Outgoing footer: author + time + delivery ticks on one line */
.message .message-meta { display: flex; align-items: center; gap: 0.3rem; }
.message.is-outgoing .message-meta { justify-content: flex-end; }
.message.is-incoming .message-meta { justify-content: flex-start; }
.message .message-meta time { margin-top: 0; }

.msg-ticks { font-size: 0.72rem; line-height: 1; color: var(--muted); letter-spacing: -2px; }
.msg-ticks.is-read { color: var(--accent); }
.msg-ticks.is-failed { color: #b22222; letter-spacing: 0; }

.msg-failed-icon { color: #b22222; font-size: 0.85rem; line-height: 1; cursor: help; }

/* Failed outgoing message: reddish bubble instead of the usual accent color. */
.message.is-outgoing .bubble.is-failed,
.tarot-bubble.is-failed,
.chat-draft-bubble.is-failed {
    background: #ffecec;
    border: 1px solid #e6a3a3;
}

.window-closed-banner {
    align-self: center;
    max-width: 90%;
    color: #b22222;
    background: #ffecec;
    border: 1px solid #e6a3a3;
    border-radius: 8px;
    padding: 0.5rem 0.9rem;
    margin: 0 auto 0.4rem;
    font-size: 0.82rem;
    text-align: center;
}

/* Quoted / replied-to message preview */
.reply-quote {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    padding: 0.25rem 0.5rem;
    margin-bottom: 0.2rem;
    border-left: 3px solid var(--accent);
    border-radius: 4px;
    background: rgba(43, 108, 255, 0.07);
    text-decoration: none;
    color: inherit;
    max-width: 100%;
}
.reply-quote.is-static { cursor: default; }
.reply-quote-author { font-size: 0.7rem; font-weight: 600; color: var(--accent); }
.reply-quote-text {
    font-size: 0.78rem;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-wrap: auto;
}

/* Forwarded message — compact label inside the bubble, like a reply quote */
.forward-origin {
    display: block;
    font-size: 0.72rem;
    color: var(--muted);
    font-style: italic;
    margin-bottom: 1px;
}
.forward-origin strong { color: var(--accent); font-style: normal; font-weight: 600; }
.message .bubble.is-forwarded { border-left: 3px solid var(--muted); border-top-left-radius: 4px; border-bottom-left-radius: 4px; }

/* "Show original / Show translation" toggle under a translated message */
.translation-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
}
.translation-toggle {
    display: block;
    padding: 0;
    background: none;
    border: none;
    font-size: 0.72rem;
    color: var(--muted);
    cursor: pointer;
    opacity: 0.85;
}
.translation-toggle:hover { color: var(--accent); opacity: 1; text-decoration: underline; }
.bubble-text.is-original { font-style: italic; }

.translation-retry {
    padding: 0;
    background: none;
    border: none;
    font-size: 0.85rem;
    line-height: 1;
    color: var(--muted);
    cursor: pointer;
    opacity: 0.7;
}
.translation-retry:hover { color: var(--accent); opacity: 1; }
.translation-retry:disabled { cursor: default; opacity: 0.4; }
.translation-retry.is-loading { animation: translation-retry-spin 0.8s linear infinite; }
@keyframes translation-retry-spin { to { transform: rotate(360deg); } }

/* Emoji reactions — sit in the bubble's bottom-right corner (the meta row) */
.reactions-corner { display: inline-flex; align-items: center; gap: 0.2rem; position: relative; }
.message.is-incoming .reactions-corner { margin-left: auto; }
.reaction-chip {
    font-size: 0.85rem;
    line-height: 1;
    padding: 0.05rem 0.3rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface);
    cursor: default;
}
.reaction-chip.is-own { cursor: pointer; border-color: var(--accent); background: #eef3ff; }
.reaction-add {
    font-size: 0.95rem;
    line-height: 1;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    opacity: 0.45;
    transition: opacity 0.1s;
}
.reaction-add:hover { opacity: 1; }
.message:hover .reaction-add, .reactions-corner:focus-within .reaction-add { opacity: 0.85; }
.reaction-add-wrap { position: relative; display: inline-flex; }
.reaction-picker {
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-bottom: 0.25rem;
    display: flex;
    flex-wrap: nowrap;
    justify-content: center;
    gap: 0.15rem;
    padding: 0.25rem;
    max-width: min(320px, 90vw);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
    z-index: 5;
}
.reaction-picker[hidden] { display: none; }
.reaction-option {
    font-size: 1.1rem;
    line-height: 1;
    padding: 0.15rem;
    border: 0;
    background: transparent;
    cursor: pointer;
    border-radius: 6px;
}
.reaction-option:hover { background: var(--bg); }
.reaction-option {
    font-size: 1.1rem;
    line-height: 1;
    padding: 0.15rem;
    border: 0;
    background: transparent;
    cursor: pointer;
    border-radius: 6px;
}
.reaction-option:hover { background: var(--bg); }

.message-ad { align-self: center; max-width: 85%; width: 85%; }
.message-ad time { align-self: center; }
.ad-card {
    border: 1px solid var(--border);
    border-left: 3px solid #1877f2;
    border-radius: 10px;
    background: var(--surface);
    padding: 0.6rem 0.75rem;
}
.ad-card-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.5rem; }
.ad-card-title { font-size: 0.8rem; font-weight: 600; color: var(--muted); }
.ad-source-badge {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #fff;
    background: #1877f2;
    padding: 0.1rem 0.45rem;
    border-radius: 999px;
}
.ad-source-badge.is-tiktok { background: #000; }
.ad-source-badge.is-tg_start { background: #229ed9; }
.ad-card-body { display: flex; gap: 0.6rem; }
.ad-thumb img { width: 80px; height: 80px; object-fit: cover; border-radius: 6px; }
.ad-card-text { display: flex; flex-direction: column; gap: 0.25rem; min-width: 0; }
.ad-headline { font-weight: 600; font-size: 0.85rem; }
.ad-body { font-size: 0.8rem; color: var(--muted); white-space: pre-wrap; word-wrap: break-word; }
.ad-link { font-size: 0.78rem; }
.ad-card-meta { display: flex; gap: 0.75rem; margin-top: 0.5rem; font-size: 0.68rem; color: var(--muted); }

.attachment { display: flex; flex-direction: column; gap: 0.3rem; }
.attachment-transcript {
    font-size: 0.8rem;
    color: #555;
    font-style: italic;
    background: rgba(0, 0, 0, 0.04);
    border-left: 2px solid rgba(0, 0, 0, 0.15);
    padding: 0.3rem 0.5rem;
    border-radius: 4px;
    max-width: 360px;
    white-space: pre-wrap;
    word-wrap: break-word;
}
.pdf-preview { display: flex; flex-direction: column; gap: 0.3rem; }
.pdf-embed {
    width: 360px;
    max-width: 100%;
    height: 480px;
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 6px;
    background: #fff;
}
.attachment-link {
    font-size: 0.85rem;
    color: #2563eb;
    text-decoration: none;
}
.attachment-link:hover { text-decoration: underline; }

/* ===== Tarot reading bubble ===== */

.message-tarot { max-width: 85%; width: 85%; }
.message-tarot time { align-self: flex-end; }

.tarot-bubble {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    padding: 0.5rem 0.75rem;
    width: 100%;
    box-sizing: border-box;
}
/* Header/divider/meta live inside one wrapping element in the draft case
   (see the template docblock on why), so it must reproduce the bubble's own
   gap itself — otherwise they'd sit flush with no spacing between them. */
.tarot-order-wrap { display: flex; flex-direction: column; gap: 0.3rem; }
.message-tarot.is-draft .tarot-bubble:not(.is-editing) .tarot-text {
    cursor: pointer;
    border-radius: 6px;
    transition: background 120ms;
}
.message-tarot.is-draft .tarot-bubble:not(.is-editing) .tarot-text:hover { background: #fff; }

/* Draft (not yet sent) gets a distinct yellow tint so a chatter can never
   mistake it for a delivered message — same idea as .is-failed's red tint,
   which takes priority (:not) when a send attempt on the draft failed. */
.message-tarot.is-draft .tarot-bubble:not(.is-failed) {
    background: #fffbeb;
    border: 1px solid #fbbf24;
}

.tarot-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}
.tarot-title {
    font-weight: 300;
    font-size: 0.8rem;
    line-height: 1.3;
}
.tarot-title small {
    font-weight: 400; color: var(--muted);
}

/* The editable headline reuses .tarot-title's look but is a <button> living
   in the header row itself (not the block-style buttons below it), so it
   needs its own reset instead of the shared .tarot-order-headline rule. */
/* flex: 1 1 auto so it takes the space .tarot-header-right doesn't need, but
   can also shrink below its content's natural width for a long service name
   — text-overflow below turns that into an ellipsis instead of a wrap. */
.tarot-order-headline-wrap { position: relative; flex: 1 1 auto; min-width: 0; }
button.tarot-order-headline {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    width: 100%;
    border: 0;
    background: none;
    padding: 0;
    margin: 0;
    cursor: pointer;
    /* NOT the `font` shorthand — a <button> doesn't inherit typography by
       default, and `font: inherit` pulls the *parent's* ambient font-size
       (16px, since nothing here sets one) rather than .tarot-title's own
       0.8rem, which used to blow the header up to several lines' worth of
       height. Only the family needs inheriting; size/weight/line-height
       come from .tarot-title, which is also on this element. */
    font-family: inherit;
    color: inherit;
    text-align: left;
    min-width: 0;
}
button.tarot-order-headline:hover .tarot-order-edit-icon { color: #333; }
.tarot-order-headline-icon,
.tarot-order-edit-icon { flex: 0 0 auto; }
/* The one part allowed to shrink and clip — a long service name/subtype
   ellipsizes instead of wrapping the button onto a second line and
   inflating the whole header's height. */
.tarot-order-headline-text {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.tarot-header-right {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    flex: 0 0 auto;
}
.tarot-send-form { margin: 0; display: inline-flex; }

/* Always visible near Draft — the icon-only refresh glyph, muted by default;
   .is-stale (order edited after this reading's own updatedAt, see
   OrderedService::needsRegeneration()) switches it to the accent color so a
   chatter still notices the reading is now out of date. */
.tarot-btn-regen {
    background: #fff;
    border-color: var(--border);
    color: var(--muted);
    line-height: 1;
}
.tarot-btn-regen:hover { background: var(--bg); }
.tarot-btn-regen.is-stale {
    border-color: var(--accent);
    color: var(--accent);
    font-weight: 600;
}
.tarot-btn-regen.is-stale:hover { background: var(--accent); color: #fff; }

/* Final review verdict, before the 📜 icon: ✅ clean pass, ❌ outstanding
   violations (see TarotReadingMessage::$reviewedAt / $currentViolations). */
.tarot-review-badge { flex: 0 0 auto; font-size: 0.75rem; }

.tarot-status-badge {
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    padding: 0.1rem 0.4rem;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.08);
    color: #333;
}
.tarot-status-badge.is-draft { background: #fde68a; color: #7c4a03; }
.tarot-status-badge.is-sent { background: #bbf7d0; color: #14532d; }

.tarot-meta {
    font-size: 0.75rem;
    color: var(--muted);
    line-height: 1.25;
    white-space: normal;
}

.tarot-history {
    white-space: pre-wrap;
    margin-bottom: 0.35rem;
}

.tarot-customer { display: flex; align-items: center; gap: 0.3rem; flex-wrap: wrap; }

.tarot-issue-badge {
    font-size: 0.65rem;
    background: #fee2e2;
    color: #991b1b;
    border-radius: 999px;
    padding: 0.05rem 0.4rem;
    display: inline-block;
    margin-bottom: 0.3rem;
}

/* Notice-only variant: unlike .tarot-issue-badge this never blocks send —
   just a heads-up that a clarifying question/short history is still blank. */
.tarot-issue-badge--notice {
    background: #fef3c7;
    color: #92400e;
}

/* Review status of the payment a reading draft belongs to (see
   _message.html.twig): green = confirmed, yellow = still in review, red = declined. */
.tarot-payment-badge--approved { background: #dcfce7; color: #166534; }
.tarot-payment-badge--pending { background: #fef3c7; color: #92400e; }
.tarot-payment-badge--rejected { background: #fee2e2; color: #991b1b; }

/* AI reviewer findings — between the service headline and the customers
   block (see _message.html.twig), red so a chatter can't miss why the draft
   didn't go out. */
.tarot-review-violations {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    margin: 0.1rem 0;
    font-size: 0.8rem;
    color: #b91c1c;
}
.tarot-review-violation { white-space: pre-wrap; }

/* Shared "popover panel" look for every small edit form hanging off the
   order panel (headline, a customer slot, notes) and off a people row. */
.tarot-order-popover,
.people-edit-popover {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    z-index: 30;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    /* Fixed, not just min/max — a <details> opening inside (the "+ Новый
       человек" block) must never grow the panel; it only reveals rows
       inside a width that's already settled. */
    width: 260px;
    max-width: calc(100vw - 24px);
    padding: 0.4rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface, #fff);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
    font-size: 0.75rem;
    color: #222;
}
.tarot-order-popover[hidden],
.people-edit-popover[hidden] { display: none; }

.tarot-order-popover label,
.people-edit-form label {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    font-size: 0.7rem;
    color: var(--muted);
}
.tarot-order-popover input,
.tarot-order-popover select,
.tarot-order-popover textarea,
.people-edit-form input,
.people-edit-form select {
    font: inherit;
    padding: 0.25rem 0.35rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: #fff;
    color: #111;
}
.tarot-order-popover textarea { min-height: 50px; resize: vertical; }
.people-edit-form { display: flex; flex-direction: column; gap: 0.4rem; }

.tarot-order-actions,
.people-edit-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

.tarot-order-customer-wrap,
.tarot-order-notes-wrap { position: relative; margin-bottom: 0.15rem; }

.tarot-order-notes-btn {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    text-align: left;
    border: 1px dashed transparent;
    background: none;
    padding: 0.05rem 0.15rem;
    border-radius: 4px;
    cursor: pointer;
    font: inherit;
    color: inherit;
    width: 100%;
}
.tarot-order-notes-btn:hover { border-color: var(--border); background: #fff; }

.tarot-order-customer-btn {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    text-align: left;
    border: 1px dashed transparent;
    background: none;
    padding: 0.15rem;
    border-radius: 4px;
    cursor: pointer;
    font: inherit;
    color: inherit;
    width: 100%;
}
.tarot-order-customer-btn:hover { border-color: var(--border); background: #fff; }
.tarot-order-customer-btn .people-row-body { flex: 1 1 auto; }

/* Pencil hint only earns its space on mobile, where there's no hover state
   to reveal "this is clickable" — see the (max-width: 768px) block below. */
.tarot-order-edit-icon { font-size: 0.7rem; color: var(--muted); flex: 0 0 auto; display: none; }

.tarot-order-customers { display: flex; flex-direction: column; gap: 0.05rem; margin-bottom: 0.15rem; }

.tarot-order-customer-list {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    max-height: 220px;
    overflow-y: auto;
    margin-bottom: 0.3rem;
}

.people-popover-new-btn {
    border: 0;
    background: none;
    color: var(--accent);
    cursor: pointer;
    font: inherit;
    font-size: 0.7rem;
    text-align: left;
    padding: 0.1rem 0;
}

.tarot-order-new-person {
    border-top: 1px solid var(--border);
    padding-top: 0.35rem;
}
.tarot-order-new-person summary { cursor: pointer; font-size: 0.7rem; color: var(--muted); }
.tarot-order-new-person input,
.tarot-order-new-person select { margin-top: 0.3rem; width: 100%; }

.tarot-order-relationship-label { border-top: 1px solid var(--border); padding-top: 0.35rem; }

/* Header "People" popover + the customer-row list it shares with the
   order's own customer-slot picker. */
.people-btn svg { width: 14px; height: 14px; }
.people-popover { min-width: 260px; max-width: min(320px, calc(100vw - 24px)); max-height: min(400px, calc(100vh - 80px)); overflow-y: auto; }
.people-popover-title { font-size: 0.7rem; color: var(--muted); margin-bottom: 0.3rem; }
.people-popover-empty { font-size: 0.75rem; color: var(--muted); }

.people-row { display: flex; align-items: center; gap: 0.3rem; padding: 0.2rem 0; }
.people-row-main {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border: 0;
    background: none;
    padding: 0.2rem;
    border-radius: 4px;
    cursor: pointer;
    font: inherit;
    text-align: left;
    color: inherit;
    min-width: 0;
}
.people-row-main:hover:not(:disabled) { background: var(--bg); }
.people-row-main:disabled { cursor: default; }
.people-row-avatar {
    flex: 0 0 auto;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: #eef3ff;
    color: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 600;
}
.people-row-body { display: flex; flex-direction: column; min-width: 0; }
.people-row-name { font-size: 0.8rem; color: #222; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.people-row-role { color: var(--muted); font-weight: normal; }
.people-row-meta { font-size: 0.7rem; color: var(--muted); }
.people-row-missing { color: #b45309; }
.people-row-edit { position: relative; flex: 0 0 auto; }
.people-row-edit-btn {
    border: 0;
    background: none;
    cursor: pointer;
    color: var(--muted);
    font-size: 0.75rem;
    padding: 0.2rem;
}
.people-row-edit-btn:hover { color: #333; }
.people-popover-new { position: relative; margin-top: 0.3rem; }

.tarot-divider {
    border: 0;
    border-top: 1px solid rgba(0, 0, 0, 0.12);
    margin: 0.1rem 0;
}

.tarot-text { white-space: pre-wrap; word-wrap: break-word; }

.tarot-textarea {
    width: 100%;
    min-height: 140px;
    padding: 0.4rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font: inherit;
    resize: vertical;
    background: #fff;
    box-sizing: border-box;
}

.tarot-edit-footer { display: contents; }

.tarot-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}
.tarot-actions form { margin: 0; }

/* Visibility driven by .is-editing on the bubble */
.tarot-bubble:not(.is-editing) .tarot-textarea,
.tarot-bubble:not(.is-editing) .tarot-edit-footer,
.chat-draft-bubble:not(.is-editing) .tarot-textarea,
.chat-draft-bubble:not(.is-editing) .tarot-edit-footer { display: none; }
.tarot-bubble.is-editing .tarot-text,
.tarot-bubble.is-editing .tarot-send-form,
.chat-draft-bubble.is-editing .tarot-text,
.chat-draft-bubble.is-editing .tarot-send-form { display: none; }

/* ===== Chat draft bubble (chatter/AI-drafted ChatMessage, pending send) =====
   Sized like a regular chat bubble, not the wide tarot-reading layout. */
.message-chat-draft { max-width: 70%; }
.message-chat-draft time { align-self: flex-end; }

.chat-draft-bubble {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    padding: 0.5rem 0.75rem;
    box-sizing: border-box;
}
.message-chat-draft.is-draft .chat-draft-bubble { cursor: text; }
.message-chat-draft.is-draft .chat-draft-bubble.is-editing { cursor: default; }

.message-chat-draft.is-draft .chat-draft-bubble:not(.is-failed) {
    background: #fffbeb;
    border: 1px solid #fbbf24;
}

.tarot-btn {
    padding: 0.35rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: #fff;
    color: #222;
    cursor: pointer;
    font: inherit;
}
.tarot-btn-sm {
    padding: 0.1rem 0.5rem;
    font-size: 0.7rem;
    line-height: 1.2;
}
.tarot-btn-primary {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}
.tarot-btn[disabled] { opacity: 0.6; cursor: default; }

.is-fading-out {
    opacity: 0;
    transform: scale(0.96);
    transition: opacity 250ms ease, transform 250ms ease;
    pointer-events: none;
}

/*
 * "Crumbling" delete animation: a dot-pattern mask starts small enough to
 * read as solid, then grows while the dot radius stays fixed, so the bubble
 * visibly dissolves into grains rather than just fading — paired with a
 * gentle downward drift, blur and rotation for weight. Pure CSS, no canvas.
 */
.is-crumbling {
    animation: crumble 600ms cubic-bezier(0.55, 0, 0.85, 0.35) forwards;
    pointer-events: none;
    transform-origin: 50% 0%;
    -webkit-mask-repeat: repeat;
    mask-repeat: repeat;
}

@keyframes crumble {
    0% {
        opacity: 1;
        filter: blur(0);
        transform: translateY(0) scale(1) rotate(0deg);
        -webkit-mask-image: radial-gradient(circle 2px at center, #000 99%, transparent 100%);
        mask-image: radial-gradient(circle 2px at center, #000 99%, transparent 100%);
        -webkit-mask-size: 3px 3px;
        mask-size: 3px 3px;
    }
    45% {
        opacity: 0.85;
        filter: blur(0.5px);
        -webkit-mask-size: 8px 8px;
        mask-size: 8px 8px;
    }
    100% {
        opacity: 0;
        filter: blur(2px);
        transform: translateY(14px) scale(0.92) rotate(2deg);
        -webkit-mask-image: radial-gradient(circle 1.5px at center, #000 99%, transparent 100%);
        mask-image: radial-gradient(circle 1.5px at center, #000 99%, transparent 100%);
        -webkit-mask-size: 18px 18px;
        mask-size: 18px 18px;
    }
}

.chat-empty-wrap { display: flex; align-items: center; justify-content: center; }
.chat-empty { color: var(--muted); padding: 2rem; }

.chat-reply {
    display: flex;
    gap: 0.5rem;
    padding: 0.5rem;
    background: var(--surface);
    border-top: 1px solid var(--border);
    flex: 0 0 auto;
    align-items: flex-end;
}

/* Hidden native file input */
.chat-reply-file-input {
    display: none;
}

/* Dropzone — wraps preview + textarea */
.chat-reply-dropzone {
    flex: 1 1 auto;
    min-width: 0;
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    border: 2px dashed transparent;
    border-radius: 8px;
    transition: border-color 150ms ease, background 150ms ease;
    padding: 2px;
}
.chat-reply-dropzone.is-drag-over {
    border-color: var(--accent);
    background: #edf3ff;
}

/* Image preview strip */
.chat-reply-preview {
    position: relative;
    display: inline-flex;
    align-items: flex-start;
    align-self: flex-start;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid var(--border);
}
.chat-reply-preview[hidden] { display: none; }
.chat-reply-preview img {
    display: block;
    max-height: 120px;
    max-width: 220px;
    object-fit: cover;
    border-radius: 5px;
}
.chat-reply-preview-remove {
    position: absolute;
    top: 3px;
    right: 3px;
    width: 20px;
    height: 20px;
    line-height: 18px;
    text-align: center;
    border-radius: 50%;
    background: rgba(0,0,0,.55);
    color: #fff;
    border: 0;
    cursor: pointer;
    font-size: 14px;
    padding: 0;
}
.chat-reply-preview-remove:hover {
    background: rgba(0,0,0,.8);
}

.chat-reply textarea {
    flex: 1 1 auto;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    resize: vertical;
    min-height: 44px;
    max-height: 200px;
    font: inherit;
    width: 100%;
}
.chat-reply-dropzone.has-preview textarea {
    min-height: 36px;
}

/* Actions column: icon row on top, Send below */
.chat-reply-actions {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    flex: 0 0 auto;
    align-self: stretch;
}

/* Top row of small icon buttons */
.chat-reply-icon-row {
    display: flex;
    flex-direction: row;
    gap: 0.25rem;
    flex: 0 0 auto;
}

/* Shared style for small icon buttons (attach, AI) */
.chat-reply-icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    padding: 0;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 5px;
    cursor: pointer;
    color: var(--muted);
    transition: color 150ms, border-color 150ms;
    flex: 0 0 auto;
    position: relative;
}
.chat-reply-icon-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
}
.chat-reply-icon-btn svg {
    display: block;
    width: 14px;
    height: 14px;
}

/* Wrapper that anchors the dropdown */
.chat-reply-ai-wrap {
    position: relative;
    display: flex;
    align-items: flex-end;
}

/* AI dropdown panel */
.chat-reply-ai-dropdown {
    position: absolute;
    bottom: calc(100% + 6px);
    right: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,.1);
    min-width: 180px;
    padding: 0.25rem 0;
    z-index: 200;
}
.chat-reply-ai-dropdown[hidden] { display: none; }

/* Requisites button lives in the header, next to the price chip — reuses the
   .price/.chip-trigger pill style, just with an icon instead of text. */
.chat-reply-requisites-btn svg {
    display: block;
    width: 14px;
    height: 14px;
}

.chat-reply-ai-dropdown button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.45rem 0.75rem;
    background: none;
    border: 0;
    cursor: pointer;
    font: inherit;
    font-size: 0.85rem;
    color: #333;
    white-space: nowrap;
}
.chat-reply-ai-dropdown button:hover {
    background: var(--bg);
    color: var(--accent);
}
.chat-reply-ai-dropdown button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}
.chat-reply-ai-dropdown button:disabled:hover {
    background: none;
    color: #333;
}

/* Emoji picker */
.chat-reply-emoji-wrap {
    position: relative;
    display: flex;
    align-items: flex-end;
}
.chat-reply-emoji-panel {
    position: absolute;
    bottom: calc(100% + 6px);
    left: 0;
    width: 280px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,.1);
    padding: 0.4rem 0.5rem;
    z-index: 200;
}
.chat-reply-emoji-panel[hidden] { display: none; }
.emoji-panel-title {
    font-size: 0.7rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin: 0.25rem 0.1rem;
}
.emoji-panel-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 0.1rem;
    margin-bottom: 0.25rem;
}
.emoji-cell {
    border: 0;
    background: none;
    cursor: pointer;
    font-size: 1.25rem;
    line-height: 1;
    padding: 0.2rem;
    border-radius: 6px;
}
.emoji-cell:hover { background: var(--bg); }

/* :shortcode: autocomplete */
.chat-reply-emoji-autocomplete {
    position: absolute;
    bottom: calc(100% + 4px);
    left: 0;
    min-width: 200px;
    max-width: 320px;
    max-height: 220px;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,.12);
    padding: 0.2rem;
    z-index: 200;
}
.chat-reply-emoji-autocomplete[hidden] { display: none; }
.emoji-ac-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    text-align: left;
    border: 0;
    background: none;
    cursor: pointer;
    font: inherit;
    padding: 0.3rem 0.45rem;
    border-radius: 6px;
}
.emoji-ac-item.is-active { background: #eef3ff; }
.emoji-ac-item:hover { background: var(--bg); }
.emoji-ac-char { font-size: 1.15rem; line-height: 1; }
.emoji-ac-name { font-size: 0.82rem; color: var(--muted); }

.chat-reply-send-btn {
    flex: 1 1 auto;
    padding: 0 0.9rem;
    background: var(--accent);
    color: white;
    border: 0;
    border-radius: 6px;
    cursor: pointer;
    white-space: nowrap;
    font: inherit;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 52px;
}
.chat-reply-send-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.chat-reply.is-window-closed textarea {
    opacity: 0.45;
    cursor: not-allowed;
}
@keyframes send-spin {
    to { transform: rotate(360deg); }
}
.send-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255,255,255,.35);
    border-top-color: #fff;
    border-radius: 50%;
    animation: send-spin 0.6s linear infinite;
}
.icon-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(0,0,0,.15);
    border-top-color: currentColor;
    border-radius: 50%;
    animation: send-spin 0.6s linear infinite;
}

/* ===== Contact panel ===== */


.contact-panel {
    grid-column: 3;
    background: var(--surface);
    border-left: 1px solid var(--border);
    padding: 1rem;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-height: 0;
    max-width: 320px;
    font-size: 0.8rem;
}
.contact-panel h3,
.contact-panel h4 {
    margin: 0 0 0.35rem;
    font-size: 0.9rem;
    font-weight: 600;
}
.contact-panel h4 {
    font-size: 0.85rem;
}

.contact-links-banner {
    font-size: smaller;
}

.contact-links-list {
    margin: 0.5rem 0;
}

.contact-links-list li {
    margin-bottom: 0.3rem;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.25rem;
}
.panel-header h3 { margin: 0; }

.panel-form {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}
.panel-form label {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.8rem;
    color: var(--muted);
}
.panel-form input,
.panel-form select {
    padding: 0.4rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    color: #222;
    font: inherit;
}
.panel-form button {
    align-self: flex-start;
    padding: 0.4rem 0.75rem;
    background: var(--accent);
    color: white;
    border: 0;
    border-radius: 4px;
    cursor: pointer;
}
.panel-meta {
    margin: 0;
    font-size: 0.8rem;
    color: var(--muted);
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.25rem 0.75rem;
}
.panel-meta dt { font-weight: 600; }
.panel-meta dd { margin: 0; word-break: break-all; }

.panel-section {
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}
.panel-section .hint {
    font-size: 0.75rem;
    color: var(--muted);
    margin: 0 0 0.5rem;
}
.panel-section .panel-form {
    padding-bottom: 0;
    border-bottom: 0;
}

/* ===== System config page ===== */

.system-config-page {
    height: calc(100dvh - var(--topbar-h));
    overflow-y: auto;
    background: var(--bg);
}
.system-config-container {
    max-width: 960px;
    margin: 0 auto;
    padding: 1.5rem 1rem 3rem;
}
.system-config-header h1 { margin: 0 0 0.25rem; font-size: 1.25rem; }
.system-config-hint { margin: 0 0 1.25rem; color: var(--muted); font-size: 0.85rem; }
.system-config-hint code,
.system-config-key {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.05rem 0.35rem;
    font-size: 0.85em;
}
.system-config-empty { color: var(--muted); }
.system-config-form { display: flex; flex-direction: column; gap: 1rem; }
.system-config-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}
.system-config-tab {
    appearance: none;
    background: transparent;
    border: 0;
    border-bottom: 2px solid transparent;
    padding: 0.5rem 0.5rem;
    margin-bottom: -1px;
    font: inherit;
    font-size: 0.85rem;
    color: var(--muted);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}
.system-config-tab:hover { color: inherit; }
.system-config-tab.is-active {
    color: inherit;
    border-bottom-color: var(--accent);
    font-weight: 600;
}
.system-config-tab-count {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0 0.45rem;
    font-size: 0.7rem;
    color: var(--muted);
}
.system-config-panel {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
/* Nested strip (geo form): lighter than the page-level tabs so the hierarchy
   reads at a glance. */
.system-config-subtabs {
    border-bottom-style: dashed;
    margin-bottom: 0;
}
.system-config-subtabs .system-config-tab { padding: 0.4rem 0.7rem; font-size: 0.85rem; }
.system-config-panel[hidden] { display: none; }
.system-config-row {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.9rem 1rem;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}
.system-config-row label { font-size: 0.85rem; }
.system-config-row textarea {
    width: 100%;
    font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
    font-size: 0.85rem;
    line-height: 1.4;
    padding: 0.5rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    resize: vertical;
    background: var(--bg);
    color: #222;
}
.system-config-description {
    margin: 0;
    color: var(--muted);
    font-size: 0.8rem;
}
.system-config-meta { margin: 0; color: var(--muted); font-size: 0.7rem; }
.system-config-actions {
    position: sticky;
    bottom: 0;
    background: var(--bg);
    padding: 0.75rem 0;
    display: flex;
    justify-content: flex-end;
}
.system-config-actions button.primary {
    padding: 0.55rem 1.25rem;
    background: var(--accent);
    color: #fff;
    border: 0;
    border-radius: 4px;
    cursor: pointer;
    font: inherit;
}

.flash {
    padding: 0.55rem 0.75rem;
    border-radius: 4px;
    margin-bottom: 1rem;
    font-size: 0.85rem;
}
.flash-success { background: #e6f7ec; color: #156a2d; border: 1px solid #b9e3c5; }
.flash-error { background: #ffe8e8; color: #a00; border: 1px solid #f4bcbc; }

/* Chat layout is a fixed-height grid (100dvh - topbar) — an in-flow flash
   above it would push it past the viewport, so this overlays instead. */
.page-flash {
    position: fixed;
    top: calc(var(--topbar-h) + 0.5rem);
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    width: min(90vw, 480px);
}
.page-flash:empty { display: none; }
.page-flash .flash {
    margin-bottom: 0.5rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.system-config-row input[type='text'],
.system-config-row input[type='number'],
.system-config-row input[type='password'],
.system-config-row select {
    width: 100%;
    box-sizing: border-box;
    font-family: inherit;
    font-size: 0.9rem;
    padding: 0.4rem 0.55rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg);
    color: #222;
}
.system-config-row input[disabled] { color: var(--muted); background: var(--surface); }

/* Tenant picker row: label + select + clone/delete buttons on one line
   instead of the default stacked `.system-config-row`. */
.system-config-row--inline {
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.6rem;
}
.system-config-row--inline label { margin: 0; }
.system-config-row--inline select { width: auto; min-width: 260px; }
.system-config-inline-form { margin: 0; }
.system-config-row__end { margin-left: auto; }
.system-config-row[hidden] { display: none; }
.icon-button {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    box-sizing: border-box;
    height: 2.3rem;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.4rem 0.7rem;
    font: inherit;
    font-size: 0.8rem;
    color: var(--muted);
    cursor: pointer;
}
.icon-button:hover { color: inherit; border-color: var(--accent); }
.icon-button--danger { color: #a00; background: #fff5f5; border-color: #f4bcbc; }
.icon-button--danger:hover { background: #ffe8e8; border-color: #e59a9a; }

/* Collapsible "show deleted, restore" section — used on Гео and Методы оплаты. */
.system-config-deleted {
    margin-top: 0.25rem;
    font-size: 0.85rem;
    color: var(--muted);
}
.system-config-deleted summary { cursor: pointer; }
.system-config-deleted-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.35rem 0;
    border-bottom: 1px solid var(--border);
}
.system-config-deleted-row:last-child { border-bottom: none; }
.system-config-deleted-row form { margin: 0; }
.system-config-deleted-row button {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.25rem 0.6rem;
    font: inherit;
    font-size: 0.75rem;
    cursor: pointer;
}
.system-config-deleted-row button:hover { border-color: var(--accent); }

.geo-services { gap: 0.75rem; }
.geo-service {
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.6rem 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    background: var(--bg);
}
.geo-service-head {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem 0.75rem;
    font-size: 0.85rem;
}
.geo-service-head .system-config-key,
.geo-service-head .system-config-description { flex: 0 0 auto; }
/* A label whose control sits beside its text, not stacked under it. The
   `.geo-service label` rule further down is class+type, so these have to name
   the element too or they lose on specificity and the checkbox stacks. */
.geo-service label.geo-service-autosend,
.geo-service label.geo-service-checkbox,
.geo-service-checkbox {
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.85rem;
    color: var(--muted);
    white-space: nowrap;
}
.geo-service-autosend input,
.geo-service-checkbox input { width: auto; margin: 0; }
/* Tom Select (required-fields tag input) toned down to match the plain inputs
   around it: same border, radius and font size, no oversized control. */
.geo-service .ts-wrapper { font-size: 0.9rem; }
.geo-service .ts-control {
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.25rem 0.4rem;
    min-height: 0;
    box-shadow: none;
}
.geo-service .ts-wrapper.focus .ts-control { border-color: var(--accent); box-shadow: none; }
.geo-service .ts-control > .item {
    background: var(--bubble-out);
    border: 1px solid transparent;
    border-radius: 4px;
    color: #222;
    padding: 0.05rem 0.3rem;
}
.geo-service .ts-dropdown {
    border: 1px solid var(--border);
    border-radius: 4px;
    margin-top: 2px;
    box-shadow: 0 4px 12px rgb(0 0 0 / 8%);
}
.geo-service .ts-dropdown .active { background: var(--bubble-out); color: #222; }
.geo-service-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0.5rem 0.75rem;
}
/* Clone sits directly before delete in the head, both pushed to the right
   edge — the margin goes on clone (first of the pair) so delete just
   follows it with the row's normal gap instead of also being auto-pushed. */
.geo-service-clone {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.25rem 0.55rem;
    font: inherit;
    font-size: 0.75rem;
    color: var(--muted);
    cursor: pointer;
}
.geo-service-clone:hover { color: inherit; border-color: var(--accent); }
.geo-service-clone svg { flex: 0 0 auto; }
/* Destructive: reads as a warning even before hover. */
.geo-service-delete {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    background: #fff5f5;
    border: 1px solid #f4bcbc;
    border-radius: 4px;
    padding: 0.25rem 0.55rem;
    font: inherit;
    font-size: 0.75rem;
    color: #a00;
    cursor: pointer;
}
.geo-service-delete:hover { background: #ffe8e8; border-color: #e59a9a; }
.geo-service-delete svg { flex: 0 0 auto; }
/* Both clone and delete default to margin-left:auto so each works pushed
   right on its own (messengers/services only ever render delete alone); when
   clone directly precedes delete (payment methods) two auto margins would
   split the free space and float clone away from the edge, so collapse
   delete's back down to a plain gap from its sibling. */
.geo-service-clone + .geo-service-delete { margin-left: 0.5rem; }
/* Status has no label: keep it narrow so it reads as a chip in the card head,
   and let it stay next to the delete button instead of being stretched away. */
.geo-service-status { width: auto; min-width: 0; flex: 0 0 auto; }
.geo-service label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.8rem; color: var(--muted); }
/* The card itself is tinted, so its controls go white to stay readable. */
.geo-service input[type='text'],
.geo-service input[type='number'],
.geo-service input[type='password'],
.geo-service select,
.geo-service textarea,
.geo-service .ts-control {
    background: var(--surface);
}
.geo-service-prices {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 0.5rem;
}
.system-config-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}
.system-config-table th,
.system-config-table td {
    border: 1px solid var(--border);
    padding: 0.35rem 0.5rem;
    vertical-align: top;
    text-align: left;
}
.system-config-table th { color: var(--muted); font-weight: 500; }
.system-config-table input,
.system-config-table select,
.system-config-table textarea {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 4px;
    font: inherit;
}
/* Destructive row-delete inside a table cell — same red language as
   .geo-service-delete, just icon-sized with no auto margin (it's alone in a
   narrow td, not pushed to the edge of a wider row). */
.system-config-table-delete {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.8rem;
    height: 1.8rem;
    background: #fff5f5;
    border: 1px solid #f4bcbc;
    border-radius: 4px;
    font: inherit;
    line-height: 1;
    color: #a00;
    cursor: pointer;
}
.system-config-table-delete:hover { background: #ffe8e8; border-color: #e59a9a; }
/* Checkbox lists on the geo form (languages, payment methods) wrap in a row
   instead of stacking one per line. */
.geo-supported-languages {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem 1rem;
}
.geo-supported-language {
    display: inline-flex;
    flex-direction: row;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.85rem;
    white-space: nowrap;
}
.geo-supported-language input { width: auto; margin: 0; }
/* Payment methods on the geo form: one row each, with up/down priority buttons. */
.geo-payment-methods { flex-direction: column; flex-wrap: nowrap; }
.geo-payment-method-row { display: flex; align-items: center; gap: 0.5rem; }
.geo-payment-method-row button {
    border: 1px solid #ccc; background: #fff; border-radius: 4px;
    padding: 0 0.45rem; line-height: 1.4; cursor: pointer;
}
.geo-payment-method-row button:hover { background: #f0f0f0; }
.landing-public-urls { gap: 0.35rem; }
.landing-public-url {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
}
.landing-public-url a { word-break: break-all; }
/* Messenger checkboxes (Настройки Гео → Мессенджеры): one per line, unlike the
   wrapping row used for languages/payment methods. */
.geo-messenger-list { flex-direction: column; }
.system-config-row audio { display: block; width: 100%; max-width: 360px; margin-bottom: 0.35rem; }
.geo-image-preview { display: block; max-width: 240px; max-height: 240px; border-radius: 6px; margin-bottom: 0.35rem; }
.geo-voice-remove {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.85rem;
    margin-bottom: 0.5rem;
}
.geo-voice-remove input { width: auto; margin: 0; }
.geo-service-add {
    margin-top: 0.25rem;
    display: flex;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: 0.5rem;
}
/* The "link a catalogue service" picker: select sized to content, button beside it. */
.geo-service-add label {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.8rem;
    color: var(--muted);
}
.geo-service-add select { width: auto; min-width: 260px; }
.geo-service-add .system-config-empty { margin: 0; }
/* Same explicit height on all three controls in the row — native <select>
   rendering doesn't line up with <input>/<button> even with identical padding. */
.geo-service-add input[type='text'],
.geo-service-add select,
.geo-service-add button {
    height: 2.3rem;
}
.geo-service-add button {
    background: transparent;
    border: 1px dashed var(--border);
    border-radius: 4px;
    padding: 0.4rem 0.8rem;
    font: inherit;
    font-size: 0.85rem;
    color: var(--muted);
    cursor: pointer;
}
.geo-service-add button:hover { color: inherit; border-style: solid; }

/* ===== Shared admin widgets =====
   Common page/typography/form/table/button primitives, pulled out of the
   Настройки styles above so other admin-style pages (Проверка платежей,
   Дифф раскладов, …) reuse them instead of inventing their own. Each page
   still sets its own container max-width (layout dimension, not a shared
   widget) via an inline style or a one-off local class. */

.admin-page {
    height: calc(100dvh - var(--topbar-h));
    overflow-y: auto;
    background: var(--bg);
}
.admin-container { margin: 0 auto; padding: 1.5rem 1rem 3rem; }

/* Two standard content-container widths — add one alongside .admin-container
   / .finance-container instead of a one-off inline max-width per page.
   .container-wide is the unconstrained default (full-width tables, e.g. the
   Финансы/Когорты pages); .container-narrow caps line length for pages with a
   small amount of data (e.g. Статистика раскладов). */
.container-wide {}
.container-narrow { max-width: 960px; margin: 0 auto; }

/* Sub-tab strip shared by the pages merged under the "Контроль" nav entry —
   each tab is a real route/link (see _control_subtabs.html.twig), not a
   same-page JS switch, so it's styled like the topbar's own nav-links rather
   than system_config's JS tab strip. */
.control-subtabs {
    display: flex;
    gap: 0.25rem;
    padding: 0 1rem 0;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    overflow-x: auto;
}
.control-subtab-link {
    flex: 0 0 auto;
    padding: 0.4rem 0.75rem;
    color: var(--muted);
    text-decoration: none;
    font-size: 0.85rem;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
}
.control-subtab-link:hover { color: inherit; }
.control-subtab-link.is-active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.admin-header h1 { margin: 0 0 0.25rem; font-size: 1.25rem; }
.admin-hint { margin: 0 0 1.25rem; color: var(--muted); font-size: 0.85rem; }
.admin-meta { margin: 0.15rem 0 0; color: var(--muted); font-size: 0.75rem; }
.admin-empty { color: var(--muted); }
.admin-empty--centered { padding: 2rem 0; text-align: center; }

/* Bordered card: label(s) + control(s), stacked by default. */
.admin-row {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.9rem 1rem;
    margin: 0 0 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}
.admin-row label { font-size: 0.85rem; }
/* Modifier: controls on one line instead of stacked (e.g. a filter bar). */
.admin-row--inline { flex-direction: row; align-items: center; flex-wrap: wrap; gap: 0.6rem; }
.admin-row--inline label { margin: 0; }

.admin-row input[type='text'],
.admin-row input[type='number'],
.admin-row input[type='password'],
.admin-row select,
.admin-form-grid input[type='text'],
.admin-form-grid select {
    width: 100%;
    box-sizing: border-box;
    font-family: inherit;
    font-size: 0.9rem;
    padding: 0.4rem 0.55rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg);
    color: #222;
}

/* Dashed "add new" card: a small vertical-label grid plus a submit button. */
.admin-new-card { border: 1px dashed var(--border); border-radius: 8px; padding: 1rem; max-width: 640px; }
.admin-new-card h2 { margin: 0 0 0.75rem; font-size: 0.9rem; }
.admin-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.6rem;
    margin-bottom: 0.75rem;
}
.admin-form-grid label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.8rem; color: var(--muted); }

/* Checkbox/flag with its label on one line. */
.check-inline { display: inline-flex; flex-direction: row; align-items: center; gap: 0.35rem; font-size: 0.85rem; white-space: nowrap; }
.check-inline input { width: auto; margin: 0; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.45rem 0.9rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface);
    color: inherit;
    font: inherit;
    font-size: 0.85rem;
    cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
a.btn { text-decoration: none; }
.btn svg { flex: 0 0 auto; }
/* Same height as the selects/inputs a button sits next to in an inline row. */
.admin-row--inline .btn, .system-config-row--inline .btn { height: 2.3rem; padding-top: 0; padding-bottom: 0; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { opacity: 0.92; }
.btn-danger { background: #fff5f5; border-color: #f4bcbc; color: #a00; }
.btn-danger:hover { background: #ffe8e8; border-color: #e59a9a; }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.75rem; }

/* Table — cells default to a white surface (not the page's grey background)
   so dense data stays readable; a page can still override per-cell. Rounded
   corners on a collapsed table need the radius + overflow:hidden on the
   table itself (browsers clip collapsed cell borders to it) plus the outer
   border that radius is drawn on — a lone `overflow: hidden` with no border
   has nothing to round. */
.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}
.admin-table th,
.admin-table td { border: 1px solid var(--border); padding: 0.35rem 0.5rem; vertical-align: top; text-align: left; }
.admin-table th { color: var(--muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.02em; }
/* Excludes checkbox/radio — those must stay their native square size, not
   stretch to the cell's full width. */
.admin-table input[type='text'],
.admin-table input[type='number'],
.admin-table input[type='password'],
.admin-table select,
.admin-table textarea { width: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: 4px; font: inherit; }
.admin-table-delete {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.8rem;
    height: 1.8rem;
    background: #fff5f5;
    border: 1px solid #f4bcbc;
    border-radius: 4px;
    font: inherit;
    line-height: 1;
    color: #a00;
    cursor: pointer;
}
.admin-table-delete:hover { background: #ffe8e8; border-color: #e59a9a; }

/* ===== Finance pages ===== */

.finance-page {
    height: calc(100dvh - var(--topbar-h));
    overflow-y: auto;
    background: var(--bg);
}
.finance-container {
    padding: 1.5rem 1rem 3rem;
}
.finance-header { margin-bottom: 1rem; }
.finance-header h1 { margin: 0 0 0.25rem; font-size: 1.25rem; }
.finance-hint { margin: 0 0 1rem; color: var(--muted); font-size: 0.85rem; }
.finance-back { display: inline-block; margin-bottom: 0.5rem; color: var(--accent); text-decoration: none; font-size: 0.85rem; }
.finance-back:hover { text-decoration: underline; }
.finance-empty { color: var(--muted); }
.finance-muted { color: var(--muted); }

.finance-stats-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    align-items: start;
    margin-top: 1.5rem;
}
@media (max-width: 700px) {
    .finance-stats-columns { grid-template-columns: 1fr; }
}
.finance-stats-block h2 { margin: 0 0 0.5rem; font-size: 1.05rem; }

.finance-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    font-size: 0.9rem;
}
.finance-table th,
.finance-table td {
    text-align: left;
    padding: 0.6rem 0.9rem;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}
.finance-table th {
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.02em;
}
.finance-table tbody tr:last-child td { border-bottom: 0; }
.finance-row { cursor: pointer; }
.finance-row:hover { background: var(--bg); }
.finance-row.is-empty { cursor: default; }
.finance-row.is-empty:hover { background: transparent; }
.finance-cell-date { white-space: nowrap; min-width: 9rem; }
.finance-cell-date a { color: inherit; text-decoration: none; }
.finance-cell-date a:hover { text-decoration: underline; }
.finance-date-ymd { display: block; }
.finance-date-weekday { display: block; font-size: 0.8rem; color: var(--muted); }
.finance-cell-count, .finance-col-count { text-align: right; color: var(--muted); }
.finance-cell-totals { line-height: 1.35; }
.finance-total-in { font-weight: 500; }
.finance-total-out { font-size: 0.75rem; color: var(--muted); margin-top: 0.15rem; }

/* Date-range picker in the header */
.finance-range { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }
.finance-presets {
    font-weight: 200;
    font-size: small;
    flex-basis: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 0.2rem 0.75rem;
}
.finance-presets a { color: var(--accent); text-decoration: none; }
.finance-presets a:hover { text-decoration: underline; }
.finance-date-input {
    font: inherit;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.2rem 0.4rem;
}
.finance-range-apply {
    font: inherit;
    font-size: 0.8rem;
    cursor: pointer;
    color: var(--accent);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.2rem 0.6rem;
}
.finance-range-apply:hover { background: var(--bg); }
.finance-tenant-filter { display: inline-flex; align-items: center; gap: 0.4rem; margin-left: 0.5rem; }
.finance-tenant-option {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    cursor: pointer;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.1rem 0.4rem;
    background: var(--surface);
}
.finance-tenant-option:hover { background: var(--bg); }
.finance-tenant-option input { margin: 0; }

/* Stats table — numeric columns + period totals line */
.finance-table-stats { font-variant-numeric: tabular-nums; }
.finance-table-stats th.finance-num,
.finance-table-stats td.finance-num { text-align: right; white-space: nowrap; }
.finance-cell-sales { line-height: 1.3; }
.finance-sales-usd { font-weight: 600; }
.finance-sales-orig { font-size: 0.75rem; color: var(--muted); margin-top: 0.1rem; }
.finance-total-row td { background: var(--bg); font-weight: 600; border-bottom: 2px solid var(--border); }
.finance-total-row .finance-sales-orig { font-weight: 400; }
.finance-highlight { background: #fffde7 !important; }

.finance-day-totals { margin-top: 0.25rem; display: flex; gap: 1.25rem; flex-wrap: wrap; font-size: 0.9rem; }
.finance-day-in strong, .finance-day-out strong { font-weight: 500; }
.finance-day-out { color: var(--muted); }

.finance-table-detail .finance-cell-amount { font-variant-numeric: tabular-nums; white-space: nowrap; font-weight: 500; }
.finance-table-detail .finance-cell-amount.is-positive { color: #156a2d; }
.finance-table-detail .finance-cell-amount.is-negative { color: #a00; }
.finance-cell-time { color: var(--muted); white-space: nowrap; }
.finance-actor-ai {
    display: inline-block;
    padding: 0.05rem 0.4rem;
    border-radius: 4px;
    background: var(--bg);
    border: 1px solid var(--border);
    font-size: 0.75rem;
    color: var(--muted);
}
.finance-cell-contact a { color: var(--accent); text-decoration: none; }
.finance-cell-contact a:hover { text-decoration: underline; }
.finance-meta { font-size: 0.75rem; color: var(--muted); margin-top: 0.15rem; }
.finance-meta strong { font-weight: 500; color: inherit; }

/* Cohort matrix (finance/cohorts) */
.finance-cohort-scroll { overflow-x: auto; }
.finance-cohort-table { table-layout: fixed; }
.finance-cohort-table th, .finance-cohort-table td { white-space: nowrap; }

/* Cohort (date) and Лиды columns stay put while the offset columns scroll. */
.finance-cohort-table th:first-child, .finance-cohort-table td.finance-cell-date {
    position: sticky;
    left: 0;
    z-index: 1;
    background: var(--surface);
    width: 7rem;
}
.finance-cohort-table th:nth-child(2), .finance-cohort-table td:nth-child(2) {
    position: sticky;
    left: 7rem;
    z-index: 1;
    background: var(--surface);
    width: 3.25rem;
}
.finance-cohort-table .finance-total-row td.finance-cell-date,
.finance-cohort-table .finance-total-row td:nth-child(2) { background: var(--bg); }
/* Every column needs an explicit width under table-layout:fixed — an unset
   one doesn't just shrink, it grabs all the table's leftover width (or
   collapses to nothing), throwing off every column after it. */
.finance-cohort-table th:nth-child(3), .finance-cohort-table td:nth-child(3) { width: 4.5rem; }
.finance-cohort-table th:nth-child(4), .finance-cohort-table td:nth-child(4) { width: 4.5rem; }

.finance-cohort-table th.finance-cohort-cell, .finance-cohort-cell {
    width: 3rem;
    padding-left: 0.3rem;
    padding-right: 0.3rem;
    line-height: 1.25;
}
.finance-cohort-cell.is-future { color: var(--muted); }
.finance-cohort-usd { font-weight: 500; font-size: 0.82rem; }
.finance-cohort-count { font-size: 0.7rem; color: var(--muted); }

.finance-days-filter { display: inline-flex; align-items: center; gap: 0.35rem; margin-left: 0.5rem; }
.finance-days-input { width: 3.5rem; padding: 0.3rem 0.4rem; border: 1px solid var(--border); border-radius: 6px; font: inherit; }
.finance-days-capped { font-size: 0.75rem; }

/* Inline payment-datetime editor (finance day table) */
.pdt-editor { position: relative; display: inline-block; }
.pdt-trigger {
    border: 1px solid transparent;
    background: transparent;
    cursor: pointer;
    font: inherit;
    color: inherit;
    padding: 0.1rem 0.3rem;
    border-radius: 4px;
    border-bottom: 1px dashed var(--border);
}
.pdt-trigger:hover { background: #eef3ff; color: var(--accent); border-color: var(--accent); }

/* Fixed positioning (coords set in JS) so the popover escapes the table's
   overflow:hidden clipping context. */
.pdt-popover {
    position: fixed;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 6px 18px rgba(0,0,0,0.10);
    padding: 0.4rem;
    z-index: 50;
    width: 300px;
}
.pdt-popover[hidden] { display: none; }
.pdt-head { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); padding: 0.2rem 0.4rem 0.4rem; }
.pdt-list { display: flex; flex-direction: column; gap: 0.1rem; max-height: 320px; overflow-y: auto; }
.pdt-empty { padding: 0.5rem 0.4rem; color: var(--muted); font-size: 0.8rem; }
.pdt-item {
    width: 100%;
    text-align: left;
    border: 0;
    background: transparent;
    padding: 0.4rem 0.5rem;
    border-radius: 4px;
    cursor: pointer;
    font: inherit;
    color: #222;
}
.pdt-item:hover { background: var(--bg); }
.pdt-item:disabled { opacity: 0.5; cursor: default; }
.pdt-when { font-size: 0.78rem; font-weight: 600; white-space: nowrap; }
.pdt-text { font-size: 0.75rem; color: var(--muted); margin-top: 0.1rem; white-space: normal; }

/* ===== Mobile (≤ 768px) — single column with overlays ===== */

@media (max-width: 768px) {
    :root { --sidebar-w: 100%; --panel-w: 100%; }

    /* No hover on touch — the pencil hint earns its space back here. */
    .tarot-order-edit-icon { display: inline; }

    /* Chat pages hide the topbar on small screens to reclaim space for
       chatters; logout moves into the sidebar header (see .sidebar-logout).
       --topbar-h collapses to 0 so every calc(100dvh - var(--topbar-h)) and
       the contact-panel overlay's inset still line up without a gap. */
    body.chat-page { --topbar-h: 0px; }
    body.chat-page .topbar { display: none; }

    /* Compact topbar: swap nav text for icons so links never overflow width. */
    .topbar { gap: 0.15rem; padding: 0.5rem 0.4rem; }
    .topbar-brand { flex: 0 0 auto; }
    /* 44px+ tap target (Apple/Google's minimum) instead of a bare glyph. */
    .topbar .nav-link { display: inline-flex; align-items: center; justify-content: center; width: 2.75rem; height: 2.75rem; border-radius: 10px; }
    .topbar .nav-link:active { background: var(--bg); }
    .topbar .nav-icon { display: inline-flex; }
    .topbar .nav-icon svg { width: 1.6rem; height: 1.6rem; }
    .topbar .nav-label { display: none; }
    .topbar .user { font-size: 0.85rem; }

    .chat-layout,
    .chat-layout.has-active {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr;
    }

    .chat-sidebar,
    .chat-main,
    .contact-panel {
        grid-column: 1;
        grid-row: 1;
    }

    /* Default view = list: show sidebar, hide main + panel */
    .chat-layout .chat-sidebar { display: flex; }
    .chat-layout .chat-main { display: none; }
    .chat-layout .contact-panel { display: none; }

    /* When viewing detail: hide sidebar, show main */
    .chat-layout[data-view="detail"] .chat-sidebar { display: none; }
    .chat-layout[data-view="detail"] .chat-main { display: flex; }

    /* Panel overlay on top of detail */
    .chat-layout[data-panel-open="true"] .contact-panel {
        display: flex;
        position: fixed;
        inset: var(--topbar-h) 0 0 0;
        z-index: 20;
    }

    .header-back, .header-info, .sidebar-close, .panel-close { display: inline-flex; align-items: center; justify-content: center; }
    body.chat-page .sidebar-logout { display: inline-flex; align-items: center; justify-content: center; }
    .header-identity strong { font-size: 0.9rem; }
    .header-identity small { display: none; }
    .chat-header { gap: 0.4rem; padding: 0.5rem 0.5rem; }
    .ai-toggle-form button { padding: 0.15rem 0.45rem; font-size: 0.7rem; }

    .message { max-width: 90%; }

    .filter-dropdown { left: 0.5rem; right: 0.5rem; }

    /* Meta-filter chips: 2x2 grid overflows narrow phones (min-width 7rem
       per button doesn't leave room to wrap cleanly). Single scrollable row
       instead — chips keep their natural width, no wrap, swipe for the rest. */
    .meta-filters {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        margin: 0 -1rem;
        padding: 0 1rem;
    }
    .meta-filters::-webkit-scrollbar { display: none; }
    .meta-filter-btn {
        flex: 0 0 auto;
        min-width: auto;
        white-space: nowrap;
    }
}

/* ---- Landing live editor (LandingEditorController) ---- */
body.landing-editor-page { overflow: hidden; }
.landing-editor { position: fixed; inset: var(--topbar-h) 0 0 0; display: grid; grid-template-columns: 1fr 400px; background: var(--bg); }
.le-stage { min-width: 0; display: flex; justify-content: center; background: #1c1c22; overflow: auto; }
.le-frame { width: 100%; height: 100%; border: 0; background: #fff; }
.le-stage[data-device='mobile'] .le-frame { width: 390px; max-width: 100%; margin: 12px 0; height: calc(100% - 24px); border-radius: 14px; }
.le-sidebar { display: flex; flex-direction: column; min-height: 0; border-left: 1px solid var(--border); background: var(--surface); }
.le-head { padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 0.4rem; }
.le-head-row { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: center; font-size: 0.85rem; }
.le-head-row select { margin-left: 0.25rem; }
.le-status { min-height: 1em; opacity: 0.7; }
.le-status-error { color: #c0392b; opacity: 1; }
.le-flash { font-size: 0.85rem; padding: 0.35rem 0.6rem; border-radius: 6px; background: rgba(46, 160, 67, 0.15); }
.le-flash-error { background: rgba(192, 57, 43, 0.15); }
.le-body { flex: 1; overflow-y: auto; padding: 0.75rem 1rem; }
.le-hint { font-size: 0.9rem; opacity: 0.8; }
.le-group { border: 0; margin: 0; padding: 0; min-width: 0; }
.le-group > legend { font-weight: 700; font-size: 1rem; padding: 0 0 0.5rem; }
.le-field { display: flex; flex-direction: column; gap: 0.3rem; margin-bottom: 0.9rem; }
.le-label { font-size: 0.8rem; font-weight: 600; }
.le-label small { font-weight: 400; opacity: 0.7; display: block; }
.le-field input[type='text'], .le-field input[type='number'], .le-field textarea { width: 100%; font: inherit; font-size: 0.85rem; padding: 0.4rem 0.5rem; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: inherit; }
.le-row { display: flex; flex-direction: column; gap: 0.3rem; padding: 0.5rem; margin-bottom: 0.5rem; border: 1px dashed var(--border); border-radius: 8px; }
.le-gallery-row { flex-direction: row; align-items: center; }
.le-thumb { max-width: 120px; max-height: 120px; border-radius: 6px; object-fit: cover; }
.le-link { background: none; border: 0; padding: 0; color: var(--accent, #6c5ce7); cursor: pointer; font-size: 0.85rem; text-align: left; }
.le-danger { color: #c0392b; }
.le-prices { width: 100%; font-size: 0.8rem; border-collapse: collapse; }
.le-prices td { padding: 0.25rem 0.3rem; vertical-align: top; }
.le-prices input[type='number'] { width: 5.5rem; }
.le-foot { display: flex; gap: 0.5rem; padding: 0.75rem 1rem; border-top: 1px solid var(--border); }
.le-save { flex: 1; padding: 0.6rem; border: 0; border-radius: 8px; background: var(--accent, #6c5ce7); color: #fff; font-weight: 700; cursor: pointer; }
.le-cancel { padding: 0.6rem 1rem; border: 1px solid var(--border); border-radius: 8px; background: transparent; color: inherit; cursor: pointer; }
@media (max-width: 900px) { .landing-editor { grid-template-columns: 1fr; grid-template-rows: 45% 55%; } .le-sidebar { border-left: 0; border-top: 1px solid var(--border); } }

/* Standard dropdown: native <select> with our border/radius and a custom chevron */
.ui-select {
    font: inherit;
    font-size: 0.9rem;
    color: var(--text, #222);
    background-color: var(--surface);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%23888' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.6rem center;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.25rem 1.9rem 0.25rem 0.6rem;
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
}
.ui-select:hover { border-color: #c9c9d1; }
.ui-select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Control → activity charts (chatters / leads by time of day) */
.activity-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 1rem 1.25rem; }
.activity-chart-main { display: flex; flex-direction: column; gap: 1rem; min-width: 0; }
.activity-header { margin-bottom: 0; }
.activity-header .finance-hint { margin: 0.75rem 0 0; color: #555; }
.activity-header .finance-range { margin: 0; }
.activity-chart { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 1rem; align-items: start; }
.activity-chart-card { padding: 0.75rem; }
.activity-chart-canvas { width: 100%; }
.activity-svg { width: 100%; height: auto; display: block; }
.activity-grid { stroke: var(--border); stroke-width: 1; }
.activity-axis { fill: var(--muted); font-size: 11px; }
.activity-cursor { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; pointer-events: none; }
.activity-tooltip { position: absolute; z-index: 5; pointer-events: none; padding: 0.4rem 0.6rem; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: inherit; font-size: 0.8rem; box-shadow: 0 2px 8px rgba(0, 0, 0, .15); white-space: nowrap; }
.activity-swatch { display: inline-block; width: 0.65rem; height: 0.65rem; border-radius: 2px; margin-right: 0.4rem; vertical-align: baseline; }
.activity-legend-card { padding: 0.5rem 0.75rem; }
.activity-legend { border-collapse: collapse; font-size: 0.8rem; font-variant-numeric: tabular-nums; }
.activity-legend th { text-align: left; font-weight: 600; font-size: 0.7rem; color: var(--muted); text-transform: uppercase; padding: 0.2rem 0.5rem; }
.activity-legend td { padding: 0.2rem 0.5rem; white-space: nowrap; border-top: 1px solid var(--border); }
.activity-legend .finance-num { text-align: right; }
.activity-legend-row { cursor: pointer; }
.activity-legend-row:hover { background: var(--bg); }
.activity-legend-row.is-hidden { opacity: .4; text-decoration: line-through; }
.activity-notice { grid-column: 1 / -1; margin: 0; color: var(--muted); font-size: 0.85rem; }
@media (max-width: 900px) { .activity-chart { grid-template-columns: 1fr; } }

/* Финансы → Визуализация */
.finance-viz-filter { display: inline-flex; align-items: center; gap: 0.3rem; }
.finance-viz-filter select,
.finance-viz-compare-head select,
.finance-viz-aliases select { padding: 0.2rem 0.4rem; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); font: inherit; }
.finance-viz-tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 0.75rem; margin-bottom: 1rem; }
.finance-viz-tile { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 0.75rem 0.9rem; }
.finance-viz-tile-label { color: var(--muted); font-size: 0.8rem; }
.finance-viz-tile-value { font-size: 1.4rem; font-weight: 600; font-variant-numeric: tabular-nums; margin: 0.15rem 0; }
.finance-viz-tile-delta { font-size: 0.8rem; display: flex; gap: 0.4rem; flex-wrap: wrap; }
.finance-viz-delta.is-good { color: #2f9e44; }
.finance-viz-delta.is-bad { color: #e03131; }
.finance-viz-delta.is-neutral { color: var(--muted); }
.finance-viz-card { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 1rem 1.25rem; margin-bottom: 1rem; }
.finance-viz-card h2 { margin: 0 0 0.5rem; font-size: 1rem; }
.finance-viz-card h3 { margin: 1.25rem 0 0.5rem; font-size: 0.9rem; }
.finance-viz-card-head { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.finance-viz-card-head h2 { margin: 0; flex: 1 1 auto; }
.finance-viz-picker { position: relative; }
.finance-viz-picker summary { cursor: pointer; padding: 0.2rem 0.6rem; border: 1px solid var(--border); border-radius: 6px; font-size: 0.85rem; list-style: none; }
.finance-viz-picker-list { position: absolute; right: 0; z-index: 5; display: flex; flex-direction: column; gap: 0.25rem; min-width: 190px; margin-top: 0.25rem; padding: 0.6rem 0.75rem; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1); }
.finance-viz-picker-list label { display: flex; align-items: center; gap: 0.4rem; font-size: 0.85rem; cursor: pointer; }
.finance-viz-picker-list label.is-disabled { color: var(--muted); cursor: not-allowed; }
.finance-viz-compare { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.85rem; }
.finance-viz-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; flex: none; margin-right: 0.3rem; }
.finance-viz-picker-list .finance-viz-swatch { margin-right: 0; }
.finance-viz-chart { width: 100%; height: 320px; }
.finance-viz-svg { display: block; }
.finance-viz-grid { stroke: var(--border); stroke-width: 1; }
.finance-viz-xlabel { fill: var(--muted); font-size: 11px; }
.finance-viz-hover { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; }
.finance-viz-tooltip { position: absolute; z-index: 6; pointer-events: none; background: #222; color: #fff; border-radius: 8px; padding: 0.5rem 0.7rem; font-size: 0.8rem; line-height: 1.5; white-space: nowrap; }
.finance-viz-tooltip .finance-muted { color: #bbb; }
.finance-viz-tooltip-title { font-weight: 600; margin-bottom: 0.2rem; }
.finance-viz-compare-head { margin-bottom: 0.5rem; font-size: 0.85rem; }
.finance-viz-split { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.finance-viz-split { margin-bottom: 1rem; }
.finance-viz-split > .finance-viz-card { margin-bottom: 0; }
.finance-viz-funnel-row { display: grid; grid-template-columns: 90px minmax(0, 1fr) 220px; gap: 0.6rem; align-items: center; margin: 0.4rem 0; font-size: 0.85rem; }
.finance-viz-funnel-track { background: var(--bg); border-radius: 6px; height: 22px; }
.finance-viz-funnel-bar { height: 100%; border-radius: 6px; min-width: 2px; }
.finance-viz-funnel-bar.is-step-1 { background: #5c7cfa; }
.finance-viz-funnel-bar.is-step-2 { background: #2b6cff; }
.finance-viz-funnel-bar.is-step-3 { background: #e8590c; }
.finance-viz-funnel-bar.is-step-4 { background: #2f9e44; }
.finance-viz-funnel-value { font-variant-numeric: tabular-nums; }
.finance-viz-aliases summary { cursor: pointer; font-weight: 600; }
.finance-viz-aliases form { margin-top: 0.75rem; }
.finance-viz-alias-tools { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 0.5rem; font-size: 0.85rem; }
.finance-viz-alias-tools input[type=search] { padding: 0.25rem 0.5rem; border: 1px solid var(--border); border-radius: 6px; min-width: 220px; font: inherit; }
.finance-viz-alias-scroll { max-height: 520px; overflow-y: auto; margin-bottom: 0.75rem; }
.finance-viz-alias-scroll thead th { position: sticky; top: 0; background: var(--surface); z-index: 1; }
.finance-viz-alias-label { word-break: break-word; min-width: 200px; }
@media (max-width: 800px) {
    .finance-viz-split { grid-template-columns: 1fr; }
    .finance-viz-funnel-row { grid-template-columns: 70px minmax(0, 1fr); }
    .finance-viz-funnel-value { grid-column: 1 / -1; }
}
