/* Estilos Generales */
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: #f4f7f6;
    color: #333;
    margin: 0;
    padding: 20px;
}
.container {
    max-width: 900px;
    margin: 0 auto;
    background-color: #ffffff;
    padding: 25px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
.hidden { display: none; }

/* --- Estilos de Pestañas (Tabs) --- */
.tabs { display: flex; border-bottom: 2px solid #dee2e6; margin-bottom: 25px; }
.tab-btn { padding: 10px 20px; border: none; background-color: transparent; cursor: pointer; font-size: 16px; font-weight: 600; color: #495057; border-bottom: 2px solid transparent; margin-bottom: -2px; }
.tab-btn.active { color: #3498db; border-bottom-color: #3498db; }

/* Estilos del Encabezado */
.main-header { border-bottom: 1px solid #eee; padding-bottom: 20px; margin-bottom: 20px; }
.form-section { flex-grow: 1; }
.form-section h1 { margin-top: 0; text-align: left; color: #2c3e50; }
.header-fieldset { border: none; padding: 0; margin: 0; }

/* Estilos de Formularios y Campos */
main > fieldset, #history-view main { margin-bottom: 25px; }
fieldset { border: 1px solid #ddd; border-radius: 5px; padding: 20px; background-color: #fafafa; }
legend { font-weight: bold; color: #3498db; padding: 0 10px; }
.form-row, .form-grid-header { margin-bottom: 15px; }
.form-grid-header { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 20px; }
label { display: block; margin-bottom: 5px; font-weight: 600; font-size: 14px; color: #555; }
input[type="text"], input[type="date"], input[type="number"], select { width: 100%; padding: 10px; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box; font-size: 16px; }

/* Estilos para Grupos de Actividades (Formato Tabla) */
.activity-group { border: 1px solid #3498db; border-radius: 5px; padding: 20px; margin-top: 20px; background-color: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.05); }
.group-title { margin: 0 0 20px 0; padding-bottom: 15px; border-bottom: 1px solid #e9ecef; font-size: 18px; color: #2c3e50; font-weight: 600; }
.group-headers { font-weight: bold; color: #555; padding: 0 10px 10px; margin-bottom: 10px; border-bottom: 2px solid #dee2e6; display: grid; gap: 20px; }
.rows-wrapper .data-row { display: grid; gap: 20px; align-items: center; padding: 10px; border-radius: 4px; }
.rows-wrapper .data-row:nth-child(even) { background-color: #f8f9fa; }

/* --- Alineación de Columnas por Tipo de Actividad --- */
.group-headers.limpieza-excavacion-grid, .data-row.limpieza-excavacion-grid { grid-template-columns: 2fr 1fr 40px; }
.group-headers.soporte-compactacion-grid, .data-row.soporte-compactacion-grid { grid-template-columns: 2fr 1fr 40px; }
.group-headers.relleno-filete-grid, .data-row.relleno-filete-grid { grid-template-columns: 1fr 1fr 2fr 1fr 40px; }
.group-headers.relleno-area-grid, .data-row.relleno-area-grid { grid-template-columns: 1fr 1fr 2fr 1fr 40px; }

.material-field-group { display: flex; flex-direction: column; gap: 10px; }
.input-with-unit { display: flex; align-items: center; gap: 8px; }
.input-with-unit input { flex-grow: 1; }
.input-with-unit span { font-weight: bold; color: #555; }

/* Botones */
.remove-row-btn, .add-row-btn, .submit-btn, .clear-btn { border: none; color: white; padding: 8px 15px; border-radius: 4px; cursor: pointer; font-weight: bold; transition: background-color 0.2s; }
.remove-row-btn { background-color: #e74c3c; width: 35px; height: 35px; padding: 0; font-size: 14px; justify-self: center; }
.remove-row-btn:hover { background-color: #c0392b; }
.add-row-btn { background-color: #2ecc71; margin-top: 20px; display: inline-block; }
.add-row-btn:hover { background-color: #27ae60; }
.submit-btn { background-color: #3498db; padding: 15px; font-size: 18px; width: 100%; margin-top: 10px; }
.submit-btn:hover { background-color: #2980b9; }
.clear-btn { background-color: #e74c3c; width: 100%; padding: 12px; font-size: 16px; margin-top: 20px; }
.clear-btn:hover { background-color: #c0392b; }

/* --- Estilos para la Vista de Historial --- */
.search-bar-container { margin-bottom: 25px; }
.history-card { border: 1px solid #ddd; border-radius: 8px; padding: 20px; background-color: #fff; margin-bottom: 25px; box-shadow: 0 1px 3px rgba(0,0,0,0.05); }
.history-card-header { padding-bottom: 15px; margin-bottom: 15px; border-bottom: 1px solid #eee; display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.history-card-header p { margin: 0; }
.history-card-header strong { color: #333; }
.history-activity-title { font-size: 16px; font-weight: bold; margin: 20px 0 10px 0; color: #2c3e50; }
.history-table { width: 100%; border-collapse: collapse; }
.history-table th, .history-table td { padding: 12px; border: 1px solid #dee2e6; text-align: left; }
.history-table th { background-color: #f8f9fa; }
.history-table tbody tr:nth-child(even) { background-color: #f8f9fa; }
.no-history-message { text-align: center; color: #777; font-style: italic; padding: 40px 20px; }

/* ============ MEDIA QUERIES PARA MÓVILES ============ */
@media (max-width: 768px) {
    body { padding: 10px; }
    .container { padding: 15px; }
    .main-header, .form-section h1 { text-align: center; }
    .group-headers { display: none; }
    .rows-wrapper .data-row { grid-template-columns: 1fr; gap: 15px; padding: 15px; border: 1px solid #dee2e6; margin-bottom: 15px; }
    .rows-wrapper .data-row:nth-child(even) { background-color: #fff; }
    .remove-row-btn { justify-self: end; grid-row: 1; }
    .mobile-field::before, .material-field-group::before, .input-with-unit::before { content: attr(data-label); display: block; font-weight: 600; margin-bottom: 5px; color: #555; font-size: 14px; }
    .data-row { display: grid !important; grid-template-columns: 1fr auto !important; }
    .data-row > div { grid-column: 1 / -1; }
    /* --- Tabla de historial responsiva --- */
    .history-table thead { display: none; }
    .history-table, .history-table tbody, .history-table tr, .history-table td { display: block; width: 100%; }
    .history-table tr { margin-bottom: 15px; border: 1px solid #ddd; border-radius: 4px; padding: 10px; }
    .history-table td { display: flex; justify-content: space-between; text-align: right !important; padding: 8px 0; border: none; border-bottom: 1px solid #eee; }
    .history-table td:last-child { border-bottom: none; }
    .history-table td::before { content: attr(data-label); font-weight: bold; text-align: left; margin-right: 15px; }
}