@import url("https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap");

:root {
    --bg: #e9eef5;
    --surface: #ffffff;
    --surface-soft: #f5f8fc;
    --sidebar: #081a3b;
    --sidebar-soft: #102750;
    --text: #0f172a;
    --text-soft: #64748b;
    --line: #d6e0ec;
    --accent: #0ea5e9;
    --accent-strong: #0284c7;
    --warning: #f97316;
    --danger: #dc2626;
    --success: #15803d;
    --radius: 12px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    display: flex;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: "Plus Jakarta Sans", "Segoe UI", sans-serif;
}

.sidebar {
    width: 270px;
    background: linear-gradient(180deg, #081a3b 0%, #071634 100%);
    color: #e2e8f0;
    border-right: 1px solid rgba(148, 163, 184, 0.2);
    overflow-y: auto;
}

.sidebar h2 {
    padding: 18px 18px 16px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.25);
    letter-spacing: 0.06em;
    font-size: 1.2rem;
    font-weight: 800;
}

.sidebar ul {
    list-style: none;
    padding: 10px;
}

.sidebar li {
    margin-bottom: 4px;
}

.sidebar a {
    color: #dbe5f5;
    text-decoration: none;
    display: block;
    padding: 10px 12px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.95rem;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.sidebar a:hover {
    background: var(--sidebar-soft);
    color: #ffffff;
}

.sidebar a.menu-activo {
    background: linear-gradient(145deg, #38bdf8 0%, #0ea5e9 48%, #0369a1 100%);
    color: #ffffff;
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.35),
        inset 0 -3px 0 rgba(3, 105, 161, 0.7),
        0 10px 18px rgba(14, 165, 233, 0.28);
    transform: translateY(-1px);
}

.main-content {
    flex: 1;
    overflow-y: auto;
    padding: 30px 26px;
}

.main-content h1 {
    font-size: clamp(1.65rem, 3vw, 2.45rem);
    font-weight: 800;
    margin-bottom: 8px;
}

.main-content p {
    color: var(--text-soft);
    margin-bottom: 18px;
}

.seccion-oculta {
    display: none;
}

.seccion-activa {
    display: block;
}

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px;
    margin-bottom: 16px;
    box-shadow: 0 6px 16px rgba(15, 23, 42, 0.05);
}

.card h3 {
    margin-bottom: 12px;
    font-weight: 700;
}

.card-header-acciones {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.card-header-acciones h3 {
    margin-bottom: 0;
}

.input-group {
    margin-bottom: 12px;
}

.input-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.85rem;
    font-weight: 700;
    color: #334155;
}

input,
select,
textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    background: #fff;
    color: var(--text);
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input:focus,
select:focus,
textarea:focus {
    border-color: #7dd3fc;
    box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.15);
}

textarea {
    resize: vertical;
    min-height: 96px;
    font-family: inherit;
}

button {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 10px 14px;
    cursor: pointer;
    font-weight: 700;
    transition: background-color 0.2s ease, transform 0.1s ease;
}

button:hover {
    background: var(--accent-strong);
}

button:active {
    transform: translateY(1px);
}

.btn-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 10px 14px;
    border-radius: 10px;
    background: var(--accent);
    color: #fff;
    text-decoration: none;
    font-weight: 700;
}

.btn-link:hover {
    background: var(--accent-strong);
}

.visor-web {
    height: calc(100vh - 150px);
    min-height: 560px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--surface);
}

.visor-web-completo {
    height: calc(100vh - 60px);
    min-height: calc(100vh - 60px);
}

.visor-web iframe {
    width: 100%;
    height: 100%;
    border: 0;
}

table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin-top: 6px;
    font-size: 0.9rem;
}

th,
td {
    border-bottom: 1px solid #e2e8f0;
    padding: 10px;
    text-align: left;
    white-space: nowrap;
}

th {
    background: #f1f5f9;
    color: #334155;
    font-weight: 700;
    position: sticky;
    top: 0;
    z-index: 10;
}

/* Efecto resaltado (hover) en las filas de las tablas */
table tbody tr {
    transition: background-color 0.15s ease;
}

table tbody tr:hover {
    background-color: var(--surface-soft);
}

/* Resaltar fila completa cuando el estatus es Finalizado */
table tbody tr.fila-finalizada td {
    background-color: #ecfdf5;
}

table tbody tr.fila-finalizada:hover td {
    background-color: #d1fae5;
}

/* Alineación de montos a la derecha */
.text-right {
    text-align: right !important;
}

.filtros-servicios {
    display: grid;
    grid-template-columns: repeat(3, minmax(180px, 1fr));
    gap: 12px;
    align-items: end;
    margin-top: 10px;
}

.acciones-filtro {
    display: flex;
    justify-content: flex-start;
}

.resumen-listado {
    margin-top: 10px;
    color: #475569;
    font-size: 0.95rem;
}

.formulario-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(180px, 1fr));
    gap: 14px;
}

.campo-amplio {
    grid-column: span 2;
}

.partidas-contenedores {
    grid-column: span 2;
}

.contenedor-partida-captura {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) auto;
    gap: 10px;
}

.lista-contenedores-pago {
    list-style: none;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.lista-contenedores-pago li {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 8px 7px 10px;
    background: #e0f2fe;
    border: 1px solid #bae6fd;
    border-radius: 8px;
    color: #0f172a;
    font-weight: 700;
}

.numero-partida-contenedor {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 999px;
    background: var(--accent);
    color: #fff;
    font-size: 0.78rem;
}

.partidas-contenedores-tabla {
    margin: 0;
    padding-left: 20px;
    min-width: 160px;
}

.partidas-contenedores-tabla li {
    padding: 2px 0;
    white-space: nowrap;
}

.btn-quitar-contenedor {
    padding: 3px 7px;
    border-radius: 6px;
    background: var(--danger);
    font-size: 0.72rem;
}

.tabla-responsive {
    overflow: auto;
    max-height: calc(100vh - 240px);
    width: 100%;
}

.tabs-bar {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.tab-btn {
    background: #dbeafe;
    color: #1e3a8a;
}

.tab-btn-activa {
    background: var(--accent);
    color: #fff;
}

.tab-panel {
    display: none;
}

.tab-panel-activo {
    display: block;
}

.modal-captura {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 1000;
}

.modal-oculto {
    display: none;
}

.modal-contenido {
    width: min(1220px, 95vw);
    max-height: 90vh;
    overflow-y: auto;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 14px;
    padding: 20px;
    box-shadow: 0 18px 44px rgba(15, 23, 42, 0.25);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.modal-cerrar {
    background: var(--danger);
}

.modal-acciones {
    grid-column: 1 / -1;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.form-catalogo-grid {
    align-items: end;
}

.catalogos-pagos-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(260px, 1fr));
    gap: 16px;
}

.catalogo-pago-card {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 14px;
    background: var(--surface-soft);
}

.catalogo-pago-card h3 {
    margin-bottom: 12px;
}

.form-acciones-catalogo {
    grid-column: 1 / -1;
    display: flex;
    justify-content: flex-end;
}

.btn-secundario {
    background: #475569;
    margin-right: 8px;
}

.btn-eliminar-catalogo,
.btn-eliminar {
    background: var(--danger);
}

.acciones-listado {
    display: flex;
    gap: 6px;
    flex-wrap: nowrap;
    align-items: center;
}

table td button,
.acciones-listado button {
    width: 30px !important;
    height: 30px !important;
    padding: 0 !important;
    font-size: 0 !important; /* Oculta el texto original */
    border-radius: 50% !important; /* Círculo perfecto */
    margin: 0 !important;
    border: none !important;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.08) !important; /* Sombra sutil flotante */
    transition: transform 0.2s ease, box-shadow 0.2s ease !important;
    background-repeat: no-repeat !important;
    background-position: center !important;
    background-size: 14px !important; /* Tamaño del ícono plano */
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    cursor: pointer;
    flex-shrink: 0;
    color: transparent !important;
}

table td button:hover,
.acciones-listado button:hover {
    transform: translateY(-2px) !important; /* Efecto flotar al pasar el mouse */
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.12) !important;
}

table td button:active,
.acciones-listado button:active {
    transform: translateY(0) !important; /* Efecto hundir al hacer clic */
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08) !important;
}

/* --- ICONOS SVG Y COLORES PASTEL/MATE --- */

/* Editar (Azul Pastel) */
table td .btn-secundario, table td .btn-editar, .acciones-listado .btn-secundario, .acciones-listado .btn-editar {
    background-color: #93c5fd !important;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="%23ffffff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"></path><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"></path></svg>') !important;
}

/* Eliminar (Rojo Pastel) */
table td .btn-eliminar, table td .btn-eliminar-catalogo, table td .btn-eliminar-pago, .acciones-listado .btn-eliminar, .acciones-listado .btn-eliminar-catalogo, .acciones-listado .btn-eliminar-pago {
    background-color: #fca5a5 !important;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="%23ffffff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="3 6 5 6 21 6"></polyline><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"></path><line x1="10" y1="11" x2="10" y2="17"></line><line x1="14" y1="11" x2="14" y2="17"></line></svg>') !important;
}

/* Factura / Pago (Verde Pastel) */
table td .btn-factura, table td .btn-pago, .acciones-listado .btn-factura, .acciones-listado .btn-pago {
    background-color: #6ee7b7 !important;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="%23ffffff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="1" x2="12" y2="23"></line><path d="M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6"></path></svg>') !important;
}

/* PDF / Carta Porte (Naranja/Amarillo Pastel) */
table td .btn-pdf, table td .btn-carta, .acciones-listado .btn-pdf, .acciones-listado .btn-carta {
    background-color: #fcd34d !important;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="%23ffffff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path><polyline points="14 2 14 8 20 8"></polyline><line x1="16" y1="13" x2="8" y2="13"></line><line x1="16" y1="17" x2="8" y2="17"></line><polyline points="10 9 9 9 8 9"></polyline></svg>') !important;
}

/* Duplicar (Morado Pastel) */
table td .btn-duplicar-pago, .acciones-listado .btn-duplicar-pago {
    background-color: #c4b5fd !important;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="%23ffffff" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path></svg>') !important;
}

.btn-tabla {
    padding: 7px 10px;
    font-size: 0.78rem;
    border-radius: 8px;
}

.btn-editar {
    background: #2563eb;
}

.btn-duplicar-pago {
    background: #7c3aed;
}

.btn-carta {
    background: var(--warning);
}

.btn-pago {
    background: var(--success);
}

.celda-editable {
    background: #fffef7;
    cursor: text;
}

.celda-editable:focus {
    outline: 2px solid #7dd3fc;
    background: #f0f9ff;
}

.fila-pago-duplicado td {
    background: #ffedd5;
    border-bottom-color: #fdba74;
}

.fila-pago-duplicado td:first-child {
    border-left: 4px solid var(--warning);
}

/* --- Estilos para Modal (Iframe) --- */
body.is-modal .sidebar {
    display: none !important;
}

body.is-modal .main-content {
    padding: 15px 25px;
}

/* --- Toast Notification --- */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 9999;
}

.toast {
    background-color: var(--success);
    color: white;
    padding: 12px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    font-size: 0.95rem;
    opacity: 0;
    transform: translateY(20px);
    animation: toastEnter 0.3s ease forwards, toastExit 0.3s ease 2.7s forwards;
}

@keyframes toastEnter {
    to { opacity: 1; transform: translateY(0); }
}

@keyframes toastExit {
    to { opacity: 0; transform: translateY(-10px); }
}

@media (max-width: 1024px) {
    body {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        max-height: 220px;
    }

    .formulario-grid {
        grid-template-columns: repeat(2, minmax(180px, 1fr));
    }

    .filtros-servicios {
        grid-template-columns: repeat(2, minmax(180px, 1fr));
    }
}

@media (max-width: 640px) {
    .main-content {
        padding: 18px 14px;
    }

    .formulario-grid {
        grid-template-columns: 1fr;
    }

    .campo-amplio {
        grid-column: 1;
    }

    .partidas-contenedores {
        grid-column: 1;
    }

    .contenedor-partida-captura {
        grid-template-columns: 1fr;
    }

    .tabs-bar {
        flex-direction: column;
    }

    .card-header-acciones {
        align-items: stretch;
        flex-direction: column;
    }

    .filtros-servicios {
        grid-template-columns: 1fr;
    }

    .catalogos-pagos-grid {
        grid-template-columns: 1fr;
    }

    .acciones-listado,
    .modal-acciones {
        flex-direction: column;
    }
}
