﻿/* ==========================================================================
   CIATSOFTWARE - EBOOK: PLC DESDE CERO (Visor Protegido Página por Página)
   Optimizado para dispositivos Móviles, Tablets y Pantallas de Escritorio
   ========================================================================== */

:root {
    --bg-main: #060b16;
    --bg-panel: #0d1526;
    --bg-elevated: #131f38;
    --border-subtle: rgba(148, 163, 184, 0.16);
    --border-accent: rgba(245, 158, 11, 0.45);
    --accent-amber: #f59e0b;
    --accent-cyan: #06b6d4;
    --accent-emerald: #10b981;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
}

* {
    box-sizing: border-box;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
    background-color: var(--bg-main);
    color: var(--text-primary);
    font-family: 'Space Grotesk', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.mono {
    font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.ciat-wordmark {
    letter-spacing: -0.02em;
}

/* ==========================================================================
   LAYOUT PRINCIPAL DEL VISOR (100dvh para navegadores móviles modernos)
   ========================================================================== */
.ebook-shell {
    display: flex;
    flex-direction: column;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    background:
        radial-gradient(circle at 15% 15%, rgba(245, 158, 11, 0.07), transparent 40%),
        radial-gradient(circle at 85% 85%, rgba(6, 182, 212, 0.07), transparent 40%),
        var(--bg-main);
}

/* Barra Superior */
.ebook-topbar {
    height: 60px;
    min-height: 60px;
    background: rgba(13, 21, 38, 0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 14px;
    z-index: 40;
    gap: 10px;
}

.ebook-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex-shrink: 1;
}

.ebook-quick-menus {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.ebook-app-trigger-box {
    max-width: 100%;
    min-width: 0;
}

.ebook-title-badge {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-width: 0;
    gap: 2px;
}

.ebook-title-main {
    font-size: 0.86rem;
    font-weight: 700;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: 0.02em;
    line-height: 1.15;
}

.ebook-title-sub {
    font-size: 0.68rem;
    color: var(--accent-amber);
    font-family: 'JetBrains Mono', monospace;
    display: flex;
    align-items: center;
    gap: 6px;
    line-height: 1.1;
}

/* Controles Centrales de Paginación (Escritorio) */
.ebook-nav-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(6, 11, 22, 0.85);
    padding: 4px 8px;
    border-radius: 12px;
    border: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

.ebook-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 36px;
    padding: 0 11px;
    border-radius: 8px;
    border: 1px solid rgba(148, 163, 184, 0.18);
    background: rgba(30, 41, 59, 0.65);
    color: #e2e8f0;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.16s ease;
    white-space: nowrap;
    flex-shrink: 0;
}

.ebook-btn:hover:not(:disabled) {
    background: rgba(245, 158, 11, 0.16);
    border-color: rgba(245, 158, 11, 0.55);
    color: #fff;
}

.ebook-btn.active {
    background: rgba(245, 158, 11, 0.24);
    border-color: #f59e0b;
    color: #fde68a;
    box-shadow: 0 0 10px rgba(245, 158, 11, 0.18);
}

.ebook-btn:active:not(:disabled) {
    transform: translateY(1px);
}

.ebook-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.ebook-btn-primary {
    background: linear-gradient(135deg, #f59e0b, #ea580c);
    border-color: rgba(251, 191, 36, 0.6);
    color: #0f172a;
    font-weight: 700;
}

.ebook-btn-primary:hover:not(:disabled) {
    background: linear-gradient(135deg, #fbbf24, #f97316);
    color: #090d16;
    border-color: #fde68a;
}

.ebook-btn-practicas {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.18), rgba(6, 182, 212, 0.18));
    border-color: rgba(245, 158, 11, 0.5);
    color: #fde68a;
}

.ebook-btn-practicas:hover:not(:disabled),
.ebook-btn-practicas.active {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.32), rgba(6, 182, 212, 0.28));
    border-color: #fbbf24;
    color: #ffffff;
}

/* ==========================================================================
   MENÚ DESPLEGABLE DE LAS 10 PRÁCTICAS EN BARRA SUPERIOR
   ========================================================================== */
.ebook-practicas-dropdown-wrap {
    position: relative;
    flex-shrink: 0;
}

.ebook-practicas-menu {
    position: absolute;
    top: calc(100% + 10px);
    left: 0;
    width: 390px;
    max-width: calc(100vw - 24px);
    max-height: calc(100dvh - 85px);
    background: rgba(11, 18, 33, 0.98);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(245, 158, 11, 0.4);
    border-radius: 14px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.85);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 60;
    opacity: 0;
    transform: translateY(-6px) scale(0.98);
    pointer-events: none;
    transition: opacity 0.16s ease, transform 0.16s ease;
}

.ebook-practicas-menu.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.ebook-practicas-menu-header {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border-subtle);
    background: linear-gradient(90deg, rgba(245, 158, 11, 0.12), rgba(6, 182, 212, 0.08));
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.ebook-practicas-list {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.ebook-practica-item {
    display: flex;
    align-items: center;
    gap: 11px;
    width: 100%;
    padding: 9px 11px;
    border-radius: 10px;
    background: rgba(19, 31, 56, 0.65);
    border: 1px solid rgba(148, 163, 184, 0.15);
    color: #f1f5f9;
    text-align: left;
    cursor: pointer;
    transition: all 0.15s ease;
}

.ebook-practica-item:hover {
    background: rgba(30, 41, 59, 0.95);
    border-color: rgba(245, 158, 11, 0.55);
    transform: translateX(2px);
}

.ebook-practica-item.active {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.22), rgba(15, 23, 42, 0.92));
    border-color: #f59e0b;
    box-shadow: 0 0 14px rgba(245, 158, 11, 0.2);
}

.ebook-practica-num {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'JetBrains Mono', monospace;
    font-weight: 800;
    font-size: 0.84rem;
    color: #fff;
    flex-shrink: 0;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.35);
}

.ebook-practica-info {
    flex: 1;
    min-width: 0;
}

.ebook-practica-title {
    font-size: 0.81rem;
    font-weight: 700;
    color: #f8fafc;
    line-height: 1.25;
}

.ebook-practica-meta {
    font-size: 0.68rem;
    color: var(--text-secondary);
    margin-top: 2px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.ebook-practica-page-pill {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.72rem;
    font-weight: 700;
    padding: 3px 7px;
    border-radius: 6px;
    background: rgba(6, 11, 22, 0.85);
    border: 1px solid rgba(148, 163, 184, 0.25);
    color: #fbbf24;
    flex-shrink: 0;
}

/* Colores oficiales de cada par de prácticas en el Ebook */
.prac-color-orange { background: linear-gradient(135deg, #ff5e2b, #ea580c); }
.prac-color-green  { background: linear-gradient(135deg, #65c93d, #16a34a); }
.prac-color-blue   { background: linear-gradient(135deg, #00b4fc, #0284c7); }
.prac-color-purple { background: linear-gradient(135deg, #7c3aed, #5b21b6); }
.prac-color-yellow { background: linear-gradient(135deg, #facc15, #ca8a04); color: #0f172a !important; }

.ebook-page-input-wrap {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 0 4px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.ebook-page-input {
    width: 50px;
    height: 30px;
    background: #090f1d;
    border: 1px solid rgba(148, 163, 184, 0.3);
    border-radius: 6px;
    color: #fbbf24;
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    font-size: 0.84rem;
    text-align: center;
    outline: none;
    -webkit-user-select: text;
    user-select: text;
}

.ebook-page-input:focus {
    border-color: var(--accent-amber);
    box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.25);
}

/* Herramientas de Zoom y Vista */
.ebook-zoom-controls,
.ebook-tools {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.ebook-zoom-label {
    min-width: 48px;
    text-align: center;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.76rem;
    color: #cbd5e1;
}

/* Barra de progreso de lectura */
.ebook-progress-track {
    width: 100%;
    height: 3px;
    min-height: 3px;
    background: rgba(15, 23, 42, 0.95);
    position: relative;
    z-index: 25;
}

.ebook-progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #f59e0b, #06b6d4, #10b981);
    transition: width 0.22s ease;
}

/* ==========================================================================
   CONTENEDOR CENTRAL Y PANEL LATERAL (PRÁCTICAS + 154 PÁGINAS)
   ========================================================================== */
.ebook-body {
    flex: 1;
    display: flex;
    position: relative;
    overflow: hidden;
    min-height: 0;
}

/* Backdrop para el cajón lateral en móvil/tablet */
.ebook-drawer-backdrop {
    display: none;
    position: absolute;
    inset: 0;
    background: rgba(2, 6, 23, 0.65);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    z-index: 28;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
}

.ebook-drawer-backdrop.visible {
    opacity: 1;
    pointer-events: auto;
}

/* Cajón lateral */
.ebook-drawer {
    width: 310px;
    max-width: 86vw;
    background: rgba(13, 21, 38, 0.98);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    z-index: 30;
    transition: margin-left 0.25s cubic-bezier(0.16, 1, 0.3, 1), transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.ebook-drawer.collapsed {
    margin-left: -310px;
}

.ebook-drawer-header {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* Pestañas del cajón lateral: Prácticas vs Todas las Páginas */
.ebook-drawer-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-subtle);
    background: rgba(6, 11, 22, 0.6);
}

.ebook-drawer-tab {
    padding: 7px 10px;
    border-radius: 8px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.76rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s ease;
    text-align: center;
}

.ebook-drawer-tab:hover {
    color: #fff;
    background: rgba(30, 41, 59, 0.5);
}

.ebook-drawer-tab.active {
    background: rgba(245, 158, 11, 0.18);
    border-color: rgba(245, 158, 11, 0.55);
    color: #fbbf24;
}

.ebook-drawer-practicas {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.ebook-drawer-grid {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 12px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    align-content: start;
}

.ebook-hidden {
    display: none !important;
}

.ebook-page-chip {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 10px 6px;
    border-radius: 8px;
    background: rgba(15, 23, 42, 0.8);
    border: 1px solid rgba(148, 163, 184, 0.16);
    color: #cbd5e1;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.76rem;
    cursor: pointer;
    transition: all 0.15s ease;
}

.ebook-page-chip:hover {
    border-color: rgba(245, 158, 11, 0.5);
    color: #fff;
    background: rgba(30, 41, 59, 0.9);
}

.ebook-page-chip.active {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.24), rgba(234, 88, 12, 0.24));
    border-color: #f59e0b;
    color: #fbbf24;
    font-weight: 700;
    box-shadow: 0 0 12px rgba(245, 158, 11, 0.22);
}

.ebook-page-chip-sub {
    font-size: 0.62rem;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ==========================================================================
   MÁRGENES LATERALES PERMANENTES (.ebook-stage-outer) Y ESCENARIO CON SCROLL INTERNO (#ebookStage)
   ========================================================================== */
.ebook-stage-outer {
    flex: 1;
    position: relative;
    display: flex;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    /* Márgenes laterales y verticales permanentes en Escritorio */
    padding: 16px 76px;
}

.ebook-stage {
    flex: 1;
    width: 100%;
    height: 100%;
    min-width: 0;
    min-height: 0;
    position: relative;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    display: flex;
    align-items: flex-start;
    justify-content: flex-start;
    border-radius: 8px;
}

.ebook-canvas-frame {
    position: relative;
    margin: auto;
    flex-shrink: 0;
    background: #ffffff;
    border-radius: 6px;
    box-shadow:
        0 25px 60px -15px rgba(0, 0, 0, 0.85),
        0 0 0 1px rgba(255, 255, 255, 0.12);
    overflow: hidden;
}

#ebookCanvas {
    display: block;
    background: #ffffff;
    pointer-events: none;
}

/* Capa transparente anti-descarga encima del canvas con soporte de pan táctil */
.ebook-shield-layer {
    position: absolute;
    inset: 0;
    z-index: 5;
    background: transparent;
    cursor: grab;
    touch-action: pan-x pan-y;
}

.ebook-shield-layer:active {
    cursor: grabbing;
}

/* Marca de agua sutil de protección */
.ebook-watermark {
    position: absolute;
    bottom: 8px;
    right: 12px;
    z-index: 6;
    pointer-events: none;
    font-family: 'JetBrains Mono', monospace;
    font-size: 9.5px;
    letter-spacing: 0.08em;
    color: rgba(15, 23, 42, 0.28);
    background: rgba(255, 255, 255, 0.58);
    padding: 2px 7px;
    border-radius: 4px;
}

/* Botones flotantes laterales ubicados dentro del margen lateral de Escritorio */
.ebook-side-arrow {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 44px;
    height: 74px;
    border-radius: 12px;
    background: rgba(13, 21, 38, 0.82);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(148, 163, 184, 0.22);
    color: #f8fafc;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 15;
    transition: all 0.2s ease;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.45);
}

.ebook-side-arrow:hover:not(:disabled) {
    background: rgba(245, 158, 11, 0.22);
    border-color: #f59e0b;
    color: #fbbf24;
    transform: translateY(-50%) scale(1.05);
}

.ebook-side-arrow:disabled {
    opacity: 0.22;
    cursor: not-allowed;
}

.ebook-side-arrow.prev {
    left: 16px;
}

.ebook-side-arrow.next {
    right: 16px;
}

/* Overlay de Carga por Página */
.ebook-loader {
    position: absolute;
    inset: 0;
    z-index: 10;
    background: rgba(6, 11, 22, 0.62);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.16s ease;
}

.ebook-loader.visible {
    opacity: 1;
    pointer-events: auto;
}

.ebook-spinner {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 3px solid rgba(245, 158, 11, 0.22);
    border-top-color: #f59e0b;
    animation: ebookSpin 0.75s linear infinite;
}

@keyframes ebookSpin {
    to { transform: rotate(360deg); }
}

/* ==========================================================================
   BARRA INFERIOR DE CONTROLES MÓVIL / TABLET COMPACTA (#ebookMobileDock)
   ========================================================================== */
.ebook-mobile-dock {
    display: none;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 10px;
    padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
    background: rgba(13, 21, 38, 0.96);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--border-subtle);
    z-index: 35;
}

.ebook-mobile-dock-group {
    display: flex;
    align-items: center;
    gap: 4px;
}

.ebook-mob-btn {
    height: 36px;
    width: 36px;
    padding: 0;
    border-radius: 9px;
}

.ebook-mob-page-wrap {
    padding: 0 3px;
    font-size: 0.75rem;
}

.ebook-mob-page-input {
    width: 44px;
    height: 32px;
    font-size: 0.8rem;
}

.ebook-mob-zoom-label {
    min-width: 40px;
    font-size: 0.72rem;
}

.ebook-mob-fit-btn {
    height: 36px;
    padding: 0 9px;
    font-size: 0.73rem;
    border-radius: 9px;
}

/* Pie de Estado */
.ebook-statusbar {
    height: 32px;
    min-height: 32px;
    background: rgba(9, 14, 26, 0.95);
    border-top: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 14px;
    font-size: 0.71rem;
    color: var(--text-secondary);
    z-index: 30;
    gap: 12px;
}

/* ==========================================================================
   BOTÓN DE OPCIONES COLAPSABLES Y BREAKPOINTS RESPONSIVOS (MÓVIL VERTICAL, HORIZONTAL Y TABLET)
   ========================================================================== */

/* Por defecto en monitores grandes de escritorio (>= 1240px y altura > 580px) el botón Opciones está oculto */
.ebook-btn-toggle-tools {
    display: none;
    background: rgba(245, 158, 11, 0.14);
    border-color: rgba(245, 158, 11, 0.45);
    color: #fde68a;
}

.ebook-btn-toggle-tools[aria-expanded="true"] {
    background: rgba(245, 158, 11, 0.28);
    border-color: #f59e0b;
    color: #ffffff;
}

.ebook-btn-toggle-tools[aria-expanded="true"] #icoToggleEbookHeaderTools {
    transform: rotate(180deg);
}

html[data-ciat-theme="light"] .ebook-btn-toggle-tools {
    background: rgba(245, 158, 11, 0.16) !important;
    border-color: #d97706 !important;
    color: #78350f !important;
}

/* Pantallas medianas / laptops compactas (<= 1320px) */
@media (max-width: 1320px) {
    .hide-tablet {
        display: none !important;
    }

    .ebook-stage-outer {
        padding: 14px 68px;
    }
}

/* Modo compacto activado dinámicamente por JS (data-compact-nav="true") en móviles (vertical/horizontal) y tablets (< 1220px o altura <= 580px) */
.ebook-topbar[data-compact-nav="true"] {
    height: auto;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
        "appbrand apptools"
        "quickmenus quickmenus"
        "navcontrols zoomcontrols";
    align-items: center;
    padding: 6px 10px;
    gap: 6px 8px;
}

.ebook-topbar[data-compact-nav="true"] .ebook-brand {
    display: contents;
}

.ebook-topbar[data-compact-nav="true"] .ebook-app-trigger-box {
    grid-area: appbrand;
    width: auto;
    max-width: 100%;
    min-width: 0;
    justify-self: start;
    padding: 4px 8px !important;
}

.ebook-topbar[data-compact-nav="true"] .ebook-tools {
    grid-area: apptools;
    justify-self: end;
    display: flex;
    align-items: center;
    gap: 5px;
}

.ebook-topbar[data-compact-nav="true"] .ebook-btn-toggle-tools {
    display: inline-flex;
}

/* Ocultar opciones adicionales del topbar mientras no esté desplegado (.tools-open) */
.ebook-topbar[data-compact-nav="true"]:not(.tools-open) .ebook-quick-menus,
.ebook-topbar[data-compact-nav="true"]:not(.tools-open) .ebook-nav-controls,
.ebook-topbar[data-compact-nav="true"]:not(.tools-open) .ebook-zoom-controls {
    display: none !important;
}

/* Cuando el usuario pulsa el botón "Opciones", se muestran ordenadamente debajo del título sin encimarse */
.ebook-topbar[data-compact-nav="true"].tools-open .ebook-quick-menus {
    grid-area: quickmenus;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    width: 100%;
    padding-top: 6px;
    border-top: 1px solid var(--border-subtle);
}

.ebook-topbar[data-compact-nav="true"].tools-open .ebook-nav-controls {
    grid-area: navcontrols;
    display: flex !important;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.ebook-topbar[data-compact-nav="true"].tools-open .ebook-zoom-controls {
    grid-area: zoomcontrols;
    display: flex !important;
    flex-wrap: wrap;
    align-items: center;
    justify-self: end;
    gap: 6px;
}

/* Tablets y Móviles Verticales (<= 860px) */
@media (max-width: 860px) {
    .ebook-title-badge {
        flex: 1;
        min-width: 0;
    }

    .ebook-title-main {
        font-size: 0.78rem;
        line-height: 1.15;
    }

    .ebook-title-sub {
        font-size: 0.64rem;
        line-height: 1.15;
    }

    .ebook-topbar[data-compact-nav="true"].tools-open .ebook-quick-menus {
        display: grid;
        grid-template-columns: auto minmax(0, 1fr);
    }

    /* En móvil vertical ya tenemos la barra inferior #ebookMobileDock para paginación y zoom */
    .ebook-topbar[data-compact-nav="true"].tools-open .ebook-nav-controls,
    .ebook-topbar[data-compact-nav="true"].tools-open .ebook-zoom-controls {
        display: none !important;
    }

    .ebook-practicas-dropdown-wrap {
        width: 100%;
        min-width: 0;
    }

    .ebook-btn-practicas {
        width: 100%;
        justify-content: space-between;
    }

    .ebook-btn {
        height: 34px;
        padding: 0 9px;
        font-size: 0.75rem;
    }

    .hide-on-mobile-bar,
    .hide-mobile {
        display: none !important;
    }

    /* Márgenes laterales y verticales siempre visibles en móvil; el scroll queda adentro de #ebookStage */
    .ebook-stage-outer {
        padding: 10px 14px;
    }

    /* En móvil vertical usamos la barra inferior dedicada y gestos swipe */
    .ebook-side-arrow {
        display: none !important;
    }

    .ebook-drawer-backdrop {
        display: block;
    }

    .ebook-drawer {
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        width: 300px;
        max-width: 85vw;
        margin-left: 0 !important;
        transform: translateX(0);
        box-shadow: 16px 0 40px rgba(0, 0, 0, 0.8);
    }

    .ebook-drawer.collapsed {
        transform: translateX(-105%);
        box-shadow: none;
    }

    .ebook-practicas-menu {
        position: fixed;
        top: 96px;
        left: 8px;
        right: 8px;
        width: auto;
        max-width: none;
        max-height: calc(100dvh - 165px);
    }

    .ebook-mobile-dock {
        display: flex;
    }

    .ebook-statusbar {
        height: 26px;
        min-height: 26px;
        padding: 0 10px;
        font-size: 0.66rem;
        justify-content: center;
    }
}

/* Móviles en Orientación Horizontal (Landscape de poca altura <= 580px, incluso si el ancho es 952px+) */
@media (max-height: 580px) {
    .ebook-topbar[data-compact-nav="true"] {
        padding: 4px 10px;
        gap: 5px 8px;
    }

    .ebook-topbar[data-compact-nav="true"] .ebook-title-main {
        font-size: 0.76rem;
    }

    .ebook-topbar[data-compact-nav="true"] .ebook-title-sub {
        font-size: 0.62rem;
    }

    .ebook-topbar[data-compact-nav="true"] .ebook-btn {
        height: 32px;
        padding: 0 8px;
        font-size: 0.74rem;
    }

    /* Cuando se abren las Opciones en modo horizontal móvil, mostrar Índice + 10 Prácticas + Paginación + Zoom debajo del título sin encimarse */
    .ebook-topbar[data-compact-nav="true"].tools-open {
        grid-template-areas:
            "appbrand apptools"
            "quickmenus quickmenus"
            "navcontrols zoomcontrols";
        grid-template-columns: minmax(0, 1fr) auto;
    }

    .ebook-topbar[data-compact-nav="true"].tools-open .ebook-quick-menus {
        display: flex !important;
        width: 100%;
        padding-top: 5px;
        border-top: 1px solid var(--border-subtle);
    }

    .ebook-topbar[data-compact-nav="true"].tools-open .ebook-nav-controls {
        display: flex !important;
        justify-content: flex-start;
    }

    .ebook-topbar[data-compact-nav="true"].tools-open .ebook-zoom-controls {
        display: flex !important;
        justify-self: end;
    }

    /* En modo horizontal de baja altura, despejar barra de estado inferior para dar máxima altura a la hoja */
    .ebook-statusbar {
        display: none !important;
    }

    .ebook-stage-outer {
        padding: 6px 56px;
    }

    .ebook-drawer-backdrop {
        display: block;
    }

    .ebook-drawer {
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        width: 290px;
        max-width: 80vw;
        margin-left: 0 !important;
        transform: translateX(0);
        box-shadow: 16px 0 40px rgba(0, 0, 0, 0.8);
    }

    .ebook-drawer.collapsed {
        transform: translateX(-105%);
        box-shadow: none;
    }

    .ebook-practicas-menu {
        position: fixed;
        top: 52px;
        left: 10px;
        right: 10px;
        width: auto;
        max-width: 520px;
        max-height: calc(100dvh - 64px);
    }
}

/* Smartphones pequeños (<= 420px) */
@media (max-width: 420px) {
    .ebook-topbar[data-compact-nav="true"] {
        padding: 5px 6px;
        gap: 5px 6px;
    }

    .ebook-title-main {
        font-size: 0.72rem;
    }

    .ebook-title-sub {
        font-size: 0.60rem;
    }

    #lblToggleEbookHeaderTools {
        display: none;
    }

    .ebook-stage-outer {
        padding: 8px 12px;
    }

    .ebook-mobile-dock {
        padding: 5px 6px;
        padding-bottom: calc(5px + env(safe-area-inset-bottom, 0px));
        gap: 4px;
    }

    .ebook-mob-btn {
        width: 33px;
        height: 33px;
    }

    .ebook-mob-page-input {
        width: 38px;
        height: 30px;
        font-size: 0.76rem;
    }

    .ebook-mob-zoom-label {
        min-width: 36px;
        font-size: 0.68rem;
    }

    .ebook-mob-fit-btn {
        height: 33px;
        padding: 0 7px;
        font-size: 0.69rem;
    }
}

/* Bloqueo total de impresión (Ctrl+P) */
@media print {
    html, body {
        background: #000 !important;
    }
    body * {
        display: none !important;
        visibility: hidden !important;
    }
    body::after {
        content: "DOCUMENTO PROTEGIDO POR CIATSOFTWARE — LA DESCARGA E IMPRESIÓN ESTÁN DESHABILITADAS.";
        display: block !important;
        visibility: visible !important;
        padding: 48px;
        font-size: 20pt;
        font-weight: bold;
        color: #f59e0b;
        text-align: center;
    }
}

/* ==========================================================================
   SISTEMA DE TEMA MODO CLARO / MODO OSCURO - EBOOK: PLC DESDE CERO
   ========================================================================== */
html[data-ciat-theme="light"] {
    --bg-main: #d9dde2;
    --bg-panel: #e4e8ee;
    --bg-elevated: #eef2f6;
    --border-subtle: #b8c2cf;
    --border-accent: rgba(217, 119, 6, 0.55);
    --text-primary: #0f172a;
    --text-secondary: #334155;
    --text-muted: #475569;
}

html[data-ciat-theme="light"] body {
    background-color: #d9dde2 !important;
    color: #0f172a !important;
}

/* Modal de código de acceso en Modo Claro */
html[data-ciat-theme="light"] .ebook-gate-backdrop {
    background: rgba(203, 213, 225, 0.78) !important;
}
html[data-ciat-theme="light"] .ebook-gate-card {
    background: #e4e8ee !important;
    border-color: #adb8c7 !important;
    box-shadow: 0 25px 60px -15px rgba(15, 23, 42, 0.25) !important;
}
html[data-ciat-theme="light"] .ebook-gate-brand-main {
    color: #0f172a !important;
}
html[data-ciat-theme="light"] .ebook-gate-info {
    background: #eef2f6 !important;
    border-color: #cbd5e1 !important;
    color: #334155 !important;
}
html[data-ciat-theme="light"] .ebook-gate-info-lead,
html[data-ciat-theme="light"] .ebook-gate-info ul {
    color: #1e293b !important;
}
html[data-ciat-theme="light"] .ebook-gate-label {
    color: #334155 !important;
}
html[data-ciat-theme="light"] .ebook-gate-input {
    background: #ffffff !important;
    border-color: #94a3b8 !important;
    color: #b45309 !important;
}
html[data-ciat-theme="light"] .ebook-gate-footer {
    border-top-color: #cbd5e1 !important;
    color: #475569 !important;
}
html[data-ciat-theme="light"] .ebook-gate-footer a {
    color: #b45309 !important;
}

html[data-ciat-theme="light"] .ebook-shell {
    background:
        radial-gradient(circle at 15% 15%, rgba(245, 158, 11, 0.08), transparent 40%),
        radial-gradient(circle at 85% 85%, rgba(2, 132, 199, 0.08), transparent 40%),
        var(--bg-main);
}

html[data-ciat-theme="light"] .ebook-topbar,
html[data-ciat-theme="light"] .ebook-mobile-dock {
    background: rgba(228, 232, 238, 0.96);
    border-color: #b8c2cf;
    box-shadow: 0 2px 10px rgba(15, 23, 42, 0.08);
}

html[data-ciat-theme="light"] .ebook-title-main {
    color: #0f172a;
}

html[data-ciat-theme="light"] .ebook-title-sub {
    color: #b45309;
}

html[data-ciat-theme="light"] [data-ciat-app-trigger] {
    background: #eef2f6;
    border-color: #94a3b8;
}
html[data-ciat-theme="light"] [data-ciat-app-trigger]:hover,
html[data-ciat-theme="light"] [data-ciat-app-trigger].ciat-app-trigger-open {
    background: #dde3ec;
    border-color: #d97706;
}
html[data-ciat-theme="light"] .ciat-app-trigger-chevron {
    background: rgba(245, 158, 11, 0.22);
    border-color: #d97706;
    color: #92400e;
}

html[data-ciat-theme="light"] .ebook-nav-controls {
    background: #d5dce6;
    border-color: #adb8c7;
}

html[data-ciat-theme="light"] .ebook-btn:not(.ebook-btn-primary) {
    background: #eef2f6;
    border-color: #94a3b8;
    color: #0f172a;
}

html[data-ciat-theme="light"] .ebook-btn:not(.ebook-btn-primary):hover:not(:disabled) {
    background: #cbd5e1;
    border-color: #d97706;
    color: #0f172a;
}

html[data-ciat-theme="light"] .ebook-btn:not(.ebook-btn-primary).active {
    background: rgba(245, 158, 11, 0.24);
    border-color: #d97706;
    color: #78350f;
}

html[data-ciat-theme="light"] .ebook-btn-practicas {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.22), rgba(14, 165, 233, 0.18)) !important;
    border-color: #d97706 !important;
    color: #78350f !important;
}

html[data-ciat-theme="light"] .ebook-page-input {
    background: #ffffff;
    border-color: #94a3b8;
    color: #b45309;
}

html[data-ciat-theme="light"] .ebook-zoom-label {
    color: #1e293b;
    font-weight: 700;
}

html[data-ciat-theme="light"] .ebook-progress-track {
    background: #cbd5e1;
}

/* Menú superior y cajón lateral de prácticas/páginas en Modo Claro */
html[data-ciat-theme="light"] .ebook-practicas-menu {
    background: rgba(228, 232, 238, 0.99);
    border-color: #94a3b8;
    box-shadow: 0 20px 45px rgba(15, 23, 42, 0.22);
}
html[data-ciat-theme="light"] .ebook-practicas-menu-header .text-white,
html[data-ciat-theme="light"] .ebook-drawer-header .text-white {
    color: #0f172a !important;
}
html[data-ciat-theme="light"] .ebook-practicas-menu-header .text-slate-300,
html[data-ciat-theme="light"] .ebook-drawer-header .text-slate-400 {
    color: #475569 !important;
}

html[data-ciat-theme="light"] .ebook-drawer {
    background: #e4e8ee;
    border-right-color: #b8c2cf;
}

html[data-ciat-theme="light"] .ebook-drawer-tabs {
    background: #d5dce6;
    border-bottom-color: #b8c2cf;
}

html[data-ciat-theme="light"] .ebook-drawer-tab {
    color: #334155;
}
html[data-ciat-theme="light"] .ebook-drawer-tab:hover {
    background: #eef2f6;
    color: #0f172a;
}
html[data-ciat-theme="light"] .ebook-drawer-tab.active {
    background: #ffffff;
    border-color: #d97706;
    color: #b45309;
}

html[data-ciat-theme="light"] .ebook-practica-item {
    background: #eef2f6;
    border-color: #cbd5e1;
    color: #0f172a;
}
html[data-ciat-theme="light"] .ebook-practica-item:hover {
    background: #ffffff;
    border-color: #d97706;
}
html[data-ciat-theme="light"] .ebook-practica-item.active {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.22), #ffffff);
    border-color: #d97706;
}
html[data-ciat-theme="light"] .ebook-practica-title {
    color: #0f172a;
}
html[data-ciat-theme="light"] .ebook-practica-page-pill {
    background: #e2e8f0;
    border-color: #94a3b8;
    color: #b45309;
}

html[data-ciat-theme="light"] .ebook-page-chip {
    background: #eef2f6;
    border-color: #cbd5e1;
    color: #1e293b;
}
html[data-ciat-theme="light"] .ebook-page-chip:hover {
    background: #ffffff;
    border-color: #d97706;
    color: #0f172a;
}
html[data-ciat-theme="light"] .ebook-page-chip.active {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.25), #ffffff);
    border-color: #d97706;
    color: #b45309;
}

html[data-ciat-theme="light"] .ebook-canvas-frame {
    box-shadow:
        0 18px 42px -12px rgba(15, 23, 42, 0.28),
        0 0 0 1px rgba(15, 23, 42, 0.12);
}

html[data-ciat-theme="light"] .ebook-side-arrow {
    background: rgba(238, 242, 246, 0.92);
    border-color: #94a3b8;
    color: #0f172a;
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.16);
}
html[data-ciat-theme="light"] .ebook-side-arrow:hover:not(:disabled) {
    background: #ffffff;
    border-color: #d97706;
    color: #b45309;
}

html[data-ciat-theme="light"] .ebook-loader {
    background: rgba(217, 221, 226, 0.72);
}
html[data-ciat-theme="light"] #ebookLoaderText {
    color: #b45309 !important;
}

html[data-ciat-theme="light"] .ebook-statusbar {
    background: #d5dce6;
    border-top-color: #b8c2cf;
    color: #1e293b;
}
html[data-ciat-theme="light"] .ebook-statusbar .text-slate-400 {
    color: #334155 !important;
}
html[data-ciat-theme="light"] .ebook-statusbar .text-slate-200 {
    color: #0f172a !important;
}
