/* Estilos Globales - EMAChabas UI v2.0 */

:root {
    --bg-color: #f0f4f8;
    --text-main: #2d3748;
    --text-muted: #4a5568;
    /* Glassmorphism background */
    --card-bg: rgba(255, 255, 255, 0.75);
    /* Softer shadows */
    --card-shadow: 0 4px 12px rgba(0, 0, 0, 0.04), 0 2px 4px rgba(0, 0, 0, 0.02);
    --card-hover-shadow: 0 10px 25px rgba(0, 0, 0, 0.08), 0 5px 10px rgba(0, 0, 0, 0.03);
    
    --primary: #4299e1;
    --accent: #ed8936;
    --danger: #e53e3e;
    
    /* Subtler glass border */
    --glass-border: 1px solid rgba(255, 255, 255, 0.6);
    --transition: all 0.25s cubic-bezier(0.25, 0.8, 0.25, 1);
}

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    margin: 0;
    padding: 15px; /* Reduced padding */
    animation: fadeIn 0.6s ease-out;
    background-image: radial-gradient(circle at 10% 20%, rgba(66, 153, 225, 0.03) 0%, transparent 40%),
                      radial-gradient(circle at 90% 80%, rgba(237, 137, 54, 0.03) 0%, transparent 40%);
    background-attachment: fixed;
}

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

h2 {
    text-align: center;
    font-weight: 700;
    font-size: 1.5rem; /* Reduced from 1.8 */
    margin-bottom: 25px;
    color: var(--text-main);
}

.section-title {
    margin-top: 35px;
    margin-bottom: 20px;
    font-size: 1.35rem; /* Reduced from 1.5 */
}

/* BENTO GRID */
.bento-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); /* Reduced from 240px */
    gap: 15px; /* Reduced from 20px */
    max-width: 950px; /* Scaled down central width */
    margin: 0 auto;
}

.bento-large {
    grid-column: span 2;
}
@media (max-width: 700px) {
    .bento-large {
        grid-column: span 1;
    }
}

/* CARD STYLING */
.card {
    background: var(--card-bg);
    border-radius: 16px; /* Reduced from 20px */
    padding: 18px; /* Reduced from 24px */
    box-shadow: var(--card-shadow);
    border: var(--glass-border);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
}

.card:hover {
    transform: translateY(-3px); /* Subtle lift */
    box-shadow: var(--card-hover-shadow);
}

/* Card Header (Icon + Title) */
.card-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    color: #4a5568; 
    font-weight: 500;
    font-size: 1rem; /* Scaled down */
    z-index: 2;
}

.card-header i {
    font-size: 1.1rem;
    width: 20px;
    text-align: center;
}

/* Weather Icons Colors */
.icon-temp { color: var(--accent); }
.icon-hum { color: var(--primary); }
.icon-wind { color: #805ad5; }
.icon-rain { color: #3182ce; }
.icon-press { color: #718096; }
.icon-time { color: #38a169; }

/* Card Values */
.card-value {
    font-size: 2rem; /* Reduced from 2.5rem */
    font-weight: 700;
    color: var(--text-main);
    margin: 5px 0 5px 0;
    z-index: 2;
}

.card-value span {
    font-size: 1rem; /* Unit size reduced */
    color: var(--text-muted);
}

.card-subtitle {
    font-size: 0.85rem; /* Reduced from 0.95 */
    color: var(--text-muted);
    font-weight: 500;
    z-index: 2;
}

/* Decorative subtle background icon */
.card-bg-icon {
    position: absolute;
    right: -15px;
    bottom: -15px;
    font-size: 6.5rem; /* Reduced from 8 */
    opacity: 0.03;
    z-index: 1;
    transform: rotate(-10deg);
}

/* List container standard */
.data-list {
    margin-top: 15px;
    border-top: 1px solid rgba(0,0,0,0.05);
    padding-top: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.data-item {
    display: flex;
    justify-content: space-between;
    font-size: 0.9rem;
    background: rgba(255, 255, 255, 0.4);
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.7);
}

/* Universal Table styling matching Bento */
.table-container {
    max-width: 1000px;
    margin: auto;
    background: var(--card-bg);
    border-radius: 16px;
    box-shadow: var(--card-shadow);
    border: var(--glass-border);
    backdrop-filter: blur(12px);
    overflow: hidden;
    overflow-x: auto; /* Responsive scrolling */
}

table.bento-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    text-align: center;
}

table.bento-table th {
    background-color: rgba(0, 0, 0, 0.03);
    color: var(--text-main);
    font-weight: 600;
    padding: 14px 10px;
    border-bottom: 2px solid rgba(0,0,0,0.05);
    white-space: nowrap;
}

table.bento-table td {
    padding: 12px 10px;
    border-bottom: 1px solid rgba(0,0,0,0.03);
    color: var(--text-muted);
}

table.bento-table tbody tr:hover {
    background-color: rgba(0, 0, 0, 0.015);
}

/* Style for controls inside tables */
.table-controls {
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(255, 255, 255, 0.5);
    border-bottom: 1px solid rgba(0,0,0,0.05);
}

.table-controls input {
    border: 1px solid #cbd5e0;
    border-radius: 6px;
    padding: 6px 12px;
    font-family: inherit;
    font-size: 0.9rem;
    background: white;
}

/* MOBILE RESPONSIVE BENTO TABLE */
@media (max-width: 768px) {
    table.bento-table {
        display: block;
    }
    table.bento-table thead {
        display: none;
    }
    table.bento-table tbody {
        display: block;
        padding: 10px;
    }
    table.bento-table tr {
        display: block;
        background: rgba(255, 255, 255, 0.6);
        border: 1px solid rgba(0,0,0,0.05);
        border-radius: 12px;
        margin-bottom: 15px;
        padding: 10px 15px;
        box-shadow: 0 2px 4px rgba(0,0,0,0.02);
    }
    table.bento-table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 8px 0;
        border-bottom: 1px dashed rgba(0,0,0,0.08); /* Make dividing lines visible */
        text-align: right;
    }
    table.bento-table td:last-child {
        border-bottom: none;
    }
    table.bento-table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-muted);
        text-align: left;
        margin-right: 15px;
        font-size: 0.85rem;
    }
}

/* Enable Pinch Zoom on Charts for Mobile */

/* Animaciones de cambio de valor (Micro-feedback) */
@keyframes flashRed {
    0% { background-color: rgba(229, 62, 62, 0.2); }
    100% { background-color: var(--card-bg); }
}
@keyframes flashBlue {
    0% { background-color: rgba(66, 153, 225, 0.2); }
    100% { background-color: var(--card-bg); }
}
@keyframes flashGreen {
    0% { background-color: rgba(56, 161, 105, 0.2); }
    100% { background-color: var(--card-bg); }
}

.flash-up { animation: flashRed 2s ease-out; }
.flash-down { animation: flashBlue 2s ease-out; }
.flash-change { animation: flashGreen 2s ease-out; }

/* Efecto de pulso para lluvia */
@keyframes rainDrop {
    0% { transform: scale(1); filter: drop-shadow(0 0 0px var(--primary)); }
    100% { transform: scale(1.1); filter: drop-shadow(0 0 10px var(--primary)); }
}
.pulse-rain {
    animation: rainDrop 1.5s infinite alternate;
}

/* --- Análisis Local Avanzado --- */
.analysis-panel {
    background: #ffffff;
    border-radius: 16px;
    margin: 20px auto;
    max-width: 950px;
    overflow: hidden;
    box-shadow: var(--card-shadow);
    border: 1px solid rgba(0,0,0,0.05);
    transition: var(--transition);
}

.analysis-header {
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    background: #f8fafc;
}

.analysis-header h2 {
    margin: 0;
    font-size: 1rem;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: 10px;
}

.analysis-summary {
    display: flex;
    gap: 12px;
    align-items: center;
}

.badge {
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
}

.badge-low { background: #e2e8f0; color: #475569; }
.badge-medium { background: #fef3c7; color: #92400e; }
.badge-high { background: #fee2e2; color: #991b1b; }

.analysis-content {
    display: none; /* OCULTO POR DEFECTO */
    padding: 20px;
    border-top: 1px solid #f1f5f9;
}

.analysis-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 15px;
}

.analysis-item {
    padding: 15px;
    background: #ffffff;
    border-radius: 10px;
    border: 1px solid #f1f5f9;
}

.analysis-item h4 {
    margin: 0 0 5px;
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
}

.analysis-item .value {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--primary);
}

/* --- Sistema de Tarjetas Expandibles (Accordion) --- */
.card {
    cursor: pointer;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 20px rgba(0,0,0,0.1);
}

.card.active {
    grid-column: 1 / -1 !important; /* SE EXPANDE A ANCHO COMPLETO EN EL GRID */
    background: #ffffff;
    z-index: 10;
}

.card-details {
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    transition: all 0.5s ease;
    padding: 0 5px;
}

.card.active .card-details {
    max-height: 800px;
    opacity: 1;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid #f1f5f9;
}

.details-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
}

@media (min-width: 768px) {
    .details-grid {
        grid-template-columns: 1.5fr 1fr;
    }
}

.chart-container-inline {
    height: 250px;
    width: 100%;
}

.explanation-box {
    background: #f0f9ff;
    padding: 15px;
    border-radius: 12px;
    border-left: 4px solid var(--primary);
}

.explanation-box strong {
    display: block;
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--primary);
    margin-bottom: 5px;
}

.explanation-box p {
    margin: 0;
    font-size: 0.95rem;
    line-height: 1.5;
    color: #1e3a8a;
}

.main-container { max-width: 950px; margin: 0 auto; padding: 0 10px; }

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

/* --- Super-Cards layouts (Compact Grids) --- */
.card-compact-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-top: 10px;
    z-index: 2;
}

.compact-item {
    display: flex;
    flex-direction: column;
    padding: 8px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.5);
}

.compact-item span {
    font-size: 0.65rem;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 700;
}

.compact-item .val {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-main);
}

.compact-item .unit {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 400;
    margin-left: 1px;
}

/* Prediction / Diagnosis Box */
.diagnosis-container {
    margin-top: 15px;
    z-index: 2;
}

.diagnosis-box {
    padding: 12px 15px;
    border-radius: 12px;
    border-left: 4px solid #cbd5e0;
    background: rgba(255, 255, 255, 0.5);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.diagnosis-box.level-low { border-left-color: #38a169; background: rgba(56, 161, 105, 0.05); }
.diagnosis-box.level-medium { border-left-color: #ed8936; background: rgba(237, 137, 54, 0.05); }
.diagnosis-box.level-high { border-left-color: #e53e3e; background: rgba(229, 62, 62, 0.05); }

.diag-title {
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    gap: 8px;
}

.diag-tip {
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.4;
    font-style: italic;
}

/* Rain History Table inside Card */
.rain-history-compact {
    width: 100%;
    font-size: 0.85rem;
    border-collapse: collapse;
    margin-top: 10px;
}

.rain-history-compact td {
    padding: 8px 0;
    border-bottom: 1px solid rgba(0,0,0,0.05);
}

.rain-history-compact tr:last-child td { border-bottom: none; }

/* Global badge colors adjustment for consistency */
.badge-baja { background: #e2e8f0; color: #4a5568; }
.badge-media { background: #fef3c7; color: #92400e; }
.badge-alta { background: #fee2e2; color: #991b1b; }

@media (max-width: 480px) {
    body { padding: 10px; }
    .bento-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
    .bento-large {
        grid-column: span 2;
    }
    .card { padding: 12px; }
    .card-value { font-size: 1.5rem; }
    .card-header { font-size: 0.85rem; gap: 6px; }
    .card-compact-grid { gap: 8px; }
    .compact-item .val { font-size: 1rem; }
}

/* Récords Históricos Mini-Table */
.records-table-wrapper {
    margin-top: 12px;
    padding: 15px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.5);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.02);
}

.records-table-wrapper strong {
    display: block;
    margin-bottom: 10px;
    color: var(--primary);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.records-mini-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.records-mini-table th {
    text-align: left;
    padding: 5px 8px 5px 0;
    color: var(--text-muted);
    font-weight: 600;
    border-bottom: 1.5px solid rgba(0,0,0,0.05);
}

.records-mini-table td {
    padding: 8px 8px 8px 0;
    border-bottom: 1px solid rgba(0,0,0,0.03);
    color: var(--text-main);
    font-weight: 500;
}

.records-mini-table td span {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 400;
}

.records-mini-table tr:last-child td {
    border-bottom: none;
}
.idea-clave {
    background: rgba(66, 153, 225, 0.08);
    border-left: 3px solid var(--primary);
    padding: 10px;
    border-radius: 6px;
    margin-top: 10px;
    font-size: 0.85rem;
    color: var(--text-main);
}
.explanation-box p small {
    display: block;
    margin-top: 8px;
    color: var(--text-muted);
}
.explanation-box strong {
    display: block;
    margin-bottom: 8px;
    font-size: 1rem;
    color: var(--primary);
}
