/* Contratos - Formulario y Lista */
:root {
    --primary: #D4A574;
    --primary-dark: #B8824F;
    --text: #333;
    --text-light: #666;
    --white: #fff;
    --bg: #f5f5f5;
    --border: #ddd;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'Sora', sans-serif; background: var(--bg); color: var(--text); line-height: 1.5; overflow-x: hidden; }

.contrato-container { max-width: min(1600px, 96vw); margin: 0 auto; padding: 0 16px 40px; width: 100%; }

/* Header */
.contrato-header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: var(--white);
    padding: 20px 0;
    margin: 0 -16px 24px;
    padding-left: 16px;
    padding-right: 16px;
}
.header-content { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; max-width: min(1600px, 96vw); margin: 0 auto; width: 100%; }
.contrato-header-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
}
.contrato-header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
}
.contrato-header h1 { font-size: 1.5rem; display: flex; align-items: center; gap: 10px; min-width: 0; overflow-wrap: anywhere; }
.header-actions,
.contrato-header-toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; width: 100%; }

.contrato-nav-menu { position: relative; }
.contrato-nav-menu > summary {
    list-style: none;
    cursor: pointer;
}
.contrato-nav-menu > summary::-webkit-details-marker { display: none; }
.contrato-nav-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    color: #fff;
    background: rgba(255, 255, 255, 0.18);
    border: 1px solid rgba(255, 255, 255, 0.35);
    border-radius: 8px;
}
.contrato-nav-toggle:hover { background: rgba(255, 255, 255, 0.28); }
.contrato-nav-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 300;
    min-width: 220px;
    padding: 8px;
    background: #fff;
    border-radius: 10px;
    box-shadow: 0 8px 28px rgba(0, 0, 0, 0.18);
    border: 1px solid #e8e8e8;
}
.contrato-nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    color: #333;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    border-radius: 8px;
}
.contrato-nav-link:hover {
    background: #f5f0eb;
    color: #4e342e;
}
.contrato-nav-link i {
    width: 18px;
    color: #8d6e63;
    text-align: center;
}

.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 10px 16px; border: none; border-radius: 8px;
    font-size: 14px; font-weight: 600; cursor: pointer;
    text-decoration: none; font-family: inherit;
    transition: transform 0.2s, background 0.2s;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: rgba(255,255,255,0.25); color: var(--white); }
.btn-primary:hover { background: rgba(255,255,255,0.35); }
.btn-secondary { background: rgba(255,255,255,0.2); color: var(--white); }
.btn-secondary:hover { background: rgba(255,255,255,0.3); }
.btn-success { background: #2e7d32; color: var(--white); }
.btn-success:hover { background: #1b5e20; }
.btn-pdf { background: #c62828; color: var(--white); }
.btn-pdf:hover { background: #b71c1c; }
.btn-back { background: rgba(255,255,255,0.2); color: var(--white); }
.btn-back:hover { background: rgba(255,255,255,0.3); }
.btn-edit { padding: 6px 12px; font-size: 13px; background: var(--primary); color: var(--white); }
.btn-edit:hover { background: var(--primary-dark); }
.btn-delete { padding: 6px 12px; font-size: 13px; background: #c62828; color: var(--white); }
.btn-delete:hover { background: #b71c1c; }
.btn-cancel-contrato { padding: 6px 12px; font-size: 13px; background: #9c1d3e; color: var(--white); }
.btn-cancel-contrato:hover { background: #741530; }

.estado-badge-vigente { display: inline-block; padding: 3px 8px; border-radius: 6px; font-size: 12px; font-weight: 600; background: #e8f5e9; color: #2e7d32; }
.estado-badge-cancelado { display: inline-block; padding: 3px 8px; border-radius: 6px; font-size: 12px; font-weight: 600; background: #ffebee; color: #c62828; }
.estado-badge-suspendido { display: inline-block; padding: 3px 8px; border-radius: 6px; font-size: 12px; font-weight: 600; background: #fff3e0; color: #e65100; }

.modal-cancel-lista { position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal-cancel-content { background: #fff; border-radius: 12px; max-width: 480px; width: 100%; box-shadow: 0 8px 32px rgba(0,0,0,0.2); }
.modal-cancel-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid #eee; }
.modal-cancel-header h2 { font-size: 1.1rem; display: flex; align-items: center; gap: 8px; }
.modal-cancel-close { background: none; border: none; font-size: 24px; cursor: pointer; color: #666; line-height: 1; }
.modal-cancel-body { padding: 20px; }
.modal-cancel-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 16px; }

/* Form */
.contrato-main { background: var(--white); border-radius: 12px; box-shadow: 0 2px 12px rgba(0,0,0,0.08); padding: 20px; }
.form-section { margin-bottom: 28px; }
.form-section:last-child { margin-bottom: 0; }

.section-title {
    background: var(--primary);
    color: var(--white);
    padding: 10px 14px;
    font-size: 1rem;
    font-weight: 600;
    margin: -20px -20px 20px -20px;
    padding-left: 20px;
}
.form-header-block .section-title { margin-top: 0; }
.form-header-block { padding-top: 0; }

/* Encabezado: FOLIO (izq) | Teléfonos (centro) | CONTRATO NO. (der) */
.header-top-row {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 16px 24px;
    align-items: start;
    margin-bottom: 14px;
    max-width: 100%;
}
.header-folio, .header-contrato { min-width: 0; }
.header-label-bar {
    background: #1a1a1a;
    color: #fff;
    font-weight: 700;
    font-size: 14px;
    padding: 8px 12px;
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}
.header-folio input, .header-contrato input {
    width: 100%;
    padding: 10px 12px;
    border: 2px solid #333;
    border-radius: 4px;
    font-size: 16px;
    font-family: inherit;
    background: #fff;
}
.header-folio input[readonly], .header-contrato input[readonly] { background: #f5f5f5; }
.header-phones-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 0 8px;
}
.header-phones-wrap .header-phones {
    color: #333;
    font-size: 18px;
    font-weight: 600;
    margin: 0;
    line-height: 1.5;
    text-align: center;
}
.tipo-contrato {
    display: flex;
    gap: 24px;
    flex-wrap: wrap;
    justify-content: center;
}
.tipo-contrato label { display: flex; align-items: center; gap: 6px; cursor: pointer; font-size: 14px; }

.form-group-sucursal {
    max-width: 420px;
    margin-top: 12px;
}

.form-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px 16px; }
.form-group { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.form-group.full-width { grid-column: 1 / -1; }
.form-group.span-2 { grid-column: span 2; }
.form-group.span-3 { grid-column: span 3; }
.form-group label { font-size: 13px; font-weight: 600; color: var(--text); }
.form-group label .label-hint { font-weight: 500; color: var(--text-light); font-size: 12px; }
.form-group input, .form-group textarea, .form-group select {
    padding: 10px 12px; border: 2px solid var(--border); border-radius: 8px;
    font-size: 14px; font-family: inherit;
}
.form-group input:focus, .form-group textarea:focus {
    outline: none; border-color: var(--primary);
}
.form-group input[readonly] { background: #f0f0f0; }

.dias-cobro-input {
    width: 100%;
    box-sizing: border-box;
}
.dias-cobro-primer-hint {
    margin: 6px 0 0;
    font-size: 12px;
    color: #5d4037;
    line-height: 1.35;
}

.form-locked-hint { display: none; margin-bottom: 12px; padding: 10px 14px; background: #fff3e0; color: #e65100; border-radius: 8px; font-size: 14px; }
#formContrato.form-locked .form-locked-hint { display: block; }
#formContrato.form-locked input:disabled,
#formContrato.form-locked textarea:disabled,
#formContrato.form-locked select:disabled { opacity: 0.75; cursor: not-allowed; }

/* Mayúsculas al escribir (salvo correo y días de cobro, texto libre) */
.form-group input:not([type="email"]):not([type="number"]):not([type="date"]):not([type="hidden"]):not(.dias-cobro-input),
.form-group textarea { text-transform: uppercase; }
.form-group input[type="email"] { text-transform: lowercase; }
.checkbox-group { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.checkbox-group.wrap { flex-wrap: wrap; }
.checkbox-group .inline { display: flex; align-items: center; gap: 6px; font-weight: normal; cursor: pointer; font-size: 13px; }

/* Modalidad de pago (3/6/12 meses o pago único) */
.modalidad-buttons {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    align-items: center;
}
.modalidad-option {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    border: 2px solid var(--border);
    border-radius: 10px;
    background: #fff;
    cursor: pointer;
    font-weight: 700;
    font-size: 12px;
    -webkit-user-select: none;
    user-select: none;
    white-space: nowrap;
}
.modalidad-option input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}
.modalidad-option span {
    line-height: 1;
}
.modalidad-option input:checked + span {
    background: var(--primary);
    color: var(--white);
    padding: 5px 8px;
    border-radius: 8px;
    border: 2px solid var(--primary-dark);
}

.mensualidades-group {
    min-width: 0;
}

/* Firmas (como imagen de referencia) */
.firmas-section { margin-top: 32px; margin-bottom: 0; padding-top: 24px; }

.fecha-guadalajara-line {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 4px 2px;
    margin-bottom: 28px;
    font-size: 14px;
}
.fecha-guadalajara-text {
    font-weight: 700;
    text-transform: uppercase;
    color: #333;
    white-space: nowrap;
}
.fecha-guadalajara-inp {
    border: none;
    border-bottom: 1px solid #1a1a1a;
    background: transparent;
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    width: 2.2em;
    min-width: 2.2em;
    text-align: center;
    padding: 0 2px 2px;
}
.fecha-guadalajara-inp.fecha-guadalajara-mes { width: 3em; min-width: 3em; }
.fecha-guadalajara-inp:focus { outline: none; border-bottom-color: var(--primary); }

.firmas-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px 32px;
    max-width: 100%;
}
.firma-block {
    display: flex;
    flex-direction: column;
    align-items: center;
}
.firma-line {
    width: 100%;
    height: 52px;
    border-bottom: 2px solid #1a1a1a;
}
.firma-label {
    margin-top: 8px;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    text-align: center;
    color: #333;
    letter-spacing: 0.02em;
}

/* Filters */
.filters-section { background: var(--white); border-radius: 12px; padding: 20px; margin-bottom: 20px; box-shadow: 0 2px 10px rgba(0,0,0,0.06); }
.filters-section h2 { font-size: 1.1rem; margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }
.filters-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.filter-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.filter-group input { width: 100%; padding: 10px 12px; border: 2px solid var(--border); border-radius: 8px; font-size: 14px; }

/* Table */
.table-section { background: var(--white); border-radius: 12px; overflow: hidden; box-shadow: 0 2px 10px rgba(0,0,0,0.06); }
.table-wrap { overflow-x: auto; }
.contratos-table { width: 100%; border-collapse: collapse; }
.contratos-table th, .contratos-table td { padding: 12px 14px; text-align: left; border-bottom: 1px solid #eee; font-size: 14px; }
.contratos-table th { background: var(--primary); color: var(--white); font-weight: 600; }
.contratos-table tbody tr:hover { background: #fafafa; }
.contratos-table .btn-edit { text-decoration: none; }
.contratos-table .acciones-cell { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.contratos-table .btn-delete { text-decoration: none; border: none; cursor: pointer; font-family: inherit; }

.loading, .empty-state { text-align: center; padding: 40px 20px; color: var(--text-light); }
.empty-state i { font-size: 48px; color: #ccc; margin-bottom: 12px; display: block; }
.empty-state a { color: var(--primary); }
.hidden { display: none !important; }

/* Ocultar en pantalla; visible solo al capturar PDF */
.pdf-only { display: none !important; }
body.pdf-capturing .pdf-only { display: block !important; }

.toast {
    position: fixed; bottom: 24px; right: 24px;
    padding: 14px 20px; border-radius: 8px;
    font-weight: 600; font-size: 14px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
    z-index: 9999; display: none;
}
.toast.show { display: block; animation: fadeIn 0.3s; }
.toast.success { background: #2e7d32; color: var(--white); }
.toast.error { background: #c62828; color: var(--white); }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

@media (max-width: 900px) {
    .form-grid { grid-template-columns: repeat(2, 1fr); }
    .form-group.span-2, .form-group.span-3 { grid-column: span 2; }
    .header-top-row { grid-template-columns: 1fr; }
    .header-phones-wrap { padding: 8px 0; }
    .firmas-row { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
    .form-grid { grid-template-columns: 1fr; }
    .form-group.span-2, .form-group.span-3 { grid-column: span 1; }
}
@media (max-width: 768px) {
    .contrato-container { padding: 0 12px 40px; }
    .contrato-header { margin: 0 -12px 20px; }
    .contrato-header h1 { font-size: 1.15rem; }
    .contrato-nav-toggle-txt { display: none; }
    .header-content { flex-direction: column; align-items: stretch; }
    .contrato-header-toolbar .btn {
        flex: 1 1 calc(50% - 8px);
        justify-content: center;
    }
    .header-phones-wrap .header-phones { font-size: 14px; }
    .tipo-contrato { flex-direction: column; align-items: flex-start; gap: 10px; }
    .contrato-main { padding: 16px; }
    .section-title { margin-left: -16px; margin-right: -16px; }
    .contratos-table th, .contratos-table td { padding: 8px 10px; font-size: 13px; }
    .modal-cancel-actions { flex-direction: column; }
    .modal-cancel-actions .btn { width: 100%; justify-content: center; }
}

@media (max-width: 480px) {
    .contrato-header h1 { font-size: 1.05rem; }
    .contrato-header-toolbar .btn { flex-basis: 100%; }
}
