/* ── Theme variables ─────────────────────────────────────────────────────── */
:root {
    --bg-page:         #f0f2f5;
    --bg-surface:      #ffffff;
    --bg-surface-2:    #f8fafc;
    --text-primary:    #1a1a2e;
    --text-secondary:  #6b7280;
    --text-muted:      #9ca3af;
    --border:          #e5e7eb;
    --border-input:    #d1d5db;
    --accent:          #2563eb;
    --accent-hover:    #1d4ed8;
    --accent-disabled: #93c5fd;
    --bubble-user-bg:  #2563eb;
    --bubble-user-fg:  #ffffff;
    --bubble-bot-bg:   #ffffff;
    --bubble-bot-fg:   #1a1a2e;
    --code-bg:         #f1f5f9;
    --pre-bg:          #1e293b;
    --pre-fg:          #e2e8f0;
    --shadow-sm:       0 1px 3px rgba(0,0,0,.06);
    --shadow-md:       0 4px 24px rgba(0,0,0,.08);
    --shadow-card:     0 1px 3px rgba(0,0,0,.08);
}

[data-theme="dark"] {
    --bg-page:         #0f172a;
    --bg-surface:      #1e293b;
    --bg-surface-2:    #162032;
    --text-primary:    #e2e8f0;
    --text-secondary:  #94a3b8;
    --text-muted:      #64748b;
    --border:          #334155;
    --border-input:    #475569;
    --accent:          #3b82f6;
    --accent-hover:    #2563eb;
    --accent-disabled: #1e3a5f;
    --bubble-user-bg:  #2563eb;
    --bubble-user-fg:  #ffffff;
    --bubble-bot-bg:   #1e293b;
    --bubble-bot-fg:   #e2e8f0;
    --code-bg:         #0f172a;
    --pre-bg:          #0f172a;
    --pre-fg:          #e2e8f0;
    --shadow-sm:       0 1px 3px rgba(0,0,0,.3);
    --shadow-md:       0 4px 24px rgba(0,0,0,.4);
    --shadow-card:     0 1px 3px rgba(0,0,0,.3);
}

/* ── Reset / Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html, body {
    height: 100%;
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-page);
    color: var(--text-primary);
    transition: background .2s, color .2s;
}

#app { height: 100%; }

/* ── App Shell ───────────────────────────────────────────────────────────── */
.app-shell {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.25rem;
    height: 52px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
    position: relative;
    z-index: 100;
}

.header-brand { display: flex; align-items: center; }
.header-logo  { height: 32px; width: auto; }

/* header-pinned: always visible in header */
.header-pinned { display: flex; align-items: center; gap: 0.5rem; margin-left: auto; }

/* ── App body: sidebar + main (below header) ─────────────────────────────── */
.app-body {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

/* ── Desktop sidebar ─────────────────────────────────────────────────────── */
.app-sidebar {
    width: 260px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    overflow-x: hidden;
}

/* New chat button */
.sidebar-new-chat {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0.75rem 0.75rem 0.25rem;
    padding: 0.5rem 0.875rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: none;
    color: var(--text-primary);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background .15s;
    flex-shrink: 0;
}
.sidebar-new-chat:hover { background: var(--bg-surface-2); }
.sidebar-new-chat svg   { flex-shrink: 0; }

/* Session list */
.sidebar-sessions {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 0.25rem 0;
    min-height: 0;
}

.sidebar-section-label {
    padding: 0.375rem 0.875rem 0.25rem;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-muted);
    flex-shrink: 0;
}
.sidebar-group-label {
    padding: 0.5rem 0.875rem 0.15rem;
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-muted);
    flex-shrink: 0;
    margin-top: 0.25rem;
}
.sidebar-group-label:first-child { margin-top: 0; }

.sidebar-session {
    position: relative;
    display: flex;
    align-items: center;
    padding: 0 0.375rem 0 0.75rem;
    border-radius: 8px;
    margin: 0 0.375rem;
    transition: background .12s;
}
.sidebar-session:hover { background: var(--bg-surface-2); }
.sidebar-session.active { background: var(--bg-surface-2); }

.sidebar-session-link {
    flex: 1;
    padding: 0.4rem 0.25rem 0.4rem 0.125rem;
    font-size: 0.8125rem;
    color: var(--text-primary);
    text-decoration: none;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    min-width: 0;
}
.sidebar-session.active .sidebar-session-link { color: var(--accent); font-weight: 500; }

.sidebar-session-actions {
    flex-shrink: 0;
    display: none;
    align-items: center;
}
.sidebar-session:hover .sidebar-session-actions { display: flex; }

.sidebar-session-btn {
    display: flex; align-items: center; justify-content: center;
    width: 26px; height: 26px;
    background: none; border: none; cursor: pointer;
    color: var(--text-muted); border-radius: 5px;
    transition: background .12s, color .12s;
    padding: 0;
}
.sidebar-session-btn:hover { background: var(--bg-surface-3, var(--border)); color: var(--text-primary); }

/* Session rename input */
.sidebar-session-rename {
    flex: 1;
    padding: 0.25rem 0.375rem;
    font-size: 0.8125rem;
    background: var(--bg-input, var(--bg-surface-2));
    border: 1px solid var(--accent);
    border-radius: 5px;
    color: var(--text-primary);
    outline: none;
    min-width: 0;
}

/* Sidebar nav footer */
.sidebar-footer {
    flex-shrink: 0;
    border-top: 1px solid var(--border);
    padding: 0.5rem 0;
}

.sidebar-user-footer {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.5rem 0.875rem;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-primary);
}
.sidebar-user-info  { flex: 1; display: flex; flex-direction: column; min-width: 0; gap: 1px; }
.sidebar-user-name  { font-size: 0.8125rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user-email { font-size: 0.7rem; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user-role  { font-size: 0.68rem; color: var(--accent); font-weight: 500; }

/* Bell button */
.bell-btn {
    display: flex; align-items: center; justify-content: center;
    width: 34px; height: 34px;
    background: none; border: none; cursor: pointer;
    color: var(--text-muted); border-radius: 8px;
    transition: background .15s, color .15s;
    position: relative;
}
.bell-btn:hover:not(:disabled) { background: var(--bg-surface-2); color: var(--text-primary); }
.bell-btn:disabled { opacity: 0.45; cursor: default; }

/* Hamburger: hidden on desktop */
.hamburger-btn {
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    width: 36px; height: 36px;
    background: none; border: none; cursor: pointer;
    padding: 6px; border-radius: 8px;
    color: var(--text-primary);
    transition: background .15s;
}
.hamburger-btn:hover { background: var(--bg-surface-2); }
.hamburger-btn span {
    display: block; width: 20px; height: 2px;
    background: currentColor; border-radius: 2px;
    transition: transform .2s, opacity .2s;
}

/* Sidebar backdrop: hidden on desktop */
.sidebar-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 299;
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s;
}
.sidebar-backdrop.visible { opacity: 1; pointer-events: auto; }

/* Sidebar brand: hidden on desktop */
.sidebar-brand { display: none; }

/* usage-dropdown-hidden: hides the dropdown on desktop when closed.
   Use !important to beat .usage-dropdown { display: flex } which has equal specificity but comes later. */
.usage-dropdown-hidden { display: none !important; }

/* ── Mobile sidebar ───────────────────────────────────────────────────────── */
@media (max-width: 640px) {
    .header-brand { flex: 1; }
    .header-pinned { margin-left: 0; }

    /* Show hamburger on mobile */
    .hamburger-btn { display: flex; }

    /* Show backdrop on mobile (invisible/non-interactive until .visible) */
    .sidebar-backdrop { display: block; pointer-events: none; }

    /* Sidebar becomes a fixed overlay panel on mobile */
    .app-sidebar {
        position: fixed;
        top: 0; left: 0;
        width: min(280px, 85vw);
        height: 100dvh;
        border-right: 1px solid var(--border);
        box-shadow: var(--shadow-md);
        z-index: 300;
        transform: translateX(-110%);
        transition: transform .25s cubic-bezier(.4,0,.2,1);
    }
    .app-sidebar.open { transform: translateX(0); }

    /* Sidebar brand: only visible on mobile */
    .sidebar-brand {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0.875rem 1rem;
        border-bottom: 1px solid var(--border);
        flex-shrink: 0;
    }
    .sidebar-close-btn {
        display: flex; align-items: center; justify-content: center;
        width: 32px; height: 32px;
        background: none; border: none; cursor: pointer;
        color: var(--text-muted); border-radius: 6px;
        transition: background .15s;
    }
    .sidebar-close-btn:hover { background: var(--bg-surface-2); }
}

/* ── Sidebar navigation links (visible on desktop + mobile) ─────────────── */
.sidebar-divider { height: 1px; background: var(--border); margin: 4px 0; flex-shrink: 0; }

.sidebar-link {
    display: flex; align-items: center; gap: 0.5rem;
    padding: 0.55rem 0.875rem;
    font-size: 0.875rem; color: var(--text-muted);
    text-decoration: none;
    border-radius: 8px;
    margin: 0 0.375rem;
    transition: background .1s, color .1s;
}
.sidebar-link:hover { background: var(--bg-surface-2); color: var(--text-primary); }

.sidebar-logout {
    display: flex; align-items: center; gap: 0.5rem;
    width: calc(100% - 0.75rem); margin: 0 0.375rem;
    padding: 0.55rem 0.5rem;
    font-size: 0.875rem; color: #ef4444;
    background: none; border: none; cursor: pointer;
    border-radius: 8px;
    transition: background .1s;
    text-align: left;
}
.sidebar-logout:hover { background: var(--bg-surface-2); }

.app-main {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* ── Header user menu ────────────────────────────────────────────────────── */
.header-user-menu { position: relative; }

.avatar-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 8px;
    color: var(--text-primary);
    transition: background .15s;
}
.avatar-btn:hover { background: var(--bg-surface-2); }

.header-username {
    font-size: 0.875rem;
    font-weight: 500;
    max-width: 140px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.chevron-icon {
    color: var(--text-muted);
    flex-shrink: 0;
    transition: transform .15s;
}
.chevron-icon.open { transform: rotate(180deg); }

.dropdown-backdrop {
    position: fixed;
    inset: 0;
    z-index: 110;
}

.user-dropdown {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow-md);
    min-width: 180px;
    z-index: 120;
    overflow: hidden;
    padding: 4px 0;
}

.user-dropdown a,
.user-dropdown button {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.55rem 1rem;
    font-size: 0.875rem;
    color: var(--text-primary);
    background: none;
    border: none;
    cursor: pointer;
    text-decoration: none;
    transition: background .1s;
}
.user-dropdown a:hover,
.user-dropdown button:hover { background: var(--bg-surface-2); }

.dropdown-divider {
    height: 1px;
    background: var(--border);
    margin: 4px 0;
}

.user-dropdown .btn-logout { color: #ef4444; }

/* ── Usage widget ────────────────────────────────────────────────────────── */

.usage-widget { position: relative; }

.usage-pill {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 0.3rem 0.65rem;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-primary);
    cursor: pointer;
    transition: background .15s, border-color .15s;
    white-space: nowrap;
}
.usage-pill:hover { background: var(--bg-surface-2); }
.usage-pill .usage-icon { color: var(--text-muted); flex-shrink: 0; }

.usage-dropdown {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow-md);
    width: 220px;
    z-index: 120;
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.usage-dropdown-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding-bottom: 0.25rem;
    border-bottom: 1px solid var(--border);
}

.usage-row { display: flex; flex-direction: column; gap: 0.3rem; }

.usage-row-label {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--text-primary);
}
.usage-count { color: var(--text-muted); font-variant-numeric: tabular-nums; }

.usage-bar-bg {
    height: 6px;
    background: var(--bg-surface-2);
    border-radius: 999px;
    overflow: hidden;
}
.usage-bar-fill {
    height: 100%;
    border-radius: 999px;
    background: var(--accent);
    transition: width .3s ease;
}
.usage-bar-fill.usage-bar-warn   { background: #f59e0b; }
.usage-bar-fill.usage-bar-danger { background: #ef4444; }

.usage-upgrade-btn {
    display: block;
    text-align: center;
    background: var(--accent);
    color: #fff;
    border-radius: 8px;
    padding: 0.45rem 0.75rem;
    font-size: 0.82rem;
    font-weight: 600;
    text-decoration: none;
    margin-top: 0.15rem;
    transition: opacity .15s;
}
.usage-upgrade-btn:hover { opacity: 0.88; }

/* ── Chat ────────────────────────────────────────────────────────────────── */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    max-width: 860px;
    width: 100%;
    margin: 0 auto;
}

/* ── Empty state: welcome centered ──────────────────────────────────────── */
.chat-container.chat-empty {
    justify-content: center;
    gap: 1.25rem;
    padding-bottom: 4rem;
}
.chat-container.chat-empty .chat-messages {
    display: none;
}
.chat-container.chat-empty .chat-input-bar {
    max-width: 700px;
    width: 100%;
    margin: 0 auto;
}

.chat-welcome {
    text-align: center;
    padding: 0 1rem;
    animation: fadeInUp 0.35s ease;
}
.chat-welcome-title {
    font-size: 2rem;
    font-weight: 700;
    margin: 0 0 0.4rem;
    color: var(--text-primary);
}
.chat-welcome-sub {
    font-size: 1rem;
    color: var(--text-secondary);
    margin: 0;
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    scroll-behavior: smooth;
}

/* Chat font variants */
.chat-messages.font-sans    { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }
.chat-messages.font-system  { font-family: system-ui, sans-serif; }
.chat-messages.font-dyslexic { font-family: 'OpenDyslexic', cursive; }

/* Chat size variants */
.chat-messages.size-medium .message-bubble { font-size: 1.05rem; }
.chat-messages.size-large  .message-bubble { font-size: 1.15rem; }

.message {
    display: flex;
    flex-direction: column;
    max-width: 75%;
}

.message-user  { align-self: flex-end;  align-items: flex-end; }
.message-bot   { align-self: flex-start; align-items: flex-start; }

.message-bubble {
    padding: 0.6rem 0.9rem;
    border-radius: 18px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 0.95rem;
}

/* Markdown content inside bot bubbles */
.message-markdown { white-space: normal; }
.message-markdown p  { margin: 0 0 0.4rem; }
.message-markdown p:last-child { margin-bottom: 0; }
.message-markdown ul, .message-markdown ol { margin: 0.25rem 0 0.4rem 1.25rem; padding: 0; }
.message-markdown li { margin-bottom: 0.1rem; }
.message-markdown code { background: var(--code-bg); border-radius: 4px; padding: 0.1em 0.35em; font-size: 0.88em; }
.message-markdown pre { background: var(--pre-bg); color: var(--pre-fg); border-radius: 8px; padding: 0.75rem 1rem; overflow-x: auto; margin: 0.4rem 0; }
.message-markdown pre code { background: none; padding: 0; color: inherit; font-size: 0.85em; }
.message-markdown h1,.message-markdown h2,.message-markdown h3 { font-weight: 600; margin: 0.5rem 0 0.25rem; line-height: 1.3; }
.message-markdown h1 { font-size: 1.1rem; }
.message-markdown h2 { font-size: 1rem; }
.message-markdown h3 { font-size: 0.95rem; }
.message-markdown strong { font-weight: 600; }
.message-markdown blockquote { border-left: 3px solid var(--border); margin: 0.4rem 0; padding-left: 0.75rem; color: var(--text-secondary); }

.message-user .message-bubble {
    background: var(--bubble-user-bg);
    color: var(--bubble-user-fg);
    border-bottom-right-radius: 4px;
}

.message-bot .message-bubble {
    background: var(--bubble-bot-bg);
    color: var(--bubble-bot-fg);
    border-bottom-left-radius: 4px;
    box-shadow: var(--shadow-card);
}

.message-time {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 3px;
    padding: 0 4px;
}

/* ── Typing indicator ────────────────────────────────────────────────────── */
.typing-indicator { display: flex; gap: 5px; align-items: center; padding: 0.7rem 1rem; }
.typing-indicator span { width: 8px; height: 8px; background: var(--text-muted); border-radius: 50%; animation: bounce 1.2s infinite; }
.typing-indicator span:nth-child(2) { animation-delay: .2s; }
.typing-indicator span:nth-child(3) { animation-delay: .4s; }

@keyframes bounce {
    0%, 80%, 100% { transform: translateY(0); }
    40%            { transform: translateY(-8px); }
}

/* ── Input bar ───────────────────────────────────────────────────────────── */
.chat-input-bar {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    background: var(--bg-surface);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.chat-input {
    flex: 1;
    resize: none;
    border: 1px solid var(--border-input);
    border-radius: 12px;
    padding: 0.6rem 0.9rem;
    font-size: 0.95rem;
    font-family: inherit;
    outline: none;
    max-height: 160px;
    overflow-y: auto;
    line-height: 1.5;
    background: var(--bg-surface);
    color: var(--text-primary);
    transition: border-color .15s;
}
.chat-input:focus { border-color: var(--accent); }

.btn-send {
    width: 42px; height: 42px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background .15s;
}
.btn-send:hover:not(:disabled)  { background: var(--accent-hover); }
.btn-send:disabled               { background: var(--accent-disabled); cursor: default; }

.btn-mic {
    position: relative;
    width: 38px; height: 38px;
    border-radius: 50%;
    background: transparent;
    color: var(--text-muted);
    border: 1.5px solid var(--border-input);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: color .15s, border-color .15s, background .15s;
}
.btn-mic:hover:not(:disabled) { color: var(--accent); border-color: var(--accent); }
.btn-mic:disabled              { opacity: .45; cursor: default; }
.btn-mic.recording             { color: #ef4444; border-color: #ef4444; background: rgba(239,68,68,.08); }
.btn-mic.recording::after {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid #ef4444;
    animation: mic-pulse 1.2s ease-out infinite;
    pointer-events: none;
}
@keyframes mic-pulse {
    0%   { transform: scale(1);   opacity: .7; }
    100% { transform: scale(1.6); opacity: 0;  }
}
.spin { animation: kibo-spin .8s linear infinite; }
@keyframes kibo-spin { to { transform: rotate(360deg); } }

/* ── Thinking steps ──────────────────────────────────────────────────────── */
.thinking-steps   { font-size: 0.78rem; color: var(--text-secondary); max-width: 100%; }
.thinking-summary { cursor: pointer; color: var(--text-muted); font-style: italic; }
.thinking-step    { padding: 2px 0 2px 6px; border-left: 2px solid var(--border); margin-top: 2px; }

/* ── Action trace ────────────────────────────────────────────────────────── */
.action-trace         { font-size: 0.8rem; margin-bottom: 0.25rem; }
.action-trace-summary {
    cursor: pointer; color: var(--fg-muted, #888); font-size: 0.8rem;
    list-style: none; display: inline-flex; align-items: center; gap: 0.3rem;
    -webkit-user-select: none; user-select: none;
}
.action-trace-row {
    display: flex; flex-wrap: wrap; align-items: baseline;
    gap: 0.3rem; padding: 0.18rem 0.5rem;
    border-left: 2px solid var(--border); margin: 0.15rem 0;
    font-family: ui-monospace, monospace;
}
.action-trace-error   { border-left-color: #e55; }
.action-trace-plugin  { color: var(--accent); font-weight: 600; font-size: 0.75rem; }
.action-trace-name    { color: var(--fg); font-size: 0.75rem; }
.action-trace-params  { color: var(--fg-muted, #888); font-size: 0.72rem; flex: 1; }
.action-trace-result  { color: var(--fg-muted, #888); font-size: 0.72rem; font-style: italic; }
.action-trace-error .action-trace-result { color: #e55; }

/* ── Choices (radio / checkbox) ─────────────────────────────────────────── */
.choices-group    { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.5rem; }
.choice-btn {
    background: var(--surface-alt, #f0f4ff);
    border: 1.5px solid var(--accent);
    border-radius: 999px;
    color: var(--accent);
    cursor: pointer;
    font-size: 0.88rem;
    padding: 0.3rem 0.85rem;
    transition: background 0.15s, color 0.15s;
}
.choice-btn:hover { background: var(--accent); color: #fff; }
.choice-btn:disabled { opacity: 0.45; cursor: not-allowed; }
.choice-btn-confirm { border-radius: 6px; font-weight: 600; }
.choice-check {
    display: flex; align-items: center; gap: 0.4rem;
    font-size: 0.88rem; cursor: pointer;
    background: var(--surface-alt, #f0f4ff);
    border: 1.5px solid var(--border);
    border-radius: 6px;
    padding: 0.3rem 0.7rem;
}
.choice-check:has(input:checked) { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }

/* ── Compose (email draft) ───────────────────────────────────────────────── */
.compose-group { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.5rem; max-width: 480px; }
.compose-meta  { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.85rem; color: var(--fg-muted, #888); padding: 0.4rem 0.6rem; background: var(--surface-alt, #f0f4ff); border-radius: 6px; }
.compose-body  { width: 100%; border: 1.5px solid var(--border); border-radius: 8px; padding: 0.6rem 0.8rem; font-size: 0.9rem; background: var(--surface); color: var(--fg); resize: vertical; font-family: inherit; line-height: 1.5; }
.compose-send  { align-self: flex-start; border-radius: 6px !important; font-weight: 600; }

/* ── Auth page ───────────────────────────────────────────────────────────── */
.auth-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100%;
    padding: 2rem 1rem;
}

.auth-card {
    background: var(--bg-surface);
    border-radius: 16px;
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow-md);
}

.auth-logo { text-align: center; margin-bottom: 1.75rem; }
.auth-logo-img { height: 56px; width: auto; }

.auth-divider {
    display: flex;
    align-items: center;
    gap: .75rem;
    margin: 1.25rem 0;
    color: var(--text-muted);
    font-size: .8rem;
}
.auth-divider::before,
.auth-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--border-color);
}

.btn-google {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-surface);
    border: 1.5px solid var(--border-color);
    color: var(--text-primary);
    border-radius: 8px;
    padding: .55rem 1rem;
    font-size: .9rem;
    font-weight: 500;
    text-decoration: none;
    transition: background .15s, border-color .15s;
}
.btn-google:hover {
    background: var(--bg-surface-2);
    border-color: var(--accent);
    color: var(--text-primary);
    text-decoration: none;
}

/* ── Settings page ───────────────────────────────────────────────────────── */
.settings-layout {
    display: flex;
    height: 100%;
    overflow: hidden;
}

.settings-sidebar {
    width: 220px;
    flex-shrink: 0;
    background: var(--bg-surface);
    border-right: 1px solid var(--border);
    padding: 1.5rem 0;
    overflow-y: auto;
}

.settings-sidebar-title {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-muted);
    padding: 0.5rem 1.25rem 0.25rem;
    margin-top: 0.75rem;
}
.settings-sidebar-title:first-child { margin-top: 0; }

.settings-nav-btn {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    padding: 0.55rem 1.25rem;
    font-size: 0.875rem;
    color: var(--text-primary);
    cursor: pointer;
    border-radius: 0;
    transition: background .1s;
}
.settings-nav-btn:hover  { background: var(--bg-surface-2); }
.settings-nav-btn.active { background: var(--bg-surface-2); color: var(--accent); font-weight: 500; }

.settings-content {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
}

.settings-section-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin: 0 0 1.5rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.settings-group {
    max-width: 520px;
    margin-bottom: 2rem;
}

.settings-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.35rem;
    color: var(--text-primary);
}

.settings-group .form-control {
    background: var(--bg-surface);
    border-color: var(--border-input);
    color: var(--text-primary);
}
.settings-group .form-control:focus { border-color: var(--accent); box-shadow: none; }

.settings-group .field-hint {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.settings-success { color: #16a34a; font-size: 0.875rem; margin-top: 0.5rem; }
.settings-error   { color: #dc2626; font-size: 0.875rem; margin-top: 0.5rem; }

.settings-toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    cursor: pointer;
    font-weight: 500;
}

/* Theme/font option cards */
.option-cards {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.option-card {
    border: 2px solid var(--border);
    border-radius: 10px;
    padding: 0.6rem 1rem;
    cursor: pointer;
    font-size: 0.875rem;
    background: var(--bg-surface);
    color: var(--text-primary);
    transition: border-color .15s, background .15s;
    min-width: 90px;
    text-align: center;
}
.option-card:hover   { border-color: var(--accent); }
.option-card.active  { border-color: var(--accent); background: var(--bg-surface-2); color: var(--accent); font-weight: 500; }

/* Theme visual preview cards */
.preview-cards {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.preview-card {
    border: 2px solid var(--border);
    border-radius: 12px;
    cursor: pointer;
    background: transparent;
    padding: 0;
    overflow: hidden;
    text-align: center;
    transition: border-color .15s, box-shadow .15s;
    display: flex;
    flex-direction: column;
}
.preview-card:hover  { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.preview-card.active { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }

.preview-card svg { display: block; width: 100px; height: 70px; }

.preview-card-label {
    font-size: .78rem;
    padding: .3rem .5rem .4rem;
    color: var(--text-primary);
    display: block;
    background: var(--bg-surface);
}
.preview-card.active .preview-card-label { color: var(--accent); font-weight: 600; }

/* Font preview cards */
.font-preview-aa {
    display: block;
    font-size: 2rem;
    line-height: 1;
    padding: .55rem .75rem .25rem;
    background: var(--bg-surface);
    color: var(--text-primary);
    min-width: 70px;
}
.font-preview-aa.font-sans     { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; }
.font-preview-aa.font-system   { font-family: system-ui, sans-serif; }
.font-preview-aa.font-dyslexic { font-family: 'OpenDyslexic', cursive; } /* loaded via kiboLoadFont */

/* Org ID copy box */
.copy-box {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--bg-surface-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    font-family: monospace;
    font-size: 0.85rem;
    color: var(--text-primary);
}
.copy-box button {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0;
    font-size: 0.8rem;
    transition: color .15s;
}
.copy-box button:hover { color: var(--accent); }

/* Placeholder sections */
.placeholder-section {
    padding: 2rem;
    background: var(--bg-surface-2);
    border: 1px dashed var(--border);
    border-radius: 12px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* ── Setup page ──────────────────────────────────────────────────────────── */
.setup-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 2rem 1rem;
    background: var(--bg-page);
}

.setup-card {
    background: var(--bg-surface);
    border-radius: 16px;
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 440px;
    box-shadow: var(--shadow-md);
}

.setup-card h2 { margin: 0 0 0.5rem; font-size: 1.3rem; }
.setup-card .subtitle { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 1.75rem; }

/* Wizard progress dots */
.wizard-progress {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    margin-bottom: 1.75rem;
}
.wizard-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--border);
    transition: background 0.2s, transform 0.2s;
    flex-shrink: 0;
}
.wizard-dot.active  { background: var(--accent); transform: scale(1.25); }
.wizard-dot.done    { background: var(--accent); opacity: 0.45; }
.wizard-line {
    flex: 1;
    height: 2px;
    background: var(--border);
    max-width: 28px;
}

/* Wizard role/referral option pills */
.wizard-options {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.5rem;
}
.wizard-option-pill {
    padding: 0.45rem 0.9rem;
    border-radius: 999px;
    border: 1.5px solid var(--border-color);
    background: transparent;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 0.875rem;
    transition: border-color 0.15s, background 0.15s;
}
.wizard-option-pill:hover,
.wizard-option-pill.selected {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 10%, transparent);
}

/* Wizard nav buttons */
.wizard-nav {
    display: flex;
    gap: 0.75rem;
    margin-top: 1.5rem;
}
.wizard-nav .btn { flex: 1; }

/* Welcome step icon */
.wizard-welcome-icon {
    font-size: 3rem;
    text-align: center;
    margin-bottom: 0.75rem;
}
.wizard-integration-prompt {
    background: var(--bg-page);
    border-radius: 10px;
    padding: 1rem;
    margin: 1rem 0;
    font-size: 0.9rem;
    color: var(--text-muted);
    text-align: center;
}

/* Wizard provider cards (connect step) */
.wizard-provider-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.5rem;
}
.wizard-provider-card {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 0.85rem;
    background: var(--bg-page);
    border-radius: 10px;
    border: 1px solid var(--border);
}
.wizard-provider-icon {
    width: 28px;
    height: 28px;
    object-fit: contain;
    flex-shrink: 0;
}
.wizard-provider-name {
    font-size: 0.9rem;
    font-weight: 500;
}

/* Wizard Welcome examples */
.wizard-welcome-examples {
    margin-top: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.wizard-welcome-try {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .04em;
    margin-bottom: 0.25rem;
}
.wizard-welcome-msg {
    display: block;
    padding: 0.55rem 0.85rem;
    background: var(--bg-page);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.9rem;
    color: var(--accent);
    text-decoration: none;
    transition: background 0.15s;
}
.wizard-welcome-msg:hover {
    background: var(--bg-hover, rgba(0,0,0,.05));
}

/* ── Blazor error UI ─────────────────────────────────────────────────────── */
#blazor-error-ui {
    background: #fff3cd;
    bottom: 0; left: 0;
    box-shadow: 0 -1px 2px rgba(0,0,0,.2);
    display: none;
    padding: 0.6rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
}
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; }

.admin-container { overflow: auto; }

/* ── Knowledge Graph page ─────────────────────────────────────────────────── */

.kg-layout {
    display:        flex;
    flex-direction: column;
    flex:           1;
    min-height:     0;
    overflow:       hidden;
    background:     var(--bg-page);
}

.kg-topbar {
    display:         flex;
    align-items:     center;
    gap:             .5rem;
    padding:         .5rem .75rem;
    background:      var(--bg-surface);
    border-bottom:   1px solid var(--border);
    flex-shrink:     0;
}

.kg-search-form {
    display:  flex;
    gap:      .4rem;
    flex:     1;
    max-width: 520px;
}

.kg-search-input { flex: 1; }

.kg-topbar-actions {
    display:     flex;
    gap:         .35rem;
    margin-left: auto;
}

/* Heatmap strip */
.kg-heatmap {
    display:         none;        /* shown by JS after first data load */
    flex-shrink:     0;
    background:      var(--bg-surface);
    border-bottom:   1px solid var(--border);
    padding:         7px 16px 5px;
    overflow-x:      auto;
    overflow-y:      hidden;
}

.kg-heatmap::-webkit-scrollbar          { height: 3px; }
.kg-heatmap::-webkit-scrollbar-thumb    { background: var(--border); border-radius: 2px; }

/* SVG text labels inside heatmap */
.kg-hm-label {
    font-family: monospace;
    font-size:   9px;
    fill:        var(--text-muted);
}

/* Heat level fills — 0 = empty, 1–4 = intensity */
.kg-hc-0 { fill: var(--border);  opacity: 0.5; }
.kg-hc-1 { fill: #3b82f6; opacity: 0.30; }
.kg-hc-2 { fill: #3b82f6; opacity: 0.55; }
.kg-hc-3 { fill: #3b82f6; opacity: 0.75; }
.kg-hc-4 { fill: #3b82f6; opacity: 1.00; }

.kg-body {
    display:  flex;
    flex:     1;
    overflow: hidden;
}

.kg-body-hidden { visibility: hidden; pointer-events: none; }

.kg-canvas {
    flex:       1;
    background: var(--bg-surface-2);
    min-width:  0;
}

/* Side panel */
.kg-panel {
    width:        280px;
    flex-shrink:  0;
    background:   var(--bg-surface);
    border-left:  1px solid var(--border);
    padding:      .85rem 1rem;
    overflow-y:   auto;
    display:      flex;
    flex-direction: column;
    gap:          .5rem;
}

.kg-panel-hint {
    justify-content: center;
    align-items:     center;
    color:           var(--text-muted);
    text-align:      center;
}

.kg-panel-header {
    display:     flex;
    align-items: center;
    gap:         .4rem;
}

.kg-type-badge {
    font-size:     .7rem;
    padding:       .2em .55em;
    border-radius: 10px;
    letter-spacing: .02em;
    text-transform: capitalize;
}

.kg-panel-header-text {
    font-weight:   600;
    font-size:     .92rem;
    color:         var(--text-primary);
    line-height:   1.35;
    word-break:    break-word;
}

.kg-attrs {
    background:    var(--bg-surface-2);
    border-radius: 6px;
    padding:       .4rem .6rem;
    display:       flex;
    flex-direction: column;
    gap:           .3rem;
}

.kg-attr-row {
    display:   flex;
    gap:       .5rem;
    font-size: .8rem;
    line-height: 1.3;
}

.kg-attr-key {
    color:       var(--text-muted);
    flex-shrink: 0;
    min-width:   72px;
    font-weight: 500;
}

.kg-attr-val {
    color:      var(--text-primary);
    word-break: break-word;
}

.kg-panel-meta {
    font-size: .75rem;
    color:     var(--text-muted);
}

/* Empty / zero-results state */
.kg-empty {
    flex:            1;
    display:         flex;
    flex-direction:  column;
    align-items:     center;
    justify-content: center;
    gap:             .6rem;
    color:           var(--text-muted);
    padding:         2rem;
}

.kg-empty-icon {
    font-size:   3rem;
    line-height: 1;
    opacity:     .35;
}

/* ── Knowledge Graph modal ───────────────────────────────────────────────── */

.kg-modal-overlay {
    position:        fixed;
    inset:           0;
    z-index:         1000;
    background:      rgba(0, 0, 0, .55);
    display:         flex;
    align-items:     center;
    justify-content: center;
    padding:         1rem;
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}

.kg-modal {
    display:        flex;
    flex-direction: column;
    width:          min(1100px, 96vw);
    height:         min(700px, 90vh);
    background:     var(--bg-surface);
    border-radius:  12px;
    box-shadow:     var(--shadow-md);
    overflow:       hidden;
}

.kg-modal-header {
    display:       flex;
    align-items:   center;
    gap:           .5rem;
    padding:       .55rem .75rem;
    border-bottom: 1px solid var(--border);
    flex-shrink:   0;
    background:    var(--bg-surface);
}

.kg-modal-body {
    display:  flex;
    flex:     1;
    min-height: 0;
    position: relative;
    overflow: hidden;
}

.kg-modal-empty {
    position: absolute;
    inset:    0;
    z-index:  1;
}

.kg-canvas-hidden {
    visibility:     hidden;
    pointer-events: none;
}

/* ── End Knowledge Graph ──────────────────────────────────────────────────── */

@font-face {
    font-family: 'OpenDyslexic';
    src: url('../assets/OpenDyslexic-Regular.otf') format('opentype');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: 'OpenDyslexic';
    src: url('../assets/OpenDyslexic-Bold.otf') format('opentype');
    font-weight: 700;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: 'OpenDyslexic';
    src: url('../assets/OpenDyslexic-Italic.otf') format('opentype');
    font-weight: 400;
    font-style: italic;
    font-display: swap;
}
@font-face {
    font-family: 'OpenDyslexic';
    src: url('../assets/OpenDyslexic-BoldItalic.otf') format('opentype');
    font-weight: 700;
    font-style: italic;
    font-display: swap;
}
