/* ==========================================================
   CRM - LEGALES
   Grilla de tarjetas para js/legales.js. Mismo molde que
   .marketing-piezas-grid (marketing.css), con miniaturas más
   altas -un documento se identifica mejor en vertical que un
   banner cuadrado- y una variante de ícono para Word/Excel, que
   no tienen vista previa real.
   ========================================================== */

.section-head .legales-subir { cursor: pointer; }
.section-head .legales-subir.es-deshabilitado { opacity: 0.6; cursor: default; pointer-events: none; }

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

.legales-doc {
    border-radius: var(--radius-md, 10px);
    border: 1px solid var(--border-color);
    background: var(--bg-surface);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.legales-doc__mini {
    aspect-ratio: 3 / 4;
    background-size: cover;
    background-position: center top;
    background-color: var(--surf-1, #171719);
}

.legales-doc__mini--icono {
    display: grid;
    place-items: center;
}

.legales-doc__mini--icono i {
    font-size: 2.4rem;
    color: var(--text-dim);
}

.legales-doc__pie {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 6px;
    padding: 8px 10px 4px;
}

.legales-doc__nombre {
    font-size: 0.82rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.legales-doc__peso {
    font-size: 0.7rem;
    color: var(--text-dim);
    flex: 0 0 auto;
}

/* El estado de firma en la tarjeta de la grilla. Va entre el nombre
   y los botones: es lo primero que uno busca cuando entra a Legales a
   ver si el cliente firmó o no. */
.legales-doc__firma {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.68rem;
    font-weight: 600;
    padding: 0 10px 2px;
}
.legales-doc__firma.es-firmado { color: var(--primary); }
.legales-doc__firma.es-pendiente { color: #eab308; }

.legales-doc__acciones {
    display: flex;
    gap: 4px;
    padding: 4px 8px 10px;
}

.legales-doc__acciones .btn-icon {
    width: 30px;
    height: 30px;
}

.legales-doc__acciones .btn-icon:disabled {
    opacity: 0.35;
    cursor: default;
}

/* --- Celular: una columna más angosta -------------------------- */

@media (max-width: 768px) {
    .legales-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)) !important; }
}


/* ==========================================================
   EL MODAL EDITOR (imagen, PDF, Excel, Word)

   Un solo cascaron -#legales-editor-modal en index.html- que los
   cuatro editores comparten. Bastante más ancho que el modal-card
   de 650px de un formulario (legibilidad.css): acá adentro hay un
   canvas o una grilla, no ocho campos. El tope de 1500px es para
   que en un monitor grande el documento se lea sin achicarlo: 150px
   se los lleva la tira de miniaturas y el resto es hoja.
   ========================================================== */

html body #legales-editor-modal .modal-card.legales-editor-card {
    max-width: 1500px !important;
    width: 96vw !important;
    height: 90vh !important;
    max-height: 90vh !important;
    display: flex !important;
    flex-direction: column !important;
    padding: 0 !important;
    overflow: hidden !important;
}

/* El div lo pone index.html a mano, sin estilo -era un <div> comun
   adentro de un padre flex-column, asi que por defecto NO crecia
   (flex-grow:0 de fabrica) y se achicaba al contenido. Todo lo de
   adentro tiene height:100% colgado de esto, asi que sin esta regla
   el editor entero terminaba comprimido a un cuadradito -el lienzo
   de PDF/imagen se veia diminuto y pegado a un borde en vez de
   ocupar el modal. */
#legales-editor-raiz {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    /* El pad de firma se monta acá con inset:0, y un absoluto se
       cuelga del ancestro posicionado más cercano: sin esto se iría
       a cubrir la ventana entera en vez del editor. */
    position: relative;
}

.legales-editor {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-height: 0;
}

.legales-editor__barra {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-color);
    flex: 0 0 auto;
}

.legales-editor__titulo {
    font-size: 0.86rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 220px;
    margin-right: 4px;
}

.legales-editor__separador {
    width: 1px;
    align-self: stretch;
    background: var(--border-color);
    margin: 0 2px;
}

.legales-editor__herramienta {
    width: 34px;
    height: 34px;
    display: grid;
    place-items: center;
    border-radius: var(--radius-md, 10px);
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-main);
    cursor: pointer;
    transition: background 120ms ease, border-color 120ms ease;
}
.legales-editor__herramienta:hover { background: var(--surf-2); }
.legales-editor__herramienta.es-elegida {
    background: rgba(var(--acento-rgb), 0.14);
    border-color: var(--primary);
    color: var(--primary);
}
.legales-editor__herramienta:disabled { opacity: 0.35; cursor: default; }

.legales-editor__slider {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.72rem;
    color: var(--text-dim);
}
.legales-editor__slider input[type="range"] { width: 70px; }
.legales-editor__slider select {
    background: var(--bg-surface);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 3px 5px;
    font-size: 0.74rem;
    font-family: inherit;
}

/* EL COLOR ELEGIDO, VISIBLE.

   Un <input type="color"> se dibuja como un boton con el color
   adentro y un marco propio del navegador. En 30px sobre fondo
   oscuro eso queda como un cuadradito negro: el marco se come casi
   todo y no se distingue que color esta puesto. La unica forma de
   que se vea el color y no el control es sacarle el relleno con los
   pseudo-elementos ::-webkit-color-swatch, que son las partes
   internas del control. */
.legales-pdf-color {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    border: 2px solid var(--border-color);
    overflow: hidden;
    display: block;
    flex: 0 0 auto;
    cursor: pointer;
    position: relative;
}
.legales-pdf-color:hover { border-color: var(--primary); }
.legales-pdf-color input[type="color"] {
    width: 200%;
    height: 200%;
    margin: -25%;
    padding: 0;
    border: none;
    background: transparent;
    cursor: pointer;
}
.legales-pdf-color input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
.legales-pdf-color input[type="color"]::-webkit-color-swatch { border: none; }
.legales-pdf-color input[type="color"]::-moz-color-swatch { border: none; }


/* --- El pad para firmar uno mismo ------------------------------ */

.legales-pdf-firma-fondo {
    position: absolute;
    inset: 0;
    background: rgba(8, 8, 10, 0.72);
    backdrop-filter: blur(4px);
    display: grid;
    place-items: center;
    z-index: 20;
}

.legales-pdf-firma-caja {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md, 12px);
    padding: 18px;
    width: min(440px, 92%);
}
.legales-pdf-firma-caja h4 { margin: 0 0 4px; font-size: 1rem; }
.legales-pdf-firma-caja p { margin: 0 0 12px; font-size: 0.76rem; color: var(--text-dim); }

/* touch-action:none para poder firmar con el dedo sin que la
   pantalla scrollee, igual que el pad de firmar.html. */
#legales-pdf-firma-lienzo {
    width: 100%;
    height: 170px;
    background: #fff;
    border: 2px dashed var(--border-color);
    border-radius: 10px;
    touch-action: none;
    display: block;
    cursor: crosshair;
}

.legales-pdf-firma-pie {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
}

.legales-editor__cuerpo {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surf-1, #101012);
    position: relative;
}

.legales-editor__lienzo-caja {
    position: relative;
    max-width: 100%;
    max-height: 100%;
}

.legales-editor__lienzo-caja canvas {
    display: block;
    max-width: 100%;
    max-height: 100%;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

.legales-editor__aviso {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    font-size: 0.76rem;
    color: var(--text-dim);
    background: var(--surf-2);
    border-top: 1px solid var(--border-color);
}
.legales-editor__aviso i { color: var(--primary); flex: 0 0 auto; }

.legales-editor__pie {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 10px 14px;
    border-top: 1px solid var(--border-color);
    flex: 0 0 auto;
}


/* --- Editor de PDF: panel de páginas + lienzo, uno al lado del otro -- */

.legales-editor__cuerpo--con-panel {
    align-items: stretch;
    justify-content: flex-start;
}

.legales-pdf-paginas {
    flex: 0 0 150px;
    overflow-y: auto;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    border-right: 1px solid var(--border-color);
    background: var(--bg-surface);
}

.legales-pdf-pagina {
    border-radius: var(--radius-md, 10px);
    border: 2px solid transparent;
    background: var(--surf-2);
    padding: 6px;
    cursor: pointer;
}
.legales-pdf-pagina.es-elegida { border-color: var(--primary); }

.legales-pdf-pagina__lienzo {
    display: flex;
    justify-content: center;
    margin-bottom: 4px;
}
.legales-pdf-pagina__lienzo canvas {
    max-width: 100%;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.legales-pdf-pagina__numero {
    text-align: center;
    font-size: 0.7rem;
    color: var(--text-dim);
    margin-bottom: 4px;
}

.legales-pdf-pagina__acciones {
    display: flex;
    justify-content: center;
    gap: 2px;
}
.legales-pdf-pagina__acciones button {
    width: 24px;
    height: 24px;
    font-size: 0.68rem;
    display: grid;
    place-items: center;
    border-radius: 6px;
    border: none;
    background: transparent;
    color: var(--text-dim);
    cursor: pointer;
}
.legales-pdf-pagina__acciones button:hover { background: var(--surf-3); color: var(--text-main); }
.legales-pdf-pagina__acciones button:disabled { opacity: 0.3; cursor: default; }

.legales-editor__lienzo-panel {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 0;
    overflow: auto;
}

@media (max-width: 768px) {
    .legales-pdf-paginas { flex-basis: 96px; }
}


/* --- Editor de Excel: grilla editable a mano ------------------- */

.legales-excel-cuerpo {
    align-items: flex-start !important;
    justify-content: flex-start !important;
    overflow: auto;
    padding: 10px;
}

.legales-excel-tabla {
    border-collapse: collapse;
    font-size: 0.8rem;
    background: var(--bg-surface);
}

.legales-excel-tabla th,
.legales-excel-tabla td {
    border: 1px solid var(--border-color);
    padding: 4px 8px;
    min-width: 70px;
    white-space: nowrap;
}

.legales-excel-tabla thead th {
    position: sticky;
    top: 0;
    background: var(--surf-2);
    color: var(--text-dim);
    font-weight: 600;
    z-index: 1;
}

.legales-excel-tabla tbody th {
    position: sticky;
    left: 0;
    background: var(--surf-2);
    color: var(--text-dim);
    font-weight: 600;
}

.legales-excel-tabla td[contenteditable] {
    cursor: text;
    outline: none;
}
.legales-excel-tabla td[contenteditable]:focus {
    background: rgba(var(--acento-rgb), 0.12);
    box-shadow: inset 0 0 0 2px var(--primary);
}

.legales-excel-tabla td.es-formula {
    background: var(--surf-1, #101012);
    color: var(--text-dim);
    cursor: default;
}
.legales-excel-tabla td.es-formula i { font-size: 0.65rem; margin-left: 4px; }


/* --- Editor de Word: Quill sobre fondo claro a propósito -------
   Se deja el tema "snow" de Quill tal cual (blanco), no se lo
   fuerza al oscuro del CRM: es una superficie de escritura, y el
   contraste de un editor de texto se lee mejor así -mismo criterio
   que usan Docs/Notion embebidos en apps oscuras. */

.legales-word-cuerpo {
    align-items: stretch !important;
    justify-content: flex-start !important;
    flex-direction: column;
    padding: 0 !important;
    background: #fff;
}

.legales-word-cuerpo .ql-toolbar.ql-snow {
    border: none;
    border-bottom: 1px solid #ccc;
    flex: 0 0 auto;
}

.legales-word-cuerpo #legales-word-quill {
    flex: 1 1 auto;
    min-height: 0;
}

.legales-word-cuerpo .ql-container.ql-snow {
    border: none;
    height: 100%;
    overflow-y: auto;
    font-size: 15px;
}

/* ==========================================================
   FIRMA A DISTANCIA

   El modal del lado NUESTRO: pedir el link y seguir el estado.
   La pantalla que ve el cliente es firmar.html, que no comparte
   ni una linea de esta hoja -es una pagina suelta, sin login y
   con su propio estilo adentro.
   ========================================================== */

html body #legales-firma-modal .modal-card.legales-firma-card {
    max-width: 760px !important;
    width: 96vw !important;
    max-height: 88vh !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
}

.legales-firma-cuerpo {
    overflow-y: auto;
    padding-top: 4px;
}

.legales-firma-doc {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.86rem;
    font-weight: 600;
    color: var(--text-main);
    background: var(--surf-2);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md, 10px);
    padding: 10px 12px;
    margin: 0 0 16px;
}
.legales-firma-doc i { color: var(--primary); flex: 0 0 auto; }
.legales-firma-doc > span:first-of-type {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.legales-firma-version {
    margin-left: auto;
    flex: 0 0 auto;
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-dim);
}

.legales-firma-nuevo {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md, 10px);
    padding: 14px;
    margin-bottom: 18px;
}
.legales-firma-nuevo h4 {
    margin: 0 0 12px;
    font-size: 0.9rem;
}

.legales-firma-campos {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px 12px;
    margin-bottom: 14px;
}
.legales-firma-campos label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.74rem;
    color: var(--text-dim);
}
.legales-firma-campos input,
.legales-firma-campos select {
    padding: 9px 10px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-surface);
    color: var(--text-main);
    font-size: 0.86rem;
    font-family: inherit;
}

.legales-firma-vacio {
    color: var(--text-dim);
    font-size: 0.84rem;
    text-align: center;
    padding: 18px 0;
    margin: 0;
}

.legales-firma-lista {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.legales-firma-item {
    display: flex;
    align-items: center;
    gap: 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md, 10px);
    background: var(--surf-2);
    padding: 10px 12px;
}
.legales-firma-item__datos { flex: 1 1 auto; min-width: 0; }
.legales-firma-item__nombre {
    font-size: 0.86rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.legales-firma-item__meta {
    font-size: 0.72rem;
    color: var(--text-dim);
    margin-top: 2px;
    word-break: break-word;
}
.legales-firma-item__acciones {
    display: flex;
    gap: 4px;
    flex: 0 0 auto;
    align-items: center;
}
.legales-firma-item__acciones .btn-icon { width: 30px; height: 30px; }
.legales-firma-item__acciones .btn-icon:disabled { opacity: 0.3; cursor: default; }

/* Botones CON TEXTO y no iconos pelados. Cuatro iconos de 30px en
   fila -copiar, WhatsApp, sobre, prohibido- no dicen cual manda el
   documento, y el resultado fue el previsible: se genero el pedido y
   nadie toco el sobre, esperando que el mail hubiera salido solo. */
.legales-firma-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 11px;
    font-size: 0.75rem;
    font-weight: 600;
    font-family: inherit;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-surface);
    color: var(--text-main);
    cursor: pointer;
    white-space: nowrap;
    transition: border-color 120ms ease, color 120ms ease;
}
.legales-firma-btn:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); }
.legales-firma-btn:disabled { opacity: 0.35; cursor: default; }

/* Como salio el ultimo envio de mail. Va pegado a la fila y se
   queda: un toast que se va solo no sirve para contestar "¿mandaste
   el mail o no?" cinco minutos despues. */
.legales-firma-envio {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.72rem;
    margin-top: 5px;
    word-break: break-word;
}
.legales-firma-envio--ok { color: var(--primary); }
.legales-firma-envio--yendo { color: var(--text-dim); }
.legales-firma-envio--error { color: var(--danger, #f87171); }

.legales-firma-chip {
    font-size: 0.66rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 2px 8px;
    border-radius: 999px;
}
.legales-firma-chip--ok { background: rgba(var(--acento-rgb), 0.16); color: var(--primary); }
.legales-firma-chip--reloj { background: rgba(234, 179, 8, 0.16); color: #eab308; }
.legales-firma-chip--gris { background: var(--surf-3); color: var(--text-dim); }

.legales-firma-legal {
    font-size: 0.72rem;
    color: var(--text-dim);
    line-height: 1.55;
    margin: 18px 0 0;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
}
.legales-firma-legal i { color: var(--primary); margin-right: 4px; }

@media (max-width: 768px) {
    html body #legales-editor-modal .modal-card.legales-editor-card {
        width: 100vw !important;
        height: 100vh !important;
        max-height: 100vh !important;
        border-radius: 0 !important;
    }
    .legales-editor__titulo { display: none; }

    .legales-firma-campos { grid-template-columns: 1fr; }
    .legales-firma-item { flex-direction: column; align-items: stretch; }
    .legales-firma-item__acciones { justify-content: flex-end; }
}
