:root {
    /* Light Theme */
    --bg-primary: #fdfcf9;
    --bg-secondary: #f5f2ed;
    --bg-card: #ffffff;
    --text-primary: #1a1614;
    --text-secondary: #5c5551;
    --text-tertiary: #8b8783;
    --accent-primary: #d4501f;
    --accent-secondary: #f39c6b;
    --border-color: #e8e5e0;
    --shadow-sm: 0 2px 8px rgba(26, 22, 20, 0.04);
    --shadow-md: 0 4px 20px rgba(26, 22, 20, 0.08);
    --shadow-lg: 0 8px 40px rgba(26, 22, 20, 0.12);
    
    /* File Type Colors (flexibles) */
    --cat-pdf: #c7522a;
    --cat-word: #2563b3;
    --cat-excel: #059669;
    --cat-powerpoint: #f59e0b;
    --cat-texto: #6b7280;
    --cat-archivo: #8b5cf6;
    --cat-gis: #16a34a;
    --cat-arcgis: #0ea5e9;
    --cat-geodatabase: #0891b2;
    --cat-raster: #84cc16;
    --cat-kml: #ea580c;
    --cat-geojson: #7c3aed;
    --cat-gpx: #dc2626;
    --cat-leyes: #c7522a;
    --cat-normas: #2563b3;
    --cat-proyectos: #8b5cf6;
    --cat-academicos: #059669;
    --cat-default: #6b7280;
}

[data-theme="dark"] {
    --bg-primary: #0f0e0d;
    --bg-secondary: #1a1816;
    --bg-card: #252321;
    --text-primary: #f5f2ed;
    --text-secondary: #bfb9b3;
    --text-tertiary: #8b8783;
    --accent-primary: #f39c6b;
    --accent-secondary: #d4501f;
    --border-color: #353330;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.5);
}

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

body {
    font-family: 'Instrument Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    transition: background-color 0.3s ease, color 0.3s ease;
    overflow-x: hidden;
}

/* Header */
.header {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    padding: 2rem 0;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(10px);
    background: rgba(var(--bg-card), 0.95);
    box-shadow: var(--shadow-sm);
    animation: slideDown 0.5s ease;
}

@keyframes slideDown {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.header-content {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-family: 'Fraunces', serif;
    font-size: 2.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, var(--text-primary) 0%, var(--accent-primary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.25rem;
}

.logo-accent {
    font-style: italic;
    font-weight: 300;
}

.tagline {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.theme-toggle {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
}

.theme-toggle:hover {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    transform: rotate(180deg);
}

.theme-toggle:hover svg {
    color: white;
}

.sun-icon,
.moon-icon {
    position: absolute;
    transition: all 0.3s ease;
}

[data-theme="dark"] .sun-icon {
    opacity: 0;
    transform: rotate(180deg) scale(0);
}

[data-theme="dark"] .moon-icon {
    opacity: 1;
    transform: rotate(0) scale(1);
}

[data-theme="light"] .moon-icon {
    opacity: 0;
    transform: rotate(-180deg) scale(0);
}

[data-theme="light"] .sun-icon {
    opacity: 1;
    transform: rotate(0) scale(1);
}

/* Search Section */
.search-section {
    max-width: 1400px;
    margin: 3rem auto;
    padding: 0 2rem;
    animation: fadeInUp 0.6s ease 0.2s both;
}

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

.search-container {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.search-box {
    position: relative;
    max-width: 700px;
}

.search-icon {
    position: absolute;
    left: 1.25rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-tertiary);
    pointer-events: none;
}

.search-input {
    width: 100%;
    padding: 1rem 1rem 1rem 3.5rem;
    font-size: 1.125rem;
    font-family: inherit;
    background: var(--bg-card);
    border: 2px solid var(--border-color);
    border-radius: 16px;
    color: var(--text-primary);
    transition: all 0.3s ease;
}

.search-input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 4px rgba(212, 80, 31, 0.1);
}

.search-input::placeholder {
    color: var(--text-tertiary);
}

.filter-chips {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.chip {
    padding: 0.625rem 1.25rem;
    background: var(--bg-card);
    border: 2px solid var(--border-color);
    border-radius: 50px;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.chip:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    transform: translateY(-2px);
}

.chip.active {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
}

.results-info {
    margin-top: 1.5rem;
}

.result-count {
    font-size: 0.9375rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Documents Grid */
.main-content {
    max-width: 1400px;
    margin: 2rem auto 4rem;
    padding: 0 2rem;
    animation: fadeInUp 0.6s ease 0.4s both;
}

.documents-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1.75rem;
}

.doc-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 1.75rem;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    animation: scaleIn 0.4s ease both;
}

@keyframes scaleIn {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.doc-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--doc-color, var(--cat-default));
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.3s ease;
}

.doc-card:hover::before {
    transform: scaleX(1);
}

.doc-card:hover {
    transform: translateY(-8px);
    box-shadow: var(--shadow-lg);
    border-color: var(--doc-color, var(--border-color));
}

.doc-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.doc-icon {
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, var(--doc-color, var(--cat-default)), var(--doc-color-light, var(--cat-default)));
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: white;
    font-weight: 700;
    font-size: 1.25rem;
}

.doc-category {
    display: inline-block;
    padding: 0.35rem 0.85rem;
    background: var(--doc-color, var(--cat-default));
    color: white;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.doc-title {
    font-family: 'Fraunces', serif;
    font-size: 1.375rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
    line-height: 1.3;
}

.doc-description {
    font-size: 0.9375rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    line-height: 1.6;
}

.doc-meta {
    display: flex;
    gap: 1.5rem;
    font-size: 0.8125rem;
    color: var(--text-tertiary);
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.doc-meta-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.doc-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.tag {
    padding: 0.25rem 0.625rem;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 500;
}

/* No Results */
.no-results {
    text-align: center;
    padding: 4rem 2rem;
    color: var(--text-secondary);
}

.no-results svg {
    margin-bottom: 1.5rem;
    opacity: 0.3;
}

.no-results h3 {
    font-family: 'Fraunces', serif;
    font-size: 1.75rem;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.modal.active {
    display: flex;
}

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(8px);
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    position: relative;
    background: var(--bg-card);
    border-radius: 24px;
    max-width: 1200px;
    width: 100%;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    animation: modalSlideIn 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: scale(0.9) translateY(30px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-title {
    font-family: 'Fraunces', serif;
    font-size: 1.5rem;
    font-weight: 600;
}

.modal-close {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    color: var(--text-secondary);
    transition: all 0.2s ease;
    border-radius: 8px;
}

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

.modal-body {
    flex: 1;
    padding: 0;
    overflow: hidden;
}

.modal-body iframe {
    width: 100%;
    height: 100%;
    min-height: 600px;
}

.modal-footer {
    padding: 1.5rem 2rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
}

.download-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.875rem 1.75rem;
    background: var(--accent-primary);
    color: white;
    border-radius: 12px;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.2s ease;
}

.download-btn:hover {
    background: var(--accent-secondary);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

/* Loading State */
.loading-state {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-primary);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    gap: 1.5rem;
}

.loading-state.hidden {
    display: none;
}

.loading-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid var(--border-color);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.loading-state p {
    color: var(--text-secondary);
    font-weight: 500;
}

/* Responsive */
@media (max-width: 768px) {
    .header-content {
        padding: 0 1rem;
    }
    
    .logo {
        font-size: 1.875rem;
    }
    
    .search-section,
    .main-content {
        padding: 0 1rem;
    }
    
    .documents-grid {
        grid-template-columns: 1fr;
        gap: 1.25rem;
    }
    
    .filter-chips {
        overflow-x: auto;
        flex-wrap: nowrap;
        padding-bottom: 0.5rem;
    }
    
    .chip {
        white-space: nowrap;
    }
    
    .modal {
        padding: 1rem;
    }
    
    .modal-content {
        max-height: 95vh;
    }
    
    .modal-body iframe {
        min-height: 400px;
    }
}

/* Animation delays for staggered effect */
.doc-card:nth-child(1) { animation-delay: 0.05s; }
.doc-card:nth-child(2) { animation-delay: 0.1s; }
.doc-card:nth-child(3) { animation-delay: 0.15s; }
.doc-card:nth-child(4) { animation-delay: 0.2s; }
.doc-card:nth-child(5) { animation-delay: 0.25s; }
.doc-card:nth-child(6) { animation-delay: 0.3s; }
