:root {
    --primary: #1E3A8A;
    /* Dark blue executive */
    --primary-hover: #1E40AF;
    --whatsapp: #25D366;
    --whatsapp-hover: #128C7E;
    --bg-color: #F1F5F9;
    --card-bg: #FFFFFF;
    --text-main: #0F172A;
    --text-muted: #475569;
    --border-color: #CBD5E1;
    --focus-ring: rgba(30, 58, 138, 0.25);
    --radius: 8px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* Elegant Executive Background */
body {
    font-family: 'Inter', 'Helvetica Neue', Arial, sans-serif;
    background: #e2e8f0;
    background-image:
        radial-gradient(circle at 100% 150%, #eff6ff 24%, white 24%, white 28%, #eff6ff 28%, #eff6ff 36%, white 36%, white 40%, transparent 40%, transparent),
        radial-gradient(circle at 0 150%, #eff6ff 24%, white 24%, white 28%, #eff6ff 28%, #eff6ff 36%, white 36%, white 40%, transparent 40%, transparent),
        radial-gradient(circle at 50% 100%, white 10%, #eff6ff 10%, #eff6ff 23%, white 23%, white 30%, #eff6ff 30%, #eff6ff 43%, white 43%, white 50%, #eff6ff 50%, #eff6ff 63%, white 63%, white 71%, transparent 71%, transparent),
        radial-gradient(circle at 100% 50%, #eff6ff 5%, white 5%, white 15%, #eff6ff 15%, #eff6ff 20%, white 20%, white 29%, #eff6ff 29%, #eff6ff 34%, white 34%, white 44%, #eff6ff 44%, #eff6ff 49%, transparent 49%, transparent),
        radial-gradient(circle at 0 50%, #eff6ff 5%, white 5%, white 15%, #eff6ff 15%, #eff6ff 20%, white 20%, white 29%, #eff6ff 29%, #eff6ff 34%, white 34%, white 44%, #eff6ff 44%, #eff6ff 49%, transparent 49%, transparent);
    background-size: 100px 50px;
    background-color: #f1f5f9;
    color: var(--text-main);
    line-height: 1.6;
    padding: 30px 15px;
}

.app-container {
    max-width: 900px;
    margin: 0 auto;
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: 0 15px 35px -5px rgba(0, 0, 0, 0.1), 0 10px 15px -5px rgba(0, 0, 0, 0.04);
    overflow: hidden;
    border-top: 5px solid var(--primary);
}

.app-header {
    text-align: center;
    background-color: #FFFFFF;
    color: var(--text-main);
}

.app-header img {
    width: 100%;
    height: auto;
    object-fit: contain;
    display: block;
}

.header-text {
    padding: 25px 20px;
    border-bottom: 1px solid #E2E8F0;
}

.header-text h1 {
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    margin-bottom: 5px;
    color: var(--primary);
}

.header-text p {
    color: var(--text-muted);
    font-size: 0.95rem;
    font-weight: 500;
}

.main-form {
    padding: 30px;
}

.form-section {
    border: none;
    margin-bottom: 40px;
}

.form-section legend {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 20px;
    width: 100%;
    border-bottom: 2px solid var(--primary);
    padding-bottom: 8px;
    text-transform: uppercase;
}

.legal-text-header {
    background-color: #F8FAFC;
    padding: 15px;
    border-left: 4px solid var(--primary);
    margin-bottom: 20px;
    font-size: 0.85rem;
    color: var(--text-main);
}

.form-row {
    margin-bottom: 18px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

@media (min-width: 600px) {
    .split-2 {
        flex-direction: row;
    }

    .split-2>.form-group {
        flex: 1;
    }
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group label:not(.custom-checkbox):not(.custom-radio):not(.upload-label) {
    font-weight: 600;
    font-size: 0.85rem;
    margin-bottom: 6px;
    color: #334155;
    text-transform: uppercase;
}

input[type="text"],
input[type="date"],
textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.95rem;
    font-family: inherit;
    transition: all 0.2s ease;
    background-color: #F8FAFC;
}

input[type="text"]:focus,
input[type="date"]:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--focus-ring);
    background-color: #FFFFFF;
}

/* Checkboxes and Radios */
.checkbox-group {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 10px;
}

.custom-checkbox,
.custom-radio {
    display: flex;
    align-items: center;
    cursor: pointer;
    font-size: 0.95rem;
    color: #475569;
    transition: background 0.2s;
}

.custom-checkbox input,
.custom-radio input {
    margin-right: 10px;
    width: 16px;
    height: 16px;
    accent-color: var(--primary);
}

.dark-text {
    color: var(--text-main);
    font-weight: 500;
    font-size: 0.8rem;
}

.inline-options {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
}

.group-label {
    font-weight: 600;
    color: #334155;
    margin-bottom: 8px;
    display: block;
    text-transform: uppercase;
    font-size: 0.85rem;
}

.sub-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 12px;
}

/* SENIAT Grid Layout (Strict Match Image) */
.seniat-grid-container {
    overflow-x: auto;
    background: #FFF;
    margin-bottom: 20px;
}

.seniat-grid {
    width: 100%;
    border-collapse: collapse;
    min-width: 600px;
    font-size: 0.85rem;
    font-family: Arial, sans-serif;
    color: #000;
}

.seniat-grid thead tr.thick-header th {
    background-color: #FFF;
    color: #000;
    text-align: center;
    border-top: 4px solid #000;
    border-bottom: 4px solid #000;
    font-weight: normal;
    padding: 10px 5px;
    text-transform: uppercase;
}

.seniat-grid th:first-child {
    border-left: 4px solid #000;
}

.seniat-grid th:last-child {
    border-right: 4px solid #000;
}

.seniat-grid td {
    padding: 10px 5px;
    vertical-align: middle;
}

.col-tipo {
    white-space: nowrap;
}

.lbl-tipo {
    font-size: 0.85rem;
    color: #64748B;
    text-transform: uppercase;
    font-weight: 600;
}

.mini-input,
.border-box {
    border: 1px solid #94A3B8 !important;
    border-radius: 2px !important;
    background: #FFF !important;
    box-shadow: none !important;
}

.txt-center {
    text-align: center;
}

.desde-hasta-group {
    display: flex;
    justify-content: space-around;
    gap: 10px;
}

.input-col {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.input-col span {
    font-size: 0.75rem;
    color: #000;
    margin-bottom: 2px;
}

.input-col input {
    width: 65px !important;
    padding: 4px !important;
}

.col-serie input {
    width: 70px !important;
    padding: 4px !important;
}

/* File Upload */
.file-upload-box,
.upload-area {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius);
    padding: 20px;
    text-align: center;
    background-color: #F8FAFC;
    transition: all 0.2s;
    position: relative;
    margin-bottom: 10px;
}

.file-upload-box:hover,
.upload-area:hover {
    border-color: var(--primary);
    background-color: #EFF6FF;
}

.file-upload-box input[type="file"],
.upload-area input[type="file"] {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    cursor: pointer;
}

.upload-icon {
    font-size: 1.8rem;
    margin-bottom: 5px;
}

.upload-text {
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--primary);
}

.file-name {
    margin-top: 5px;
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* Signature */
.signature-tabs {
    display: flex;
    gap: 20px;
    margin-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
}

.signature-tabs label {
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
}

.draw-area,
.upload-area {
    display: none;
}

.draw-area.active,
.upload-area.active {
    display: block;
}

.draw-area {
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background-color: #fff;
    padding: 10px;
    text-align: center;
}

canvas {
    border: 1px dashed #94A3B8;
    border-radius: 4px;
    background: #F8FAFC;
    cursor: crosshair;
    touch-action: none;
    width: 100%;
    height: 180px;
}

.btn-clear {
    margin-top: 10px;
    background: #EF4444;
    color: white;
    border: none;
    padding: 6px 14px;
    border-radius: 4px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-clear:hover {
    background: #DC2626;
}

/* Submit Button */
.submit-btn {
    width: 100%;
    background-color: var(--primary);
    color: white;
    border: none;
    padding: 16px;
    font-size: 1.05rem;
    font-weight: 700;
    border-radius: var(--radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.3s;
    text-transform: uppercase;
    box-shadow: 0 4px 6px -1px rgba(30, 58, 138, 0.4);
}

.submit-btn:hover {
    background-color: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 8px -1px rgba(30, 58, 138, 0.5);
}

.app-footer {
    text-align: center;
    padding: 20px;
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 600;
    margin-top: -20px;
    padding-bottom: 30px;
}

/* Overlay & Loader */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.7);
    display: none;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.loader-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 30px 40px;
    border-radius: 8px;
    text-align: center;
    z-index: 1001;
    display: none;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}

.spinner {
    border: 4px solid #E2E8F0;
    border-top: 4px solid var(--primary);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 0 auto 15px auto;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

@media (max-width: 600px) {
    body {
        padding: 5px 2px;
    }

    .app-container {
        border-radius: 0;
        border-top: none;
        box-shadow: none;
    }

    .main-form {
        padding: 5px 0;
    }

    .seniat-grid-container {
        overflow-x: hidden;
        margin-left: 0;
        margin-right: 0;
        padding-bottom: 2px;
    }

    .seniat-grid {
        min-width: 100%;
        max-width: 100%;
        table-layout: fixed;
        /* STRICTLY Force proportional widths */
        font-size: 0.60rem;
    }

    .seniat-grid th:nth-child(1) {
        width: 33%;
    }

    .seniat-grid th:nth-child(2) {
        width: 15%;
    }

    .seniat-grid th:nth-child(3) {
        width: 26%;
    }

    .seniat-grid th:nth-child(4) {
        width: 26%;
    }

    .seniat-grid thead tr.thick-header th {
        font-size: 0.65rem;
        padding: 4px 1px;
        word-wrap: break-word;
        white-space: normal;
    }

    .seniat-grid td {
        padding: 4px 2px;
        word-wrap: break-word;
    }

    .col-tipo {
        white-space: normal !important;
        /* ALLOW Wrapping */
    }

    .lbl-tipo {
        font-size: 0.65rem;
    }

    /* VITAL CHANGE: Stack Desde and Hasta vertically instead of side-by-side to save massive horizontal space */
    .desde-hasta-group {
        display: flex;
        flex-direction: column;
        gap: 6px;
    }

    .input-col {
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: flex-start;
    }

    .input-col span {
        font-size: 0.65rem;
        margin-right: 2px;
        margin-bottom: 0px;
    }

    .input-col input,
    .col-serie input {
        width: 100% !important;
        max-width: 40px !important;
        padding: 2px !important;
        font-size: 0.65rem !important;
    }

    .custom-checkbox input {
        margin-right: 4px;
        width: 12px;
        height: 12px;
    }
}