/* ── Theme variables ───────────────────────────────────────────────────── */
/* Values are space-separated rgb triplets so Tailwind v3's <alpha-value>
 * placeholder (rgb(var(--x) / <alpha-value>)) can apply opacity modifiers
 * like bg-donio-accent/50. Dark = default. */
:root, [data-theme="dark"] {
    --donio-bg:        26 27 35;     /* #1a1b23 */
    --donio-sidebar:   19 19 24;     /* #131318 */
    --donio-surface:   30 31 42;     /* #1e1f2a */
    --donio-border:    45 46 58;     /* #2d2e3a */
    --donio-input:     20 20 25;     /* #141419 */
    --donio-hover:     38 39 54;     /* #262736 */
    --donio-accent:    79 138 216;   /* #4F8AD8 */
    --donio-light:     107 163 232;  /* #6BA3E8 */
    --donio-muted:     107 114 128;  /* #6b7280 */
    --donio-text:      243 244 246;  /* #f3f4f6 — body */
    --donio-text-soft: 209 213 219;  /* #d1d5db — secondary */
    --donio-bubble-user: 38 39 54;   /* #262736 */
    --donio-bubble-user-border: 54 55 72; /* #363748 */
    --donio-code-bg:   15 16 23;     /* #0f1017 */
    --donio-code-border: 30 31 42;
    --donio-link:      107 163 232;
    --donio-strong:    255 255 255;
    --donio-em:        165 180 252;  /* #a5b4fc */
}

[data-theme="light"] {
    --donio-bg:        249 250 251;  /* #f9fafb */
    --donio-sidebar:   243 244 246;  /* #f3f4f6 */
    --donio-surface:   255 255 255;  /* #ffffff */
    --donio-border:    229 231 235;  /* #e5e7eb */
    --donio-input:     255 255 255;
    --donio-hover:     243 244 246;  /* #f3f4f6 */
    --donio-accent:    37 99 235;    /* #2563eb */
    --donio-light:     59 130 246;   /* #3b82f6 */
    --donio-muted:     107 114 128;  /* #6b7280 */
    --donio-text:      17 24 39;     /* #111827 */
    --donio-text-soft: 55 65 81;     /* #374151 */
    --donio-bubble-user: 224 235 255; /* light blue tint */
    --donio-bubble-user-border: 191 219 254;
    --donio-code-bg:   249 250 251;
    --donio-code-border: 229 231 235;
    --donio-link:      37 99 235;
    --donio-strong:    17 24 39;
    --donio-em:        59 7 100;
}

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

.sidebar-nav {
    transition: transform 0.25s ease, width 0.25s ease, opacity 0.2s ease;
    overflow: hidden;
}
/* Mobile (< 768px): sidebar is a fixed overlay; "hidden" slides off-screen
 * instead of collapsing width. md+ uses width-collapse so the main flexes. */
.sidebar-hidden {
    transform: translateX(-100%);
}
@media (min-width: 768px) {
    .sidebar-hidden {
        transform: none;
        width: 0 !important;
        padding: 0 !important;
        border: none !important;
        opacity: 0;
        pointer-events: none;
    }
    /* When the sidebar is collapsed in desktop the main expands to fill
     * the row, but the fixed open-button (top:3, left:3, ~36px square)
     * sits on top of the page content. Push <main> to the right so the
     * button has its own gutter and never overlaps page headings. */
    body.sidebar-collapsed main {
        padding-left: 3rem;
    }
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-radius: 0.5rem;
    color: rgb(var(--donio-text-soft));
    font-size: 0.8rem;
    transition: all 0.15s;
    cursor: pointer;
}
.nav-link:hover { background: rgb(var(--donio-hover)); color: rgb(var(--donio-text)); }
.nav-link.active { background: rgb(var(--donio-accent) / 0.15); color: rgb(var(--donio-light)); }

/* ── Suggestions ──────────────────────────────────────────────────────── */

.suggestion {
    padding: 0.5rem 1rem;
    border: 1px solid rgb(var(--donio-border));
    border-radius: 0.75rem;
    font-size: 0.8rem;
    color: rgb(var(--donio-text-soft));
    cursor: pointer;
    background: transparent;
    transition: all 0.15s;
}
.suggestion:hover { border-color: rgb(var(--donio-accent)); color: rgb(var(--donio-light)); background: rgb(var(--donio-accent) / 0.08); }

/* ── Chat bubbles ─────────────────────────────────────────────────────── */

.msg-user {
    background: rgb(var(--donio-bubble-user));
    border: 1px solid rgb(var(--donio-bubble-user-border));
    border-radius: 1.25rem 1.25rem 0.25rem 1.25rem;
    color: rgb(var(--donio-text));
}
.msg-assistant {
    background: transparent;
    border: none;
    border-radius: 0;
    font-size: 0.925rem;
    line-height: 1.7;
    color: rgb(var(--donio-text));
}

/* ── Markdown in assistant messages ───────────────────────────────────── */

.msg-assistant p { margin: 0 0 0.75rem; }
.msg-assistant p:last-child { margin-bottom: 0; }

/* Headers: clear descending hierarchy, h3 in donio-accent for visual pop */
.msg-assistant h1 {
    font-size: 1.35rem;
    font-weight: 700;
    color: rgb(var(--donio-strong));
    margin: 1.25rem 0 0.6rem;
    border-bottom: 1px solid rgb(var(--donio-border));
    padding-bottom: 0.5rem;
    letter-spacing: -0.01em;
}
.msg-assistant h2 {
    font-size: 1.15rem;
    font-weight: 700;
    color: rgb(var(--donio-text));
    margin: 1.1rem 0 0.5rem;
    letter-spacing: -0.01em;
}
.msg-assistant h3 {
    font-size: 1rem;
    font-weight: 600;
    color: rgb(var(--donio-light));
    margin: 0.95rem 0 0.4rem;
}
.msg-assistant h4 {
    font-size: 0.85rem;
    font-weight: 600;
    color: rgb(var(--donio-muted));
    margin: 0.8rem 0 0.3rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.msg-assistant h1:first-child,
.msg-assistant h2:first-child,
.msg-assistant h3:first-child,
.msg-assistant h4:first-child { margin-top: 0; }

/* Strong / em with real contrast */
.msg-assistant strong { color: rgb(var(--donio-strong)); font-weight: 700; }
.msg-assistant em { color: rgb(var(--donio-em)); font-style: italic; }

/* Lists with accent markers */
.msg-assistant ul, .msg-assistant ol {
    padding-left: 1.5rem;
    margin: 0.5rem 0 0.75rem;
}
.msg-assistant ul { list-style-type: disc; }
.msg-assistant ol { list-style-type: decimal; }
.msg-assistant ul > li::marker { color: rgb(var(--donio-light)); }
.msg-assistant ol > li::marker { color: rgb(var(--donio-light)); font-weight: 600; }
.msg-assistant li { margin-bottom: 0.35rem; line-height: 1.65; }
.msg-assistant li > ul, .msg-assistant li > ol { margin: 0.25rem 0 0.25rem; }
.msg-assistant li > p { margin: 0; }
.msg-assistant li:last-child { margin-bottom: 0; }

/* Code blocks */
.msg-assistant pre {
    background: rgb(var(--donio-code-bg));
    border: 1px solid rgb(var(--donio-code-border));
    border-radius: 0.5rem;
    padding: 0.875rem;
    overflow-x: auto;
    margin: 0.75rem 0;
    position: relative;
}
.msg-assistant code {
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.8rem;
}
.msg-assistant :not(pre) > code {
    background: rgb(var(--donio-accent) / 0.12);
    border: 1px solid rgb(var(--donio-accent) / 0.18);
    color: rgb(var(--donio-light));
    padding: 0.1rem 0.4rem;
    border-radius: 0.25rem;
    font-size: 0.85em;
}

/* Blockquote with subtle background */
.msg-assistant blockquote {
    border-left: 3px solid rgb(var(--donio-accent));
    background: rgb(var(--donio-accent) / 0.06);
    padding: 0.5rem 0.875rem;
    margin: 0.75rem 0;
    border-radius: 0 0.375rem 0.375rem 0;
    color: rgb(var(--donio-text-soft));
}
.msg-assistant blockquote > p:last-child { margin-bottom: 0; }

/* Tables with highlighted header */
.msg-assistant table {
    border-collapse: collapse;
    width: 100%;
    margin: 0.875rem 0;
    font-size: 0.85rem;
    border-radius: 0.5rem;
    overflow: hidden;
    border: 1px solid rgb(var(--donio-border));
}
.msg-assistant th {
    background: rgb(var(--donio-accent) / 0.15);
    color: rgb(var(--donio-text));
    padding: 0.55rem 0.75rem;
    text-align: left;
    font-weight: 700;
    border-bottom: 2px solid rgb(var(--donio-accent));
}
.msg-assistant td {
    padding: 0.5rem 0.75rem;
    border-top: 1px solid rgb(var(--donio-border));
}
.msg-assistant tr:nth-child(even) td { background: rgb(var(--donio-muted) / 0.05); }

/* hr with subtle gradient */
.msg-assistant hr {
    border: none;
    height: 1px;
    background: linear-gradient(to right, transparent, rgb(var(--donio-border)), transparent);
    margin: 1.25rem 0;
}

/* Links */
.msg-assistant a {
    color: rgb(var(--donio-link));
    text-decoration: none;
    border-bottom: 1px solid rgb(var(--donio-link) / 0.35);
    transition: border-color 0.15s, color 0.15s;
}
.msg-assistant a:hover { color: rgb(var(--donio-light)); border-bottom-color: rgb(var(--donio-light)); }

/* del / kbd */
.msg-assistant del { color: rgb(var(--donio-muted)); text-decoration: line-through; }
.msg-assistant kbd {
    background: rgb(var(--donio-hover));
    border: 1px solid rgb(var(--donio-border));
    border-bottom-width: 2px;
    border-radius: 0.25rem;
    padding: 0.1rem 0.4rem;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.8em;
    color: rgb(var(--donio-text));
}

/* ── Module browser ───────────────────────────────────────────────────── */

.module-item {
    padding: 0.375rem 0.625rem;
    border-radius: 0.25rem;
    cursor: pointer;
    font-size: 0.8rem;
    transition: background 0.15s;
    color: rgb(var(--donio-text-soft));
}
.module-item:hover { background: rgb(var(--donio-hover)); }
.module-item.active { background: rgb(var(--donio-accent) / 0.15); color: rgb(var(--donio-light)); }

/* ── Chat history sidebar ─────────────────────────────────────────────── */

.history-item {
    display: block;
    padding: 0.375rem 0.625rem;
    border-radius: 0.5rem;
    font-size: 0.75rem;
    color: rgb(var(--donio-text-soft));
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background 0.15s;
}
.history-item:hover { background: rgb(var(--donio-hover)); color: rgb(var(--donio-text)); }
.history-item.active { color: rgb(var(--donio-light)); background: rgb(var(--donio-accent) / 0.12); }

/* ── History date group labels ────────────────────────────────────────── */

.history-group-label {
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: rgb(var(--donio-muted));
    padding: 0.5rem 0.625rem 0.25rem;
    margin-top: 0.375rem;
}
.history-group-label:first-child { margin-top: 0; }

/* ── Thinking area — visible during streaming ─────────────────────────── */

.thinking-area {
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid rgb(var(--donio-border));
}
.thinking-area:empty { display: none; margin: 0; padding: 0; border: none; }
.thinking-step {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: rgb(var(--donio-accent));
    font-size: 0.8rem;
    padding: 0.25rem 0;
}
.thinking-dot {
    width: 7px; height: 7px;
    background: rgb(var(--donio-accent));
    border-radius: 50%;
    flex-shrink: 0;
    animation: pulse 1.5s ease-in-out infinite;
}
.thinking-area.done .thinking-dot { animation: none; opacity: 0.5; }
.thinking-area.done .thinking-step { color: rgb(var(--donio-muted)); }
@keyframes pulse {
    0%, 100% { opacity: 0.3; transform: scale(0.8); }
    50% { opacity: 1; transform: scale(1.2); }
}

/* ── Content area — hidden during streaming, shown on done or toggle ── */

.content-area { display: none; }
.content-area.show { display: block; }

/* ── Message entrance animation ───────────────────────────────────────── */

.msg-enter { animation: msgEnter 0.2s ease-out; }
@keyframes msgEnter {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── Composer ─────────────────────────────────────────────────────────── */

.composer:focus-within { border-color: rgb(var(--donio-accent) / 0.4); }
#chatInput { min-height: 28px; max-height: 160px; transition: height 0.1s ease; line-height: 1.5; color: rgb(var(--donio-text)); }
#chatInput::placeholder, #chatInputWelcome::placeholder { color: rgb(var(--donio-muted)); }
#chatInputWelcome { color: rgb(var(--donio-text)); }

/* ── Code block header bar ────────────────────────────────────────────── */

.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.25rem 0.5rem;
    margin: -0.875rem -0.875rem 0.5rem -0.875rem;
    border-bottom: 1px solid rgb(var(--donio-code-border));
    font-size: 0.7rem;
}
.code-lang {
    color: rgb(var(--donio-muted));
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.copy-btn {
    color: rgb(var(--donio-muted));
    padding: 0.25rem;
    border-radius: 0.25rem;
    cursor: pointer;
    background: transparent;
    border: none;
    transition: color 0.15s;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}
.copy-btn:hover { color: rgb(var(--donio-text)); }

/* ── Scroll-to-bottom pill ────────────────────────────────────────────── */

.scroll-pill {
    position: absolute;
    bottom: 6rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 10;
}

/* ── Graph fullscreen ─────────────────────────────────────────────────── */

.graph-panel.fullscreen {
    position: fixed;
    inset: 0;
    width: 100% !important;
    z-index: 50;
    background: rgb(var(--donio-bg));
    border: none !important;
}

/* ── Mobile tweaks ────────────────────────────────────────────────────── */
@media (max-width: 767px) {
    /* Tighten chat padding so messages get more horizontal room */
    #messages { padding: 0.75rem 0.875rem !important; }
    /* Composer max-width is already 3xl; on mobile drop to full width */
    .max-w-3xl { max-width: 100% !important; }
    /* Larger touch targets for thumbs/copy buttons */
    .feedback-btn { width: 1.85rem; height: 1.85rem; }
}

/* ── Pygments monokai theme ───────────────────────────────────────────── */

.msg-assistant .highlight { background: #0f1017; border: 1px solid #1e1f2a; border-radius: 0.5rem; padding: 0.875rem; overflow-x: auto; margin: 0.625rem 0; }
.msg-assistant .highlight pre { margin: 0; background: transparent; border: none; padding: 0; }
.msg-assistant .highlight code { font-family: 'JetBrains Mono', 'Fira Code', monospace; font-size: 0.8rem; }
.highlight .hll { background-color: #49483e }
.highlight .c { color: #959077 }
.highlight .k { color: #66D9EF }
.highlight .l { color: #AE81FF }
.highlight .n { color: #F8F8F2 }
.highlight .o { color: #FF4689 }
.highlight .p { color: #F8F8F2 }
.highlight .ch,.highlight .cm,.highlight .cp,.highlight .cpf,.highlight .c1,.highlight .cs { color: #959077 }
.highlight .gd { color: #FF4689 }
.highlight .gi { color: #A6E22E }
.highlight .ge { font-style: italic }
.highlight .gs { font-weight: bold }
.highlight .kc,.highlight .kd,.highlight .kp,.highlight .kr,.highlight .kt { color: #66D9EF }
.highlight .kn { color: #FF4689 }
.highlight .m,.highlight .mb,.highlight .mf,.highlight .mh,.highlight .mi,.highlight .mo,.highlight .il { color: #AE81FF }
.highlight .s,.highlight .sa,.highlight .sb,.highlight .sc,.highlight .dl,.highlight .sd,.highlight .s2,.highlight .sh,.highlight .si,.highlight .sx,.highlight .sr,.highlight .s1,.highlight .ss { color: #E6DB74 }
.highlight .se { color: #AE81FF }
.highlight .na { color: #A6E22E }
.highlight .nc,.highlight .nd,.highlight .ne,.highlight .nf,.highlight .nx,.highlight .fm { color: #A6E22E }
.highlight .nt { color: #FF4689 }
.highlight .ow { color: #FF4689 }
.highlight .w { color: #F8F8F2 }

/* ── Streaming markdown cursor + highlight.js override ────────────────── */

.content-area.streaming > *:last-child::after {
    content: '▊';
    display: inline-block;
    margin-left: 2px;
    color: #4F8AD8;
    opacity: 0.8;
    animation: donio-blink 1s steps(2) infinite;
    vertical-align: baseline;
}
@keyframes donio-blink { 50% { opacity: 0; } }

.content-area pre code.hljs {
    background: transparent;
    padding: 0;
}

/* ── Feedback buttons (thumbs in metadata bar) ────────────────────────── */

.feedback-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.625rem;
    height: 1.625rem;
    border-radius: 0.375rem;
    border: 1px solid transparent;
    background: transparent;
    color: #6b7280;
    cursor: pointer;
    transition: all 0.15s;
    padding: 0;
}
.feedback-btn:hover { background: #262736; color: #e5e7eb; }
.feedback-btn.feedback-active {
    background: rgba(79,138,216,0.18);
    color: #6BA3E8;
    border-color: rgba(79,138,216,0.35);
}
.feedback-btn.feedback-neg.feedback-active {
    background: rgba(220,38,38,0.18);
    color: #f87171;
    border-color: rgba(220,38,38,0.35);
}

/* ── Feedback modal ───────────────────────────────────────────────────── */

.modal-backdrop {
    backdrop-filter: blur(2px);
}
.modal-backdrop.hidden { display: none !important; }
.modal-backdrop.flex { display: flex; }

.feedback-rating-btn {
    color: #9ca3af;
    transition: all 0.15s;
    background: transparent;
    cursor: pointer;
}
.feedback-rating-btn:hover {
    background: #262736;
    color: #e5e7eb;
}
.feedback-rating-btn.feedback-active {
    background: rgba(79,138,216,0.18);
    color: #6BA3E8;
    border-color: rgba(79,138,216,0.4);
}

.category-chip {
    cursor: pointer;
    background: transparent;
}
.category-chip.feedback-active {
    background: rgba(79,138,216,0.18);
    color: #6BA3E8;
    border-color: rgba(79,138,216,0.4);
}
.category-chip-pos.feedback-active {
    background: rgba(34,197,94,0.18);
    color: #4ade80;
    border-color: rgba(34,197,94,0.4);
}
.category-chip-neg.feedback-active {
    background: rgba(220,38,38,0.18);
    color: #f87171;
    border-color: rgba(220,38,38,0.4);
}

/* ── RAG Context drawer ─────────────────────────────────────────────────
   Right-side slide-in panel that shows what the agent consulted to generate
   a response. Built once via ensureContextDrawer() in chat.js, populated
   from messageContextMap (per-message) or consolidateConversationContext
   (whole conversation). */
.context-drawer {
    position: fixed;
    inset: 0;
    z-index: 60;            /* above the feedback modal (z-50) */
    pointer-events: none;
}
.context-drawer.hidden { display: none !important; }

.context-drawer-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(2px);
    pointer-events: auto;
    animation: ctxFade 0.18s ease-out;
}

.context-drawer-panel {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-width: 100%;
    background: rgb(var(--donio-surface));
    border-left: 1px solid rgb(var(--donio-border));
    box-shadow: -8px 0 24px rgba(0,0,0,0.4);
    display: flex;
    flex-direction: column;
    pointer-events: auto;
    animation: ctxSlideIn 0.22s ease-out;
}
@media (min-width: 768px) {
    .context-drawer-panel { width: 48vw; max-width: 720px; }
}

@keyframes ctxFade {
    from { opacity: 0; }
    to   { opacity: 1; }
}
@keyframes ctxSlideIn {
    from { transform: translateX(100%); }
    to   { transform: translateX(0); }
}

/* Tabs */
.ctx-tab {
    background: transparent;
    border: 1px solid rgb(var(--donio-border));
    border-bottom: none;
    color: #9ca3af;
    padding: 6px 12px;
    border-radius: 8px 8px 0 0;
    font-size: 12px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: color 0.15s, background 0.15s;
}
.ctx-tab:hover {
    color: #e5e7eb;
    background: rgb(var(--donio-hover));
}
.ctx-tab-active {
    color: #6BA3E8;
    background: rgb(var(--donio-hover));
    border-color: rgba(79,138,216,0.35);
}
.ctx-tab-count {
    background: rgba(79,138,216,0.18);
    color: #6BA3E8;
    border-radius: 999px;
    padding: 1px 7px;
    font-size: 10px;
    min-width: 18px;
    text-align: center;
}

.ctx-pane {
    background: rgb(var(--donio-input));
    border-top: 1px solid rgba(79,138,216,0.35);
    margin-top: -1px;
}

/* Vector chunk rows */
.ctx-chunk {
    background: rgb(var(--donio-surface));
    border: 1px solid rgb(var(--donio-border));
    border-radius: 8px;
    padding: 10px 12px;
    transition: border-color 0.15s;
}
.ctx-chunk:hover { border-color: rgba(79,138,216,0.4); }

.ctx-score-badge {
    display: inline-block;
    min-width: 44px;
    text-align: center;
    font-variant-numeric: tabular-nums;
    font-size: 11px;
    font-weight: 600;
    padding: 3px 6px;
    border-radius: 6px;
    border: 1px solid;
}
.ctx-score-high {
    background: rgba(34,197,94,0.15);
    color: #4ade80;
    border-color: rgba(34,197,94,0.4);
}
.ctx-score-mid {
    background: rgba(245,158,11,0.15);
    color: #fbbf24;
    border-color: rgba(245,158,11,0.4);
}
.ctx-score-low {
    background: rgba(107,114,128,0.15);
    color: #9ca3af;
    border-color: rgba(107,114,128,0.4);
}

.ctx-doctype-chip {
    display: inline-block;
    font-size: 10px;
    padding: 1px 6px;
    border-radius: 999px;
    background: rgba(79,138,216,0.15);
    color: #93c5fd;
    border: 1px solid rgba(79,138,216,0.3);
    text-transform: lowercase;
}

#ctxGraphContainer {
    background: rgb(var(--donio-input));
}

/* ── Tutorial artifact panel (sidebar lateral) ─────────────────────── */
/* El panel vive fijo a la derecha. Cuando body tiene .tutorial-panel-open
   los mensajes del chat se encogen para dejarle espacio. */
/* Panel fixed a la derecha; el layout principal se corre con padding-right
   en body (una sola declaración) en vez de margin-right en múltiples hijos
   — así no hay compounding accidental. */
.tutorial-panel {
    position: fixed;
    top: 0; right: 0; bottom: 0;
    width: min(720px, 42vw);
    min-width: 520px;
    background: #1a1725;
    border-left: 1px solid rgba(128, 81, 161, 0.28);
    box-shadow: -10px 0 30px rgba(0,0,0,0.45);
    transform: translateX(100%);
    transition: transform 220ms ease;
    z-index: 40;
    display: flex;
    flex-direction: column;
    color: #e7e3ef;
}
.tutorial-panel.open { transform: translateX(0); }

body.tutorial-panel-open {
    /* Empuja TODO el flex principal (sidebar + main) a la izquierda del
       panel. body ya es `h-screen flex`; con padding-right los flex-items
       redistribuyen su espacio sin necesidad de tocar margin en cada hijo. */
    padding-right: min(720px, 42vw);
    transition: padding-right 220ms ease;
}

/* Con el panel abierto el `max-w-3xl mx-auto` deja aire a ambos lados
   de las bubbles. Removemos el auto-centrado (mx-auto=0) y la cota
   superior (max-w-3xl=none) para que el wrapper use toda la columna.
   Las bubbles respetan su max-w propio: user=80% pegada a la derecha
   (flex justify-end), assistant=90% al izquierdo. */
body.tutorial-panel-open #messages > .max-w-3xl,
body.tutorial-panel-open #chatBar > form.max-w-3xl {
    max-width: none !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
}

@media (max-width: 900px) {
    .tutorial-panel { width: 92vw; min-width: 0; }
    body.tutorial-panel-open {
        padding-right: 0;  /* overlay en mobile */
    }
}

.tutorial-panel-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    border-bottom: 1px solid rgba(128, 81, 161, 0.22);
    background: linear-gradient(180deg, #2a2340 0%, #1a1725 100%);
    flex-shrink: 0;
}
.tutorial-panel-title {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.tutorial-panel-title .label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: #a692c7;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 6px;
}
.tutorial-panel-title .label::before {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #c9a5ff;
    box-shadow: 0 0 8px rgba(201, 165, 255, 0.6);
}
.tutorial-panel-title .tutorial-intent {
    font-size: 15px;
    color: #f8f5ff;
    font-weight: 500;
    line-height: 1.35;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.tutorial-panel-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}
.tutorial-status {
    font-size: 11px;
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(128, 81, 161, 0.22);
    color: #d6c6f0;
    white-space: nowrap;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}
.tutorial-status[data-phase="done"]    { background: rgba(34,197,94,0.20);  color: #7ee0a1; }
.tutorial-status[data-phase="error"]   { background: rgba(239,68,68,0.22);  color: #ff9b9b; }
.tutorial-status[data-phase="starting"],
.tutorial-status[data-phase="launching_browser"],
.tutorial-status[data-phase="logged_in"] { background: rgba(234,179,8,0.20); color: #ffd966; }

.tutorial-close {
    background: transparent;
    border: none;
    color: #a598c0;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    width: 30px;
    height: 30px;
    display: grid;
    place-items: center;
    border-radius: 6px;
    transition: background 120ms ease, color 120ms ease;
}
.tutorial-close:hover { background: rgba(128, 81, 161, 0.25); color: #fff; }

.tutorial-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 18px 20px 28px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    scroll-behavior: smooth;
}
.tutorial-panel-body::-webkit-scrollbar { width: 8px; }
.tutorial-panel-body::-webkit-scrollbar-track { background: transparent; }
.tutorial-panel-body::-webkit-scrollbar-thumb {
    background: rgba(128, 81, 161, 0.25);
    border-radius: 4px;
}
.tutorial-panel-body::-webkit-scrollbar-thumb:hover { background: rgba(128, 81, 161, 0.4); }

.tutorial-narration {
    font-size: 13px;
    line-height: 1.55;
    color: #d6c6f0;
    font-style: italic;
    padding: 12px 14px;
    background: rgba(128, 81, 161, 0.08);
    border-radius: 10px;
    border-left: 3px solid #8b5fbf;
    min-height: 0;
}
.tutorial-narration:empty { display: none; }

/* ── Diátaxis prose sections (preamble + epilogue alrededor del carrusel) ─ */
.tutorial-preamble,
.tutorial-epilogue {
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.tutorial-preamble:empty,
.tutorial-epilogue:empty { display: none; }

.prose-section {
    background: rgba(128, 81, 161, 0.06);
    border: 1px solid rgba(128, 81, 161, 0.18);
    border-radius: 10px;
    padding: 12px 14px;
    animation: tut-fadein 260ms cubic-bezier(0.2, 0.7, 0.3, 1);
}
.prose-section h4 {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #b596d8;
    margin: 0 0 8px 0;
}
.prose-section p {
    font-size: 13px;
    line-height: 1.55;
    color: #d6c6f0;
    margin: 0 0 8px 0;
}
.prose-section p:last-child { margin-bottom: 0; }
.prose-section ul {
    font-size: 12px;
    line-height: 1.5;
    color: #c5b3e0;
    margin: 0;
    padding-left: 18px;
}
.prose-section ul li { margin-bottom: 4px; }
.prose-section ul li:last-child { margin-bottom: 0; }
.prose-section code {
    background: rgba(128, 81, 161, 0.15);
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 11px;
    color: #d6c6f0;
}
.prose-section strong { color: #e5d7f5; }
.prose-tags {
    font-size: 11px;
    color: #b596d8;
    margin-top: 6px;
}
.prose-tags strong { color: #c5a3e8; }

.tutorial-steps {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

/* ── v3 grouped: group card con header + narración + carrusel ─────── */
.tutorial-group {
    background: linear-gradient(180deg, #231c34 0%, #1e1828 100%);
    border: 1px solid rgba(128, 81, 161, 0.22);
    border-radius: 12px;
    padding: 14px;
    animation: tut-fadein 260ms cubic-bezier(0.2, 0.7, 0.3, 1);
}
.tutorial-group-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
}
.tutorial-group-header .idx {
    font-size: 11px;
    font-weight: 700;
    color: #c9a5ff;
    padding: 2px 8px;
    background: rgba(128, 81, 161, 0.18);
    border-radius: 6px;
    white-space: nowrap;
    letter-spacing: 0.02em;
}
.tutorial-group-header .tgroup-title {
    flex: 1;
    color: #f2eefb;
    font-size: 14px;
    font-weight: 500;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.tutorial-group-header .tgroup-status {
    font-size: 11px;
    color: #9a8cb5;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(128, 81, 161, 0.12);
    white-space: nowrap;
}
.tutorial-group-header .tgroup-status[data-state="running"] { color: #ffda6b; background: rgba(234,179,8,0.15); }
.tutorial-group-header .tgroup-status[data-state="done"]    { color: #7ee0a1; background: rgba(34,197,94,0.15); }
.tutorial-group-header .tgroup-status[data-state="error"]   { color: #ff9b9b; background: rgba(239,68,68,0.18); }

.tutorial-group-narration {
    font-size: 13px;
    color: #d6c6f0;
    line-height: 1.5;
    margin-bottom: 10px;
    font-style: italic;
    padding-left: 8px;
    border-left: 2px solid rgba(128, 81, 161, 0.35);
}
.tutorial-group-narration:empty { display: none; }

/* Carrusel: viewport oculta overflow, track se translada en X */
.tutorial-carousel {
    position: relative;
    background: #16111f;
    border-radius: 10px;
    overflow: hidden;
}
.tutorial-carousel-empty {
    padding: 32px 16px;
    text-align: center;
    color: #7e6fa1;
    font-size: 12px;
    font-style: italic;
}
.tutorial-carousel[data-state="done"] .tutorial-carousel-empty { display: none; }
.tutorial-carousel-viewport {
    display: flex;
    transition: transform 320ms cubic-bezier(0.2, 0.7, 0.3, 1);
}
.tc-slide {
    flex: 0 0 100%;
    min-width: 0;
    padding: 10px;
}
.tc-slide-sublabel {
    margin-top: 8px;
    font-size: 12.5px;
    color: #d6c6f0;
    line-height: 1.45;
    padding: 6px 10px;
    background: rgba(128, 81, 161, 0.10);
    border-radius: 6px;
}
.tc-slide-missing {
    padding: 32px;
    text-align: center;
    color: #7e6fa1;
    font-size: 12px;
}

/* Nav: prev/next + dots */
.tutorial-carousel-nav {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 8px 10px 10px;
    border-top: 1px solid rgba(128, 81, 161, 0.15);
}
.tc-prev, .tc-next {
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    background: rgba(128, 81, 161, 0.12);
    border: 1px solid rgba(128, 81, 161, 0.25);
    border-radius: 6px;
    color: #c9bcdf;
    font-size: 16px;
    cursor: pointer;
    transition: background 120ms ease, color 120ms ease;
}
.tc-prev:hover, .tc-next:hover {
    background: rgba(128, 81, 161, 0.28);
    color: #fff;
}
.tc-prev[disabled], .tc-next[disabled] {
    opacity: 0.3;
    cursor: not-allowed;
}
.tutorial-carousel-dots {
    display: flex;
    gap: 6px;
    flex: 1;
    justify-content: center;
}
.tc-dot {
    width: 8px;
    height: 8px;
    border: 0;
    padding: 0;
    border-radius: 50%;
    background: rgba(128, 81, 161, 0.25);
    cursor: pointer;
    transition: background 120ms ease, transform 120ms ease;
}
.tc-dot:hover { background: rgba(128, 81, 161, 0.45); }
.tc-dot.active {
    background: #c9a5ff;
    transform: scale(1.25);
}
.tutorial-step {
    background: linear-gradient(180deg, #231c34 0%, #1e1828 100%);
    border: 1px solid rgba(128, 81, 161, 0.22);
    border-radius: 12px;
    padding: 14px;
    animation: tut-fadein 260ms cubic-bezier(0.2, 0.7, 0.3, 1);
    position: relative;
}
@keyframes tut-fadein {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
.tutorial-step-caption {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    color: #9a8cb5;
    margin-bottom: 8px;
}
.tutorial-step-caption .idx {
    font-weight: 700;
    color: #c9a5ff;
    font-size: 13px;
    letter-spacing: 0.02em;
}
.tutorial-step-caption .tool {
    font-family: ui-monospace, "SF Mono", Menlo, monospace;
    font-size: 10px;
    background: rgba(128, 81, 161, 0.18);
    color: #d6c6f0;
    padding: 3px 8px;
    border-radius: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 60%;
}
.tutorial-step-narration {
    font-size: 13.5px;
    color: #e7dff7;
    margin-bottom: 10px;
    line-height: 1.5;
}
.tutorial-thumb-wrap {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    background: #0f0b17;
    box-shadow: 0 2px 8px rgba(0,0,0,0.28);
}
.tutorial-thumb {
    display: block;
    width: 100%;
    max-height: 320px;
    object-fit: cover;
    object-position: top;
    cursor: zoom-in;
    transition: transform 280ms ease;
}
.tutorial-thumb-wrap:hover .tutorial-thumb { transform: scale(1.01); }
.tutorial-thumb-wrap::after {
    content: '⛶';
    position: absolute;
    right: 8px;
    top: 8px;
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    background: rgba(0,0,0,0.55);
    color: #fff;
    border-radius: 6px;
    font-size: 14px;
    opacity: 0;
    transition: opacity 180ms ease;
    pointer-events: none;
}
.tutorial-thumb-wrap:hover::after { opacity: 1; }

/* Lightbox (click en thumb → fullscreen) */
.tutorial-lightbox {
    position: fixed;
    inset: 0;
    background: rgba(10, 7, 18, 0.92);
    z-index: 60;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 4vh 4vw;
    cursor: zoom-out;
    animation: tut-fadein 180ms ease;
}
.tutorial-lightbox.open { display: flex; }
.tutorial-lightbox img {
    max-width: 100%;
    max-height: 100%;
    border-radius: 8px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.6);
    object-fit: contain;
}
.tutorial-lightbox-close {
    position: absolute;
    top: 16px;
    right: 20px;
    width: 36px;
    height: 36px;
    display: grid;
    place-items: center;
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 8px;
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    backdrop-filter: blur(8px);
}
.tutorial-lightbox-close:hover { background: rgba(255,255,255,0.2); }
.tutorial-lightbox-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 44px;
    height: 60px;
    display: grid;
    place-items: center;
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.18);
    border-radius: 8px;
    color: #fff;
    font-size: 22px;
    cursor: pointer;
    backdrop-filter: blur(8px);
    transition: background 120ms ease;
}
.tutorial-lightbox-nav:hover { background: rgba(255,255,255,0.2); }
.tutorial-lightbox-nav.prev { left: 20px; }
.tutorial-lightbox-nav.next { right: 20px; }
.tutorial-lightbox-nav[disabled] { opacity: 0.3; cursor: not-allowed; }
.tutorial-lightbox-counter {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    padding: 6px 14px;
    background: rgba(0,0,0,0.6);
    color: #fff;
    border-radius: 999px;
    font-size: 12px;
    backdrop-filter: blur(8px);
}

/* Link inline debajo del assistant_msg: "Ver tutorial" */
.tutorial-reopen {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
    padding: 6px 12px;
    background: linear-gradient(135deg, rgba(128, 81, 161, 0.18) 0%, rgba(128, 81, 161, 0.10) 100%);
    border: 1px solid rgba(128, 81, 161, 0.35);
    border-radius: 999px;
    color: #d7beff;
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    transition: all 160ms ease;
}
.tutorial-reopen:hover {
    background: linear-gradient(135deg, rgba(128, 81, 161, 0.38) 0%, rgba(128, 81, 161, 0.22) 100%);
    color: #fff;
    border-color: rgba(128, 81, 161, 0.55);
}
