/* =================================
   Configuración Global
   ================================= */
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: #f4f7f6;
    color: #333;
    margin: 0;
    line-height: 1.6;
}

h1, h2, h3 {
    color: #2c3e50;
}

.container {
    display: grid;
    grid-template-areas:
        "controls column"
        "output   column";
    grid-template-columns: 350px 1fr;
    grid-gap: 20px;
    padding: 20px;
    max-width: 1600px;
    margin: 0 auto;
}

/* =================================
   Paneles de la Interfaz
   ================================= */
#controls-panel {
    grid-area: controls;
    background: #fff;
    padding: 15px;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

#output-panel {
    grid-area: output;
}

#column-viewer {
    grid-area: column;
    background: #fff;
    padding: 20px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    overflow-x: auto;
}

/* =================================
   Estilos de Formularios
   ================================= */
form fieldset {
    border: 1px solid #ddd;
    border-radius: 4px;
    margin-bottom: 15px;
}
form legend {
    font-weight: bold;
    color: #3498db;
}
form label {
    display: block;
    margin-top: 10px;
    font-size: 0.9em;
    font-weight: 600;
}
form input[type="number"],
form input[type="file"],
form select,
form textarea {
    width: 100%;
    padding: 8px;
    box-sizing: border-box; /* Importante */
    border: 1px solid #ccc;
    border-radius: 4px;
}
form button {
    background-color: #2ecc71;
    color: white;
    padding: 10px 15px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1em;
    width: 100%;
    margin-top: 10px;
}
form button:hover {
    background-color: #27ae60;
}

#btn-generate-pdf {
    background-color: #e74c3c;
}
#btn-generate-pdf:hover {
    background-color: #c0392b;
}


/* =================================
   Área de la Columna
   ================================= */
#column-wrapper {
    display: flex;
    border-left: 1px solid #000;
    border-bottom: 1px solid #000;
    min-height: 500px; 
}

.track {
    position: relative;
    border-right: 1px solid #ccc;
}
.track-title {
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    text-align: center;
    padding: 5px;
    border-bottom: 1px solid #ccc;
    background: #f9f9f9;
    font-weight: bold;
    height: 100px;
    position: sticky;
    top: 0;
    z-index: 20;
}

#scale-track { width: 40px; }
#lithology-track { 
    width: 200px;
    border: none;
}
#grainsize-track { width: 60px; }
#fossils-track { width: 50px; }
#structures-track { width: 50px; }


/* Estilos para los Estratos (generados por JS) */
.stratum {
    position: absolute;
    width: 100%;
    box-sizing: border-box;
    
    /* 1.2 Ancho Gradual (Competencia) */
    clip-path: var(--clip-path); 
}

/* =================================
   Paneles de Salida
   ================================= */
#legend-content, #table-content {
    background: #fff;
    padding: 10px;
    border-radius: 4px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    margin-top: 10px;
    max-height: 300px;
    overflow-y: auto;
}
table {
    width: 100%;
    border-collapse: collapse;
}
th, td {
    border: 1px solid #ddd;
    padding: 6px;
    text-align: left;
    font-size: 0.9em;
}
th {
    background-color: #f2f2f2;
    position: sticky;
    top: 0;
}

/* =================================
   Estilos para Función 1.4 (Escala y Grano)
   ================================= */
#scale-track {
    position: relative; /* Necesario para posicionar los 'bottom' */
    border-right: 1px solid #000;
}
.scale-tick {
    position: absolute;
    width: 100%;
    left: 0;
    font-size: 10px;
    color: #333;
    border-top: 1px solid #aaa; /* La línea de la marca */
    padding-left: 4px;
    box-sizing: border-box;
    transform: translateY(50%); 
}
#grainsize-track {
    background-color: #fcfcfc;
    /* Línea central para 0.55 */
    background-image: linear-gradient(to right, #eee 1px, transparent 1px);
    background-size: 50% 100%; 
    background-position: left;
    background-repeat: no-repeat;
}
#grainsize-track canvas {
    display: block; /* Elimina espacio extra */
    position: relative;
    z-index: 10;
}

/* =================================
   Estilos para Función 1.1 (Compleja)
   ================================= */
.btn-add-strata {
    background-color: #3498db;
    color: white;
    border: none;
    padding: 4px 8px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.9em;
}
.btn-add-strata:hover {
    background-color: #2980b9;
}
/* Fila de estrato en la tabla (Sangría) */
.stratum-row td:first-child {
    padding-left: 25px; /* Función 4.1 Sangría */
}
.stratum-row {
    background-color: #f9f9f9;
}
.unit-row {
    font-weight: bold;
    background-color: #efefef;
    border-top: 2px solid #ccc;
}
#form-add-stratum {
    border: 2px dashed #3498db;
    padding: 10px;
    margin-top: 15px;
    background: #fafdff;
}
#form-add-stratum button[type="button"] {
    background-color: #95a5a6;
}
#form-add-stratum button[type="button"]:hover {
    background-color: #7f8c8d;
}

/* =================================
   Estilos para Función 1.3 (Contactos)
   ================================= */
.stratum {
    position: relative; /* Clave para los contactos */
    border: none; /* Desactivamos el borde simple */
}
.stratum::before,
.stratum::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    height: 4px; /* Grosor del contacto */
    background-color: #000; /* Color simple */
    z-index: 10;
}
.stratum::before { top: -2px; } /* Se posiciona en el techo */
.stratum::after { bottom: -2px; } /* Se posiciona en la base */

/* --- Estilos Específicos de Contacto (Techo) --- */
[data-contact-top="neto"]::before { background-color: #000; }
[data-contact-top="gradacional"]::before {
    background: none;
    border-top: 3px dashed #000;
}
[data-contact-top="ondulado"]::before {
    background: none;
    height: 10px;
    background: radial-gradient(circle at 50% 100%, transparent 5px, #000 5px, #000 6px, transparent 6px) 0 -5px repeat-x;
    background-size: 20px 10px;
    border: none;
}
[data-contact-top="erosivo"]::before {
    background: none;
    height: 10px;
    background-color: #000;
    clip-path: polygon(0 100%, 0 50%, 10% 80%, 20% 50%, 30% 80%, 40% 50%, 50% 80%, 60% 50%, 70% 80%, 80% 50%, 90% 80%, 100% 50%, 100% 100%);
}
/* --- Estilos Específicos de Contacto (Base) --- */
[data-contact-bottom="neto"]::after { background-color: #000; }
[data-contact-bottom="gradacional"]::after {
    background: none;
    border-bottom: 3px dashed #000;
}

/* =================================
   Estilos para Función 2.1 (Símbolos)
   ================================= */
#fossils-track,
#structures-track {
    position: relative; /* Clave para posicionar símbolos */
}
.symbol-icon {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    font-size: 20px; /* Tamaño del emoji/símbolo */
    line-height: 1;
    margin-bottom: -10px; 
    z-index: 5;
}

/* =================================
   Función 1.2 (Tramas y Borde Hecho a Mano)
   ================================= */
.stratum {
    background-color: #fff;
    background-repeat: repeat;
    background-size: 100px 100px; /* Tamaño de la trama */
    
    /* Aplica el filtro SVG */
    filter: url(#hand-drawn-filter);
    
    /* Un drop-shadow sutil */
    box-shadow: 2px 2px 3px rgba(0,0,0,0.1);
}
@media print {
    .stratum {
        filter: none;
        box-shadow: none;
    }
}

/* =================================
   Función 2.2 (Leyenda Dinámica)
   ================================= */
#legend-content {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.legend-item {
    display: flex;
    align-items: center;
    font-size: 0.9em;
}
.legend-swatch {
    width: 30px;
    height: 30px;
    border: 1px solid #999;
    margin-right: 8px;
    background-repeat: repeat;
    background-size: 100px 100px;
    background-position: center;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2em;
}
.legend-name {
    font-family: monospace;
}

/* =================================
   Función 4.2 (Modo Exportación PDF)
   ================================= */
.pdf-export-mode .stratum {
    filter: none !important;
    box-shadow: none !important;
}
.pdf-export-mode .stratum::before, 
.pdf-export-mode .stratum::after {
    display: none !important;
}
.pdf-export-mode .stratum {
    border-top: 1px solid #000;
    border-bottom: 1px solid #000;
}
.pdf-export-mode #controls-panel,
.pdf-export-mode #output-panel,
.pdf-export-mode header {
    display: none;
}
.pdf-export-mode #column-viewer {
    grid-area: 1 / 1 / -1 / -1; /* Ocupa toda la cuadrícula */
    padding: 0;
    background: #fff;
}
.pdf-export-mode #print-area {
    /* Añadimos un pequeño margen para el PDF */
    padding: 20px;
}

/* =================================
   Función 3.1 (Librería Personalizada)
   ================================= */
#btn-clear-custom {
    background-color: #e74c3c;
    color: white;
    padding: 8px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
    width: 100%;
    margin-top: 10px;
}
#btn-clear-custom:hover {
    background-color: #c0392b;
}
.symbol-icon img {
    width: 24px;
    height: 24px;
    object-fit: contain;
}
.legend-swatch img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}