:root {
    --primary: #2563eb;
    --primary-light: #3b82f6;
    --primary-dark: #1e40af;
    --bg-body: #f1f5f9;
    --bg-card: #ffffff;
    --bg-muted: #f8fafc;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1);
    --radius: 16px;
    --radius-sm: 10px;
    --radius-xs: 8px;
    --font-family: 'Inter', system-ui, -apple-system, sans-serif;
    --aqi-good: #22c55e;
    --aqi-moderate: #eab308;
    --aqi-unhealthy-sensitive: #f97316;
    --aqi-unhealthy: #ef4444;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    background: var(--bg-body);
    background-image: radial-gradient(#e2e8f0 1px, transparent 1px);
    background-size: 24px 24px;
    font-family: var(--font-family);
    color: var(--text-main);
    line-height: 1.6;
    padding: 1rem;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

.app-container {
    max-width: 520px;
    margin: 0 auto;
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}

.app-header {
    text-align: center;
    padding: 1.25rem 1rem;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
}

.app-header h1 {
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: -0.025em;
    background: linear-gradient(135deg, #1e293b 0%, #2563eb 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.city-section {
    padding: 1.5rem 1.25rem 1rem;
    text-align: center;
}

.city-title {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 0.75rem;
    line-height: 1.3;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.update-badge {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-muted);
    background: #f1f5f9;
    padding: 0.35rem 0.75rem;
    border-radius: 50px;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--bg-muted);
    border-radius: 50px;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-main);
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--aqi-moderate);
    flex-shrink: 0;
}

.status-dot.good { background: var(--aqi-good); }
.status-dot.moderate { background: var(--aqi-moderate); }
.status-dot.unhealthy-sensitive { background: var(--aqi-unhealthy-sensitive); }
.status-dot.unhealthy { background: var(--aqi-unhealthy); }
.status-dot.neutral { background: #94a3b8; }
/* Banda 5 EEA */
.status-dot.hazardous { background: #7c3aed !important; }

.metrics-section {
    padding: 0 1.25rem 1.25rem;
    border-bottom: 1px solid var(--border);
}

.metrics-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 0.625rem;
}

.metric-card {
    background: var(--bg-muted);
    border-radius: var(--radius-xs);
    padding: 1rem 0.5rem;
    text-align: center;
    transition: all 0.2s ease;
}

.metric-card.highlight { color: #fff; }
.metric-card.highlight.good { background: var(--aqi-good); }
.metric-card.highlight.moderate { background: var(--aqi-moderate); }
.metric-card.highlight.unhealthy-sensitive { background: var(--aqi-unhealthy-sensitive); }
.metric-card.highlight.unhealthy { background: var(--aqi-unhealthy); }
.metric-card.highlight.neutral { background: #94a3b8; }
/* Banda 5 EEA */
.metric-card.highlight.hazardous {
    background: #7c3aed !important;
    color: #fff !important;
}

.metric-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    opacity: 0.8;
    margin-bottom: 0.25rem;
}

.metric-value {
    font-size: 1.4rem;
    font-weight: 800;
    line-height: 1.1;
}

.metric-unit {
    font-size: 0.65rem;
    font-weight: 500;
    opacity: 0.7;
    margin-top: 0.125rem;
}

.search-section-top {
    padding: 1.25rem;
    border-bottom: 1px solid var(--border);
    background: #f8fafc;
}

.consejo-del-dia {
    padding: 1rem 1.25rem;
    background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
    border-bottom: 1px solid var(--border);
}

.consejo-del-dia p {
    font-size: 0.9rem;
    color: var(--text-main);
    line-height: 1.6;
    margin: 0;
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
}

.consejo-del-dia p::before {
    content: '💡';
    flex-shrink: 0;
}

.recommendations-section {
    padding: 1.25rem;
    background: #f8fafc;
}

.rec-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 1rem;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    transition: all 0.2s ease;
}

.rec-card:hover {
    border-color: var(--primary-light);
    box-shadow: var(--shadow);
    transform: translateY(-1px);
}

.rec-card:last-child { margin-bottom: 0; }

.rec-icon {
    width: 40px;
    height: 40px;
    background: #f1f5f9;
    border-radius: var(--radius-xs);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    flex-shrink: 0;
}

.rec-icon.warning { background: #fef2f2; }
.rec-icon.info { background: #eff6ff; }
.rec-icon.success { background: #f0fdf4; }
.rec-icon.neutral { background: #f8fafc; }

.rec-content { flex: 1; min-width: 0; }

.rec-title {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 0.25rem;
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.rec-text {
    font-size: 0.825rem;
    color: var(--text-muted);
    line-height: 1.5;
}

.wellness-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 1rem;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.wellness-info { flex: 1; }

.wellness-title {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 0.25rem;
}

.wellness-text {
    font-size: 0.825rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.wellness-badge {
    font-weight: 700;
    padding: 0.5rem 1rem;
    border-radius: 50px;
    font-size: 0.8rem;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    white-space: nowrap;
}

.wellness-badge.green { background: #dcfce7; color: #166534; }
.wellness-badge.yellow { background: #fef9c3; color: #854d0e; }
.wellness-badge.orange { background: #ffedd5; color: #9a3412; }
.wellness-badge.red { background: #fee2e2; color: #991b1b; }

.forecast-section {
    padding: 1.25rem;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}

.forecast-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
}

.forecast-card {
    background: var(--bg-muted);
    border-radius: var(--radius-sm);
    padding: 1rem 0.75rem;
    text-align: center;
    border: 1px solid var(--border);
}

.forecast-card.today {
    background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
    border-color: #bfdbfe;
}

.forecast-card.tomorrow {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    border-color: #fcd34d;
}

.forecast-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.forecast-card.today .forecast-label { color: #1e40af; }
.forecast-card.tomorrow .forecast-label { color: #92400e; }

.forecast-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    line-height: 1;
}

.forecast-temp {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 0.25rem;
}

.forecast-detail {
    font-size: 0.7rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.forecast-detail strong { color: var(--text-main); font-weight: 600; }

.activities-section { padding: 1.25rem; }

.activities-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
}

.activity-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    padding: 0.875rem 0.5rem;
    text-align: center;
    transition: all 0.2s ease;
}

.activity-card:hover {
    border-color: var(--primary-light);
    transform: translateY(-2px);
}

.activity-icon {
    font-size: 1.5rem;
    margin-bottom: 0.25rem;
    line-height: 1;
}

.activity-label {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.025em;
    margin-bottom: 0.25rem;
    line-height: 1.2;
}

.activity-value {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--text-main);
}

.activity-value.yes { color: var(--aqi-good); }
.activity-value.no { color: var(--aqi-unhealthy); }
.activity-value.maybe { color: var(--aqi-moderate); }

.search-section {
    padding: 1.25rem;
    border-top: 1px solid var(--border);
    background: #f8fafc;
}

.input-group {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    position: relative;
}

.input-field { flex: 1; }

.input-field label {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--primary);
    display: block;
    margin-bottom: 0.35rem;
    padding-left: 0.25rem;
}

.input-field input {
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 0.9rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    background: #fff;
    font-family: inherit;
    color: var(--text-main);
    transition: all 0.2s ease;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.input-field input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.autocomplete-items {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid var(--border);
    border-radius: var(--radius-xs);
    max-height: 200px;
    overflow-y: auto;
    z-index: 50;
    box-shadow: var(--shadow-lg);
    margin-top: 0.25rem;
    display: none;
    padding: 0.25rem;
}

.autocomplete-item {
    padding: 0.6rem 0.75rem;
    cursor: pointer;
    border-radius: var(--radius-xs);
    transition: background 0.15s;
    color: var(--text-main);
    font-size: 0.85rem;
}

.autocomplete-item:hover { background: #f1f5f9; }

button {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    border: none;
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius-xs);
    font-weight: 600;
    font-size: 0.875rem;
    color: white;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    white-space: nowrap;
    box-shadow: 0 2px 4px rgba(37, 99, 235, 0.3);
    align-self: flex-end;
}

button:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(37, 99, 235, 0.4);
}

button:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
}

.favorites {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.favorites-label {
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 500;
}

.fav-badge {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 50px;
    padding: 0.35rem 0.75rem;
    font-size: 0.75rem;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    cursor: pointer;
    transition: all 0.2s;
    color: var(--text-main);
    font-weight: 600;
}

.fav-badge:hover {
    background: #f1f5f9;
    border-color: var(--primary-light);
    transform: translateY(-1px);
}

.fav-badge button {
    background: none;
    border: none;
    color: #ef4444;
    font-size: 0.85rem;
    cursor: pointer;
    padding: 0;
    margin: 0;
    display: flex;
    align-items: center;
    box-shadow: none;
}

.fav-badge button:hover { transform: scale(1.15); }

#addFavoriteBtn {
    background: var(--text-muted);
    padding: 0.35rem 0.75rem;
    font-size: 0.75rem;
    border-radius: 50px;
    box-shadow: none;
}

#addFavoriteBtn:hover { background: #475569; }

#statusMessage {
    padding: 0.75rem 0 0;
    text-align: center;
    font-size: 0.8rem;
    min-height: 1.25rem;
}

.footer-note {
    text-align: center;
    font-size: 0.7rem;
    color: var(--text-muted);
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border);
    background: #f8fafc;
    line-height: 1.6;
}

.footer-note a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}

.footer-note a:hover { text-decoration: underline; }

.loading-spinner {
    display: inline-block;
    width: 0.875rem;
    height: 0.875rem;
    border: 2px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 0.6s linear infinite;
    margin-right: 0.5rem;
}

@keyframes spin { to { transform: rotate(360deg); } }

.error {
    background: #fef2f2;
    border-left: 3px solid #ef4444;
    padding: 0.625rem 0.75rem;
    border-radius: var(--radius-xs);
    margin: 0.5rem 0;
    color: #991b1b;
    font-size: 0.8rem;
}

.token-warning {
    background: #fef3c7;
    border-left: 3px solid #f59e0b;
    padding: 0.75rem 1rem;
    margin: 1rem 1.25rem;
    border-radius: var(--radius-xs);
    font-size: 0.8rem;
    color: #92400e;
}

.token-warning a {
    color: #b45309;
    font-weight: 600;
    text-decoration: underline;
}

.guide-button {
    background: var(--bg-muted);
    color: var(--text-main);
    font-size: 0.85rem;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-xs);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: none;
    border: 1px solid var(--border);
    font-family: inherit;
}

/* NUEVA CLASE PARA CENTRAR EL BOTÓN DEL GLOSARIO */
.guia-boton-wrapper {
    text-align: center;
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border);
    background: #f8fafc;
}

.guide-button:hover {
    background: #f1f5f9;
    border-color: var(--primary-light);
    transform: translateY(-1px);
}

.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
    opacity: 0;
    animation: fadeIn 0.3s ease forwards;
}

@keyframes fadeIn {
    to { opacity: 1; }
}

.modal-content {
    background: var(--bg-card);
    border-radius: var(--radius);
    max-width: 560px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    border-radius: var(--radius) var(--radius) 0 0;
}

.modal-header h3 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-main);
    margin: 0;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.75rem;
    cursor: pointer;
    color: var(--text-muted);
    padding: 0;
    box-shadow: none;
    line-height: 1;
    transition: color 0.2s;
}

.modal-close:hover {
    color: var(--text-main);
}

.modal-body {
    padding: 1.5rem;
}

.guide-section {
    margin-bottom: 1.5rem;
}

.guide-section:last-child {
    margin-bottom: 0;
}

.guide-section h4 {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 0.65rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.guide-section p {
    font-size: 0.9rem;
    color: var(--text-muted);
    line-height: 1.7;
    margin-bottom: 0.75rem;
}

.guide-section ul {
    padding-left: 1.25rem;
    font-size: 0.9rem;
    color: var(--text-muted);
    line-height: 1.8;
}

.guide-section li {
    margin-bottom: 0.5rem;
}

.guide-section strong {
    color: var(--text-main);
}

.scale-bar {
    display: flex;
    gap: 0.35rem;
    margin-top: 0.875rem;
    border-radius: var(--radius-xs);
    overflow: hidden;
    flex-wrap: wrap;
}

.scale-segment {
    flex: 1;
    text-align: center;
    padding: 0.625rem 0.35rem;
    font-size: 0.7rem;
    font-weight: 600;
    color: #fff;
    min-width: 70px;
    border-radius: 4px;
    line-height: 1.3;
}

.scale-segment.good { background: var(--aqi-good); }
.scale-segment.moderate { background: var(--aqi-moderate); }
.scale-segment.unhealthy-sensitive { background: var(--aqi-unhealthy-sensitive); }
.scale-segment.unhealthy { background: var(--aqi-unhealthy); }
.scale-segment.very-unhealthy { background: #7c3aed; }
/* Banda 5 EEA coherente con backend */
.scale-segment.hazardous { background: #7c3aed !important; }

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border);
    background: #f8fafc;
    border-radius: 0 0 var(--radius) var(--radius);
}

.modal-source {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin: 0;
    text-align: center;
    line-height: 1.5;
}

@media (min-width: 768px) {
    body { padding: 2rem; }
    .app-container { max-width: 560px; }
    .city-title { font-size: 1.6rem; }
    .metric-card { padding: 1.125rem 0.625rem; }
    .metric-value { font-size: 1.6rem; }
    .recommendations-section, .forecast-section, .activities-section, .search-section, .search-section-top { padding: 1.5rem; }
    .rec-card { padding: 1.125rem; }
    .activity-card { padding: 1rem 0.625rem; }
    .footer-note { padding: 1.25rem 1.5rem; }
}

@media (min-width: 1024px) {
    body {
        display: flex;
        align-items: flex-start;
        justify-content: center;
        min-height: 100vh;
        padding-top: 3rem;
        padding-bottom: 3rem;
    }
    .app-container { max-width: 580px; }
    .city-title { font-size: 1.75rem; }
    .app-header h1 { font-size: 1.75rem; }
}

@media (max-width: 360px) {
    body { padding: 0.5rem; }
    .city-title { font-size: 1.2rem; }
    .metric-value { font-size: 1.2rem; }
    .metric-label { font-size: 0.6rem; }
    .rec-title { font-size: 0.85rem; }
    .rec-text { font-size: 0.775rem; }
    .forecast-grid { grid-template-columns: 1fr; }
    .activity-label { font-size: 0.6rem; }
    .input-group { flex-direction: column; }
    button { width: 100%; align-self: stretch; }
    .update-badge { font-size: 0.65rem; padding: 0.25rem 0.5rem; }
    .metrics-row { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 480px) {
    .modal-content {
        max-height: 90vh;
    }
    .scale-bar {
        flex-wrap: wrap;
    }
    .scale-segment {
        flex: 1 1 45%;
        min-width: unset;
    }
    .modal-header {
        padding: 1rem;
    }
    .modal-body {
        padding: 1.25rem 1rem;
    }
}

.modal-content::-webkit-scrollbar {
    width: 8px;
}

.modal-content::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}

.modal-content::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

.modal-content::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* --- FIX DEFINITIVO PARA MODALES EN MÓVIL --- */
@media (max-width: 480px) {
    .modal {
        align-items: center !important;
        justify-content: center !important;
        padding: 1rem !important;
    }
}
