/* ==========================================================================
   1. MODALES, DIALOGS Y AUTOCOMPLETADO
   ========================================================================== */
dialog.category-modal,
dialog.weather-modal {
    background-color: #202124;
    color: #e8eaed;
    border: 1px solid #5f6368;
    padding: 0;
    margin: auto;
    width: 90%;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
    opacity: 0;
    transform: scale(0.96) translateY(6px);
    overflow: visible !important;
    transition: 
        opacity 0.2s ease-out, 
        transform 0.2s ease-out, 
        overlay 0.2s ease-out allow-discrete, 
        display 0.2s ease-out allow-discrete;
}

dialog.category-modal { max-width: 860px; overflow: hidden !important; }
dialog.weather-modal { max-width: 440px; }

dialog.category-modal[open],
dialog.weather-modal[open] {
    opacity: 1;
    transform: scale(1) translateY(0);
}

dialog::backdrop {
    background-color: rgba(0, 0, 0, 0);
    transition: background-color 0.2s ease-out, overlay 0.2s ease-out allow-discrete, display 0.2s ease-out allow-discrete;
}

dialog.category-modal[open]::backdrop,
dialog.weather-modal[open]::backdrop {
    background-color: rgba(0, 0, 0, 0.75);
}

@starting-style {
    dialog.category-modal[open],
    dialog.weather-modal[open] {
        opacity: 0;
        transform: scale(0.96) translateY(6px);
    }
    dialog.category-modal[open]::backdrop,
    dialog.weather-modal[open]::backdrop {
        background-color: rgba(0, 0, 0, 0);
    }
}

.modal-header,
.weather-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    border-bottom: 1px solid #3c4043;
    background-color: #303134;
}

.modal-header h3,
.weather-modal-header h3 {
    font-size: 0.95rem;
    color: #8ab4f8;
    margin: 0;
    font-weight: bold;
}

.modal-close-btn,
dialog.weather-modal .close-btn {
    background: none;
    border: none;
    color: #e8eaed;
    font-size: 20px;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    box-shadow: none;
    text-shadow: none;
    line-height: 1;
    min-height: auto;
}

.modal-close-btn:hover,
dialog.weather-modal .close-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: #f28b82;
}

.weather-modal-body {
    padding: 14px 16px;
    font-size: 0.875rem;
    line-height: 1.45;
    color: #bdc1c6;
    overflow: visible !important;
    position: relative;
}

.weather-modal-body hr {
    border: 0;
    border-top: 1px solid #3c4043;
    margin: 10px 0;
}

.weather-search-box {
    position: relative;
    margin-bottom: 0.5rem;
    overflow: visible !important;
}

/* Modal Custom Backdrop (Fuera del elemento dialog) */
.modal-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
    z-index: 10000;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    box-sizing: border-box;
}

.modal-backdrop.active { display: flex; }

.modal-container {
    background-color: var(--bg-color, #202124);
    color: var(--text-color, #e8eaed);
    border: 1px solid #3c4043;
    border-radius: 8px;
    max-width: 650px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    padding: 2rem;
    position: relative;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
}

.modal-content-block {
    display: none;
    color: #e8eaed;
}

.modal-content-block.active { display: block; }

.modal-title {
    font-size: 1.4rem;
    margin-top: 0;
    margin-bottom: 0.5rem;
    color: #8ab4f8;
}

.modal-subtitle {
    font-size: 0.9rem;
    color: var(--text-secondary, #9aa0a6);
    margin-bottom: 1.5rem;
}

.modal-directory-body,
.modal-container,
.modal-content-block,
.directory-section {
    color: #e8eaed;
}

.modal-directory-body a,
.modal-container a,
.modal-content-block a,
.directory-section a {
    color: #8ab4f8;
    text-decoration: underline;
    transition: color 0.15s ease;
}

.modal-directory-body a:hover,
.modal-container a:hover,
.modal-content-block a:hover,
.directory-section a:hover,
.modal-directory-body a:visited,
.modal-container a:visited,
.modal-content-block a:visited,
.directory-section a:visited {
    color: #c58af9;
}

.link-desc {
    color: #bdc1c6;
    font-size: 0.85rem;
}

/* --------------------------------------------------------------------------
   1.1. REGLAS DE AUTOCOMPLETADO
   -------------------------------------------------------------------------- */
#weatherSearchResults,
#cardWeatherSearchResults,
#headerWeatherSearchResults {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background-color: #202124;
    border: 1px solid #5f6368;
    border-radius: 0 0 6px 6px;
    max-height: 200px;
    overflow-y: auto;
    margin-top: 4px;
    padding: 0;
    list-style: none;
    z-index: 99999 !important;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.5);
}

#weatherSearchResults.active,
#cardWeatherSearchResults.active,
#headerWeatherSearchResults.active,
#weatherSearchResults:not(:empty),
#cardWeatherSearchResults:not(:empty) {
    display: block !important;
}

#weatherSearchResults li,
#cardWeatherSearchResults li,
#headerWeatherSearchResults li {
    padding: 8px 12px;
    font-size: 0.875rem;
    cursor: pointer;
    border-bottom: 1px solid #3c4043;
    color: #e8eaed;
    transition: background-color 0.15s ease;
}

#weatherSearchResults li:last-child,
#cardWeatherSearchResults li:last-child,
#headerWeatherSearchResults li:last-child { 
    border-bottom: none; 
}

#weatherSearchResults li:hover,
#cardWeatherSearchResults li:hover,
#headerWeatherSearchResults li:hover,
#weatherSearchResults li.selected,
#cardWeatherSearchResults li.selected,
#headerWeatherSearchResults li.selected { 
    background-color: #303134; 
    color: #8ab4f8;
}


/* ==========================================================================
   2. CONMUTADOR DE TEMA Y DEFINICIÓN DE TEMAS (CLARO Y OSCURO)
   ========================================================================== */
.theme-toggle-btn {
    background: transparent !important;
    border: none !important;
    border-radius: 0 !important;
    width: auto !important;
    height: auto !important;
    min-height: auto !important;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 4px !important;
    box-shadow: none !important;
    text-shadow: none !important;
    transition: opacity 0.2s ease, transform 0.2s ease;
    color: #9aa0a6;
    flex-shrink: 0;
}

.theme-icon {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-toggle-btn:hover { color: #ffffff; opacity: 1; transform: scale(1.1); }
.theme-toggle-btn:active { transform: scale(0.95); }

/* Tema Oscuro */
body.dark-theme,
[data-theme="dark"] { 
    background-color: #121212; 
    color: #e0e0e0; 
}
body.dark-theme .search-footer { color: #9aa0a6; border-top: none; }
body.dark-theme .theme-toggle-btn { color: #9aa0a6; }
body.dark-theme .theme-toggle-btn:hover { color: #ffffff; }
body.dark-theme .page-title .title-dark { color: #e8eaed; }

[data-theme="dark"] .directory-card-title,
body.dark-theme .directory-card-title { color: #8ab4f8; }

[data-theme="dark"] .directory-card-desc,
body.dark-theme .directory-card-desc { color: #bdc1c6; }

[data-theme="dark"] .modal-container,
body.dark-theme .modal-container {
    background-color: #202124;
    border: 1px solid #3c4043;
    color: #e8eaed;
}

/* Tema Claro */
body.light-theme { background-color: #f8f9fa; color: #202124; }
body.light-theme .header-overlay-text { color: #202124; }
body.light-theme .widget-item { color: #3c4043; }
body.light-theme .page-title { color: #202124; }

body.light-theme input[type="text"] {
    background-color: #ffffff;
    color: #202124;
    border-color: #dadce0;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.08);
}

body.light-theme input[type="text"]:focus {
    border-color: #1a73e8;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.08), 0 0 4px rgba(26, 115, 232, 0.25);
}

body.light-theme button,
body.light-theme .page-btn {
    background: linear-gradient(180deg, #ffffff 0%, #f1f3f4 100%);
    color: #3c4043;
    border-color: #dadce0;
    box-shadow: inset 0 1px 0 #ffffff, 0 1px 2px rgba(0, 0, 0, 0.05);
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.8);
}

body.light-theme button:hover,
body.light-theme .page-btn:hover:not(:disabled) {
    background: linear-gradient(180deg, #f8f9fa 0%, #e8eaed 100%);
    border-color: #bdc1c6;
}

body.light-theme button:active {
    background: #e8eaed;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.15);
}

body.light-theme .page-btn.active {
    background: linear-gradient(180deg, #1a73e8 0%, #1557b0 100%);
    color: #ffffff;
    border-color: #1a73e8;
    text-shadow: none;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
}

body.light-theme .stats { color: #5f6368; border-bottom-color: #dadce0; }
body.light-theme .result-title { color: #1a0dab; }
body.light-theme .result-title:visited { color: #681da8; }
body.light-theme .result-snippet { color: #4d5156; }
body.light-theme .result-header { color: #137333; }
body.light-theme .score-tag { color: #70757a; }
body.light-theme .highlight { color: #d93025; background-color: rgba(217, 48, 37, 0.1); }

body.light-theme .skeleton-line { background-color: #e8eaed; }
body.light-theme .skeleton-line::after {
    background: linear-gradient(90deg, transparent 0%, rgba(255, 255, 255, 0.6) 50%, transparent 100%);
}

/* Tema Claro - Knowledge Panel */
body.light-theme #knowledgePanel {
    background-color: #ffffff;
    border-color: #dadce0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

body.light-theme #kpTitle { color: #202124; }
body.light-theme #kpSubtitle,
body.light-theme .kp-platforms-label { color: #5f6368; }
body.light-theme #kpExtract { color: #3c4043; }
body.light-theme #kpImageContainer { background-color: #f1f3f4; }
body.light-theme .kp-platforms-container { border-top-color: #dadce0; }

body.light-theme .platform-link {
    background-color: #f8f9fa;
    border-color: #dadce0;
    color: #1a73e8;
}

body.light-theme .platform-link:hover {
    background-color: rgba(26, 115, 232, 0.1);
    border-color: #1a73e8;
    color: #681da8;
}

body.light-theme #kpWikiLink { color: #1a73e8; }
body.light-theme #kpWikiLink:hover { color: #681da8; }

body.light-theme .search-divider { border-top-color: #dadce0; }
body.light-theme .news-title,
body.light-theme .news-subtitle { color: #202124; }

body.light-theme .actuality-card {
    background-color: #ffffff;
    border-color: #dadce0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

body.light-theme .actuality-card-header h3,
body.light-theme .weather-temp-highlight,
body.light-theme .forecast-temp { color: #202124; }

body.light-theme .dollar-value-highlight { color: #2e7d32; }
body.light-theme .actuality-card-sub,
body.light-theme .weather-condition-label,
body.light-theme .forecast-container h4 { color: #5f6368; }

body.light-theme .weather-city-badge {
    background: #eef2f5;
    color: #1a73e8;
}

body.light-theme .forecast-item {
    background: #f8f9fa;
    border-color: #dadce0;
}

body.light-theme .forecast-day { color: #1a73e8; }

body.light-theme .carousel-arrow,
body.light-theme .side-toggle-btn {
    background: linear-gradient(180deg, #ffffff 0%, #f1f3f4 100%);
    color: #3c4043;
    border-color: #dadce0;
    box-shadow: inset 0 1px 0 #ffffff, 0 1px 2px rgba(0, 0, 0, 0.1);
    text-shadow: 0 1px 0 rgba(255, 255, 255, 0.8);
}

body.light-theme .carousel-arrow:hover,
body.light-theme .side-toggle-btn:hover {
    background: linear-gradient(180deg, #f8f9fa 0%, #e8eaed 100%);
    border-color: #bdc1c6;
    color: #202124;
}

body.light-theme .carousel-arrow:active,
body.light-theme .side-toggle-btn:active {
    background: #e8eaed;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.2);
    transform: scale(0.96) translateX(2px);
}

body.light-theme .directory-section-container {
    background-color: transparent;
    border-color: transparent;
    box-shadow: none;
}

body.light-theme .news-card {
    background-color: #ffffff;
    border-color: #dadce0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

body.light-theme .directory-title {
    color: #202124;
    border-bottom-color: #dadce0;
}

body.light-theme .directory-card-block {
    background-color: #f8f9fa;
    border-color: #dadce0;
}

body.light-theme .directory-card-block a,
body.light-theme .national-links-list a,
body.light-theme .directory-links-list a {
    color: #1a73e8;
    background-color: rgba(0, 0, 0, 0.03);
}

body.light-theme .directory-card-block a:hover,
body.light-theme .national-links-list a:hover,
body.light-theme .directory-links-list a:hover {
    background-color: rgba(26, 115, 232, 0.1);
    color: #681da8;
}

body.light-theme .section-subtitle,
body.light-theme .news-card-badge,
body.light-theme .news-card-link { color: #1a73e8; }

body.light-theme .news-card-title { color: #202124; }
body.light-theme .news-card-snippet { color: #5f6368; }

body.light-theme .status-badge.online {
    background-color: #0d9488;
    box-shadow: 0 0 5px rgba(13, 148, 136, 0.5);
}

body.light-theme .status-badge.offline {
    background-color: #d90429;
    box-shadow: 0 0 5px rgba(217, 4, 41, 0.5);
}

body.light-theme .status-badge.checking {
    background-color: #d97706;
}

body.light-theme dialog.category-modal,
body.light-theme dialog.weather-modal {
    background-color: #ffffff;
    color: #202124;
    border-color: #dadce0;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

body.light-theme .modal-header,
body.light-theme .weather-modal-header { background-color: #f1f3f4; border-bottom-color: #dadce0; }
body.light-theme .modal-header h3,
body.light-theme .weather-modal-header h3,
body.light-theme .section-title,
body.light-theme .national-links-list a,
body.light-theme .footer-text a,
body.light-theme .brand-subtle,
body.light-theme .directory-main-btn,
body.light-theme .header-link { color: #1a73e8; }

body.light-theme .modal-close-btn,
body.light-theme dialog.weather-modal .close-btn,
body.light-theme .theme-toggle-btn { color: #3c4043; }

body.light-theme .modal-close-btn:hover,
body.light-theme dialog.weather-modal .close-btn:hover { background-color: rgba(0, 0, 0, 0.05); color: #d93025; }
body.light-theme .weather-modal-body { color: #3c4043; }
body.light-theme .weather-modal-body hr { border-color: #dadce0; }
body.light-theme .search-footer { border-top: none; }
body.light-theme .link-desc, body.light-theme .search-footer { color: #5f6368; }
body.light-theme .footer-text a:visited, 
body.light-theme .directory-main-btn:hover,
body.light-theme .header-link:hover { color: #681da8; }
body.light-theme .theme-toggle-btn:hover { color: #202124; }

body.light-theme #weatherSearchResults,
body.light-theme #cardWeatherSearchResults,
body.light-theme #headerWeatherSearchResults { 
    background-color: #ffffff; 
    border-color: #dadce0; 
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.15); 
}

body.light-theme #weatherSearchResults li,
body.light-theme #cardWeatherSearchResults li,
body.light-theme #headerWeatherSearchResults li { 
    border-bottom-color: #f1f3f4; 
    color: #202124; 
}

body.light-theme #weatherSearchResults li:hover,
body.light-theme #cardWeatherSearchResults li:hover,
body.light-theme #headerWeatherSearchResults li:hover,
body.light-theme #weatherSearchResults li.selected,
body.light-theme #cardWeatherSearchResults li.selected,
body.light-theme #headerWeatherSearchResults li.selected { 
    background-color: #f8f9fa; 
    color: #1a73e8; 
}

.modal-section-subtitle {
    font-size: 1.05rem;
    font-weight: 700;
    margin-bottom: 0.6rem;
    color: var(--primary-color, #007bb5);
    border-bottom: 1px solid rgba(128, 128, 128, 0.2);
    padding-bottom: 0.3rem;
}

/* ==========================================================================
   3. MEDIA QUERIES RESPONSIVAS PARA MODALES
   ========================================================================== */
@media (max-width: 768px) {
    dialog.category-modal { max-width: 100%; }
    .modal-directory-body { display: block; }
    .directory-section { margin-bottom: 16px; }
    .directory-section:last-child { margin-bottom: 0; }
    .national-links-list { display: flex; flex-direction: column; gap: 8px; }
}