/**
 * Simulador de Méritos GC - Estilos
 * Adaptado para IGC Profesional (https://www.igcprofesional.es/)
 */

/* ================================
   VARIABLES Y RESET
   ================================ */
.smgc-container {
    --smgc-primary: #006400;
    --smgc-primary-dark: #004d00;
    --smgc-primary-light: #228B22;
    --smgc-accent: #c9a227;
    --smgc-accent-light: #d4af37;
    --smgc-text: #333333;
    --smgc-text-light: #666666;
    --smgc-bg: #ffffff;
    --smgc-bg-alt: #f8f9fa;
    --smgc-border: #e0e0e0;
    --smgc-error: #dc3545;
    --smgc-success: #28a745;
    --smgc-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    --smgc-radius: 8px;
}

.smgc-container * {
    box-sizing: border-box;
}

/* ================================
   CONTENEDOR PRINCIPAL
   ================================ */
.smgc-container {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    color: var(--smgc-text);
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

/* ================================
   CABECERA
   ================================ */
.smgc-header {
    text-align: center;
    margin-bottom: 30px;
    padding: 30px 20px;
    background: linear-gradient(135deg, var(--smgc-primary) 0%, var(--smgc-primary-dark) 100%);
    border-radius: var(--smgc-radius);
    color: #fff;
}

.smgc-header h2 {
    margin: 0 0 10px 0;
    font-size: 2em;
    font-weight: 700;
    color: #fff !important;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.2);
}

.smgc-subtitle {
    margin: 0;
    font-size: 1.1em;
    opacity: 0.9;
    color: #fff !important;
}

/* ================================
   MENSAJES DE ERROR
   ================================ */
.smgc-error {
    background: linear-gradient(135deg, #fff5f5 0%, #fee2e2 100%);
    border: 1px solid #fecaca;
    border-left: 4px solid var(--smgc-error);
    color: #b91c1c;
    padding: 15px 20px;
    border-radius: var(--smgc-radius);
    margin-bottom: 20px;
}

.smgc-error p {
    margin: 0;
}

/* ================================
   FORMULARIO
   ================================ */
.smgc-form {
    background: var(--smgc-bg);
    border-radius: var(--smgc-radius);
    box-shadow: var(--smgc-shadow);
    padding: 30px;
    border: 1px solid var(--smgc-border);
}

.smgc-form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-bottom: 25px;
}

/* Fila de selectores con botón Cargar */
.smgc-form-row-selects {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 20px;
    align-items: end;
    margin-bottom: 25px;
}

.smgc-form-group {
    display: flex;
    flex-direction: column;
}

.smgc-form-group-btn {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
}

.smgc-form-group-btn label {
    visibility: hidden;
    height: 0;
    margin: 0;
}

.smgc-form-group label {
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--smgc-primary-dark);
    font-size: 0.95em;
}

/* SELECTORES - Corregido para que no se corte el texto */
.smgc-form-group select {
    width: 100%;
    padding: 12px 40px 12px 15px;
    border-radius: var(--smgc-radius);
    border: 2px solid var(--smgc-border);
    background-color: var(--smgc-bg);
    color: var(--smgc-text);
    font-size: 1em;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23333' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 15px center;
    background-size: 12px;
    min-height: 48px;
    line-height: 1.4;
    white-space: normal;
    word-wrap: break-word;
}

.smgc-form-group select:focus {
    border-color: var(--smgc-primary);
    box-shadow: 0 0 0 3px rgba(0, 100, 0, 0.15);
}

.smgc-form-group select:hover {
    border-color: var(--smgc-primary-light);
}

/* Opciones del select */
.smgc-form-group select option {
    padding: 10px;
    background: #fff;
    color: var(--smgc-text);
    white-space: normal;
    word-wrap: break-word;
}

/* ================================
   SECCIÓN DE APARTADOS
   ================================ */
.smgc-apartados {
    margin-top: 30px;
    padding-top: 30px;
    border-top: 2px solid var(--smgc-border);
}

.smgc-apartados h3 {
    color: var(--smgc-primary-dark);
    font-size: 1.3em;
    margin: 0 0 20px 0;
    text-align: center;
}

/* ================================
   TABLA
   ================================ */
.smgc-table-wrapper {
    overflow-x: auto;
    margin-bottom: 25px;
    border-radius: var(--smgc-radius);
    border: 1px solid var(--smgc-border);
}

.smgc-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9em;
    min-width: 750px;
    table-layout: fixed;
}

/* Anchos de columnas ajustados */
.smgc-table th.col-codigo,
.smgc-table td.col-codigo {
    width: 9%;
    min-width: 75px;
}

.smgc-table th.col-desc,
.smgc-table td.smgc-desc {
    width: 32%;
}

.smgc-table th.col-grupo,
.smgc-table td.col-grupo {
    width: 11%;
    min-width: 85px;
}

.smgc-table th.col-umbral,
.smgc-table td.col-umbral {
    width: 10%;
    min-width: 75px;
}

.smgc-table th.col-baremo,
.smgc-table td.col-baremo {
    width: 10%;
}

.smgc-table th.col-norm,
.smgc-table td.col-norm {
    width: 12%;
}

.smgc-table th.col-reales,
.smgc-table td.smgc-puntos-reales {
    width: 16%;
}

.smgc-table thead {
    background: linear-gradient(135deg, var(--smgc-primary) 0%, var(--smgc-primary-dark) 100%) !important;
}

/* TH - Color BLANCO forzado */
.smgc-table th,
.smgc-table thead th,
.smgc-container .smgc-table th,
.smgc-container .smgc-table thead th {
    padding: 14px 8px !important;
    text-align: center !important;
    color: #ffffff !important;
    background-color: transparent !important;
    font-weight: 600 !important;
    font-size: 0.82em !important;
    text-transform: uppercase !important;
    letter-spacing: 0.3px !important;
    border: none !important;
}

/* TEXTO DE LAS CELDAS EN COLOR OSCURO (no gris) */
.smgc-table td {
    padding: 12px 8px;
    border-bottom: 1px solid var(--smgc-border);
    text-align: center;
    vertical-align: middle;
    color: #222222;
    font-weight: 500;
}

.smgc-table tbody tr:hover {
    background-color: var(--smgc-bg-alt);
}

.smgc-table tbody tr:last-child td {
    border-bottom: none;
}

.smgc-desc {
    text-align: left !important;
    word-wrap: break-word;
    overflow-wrap: break-word;
    color: #222222;
}

/* Fila de grupo */
.smgc-grupo-header {
    background: linear-gradient(135deg, var(--smgc-accent) 0%, var(--smgc-accent-light) 100%) !important;
}

.smgc-grupo-header td {
    color: #ffffff !important;
    font-weight: 700 !important;
    text-transform: uppercase;
    font-size: 0.85em;
    letter-spacing: 1px;
    padding: 10px 12px;
    text-align: center !important;
}

.smgc-grupo-header:hover {
    background: linear-gradient(135deg, var(--smgc-accent) 0%, var(--smgc-accent-light) 100%) !important;
}

/* Input de umbral - Más compacto */
.smgc-input-umbral {
    width: 100%;
    max-width: 70px;
    padding: 8px 5px;
    border: 2px solid var(--smgc-border);
    border-radius: 5px;
    text-align: right;
    font-size: 0.9em;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.smgc-input-umbral:focus {
    outline: none;
    border-color: var(--smgc-primary);
    box-shadow: 0 0 0 3px rgba(0, 100, 0, 0.15);
}

/* Puntos reales */
.smgc-puntos-reales {
    font-weight: 700;
    color: var(--smgc-primary) !important;
    transition: background-color 0.3s ease, transform 0.2s ease;
}

/* Animación cuando se actualiza */
.smgc-puntos-reales.smgc-updated {
    background-color: rgba(0, 100, 0, 0.15);
    transform: scale(1.05);
}

/* ================================
   TOTALES
   ================================ */
.smgc-totales {
    background: linear-gradient(135deg, var(--smgc-bg-alt) 0%, #eef5ee 100%);
    border: 2px solid var(--smgc-primary-light);
    border-radius: var(--smgc-radius);
    padding: 25px;
    margin-top: 25px;
}

.smgc-total-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px dashed var(--smgc-border);
}

.smgc-total-item:last-child {
    border-bottom: none;
}

.smgc-total-label {
    font-weight: 600;
    color: var(--smgc-text);
}

.smgc-total-value {
    font-size: 1.2em;
    font-weight: 700;
    color: var(--smgc-primary);
    transition: transform 0.3s ease, color 0.3s ease;
}

/* Animación cuando se actualiza el total */
.smgc-total-value.smgc-total-updated {
    transform: scale(1.15);
    color: var(--smgc-primary-dark);
}

.smgc-total-final {
    margin-top: 10px;
    padding-top: 15px;
    border-top: 2px solid var(--smgc-primary);
    border-bottom: none;
}

.smgc-total-final .smgc-total-label {
    font-size: 1.1em;
    color: var(--smgc-primary-dark);
}

.smgc-total-final .smgc-total-value {
    font-size: 1.5em;
    color: var(--smgc-primary-dark);
}

/* ================================
   BOTONES - Border radius 5px
   ================================ */
.smgc-actions {
    margin-top: 30px;
    text-align: center;
}

.smgc-button {
    display: inline-block;
    min-width: 150px;
    padding: 12px 30px;
    border-radius: 5px !important;
    border: none !important;
    font-size: 1em;
    font-weight: 700;
    cursor: pointer;
    color: #fff !important;
    background: linear-gradient(135deg, var(--smgc-primary) 0%, var(--smgc-primary-dark) 100%) !important;
    box-shadow: 0 4px 15px rgba(0, 100, 0, 0.3);
    transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.smgc-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(0, 100, 0, 0.4);
    background: linear-gradient(135deg, var(--smgc-primary-light) 0%, var(--smgc-primary) 100%) !important;
}

.smgc-button:active {
    transform: translateY(0);
    box-shadow: 0 2px 10px rgba(0, 100, 0, 0.3);
}

/* Botón Cargar - junto a los selectores */
.smgc-button-cargar {
    min-width: 120px;
    padding: 12px 25px;
    height: 48px;
}

/* Botón Calcular */
.smgc-button-calcular {
    min-width: 200px;
    padding: 14px 40px;
}

/* ================================
   RESPONSIVE
   ================================ */
@media (max-width: 900px) {
    .smgc-form-row-selects {
        grid-template-columns: 1fr 1fr;
    }
    
    .smgc-form-group-btn {
        grid-column: 1 / -1;
        justify-content: center;
        align-items: center;
    }
    
    .smgc-form-group-btn label {
        display: none;
    }
    
    .smgc-button-cargar {
        width: 100%;
        max-width: 300px;
    }
}

@media (max-width: 768px) {
    .smgc-container {
        padding: 10px;
    }

    .smgc-header {
        padding: 20px 15px;
    }

    .smgc-header h2 {
        font-size: 1.5em;
    }

    .smgc-form {
        padding: 20px 15px;
    }

    .smgc-form-row-selects {
        grid-template-columns: 1fr;
    }

    /* Selectores en móvil */
    .smgc-form-group select {
        min-height: 52px;
        font-size: 0.95em;
        padding: 12px 40px 12px 12px;
    }

    /* Tabla responsive */
    .smgc-table-wrapper {
        border: none;
    }

    .smgc-table {
        min-width: unset;
        table-layout: auto;
    }

    .smgc-table thead {
        display: none;
    }

    .smgc-table tbody tr {
        display: block;
        margin-bottom: 15px;
        background: var(--smgc-bg);
        border: 1px solid var(--smgc-border);
        border-radius: var(--smgc-radius);
        box-shadow: var(--smgc-shadow);
    }

    .smgc-table tbody tr:hover {
        background: var(--smgc-bg);
    }

    .smgc-table td {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        padding: 12px 15px;
        text-align: left;
        border-bottom: 1px solid var(--smgc-border);
        width: 100% !important;
        min-width: unset !important;
        gap: 4px;
    }

    .smgc-table td::before {
        content: attr(data-label);
        font-weight: 700;
        font-size: 0.75em;
        color: var(--smgc-primary-dark);
        text-transform: uppercase;
        letter-spacing: 0.5px;
        margin-bottom: 2px;
    }

    .smgc-table td:last-child {
        border-bottom: none;
    }

    .smgc-desc {
        text-align: left !important;
        max-width: none;
        word-break: break-word;
    }

    .smgc-grupo-header {
        border-radius: var(--smgc-radius);
        margin-bottom: 10px;
    }

    .smgc-grupo-header td {
        justify-content: center;
    }

    .smgc-grupo-header td::before {
        display: none;
    }

    .smgc-input-umbral {
        max-width: 100%;
        width: 100%;
        text-align: left;
    }

    .smgc-totales {
        padding: 20px 15px;
    }

    .smgc-total-item {
        flex-direction: column;
        text-align: center;
        gap: 5px;
    }

    .smgc-button {
        width: 100%;
        min-width: unset;
    }
    
    .smgc-button-cargar {
        max-width: none;
    }
}

/* ================================
   PRINT STYLES
   ================================ */
@media print {
    .smgc-container {
        padding: 0;
    }

    .smgc-header {
        background: none !important;
        color: #000 !important;
        border: 2px solid #000;
    }

    .smgc-header h2,
    .smgc-subtitle {
        color: #000 !important;
    }

    .smgc-form {
        box-shadow: none;
        border: none;
    }

    .smgc-form-row-selects,
    .smgc-actions {
        display: none;
    }

    .smgc-table thead {
        background: #f0f0f0 !important;
    }

    .smgc-table th {
        color: #000 !important;
    }

    .smgc-grupo-header {
        background: #e0e0e0 !important;
    }

    .smgc-grupo-header td {
        color: #000 !important;
    }

    .smgc-button {
        display: none;
    }
}

/* ================================
   ACCESIBILIDAD
   ================================ */
.smgc-form-group select:focus-visible,
.smgc-input-umbral:focus-visible,
.smgc-button:focus-visible {
    outline: 3px solid var(--smgc-accent);
    outline-offset: 2px;
}

/* Modo alto contraste */
@media (prefers-contrast: high) {
    .smgc-container {
        --smgc-border: #000;
    }

    .smgc-form {
        border-width: 2px;
    }

    .smgc-table td {
        border-color: #000;
    }
}

/* Reducir movimiento */
@media (prefers-reduced-motion: reduce) {
    .smgc-button,
    .smgc-form-group select,
    .smgc-input-umbral,
    .smgc-puntos-reales,
    .smgc-total-value {
        transition: none;
    }
    
    .smgc-puntos-reales.smgc-updated,
    .smgc-total-value.smgc-total-updated {
        transform: none;
    }
}
