:root {
    --bg-primary: #0f0f0f;
    --bg-secondary: #1a1a1a;
    --bg-card: #242424;
    --text-primary: #ffffff;
    --text-secondary: #b3b3b3;
    --accent: #ff6b35; /* Color principal de Exploradores */
    --accent-hover: #ff8257;
    --border: #333333;
    --shadow: rgba(0, 0, 0, 0.5);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    overflow-x: hidden;
    overscroll-behavior-y: contain;
    /* NUEVO: Ocultar la barra de desplazamiento vertical */
    overflow-y: scroll; /* Keep scroll functionality */
    -ms-overflow-style: none; /* IE and Edge */
    scrollbar-width: none; /* Firefox */
}

/* NUEVO: Ocultar la barra de desplazamiento vertical para Webkit (Chrome, Safari) */
body::-webkit-scrollbar {
    display: none;
}

/* NUEVO: Evita el scroll del fondo cuando un modal está abierto */
body.modal-open {
    overflow: hidden;
}

.header {
    background: var(--bg-secondary);
    padding: 1rem;
    position: sticky;
    top: 0;
    z-index: 100;
    border-bottom: 1px solid var(--border);
}

.header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 1rem;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    /* NEW: Font and color for header H1 */
    font-family: 'Press Start 2P', cursive;
    color: var(--accent);
}

.search-modal-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1rem;
    padding: 0.5rem;
    border-radius: 50%;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 40px;
}

.search-modal-btn:hover {
    background: var(--bg-card);
    color: var(--accent);
    transform: scale(1.1);
}

.controls {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.controls-single-row {
    display: flex;
    gap: 0.4rem;
    align-items: center;
}

.search-box {
    flex: 1;
    min-width: 0;
    padding: 0.75rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 1rem;
    flex-shrink: 1;
}

.search-box:focus {
    outline: none;
    border-color: var(--accent);
}

.control-btn {
    padding: 0.5rem;
    background: var(--bg-card);
    color: var(--text-secondary);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.8rem;
    min-width: 35px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    flex-shrink: 0;
}

.control-btn:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.control-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.sort-select {
    padding: 0.5rem 0.3rem;
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.8rem !important; /* match control-btn size */
    min-width: 40px;
    flex-shrink: 0;
}

.sort-select:focus {
    outline: none;
    border-color: var(--accent);
}

.refresh-btn {
    padding: 0.5rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    min-width: 35px;
    flex-shrink: 0;
}

.refresh-btn:hover {
    background: var(--accent-hover);
}

.refresh-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* MODIFICADO: Estilos para el overlay de carga/estado */
/* Overlay-style full-screen status (used for global loading/errors) */
.status {
    position: fixed; /* Make it an overlay */
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8); /* Dark semi-transparent background */
    z-index: 1001; /* Above other content, including modals if they exist */
    display: flex; /* Use flexbox for centering */
    align-items: center; /* Center vertically */
    justify-content: center; /* Center horizontally */
    flex-direction: column; /* Stack spinner and text */
    gap: 1rem; /* Space between spinner and text */

    font-size: 1.1rem; /* Slightly larger text for overlay */
    color: var(--text-primary); /* Use primary text color for better visibility */
}

/* Ensure inline/status blocks that are inserted inside content areas (e.g. "No se encontraron...") 
   or .empty-state / .loading elements are centered within their parent and look consistent.
   This also covers notices rendered inside the grid or results containers. */
.movie-grid .status,
.movie-grid > .status,
.movie-grid > .empty-state,
.results .status,
.results .empty-state,
.empty-state,
.loading,
.error-message,
.imdb-no-results {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    min-height: 180px; /* ensure vertical centering space */
    padding: 1rem;
    gap: 0.5rem;
}

.loading { /* This class is now primarily for the color of the text within the overlay */
    color: var(--accent);
}

.movie-grid {
    padding: 1rem;
    display: grid;
    gap: 1rem;
    grid-template-columns: 1fr;
}

/* Vista lista */
.movie-grid.list-view {
    display: block;
    padding: 0;
}

.movie-list-item {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background-color 0.2s;
}

.movie-list-item:hover {
    background: var(--bg-card);
}

.list-poster-container {
    flex-shrink: 0;
    width: 40px;
    height: 60px;
    margin-right: 1rem;
    border-radius: 4px;
    overflow: hidden;
    background: var(--bg-card);
    display: flex;
    align-items: center;
    justify-content: center;
}

.list-poster {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.list-poster-placeholder {
    color: var(--text-secondary);
    font-size: 1.2rem;
}

.list-info {
    flex: 1;
    min-width: 0;
}

.list-title {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.list-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.list-separator {
    color: var(--border);
}

/* Vista cuadrícula */
.movie-card {
    background: var(--bg-card);
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid var(--border);
    transition: transform 0.2s, box-shadow 0.2s;
    cursor: pointer;
    position: relative;
}

.movie-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px var(--shadow);
}

/* Ocultar el uploader en modo cuadrícula */
.movie-card .movie-description {
    display: none;
}

.movie-content {
    display: flex;
    padding: 1rem;
    gap: 1rem;
}

.poster-container {
    flex-shrink: 0;
    width: 80px;
    height: 120px;
    background: linear-gradient(135deg, var(--accent), #ff8c66);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}

.poster-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 8px;
}

.poster-placeholder {
    color: white;
    font-size: 2rem;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

.movie-info {
    flex: 1;
    min-width: 0;
}

.movie-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.movie-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
}

.movie-year {
    color: var(--accent);
    font-weight: 500;
}

.movie-category {
    background: var(--bg-secondary);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.movie-description {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.4;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.movie-date {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.5rem;
}

.movie-author {
    color: var(--text-secondary);
}

.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 0.5rem;
    padding: 2rem 1rem;
}

.page-btn {
    padding: 0.5rem 1rem;
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    min-width: 40px;
    text-align: center;
}

.page-btn:hover {
    background: var(--bg-secondary);
}

.page-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.page-info {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin: 0 1rem;
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    overflow-y: auto;
}

.modal-content {
    background: var(--bg-card);
    margin: 2rem auto;
    padding: 1.5rem;
    border-radius: 12px;
    max-width: 90vw;
    max-height: 95vh; /* Increased max-height */
    overflow-y: auto;
    position: relative;
}

.search-modal-content {
    max-width: 500px;
    max-height: none;
}

.search-modal-content h3 {
    margin-bottom: 1.5rem;
    color: var(--accent);
    text-align: center;
}

.search-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.search-input {
    width: 100%;
    padding: 0.75rem;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 1rem;
}

.search-input:focus {
    outline: none;
    border-color: var(--accent);
}

.search-buttons {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
}

.search-btn {
    padding: 0.75rem 1.5rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: background-color 0.2s;
}

.search-btn:hover {
    background: var(--accent-hover);
}

.back-btn {
    padding: 0.75rem 1.5rem;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    transition: background-color 0.2s;
}

.back-btn:hover {
    background: var(--bg-card);
}

.modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
}

.modal-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 1.5rem;
}

.modal-poster {
    width: 150px;
    height: 225px;
    object-fit: cover;
    border-radius: 8px;
    margin-bottom: 1rem;
    cursor: pointer; 
}

.modal-title {
    font-size: 1.5rem;
    font-weight: 700;
    text-align: center;
    line-height: 1.3;
}

.modal-description {
    line-height: 1.6;
    color: var(--text-secondary);
}

.synopsis-block {
    position: relative;
    margin-top: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem; /* vertical separation between text and buttons */
}

/* Container for the inline action buttons shown under the synopsis */
.synopsis-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap; /* keep buttons on one line when possible, wrap on small screens */
}

/* New layout: place actions (buttons) at left and the source label at right, vertically centered */
.synopsis-actions-row {
    display: flex;
    align-items: center; /* vertical center */
    justify-content: space-between; /* buttons left, source right */
    gap: 0.75rem;
    margin-top: 0.5rem; /* space above the row */
}

/* Ensure the source text doesn't shrink awkwardly and remains vertically centered */
.synopsis-source {
    flex: 0 0 auto;
    font-size: 0.9rem;
    color: var(--text-secondary);
    white-space: nowrap;
    margin-left: 0.5rem;
    align-self: center;
}

/* Ensure existing button sizing rules still apply to action buttons */
.synopsis-actions button {
    min-height: 36px;
    padding: 6px 10px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.translate-toggle-btn {
    margin-top: 0; /* align with other inline buttons */
    vertical-align: middle;
    /* Google Translate style blue button */
    background: #1a73e8;
    border: none;
    color: #ffffff;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 6px 10px;
    border-radius: 6px;
    transition: background-color 0.15s ease, color 0.15s ease;
}
 
/* Ensure small action buttons next to the translate button keep stable dimensions
   when toggled/disabled/pressed (prevents vertical jump on click). */
.synopsis-block button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 6px 10px;
    line-height: 1;
    font-size: 0.9rem;
    border-radius: 6px;
    min-height: 36px; /* fixed minimum height to avoid vertical growth */
    box-sizing: border-box;
    vertical-align: middle; /* ensure buttons align on the same baseline */
    transition: opacity 0.12s ease, transform 0.08s ease;
}

.synopsis-block button.loading {
    opacity: 0.6;
    cursor: default;
    transform: none; /* ensure no transform applied while loading */
}

/* Keep disabled buttons visually consistent */
.synopsis-block button:disabled {
    opacity: 0.6;
    cursor: default;
}

.translate-toggle-btn:hover {
    background: #1669c1;
    color: #ffffff;
}

.translate-toggle-btn i {
    font-size: 1rem;
}

.translate-toggle-btn.loading {
    opacity: 0.6;
    cursor: default;
}

/* Synopsis source buttons (IMDb / TMDb) - transparent by default, active is IMDb-yellow */
.synopsis-source-btn {
    margin-left: 8px;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid rgba(255,255,255,0.04);
    padding: 6px 10px;
    border-radius: 6px;
    font-weight: 700;
    cursor: pointer;
    font-size: 0.9rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    transition: background-color 0.12s, color 0.12s, border-color 0.12s;
}

.synopsis-source-btn:hover {
    background: rgba(255,255,255,0.02);
    color: var(--text-primary);
}

.synopsis-source-btn.active {
    background: #f5c518; /* IMDb-like yellow for active */
    color: #000;
    border-color: #f5c518;
}

/* Ensure the specific IMDb and TMDb synopsis buttons have a prominent yellow border by default */
#imdbFetchBtn,
#tmdbFetchBtn {
    border-color: #f5c518 !important;
    box-shadow: 0 0 0 2px rgba(245,197,24,0.07);
    color: #fff;
}

/* Keep hover/active behavior coherent when forced border is present */
#imdbFetchBtn:hover,
#tmdbFetchBtn:hover {
    background: rgba(245,197,24,0.08);
    color: #fff;
}

#imdbFetchBtn.active,
#tmdbFetchBtn.active {
    background: #f5c518;
    color: #000;
    border-color: #f5c518;
}

/* Back-to-top button placed next to synopsis source label */
.back-to-top-btn {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.06);
    color: var(--text-secondary);
    width: 28px;              /* reduced size */
    height: 28px;             /* reduced size */
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.12s, color 0.12s, transform 0.08s;
    flex: 0 0 auto;
    padding: 0;
    font-size: 0.78rem;       /* slightly smaller icon */
}

.back-to-top-btn:hover {
    background: rgba(255,255,255,0.03);
    color: var(--accent);
    transform: translateY(-1px);
}

.back-to-top-btn i {
    margin: 0;
    font-size: 0.95rem;
}

.message-modal-content {
    max-width: 400px;
    padding: 2rem;
    text-align: center;
}

.message-modal-content p {
    font-size: 1.1rem;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

.message-modal-ok-btn {
    padding: 0.75rem 2rem;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    transition: background-color 0.2s;
}

.message-modal-ok-btn:hover {
    background: var(--accent-hover);
}

@media (min-width: 768px) {
    .movie-grid {
        grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
        padding: 2rem;
        gap: 1.5rem;
    }
    .modal-content {
        max-width: 700px;
    }
    .search-modal-content {
        max-width: 600px;
    }
    .controls-single-row {
        gap: 0.6rem;
    }
    .control-btn {
        min-width: 40px;
        padding: 0.6rem;
        font-size: 0.85rem;
    }
    .sort-select {
        min-width: 50px;
        padding: 0.6rem;
        font-size: 0.85rem !important; /* match control-btn size on wider screens */
    }
    .refresh-btn {
        min-width: 40px;
        padding: 0.6rem;
    }
    .search-box {
        max-width: 70%;
    }
}

/* NEW: Styles for vertical mobile screens to keep header on one line */
@media (max-width: 500px) {
    .header h1 {
        font-size: 1.0rem; /* Smaller font size for the header title */
        gap: 0.2rem; /* Reduce gap between text and button */
    }

    .search-modal-btn {
        min-width: 30px; 
        height: 30px; 
        font-size: 0.8rem; 
        padding: 0.1rem; 
    }

    .header {
        padding: 0.8rem 0.4rem; 
    }

    .controls-single-row {
        gap: 0.2rem; 
    }

    .search-box {
        padding: 0.5rem;
        font-size: 0.8rem;
        margin-left: 2px;
    }

    .control-btn,
    .sort-select,
    .refresh-btn {
        padding: 0.35rem;
        font-size: 0.65rem;
        min-width: 28px;
    }
}

.error {
    color: #ff6b6b;
    background: rgba(255, 107, 107, 0.1);
    padding: 1rem;
    border-radius: 8px;
    text-align: center;
}

.stats {
    display: flex;
    justify-content: center; /* Centramos el contenido */
    align-items: center;
    padding: 1rem; /* Aumentamos el padding */
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    font-size: 0.9rem; /* Aumentamos el tamaño de fuente */
    color: var(--text-secondary);
}

.loading-spinner {
    display: inline-block;
    width: 40px; /* Tamaño del spinner más grande para el overlay */
    height: 40px; /* Tamaño del spinner más grande para el overlay */
    border: 4px solid var(--border); /* Borde más grueso */
    border-radius: 50%;
    border-top-color: var(--accent);
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.modal-trailer-container {
    position: relative;
    overflow: hidden;
    width: 100%;
    padding-top: 56.25%; /* 16:9 Aspect Ratio */
    margin-top: 1rem;
    border-radius: 8px;
}

.modal-trailer-container iframe {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    width: 100%;
    height: 100%;
    border: none;
}

.modal-details-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
    padding: 1rem;
    background-color: var(--bg-secondary);
    border-radius: 8px;
}

.detail-item {
    font-size: 0.9rem;
}

.detail-item strong {
    display: block;
    color: var(--text-primary);
    font-weight: 600;
    margin-bottom: 0.25rem;
}

/* Ensure detail values can be limited to a single truncated line (used for País) */
.detail-value {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.fullscreen-poster-modal {
    display: none; 
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.9);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.fullscreen-poster-modal img {
    max-width: 90%;
    max-height: 90%;
    object-fit: contain;
    transform-origin: center center; /* Essential for correct zoom behavior */
    cursor: zoom-in; /* Default state for potential zoom */
}

/* Cursor style for when the image is zoomed and can be dragged */
.fullscreen-poster-modal img[style*="scale"]:not([style*="scale(1)"]) {
    cursor: grab;
}

/* Cursor style when actively dragging/panning a zoomed image */
.fullscreen-poster-modal img.panning {
    cursor: grabbing !important; /* Use !important to override other cursor rules during active pan */
}

.fullscreen-poster-close {
    position: absolute;
    top: 20px;
    right: 30px;
    font-size: 40px;
    color: white;
    background: none;
    border: none;
    cursor: pointer;
}

/* Modal action rows: first row distributes buttons evenly, second row centers export button */
.modal-action-row {
    display: flex;
    gap: 0.6rem;
    justify-content: space-between; /* distribute items equally across row */
    align-items: center;
    width: 100%;
    max-width: 640px; /* keeps a comfortable width on large screens */
    margin: 0 auto;
    box-sizing: border-box;
}

.modal-action-row a,
.modal-action-row button {
    flex: 1 1 0; /* allow equal width */
    text-align: center;
    padding: 8px 10px;
    border-radius: 6px;
    font-weight: 700;
    text-decoration: none;
    border: 1px solid transparent;
    min-width: 0;
}

.modal-action-row a { display: inline-flex; justify-content:center; align-items:center; gap:0.5rem; }

.modal-action-row.export-row {
    margin-top: 25px;
    justify-content: center; /* center the export button row */
}

/* Make the export button span the full width available inside the modal-action-row,
   keeping the modal's internal spacing consistent with other controls. */
.modal-action-row.export-row button {
    flex: 1 1 100%;
    max-width: 100%;
    margin: 0;
    display: inline-flex;
    justify-content: center;
    align-items: center;
}

/* Modal-specific loading styling: center and improve the "Cargando detalles..." block
   when it's rendered inside modal content (does not affect global full-screen status). */
.modal .status {
    position: static; /* flow inside modal rather than full-screen overlay */
    top: auto;
    left: auto;
    right: auto;
    bottom: auto;
    background: transparent;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 1.25rem 1.5rem;
    min-height: 160px;
    color: var(--text-primary);
    box-shadow: none;
    border-radius: 10px;
}

/* Slightly larger spinner inside modal for better visibility */
.modal .status .loading-spinner {
    width: 48px;
    height: 48px;
    border: 5px solid var(--border);
    border-top-color: var(--accent);
}

/* Subtle text styling for the loading label inside modal */
.modal .status span {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-top: 4px;
    text-align: center;
}