/* ── Tokens ───────────────────────────────────────────── */

:root {
    --bg:       #0c0c0c;
    --sidebar:  #111111;
    --surface:  #1a1a1a;
    --surface2: #222222;
    --border:   #2a2a2a;
    --text:     #eeeeee;
    --muted:    #666666;
    --accent:   #ffffff;
    --token:    #4ade80;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: #0c0c0c;
}

/* Bootstrap dark theme override */
[data-bs-theme="dark"] {
    --bs-body-bg:        var(--bg);
    --bs-body-color:     var(--text);
    --bs-border-color:   var(--border);
    --bs-secondary-bg:   var(--surface);
    --bs-tertiary-bg:    var(--surface2);
}

*, *::before, *::after { box-sizing: border-box; }

/* ── Icons ────────────────────────────────────────────────
   Универсальная система: <svg class="icon"> = 14px (1x).
   Множители: .icon-2x = 20px, .icon-3x = 28px, .icon-4x = 40px.
   Любая иконка наследует currentColor и центрируется по vertical-align. */
.icon {
    display: inline-block;
    vertical-align: middle;
    flex-shrink: 0;
    width: 14px;
    height: 14px;
}
.icon-2x { width: 20px; height: 20px; }
.icon-3x { width: 28px; height: 28px; }
.icon-4x { width: 40px; height: 40px; }

html, body {
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* ── Base components ──────────────────────────────────── */

/*
 * .btn-icon      — ghost icon-only button (transparent, muted color)
 * .ctrl-pill     — bordered pill dropdown/button for controls
 * .ctrl-pill-primary — variant with icon slot (model/provider selector)
 * .ctrl-pill-icon — small colored icon inside .ctrl-pill-primary
 * .ctrl-sep      — vertical 1px separator between controls
 * .ctrl-counter  — — N/max + stepper control
 * .textarea-base — bare textarea reset (no border/bg, styled by parent)
 */

/* Ghost icon button */
.btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 7px;
    border: none;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s, color 0.15s;
}
.btn-icon:hover { background: var(--surface); color: var(--text); }

/* Pill control button */
.ctrl-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: transparent;
    color: var(--text);
    font-family: var(--font);
    font-size: 12px;
    padding: 4px 10px;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
    white-space: nowrap;
}
.ctrl-pill:hover    { border-color: #444; background: var(--surface2); }
.ctrl-pill::after   { opacity: 0.5; margin-left: 2px; }
.ctrl-pill:disabled { opacity: 0.3; cursor: not-allowed; }

#chat-img-enhance-btn.enhance-on  { color: #4ade80; }
#chat-img-enhance-btn.enhance-off { color: #fb923c; }

/* Primary pill variant — model/provider selector */
.ctrl-pill-primary { font-weight: 500; gap: 7px; }

/* Colored icon slot inside primary pill */
.ctrl-pill-icon {
    width: 16px;
    height: 16px;
    border-radius: 4px;
    background: #10a37f;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
    color: #fff;
    flex-shrink: 0;
    line-height: 1;
}

/* Sub-label inside pill dropdown items */
.ctrl-pill-sub { color: var(--muted); font-size: 11px; }

/* Vertical separator between controls */
.ctrl-sep {
    width: 1px;
    height: 16px;
    background: var(--border);
    flex-shrink: 0;
}

/* Count stepper: — N/max + */
.ctrl-counter {
    display: inline-flex;
    align-items: center;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    flex-shrink: 0;
}

.ctrl-counter-btn {
    width: 28px;
    height: 30px;
    border: none;
    background: transparent;
    color: var(--text);
    font-size: 15px;
    font-family: var(--font);
    cursor: pointer;
    transition: background 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.ctrl-counter-btn:hover:not(:disabled) { background: var(--surface2); }
.ctrl-counter-btn:disabled { color: var(--muted); cursor: not-allowed; }

.ctrl-counter-val {
    font-size: 12px;
    color: var(--text);
    padding: 0 8px;
    white-space: nowrap;
    user-select: none;
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
    line-height: 30px;
}

/* Textarea reset — no border/bg/outline, styled by container */
.textarea-base {
    background: transparent;
    border: none;
    outline: none;
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.6;
    resize: none;
}
.textarea-base::placeholder { color: var(--muted); }
.textarea-base { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
.textarea-base::-webkit-scrollbar       { width: 4px; }
.textarea-base::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* ── Sidebar ──────────────────────────────────────────── */

.sidebar {
    width: 256px;
    flex-shrink: 0;
    background: var(--sidebar);
    border-right: 1px solid var(--border);
    transition: width 0.2s ease;
    overflow: hidden;
    padding: 12px 0;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 8px 0 14px;
    margin-bottom: 16px;
    flex-shrink: 0;
    min-height: 32px;
}

.sidebar-logo {
    font-size: 17px;
    font-weight: 600;
    letter-spacing: -0.02em;
    color: var(--text);
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn-collapse,
.btn-expand {
    width: 28px;
    height: 28px;
}

.sidebar-nav { overflow: hidden; flex-shrink: 0; }

.sidebar-nav-item {
    display: flex;
    align-items: center;
    padding: 9px 12px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: var(--muted);
    font-size: 13.5px;
    font-family: var(--font);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    text-align: left;
    margin-bottom: 2px;
    white-space: nowrap;
}
.sidebar-nav-item         { color: var(--text); }
.sidebar-nav-item:hover   { background: var(--surface); }
.sidebar-nav-item.active  { background: var(--surface); }

.nav-icon  { flex-shrink: 0; width: 13px; height: 13px; }
.nav-label { margin-left: 10px; }

/* History section */
.sidebar-history {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding-top: 4px;
}

.sidebar-history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2px;
}

.sidebar-history-label { flex: 1; cursor: default; margin-bottom: 0; }
.sidebar-history-label:hover { background: transparent; }

.btn-history-toggle { width: 24px; height: 24px; border-radius: 6px; }

.sidebar-history.collapsed .chat-history             { display: none; }
.sidebar-history.collapsed .btn-history-toggle svg   { transform: rotate(180deg); }

.chat-history {
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    flex: 1;
}

.chat-history-item {
    display: flex;
    align-items: center;
    gap: 8px;
    height: 36px;
    padding: 0 4px 0 10px;
    border-radius: 7px;
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
    transition: background 0.12s;
    overflow: hidden;
    flex-shrink: 0;
}
.chat-history-item:hover  { background: var(--surface); }
.chat-history-item.active { background: var(--surface2); }

.chat-history-empty {
    padding: 10px 10px;
    font-size: 12.5px;
    color: var(--muted);
    font-style: italic;
}

.history-item-icon {
    display: flex;
    align-items: center;
    flex-shrink: 0;
    opacity: 0.45;
}

.history-ctx-btn {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    border: none;
    background: transparent;
    color: var(--muted);
    border-radius: 5px;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.12s, background 0.12s, color 0.12s;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}
.chat-history-item:hover .history-ctx-btn { opacity: 1; }
.history-ctx-btn:hover { background: var(--border); color: var(--text); }

/* ── History context menu ─────────────────────────────── */

#history-ctx-menu {
    position: fixed;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 4px;
    min-width: 180px;
    z-index: 2000;
    box-shadow: 0 8px 28px rgba(0,0,0,0.5);
}

.ctx-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 10px;
    border-radius: 6px;
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
    transition: background 0.1s;
    white-space: nowrap;
    user-select: none;
}
.ctx-item svg { flex-shrink: 0; opacity: 0.65; }
.ctx-item:hover { background: rgba(255,255,255,0.06); }
.ctx-item-danger { color: #ff5555; }
.ctx-item-danger svg { opacity: 1; stroke: #ff5555; }
.ctx-item-danger:hover { background: rgba(255,60,60,0.08); }

.ctx-sep {
    height: 1px;
    background: var(--border);
    margin: 4px 2px;
}

.sidebar-footer {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    padding: 8px 8px 12px 18px;
    margin-top: auto;
}

/* ── Avatar with token ring ───────────────────────────── */

.avatar-wrap {
    position: relative;
    width: 44px;
    height: 44px;
    cursor: pointer;
    flex-shrink: 0;
}
.avatar-wrap.unauth .avatar-ring { display: none; }

.avatar-ring {
    position: absolute;
    inset: 0;
    transform: rotate(-90deg);
    pointer-events: none;
}

.avatar-ring-bg {
    stroke: rgba(255,255,255,0.07);
    stroke-width: 2.5;
}

.avatar-ring-fill {
    stroke: var(--token);
    stroke-width: 2.5;
    stroke-linecap: round;
    transition: stroke-dashoffset 0.6s ease;
}

.account-avatar {
    position: absolute;
    inset: 6px;
    border-radius: 50%;
    background: var(--surface2);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    color: var(--text);
    transition: border-color 0.15s;
}
.avatar-wrap:hover .account-avatar { border-color: #444; }

/* ── User menu ────────────────────────────────────────── */

.user-menu {
    position: fixed;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 6px;
    width: 244px;
    z-index: 2000;
    box-shadow: 0 -4px 32px rgba(0,0,0,0.5);
}

.user-menu-tokens {
    padding: 10px 10px 12px;
}

.user-menu-tokens-top {
    display: flex;
    align-items: center;
    gap: 7px;
    margin-bottom: 10px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
}
.user-menu-tokens-top svg { stroke: var(--token); opacity: 0.9; }

.user-menu-tokens-label { flex: 1; }

.user-menu-tokens-days {
    font-size: 11px;
    color: var(--text);
    font-weight: 400;
}

.user-menu-tokens-bar {
    height: 3px;
    background: rgba(255,255,255,0.07);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 7px;
}

.user-menu-tokens-fill {
    height: 100%;
    background: var(--token);
    border-radius: 2px;
    transition: width 0.4s ease;
}

.user-menu-tokens-count {
    font-size: 11.5px;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.user-menu-sep {
    height: 1px;
    background: var(--border);
    margin: 4px 2px;
}

.user-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 7px;
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
    transition: background 0.1s;
    user-select: none;
}
.user-menu-item svg:first-child { opacity: 0.6; flex-shrink: 0; }
.user-menu-item:hover { background: rgba(255,255,255,0.06); }

.user-menu-item-chevron { margin-left: auto; opacity: 0.3; flex-shrink: 0; }

.user-menu-email {
    padding: 10px 12px 4px;
    font-size: 12px;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#user-menu.unauth .auth-only { display: none; }
#user-menu:not(.unauth) .unauth-only { display: none; }

.user-menu-item-danger { color: #ff5555; }
.user-menu-item-danger svg:first-child { opacity: 0.8; stroke: #ff5555; }
.user-menu-item-danger:hover { background: rgba(255,60,60,0.08); }

.user-menu-item.submenu-open { background: rgba(255,255,255,0.06); }

.user-submenu {
    position: fixed;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 6px;
    width: 220px;
    z-index: 2001;
    box-shadow: 0 4px 24px rgba(0,0,0,0.45);
}

/* ── Collapsed sidebar ────────────────────────────────── */

.sidebar.collapsed { width: 72px; }

.sidebar.collapsed .logo-text       { display: none; }
.sidebar.collapsed .nav-label       { display: none; }
.sidebar.collapsed .sidebar-history { display: none; }
.sidebar.collapsed .btn-collapse    { display: none; }
.sidebar.collapsed .btn-expand      { display: flex !important; }

.sidebar.collapsed .sidebar-nav-item {
    justify-content: center;
    padding: 9px 0;
}
.sidebar.collapsed .nav-icon    { width: 20px; height: 20px; }
.sidebar.collapsed .sidebar-header { justify-content: center; padding: 0 8px; }

/* ── Dropdown menu ────────────────────────────────────── */

.dropdown-menu {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 4px;
    min-width: 140px;
}

.dropdown-item {
    color: var(--text);
    font-family: var(--font);
    font-size: 13px;
    border-radius: 7px;
    padding: 7px 12px;
}
.dropdown-item:hover,
.dropdown-item:focus  { background: var(--surface); color: var(--text); }
.dropdown-item.active,
.dropdown-item:active { background: var(--surface); color: var(--text); }

/* Chat attach menu — submenu for recent files */
.chat-attach-menu .dropdown-item { display: flex; align-items: center; }
.chat-attach-menu .chat-recent-parent { position: relative; }
.chat-attach-menu .chat-recent-chev { margin-left: auto; opacity: 0.5; width: 11px; height: 11px; }
.chat-recent-submenu {
    display: none;
    position: absolute;
    left: 100%;
    top: -5px;
    margin-left: 2px;
    min-width: 220px;
    max-width: 320px;
}
.chat-attach-menu .chat-recent-parent.open > .chat-recent-submenu { display: block; }
.chat-attach-menu .chat-recent-parent.open > .dropdown-item { background: var(--surface); }
.chat-recent-submenu .dropdown-item { display: flex; align-items: center; gap: 8px; }
.chat-recent-submenu .chat-recent-thumb {
    width: 22px; height: 22px; border-radius: 4px; object-fit: cover; flex-shrink: 0;
    background: var(--surface);
}
.chat-recent-submenu .chat-recent-name {
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-recent-submenu .chat-recent-empty {
    padding: 8px 12px; color: var(--muted); font-size: 12px;
}

/* ── Empty / chat states ──────────────────────────────── */

#chat-screen.chat-empty #chat-content  { justify-content: center; }
#chat-screen.chat-empty #messages      { display: none !important; }

.welcome-title {
    display: none;
    font-size: 24px;
    font-weight: 600;
    letter-spacing: -0.02em;
    text-align: center;
    color: var(--text);
    margin-bottom: 20px;
}
#chat-screen.chat-empty .welcome-title { display: block; }

#input-zone {
    width: 100%;
    max-width: 720px;
    margin: 0 auto;
}

/* ── Messages ─────────────────────────────────────────── */

#messages {
    display: flex;
    flex-direction: column;
    gap: 32px;
    padding: 32px 0 24px;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}
#messages::-webkit-scrollbar       { width: 4px; }
#messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.msg-user,
.msg-assistant {
    width: 100%;
    max-width: 720px;
    margin: 0 auto;
    padding: 0 24px;
}

.msg-user { display: flex; justify-content: flex-end; }

.user-bubble-wrap {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    max-width: 80%;
    gap: 4px;
}

.user-copy-btn {
    opacity: 0;
    transition: opacity 0.15s;
}
.msg-user:hover .user-copy-btn { opacity: 1; }

.user-bubble {
    width: 100%;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 18px;
    border-bottom-right-radius: 4px;
    padding: 12px 18px;
    font-size: 16px;
    line-height: 1.65;
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--text);
}

.user-file-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 10px;
    margin-bottom: 6px;
    font-size: 12px;
    color: var(--text);
}
.user-file-chip svg { flex-shrink: 0; color: var(--muted); }
.user-file-chip-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 240px;
}
.user-file-view-btn {
    background: none;
    border: none;
    color: var(--muted);
    font-size: 11px;
    cursor: pointer;
    padding: 0;
    flex-shrink: 0;
    text-decoration: underline;
    text-underline-offset: 2px;
}
.user-file-view-btn:hover { color: var(--text); }

/* ── File viewer popup ───────────────────────────────── */

.file-viewer {
    position: fixed;
    inset: 0;
    z-index: 1060;
    display: flex;
    align-items: center;
    justify-content: center;
}
.file-viewer-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.7);
}
.file-viewer-inner {
    position: relative;
    width: min(90vw, 820px);
    max-height: 80vh;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.file-viewer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    gap: 12px;
}
.file-viewer-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.file-viewer-header-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.file-viewer-close {
    background: none;
    border: none;
    color: var(--muted);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    padding: 0 2px;
}
.file-viewer-close:hover { color: var(--text); }
.file-viewer-content {
    flex: 1;
    overflow: auto;
    margin: 0;
    padding: 16px 20px;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 12px;
    line-height: 1.6;
    color: var(--text);
    background: transparent;
    white-space: pre-wrap;
    word-break: break-all;
}

.msg-assistant { display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap; }

.assistant-icon {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--surface2);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--muted);
    margin-top: 2px;
}

.assistant-body {
    flex: 1;
    font-size: 16px;
    line-height: 1.75;
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--text);
    padding-top: 2px;
}

.msg-footer {
    flex: 0 0 100%;
    display: flex;
    align-items: center;
    gap: 20px;
    padding-bottom: 10px;
}
#bp-messages .msg-footer,
#bp-prompt-messages .msg-footer { padding-left: 40px; }

.msg-copy-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 7px;
    border: none;
    background: transparent;
    color: #888;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}
.msg-copy-btn:hover  { background: var(--surface2); color: var(--text); }
.msg-copy-btn.copied { color: #6ee7a0; }

.msg-model-label { font-size: 11px; color: var(--muted); }

.loading-cursor { animation: blink 1s infinite; }

@keyframes blink {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0; }
}

/* ── Input area ───────────────────────────────────────── */

.input-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 14px 14px 10px;
    transition: border-color 0.15s;
}
.input-box:has(#message-input:focus) { border-color: #444; }

#message-input {
    max-height: calc(12 * 14px * 1.6);
    overflow-y: hidden;
}

.input-footer {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-top: 8px;
}
.input-footer .send-btn { margin-left: auto; }

.chat-footer-controls { display: flex; align-items: center; gap: 10px; }

.chat-attachments { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.chat-attach-row   { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }

.chat-mode-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 4px 8px 4px 10px;
    font-size: 12px;
    color: var(--text);
}
.chat-mode-chip-close {
    border: none;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-size: 15px;
    line-height: 1;
    padding: 0 0 0 2px;
    display: flex;
    align-items: center;
}
.chat-mode-chip-close:hover { color: var(--text); }

/* ── "+" add-ref button in attachments bar ─────── */
.chat-ref-add-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: 1.5px dashed var(--border);
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    flex-shrink: 0;
    padding: 0;
}
.chat-ref-add-btn:hover { border-color: var(--text); color: var(--text); }
.chat-ref-add-btn:disabled, .chat-ref-add-btn.disabled { opacity: 0.35; cursor: not-allowed; pointer-events: none; }

/* ── Ref image chips in attachments bar ────────── */
.chat-ref-imgs { display: flex; gap: 6px; flex-wrap: wrap; }
.chat-ref-chip {
    position: relative;
    width: 72px;
    height: 72px;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid var(--border);
    flex-shrink: 0;
    cursor: pointer;
}
.chat-ref-chip img { width: 100%; height: 100%; object-fit: cover; display: block; }
.chat-ref-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background: rgba(0,0,0,.65);
    border: none;
    color: #fff;
    font-size: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    line-height: 1;
}

/* ── Ref images in user bubble ─────────────────── */
.user-bubble-img-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    font-weight: 500;
    color: var(--muted);
    margin-bottom: 4px;
}
.user-bubble-img-badge svg { flex-shrink: 0; }

/* ── Ref image preview lightbox ──────────────────── */
.ref-preview-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.85);
    z-index: 10100;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: zoom-out;
}
.ref-preview-img {
    max-width: 90vw;
    max-height: 90vh;
    border-radius: 8px;
    object-fit: contain;
    pointer-events: none;
}
.ref-preview-close {
    position: fixed;
    top: 16px;
    right: 20px;
    background: transparent;
    border: none;
    color: #fff;
    font-size: 32px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    opacity: .7;
}
.ref-preview-close:hover { opacity: 1; }

.user-bubble-ref-imgs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 6px; }
.user-bubble-ref-img {
    width: 72px;
    height: 72px;
    border-radius: 6px;
    object-fit: cover;
    border: 1px solid var(--border);
    cursor: pointer;
}

/* ── Ref image picker modal ────────────────────── */
.ref-picker-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.55);
    z-index: 1055;
    display: flex;
    align-items: center;
    justify-content: center;
}
.ref-picker-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    width: 900px;
    max-width: calc(100vw - 32px);
    height: 80vh;
    max-height: 800px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.ref-picker-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px 12px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
    font-weight: 600;
}
.ref-picker-body { flex: 1; overflow-y: auto; padding: 14px 18px; min-height: 200px; }
.ref-img-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-content: flex-start;
}
.ref-thumb {
    height: 140px;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    border: 2px solid transparent;
    position: relative;
    background: var(--surface2);
    flex: 0 0 auto;
}
.ref-thumb img { display: block; height: 100%; width: auto; object-fit: cover; }
.ref-thumb.selected { border-color: var(--accent); }
.ref-thumb-check {
    position: absolute;
    top: 5px;
    right: 5px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent);
    display: none;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
}
.ref-thumb.selected .ref-thumb-check { display: flex; }
.ref-upload-tile {
    height: 140px;
    width: 140px;
    border-radius: 8px;
    border: 1.5px dashed var(--border);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    cursor: pointer;
    color: var(--muted);
    font-size: 12px;
    background: var(--surface2);
    flex: 0 0 auto;
    text-align: center;
    padding: 12px;
}
.ref-upload-tile .icon { color: currentColor; }
.ref-upload-tile:hover { border-color: var(--text); color: var(--text); }
.ref-empty { text-align: center; padding: 40px 20px; color: var(--muted); font-size: 13px; }
.ref-picker-footer {
    padding: 18px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.ref-picker-footer-right { display: flex; gap: 8px; }
.ref-picker-footer .btn {
    font-size: 13px;
    font-weight: 600;
    padding: 8px 16px;
    border-radius: 10px;
    line-height: 1.6;
}

/* ── Ref images in image popup ─────────────────── */
.img-popup-refs {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 10px;
}
.img-popup-ref-img {
    width: 56px;
    height: 56px;
    border-radius: 6px;
    object-fit: cover;
    border: 1px solid var(--border);
    cursor: pointer;
}

.chat-images { display: flex; flex-direction: row; flex-wrap: nowrap; gap: 8px; width: 100%; }

.chat-img-placeholder {
    min-height: 80px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 8px;
}
.chat-img-spinner-ring {
    width: 28px; height: 28px; border-radius: 50%;
    border: 3px solid var(--border); border-top-color: #a855f7;
    animation: bpSpin 0.8s linear infinite;
}
.chat-img-timer { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }

.chat-attach-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    margin-bottom: 2px;
}
.chat-attach-row #message-input { flex: 1; min-width: 0; }

.chat-attach-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border: none;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    flex-shrink: 0;
    padding: 0;
    margin-bottom: 2px;
}

.send-btn {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    border: none;
    background: var(--text);
    color: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: opacity 0.15s, transform 0.1s;
    flex-shrink: 0;
}
.send-btn:hover    { opacity: 0.85; }
.send-btn:active   { transform: scale(0.94); }
.send-btn:disabled { opacity: 0.25; cursor: not-allowed; transform: none; }

.input-hint { font-size: 11px; color: var(--muted); margin: 0; }

/* ── Markdown ─────────────────────────────────────────── */

.md { white-space: normal; }
.md p           { margin: 0 0 0.75em; }
.md p:last-child { margin-bottom: 0; }

.md h1, .md h2, .md h3,
.md h4, .md h5, .md h6 {
    font-weight: 600;
    line-height: 1.3;
    margin: 1em 0 0.4em;
    color: var(--text);
}
.md h1 { font-size: 1.25em; }
.md h2 { font-size: 1.1em; }
.md h3 { font-size: 1em; }

.md ul, .md ol { padding-left: 1.4em; margin: 0.5em 0; }
.md li         { margin-bottom: 0.25em; }

.md code {
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.88em;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 1px 5px;
    color: #c9d1d9;
}

.md pre {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 16px;
    overflow-x: auto;
    margin: 0.75em 0;
}
.md pre code { background: none; border: none; padding: 0; font-size: 13px; color: #c9d1d9; }

.md blockquote {
    border-left: 3px solid var(--border);
    margin: 0.75em 0;
    padding: 4px 0 4px 14px;
    color: #aaa;
}

.md a { color: #7da2f8; text-decoration: none; }
.md a:hover { text-decoration: underline; }

.md table { width: 100%; border-collapse: collapse; margin: 0.75em 0; font-size: 13px; }
.md th, .md td { border: 1px solid var(--border); padding: 7px 12px; text-align: left; }
.md th { background: var(--surface2); font-weight: 600; }

.md hr { border: none; border-top: 1px solid var(--border); margin: 1em 0; }


.img-timer {
    font-size: 22px;
    font-weight: 600;
    font-style: normal;
    color: var(--text);
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
}

/* ── Image card ───────────────────────────────────────── */

.img-card {
    position: relative;
    flex-shrink: 0;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    background: var(--surface2);
    border: 1px solid var(--border);
}

.img-card-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.img-card-overlay {
    position: absolute;
    bottom: 0; left: 0; right: 0;
    padding: 6px 8px;
    background: linear-gradient(transparent, rgba(0,0,0,0.72));
    display: flex;
    gap: 4px;
    align-items: center;
    opacity: 0;
    transition: opacity 0.15s;
}
.img-card:hover .img-card-overlay { opacity: 1; }

.img-card-btn {
    width: 26px;
    height: 26px;
    border-radius: 6px;
    border: 1px solid rgba(255,255,255,0.18);
    background: rgba(0,0,0,0.4);
    color: rgba(255,255,255,0.85);
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.12s, border-color 0.12s;
    padding: 0;
}
.img-card-btn:hover { background: rgba(255,255,255,0.15); border-color: rgba(255,255,255,0.4); }
.img-card-btn.active { background: rgba(255,255,255,0.25); border-color: rgba(255,255,255,0.6); }

.img-card-corner {
    position: absolute;
    width: 26px; height: 26px;
    border-radius: 6px;
    border: 1px solid rgba(255,255,255,0.18);
    background: rgba(0,0,0,0.45);
    color: rgba(255,255,255,0.85);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    opacity: 0;
    transition: opacity 0.15s, background 0.12s, border-color 0.12s;
    z-index: 3; padding: 0;
}
.img-card:hover .img-card-corner { opacity: 1; }
.img-card-corner:hover { background: rgba(255,255,255,0.15); border-color: rgba(255,255,255,0.4); }
.img-card-corner.active { background: rgba(255,255,255,0.25); border-color: rgba(255,255,255,0.6); }
.img-card-corner-tl { top: 6px; left: 6px; }
.img-card-corner-tr { top: 6px; right: 6px; }

.img-card-error {
    width: 100%; height: 100%;
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; color: #e06b6b; padding: 8px; text-align: center;
}

.img-card-loading {
    width: 100%; height: 100%;
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; color: var(--muted); flex-direction: column; gap: 6px;
}

/* ── Image Popup ──────────────────────────────────────── */

.img-popup {
    position: fixed;
    inset: 0;
    z-index: 9999;
}

.img-popup-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.88);
    cursor: pointer;
}

.img-popup-inner {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    pointer-events: none;
}
.img-popup-inner > * { pointer-events: auto; }

.img-popup-body {
    display: flex;
    align-items: flex-start;
    gap: 28px;
    pointer-events: auto;
    max-height: 88vh;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 24px;
}

.img-popup-close {
    position: absolute;
    top: 18px; right: 22px;
    width: 36px; height: 36px;
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,0.2);
    background: rgba(255,255,255,0.08);
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.15s;
    z-index: 1;
    pointer-events: auto;
}
.img-popup-close:hover { background: rgba(255,255,255,0.18); }

.img-popup-left {
    position: relative;
    flex-shrink: 0;
    max-width: 62vw;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

.img-popup-img {
    max-width: 100%;
    max-height: 76vh;
    object-fit: contain;
    border-radius: 8px;
    display: block;
}

.img-popup-nav {
    display: flex;
    gap: 8px;
}

.img-popup-nav-btn {
    width: 36px; height: 36px;
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.2);
    background: rgba(255,255,255,0.08);
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.15s;
}
.img-popup-nav-btn:hover { background: rgba(255,255,255,0.18); }
.img-popup-nav-btn:disabled { opacity: 0.3; cursor: default; }

.img-popup-right {
    width: 300px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 14px;
    max-height: 88vh;
    overflow-y: auto;
}

.img-popup-prompt-wrap { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }

.img-popup-prompt {
    font-size: 13px;
    color: #e8e8e8;
    line-height: 1.65;
    word-break: break-word;
    max-height: 320px;
    overflow-y: auto;
}

.img-popup-icon-btn {
    width: 28px; height: 28px;
    border-radius: 7px;
    border: 1px solid rgba(255,255,255,0.12);
    background: rgba(255,255,255,0.06);
    color: rgba(255,255,255,0.55);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.12s, color 0.12s, border-color 0.12s;
    padding: 0; flex-shrink: 0;
}
.img-popup-icon-btn:hover { background: rgba(255,255,255,0.12); color: #fff; border-color: rgba(255,255,255,0.25); }
.img-popup-icon-btn.copied { color: #22c55e !important; border-color: #22c55e55 !important; }
.img-popup-lib-btn.in-library { border-color: #22c55e55; background: rgba(34,197,94,0.10); }
.img-popup-lib-btn.in-library:hover { background: rgba(34,197,94,0.18); border-color: #22c55eaa; }

.img-lib-menu {
    position: absolute;
    z-index: 10000;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 4px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.4);
    min-width: 180px;
}
.img-lib-menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 12px;
    background: none;
    border: none;
    color: var(--text);
    font-size: 13px;
    text-align: left;
    border-radius: 6px;
    cursor: pointer;
}
.img-lib-menu-item:hover { background: var(--surface2); }
.img-lib-menu-item-danger { color: #ff5555; }

.img-popup-meta {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.img-popup-meta-row {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
}
.img-popup-meta-label { color: var(--muted); }
.img-popup-meta-value { color: var(--text); }

.img-popup-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

.img-popup-action-btn {
    padding: 5px 14px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface2);
    color: var(--text);
    font-size: 12px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}
.img-popup-action-btn:hover { background: var(--surface3, #2a2a2a); border-color: #555; }

.ctrl-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--muted);
    margin-bottom: 8px;
}

.ctrl-val { color: var(--text); font-weight: 500; text-transform: none; letter-spacing: 0; }
.ctrl-hint { font-size: 11px; color: var(--muted); white-space: nowrap; }

.ctrl-select {
    width: 100%;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-family: var(--font);
    font-size: 13px;
    padding: 8px 10px;
    outline: none;
    cursor: pointer;
    transition: border-color 0.15s;
}
.ctrl-select:focus { border-color: #444; }

.form-range::-webkit-slider-thumb { background: var(--text); }
.form-range::-moz-range-thumb     { background: var(--text); }
.form-range { accent-color: var(--text); }

.btn-generate {
    width: 100%;
    padding: 9px 0;
    border-radius: 10px;
    border: none;
    background: var(--text);
    color: var(--bg);
    font-family: var(--font);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s;
}
.btn-generate:hover    { opacity: 0.85; }
.btn-generate:disabled { opacity: 0.3; cursor: not-allowed; }

.btn-download {
    display: block;
    text-align: center;
    padding: 7px 0;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    font-family: var(--font);
    font-size: 13px;
    cursor: pointer;
    text-decoration: none;
    transition: border-color 0.15s, background 0.15s;
}
.btn-download:hover { border-color: #444; background: var(--surface2); color: var(--text); }

/* ── Blueprint modals ────────────────────────────────── */

#bp-port-modal .modal-content {
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text);
}
#bp-port-modal .modal-header,
#bp-port-modal .modal-footer {
    border-color: var(--border);
}
#bp-port-modal .modal-title { color: var(--text); }
#bp-port-modal #bp-port-modal-text {
    background: var(--surface);
    border-color: var(--border);
    color: var(--text);
}

/* ── Blueprints ───────────────────────────────────────── */

/* Canvas wrap */
.bp-canvas-wrap {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: var(--bg);
}
.bp-canvas-wrap::before {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    background-image: radial-gradient(circle, #252525 1px, transparent 1px);
    background-size: 24px 24px;
    z-index: 0;
}

.bp-canvas {
    position: absolute;
    inset: 0;
    z-index: 1;
}

.bp-svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: visible;
}

.bp-elements-panel {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 10;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 6px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.35);
    user-select: none;
}

.bp-elem-item {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.12s, opacity 0.12s;
    flex-shrink: 0;
    opacity: 0.75;
}
.bp-elem-item:hover { background: var(--surface2); opacity: 1; }
.bp-elem-item:active { opacity: 0.5; }

.bp-elem-divider {
    width: 20px;
    margin: 3px 0;
    border-top: 1px solid var(--border);
    opacity: 1;
}

/* Nodes */
.bp-node {
    position: absolute;
    width: 270px;
    background: var(--surface);
    border: 1px solid var(--node-accent, var(--border));
    border-radius: 12px;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
    user-select: none;
}
.bp-node:hover {
    border-color: var(--node-accent-bright, #444);
}
.bp-node.bp-active {
    border-color: var(--node-accent-bright, #555);
    box-shadow: 0 0 0 1px var(--node-accent-bright, #555);
}

.bp-node-head {
    padding: 12px 26px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid var(--node-head-border, var(--border));
    font-size: 12px;
    font-weight: 700;
    cursor: move;
}

/* Unified badge — top-left corner, mirrors delete button */
.bp-node-badge {
    position: absolute;
    top: -18px; left: -18px;
    width: 36px; height: 36px;
    border-radius: 50%;
    border: 1px solid;
    display: flex; align-items: center; justify-content: center;
    pointer-events: none;
}

.bp-node-title { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; outline: none; }
.bp-node-title-editing { background: var(--surface2); border-radius: 4px; padding: 0 4px; overflow: visible; }
.bp-board-title-editing { outline: 1px solid var(--border); border-radius: 4px; background: var(--surface2); }

.bp-node-del {
    position: absolute;
    top: -18px;
    right: -18px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--surface2);
    color: var(--text);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s, color 0.15s, background 0.15s;
}
.bp-node:hover .bp-node-del { opacity: 1; }
.bp-node-del:hover { background: #2d1515; border-color: #f87171; color: #f87171; }

.bp-node-query {
    padding: 12px 26px;
    font-size: 12px;
    color: var(--text);
    line-height: 1.5;
    min-height: 40px;
    max-height: 160px; /* ~8 lines */
    white-space: pre-wrap;
    word-break: break-word;
    overflow: hidden;
    position: relative;
    outline: none;
    cursor: default;
}
.bp-node-query-placeholder { opacity: 0.4; font-style: italic; }
.bp-node-query-editing {
    overflow-y: auto;
    background: rgba(255,255,255,0.04);
    border-radius: 6px;
    cursor: text;
}
.bp-node-query-clear {
    position: absolute; top: 6px; right: 10px;
    width: 18px; height: 18px; border-radius: 50%;
    border: none; background: transparent;
    color: var(--muted); font-size: 15px; line-height: 1;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; padding: 0;
    opacity: 0; transition: opacity 0.15s, color 0.15s;
}
.bp-node:hover .bp-node-query-clear { opacity: 1; }
.bp-node-query-clear:hover { color: var(--text); }

.bp-node-foot {
    border-top: 1px solid var(--border);
    padding: 5px 14px 7px;
    display: flex;
    justify-content: flex-end;
}
.bp-node-renew {
    display: inline-flex; align-items: center; gap: 5px;
    font-size: 10px; color: var(--muted);
    background: transparent; border: none;
    cursor: pointer; padding: 3px 7px; border-radius: 4px;
    transition: background 0.15s, color 0.15s;
}
.bp-node-renew:hover { background: var(--surface2); color: var(--text); }

/* Ports */
.bp-port {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid #444;
    background: var(--surface2);
    position: absolute;
    cursor: crosshair;
    transition: border-color 0.15s, background 0.15s;
    z-index: 2;
    flex-shrink: 0;
}
.bp-port:hover,
.bp-port.bp-port-active { border-color: var(--text); background: var(--text); }

.bp-port-in  { left: -12px; top: 50%; transform: translateY(-50%); }
.bp-port-out { right: -12px; }
.bp-port-out:hover { background: var(--port-color, var(--text)); border-color: var(--port-color, var(--text)); }

/* Output port stack (multiple marked messages) */
.bp-node-ports-out {
    position: absolute;
    right: -12px;
    top: 50px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding-bottom: 14px;
    pointer-events: none;
}
.bp-node-ports-out .bp-port { position: relative; right: auto; pointer-events: all; }

/* Input port stack + add button */
.bp-node-ports-in {
    position: absolute;
    left: -12px;
    top: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 50px 0 14px; /* 50px top aligns first item with preview body */
    gap: 10px;
    pointer-events: none;
    z-index: 2;
}
.bp-node-ports-in .bp-port { position: relative; left: auto; top: auto; transform: none; pointer-events: all; }
.bp-port-add-in {
    width: 24px; height: 24px; border-radius: 50%;
    border: 1.5px dashed #888;
    background: transparent; color: #bbb;
    display: flex; align-items: center; justify-content: center;
    font-size: 16px; line-height: 1; padding: 0;
    cursor: pointer; pointer-events: all;
    transition: border-color 0.15s, color 0.15s;
}
.bp-port-add-in:hover { border-color: var(--text); color: var(--text); }

/* Wires */
.bp-wire      { fill: none; stroke: #3a3a3a; stroke-width: 2; pointer-events: none; }
.bp-wire-temp { fill: none; stroke: #555; stroke-width: 2; stroke-dasharray: 6 4; pointer-events: none; }

/* Image ports — square shape */
.bp-port.bp-port-image { border-radius: 3px; }
.bp-port.bp-port-image-warn { border-color: #f59e0b !important; border-style: dashed !important; }

/* Image wire glow */
.bp-wire-glow { stroke-width: 8; opacity: 0.25; }

/* Resizer */
.bp-resizer {
    width: 4px;
    flex-shrink: 0;
    background: var(--border);
    cursor: col-resize;
    transition: background 0.15s;
    position: relative;
    z-index: 5;
}
.bp-resizer:hover,
.bp-resizer.bp-resizing { background: #444; }

/* Right panel */
.bp-panel {
    width: 380px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.bp-panel-empty {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    font-size: 13px;
}

.bp-panel-chat {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
}

.bp-panel-title {
    padding: 10px 16px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    border-bottom: 1px solid var(--border);
    color: var(--muted);
    flex-shrink: 0;
}

.bp-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.bp-input-wrap {
    padding: 10px 12px 12px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

/* Mark button */
.bp-mark-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 7px;
    border: none;
    background: transparent;
    color: #888;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}
.bp-mark-btn:hover  { background: var(--surface2); color: var(--text); }
.bp-mark-btn.marked { color: inherit; }

/* Marked message highlight — color set via inline style */
.bp-msg-marked { border-radius: 12px; }

/* Edited badge */
.bp-edited-badge {
    font-size: 10px;
    color: var(--muted);
    padding: 1px 6px;
    border: 1px solid var(--border);
    border-radius: 4px;
    line-height: 1.6;
    align-self: center;
}

/* ── Auth modal ─────────────────────────────────────── */
.auth-backdrop {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.6);
    z-index: 2100;
    display: flex; align-items: center; justify-content: center;
}
.auth-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    width: 420px;
    max-width: calc(100vw - 32px);
    display: flex; flex-direction: column;
    overflow: hidden;
}
.auth-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 18px 24px 14px;
    border-bottom: 1px solid var(--border);
    font-size: 15px; font-weight: 600;
}
.auth-close {
    background: none; border: none; color: var(--muted);
    font-size: 22px; line-height: 1; cursor: pointer; padding: 0;
}
.auth-close:hover { color: var(--text); }
.auth-body {
    padding: 24px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 420px;
    gap: 32px;
}
.auth-content { display: flex; flex-direction: column; gap: 16px; }
.auth-footer { display: flex; flex-direction: column; gap: 12px; }
.auth-field { display: flex; flex-direction: column; gap: 6px; }
.auth-label { font-size: 12px; color: var(--muted); font-weight: 500; }
.auth-input {
    width: 100%;
    padding: 10px 12px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.4;
    outline: none;
}
.auth-input:focus { border-color: var(--text); }
.auth-input-pin {
    text-align: center;
    letter-spacing: 8px;
    font-size: 22px;
    font-weight: 600;
}
.auth-terms { display: flex; flex-direction: column; gap: 8px; padding: 4px 0; }
.auth-check {
    display: flex; align-items: flex-start; gap: 10px;
    font-size: 12px; color: var(--text); cursor: pointer; line-height: 1.4;
}
.auth-check input { margin-top: 2px; flex-shrink: 0; }
.auth-check a { color: var(--text); text-decoration: underline; }
.auth-hint { font-size: 11px; color: var(--muted); line-height: 1.4; }
.auth-error { font-size: 12px; color: #ff5555; line-height: 1.4; }
.auth-row { display: flex; justify-content: space-between; align-items: center; }
.auth-link {
    background: none; border: none; color: var(--muted);
    font-size: 12px; cursor: pointer; padding: 4px 0;
}
.auth-link:hover:not(:disabled) { color: var(--text); }
.auth-link:disabled { opacity: 0.4; cursor: not-allowed; }
.auth-btn {
    padding: 10px 0; border-radius: 10px; border: none;
    font-family: var(--font); font-size: 13px; font-weight: 600;
    cursor: pointer; transition: opacity 0.15s; width: 100%;
}
.auth-btn-primary { background: var(--text); color: var(--bg); }
.auth-btn-primary:hover:not(:disabled) { opacity: 0.85; }
.auth-btn-primary:disabled { opacity: 0.3; cursor: not-allowed; }

/* ── Settings modal ─────────────────────────────────── */
.settings-backdrop {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.6);
    z-index: 2150;
    display: flex; align-items: center; justify-content: center;
}
.settings-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    width: 860px;
    max-width: calc(100vw - 32px);
    height: 80vh;
    max-height: 720px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.settings-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 18px 24px 14px;
    border-bottom: 1px solid var(--border);
    font-size: 15px; font-weight: 600;
}
.settings-close {
    background: none; border: none; color: var(--muted);
    font-size: 22px; line-height: 1; cursor: pointer; padding: 0;
}
.settings-close:hover { color: var(--text); }
.settings-body {
    display: flex;
    flex: 1;
    min-height: 0;
}
.settings-sidebar {
    width: 220px;
    border-right: 1px solid var(--border);
    padding: 14px 10px;
    display: flex; flex-direction: column;
    gap: 2px;
    flex-shrink: 0;
}
.settings-tab {
    padding: 9px 14px;
    border-radius: 8px;
    color: var(--text);
    font-size: 13px;
    cursor: pointer;
    transition: background 0.12s;
}
.settings-tab:hover  { background: var(--surface2); }
.settings-tab.active { background: var(--surface2); }
.settings-content {
    flex: 1;
    padding: 20px 24px;
    overflow-y: auto;
}
.settings-section { color: var(--text); display: flex; flex-direction: column; gap: 22px; max-width: 480px; }

.settings-row { display: flex; align-items: center; gap: 20px; }
.settings-row-avatar { gap: 20px; }

.settings-avatar {
    width: 84px; height: 84px;
    border-radius: 50%;
    background: var(--surface2);
    border: 1px solid var(--border);
    display: flex; align-items: center; justify-content: center;
    overflow: hidden;
    color: var(--text);
    font-size: 28px;
    font-weight: 600;
    flex-shrink: 0;
}
.settings-avatar img {
    width: 100%; height: 100%;
    object-fit: cover;
    display: block;
}
.settings-avatar-actions { display: flex; flex-direction: column; gap: 8px; }
.settings-btn-narrow {
    width: auto !important;
    padding: 11px 18px;
    font-size: 14px;
    line-height: 1.4;
}
.settings-btn-ghost {
    background: var(--surface2);
    color: var(--text);
    border: 1px solid var(--border);
}
.settings-btn-ghost:hover:not(:disabled) { opacity: 0.85; }
.settings-btn-danger {
    background: transparent;
    color: #ff5555;
    border: 1px solid #ff555533;
    width: auto !important;
    padding: 8px 18px;
}
.settings-btn-danger:hover { background: rgba(255,85,85,0.08); border-color: #ff555588; }

.settings-field { display: flex; flex-direction: column; gap: 6px; }
.settings-label { font-size: 12px; color: var(--muted); font-weight: 500; }
.settings-hint  { font-size: 11px; color: var(--muted); }
.settings-logout-row { margin-top: 8px; }

/* App-wide custom select (replaces native <select>) */
.app-select { position: relative; }
.app-select-toggle {
    display: flex;
    align-items: center;
    width: 100%;
    text-align: left;
    cursor: pointer;
    padding-right: 36px;
}
.app-select-toggle.dropdown-toggle::after {
    border: none;
    width: 10px; height: 10px;
    margin-left: auto;
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%23999' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    position: absolute;
    right: 12px; top: 50%;
    transform: translateY(-50%);
    transition: transform 0.15s;
    vertical-align: 0;
}
.app-select.show .app-select-toggle.dropdown-toggle::after {
    transform: translateY(-50%) rotate(180deg);
}
.app-select-label { color: var(--text); }
.app-select-menu  { width: 100%; min-width: 0; }
.app-select-menu .dropdown-item.active {
    background: var(--surface);
    color: var(--text);
}

.storage-list {
    display: flex; flex-direction: column;
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    background: var(--surface2);
}
.storage-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    font-size: 13px;
    color: var(--text);
    border-bottom: 1px solid var(--border);
}
.storage-row:last-child { border-bottom: none; }
.storage-row-label { color: var(--muted); }
.storage-row-size {
    font-variant-numeric: tabular-nums;
    font-weight: 500;
}
.storage-row-total .storage-row-label { color: var(--text); font-weight: 500; }
.storage-row-total { background: rgba(255,255,255,0.03); }

/* Referral section */
.ref-intro {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px 20px;
    margin-bottom: 16px;
}
.ref-intro-title { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.ref-intro-text  { font-size: 13px; color: var(--muted); line-height: 1.5; }

.ref-links-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 6px;
    margin-bottom: 12px;
}
.ref-links-empty {
    font-size: 12px;
    color: var(--muted);
    padding: 8px 0;
}
.ref-link-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 10px;
}
.ref-link-label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    min-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ref-link-url {
    flex: 1;
    font-family: monospace;
    font-size: 12px;
    color: var(--muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ref-link-stats {
    font-size: 11px;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.ref-link-actions { display: flex; gap: 4px; }
.ref-link-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 11px;
    padding: 4px 10px;
    border-radius: 6px;
    cursor: pointer;
}
.ref-link-btn:hover { background: var(--surface); }
.ref-link-btn-danger { color: #ff5555; border-color: #ff555533; }
.ref-link-btn-danger:hover { background: rgba(255,85,85,0.08); }
.ref-link-icon-btn {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--muted);
    width: 28px; height: 28px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
}
.ref-link-icon-btn:hover { background: var(--surface); color: var(--text); }
.ref-link-icon-btn.copied { color: #4ade80; border-color: #4ade8055; }

.ref-link-create {
    display: flex;
    gap: 8px;
}
.ref-link-create .auth-input { flex: 1; }

.promo-inline-form {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    align-items: center;
}
.promo-inline-form .app-select { min-width: 140px; }
.promo-inline-form .promo-uses-input { width: 90px; flex-shrink: 0; }
.promo-inline-form .promo-create-add-btn { margin-left: auto; white-space: nowrap; }

/* Make it obvious that the plan picker is a dropdown */
.promo-inline-form .app-select-toggle.dropdown-toggle::after {
    width: 14px; height: 14px;
    background-image: url("data:image/svg+xml,%3Csvg width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23eeeeee' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
}
.promo-inline-form .app-select-toggle:hover { border-color: var(--text); }

.promo-kebab-btn {
    background: transparent;
    border: none;
    color: var(--muted);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 18px;
    line-height: 1;
    letter-spacing: 1px;
}
.promo-kebab-btn:hover { background: var(--surface); color: var(--text); }

#promo-mine-table td:nth-child(3),
#promo-mine-table th:nth-child(3) { text-align: right; }

/* Card-style rows for promo table (similar to .ref-link-item) */
#promo-mine-table {
    border-collapse: separate;
    border-spacing: 0 6px;
}
#promo-mine-table thead th { border: none; padding-bottom: 4px; }
#promo-mine-table tbody td {
    background: var(--surface2);
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}
#promo-mine-table tbody td:first-child {
    border-left: 1px solid var(--border);
    border-top-left-radius: 10px;
    border-bottom-left-radius: 10px;
}
#promo-mine-table tbody td:last-child {
    border-right: 1px solid var(--border);
    border-top-right-radius: 10px;
    border-bottom-right-radius: 10px;
}
#promo-mine-table tbody td.plan-payments-empty {
    background: transparent;
    border: none;
}

.promo-block-icon {
    color: #ff5555;
    display: inline-block;
    vertical-align: middle;
    margin-right: 6px;
}
.promo-row-blocked td { color: #888; }
.promo-row-blocked .promo-block-icon { color: #ff5555; }

/* Bottom padding so last form has room when scrolled */
.settings-section { padding-bottom: 40px; }

#ref-enrolled { display: flex; flex-direction: column; gap: 22px; }
.ref-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}
.ref-stat {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 14px 12px;
    text-align: center;
}
.ref-stat-value { font-size: 22px; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }
.ref-stat-label { font-size: 11px; color: var(--muted); margin-top: 4px; }

.admin-promo-block { margin-top: 8px; }
.promo-admin-toggle {
    margin: 8px 0 4px;
    padding: 8px 12px;
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 12px;
}
.promo-admin-toggle input { margin-right: 8px; }
.promo-create-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 10px;
    padding: 14px 16px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 10px;
}
.promo-create-row { display: flex; align-items: center; gap: 12px; }
.promo-create-summary {
    display: flex;
    justify-content: space-between;
    margin-top: 14px;
    padding: 12px 16px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 13px;
    color: var(--text);
}
.promo-create-summary span:first-child { color: var(--muted); margin-right: 6px; }
.promo-create-summary span:last-child  { font-weight: 600; font-variant-numeric: tabular-nums; }
#promo-create-btn { margin-top: 12px; }
#promo-mine-table td:first-child { font-family: monospace; font-weight: 600; }

/* Plan section */
.plan-current {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 12px;
    gap: 16px;
}
.plan-current-info { display: flex; flex-direction: column; gap: 4px; }
.plan-current-name { font-size: 18px; font-weight: 600; color: var(--text); }
.plan-current-name.empty { font-size: 13px; font-weight: 400; color: var(--muted); }

.plan-tokens .user-menu-tokens {
    padding: 14px 16px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-top: 6px;
}

.plan-promo-row {
    display: flex;
    gap: 8px;
    align-items: center;
}
.plan-promo-row .auth-input { flex: 1; text-transform: uppercase; }
.plan-promo-msg {
    font-size: 12px;
    line-height: 1.4;
    margin-top: 4px;
}
.plan-promo-msg.is-error   { color: #ff5555; }
.plan-promo-msg.is-success { color: #4ade80; }

.plan-payments-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.plan-payments-table th,
.plan-payments-table td {
    text-align: left;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
}
.plan-payments-table th {
    color: var(--muted);
    font-weight: 500;
    font-size: 12px;
}
.plan-payments-table td { color: var(--text); }
.plan-payments-empty {
    text-align: center !important;
    color: var(--muted);
    padding: 18px !important;
}

/* Plan buy modal — opens on top of settings */
.plan-buy-backdrop {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.65);
    z-index: 2200;
    display: flex; align-items: center; justify-content: center;
}
.plan-buy-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    width: 1040px;
    max-width: calc(100vw - 32px);
    max-height: 86vh;
    display: flex; flex-direction: column;
    overflow: hidden;
}
.plan-buy-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 18px 24px 14px;
    border-bottom: 1px solid var(--border);
    font-size: 16px; font-weight: 600;
}
.plan-buy-body {
    padding: 22px 24px;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 14px;
    overflow-y: auto;
}

.plan-card {
    display: flex; flex-direction: column;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 22px 20px 20px;
    gap: 14px;
    min-height: 480px;
}
.plan-card.featured {
    border-color: var(--text);
    box-shadow: 0 0 0 1px var(--text) inset;
}
.plan-card-name {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
}
.plan-card-price-row {
    display: flex; align-items: baseline; gap: 6px;
}
.plan-card-price {
    font-size: 24px;
    font-weight: 700;
    color: var(--text);
}
.plan-card-period {
    font-size: 12px;
    color: var(--muted);
}
.plan-card-tokens {
    font-size: 13px;
    color: var(--text);
    padding: 8px 0;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}
.plan-card-tokens-value { font-weight: 600; }
.plan-card-features { display: flex; flex-direction: column; gap: 6px; flex: 1; }
.plan-card-feature {
    display: flex; align-items: flex-start; gap: 8px;
    font-size: 12px;
    color: var(--text);
    line-height: 1.4;
}
.plan-card-feature::before {
    content: '✓';
    color: var(--token);
    flex-shrink: 0;
    font-weight: 700;
}
.plan-card-buy {
    width: 100%;
    padding: 10px 0;
    border-radius: 10px;
    border: 1px solid var(--text);
    background: transparent;
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    font-family: var(--font);
    line-height: 1.4;
    transition: opacity 0.12s;
}
.plan-card-buy:hover { opacity: 0.85; }
.plan-card.featured .plan-card-buy {
    background: var(--text);
    color: var(--bg);
}

/* Avatar image in sidebar (replaces text initials) */
.account-avatar img {
    width: 100%; height: 100%;
    object-fit: cover;
    border-radius: 50%;
    display: block;
}

/* ── Confirm modal ──────────────────────────────────── */
.confirm-backdrop {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.6);
    z-index: 2200;
    display: flex; align-items: center; justify-content: center;
}
.confirm-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    width: 360px;
    max-width: calc(100vw - 32px);
    padding: 22px 24px;
    display: flex; flex-direction: column; gap: 14px;
}
.confirm-title { font-size: 15px; font-weight: 600; color: var(--text); }
.confirm-message { font-size: 13px; color: var(--muted); line-height: 1.5; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.confirm-btn {
    padding: 8px 16px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface2);
    color: var(--text);
    font-family: var(--font);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    line-height: 1.6;
    transition: opacity 0.12s;
}
.confirm-btn:hover { opacity: 0.85; }
.confirm-btn-primary { background: var(--text); border-color: var(--text); color: var(--bg); }
.confirm-btn-danger  { background: #ff5555; border-color: #ff5555; color: #fff; }

/* Inline edit UI */
.assistant-body[contenteditable="true"] {
    outline: none;
    caret-color: var(--text);
    cursor: text;
}

.bp-edit-controls {
    flex: 0 0 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0 14px;
    padding-left: 40px; /* icon(28px) + gap(12px) */
    border-top: 1px solid var(--border);
    margin-top: 4px;
}
.bp-edit-tools {
    display: flex;
    gap: 4px;
    margin-right: auto;
}
.bp-edit-tool-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    cursor: pointer;
    font-size: 12px;
    line-height: 1;
    padding: 3px 7px;
    min-width: 26px;
    text-align: center;
}
.bp-edit-tool-btn:hover { background: var(--surface2); }

.bp-edit-actions {
    display: flex;
    gap: 8px;
    margin-top: 14px;
    justify-content: flex-end;
}
.bp-edit-btn {
    font-size: 13px;
    font-weight: 600;
    padding: 8px 16px;
    border-radius: 10px;
    border: 1px solid var(--border);
    cursor: pointer;
    background: var(--surface2);
    color: var(--text);
    transition: background 0.12s, opacity 0.12s;
    line-height: 1.6;
}
.bp-edit-btn:hover { background: var(--surface); }
.bp-edit-save { background: var(--text); border-color: var(--text); color: var(--bg); }
.bp-edit-save:hover { background: var(--text); opacity: 0.85; }
.bp-edit-revert { color: var(--muted); margin-right: auto; }

/* Drop zone highlight */
.bp-canvas-wrap.bp-drop-active::after {
    content: '';
    position: absolute; inset: 0; z-index: 20;
    border: 2px dashed #5b8dd9;
    border-radius: 4px;
    pointer-events: none;
}

/* File node */

/* Ports aligned with body area (same level as chat-node ports) */
.bp-node-file .bp-port-in  { top: 50px; transform: none; }
.bp-node-file .bp-port-out { border-color: #5b8dd9; top: 50px; transform: none; }
.bp-node-file .bp-port-out:hover { background: #5b8dd9; border-color: #5b8dd9; }
.bp-node-filename {
    font-size: 11px; color: var(--muted); padding: 10px 26px 12px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* File content panel */
.bp-panel-file { display: flex; flex-direction: column; flex: 1; overflow: hidden; }
.bp-file-content {
    flex: 1; overflow-y: auto; padding: 16px;
    font-size: 16px; line-height: 1.75; color: var(--text);
    white-space: pre-wrap; word-break: break-word;
    scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}

/* ── GET / SET variable nodes ───────────────────────────── */
.bp-node-get .bp-port-out { border-color: #10a37f; top: 50px; transform: none; }

.bp-node-set .bp-port-in  { top: 50px; transform: none; }
.bp-node-set .bp-port-out { border-color: #e0884a; top: 50px; transform: none; }

.bp-node-var-wrap { padding: 4px 14px 10px; }
.bp-node-var-dropdown-btn {
    width: 100%; background: var(--surface2); border: 1px solid var(--border);
    border-radius: 6px; color: var(--text); font-size: 12px;
    padding: 5px 10px; text-align: left; cursor: pointer;
    display: flex; align-items: center; justify-content: space-between; gap: 6px;
    white-space: nowrap; overflow: hidden;
}
.bp-node-var-dropdown-btn::after { content: '▾'; font-size: 10px; color: var(--muted); flex-shrink: 0; }
.bp-node-var-dropdown-btn:hover { border-color: var(--muted); }

/* Floating variable menu (appended to body, position:fixed) */
.bp-var-menu {
    position: fixed; z-index: 9999;
    background: var(--surface2); border: 1px solid var(--border);
    border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,0.5);
    overflow: hidden; min-width: 140px;
    animation: bpFadeIn 0.1s ease;
}
.bp-var-menu-item {
    padding: 8px 14px; font-size: 12px; color: var(--text); cursor: pointer;
}
.bp-var-menu-item:hover { background: var(--surface3); }
.bp-var-menu-item.selected { color: #10a37f; }
.bp-var-menu-item.disabled { color: var(--muted); cursor: default; font-style: italic; }
@keyframes bpFadeIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }


/* Variable panel (right side) */
.bp-panel-var { display: flex; flex-direction: column; flex: 1; overflow: hidden; }
.bp-var-value {
    flex: 1; overflow-y: auto; padding: 16px;
    font-size: 16px; line-height: 1.75; color: var(--text);
    white-space: pre-wrap; word-break: break-word;
    scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}

/* ── Image nodes ────────────────────────────────────────── */
.bp-node-image .bp-port-in { /* inherits .bp-node-ports-in positioning */ }

/* Prompt area reuses .bp-node-query styles — no extra CSS needed */

/* Image thumbnail area on canvas node */
.bp-node-img-area {
    margin: 0 14px 8px;
    border-radius: 6px; overflow: hidden;
    background: #111; border: 1px solid var(--border);
    min-height: 120px;
    display: flex;
    align-items: center; justify-content: center;
    position: relative;
}
.bp-node-img-thumb {
    width: 100%;
    display: block;
    cursor: pointer;
}
.bp-node-img-placeholder {
    display: flex; flex-direction: column; align-items: center;
    gap: 8px; color: var(--border); padding: 24px;
}
.bp-node-img-error {
    font-size: 11px; color: #e06b6b; padding: 12px; text-align: center;
}

/* Spinner inside image area */
.bp-node-img-spinner {
    display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.bp-node-img-spinner-ring {
    width: 28px; height: 28px; border-radius: 50%;
    border: 3px solid var(--border); border-top-color: #a855f7;
    animation: bpSpin 0.8s linear infinite;
}
@keyframes bpSpin { to { transform: rotate(360deg); } }
.bp-node-img-timer { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* Node image settings strip */
.bp-node-img-ctrl {
    padding: 6px 14px 2px;
    display: flex; flex-direction: column; gap: 5px;
}
.bp-node-img-ctrl-row { display: flex; align-items: center; gap: 8px; }
.bp-node-img-ctrl-label { flex: 1; font-size: 11px; color: var(--muted); }
.bp-node-img-ctrl-val { min-width: 60px; text-align: center; justify-content: center; }
.bp-node-img-ctrl .ctrl-pill { font-size: 11px; padding: 3px 10px; }
.bp-node-img-ctrl .ctrl-pill-primary { gap: 5px; }

/* Generate button */
.bp-node-image { display: flex; flex-direction: column; }
.bp-node-img-footer { padding: 8px 30px 20px; margin-top: auto; }
.bp-node-img-gen-btn {
    width: 100%; padding: 7px 0; border-radius: 8px;
    border: none; background: var(--text); color: var(--bg);
    font-family: var(--font); font-size: 12px; font-weight: 600;
    cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 6px;
    transition: opacity 0.15s;
}
.bp-node-img-gen-btn:hover    { opacity: 0.85; }
.bp-node-img-gen-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* ── Image right panel ──────────────────────────────────── */
.bp-panel-img { display: flex; flex-direction: column; flex: 1; overflow: hidden; }

.bp-img-settings {
    padding: 12px 16px; border-bottom: 1px solid var(--border);
    display: flex; flex-direction: column; gap: 10px; flex-shrink: 0;
}
.bp-img-settings-row { display: flex; align-items: center; gap: 10px; }
.bp-img-settings-label { font-size: 11px; color: var(--muted); min-width: 80px; flex-shrink: 0; }
.bp-img-ratio-btns, .bp-img-quality-btns { display: flex; gap: 4px; }
.bp-img-setting-btn {
    border: 1px solid var(--border); border-radius: 6px;
    background: transparent; color: var(--muted);
    font-size: 11px; padding: 3px 9px; cursor: pointer;
    transition: all 0.15s;
}
.bp-img-setting-btn:hover { border-color: #555; color: var(--text); }
.bp-img-setting-btn.active { border-color: #a855f7; color: #a855f7; background: #a855f715; }

/* History list */
.bp-img-history {
    flex: 1; overflow-x: auto; overflow-y: hidden;
    padding: 12px 16px;
    display: flex; flex-direction: row; gap: 10px; align-items: flex-start;
    scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}

/* ── Text node ──────────────────────────────────────────── */
.bp-node-text .bp-port-out { border-color: #d97706; top: 50px; transform: none; }
.bp-node-text .bp-port-out:hover { background: #d97706; border-color: #d97706; }

/* ── Static image node ──────────────────────────────────── */
.bp-node-static-image { display: flex; flex-direction: column; }
.bp-node-static-image .bp-node-img-area { margin-bottom: 0; }
.bp-node-static-image .bp-port-out {
    top: 50%;
    transform: translateY(-50%);
}

/* Static image inspector panel */
.bp-panel-static-img {
    display: flex;
    flex-direction: column;
    height: 100%;
}
.bp-panel-static-img.d-none { display: none !important; }
.bp-static-img-preview-wrap {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    overflow: hidden;
    min-height: 0;
}
.bp-static-img-preview {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 6px;
    display: block;
    cursor: pointer;
}
.bp-static-img-actions {
    display: flex;
    gap: 8px;
    padding: 8px 16px 16px;
    flex-shrink: 0;
}
.bp-node-text-preview {
    padding: 6px 14px 10px;
    font-size: 11px; color: var(--muted); line-height: 1.6;
    display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
    overflow: hidden; word-break: break-word;
    min-height: 42px;
}
.bp-node-text-preview.empty { font-style: italic; opacity: 0.5; }

/* ── Text right panel ───────────────────────────────────── */
.bp-panel-text { display: flex; flex-direction: column; flex: 1; overflow: hidden; }
.bp-text-editor {
    flex: 1; margin: 0 16px 16px; padding: 12px;
    background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
    color: var(--text); font-family: var(--font); font-size: 13px; line-height: 1.7;
    resize: none; outline: none;
    scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
.bp-text-editor:focus { border-color: #d97706; }

/* ── Prompt node ─────────────────────────────────────────── */
.bp-node-prompt-status {
    padding: 4px 14px 2px;
    font-size: 11px;
    color: var(--muted);
}

.bp-node-generate { color: #0d9488; }
.bp-node-generate:hover { color: #14b8a6; }

/* Prompt right panel */
.bp-panel-prompt {
    display: flex;
    flex-direction: column;
    height: 100%;
}
.bp-panel-prompt.d-none { display: none !important; }
.bp-panel-prompt .bp-messages {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}
