/* ============================================
   STYLES.CSS - RTBROK CATÁLOGO GENERATOR
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap');

/* ============================================
   RESET & BASE
   ============================================ */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Roboto', sans-serif;
    background-color: #f8fafc;
    overflow: hidden;
    height: 100vh;
    height: 100dvh;
    padding-bottom: env(safe-area-inset-bottom);
}

.app-container {
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ============================================
   RTBROK SIDEBAR / DARK WORKSPACE THEME
   ============================================ */
.rtbrok-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 220px;
    height: 100vh;
    height: 100dvh;
    padding: 20px 12px;
    background: #080b10;
    border-right: 1px solid #1b2028;
    display: flex;
    flex-direction: column;
    z-index: 40;
}

.rtbrok-sidebar-brand {
    display: flex;
    align-items: center;
    height: 58px;
    padding: 0 12px;
    margin-bottom: 10px;
    color: #f4f4f5;
    font-family: Georgia, serif;
    font-size: 30px;
    letter-spacing: -1px;
}

.rtbrok-sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.rtbrok-sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    min-height: 48px;
    padding: 8px 10px;
    color: #d4d4d8;
    background: transparent;
    border: 0;
    border-radius: 0;
    text-decoration: none;
    text-align: left;
    font-family: 'Roboto', sans-serif;
    cursor: pointer;
    transition: background .15s ease, color .15s ease;
}

.rtbrok-sidebar-link:hover,
.rtbrok-sidebar-link.active {
    color: #fff;
    background: #1a1f28;
}

.rtbrok-sidebar-link.active {
    cursor: default;
}

.rtbrok-sidebar-link .icon-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 30px;
    width: 30px;
    height: 30px;
    color: #a1a1aa;
    font-size: 18px;
}

.rtbrok-sidebar-link:hover .icon-wrap,
.rtbrok-sidebar-link.active .icon-wrap {
    color: #fff;
}

.rtbrok-sidebar-link > span:last-child {
    font-size: 13px;
    font-weight: 500;
    letter-spacing: .01em;
}

.workspace-area {
    position: relative;
    padding-left: 220px;
    background: #070a0e;
}

.workspace-area > .home-screen,
.workspace-area > .main-content {
    background: #0d1117;
}

header {
    margin-left: 220px;
    background: #080b10 !important;
    border-bottom-color: #1b2028 !important;
    color: #f4f4f5;
}

header .text-slate-900,
header .text-slate-700,
header .text-slate-600 {
    color: #f4f4f5 !important;
}

header .text-slate-500,
header .text-gray-400 {
    color: #a1a1aa !important;
}

header .border-gray-300,
header .border-gray-200 {
    border-color: #1f242c !important;
}

header .bg-gray-50 {
    background: #11161d !important;
    border-color: #2a2f38 !important;
    color: #f4f4f5;
}

.home-screen {
    background: #0d1117;
}

.home-screen .logo {
    color: #f4f4f5;
}

.home-screen .subtitle,
.home-screen h2 {
    color: #a1a1aa;
}

.catalog-card,
.personalized-catalog-card,
.results-header,
.grid-card {
    background: #11161d;
    border-color: #1f242c;
    color: #e4e4e7;
}

.catalog-card .name-input {
    color: #f4f4f5;
    border-bottom-color: #3f4652;
}

.btn-create-catalog {
    background: #1a1f28;
}

.btn-create-catalog:hover {
    background: #252c37;
}

.filter-panel-full,
.config-panel-content {
    background: #0d1117;
    color: #e4e4e7;
}

.filter-header,
.filter-actions,
.config-section,
.config-input,
.config-textarea,
.filter-select {
    border-color: #1f242c;
}

.config-section,
.filter-select,
.config-input,
.config-textarea {
    background: #11161d;
    color: #e4e4e7;
}

@media (max-width: 640px) {
    .rtbrok-sidebar {
        display: none;
    }

    .workspace-area {
        padding-left: 0;
    }

    header {
        margin-left: 0;
    }
}

/* Legibilidad sobre el tema oscuro. Tailwind utilities de los elementos
   renderizados dinámicamente necesitan prioridad para no volver al gris oscuro. */
.home-screen .logo,
.home-screen .subtitle,
.home-screen h2,
.home-screen .text-slate-900,
.home-screen .text-slate-800,
.home-screen .text-slate-700,
.home-screen .text-slate-600,
.home-screen .text-slate-500,
.home-screen .text-slate-400,
.home-screen .text-gray-400,
.catalog-card,
.personalized-catalog-card,
.catalog-card .name-input,
.personalized-catalog-card .text-slate-800,
.catalog-card .edit-hint,
.catalog-card .text-slate-900,
.catalog-card .text-slate-800,
.catalog-card .text-slate-700,
.catalog-card .text-slate-600,
.catalog-card .text-slate-500,
.catalog-card .text-slate-400 {
    color: #f4f4f5 !important;
}

.home-screen .subtitle,
.home-screen .text-slate-500,
.home-screen .text-slate-400,
.home-screen .text-gray-400,
.catalog-card .edit-hint,
.personalized-catalog-card .text-slate-400,
.catalog-card .text-slate-500,
.catalog-card .text-slate-400 {
    color: #a1a1aa !important;
}

.catalog-card .text-slate-700,
.catalog-card .text-slate-600,
.personalized-catalog-card .text-slate-800 {
    color: #d4d4d8 !important;
}

.filter-panel-full .text-slate-900,
.filter-panel-full .text-slate-800,
.filter-panel-full .text-slate-700,
.filter-panel-full .text-slate-600,
.filter-panel-full .text-slate-500,
.filter-panel-full .text-slate-400,
.config-panel-content .text-slate-900,
.config-panel-content .text-slate-800,
.config-panel-content .text-slate-700,
.config-panel-content .text-slate-600,
.config-panel-content .text-slate-500,
.config-panel-content .text-slate-400,
.main-content .text-slate-900,
.main-content .text-slate-800,
.main-content .text-slate-700,
.main-content .text-slate-600,
.main-content .text-slate-500,
.main-content .text-slate-400 {
    color: #e4e4e7 !important;
}

.filter-panel-full .text-slate-500,
.filter-panel-full .text-slate-400,
.config-panel-content .text-slate-500,
.config-panel-content .text-slate-400,
.main-content .text-slate-500,
.main-content .text-slate-400 {
    color: #a1a1aa !important;
}

.results-toolbar-btn,
.select-all-btn,
.order-select,
.pdf-config-bar .config-group label,
.page-layout-btn,
.view-toggle button,
.filter-label {
    color: #d4d4d8;
}

.results-toolbar-btn:hover,
.select-all-btn:hover,
.view-toggle button:hover:not(.active) {
    color: #ffffff;
}

.results-toolbar-btn:hover,
.results-toolbar-btn:not(.results-toolbar-btn-primary):hover,
.select-all-btn:hover {
    background: #1a1f28;
    border-color: #2a2f38;
}

.pdf-config-bar .config-group,
.page-layout-btn,
.view-toggle {
    background: #1a1f28;
    border-color: #2a2f38;
}

.view-toggle button.active,
.page-layout-btn.active {
    background: #2a2f38;
    color: #ffffff;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* ============================================
   HEADER
   ============================================ */
header {
    background: white;
    border-bottom: 1px solid #e5e7eb;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 12px;
    flex-shrink: 0;
    z-index: 20;
    gap: 8px;
}

@media (min-width: 640px) {
    header {
        padding: 0 24px;
    }
}

/* ============================================
   WORKSPACE
   ============================================ */
.workspace-area {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* ============================================
   HOME SCREEN
   ============================================ */
.home-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
    padding: 20px;
    overflow-y: auto;
}

.home-screen .logo {
    font-size: 48px;
    font-weight: 700;
    letter-spacing: 8px;
    color: #1e293b;
    margin-bottom: 8px;
}

.home-screen .subtitle {
    color: #64748b;
    letter-spacing: 4px;
    font-size: 14px;
    margin-bottom: 40px;
}

/* ============================================
   CATALOG CARDS
   ============================================ */
.catalogs-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    width: 100%;
    max-width: 1200px;
    max-height: 55vh;
    overflow-y: auto;
    padding: 4px;
}

@media (max-width: 640px) {
    .catalogs-grid {
        grid-template-columns: 1fr;
    }
}

.catalog-card {
    background: white;
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
    transition: all 0.3s;
    cursor: pointer;
    border: 2px solid transparent;
}

.catalog-card:hover {
    border-color: #1e293b;
    transform: translateY(-2px);
    box-shadow: 0 8px 30px rgba(0,0,0,0.12);
}

.catalog-card .name-input {
    background: transparent;
    border: none;
    border-bottom: 2px dashed #cbd5e1;
    font-size: 16px;
    font-weight: 600;
    color: #1e293b;
    width: 100%;
    padding: 4px 0;
    transition: border-color 0.3s;
}

.catalog-card .name-input:focus {
    outline: none;
    border-bottom-color: #1e293b;
}

.catalog-card .name-input:hover {
    border-bottom-color: #94a3b8;
}

.personalized-catalogs-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
    width: 100%;
    max-height: 35vh;
    overflow-y: auto;
    padding: 4px;
}

.personalized-catalog-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-width: 0;
    padding: 16px;
    background: #11161d;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

.personalized-catalog-download {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex: 0 0 auto;
    padding: 8px 10px;
    color: #fff;
    background: #1e293b;
    border-radius: 8px;
    font-size: 12px;
    text-decoration: none;
    transition: background .2s;
}

.personalized-catalog-download:hover {
    background: #334155;
}

.personalized-catalog-upload-status {
    margin-top: 10px;
    font-size: 12px;
    color: #64748b;
}

.personalized-catalog-upload-status.is-uploading {
    color: #2563eb;
}

.personalized-catalog-upload-status.is-success {
    color: #059669;
}

.personalized-catalog-upload-status.is-error {
    color: #dc2626;
}

@media (max-width: 640px) {
    .personalized-catalogs-list {
        grid-template-columns: 1fr;
    }

    .personalized-catalog-download span {
        display: none;
    }
}

.edit-hint {
    font-size: 11px;
    color: #94a3b8;
    margin-top: 4px;
}

.btn-create-catalog {
    width: 100%;
    background: #1e293b;
    color: white;
    padding: 16px;
    border-radius: 12px;
    font-size: 18px;
    font-weight: 700;
    transition: all 0.3s;
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    border: none;
    cursor: pointer;
}

.btn-create-catalog:hover {
    background: #0f172a;
    box-shadow: 0 20px 25px -5px rgba(0,0,0,0.15);
    transform: translateY(-2px);
}

/* ============================================
   FILTER PANEL
   ============================================ */
.filter-panel-full {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: white;
    z-index: 100;
    overflow-y: auto;
    padding: 20px;
    display: none;
}

.filter-panel-full.active {
    display: block;
}

.filter-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid #e2e8f0;
    flex-wrap: wrap;
    gap: 10px;
}

@media (max-width: 768px) {
    .filter-header {
        flex-direction: column;
        align-items: stretch;
    }
    .filter-header > div:first-child {
        text-align: center;
    }
    .filter-header .flex {
        justify-content: center;
    }
}

.filter-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 24px;
}

@media (min-width: 768px) {
    .filter-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 1024px) {
    .filter-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

.filter-label {
    font-size: 11px;
    font-weight: 700;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}

.filter-select {
    width: 100%;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 12px;
    font-size: 14px;
    background: white;
    color: #1e293b;
    transition: border-color 0.2s;
}

.filter-select:focus {
    outline: none;
    border-color: #94a3b8;
}

.filter-actions {
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid #e5e7eb;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    flex-wrap: wrap;
}

/* ============================================
   RESULTS PANEL
   ============================================ */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

.results-header {
    flex-shrink: 0;
    padding: 12px 16px;
    background: white;
    border-bottom: 1px solid #e5e7eb;
}

@media (min-width: 640px) {
    .results-header {
        padding: 16px 32px;
    }
}

.results-header-top {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

/* Barra compacta de acciones, inspirada en los grupos de herramientas de Photoshop. */
.results-toolbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px;
}

.results-toolbar-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 32px;
    padding: 6px 9px;
    color: #475569;
    border: 1px solid transparent;
    border-radius: 5px;
    background: transparent;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, color 0.2s, border-color 0.2s;
}

.results-toolbar-btn:hover {
    color: #0f172a;
    background: #f1f5f9;
    border-color: #e2e8f0;
}

.results-toolbar-btn-primary {
    color: white;
    background: #2563eb;
    border-color: #2563eb;
}

.results-toolbar-btn-primary:hover {
    color: white;
    background: #1d4ed8;
    border-color: #1d4ed8;
}

.results-toolbar-divider {
    width: 1px;
    height: 24px;
    margin: 0 3px;
    background: #e2e8f0;
}

@media (max-width: 639px) {
    .results-header-top {
        align-items: flex-start;
    }

    .results-toolbar {
        width: 100%;
        padding-top: 6px;
        border-top: 1px solid #f1f5f9;
        overflow-x: auto;
        flex-wrap: nowrap;
    }

    .results-toolbar-btn {
        flex: 0 0 auto;
    }
}

.select-all-btn {
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 500;
    color: #475569;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    background: white;
    cursor: pointer;
    transition: all 0.2s;
}

.select-all-btn:hover {
    background: #1e293b;
    color: white;
}

/* ============================================
   PDF CONFIG BAR
   ============================================ */
.pdf-config-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding: 8px 0;
}

.pdf-config-bar .config-group {
    display: flex;
    align-items: center;
    gap: 6px;
    background: #f1f5f9;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 11px;
    flex-wrap: wrap;
}

.pdf-config-bar .config-group label {
    display: flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    color: #475569;
    font-weight: 400;
}

.pdf-config-bar .config-group input[type="checkbox"] {
    width: 14px;
    height: 14px;
    accent-color: #1e293b;
    cursor: pointer;
}

.page-layout-btn {
    padding: 4px 12px;
    border-radius: 16px;
    font-size: 11px;
    font-weight: 500;
    background: #f1f5f9;
    color: #64748b;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.2s;
}

.page-layout-btn.active {
    background: #1e293b;
    color: white;
    border-color: #1e293b;
}

.page-layout-btn:hover:not(.active) {
    border-color: #94a3b8;
}

.view-toggle {
    display: flex;
    background: #f1f5f9;
    border-radius: 6px;
    border: 1px solid #e5e7eb;
    padding: 2px;
    font-size: 12px;
    margin-left: auto;
}

.view-toggle button {
    padding: 4px 10px;
    border-radius: 4px;
    background: transparent;
    color: #94a3b8;
    border: none;
    cursor: pointer;
    transition: all 0.2s;
}

.view-toggle button.active {
    background: white;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    color: #1e293b;
}

.view-toggle button:hover:not(.active) {
    color: #475569;
}

.order-select {
    border: none;
    font-size: 12px;
    font-weight: 500;
    color: #1e293b;
    background: transparent;
    cursor: pointer;
}

.order-select:focus {
    outline: none;
}

/* ============================================
   GRID
   ============================================ */
.grid-wrapper {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px;
}

@media (min-width: 640px) {
    .grid-wrapper {
        padding: 24px;
    }
}

.grid-container {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0;
}

@media (min-width: 640px) {
    .grid-container {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 1024px) {
    .grid-container {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 1280px) {
    .grid-container {
        grid-template-columns: repeat(6, 1fr);
    }
}

.grid-container.list-view {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.empty-state {
    display: none;
    height: 100%;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: #94a3b8;
    padding: 80px 16px;
    text-align: center;
}

.empty-state:not(.hidden) {
    display: flex;
}

/* ============================================
   GRID CARDS
   ============================================ */
.grid-card {
    background: white;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid #e5e7eb;
    transition: all 0.2s;
    position: relative;
}

.grid-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

.grid-card.selected {
    border-color: #1e293b;
    ring: 1px solid #1e293b;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.grid-card.list-view {
    display: flex;
    flex-direction: row;
    height: 140px;
}

@media (max-width: 640px) {
    .grid-card.list-view {
        height: 120px;
    }
}

/* ============================================
   CONFIG PANEL
   ============================================ */
.config-panel {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 50;
    display: none;
}

.config-panel:not(.hidden) {
    display: block;
}

.config-panel-content {
    position: absolute;
    right: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: white;
    box-shadow: -4px 0 20px rgba(0,0,0,0.1);
    overflow-y: auto;
}

@media (min-width: 640px) {
    .config-panel-content {
        width: 384px;
    }
}

.config-panel-header {
    background: #1e293b;
    color: white;
    padding: 20px;
    position: sticky;
    top: 0;
    z-index: 10;
}

.config-close-btn {
    position: absolute;
    top: 16px;
    right: 16px;
    color: #94a3b8;
    background: transparent;
    border: none;
    font-size: 20px;
    cursor: pointer;
    transition: color 0.2s;
}

.config-close-btn:hover {
    color: white;
}

.config-clear-btn {
    width: 100%;
    border: 1px solid #334155;
    background: transparent;
    color: white;
    padding: 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.config-clear-btn:hover {
    background: #334155;
}

.config-panel-body {
    padding: 20px;
}

.config-section-title {
    font-size: 10px;
    font-weight: 700;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 12px;
}

.config-section {
    background: #f8fafc;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid #e5e7eb;
    space-y: 10px;
}

.config-section > div {
    margin-bottom: 10px;
}

.config-section > div:last-child {
    margin-bottom: 0;
}

.config-label {
    font-size: 9px;
    font-weight: 700;
    color: #64748b;
    display: block;
    margin-bottom: 4px;
}

.config-input {
    width: 100%;
    font-size: 12px;
    padding: 8px;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
}

.config-input:focus {
    outline: none;
    border-color: #94a3b8;
}

.config-textarea {
    width: 100%;
    font-size: 10px;
    padding: 8px;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    resize: vertical;
    line-height: 1.5;
}

.config-textarea:focus {
    outline: none;
    border-color: #94a3b8;
}

.config-divider {
    border: none;
    border-top: 1px solid #e5e7eb;
    margin: 16px 0;
}

.config-toggles {
    space-y: 14px;
}

.config-toggle-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* ============================================
   TOGGLES
   ============================================ */
.toggle-switch {
    appearance: none;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: white;
    border: 2px solid #cbd5e1;
    cursor: pointer;
    transition: all 0.3s;
    position: absolute;
    top: -4px;
}

.toggle-switch:checked {
    border-color: #1e293b;
    right: -4px;
}

.toggle-switch:not(:checked) {
    right: 14px;
}

.toggle-switch:checked + .toggle-bg {
    background-color: #1e293b;
}

.toggle-wrapper {
    position: relative;
    display: inline-block;
    width: 36px;
}

.toggle-bg {
    display: block;
    width: 36px;
    height: 20px;
    border-radius: 9999px;
    background-color: #cbd5e1;
    cursor: pointer;
    transition: background-color 0.3s;
}

/* ============================================
   LOCAL CATALOGS PANEL
   ============================================ */
.local-catalogs-panel {
    position: fixed;
    bottom: 80px;
    right: 8px;
    width: calc(100% - 16px);
    max-width: 320px;
    background: #1e293b;
    color: white;
    border-radius: 8px;
    box-shadow: 0 20px 25px -5px rgba(0,0,0,0.2);
    border: 1px solid #334155;
    display: none;
    flex-direction: column;
    z-index: 50;
    overflow: hidden;
    max-height: 380px;
}

@media (min-width: 640px) {
    .local-catalogs-panel {
        right: 24px;
        width: 320px;
    }
}

.local-catalogs-panel:not(.hidden) {
    display: flex;
}

.local-catalogs-header {
    background: #0f172a;
    padding: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #334155;
}

.local-catalogs-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    space-y: 8px;
}

/* ============================================
   FOOTER
   ============================================ */
.app-footer {
    background: #1e293b;
    color: white;
    border-top: 1px solid #334155;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    flex-shrink: 0;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.05em;
    z-index: 20;
    position: relative;
    padding: 8px 16px;
    box-shadow: 0 -4px 10px rgba(0,0,0,0.1);
    padding-bottom: env(safe-area-inset-bottom);
    padding-bottom: max(env(safe-area-inset-bottom), 8px);
    min-height: 64px;
}

@media (min-width: 640px) {
    .app-footer {
        gap: 24px;
        font-size: 12px;
    }
}

.btn-pdf {
    background: #2563eb;
    color: white;
    padding: 8px 16px;
    border-radius: 6px;
    border: 1px solid #3b82f6;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: background 0.2s;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
}

.btn-pdf:hover {
    background: #1d4ed8;
}

.btn-footer {
    background: transparent;
    color: white;
    border: none;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: color 0.2s;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.05em;
}

@media (min-width: 640px) {
    .btn-footer {
        font-size: 12px;
    }
}

.btn-footer:hover {
    color: #60a5fa;
}

.footer-divider {
    width: 1px;
    height: 24px;
    background: #334155;
}

/* ============================================
   LOADER
   ============================================ */
.loader-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255,255,255,0.85);
    backdrop-filter: blur(4px);
    z-index: 50;
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

.loader-overlay:not(.hidden) {
    display: flex;
}

.loader-spinner {
    animation: spin 1s linear infinite;
    border-radius: 50%;
    height: 64px;
    width: 64px;
    border-top: 4px solid #1e293b;
    border-bottom: 4px solid #1e293b;
    margin-bottom: 16px;
}

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

/* ============================================
   TOAST
   ============================================ */
.custom-toast {
    position: fixed;
    bottom: 96px;
    left: 50%;
    transform: translateX(-50%);
    width: max-content;
    max-width: 90vw;
    background: #1e293b;
    color: white;
    font-size: 12px;
    padding: 12px 16px;
    border-radius: 6px;
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.3s;
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
    pointer-events: none;
    z-index: 50;
}

.custom-toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
    pointer-events: auto;
}

/* ============================================
   CHECKBOX CUSTOM
   ============================================ */
.img-checkbox {
    appearance: none;
    background-color: rgba(255,255,255,0.9);
    margin: 0;
    width: 1.5em;
    height: 1.5em;
    border: 1px solid #cbd5e1;
    border-radius: 0.25em;
    display: grid;
    place-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.img-checkbox::before {
    content: "";
    width: 0.8em;
    height: 0.8em;
    transform: scale(0);
    transition: 120ms transform ease-in-out;
    box-shadow: inset 1em 1em #ffffff;
    clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
}

.img-checkbox:checked {
    background-color: #1e293b;
    border-color: #1e293b;
}

.img-checkbox:checked::before {
    transform: scale(1);
}

/* ============================================
   ANIMATIONS
   ============================================ */
.fade-in {
    animation: fadeIn 0.5s ease-in-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ============================================
   UTILITIES
   ============================================ */
.font-serif-pdf {
    font-family: 'Times New Roman', Times, serif;
}

.hidden {
    display: none !important;
}

.opacity-60 {
    opacity: 0.6;
}

.truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ============================================
   PDF VIEWER - VERSIÓN MEJORADA
   ============================================ */

.pdf-viewer-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

    .pdf-viewer-overlay:not(.hidden) {
        display: flex;
    }

.pdf-viewer-container {
    background: white;
    width: 100%;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

/* ============================================
   HEADER DEL VISOR
   ============================================ */

.pdf-viewer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    border-bottom: 1px solid #e5e7eb;
    background: #f8fafc;
    flex-shrink: 0;
    gap: 6px;
    min-height: 48px;
    z-index: 10;
}

.pdf-viewer-title {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    color: #1e293b;
    min-width: 0;
    flex: 1;
}

    .pdf-viewer-title i {
        font-size: 14px;
        flex-shrink: 0;
    }

    .pdf-viewer-title span {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

.pdf-viewer-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.pdf-viewer-btn {
    padding: 4px 8px;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    background: white;
    color: #475569;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    min-height: 32px;
}

    .pdf-viewer-btn i {
        font-size: 14px;
    }

    .pdf-viewer-btn span {
        display: none;
    }

    .pdf-viewer-btn:hover {
        background: #f1f5f9;
        border-color: #94a3b8;
    }

.pdf-viewer-btn-close {
    padding: 4px 10px;
    border: none;
    border-radius: 4px;
    background: #ef4444;
    color: white;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 16px;
    min-height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

    .pdf-viewer-btn-close:hover {
        background: #dc2626;
    }

/* ============================================
   CUERPO DEL VISOR
   ============================================ */

.pdf-viewer-body {
    display: flex;
    flex: 1;
    overflow: hidden;
    flex-direction: column;
}

/* ============================================
   SIDEBAR - Mobile First (Arriba)
   ============================================ */

.pdf-viewer-sidebar {
    width: 100%;
    max-height: 160px;
    border-bottom: 1px solid #e5e7eb;
    background: #f8fafc;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
}

.pdf-sidebar-header {
    padding: 6px 12px;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: white;
    flex-shrink: 0;
}

    .pdf-sidebar-header h3 {
        font-size: 11px;
        font-weight: 600;
        color: #1e293b;
        display: flex;
        align-items: center;
        gap: 4px;
    }

        .pdf-sidebar-header h3 i {
            font-size: 12px;
        }

.pdf-catalog-list {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 4px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    -webkit-overflow-scrolling: touch;
}

.pdf-catalog-item {
    padding: 6px 10px;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    border: 2px solid transparent;
    background: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 6px;
    min-height: 36px;
    touch-action: manipulation;
}

    .pdf-catalog-item:active {
        transform: scale(0.97);
    }

    .pdf-catalog-item.active {
        background: #1e293b;
        color: white;
        border-color: #1e293b;
    }

        .pdf-catalog-item.active .pdf-catalog-date {
            color: #94a3b8;
        }

    .pdf-catalog-item .pdf-catalog-info {
        display: flex;
        flex-direction: column;
        min-width: 0;
        flex: 1;
    }

    .pdf-catalog-item .pdf-catalog-title {
        font-size: 11px;
        font-weight: 500;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .pdf-catalog-item .pdf-catalog-date {
        font-size: 9px;
        color: #94a3b8;
    }

    .pdf-catalog-item .pdf-catalog-count {
        font-size: 9px;
        background: #e5e7eb;
        padding: 1px 6px;
        border-radius: 10px;
        white-space: nowrap;
        flex-shrink: 0;
    }

    .pdf-catalog-item.active .pdf-catalog-count {
        background: #334155;
        color: #94a3b8;
    }

/* ============================================
   ÁREA DEL PDF
   ============================================ */

.pdf-viewer-content {
    flex: 1;
    background: #e5e7eb;
    overflow: hidden;
    position: relative;
    min-height: 200px;
}

.pdf-viewer-frame {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #e5e7eb;
    padding: 4px;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

    .pdf-viewer-frame canvas {
        max-width: 100%;
        height: auto !important;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        border-radius: 4px;
        background: white;
    }

.pdf-placeholder {
    text-align: center;
    color: #94a3b8;
    padding: 20px;
}

    .pdf-placeholder i {
        display: block;
        font-size: 40px;
        margin-bottom: 10px;
    }

    .pdf-placeholder p {
        font-size: 12px;
    }

    .pdf-placeholder .text-sm {
        font-size: 10px;
    }

/* ============================================
   CONTROLES DE NAVEGACIÓN DEL PDF
   ============================================ */

.pdf-viewer-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 6px 12px;
    background: #f8fafc;
    border-top: 1px solid #e5e7eb;
    flex-shrink: 0;
    min-height: 40px;
}

.pdf-nav-btn {
    padding: 6px 12px;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    background: white;
    color: #475569;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 14px;
    min-width: 36px;
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

    .pdf-nav-btn:active {
        transform: scale(0.95);
    }

    .pdf-nav-btn:hover {
        background: #f1f5f9;
        border-color: #94a3b8;
    }

    .pdf-nav-btn:disabled {
        opacity: 0.3;
        cursor: not-allowed;
    }

.pdf-page-info {
    font-size: 12px;
    color: #475569;
    min-width: 80px;
    text-align: center;
}

/* ============================================
   LOADING EN EL VISOR
   ============================================ */

.pdf-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #64748b;
    padding: 20px;
}

    .pdf-loading .spinner {
        width: 32px;
        height: 32px;
        border: 3px solid #e5e7eb;
        border-top: 3px solid #1e293b;
        border-radius: 50%;
        animation: spin 1s linear infinite;
        margin-bottom: 10px;
    }

    .pdf-loading p {
        font-size: 12px;
    }

/* ============================================
   RESPONSIVE - Tablet (>= 640px)
   ============================================ */

@media (min-width: 640px) {
    .pdf-viewer-container {
        width: 95%;
        height: 92vh;
        max-height: 92vh;
        border-radius: 12px;
        box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    }

    .pdf-viewer-header {
        padding: 10px 16px;
        min-height: 52px;
    }

    .pdf-viewer-title {
        font-size: 14px;
    }

    .pdf-viewer-btn {
        padding: 6px 12px;
        font-size: 12px;
        min-height: 36px;
    }

        .pdf-viewer-btn span {
            display: inline;
        }

    .pdf-viewer-btn-close {
        padding: 6px 14px;
        font-size: 18px;
        min-height: 36px;
    }

    .pdf-sidebar-header h3 {
        font-size: 12px;
    }

    .pdf-catalog-item {
        padding: 8px 12px;
        min-height: 40px;
    }

        .pdf-catalog-item .pdf-catalog-title {
            font-size: 12px;
        }

    .pdf-viewer-controls {
        padding: 8px 16px;
        min-height: 44px;
    }
}

/* Final theme overrides keep dynamically rendered panels consistent with the
   sidebar palette, including rules declared earlier in this stylesheet. */
body {
    background-color: #070a0e;
    color: #e4e4e7;
}

.workspace-area,
.home-screen {
    background: #0d1117 !important;
}

.catalog-card,
.results-header,
.grid-card,
.local-catalogs-panel,
.pdf-viewer-sidebar {
    background: #11161d;
    border-color: #1f242c;
    color: #e4e4e7;
}

.main-content,
.grid-wrapper {
    background: #0d1117;
}

.filter-panel-full,
.config-panel-content,
.modal-content,
.pdf-viewer-container {
    background: #0d1117;
    color: #e4e4e7;
}

.filter-select,
.config-input,
.config-textarea {
    background: #11161d;
    border-color: #2a2f38;
    color: #e4e4e7;
}

@media (max-width: 640px) {
    .workspace-area {
        padding-left: 0;
    }

    header {
        margin-left: 0;
    }
}

/* ============================================
   RESPONSIVE - Desktop (>= 1024px)
   ============================================ */

@media (min-width: 1024px) {
    .pdf-viewer-body {
        flex-direction: row;
    }

    .pdf-viewer-sidebar {
        width: 280px;
        min-width: 280px;
        max-height: 100%;
        border-bottom: none;
        border-right: 1px solid #e5e7eb;
    }

    .pdf-catalog-list {
        max-height: calc(100% - 44px);
    }

    .pdf-viewer-content {
        flex: 1;
    }

    .pdf-viewer-frame {
        padding: 12px;
    }

    .pdf-placeholder i {
        font-size: 64px;
    }

    .pdf-placeholder p {
        font-size: 14px;
    }
}

/* ============================================
   RESPONSIVE - Móvil pequeño (< 480px)
   ============================================ */

@media (max-width: 480px) {
    .pdf-viewer-header {
        padding: 4px 8px;
        min-height: 40px;
    }

    .pdf-viewer-title {
        font-size: 10px;
    }

        .pdf-viewer-title i {
            font-size: 12px;
        }

    .pdf-viewer-btn {
        padding: 3px 6px;
        font-size: 10px;
        min-height: 28px;
    }

        .pdf-viewer-btn i {
            font-size: 12px;
        }

    .pdf-viewer-btn-close {
        padding: 3px 8px;
        font-size: 14px;
        min-height: 28px;
    }

    .pdf-viewer-sidebar {
        max-height: 120px;
    }

    .pdf-sidebar-header {
        padding: 4px 8px;
    }

        .pdf-sidebar-header h3 {
            font-size: 10px;
        }

    .pdf-catalog-item {
        padding: 4px 8px;
        min-height: 30px;
    }

        .pdf-catalog-item .pdf-catalog-title {
            font-size: 10px;
        }

        .pdf-catalog-item .pdf-catalog-date {
            font-size: 8px;
        }

        .pdf-catalog-item .pdf-catalog-count {
            font-size: 8px;
            padding: 1px 4px;
        }

    .pdf-viewer-controls {
        padding: 4px 8px;
        min-height: 32px;
        gap: 8px;
    }

    .pdf-nav-btn {
        padding: 4px 8px;
        font-size: 12px;
        min-width: 30px;
        min-height: 30px;
    }

    .pdf-page-info {
        font-size: 10px;
        min-width: 60px;
    }

    .pdf-viewer-frame {
        padding: 2px;
    }

    .pdf-placeholder i {
        font-size: 32px;
    }

    .pdf-placeholder p {
        font-size: 11px;
    }
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}
