/* ── Design Tokens ─────────────────────────────────────────────────── */
:root {
    --ep-bg: #FAFAFA;
    --ep-card: #FFFFFF;
    --ep-text-primary: #111827;
    --ep-text-secondary: #6B7280;
    --ep-primary: #0071E3;
    --ep-primary-hover: #005BB5;
    --ep-border: #E5E7EB;
    --ep-success: #059669;
    --ep-warning: #D97706;
    --ep-cta: #10B981;
    --ep-cta-hover: #059669;
    --ep-sidebar-w: 256px;
    --ep-header-h: 56px;
}
.dark {
    --ep-bg: #121212;
    --ep-card: #1A1A1A;
    --ep-text-primary: #E5E7EB;
    --ep-text-secondary: #9CA3AF;
    --ep-border: #374151;
    --ep-cta: #10B981;
    --ep-cta-hover: #059669;
}

/* ── Guided Tour (spotlight + floating card) ── */
#tour-overlay {
    position: fixed;
    inset: 0;
    background: transparent;
    z-index: 998;
    pointer-events: none;
}
.tour-spotlight {
    position: relative;
    z-index: 999;
    box-shadow: 0 0 0 9999px rgba(15, 23, 42, 0.55);
    border-radius: 12px;
    transition: box-shadow 250ms ease-out;
    animation: tour-pulse 2200ms ease-in-out infinite;
}
.dark .tour-spotlight {
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.7);
}
@keyframes tour-pulse {
    0%, 100% { outline: 2px solid rgba(0, 113, 227, 0.9); outline-offset: 3px; }
    50%      { outline: 2px solid rgba(0, 113, 227, 0.4); outline-offset: 6px; }
}
#tour-card {
    position: absolute;
    z-index: 1000;
    width: min(360px, calc(100vw - 24px));
    background: #FFFFFF;
    color: #111827;
    border-radius: 14px;
    box-shadow: 0 20px 40px -10px rgba(15, 23, 42, 0.35), 0 0 0 1px rgba(15, 23, 42, 0.08);
    padding: 18px 20px 16px;
    opacity: 0;
}
.dark #tour-card {
    background: #1F2937;
    color: #E5E7EB;
    box-shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.08);
}
#tour-card .tour-card-btn {
    font-size: 13px;
    font-weight: 600;
    padding: 7px 14px;
    border-radius: 8px;
    transition: background 150ms ease, color 150ms ease;
    cursor: pointer;
}
#tour-card .tour-card-btn.primary {
    background: #0071E3;
    color: #FFFFFF;
}
#tour-card .tour-card-btn.primary:hover { background: #005BB5; }
#tour-card .tour-card-btn.secondary {
    background: transparent;
    color: #6B7280;
    border: 1px solid #E5E7EB;
}
.dark #tour-card .tour-card-btn.secondary {
    color: #9CA3AF;
    border-color: #374151;
}
#tour-card .tour-card-btn.secondary:hover { background: #F3F4F6; color: #111827; }
.dark #tour-card .tour-card-btn.secondary:hover { background: #374151; color: #E5E7EB; }
#tour-card .tour-card-btn.ghost {
    background: transparent;
    color: #9CA3AF;
    font-weight: 500;
}
#tour-card .tour-card-btn.ghost:hover { color: #6B7280; text-decoration: underline; }
.dark #tour-card .tour-card-btn.ghost:hover { color: #D1D5DB; }
body.tour-active { overflow-x: hidden; }
@media (prefers-reduced-motion: reduce) {
    .tour-spotlight { animation: none !important; }
    #tour-card { transition: none !important; }
}

/* ── Reduced motion ────────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ── Sidebar trash panel (popover que abre hacia arriba) ─────────── */
#sidebar-trash-wrapper { position: relative; }

#sidebar-trash-panel {
    position: absolute;
    left: 0;
    right: 0;
    bottom: calc(100% + 4px);
    background: #FFFFFF;
    border: 1px solid #E5E7EB;
    border-radius: 10px;
    box-shadow: 0 -12px 28px -6px rgba(15, 23, 42, 0.25), 0 0 0 1px rgba(15, 23, 42, 0.04);
    z-index: 100;
    max-height: 320px;
    overflow-y: auto;
    padding: 4px;
}
.dark #sidebar-trash-panel {
    background: #1f2937;
    border-color: #374151;
    box-shadow: 0 -12px 28px -6px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.06);
}
#sidebar-trash-panel .trash-empty {
    font-size: 12px;
    color: #9ca3af;
    text-align: center;
    padding: 14px;
}

/* Items estilizados como history-item */
.sidebar-trash-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 8px;
    cursor: default;
    transition: background 150ms ease;
    font-size: 13px;
    color: #374151;
    position: relative;
}
.dark .sidebar-trash-item { color: #d1d5db; }
.sidebar-trash-item:hover {
    background: rgba(0, 0, 0, 0.04);
}
.dark .sidebar-trash-item:hover {
    background: rgba(255, 255, 255, 0.06);
}
.sidebar-trash-item .trash-icon {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    color: #9ca3af;
}
.sidebar-trash-item .trash-title {
    flex: 1 1 auto;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.sidebar-trash-item .trash-restore-btn {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    margin-right: -4px;
    border-radius: 6px;
    color: #9ca3af;
    background: transparent;
    border: none;
    cursor: pointer;
    opacity: 0;
    transition: opacity 150ms ease, background 150ms ease, color 150ms ease;
    line-height: 0;
}
.sidebar-trash-item:hover .trash-restore-btn,
.sidebar-trash-item .trash-restore-btn:focus { opacity: 1; }
.sidebar-trash-item .trash-restore-btn:hover {
    background: rgba(37, 99, 235, 0.12);
    color: #2563eb;
}
.dark .sidebar-trash-item .trash-restore-btn:hover {
    background: rgba(96, 165, 250, 0.18);
    color: #60a5fa;
}
#sidebar-trash-btn[aria-expanded="true"] #sidebar-trash-chevron {
    transform: rotate(180deg);
}

/* ── Sidebar history kebab menu ───────────────────────────────────── */
.sidebar-history-item { position: relative; }
.sidebar-history-item .history-kebab {
    opacity: 0;
    transition: opacity 150ms ease, background 150ms ease, color 150ms ease;
    padding: 4px;
    margin-right: -4px;
    border-radius: 6px;
    color: #9ca3af;
    background: transparent;
    border: none;
    cursor: pointer;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
}
.sidebar-history-item:hover .history-kebab,
.sidebar-history-item .history-kebab:focus,
.sidebar-history-item .history-kebab[aria-expanded="true"] { opacity: 1; }
.sidebar-history-item .history-kebab:hover {
    background: rgba(0, 0, 0, 0.08);
    color: #111827;
}
.dark .sidebar-history-item .history-kebab:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #e5e7eb;
}
.history-menu {
    position: absolute;
    right: 4px;
    top: calc(100% + 2px);
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    box-shadow: 0 12px 28px -6px rgba(15, 23, 42, 0.25), 0 0 0 1px rgba(15, 23, 42, 0.04);
    z-index: 100;
    min-width: 150px;
    padding: 4px;
}
.dark .history-menu {
    background: #1f2937;
    border-color: #374151;
    box-shadow: 0 12px 28px -6px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255, 255, 255, 0.06);
}
.history-menu button {
    width: 100%;
    text-align: left;
    padding: 7px 10px;
    font-size: 12px;
    font-weight: 500;
    color: #374151;
    background: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 120ms ease, color 120ms ease;
}
.dark .history-menu button { color: #d1d5db; }
.history-menu button:hover {
    background: #fee2e2;
    color: #dc2626;
}
.dark .history-menu button:hover {
    background: rgba(220, 38, 38, 0.18);
    color: #f87171;
}

/* ── Sidebar ───────────────────────────────────────────────────────── */
.sidebar-open { overflow: hidden; }
@media (max-width: 767px) {
    #sidebar.open { transform: translateX(0); }
}
@media (min-width: 768px) {
    #main-content { margin-left: var(--ep-sidebar-w); }
}
body.sidebar-resizing { cursor: col-resize !important; user-select: none !important; }
body.sidebar-resizing * { cursor: col-resize !important; }
body.sidebar-resizing #sidebar,
body.sidebar-resizing #sidebar-resizer,
body.sidebar-resizing #main-content { transition: none !important; }
.sidebar-history-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    font-size: 13px;
    color: var(--ep-text-secondary);
}
.sidebar-history-item:hover {
    background: rgba(0, 0, 0, 0.04);
    color: var(--ep-text-primary);
}
.dark .sidebar-history-item:hover {
    background: rgba(255, 255, 255, 0.06);
}
.sidebar-history-item.active {
    background: rgba(0, 113, 227, 0.08);
    color: #0071E3;
}
.dark .sidebar-history-item.active {
    background: rgba(0, 113, 227, 0.15);
    color: #60A5FA;
}

/* ── Source Tabs ────────────────────────────────────────────────────── */
.source-tab {
    color: var(--ep-text-secondary);
    background: transparent;
}
.source-tab:hover:not(.active) {
    background: rgba(0, 0, 0, 0.04);
}
.dark .source-tab:hover:not(.active) {
    background: rgba(255, 255, 255, 0.06);
}
.source-tab.active {
    background: #fff;
    color: var(--ep-text-primary);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
.dark .source-tab.active {
    background: #374151;
    color: #E5E7EB;
}

/* Custom Animations */
@keyframes shimmer {
    0% {
        transform: translateX(-100%);
    }

    100% {
        transform: translateX(200%);
    }
}

.loading-shimmer {
    animation: shimmer 1.5s infinite linear;
    transform-origin: left;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-fade-in {
    animation: fadeIn 0.4s ease-out forwards;
}

/* Hide scrollbar for cleaner look */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background-color: #D1D5DB;
    border-radius: 10px;
}

::-webkit-scrollbar-thumb:hover {
    background-color: #9CA3AF;
}

/* Utilities not in compiled Tailwind build */
.overflow-x-auto  { overflow-x: auto; }
.overflow-y-auto  { overflow-y: auto; }
.tabular-nums     { font-variant-numeric: tabular-nums; }
.text-10          { font-size: 10px; }
.leading-none     { line-height: 1; }

/* Dividers for toolbar groups */
.toolbar-group {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 13px 20px;
    border-right: 1px solid #F3F4F6;
}
.dark .toolbar-group { border-right-color: #1F2937; }
.toolbar-group:last-child { border-right: none; }

/* Preview button — bg tint not in compiled CSS */
#preview-toggle-btn {
    background-color: rgba(0, 113, 227, 0.05);
    border-color: rgba(0, 113, 227, 0.3);
}
#preview-toggle-btn:hover {
    background-color: rgba(0, 113, 227, 0.1);
    border-color: rgba(0, 113, 227, 0.55);
}
.dark #preview-toggle-btn {
    background-color: rgba(0, 113, 227, 0.08);
    border-color: rgba(0, 113, 227, 0.22);
}
.dark #preview-toggle-btn:hover {
    background-color: rgba(0, 113, 227, 0.15);
    border-color: rgba(0, 113, 227, 0.5);
}

/* sm:hidden / sm:flex for mobile print button */
@media (min-width: 640px) {
    .sm-hidden { display: none !important; }
    .sm-flex   { display: flex !important; }
}

/* Segmented control pills for compact toolbars (preview modal) */
.seg-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 5px 14px;
    font-size: 12px;
    font-weight: 600;
    border: 1px solid #E5E7EB;
    background: #fff;
    color: #374151;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    white-space: nowrap;
    line-height: 1.6;
}
.seg-btn:first-child { border-radius: 8px 0 0 8px; }
.seg-btn:last-child  { border-radius: 0 8px 8px 0; border-left: none; }
.seg-btn:only-child  { border-radius: 8px; }
.seg-btn + .seg-btn  { border-left: none; }
.seg-btn:hover:not(.active) { background: #F9FAFB; border-color: rgba(0,113,227,0.4); }
.seg-btn.active {
    background: #0071E3;
    border-color: #0071E3;
    color: #fff;
    z-index: 1;
    position: relative;
}

.dark .seg-btn {
    background: #374151;
    border-color: #4B5563;
    color: #D1D5DB;
}
.dark .seg-btn:hover:not(.active) { background: #4B5563; border-color: rgba(96,165,250,0.5); }
.dark .seg-btn.active { background: #0071E3; border-color: #0071E3; color: #fff; }

/* Preview document shadow for the scaled iframe wrapper */
#pdf-preview-modal-scaler iframe {
    box-shadow: 0 4px 24px rgba(0,0,0,0.18), 0 1px 4px rgba(0,0,0,0.1);
}

/* Pareados: glow when a new field is added */
@keyframes fieldGlow {
    0%   { box-shadow: 0 0 0 3px rgba(139,92,246,0.5); }
    100% { box-shadow: 0 0 0 3px transparent; }
}
.field-highlight {
    animation: fieldGlow 1.2s ease-out forwards;
}

/* ── Drag & Drop de preguntas ───────────────────────────────────────── */
.draggable-card { position: relative; }
.drag-handle {
    position: absolute;
    left: 4px;
    top: 20px;
    width: 22px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #9ca3af;
    background: transparent;
    border: none;
    padding: 0;
    cursor: grab;
    opacity: 0;
    border-radius: 4px;
    transition: opacity 0.15s ease, color 0.15s ease, background 0.15s ease;
    touch-action: none;
    user-select: none;
    z-index: 5;
}
.draggable-card:hover .drag-handle { opacity: 1; }
.drag-handle:hover { color: #e8614d; background: rgba(232, 97, 77, 0.1); }
.drag-handle:active { cursor: grabbing; }
.dark .drag-handle { color: #6b7280; }
.dark .drag-handle:hover { color: #f87171; background: rgba(232, 97, 77, 0.15); }
@media (max-width: 640px) {
    .drag-handle { opacity: 1; }
}
.draggable-card.dragging {
    opacity: 0.85;
    border: 2px dashed #e8614d !important;
    padding-top: 0.75rem !important;
    padding-bottom: 0.75rem !important;
}
/* Colapsar contenido de la card mientras se arrastra: mostrar solo el header
   (enunciado + badge). Aplica a la card activa (.dragging) y a las peers de
   la misma sección (.drag-peer-collapsed). Transiciones con max-height para
   que colapso/expansión sean fluidos. */
.draggable-card {
    transition: transform 0.22s cubic-bezier(.2,.7,.3,1),
                padding 0.22s ease;
}
.draggable-card > *:not(.drag-handle):not(:first-child) {
    overflow: hidden;
    transition: max-height 0.25s ease, opacity 0.2s ease,
                margin 0.25s ease, padding 0.25s ease;
    max-height: 1500px;
    opacity: 1;
}
.draggable-card.dragging > *:not(.drag-handle):not(:first-child),
.draggable-card.drag-peer-collapsed > *:not(.drag-handle):not(:first-child) {
    max-height: 0 !important;
    opacity: 0 !important;
    margin-top: 0 !important;
    margin-bottom: 0 !important;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
}
.draggable-card.dragging > :first-child,
.draggable-card.drag-peer-collapsed > :first-child {
    margin-bottom: 0 !important;
}
.draggable-card.dragging .q-text,
.draggable-card.drag-peer-collapsed .q-text {
    min-height: 0 !important;
    pointer-events: none;
}
.draggable-card.dragging,
.draggable-card.drag-peer-collapsed {
    padding-top: 0.75rem !important;
    padding-bottom: 0.75rem !important;
}
.draggable-card.drag-peer-collapsed { opacity: 0.9; }
.draggable-card.drop-indicator-top { box-shadow: 0 -3px 0 0 #e8614d; }
.draggable-card.drop-indicator-bottom { box-shadow: 0 3px 0 0 #e8614d; }

/* Stepper buttons for question composition */
.stepper-btn {
    width: 28px; height: 28px;
    display: flex; align-items: center; justify-content: center;
    border-radius: 6px;
    background: #fff; border: 1px solid #e5e7eb;
    color: #6b7280; font-size: 16px; font-weight: 700; line-height: 1;
    cursor: pointer; transition: all 0.1s;
    user-select: none;
}
.stepper-btn:hover { border-color: #0071E3; color: #0071E3; }
.stepper-btn:active { transform: scale(0.9); }
.stepper-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.dark .stepper-btn { background: #374151; border-color: #4b5563; color: #d1d5db; }
.dark .stepper-btn:hover { border-color: #60a5fa; color: #60a5fa; }
@media (max-width: 640px) {
    .stepper-btn { width: 44px; height: 44px; font-size: 18px; }
}

/* Editable number pill */
.val-pill {
    width: 40px; text-align: center; font-size: 15px; font-weight: 700;
    background: rgba(37,99,235,0.08); border: none; border-radius: 8px;
    color: #2563eb; cursor: text; padding: 4px 0;
    transition: all 0.15s;
}
.val-pill:hover { background: rgba(37,99,235,0.15); }
.val-pill:focus { background: rgba(37,99,235,0.2); box-shadow: 0 0 0 2px rgba(37,99,235,0.25); outline: none; }
.dark .val-pill { color: #60a5fa; background: rgba(59,130,246,0.12); }
.dark .val-pill:hover { background: rgba(59,130,246,0.2); }
.dark .val-pill:focus { background: rgba(59,130,246,0.25); box-shadow: 0 0 0 2px rgba(59,130,246,0.3); }

/* Mobile fixes */
@media (max-width: 640px) {
    /* Feedback panel: full-width fixed on mobile */
    #feedback-panel {
        position: fixed !important;
        top: 56px !important;
        left: 0.5rem !important;
        right: 0.5rem !important;
        width: auto !important;
        max-height: calc(100dvh - 56px - 1rem) !important;
        overflow-y: auto !important;
        z-index: 50 !important;
    }
    /* Source tabs: fade hint for hidden tabs */
    #source-tabs {
        -webkit-mask-image: linear-gradient(to right, black 82%, transparent 100%);
        mask-image: linear-gradient(to right, black 82%, transparent 100%);
        scrollbar-width: none;
    }
    #source-tabs::-webkit-scrollbar { display: none; }
    /* Drag handles: bigger touch target */
    .drag-handle { width: 44px; height: 44px; }
    /* Editor toolbar: no sticky on mobile to save viewport */
    .sticky.top-14 { position: relative; }
    /* Toolbar groups: stack vertically */
    .toolbar-group {
        border-right: none !important;
        border-bottom: 1px solid rgba(243,244,246,0.1);
        padding: 10px 16px;
        width: 100%;
        justify-content: space-between;
    }
    .toolbar-group:last-child { border-bottom: none; }
}

/* Tooltip tap-toggle for touch devices */
.tooltip-content.tap-visible {
    opacity: 1 !important;
    visibility: visible !important;
    transform: scale(1) !important;
    pointer-events: auto !important;
}