/* LexDom — guía interactiva / tutorial */

body.ld-tutorial-active {
    overflow: hidden;
}

.ld-tutorial-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    z-index: 99990;
    pointer-events: auto;
}

.ld-tutorial-spotlight {
    position: fixed;
    border-radius: 14px;
    box-shadow: 0 0 0 9999px rgba(15, 23, 42, 0.55);
    background: transparent;
    pointer-events: none;
    transition: top 0.2s ease, left 0.2s ease, width 0.2s ease, height 0.2s ease;
    z-index: 99991;
}

.ld-tutorial-popover {
    position: fixed;
    z-index: 99992;
    width: min(420px, calc(100vw - 24px));
    background: #fff;
    border: 1px solid #dbe5f1;
    border-radius: 18px;
    padding: 16px 18px;
    box-shadow: 0 20px 50px rgba(15, 23, 42, 0.22);
    box-sizing: border-box;
}

.ld-tutorial-popover-kicker {
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #2563eb;
    margin-bottom: 6px;
}

.ld-tutorial-popover-title {
    margin: 0 0 8px;
    font-size: 18px;
    font-weight: 900;
    color: #0f172a;
    line-height: 1.2;
}

.ld-tutorial-popover-body {
    margin: 0 0 14px;
    font-size: 14px;
    line-height: 1.5;
    color: #475569;
}

.ld-tutorial-popover-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}

.ld-tutorial-popover-nav {
    display: flex;
    gap: 8px;
    margin-left: auto;
}

.ld-tutorial-btn {
    min-height: 44px;
    padding: 0 14px;
    border-radius: 12px;
    border: none;
    font-size: 13px;
    font-weight: 800;
    cursor: pointer;
}

.ld-tutorial-btn.primary {
    background: linear-gradient(90deg, #2563eb, #1d4ed8);
    color: #fff;
}

.ld-tutorial-btn.soft {
    background: #eff6ff;
    color: #1d4ed8;
}

.ld-tutorial-btn.ghost {
    background: transparent;
    color: #64748b;
    min-height: 44px;
    padding: 0 8px;
}

.ld-help-topbtn {
    min-height: 38px;
    padding: 0 12px;
    border: 1px solid #dbe5f1;
    border-radius: 12px;
    background: #f8fbff;
    color: #1d4ed8;
    font-size: 12px;
    font-weight: 900;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.ld-help-topbtn:hover {
    background: #eff6ff;
    border-color: #93c5fd;
}

.ld-tutorial-panel {
    position: fixed;
    top: 70px;
    right: 16px;
    bottom: auto;
    z-index: 99981;
    width: min(360px, calc(100vw - 24px));
    max-height: min(70vh, 520px);
    overflow: auto;
    background: #fff;
    border: 1px solid #dbe5f1;
    border-radius: 18px;
    box-shadow: 0 20px 50px rgba(15, 23, 42, 0.18);
    padding: 14px;
    box-sizing: border-box;
}

.ld-tutorial-panel-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 10px;
}

.ld-tutorial-panel-head h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 900;
    color: #0f172a;
}

.ld-tutorial-panel-head p {
    margin: 4px 0 0;
    font-size: 12px;
    color: #64748b;
}

.ld-tutorial-panel-close {
    border: none;
    background: #f1f5f9;
    width: 32px;
    height: 32px;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 900;
    color: #475569;
}

.ld-tutorial-panel-section {
    margin-bottom: 14px;
    padding-bottom: 12px;
    border-bottom: 1px solid #e7edf5;
}

.ld-tutorial-panel-section:last-of-type {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.ld-tutorial-panel-section-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    font-weight: 900;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #334155;
    margin: 0 0 8px 2px;
}

.ld-tutorial-panel-section-bullet {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #2563eb;
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
    flex-shrink: 0;
}

.ld-tutorial-panel-group {
    margin-bottom: 12px;
}

.ld-tutorial-panel-group-title {
    font-size: 11px;
    font-weight: 900;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: #64748b;
    margin: 0 0 6px 2px;
}

.ld-tutorial-panel-item-wrap {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    border: 1px solid #e7edf5;
    background: #f8fbff;
    border-radius: 14px;
    padding: 10px 12px;
    margin-bottom: 6px;
}

.ld-tutorial-panel-item-wrap.is-done {
    border-color: #bbf7d0;
    background: #f0fdf4;
}

.ld-tutorial-panel-item-text strong {
    display: block;
    font-size: 14px;
    color: #0f172a;
    margin-bottom: 2px;
}

.ld-tutorial-panel-item-text span {
    display: block;
    font-size: 12px;
    color: #64748b;
    line-height: 1.35;
}

.ld-tutorial-panel-item-text em {
    display: block;
    font-size: 11px;
    font-style: normal;
    font-weight: 700;
    color: #2563eb;
    margin-top: 4px;
}

.ld-tutorial-panel-item-wrap.is-done .ld-tutorial-panel-item-text strong::after {
    content: ' ✓';
    color: #16a34a;
}

.ld-tutorial-panel-start {
    flex-shrink: 0;
    min-height: 44px;
    padding: 0 12px;
    border: none;
    border-radius: 12px;
    background: linear-gradient(90deg, #2563eb, #1d4ed8);
    color: #fff;
    font-size: 12px;
    font-weight: 800;
    cursor: pointer;
    white-space: nowrap;
}

.ld-tutorial-panel-list {
    display: block;
}

.ld-tutorial-panel-item {
    display: none;
}

.ld-tutorial-panel-reset {
    margin-top: 10px;
    width: 100%;
    min-height: 44px;
    border: 1px dashed #cbd5e1;
    background: #fff;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 700;
    color: #64748b;
    cursor: pointer;
}

@media (max-width: 640px) {
    .ld-help-topbtn-label {
        display: none;
    }

    .ld-tutorial-panel {
        top: 64px;
        right: 8px;
        left: 8px;
        width: auto;
    }

    .ld-tutorial-popover-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .ld-tutorial-popover-nav {
        width: 100%;
        margin-left: 0;
    }

    .ld-tutorial-popover-nav .ld-tutorial-btn {
        flex: 1;
    }
}

/* Asistente de ayuda contextual: botón flotante + panel lateral (Preguntar / Tutorial) */
.ld-asst-fab {
    position: fixed;
    right: max(16px, env(safe-area-inset-right));
    bottom: max(16px, env(safe-area-inset-bottom));
    z-index: 99970;
    width: clamp(52px, 3.2vw, 72px);
    height: clamp(52px, 3.2vw, 72px);
    border-radius: 50%;
    border: none;
    background: var(--primary, #C1572A);
    color: #fff;
    font-size: clamp(22px, 1.4vw, 30px);
    font-weight: 800;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(26, 24, 22, 0.25);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease, background 0.15s ease;
}

.ld-asst-fab:hover {
    background: var(--primary-dark, #9C4521);
}

.ld-asst-fab:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px #fff, 0 0 0 6px rgba(193, 87, 42, 0.55);
}

.ld-asst-panel {
    position: fixed;
    right: max(16px, env(safe-area-inset-right));
    bottom: calc(max(16px, env(safe-area-inset-bottom)) + clamp(52px, 3.2vw, 72px) + 12px);
    top: calc(var(--ld-topbar-h, 64px) + 12px);
    z-index: 99971;
    width: clamp(380px, 24vw, 440px);
    max-width: calc(100vw - 32px);
    display: flex;
    flex-direction: column;
    background: var(--card, #fff);
    border: 1px solid var(--border, #E6E1D8);
    border-radius: 16px;
    box-shadow: 0 20px 50px rgba(26, 24, 22, 0.22);
    box-sizing: border-box;
    overflow: hidden;
    font-family: var(--font-ui, system-ui, sans-serif);
    font-size: clamp(14px, 0.85vw, 16px);
    color: var(--ink, #1A1816);
}

.ld-asst-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    padding: 14px 16px 10px;
    border-bottom: 1px solid var(--border, #E6E1D8);
}

.ld-asst-head h3 {
    margin: 0;
    font-size: 1.15em;
    font-weight: 800;
}

.ld-asst-head p {
    margin: 2px 0 0;
    font-size: 0.85em;
    color: var(--text-mut, #6b6559);
}

.ld-asst-close {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 10px;
    background: var(--bg, #F7F5F0);
    color: var(--ink, #1A1816);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
}

.ld-asst-tabs {
    display: flex;
    gap: 6px;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border, #E6E1D8);
}

.ld-asst-tab {
    flex: 1;
    min-height: 44px;
    border: 1px solid var(--border, #E6E1D8);
    border-radius: 10px;
    background: var(--bg, #F7F5F0);
    color: var(--ink, #1A1816);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.ld-asst-tab.active {
    background: var(--primary, #C1572A);
    border-color: var(--primary, #C1572A);
    color: #fff;
}

.ld-asst-chat {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 0 16px 10px;
}

.ld-asst-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 12px 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.ld-asst-welcome p {
    margin: 0 0 10px;
    line-height: 1.5;
}

.ld-asst-chips {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ld-asst-chip {
    text-align: left;
    min-height: 44px;
    padding: 8px 12px;
    border-radius: 10px;
    border: 1px solid var(--primary-tint, #F7E6DA);
    background: #fff;
    color: var(--primary-dark, #9C4521);
    font: inherit;
    font-size: 0.93em;
    font-weight: 600;
    cursor: pointer;
}

.ld-asst-chip:hover:not(:disabled) {
    background: var(--primary-tint, #F7E6DA);
}

.ld-asst-chip:disabled {
    opacity: 0.6;
    cursor: default;
}

.ld-asst-bubble {
    max-width: 92%;
    padding: 10px 12px;
    border-radius: 12px;
    line-height: 1.5;
    overflow-wrap: anywhere;
}

.ld-asst-bubble--user {
    align-self: flex-end;
    background: var(--ink, #1A1816);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.ld-asst-bubble--bot {
    align-self: flex-start;
    background: var(--bg, #F7F5F0);
    border: 1px solid var(--border, #E6E1D8);
    border-bottom-left-radius: 4px;
}

.ld-asst-bubble-text--plain {
    white-space: pre-wrap;
}

.ld-asst-bubble-text p,
.ld-asst-bubble-text ul,
.ld-asst-bubble-text ol {
    margin: 0 0 8px;
}

.ld-asst-bubble-text > :last-child {
    margin-bottom: 0;
}

.ld-asst-bubble-text ul,
.ld-asst-bubble-text ol {
    padding-left: 1.25em;
}

.ld-asst-note {
    display: block;
    margin-top: 6px;
    font-size: 0.78em;
    color: var(--text-mut, #6b6559);
    font-style: italic;
}

.ld-asst-typing {
    font-style: italic;
    color: var(--text-mut, #6b6559);
}

.ld-asst-alert {
    margin: 0 0 8px;
    padding: 8px 10px;
    border-radius: 10px;
    background: var(--warning-tint, #F3E9D4);
    color: #6b4a12;
    font-size: 0.88em;
}

.ld-asst-form {
    display: flex;
    flex-direction: column;
    gap: 8px;
    border-top: 1px solid var(--border, #E6E1D8);
    padding-top: 10px;
}

.ld-asst-input {
    width: 100%;
    min-height: 64px;
    max-height: 160px;
    resize: vertical;
    border: 1px solid var(--border, #E6E1D8);
    border-radius: 12px;
    padding: 10px 12px;
    font: inherit;
    box-sizing: border-box;
    background: #fff;
    color: var(--ink, #1A1816);
}

.ld-asst-input:focus {
    outline: none;
    border-color: var(--primary, #C1572A);
    box-shadow: var(--focus-ring, 0 0 0 3px rgba(193, 87, 42, 0.22));
}

.ld-asst-form-actions {
    display: flex;
    gap: 8px;
    justify-content: space-between;
}

.ld-asst-send,
.ld-asst-btn-ghost {
    min-height: 44px;
    padding: 0 16px;
    border-radius: 12px;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.ld-asst-send {
    min-width: 96px;
    border: none;
    background: var(--primary, #C1572A);
    color: #fff;
}

.ld-asst-btn-ghost {
    border: 1px solid var(--border, #E6E1D8);
    background: #fff;
    color: var(--ink, #1A1816);
}

.ld-asst-send:disabled,
.ld-asst-btn-ghost:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.ld-asst-foot {
    margin: 8px 0 0;
    font-size: 0.78em;
    color: var(--text-mut, #6b6559);
    line-height: 1.4;
}

.ld-asst-tours {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 14px 16px;
}

.ld-asst-sr {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

body.ld-tutorial-active .ld-asst-fab {
    display: none;
}

@media (max-width: 640px) {
    .ld-asst-fab {
        right: max(12px, env(safe-area-inset-right));
        bottom: max(12px, env(safe-area-inset-bottom));
    }

    .ld-asst-panel {
        top: max(8px, env(safe-area-inset-top));
        left: 8px;
        right: 8px;
        bottom: calc(max(12px, env(safe-area-inset-bottom)) + 52px + 8px);
        width: auto;
        max-width: none;
        font-size: 15px;
    }

    .ld-asst-form-actions {
        flex-direction: column-reverse;
    }

    .ld-asst-send,
    .ld-asst-btn-ghost {
        width: 100%;
    }
}

@media (min-width: 2560px) {
    .ld-asst-panel {
        width: clamp(440px, 20vw, 640px);
        font-size: clamp(16px, 0.75vw, 22px);
    }

    .ld-asst-close,
    .ld-asst-tab,
    .ld-asst-chip,
    .ld-asst-send,
    .ld-asst-btn-ghost {
        min-height: clamp(44px, 2.2vw, 64px);
    }
}
