:root,
[data-pub-theme="light"] {
    --pub-bg: #fafafa;
    --pub-surface: #ffffff;
    --pub-sidebar-bg: #f8f9fa;
    --pub-sidebar-border: #e5e5e5;
    --pub-text: #212529;
    --pub-muted: #6c757d;
    --pub-accent: #0d6efd;
    --pub-login-grad: linear-gradient(135deg, #e3f2fd 0%, #f5f5f5 100%);
    --pub-pdf-bg: #555;
    --pub-timeline-bg: #eee;
    --pub-overlay-bg: #ffffff;
}

[data-pub-theme="dark"] {
    --pub-bg: #121418;
    --pub-surface: #1c1f26;
    --pub-sidebar-bg: #181a20;
    --pub-sidebar-border: #2a2d36;
    --pub-text: #e8eaed;
    --pub-muted: #9aa0a6;
    --pub-accent: #4c8dff;
    --pub-login-grad: linear-gradient(135deg, #1a2233 0%, #121418 100%);
    --pub-pdf-bg: #0f1115;
    --pub-timeline-bg: #2a2d36;
    --pub-overlay-bg: #121418;
}

body {
    min-height: 100vh;
    background: var(--pub-bg);
    color: var(--pub-text);
}

.app-shell {
    display: grid;
    grid-template-columns: 240px 1fr;
    min-height: 100vh;
}

.app-sidebar {
    background: var(--pub-sidebar-bg);
    border-right: 1px solid var(--pub-sidebar-border);
    padding: 1rem;
}

.app-main {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.app-topbar {
    background: var(--pub-surface);
    border-bottom: 1px solid var(--pub-sidebar-border);
    padding: .5rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.app-content {
    padding: 1rem;
    flex: 1;
}

.login-shell {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--pub-login-grad);
}

.login-card {
    width: 100%;
    max-width: 420px;
}

.publicacion-card {
    transition: transform .15s, box-shadow .15s;
}
.publicacion-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 .5rem 1rem rgba(0,0,0,.1);
}

.pub-icon {
    width: 64px;
    text-align: center;
}

.pdf-container {
    position: relative;
    max-height: 80vh;
    overflow: auto;
    background: var(--pub-pdf-bg);
    padding: 8px;
    border-radius: 4px;
}
.pdf-page-wrapper {
    position: relative;
    margin: 0 auto 8px auto;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,.5);
}
.pdf-annotation-layer {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    pointer-events: none;
}
.pdf-pin {
    position: absolute;
    width: 20px; height: 20px;
    border-radius: 50%;
    transform: translate(-50%, -100%);
    border: 2px solid #fff;
    box-shadow: 0 2px 4px rgba(0,0,0,.3);
    pointer-events: auto;
    cursor: pointer;
}
.pdf-highlight {
    position: absolute;
    opacity: .35;
    mix-blend-mode: multiply;
    pointer-events: none;
}
.pdf-pin-flash {
    animation: pdf-pin-flash 1.6s ease-out;
}
@keyframes pdf-pin-flash {
    0%   { box-shadow: 0 0 0 0 rgba(255,193,7,.9); transform: translate(-50%, -100%) scale(1); }
    30%  { box-shadow: 0 0 0 16px rgba(255,193,7,0); transform: translate(-50%, -100%) scale(1.6); }
    100% { box-shadow: 0 0 0 0 rgba(255,193,7,0);  transform: translate(-50%, -100%) scale(1); }
}

.video-timeline {
    position: relative;
    height: 24px;
    background: var(--pub-timeline-bg);
    border-radius: 3px;
}
.video-timeline-mark {
    position: absolute;
    top: 2px;
    width: 3px;
    height: 20px;
    background: var(--pub-accent);
    cursor: pointer;
}

.anotacion-item {
    font-size: .9rem;
}

.tag-input .badge {
    font-size: .75rem;
}

/* ===== Visor pantalla completa ===== */
.viewer-fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 1050;
    background: var(--pub-overlay-bg);
    overflow: hidden;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: row;
}
.viewer-fullscreen-main {
    flex: 1 1 auto;
    width: 100%;
    height: 100%;
    position: relative;
    overflow: auto;
    min-width: 0;
}
.viewer-fullscreen-close {
    position: fixed;
    top: 8px;
    right: 8px;
    z-index: 1060;
    box-shadow: 0 2px 6px rgba(0,0,0,.25);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.viewer-fullscreen.viewer-fullscreen-with-panel .viewer-fullscreen-close {
    right: calc(var(--pub-fs-side, 380px) + 8px);
}
.viewer-fullscreen .card {
    height: 100%;
    border: 0;
    border-radius: 0;
    margin: 0;
}
.viewer-fullscreen .card-body {
    height: 100%;
    padding: 0;
}
.viewer-fullscreen iframe,
.viewer-fullscreen video {
    width: 100% !important;
    height: 100vh !important;
    max-height: none !important;
    border: 0 !important;
    border-radius: 0 !important;
}
.viewer-fullscreen img {
    max-width: 100% !important;
    max-height: 100vh !important;
}
.viewer-fullscreen .pdf-container {
    max-height: 100vh !important;
    height: 100vh;
    border-radius: 0;
}

/* En pantalla completa, ocultar el aviso informativo del embed y hacer que el iframe use todo el alto disponible */
.viewer-fullscreen .video-embed-info {
    display: none !important;
}
.viewer-fullscreen .ratio {
    max-height: none !important;
    height: 100vh !important;
}
.viewer-fullscreen .ratio::before {
    display: none !important;
}

/* Panel lateral de anotaciones en pantalla completa */
.viewer-fullscreen-side {
    flex: 0 0 var(--pub-fs-side, 380px);
    width: var(--pub-fs-side, 380px);
    max-width: 100vw;
    height: 100vh;
    background: var(--pub-surface);
    border-left: 1px solid var(--pub-sidebar-border);
    display: flex;
    flex-direction: column;
    box-shadow: -4px 0 12px rgba(0,0,0,.15);
    z-index: 1055;
}
.viewer-fullscreen-side-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .5rem .75rem;
    border-bottom: 1px solid var(--pub-sidebar-border);
    background: var(--pub-surface);
    color: var(--pub-text);
}
.viewer-fullscreen-side-body {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: .5rem;
}

@media (max-width: 768px) {
    .viewer-fullscreen-side {
        flex: 0 0 100%;
        width: 100%;
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
    }
    .viewer-fullscreen.viewer-fullscreen-with-panel .viewer-fullscreen-main {
        display: none;
    }
    .viewer-fullscreen.viewer-fullscreen-with-panel .viewer-fullscreen-close {
        right: 8px;
    }
}

/* ===== Ajustes tema oscuro ===== */
[data-pub-theme="dark"] {
    /* Overrides de variables Bootstrap para que titulos y body hereden bien */
    --bs-body-color: var(--pub-text);
    --bs-heading-color: var(--pub-text);
    --bs-emphasis-color: var(--pub-text);
    --bs-secondary-color: var(--pub-muted);
    --bs-tertiary-color: var(--pub-muted);
    color-scheme: dark;
}
[data-pub-theme="dark"] body,
[data-pub-theme="dark"] h1,
[data-pub-theme="dark"] h2,
[data-pub-theme="dark"] h3,
[data-pub-theme="dark"] h4,
[data-pub-theme="dark"] h5,
[data-pub-theme="dark"] h6,
[data-pub-theme="dark"] .h1,
[data-pub-theme="dark"] .h2,
[data-pub-theme="dark"] .h3,
[data-pub-theme="dark"] .h4,
[data-pub-theme="dark"] .h5,
[data-pub-theme="dark"] .h6,
[data-pub-theme="dark"] p,
[data-pub-theme="dark"] label,
[data-pub-theme="dark"] legend,
[data-pub-theme="dark"] dt,
[data-pub-theme="dark"] dd,
[data-pub-theme="dark"] figcaption {
    color: var(--pub-text);
}
[data-pub-theme="dark"] .text-dark,
[data-pub-theme="dark"] .text-body,
[data-pub-theme="dark"] .text-body-emphasis,
[data-pub-theme="dark"] .text-black {
    color: var(--pub-text) !important;
}
[data-pub-theme="dark"] .bg-light {
    background-color: var(--pub-surface) !important;
    color: var(--pub-text);
}
[data-pub-theme="dark"] .bg-white {
    background-color: var(--pub-surface) !important;
    color: var(--pub-text) !important;
}
[data-pub-theme="dark"] .text-muted,
[data-pub-theme="dark"] .text-body-secondary {
    color: var(--pub-muted) !important;
}
[data-pub-theme="dark"] .badge.bg-light.text-dark {
    background-color: #2a2d36 !important;
    color: var(--pub-text) !important;
    border-color: #3a3d46 !important;
}
[data-pub-theme="dark"] .alert-light {
    background-color: #1c1f26;
    border-color: #2a2d36;
    color: var(--pub-text);
}
[data-pub-theme="dark"] .alert-info {
    background-color: #132236;
    border-color: #1f3a5c;
    color: #cfe2ff;
}
[data-pub-theme="dark"] .alert-warning {
    background-color: #3a2e10;
    border-color: #5a4617;
    color: #ffe69c;
}
[data-pub-theme="dark"] .alert-danger {
    background-color: #3a1519;
    border-color: #5a1f26;
    color: #f5c2c7;
}
[data-pub-theme="dark"] .alert-success {
    background-color: #133320;
    border-color: #1f5233;
    color: #a3cfbb;
}
[data-pub-theme="dark"] .form-text {
    color: var(--pub-muted);
}
[data-pub-theme="dark"] .card {
    background-color: var(--pub-surface);
    border-color: var(--pub-sidebar-border);
    color: var(--pub-text);
}
[data-pub-theme="dark"] .card-header,
[data-pub-theme="dark"] .card-footer {
    background-color: var(--pub-surface);
    border-color: var(--pub-sidebar-border);
    color: var(--pub-text);
}
[data-pub-theme="dark"] .modal-content {
    background-color: var(--pub-surface);
    color: var(--pub-text);
    border-color: var(--pub-sidebar-border);
}
[data-pub-theme="dark"] .modal-header,
[data-pub-theme="dark"] .modal-footer {
    border-color: var(--pub-sidebar-border);
}
[data-pub-theme="dark"] .modal-title {
    color: var(--pub-text);
}
[data-pub-theme="dark"] .btn-close {
    filter: invert(1) grayscale(100%) brightness(200%);
}
[data-pub-theme="dark"] .table {
    --bs-table-bg: transparent;
    --bs-table-color: var(--pub-text);
    --bs-table-striped-bg: rgba(255,255,255,0.04);
    --bs-table-striped-color: var(--pub-text);
    --bs-table-hover-bg: rgba(255,255,255,0.06);
    --bs-table-hover-color: var(--pub-text);
    --bs-table-border-color: var(--pub-sidebar-border);
    color: var(--pub-text);
}
[data-pub-theme="dark"] .form-control,
[data-pub-theme="dark"] .form-select {
    background-color: #1c1f26;
    border-color: #2a2d36;
    color: var(--pub-text);
}
[data-pub-theme="dark"] .form-control::placeholder {
    color: var(--pub-muted);
}
[data-pub-theme="dark"] .form-control:focus,
[data-pub-theme="dark"] .form-select:focus {
    background-color: #1c1f26;
    color: var(--pub-text);
    border-color: var(--pub-accent);
    box-shadow: 0 0 0 .2rem rgba(76,141,255,.25);
}
[data-pub-theme="dark"] .input-group-text {
    background-color: #2a2d36;
    border-color: #2a2d36;
    color: var(--pub-text);
}
[data-pub-theme="dark"] .nav-link {
    color: var(--pub-text);
}
[data-pub-theme="dark"] .nav-link.active {
    background-color: rgba(76,141,255,.18);
    color: var(--pub-text);
}
[data-pub-theme="dark"] .dropdown-menu {
    background-color: var(--pub-surface);
    border-color: var(--pub-sidebar-border);
    color: var(--pub-text);
}
[data-pub-theme="dark"] .dropdown-item {
    color: var(--pub-text);
}
[data-pub-theme="dark"] .dropdown-item:hover,
[data-pub-theme="dark"] .dropdown-item:focus {
    background-color: rgba(255,255,255,0.06);
    color: var(--pub-text);
}
[data-pub-theme="dark"] .navbar.bg-dark {
    background-color: #0b0d11 !important;
}
[data-pub-theme="dark"] code,
[data-pub-theme="dark"] pre {
    color: #ffb86c;
}
[data-pub-theme="dark"] hr {
    border-color: var(--pub-sidebar-border);
}
[data-pub-theme="dark"] .btn-outline-secondary {
    color: var(--pub-text);
    border-color: #4a4d56;
}
[data-pub-theme="dark"] .btn-outline-secondary:hover {
    background-color: #2a2d36;
    color: var(--pub-text);
    border-color: #4a4d56;
}
[data-pub-theme="dark"] .btn-light {
    background-color: #2a2d36;
    border-color: #2a2d36;
    color: var(--pub-text);
}
[data-pub-theme="dark"] .btn-light:hover {
    background-color: #3a3d46;
    color: var(--pub-text);
}
[data-pub-theme="dark"] .login-shell .card {
    background-color: var(--pub-surface);
}

/* Toggle icon: luna en light, sol en dark. CSS-only, sobrevive a re-renders. */
.pub-theme-icon-light { display: inline-block; }
.pub-theme-icon-dark { display: none; }
[data-pub-theme="dark"] .pub-theme-icon-light { display: none; }
[data-pub-theme="dark"] .pub-theme-icon-dark { display: inline-block; }
