/* 
    Monitor de Extrusoras - Estilos Principales
    Cliente: Lujumar - Plásticos
    Última modificación: 09/02/2026
    Versión: 2.4.0
    
    CAMBIOS EN ESTA VERSIÓN:
    - Solo gira el icono 🔄 dentro del botón, no el botón completo
*/

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #e8edf2;
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 800px;
    margin: 0 auto;
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    overflow: hidden;
}

/* Header */
.header {
    background: linear-gradient(135deg, #2e7d32 0%, #388e3c 100%);
    color: white;
    padding: 24px;
    text-align: center;
    position: relative;
}

.header h1 {
    font-size: 28px;
    margin-bottom: 8px;
}

.status {
    display: inline-block;
    padding: 6px 12px;
    background: rgba(255,255,255,0.2);
    border-radius: 20px;
    font-size: 12px;
    margin-top: 8px;
}

.status.connected {
    background: rgba(76, 175, 80, 0.3);
}

/* Selector */
.selector-section {
    padding: 24px;
    background: #ffffff;
    border-bottom: 1px solid #e0e0e0;
}

.selector-container {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.selector-group {
    flex: 1;
}

label {
    display: block;
    font-weight: 600;
    margin-bottom: 8px;
    color: #333;
    font-size: calc(14px * var(--font-scale, 1));
}

select {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #ddd;
    border-radius: 8px;
    font-size: calc(16px * var(--font-scale, 1));
    background: white;
    cursor: pointer;
    transition: border-color 0.3s;
}

select:focus {
    outline: none;
    border-color: #667eea;
}

/* Botón de Refrescar - MEJORADO */
.refresh-btn {
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, #2e7d32 0%, #388e3c 100%);
    border: none;
    border-radius: 8px;
    color: white;
    font-size: 26px;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(46, 125, 50, 0.3);
    line-height: 1;
    position: relative;
    overflow: hidden;
}

.refresh-btn:hover {
    background: linear-gradient(135deg, #388e3c 0%, #43a047 100%);
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(46, 125, 50, 0.4);
}

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

/* Icono dentro del botón */
.refresh-icon {
    display: inline-block;
    transition: transform 0.3s ease;
}

/* Solo el ICONO gira cuando el botón tiene la clase .spinning */
.refresh-btn.spinning .refresh-icon {
    animation: spin-icon 1s linear infinite;
}

/* Animación de rotación para el icono */
@keyframes spin-icon {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* Animación antigua del botón completo - YA NO SE USA
@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.refresh-btn.spinning {
    animation: spin 1s linear infinite;
}
*/

/* Motor Display */
.motor-display {
    padding: 24px;
    text-align: center;
    position: relative;
}

/* Freshness Indicator - Fuera del contenedor de imagen */
.freshness-indicator {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 20px;
    border-radius: 20px;
    font-size: calc(12px * var(--font-scale, 1));
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    margin-bottom: 16px;
}

.motor-image-container {
    position: relative;
    max-width: 800px;
    margin: 0 auto 24px;
    padding: 60px 20px;
}

.motor-image {
    width: 100%;
    height: auto;
    border-radius: 12px;
}

/* Freshness Indicator - Fuera del contenedor de imagen */
.freshness-indicator {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 20px;
    border-radius: 20px;
    font-size: calc(12px * var(--font-scale, 1));
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    margin-bottom: 16px;
}

.freshness-indicator.fresh {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    color: white;
}

.freshness-indicator.old {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
    color: white;
}

.freshness-indicator.very-old {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: white;
}

.freshness-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: white;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Current Values Overlay */
.current-values {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    grid-template-rows: auto;
    gap: 0;
    pointer-events: none;
}

/* Silo Indicators */
.silo-indicators {
    position: absolute;
    top: 2%;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-around;
    padding: 0 30px;
    pointer-events: none;
}

.silo-box {
    background: rgba(46, 125, 50, 0.90);
    color: white;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: calc(11px * var(--font-scale, 1));
    font-weight: bold;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
    text-align: center;
    min-width: 50px;
    pointer-events: auto;
}

.silo-label {
    font-size: calc(9px * var(--font-scale, 1));
    opacity: 0.9;
}

/* Production Values */
.production-values {
    position: absolute;
    top: 30%;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-around;
    padding: 0 40px;
    pointer-events: none;
    gap: 12px;
}

.prod-box {
    background: rgba(255, 255, 255, 0.92);
    padding: 12px 16px;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    pointer-events: auto;
    border: 2px solid rgba(224, 224, 224, 0.8);
    min-width: 110px;
    flex: 1;
    max-width: 140px;
}

.prod-box .value-label {
    font-size: calc(11px * var(--font-scale, 1));
    color: #666;
    margin-bottom: 4px;
}

.prod-box .value-data {
    font-size: calc(20px * var(--font-scale, 1));
    font-weight: bold;
    color: #1e3c72;
}

/* Bottom Info */
.bottom-info {
    position: absolute;
    bottom: -30px;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-around;
    padding: 0 40px;
    pointer-events: none;
    gap: 12px;
}

.info-box {
    background: rgba(255, 255, 255, 0.92);
    padding: 10px 16px;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    pointer-events: auto;
    border: 2px solid rgba(224, 224, 224, 0.8);
    flex: 1;
    max-width: 45%;
}

.info-label {
    font-size: calc(11px * var(--font-scale, 1));
    color: #666;
    margin-bottom: 2px;
}

.info-value {
    font-size: calc(16px * var(--font-scale, 1));
    font-weight: bold;
    color: #1e3c72;
}

.value-label {
    font-size: 12px;
    color: #666;
    margin-bottom: 4px;
}

.value-data {
    font-size: 20px;
    font-weight: bold;
    color: #1e3c72;
}

/* Data Grid */
.data-grid {
    padding: 24px;
    background: #ffffff;
}

.grid-title {
    font-size: calc(18px * var(--font-scale, 1));
    font-weight: 600;
    margin-bottom: 16px;
    color: #333;
}

.grid-subtitle {
    font-size: calc(14px * var(--font-scale, 1));
    color: #333;
    margin-bottom: 12px;
    font-style: italic;
    font-weight: 500;
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

thead {
    background: #1e3c72;
    color: white;
}

th {
    padding: 12px;
    text-align: left;
    font-weight: 600;
    font-size: calc(13px * var(--font-scale, 1));
}

td {
    padding: 10px 12px;
    border-bottom: 1px solid #f0f0f0;
    font-size: calc(13px * var(--font-scale, 1));
    vertical-align: top;
}

tr:last-child td {
    border-bottom: none;
}

tbody tr {
    cursor: pointer;
    transition: background 0.2s;
}

tbody tr:hover {
    background: #f8f9fa;
}

.row-main {
    background: white;
}

.row-detail {
    background: #f8f9fa;
    display: none;
}

.row-detail.expanded {
    display: table-row;
}

/* Expand Button */
.expand-btn {
    background: #1e3c72;
    color: white;
    border: none;
    border-radius: 4px;
    width: 24px;
    height: 24px;
    cursor: pointer;
    font-weight: bold;
    transition: all 0.2s;
}

.expand-btn:hover {
    background: #2a5298;
}

.expand-btn.expanded {
    transform: rotate(45deg);
}

/* Detail Grid */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    padding: 8px;
}

.detail-item {
    background: white;
    padding: 8px;
    border-radius: 6px;
    border: 1px solid #e0e0e0;
}

.detail-label {
    font-size: calc(10px * var(--font-scale, 1));
    color: #666;
    margin-bottom: 2px;
}

.detail-value {
    font-weight: 600;
    color: #333;
    font-size: calc(13px * var(--font-scale, 1));
}

/* Loading */
.loading {
    text-align: center;
    padding: 40px;
    color: #666;
    display: none;
}

.spinner {
    border: 3px solid #f3f3f3;
    border-top: 3px solid #667eea;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 0 auto 16px;
}

/* Last Update & Font Controls */
.last-update {
    text-align: center;
    padding: 16px;
    color: #666;
    font-size: calc(12px * var(--font-scale, 1));
    background: #f8f9fa;
    border-top: 1px solid #e0e0e0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
}

.last-update-text {
    flex: 1;
    min-width: 200px;
}

.font-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

.font-btn {
    background: #1e3c72;
    border: 2px solid #2a5298;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
    font-size: 18px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.font-btn:hover {
    background: #2a5298;
    transform: scale(1.1);
}

.font-size-indicator {
    color: #666;
    font-size: 12px;
    font-weight: 600;
    min-width: 50px;
    text-align: center;
}

/* Version Info */
.version-info {
    text-align: center;
    padding: 12px;
    color: #999;
    font-size: 11px;
    background: #f0f0f0;
    font-family: monospace;
    position: relative;
}

/* Loading Bar */
.loading-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 50%, #667eea 100%);
    background-size: 200% 100%;
    width: 0%;
    transition: width 0.3s ease;
    animation: shimmer 1.5s infinite;
    opacity: 0;
}

.loading-bar.active {
    opacity: 1;
    width: 100%;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Responsive Design */
@media (max-width: 640px) {
    body {
        padding: 10px;
    }

    .header h1 {
        font-size: 22px;
    }
    
    .selector-container {
        gap: 8px;
    }
    
    .refresh-btn {
        width: 44px;
        height: 44px;
        font-size: 22px;
    }

    .motor-image-container {
        padding: 30px 10px;
    }

    .silo-indicators {
        padding: 0 10px;
    }

    .silo-box {
        padding: 4px 6px;
        font-size: 10px;
        min-width: 35px;
    }

    .production-values {
        padding: 0 15px;
        flex-direction: column;
        gap: 6px;
        top: 35%;
        align-items: center;
    }

    .prod-box {
        min-width: auto;
        width: 90%;
        max-width: 200px;
    }

    .bottom-info {
        padding: 0 15px;
        flex-direction: column;
        gap: 6px;
        align-items: center;
    }

    .info-box {
        max-width: 90%;
        width: 90%;
    }

    table {
        font-size: 11px;
    }

    th, td {
        padding: 8px 6px;
    }

    .detail-grid {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .value-data {
        font-size: 16px;
    }
}

@media (max-width: 480px) {
    .freshness-indicator {
        font-size: calc(10px * var(--font-scale, 1));
        padding: 6px 12px;
    }
}