/* ==========================================================
   REPORTE TIENDA EN LINEA - COM
   Interfaz con el mismo aspecto que la hoja de Google Sheets.
   ========================================================== */
:root {
  --ui-fondo: #f9fbfd;
  --ui-barra: #edf2fa;
  --ui-borde: #c7c7c7;
  --ui-texto: #1f1f1f;
  --ui-texto-suave: #444746;
  --ui-azul: #0b57d0;
  --ui-azul-claro: #d3e3fd;
  --ui-pestana-activa: #e1e9f7;
  --cuadricula: #e2e3e3;
  --encabezado-celda: #f8f9fa;
  --encabezado-sel: #d3e3fd;
  --error: #c5221f;
  --ok: #188038;

  /* Colores de la hoja */
  --verde: #a4c862;
  --amarillo: #ffe599;
  --amarillo-claro: #fff2cc;
  --verde-azulado: #d0e0e3;
  --gris: #efefef;
  --gris-medio: #d9d9d9;
  --cafe: #d19c65;
  --azul-cielo: #9fc5e8;
  --azul-palido: #cfe2f3;
  --azul: #6d9eeb;
  --morado: #b4a7d6;
  --rojo-claro: #ea9999;
  --rojo: #e06666;
  --rosa: #e6b8af;
  --verde-hoy: #b7e1cd;
  --verde-oscuro: #356854;
  --gris-total: #d0d0d0;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 13px;
  color: var(--ui-texto);
  background: var(--ui-fondo);
  overflow: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
.cargando-inicial { padding: 24px; color: var(--ui-texto-suave); }

/* ---------- Estructura ---------- */
.app { display: flex; flex-direction: column; height: 100vh; }
.encabezado {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px 4px; background: var(--ui-fondo);
}
.logo { width: 36px; height: 36px; flex: none; }
.titulo-doc { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.titulo-doc h1 {
  font-size: 18px; font-weight: 400; margin: 0; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; font-family: "Google Sans", Arial, sans-serif;
}
.menu-doc { display: flex; gap: 2px; flex-wrap: wrap; margin-top: 2px; }
.menu-doc button {
  border: 0; background: none; padding: 2px 7px; border-radius: 4px; cursor: pointer; font-size: 14px;
}
.menu-doc button:hover { background: #e8eaed; }
.usuario { display: flex; align-items: center; gap: 8px; position: relative; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; background: #137333; color: #fff;
  display: grid; place-items: center; font-weight: 700; border: 0; cursor: pointer;
}
.usuario .quien { text-align: right; line-height: 1.2; }
.usuario .quien small { color: var(--ui-texto-suave); }
.menu-flotante {
  position: absolute; top: 40px; right: 0; z-index: 50; min-width: 220px;
  background: #fff; border-radius: 8px; box-shadow: 0 2px 6px rgba(60,64,67,.3), 0 1px 2px rgba(60,64,67,.15);
  padding: 6px 0;
}
.menu-flotante button {
  display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 16px; cursor: pointer;
}
.menu-flotante button:hover { background: #f1f3f4; }
.menu-flotante hr { border: 0; border-top: 1px solid #e0e0e0; margin: 4px 0; }

/* Barra de herramientas */
.barra {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  margin: 4px 8px; padding: 4px 10px; min-height: 40px;
  background: var(--ui-barra); border-radius: 24px;
}
.barra .sep { width: 1px; height: 20px; background: var(--ui-borde); margin: 0 4px; }
.barra label { display: inline-flex; align-items: center; gap: 4px; color: var(--ui-texto-suave); }
.barra input[type=text], .barra input[type=search], .barra input[type=date], .barra input[type=number], .barra select {
  height: 28px; border: 1px solid transparent; border-radius: 6px; background: #fff; padding: 0 8px;
}
.barra input:focus, .barra select:focus { outline: 2px solid var(--ui-azul); }
.barra input[type=number] { width: 64px; }
.boton {
  height: 28px; padding: 0 12px; border: 0; border-radius: 14px; cursor: pointer; background: transparent;
  display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
}
.boton:hover { background: #dde3ea; }
.boton:disabled { opacity: .45; cursor: default; background: transparent; }
.boton.primario { background: var(--ui-azul); color: #fff; }
.boton.primario:hover { background: #0842a0; }
.boton.peligro { color: var(--error); }
.paginacion { margin-left: auto; display: inline-flex; align-items: center; gap: 2px; color: var(--ui-texto-suave); }

/* Barra de formulas */
.barra-formula {
  display: flex; align-items: center; height: 26px; margin: 0 8px; border-top: 1px solid var(--ui-borde);
  border-bottom: 1px solid var(--ui-borde); background: #fff; font-size: 12px;
}
.barra-formula .ref { width: 96px; padding: 0 8px; border-right: 1px solid var(--ui-borde); color: var(--ui-texto-suave); }
.barra-formula .fx { padding: 0 8px; color: #80868b; font-style: italic; border-right: 1px solid var(--ui-borde); }
.barra-formula .valor { padding: 0 8px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; flex: 1; }

/* Area de trabajo */
.trabajo { flex: 1; min-height: 0; display: flex; gap: 0; margin: 0 8px; background: #fff; }
.lienzo { flex: 1; min-width: 0; overflow: auto; position: relative; }
.panel-lateral {
  width: 300px; flex: none; overflow: auto; border-left: 1px solid var(--ui-borde); padding: 12px; background: #fff;
}
.vacio { padding: 32px; color: var(--ui-texto-suave); }

/* ---------- Cuadricula tipo hoja ---------- */
table.hoja { border-collapse: separate; border-spacing: 0; table-layout: fixed; }
table.hoja th, table.hoja td {
  border-right: 1px solid var(--cuadricula); border-bottom: 1px solid var(--cuadricula);
  padding: 0; height: 21px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
table.hoja thead th {
  position: sticky; top: 0; z-index: 4; background: var(--encabezado-celda); color: #575a5c;
  font-weight: 400; font-size: 11px; height: 20px; text-align: center;
}
table.hoja th.num {
  position: sticky; left: 0; z-index: 3; background: var(--encabezado-celda); color: #575a5c;
  font-weight: 400; font-size: 11px; width: 46px; min-width: 46px; text-align: center; cursor: pointer;
}
table.hoja thead th.num { z-index: 6; cursor: default; }
table.hoja tr.seleccionada th.num { background: var(--encabezado-sel); color: #0b57d0; font-weight: 700; }
table.hoja tr.seleccionada td { box-shadow: inset 0 0 0 9999px rgba(11, 87, 208, .07); }
table.hoja td { background: #fff; font-size: 13px; vertical-align: bottom; position: relative; }
table.hoja td.fija { position: sticky; z-index: 2; }
table.hoja tr.fija-arriba td { position: sticky; z-index: 4; }
table.hoja tr.fija-arriba th.num { position: sticky; z-index: 6; }
table.hoja tr.fija-arriba td.fija { z-index: 5; }
/* Alto fijo del contenido: la fila no crece con letras grandes (necesario para el desplazamiento continuo). */
table.hoja td .txt {
  display: block; height: 20px; line-height: 20px; padding: 0 4px; overflow: hidden; text-overflow: ellipsis;
}
table.hoja td input.celda {
  width: 100%; height: 20px; border: 0; background: transparent; padding: 0 4px; outline: none; line-height: 20px;
  font: inherit; color: inherit; text-align: inherit; font-weight: inherit; display: block;
}
table.hoja td:focus-within { box-shadow: inset 0 0 0 2px var(--ui-azul); z-index: 7; }
table.hoja td.guardando { box-shadow: inset 0 0 0 2px #fbbc04; }
table.hoja td.con-error { box-shadow: inset 0 0 0 2px var(--error); background-image: linear-gradient(45deg, transparent 85%, var(--error) 85%); }
table.hoja td.solo-lectura { cursor: default; }
.borde-blanco { border-right: 2px solid #fff !important; border-bottom: 2px solid #fff !important; }
/* Barra gris de "inmovilizar" despues de la ultima columna fija (como Google Sheets). */
table.hoja th.ultima-fija, table.hoja td.ultima-fija { border-right: 4px solid #c4c7c5 !important; }
table.hoja thead th.ultima-fija { border-right-color: #9aa0a6 !important; }
/* Sin columnas fijas: la barra queda junto a los numeros de fila, lista para arrastrarla. */
table.hoja thead th.num.sin-fijas { border-right: 4px solid #9aa0a6; }
.asa-inmovilizar {
  position: absolute; top: 0; right: 0; width: 8px; height: 100%; cursor: grab; z-index: 8;
}
.asa-inmovilizar:hover { background: rgba(26, 115, 232, .35); }
.guia-inmovilizar {
  position: fixed; width: 4px; background: #9aa0a6; opacity: .85; z-index: 70; pointer-events: none;
}
body.arrastrando, body.arrastrando * { cursor: grabbing !important; user-select: none; }
.borde-negro { border: 1px solid #000 !important; }
.centro { text-align: center; }
.derecha { text-align: right; }
.negrita { font-weight: 700; }

/* ---------- Pie "Agregar 1000 filas más al final" (como Google Sheets) ---------- */
.pie-hoja {
  position: sticky; left: 0; display: flex; align-items: center; gap: 12px;
  width: max-content; padding: 14px 16px 18px 58px; color: var(--ui-texto-suave); font-size: 14px;
}
.pie-agregar {
  border: 0; background: none; color: var(--ui-azul); font-weight: 500; font-size: 14px; cursor: pointer;
  padding: 6px 8px; border-radius: 4px;
}
.pie-agregar:hover { background: #e8f0fe; }
.pie-agregar:disabled { color: #9aa0a6; cursor: default; background: none; }
.pie-cantidad {
  width: 74px; height: 32px; border: 1px solid #747775; border-radius: 4px; padding: 0 8px;
  font-size: 14px; text-align: left; background: #fff;
}
.pie-cantidad:focus { outline: 2px solid var(--ui-azul); border-color: transparent; }

/* ---------- Mini calendario de las celdas de fecha ---------- */
.calendario {
  position: fixed; z-index: 60; width: 252px; padding: 10px 12px 8px;
  background: #fff; border-radius: 8px; font-size: 13px; color: var(--ui-texto);
  box-shadow: 0 2px 6px rgba(60,64,67,.3), 0 1px 2px rgba(60,64,67,.15);
  user-select: none;
}
.cal-cabecera { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.cal-titulo { font-weight: 500; font-size: 14px; text-transform: capitalize; }
.cal-flecha {
  width: 30px; height: 30px; border: 0; border-radius: 50%; background: none; cursor: pointer;
  font-size: 20px; line-height: 1; color: var(--ui-texto-suave);
}
.cal-flecha:hover { background: #f1f3f4; }
.cal-semana, .cal-dias { display: grid; grid-template-columns: repeat(7, 1fr); text-align: center; }
.cal-semana span { font-size: 11px; color: #70757a; padding: 4px 0; }
.cal-dia {
  width: 32px; height: 32px; margin: 1px auto; border: 0; border-radius: 50%; background: none;
  cursor: pointer; font-size: 12px; color: var(--ui-texto);
}
.cal-dia:hover { background: #f1f3f4; }
.cal-dia.hoy { color: var(--ui-azul); font-weight: 700; box-shadow: inset 0 0 0 1px var(--ui-azul); }
.cal-dia.elegido { background: var(--ui-azul); color: #fff; box-shadow: none; }
.cal-pie { display: flex; justify-content: flex-end; margin-top: 4px; }
.cal-hoy { border: 0; background: none; color: var(--ui-azul); cursor: pointer; padding: 4px 8px; border-radius: 4px; font-weight: 500; }
.cal-hoy:hover { background: #e8f0fe; }
table.hoja td.celda-fecha input.celda { cursor: pointer; }
table.hoja td.celda-fecha input.celda:focus { cursor: text; }
/* Valor escrito a mano (COMISIONES): triangulo en la esquina, como una nota de Sheets. */
table.hoja td.editada-a-mano:not(.fija) { position: relative; }
table.hoja td.editada-a-mano::after { content: ''; position: absolute; top: 0; right: 0; border-style: solid; border-width: 0 7px 7px 0; border-color: transparent #f29900 transparent transparent; pointer-events: none; }
table.hoja td.editada-a-mano input.celda { background: #fff8e1; }

/* ---------- Historial de versiones (como Google Sheets) ---------- */
.historial {
  position: fixed; inset: 0; z-index: 40; display: flex; flex-direction: column; background: var(--ui-fondo);
}
.hist-encabezado { display: flex; align-items: center; gap: 12px; padding: 10px 16px 6px; }
.hist-encabezado h1 { font-size: 20px; font-weight: 400; margin: 0; }
.hist-volver { font-size: 22px; }
.hist-cuerpo { flex: 1; min-height: 0; display: flex; }
.hist-principal { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.hist-barra { justify-content: flex-end; }
.hist-total { color: var(--ui-texto); margin-right: 6px; }
.hist-lienzo { flex: 1; min-height: 0; margin: 0 8px; background: #fff; }
.hist-avisos { margin: 0 8px 6px; display: flex; flex-direction: column; gap: 4px; }
.hist-aviso { background: #fef7e0; border-radius: 6px; padding: 6px 10px; display: flex; align-items: center; gap: 8px; }
.hist-quien { color: var(--ui-texto-suave); }
.hist-panel {
  width: 340px; flex: none; display: flex; flex-direction: column; border-left: 1px solid #e0e0e0;
  background: #f8fafd; padding: 12px 16px 0;
}
.hist-panel h2 { font-size: 18px; font-weight: 400; margin: 4px 0 12px; }
.hist-filtro { height: 40px; border: 1px solid #747775; border-radius: 4px; padding: 0 10px; background: #fff; margin-bottom: 10px; }
.hist-versiones { flex: 1; min-height: 0; overflow: auto; }
.hist-grupo { font-size: 13px; color: var(--ui-texto-suave); padding: 10px 2px 6px; }
.hist-version {
  border-radius: 10px; padding: 10px 12px 10px 8px; cursor: pointer; margin-bottom: 4px; outline: none;
}
.hist-version:hover { background: #eef2f8; }
.hist-version.elegida { box-shadow: inset 0 0 0 2px var(--ui-azul); background: #fff; }
.hist-fila { display: flex; align-items: center; gap: 6px; }
.hist-fecha { font-size: 15px; }
.hist-expandir { width: 22px; height: 22px; border: 0; background: none; cursor: pointer; font-size: 18px; color: #444; line-height: 1; }
.hist-actual-txt { font-size: 12px; color: var(--ui-texto-suave); margin: 4px 0 0 28px; }
.hist-editor { display: flex; align-items: center; gap: 8px; margin: 6px 0 0 28px; font-size: 13px; }
.hist-punto { width: 10px; height: 10px; border-radius: 50%; flex: none; display: inline-block; }
.hist-detalle { margin: 6px 0 0 28px; font-size: 12px; color: var(--ui-texto-suave); display: flex; flex-direction: column; gap: 2px; }
.hist-mas { margin: 8px 0 12px; }
.hist-opciones { border-top: 1px solid #e0e0e0; padding: 12px 0 16px; display: flex; flex-direction: column; gap: 12px; }
.hist-opciones label { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.hist-opciones input { width: 18px; height: 18px; accent-color: var(--ui-azul); }
.pestana.sin-cambios { color: #9aa0a6; }
table.hoja td.hist-marcada { box-shadow: inset 0 0 0 2px var(--ui-azul); }
.boton-icono {
  width: 36px; height: 36px; border: 0; border-radius: 50%; background: none; cursor: pointer; font-size: 20px; color: #444;
}
.boton-icono:hover { background: #e8eaed; }

@media (max-width: 900px) {
  .hist-panel { width: 260px; }
}

/* ---------- Pestanas inferiores ---------- */
.pestanas {
  display: flex; align-items: center; gap: 2px; height: 40px; padding: 0 8px; background: var(--ui-fondo);
  border-top: 1px solid var(--ui-borde); overflow-x: auto; flex: none;
}
.pestanas .icono {
  width: 32px; height: 32px; border: 0; border-radius: 50%; background: none; cursor: pointer; font-size: 18px; color: #444;
  flex: none;
}
.pestanas .icono:hover { background: #e8eaed; }
.pestana {
  height: 32px; padding: 0 14px; border: 0; border-radius: 4px 4px 8px 8px; background: none; cursor: pointer;
  font-size: 13px; font-weight: 500; color: var(--ui-texto-suave); white-space: nowrap; display: inline-flex; align-items: center; gap: 6px;
  letter-spacing: .2px;
}
.pestana:hover { background: #e8eaed; }
.pestana.activa { background: var(--ui-pestana-activa); color: var(--ui-azul); }
.pestana.oculta { font-style: italic; }
.pestana .flecha { font-size: 10px; }
.menu-hojas { bottom: 44px; top: auto; left: 8px; right: auto; position: fixed; max-height: 60vh; overflow: auto; }
.menu-hojas button.activa, .menu-inmovilizar button.activa { color: var(--ui-azul); font-weight: 700; }
.menu-flotante button:disabled { color: #9aa0a6; cursor: default; background: none; }

/* ---------- Paneles / dialogos ---------- */
.tarjeta { border: 1px solid #dadce0; border-radius: 8px; padding: 12px; background: #fff; }
.tarjeta h3 { margin: 0 0 8px; font-size: 14px; }
.tabla-simple { border-collapse: collapse; width: 100%; }
.tabla-simple th, .tabla-simple td { border: 1px solid #000; padding: 3px 6px; }
.tabla-simple th { font-weight: 700; background: #fff; }

dialog {
  border: 0; border-radius: 12px; padding: 0; box-shadow: 0 4px 24px rgba(0,0,0,.25); width: min(560px, 94vw);
}
dialog::backdrop { background: rgba(32,33,36,.45); }
.dlg-cuerpo { padding: 20px 24px; }
.dlg-cuerpo h2 { margin: 0 0 12px; font-size: 18px; font-weight: 400; }
.dlg-pie { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 24px 18px; }
.campo { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.campo input, .campo select, .campo textarea {
  height: 36px; border: 1px solid #c4c7c5; border-radius: 6px; padding: 0 10px; background: #fff;
}
.campo textarea { height: auto; min-height: 80px; padding: 8px 10px; }
.campo input:focus, .campo select:focus, .campo textarea:focus { outline: 2px solid var(--ui-azul); border-color: transparent; }
.checks { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.aviso { background: #fef7e0; border-radius: 8px; padding: 10px 12px; margin-bottom: 12px; color: #5f370e; }
.lista-usuarios { width: 100%; border-collapse: collapse; }
.lista-usuarios th, .lista-usuarios td { text-align: left; padding: 6px 8px; border-bottom: 1px solid #e0e0e0; }
.etiqueta { display: inline-block; padding: 1px 8px; border-radius: 10px; background: #e8f0fe; color: #174ea6; font-size: 12px; }
.etiqueta.inactivo { background: #f1f3f4; color: #5f6368; }

/* ---------- Login ---------- */
.login {
  min-height: 100vh; display: grid; place-items: center; background: #f0f4f9;
}
.login form {
  width: min(420px, 92vw); background: #fff; border-radius: 28px; padding: 36px 36px 28px;
}
.login h1 { font-size: 24px; font-weight: 400; margin: 12px 0 4px; }
.login p { margin: 0 0 24px; color: var(--ui-texto-suave); }
.login .error { color: var(--error); min-height: 18px; margin-bottom: 8px; }
.login .acciones { display: flex; justify-content: flex-end; }
.login .boton.primario { height: 40px; padding: 0 24px; border-radius: 20px; }

/* ---------- Avisos ---------- */
#toasts { position: fixed; left: 50%; bottom: 56px; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #313033; color: #f2f2f2; padding: 12px 16px; border-radius: 6px; min-width: 260px; max-width: 80vw;
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
}
.toast.error { background: #8c1d18; }

@media (max-width: 720px) {
  .usuario .quien { display: none; }
  .panel-lateral { display: none; }
  .barra { border-radius: 12px; }
}

/* Celda que se acaba de deshacer/rehacer con Ctrl+Z / Ctrl+Y: destello como en Sheets. */
table.hoja td.deshecha { animation: destello-deshacer .9s ease-out; }
@keyframes destello-deshacer { from { box-shadow: inset 0 0 0 2px #1a73e8; background-color: #e8f0fe; } to { box-shadow: inset 0 0 0 2px transparent; } }

/* ---------- Imprimir (boton "Imprimir"): solo la tabla, sin la interfaz ---------- */
.solo-impresion { display: none; }
@media print {
  @page { size: letter landscape; margin: 8mm; }
  html, body { background: #fff !important; height: auto !important; overflow: visible !important; }
  body.imprimiendo > *:not(.solo-impresion) { display: none !important; }
  body.imprimiendo .solo-impresion { display: block; }
  .solo-impresion { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  /* Cada pagina empieza en hoja nueva (salto ANTES, nunca despues de la ultima: asi no sale hoja en blanco). */
  body.imprimiendo { margin: 0 !important; padding: 0 !important; display: block !important; }
  .pagina-impresion { break-inside: avoid; page-break-inside: avoid; overflow: hidden; }
  .pagina-impresion + .pagina-impresion { break-before: page; page-break-before: always; }
  .solo-impresion table.hoja { border-collapse: separate; border-spacing: 0; table-layout: fixed; }
  .solo-impresion table.hoja tr { break-inside: avoid; }
  .solo-impresion table.hoja td { position: static !important; overflow: hidden; white-space: nowrap; }
}

/* ---------- Lista de nombres (administrador) ---------- */
.lista-nombres { list-style: none; margin: 0; padding: 0; min-width: 320px; }
.lista-nombres li { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px; border-bottom: 1px solid #eee; }
.lista-nombres li:hover { background: #f1f3f4; }
.lista-nombres .quitar { color: #b3261e; font-size: 13px; }
.fila-agregar { display: flex; gap: 8px; margin: 8px 0; }
.fila-agregar input { flex: 1; padding: 6px 8px; border: 1px solid #c4c7c5; border-radius: 4px; }
.gris { color: #5f6368; }

/* ---------- Lista desplegable de nombres (como la de Google Sheets) ---------- */
table.hoja td.celda-lista input.celda { padding-right: 18px; }
.flecha-lista {
  position: absolute; right: 2px; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; line-height: 16px; text-align: center; border-radius: 50%;
  font-size: 12px; color: #5f6368; cursor: pointer; opacity: 0; transition: opacity .1s;
}
table.hoja td.celda-lista:hover .flecha-lista, table.hoja td.celda-lista:focus-within .flecha-lista { opacity: 1; }
.flecha-lista:hover { background: rgba(60,64,67,.12); color: #202124; }
.lista-desplegable {
  position: fixed; z-index: 60; max-height: 260px; overflow-y: auto; padding: 6px 0;
  background: #fff; border-radius: 8px; color: #202124; font-size: 13px;
  box-shadow: 0 2px 6px 2px rgba(60,64,67,.15), 0 1px 2px rgba(60,64,67,.3);
}
.ld-opcion { padding: 7px 16px; cursor: pointer; white-space: nowrap; }
.ld-opcion b { font-weight: 700; }
.ld-opcion.activa { background: #f1f3f4; }
.ld-opcion.elegida { background: #e8f0fe; color: #0b57d0; }
.ld-opcion.elegida.activa { background: #d3e3fd; }
.ld-vacia { padding: 7px 16px; color: #5f6368; font-style: italic; }

/* ---------- Seleccionar todo (cuadro de la esquina o Ctrl+A), como en Sheets ---------- */
table.hoja thead th.esquina:hover { background: #e1e3e1; }

.lienzo:focus { outline: none; }

/* ---------- Seleccion de celdas, filas y columnas (como Sheets) ---------- */
table.hoja td.sel::before {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: rgba(14, 101, 235, .1); box-shadow: inset 0 0 0 0.5px rgba(14, 101, 235, .35);
}
table.hoja th.sel-num, table.hoja thead th.sel-col { background: #0b57d0 !important; color: #fff !important; }
table.hoja th.sel-num-parcial, table.hoja thead th.sel-col-parcial { background: #d3e3fd !important; color: #0b57d0 !important; }
table.hoja thead th, table.hoja th.num { user-select: none; }
table.hoja thead th:not(.esquina) { cursor: default; }
table.hoja td.tachado .txt, table.hoja td.tachado input.celda { text-decoration: line-through; }

/* ---------- Barra de formato (como la de Sheets) ---------- */
.barra-vista { display: contents; }
.barra-formato { display: flex; align-items: center; gap: 1px; }
.barra-formato .sep { width: 1px; height: 20px; background: var(--ui-borde); margin: 0 4px; }
.bf {
  position: relative; width: 30px; height: 30px; border: 0; border-radius: 4px; background: none;
  display: inline-flex; align-items: center; justify-content: center; color: #444746; cursor: pointer; padding: 0;
}
.bf svg { fill: currentColor; }
.bf:hover { background: rgba(68, 71, 70, .08); }
.bf.activo { background: #d3e3fd; color: #0b57d0; }
.bf.con-color svg { margin-top: -4px; }
.bf .barra-color { position: absolute; left: 7px; right: 7px; bottom: 5px; height: 3px; border-radius: 1px; background: #000; }
.menu-formato {
  position: fixed; z-index: 70; background: #fff; border-radius: 8px; padding: 10px 12px;
  box-shadow: 0 2px 6px 2px rgba(60, 64, 67, .15), 0 1px 2px rgba(60, 64, 67, .3);
}
.menu-formato .restablecer {
  width: 100%; text-align: left; border: 0; background: none; padding: 6px 4px; border-radius: 4px; cursor: pointer; font-size: 13px;
}
.menu-formato .restablecer:hover { background: #f1f3f4; }
.paleta-titulo { font-size: 11px; color: #5f6368; margin: 6px 0 6px 2px; letter-spacing: .3px; }
.paleta { display: grid; grid-template-columns: repeat(10, 20px); gap: 3px; }
.paleta .muestra {
  width: 18px; height: 18px; border-radius: 50%; border: 1px solid rgba(0, 0, 0, .12); padding: 0; cursor: pointer;
}
.paleta .muestra:hover { transform: scale(1.18); box-shadow: 0 0 0 1px #5f6368; }
.opciones-borde { display: grid; grid-template-columns: repeat(4, 30px); gap: 4px; }
.opciones-borde button { width: 30px; height: 30px; border: 0; background: none; border-radius: 4px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; }
.opciones-borde button:hover { background: #f1f3f4; }

/* ---------- Zoom de la hoja (Ver > Zoom) ---------- */
table.hoja th, table.hoja td { height: calc(21px * var(--z, 1)); }
table.hoja thead th { height: calc(20px * var(--z, 1)); font-size: calc(11px * var(--z, 1)); }
table.hoja th.num { font-size: calc(11px * var(--z, 1)); width: auto; min-width: 0; }
table.hoja td { font-size: calc(13px * var(--z, 1)); }
table.hoja td .txt { height: calc(20px * var(--z, 1)); line-height: calc(20px * var(--z, 1)); }
table.hoja td input.celda { height: calc(20px * var(--z, 1)); line-height: calc(20px * var(--z, 1)); }

/* ---------- Formatos nuevos: ajuste, rotacion, notas, vinculos, combinadas ---------- */
table.hoja td.ajustar { white-space: normal; height: auto; }
table.hoja td.ajustar .txt { height: auto; white-space: pre-wrap; word-break: break-word; line-height: 1.35; padding: 2px 4px; }
table.hoja td textarea.celda {
  display: block; width: 100%; min-height: calc(20px * var(--z, 1)); border: 0; background: transparent; padding: 2px 4px;
  outline: none; resize: none; overflow: hidden; white-space: pre-wrap; word-break: break-word; line-height: 1.35;
  font: inherit; color: inherit; text-align: inherit; field-sizing: content;
}
table.hoja td.desbordar { overflow: visible; }
table.hoja td.recortar .txt, table.hoja td.recortar input.celda { text-overflow: clip; }
table.hoja td.rot-inclinar-arriba .txt, table.hoja td.rot-inclinar-arriba input.celda { transform: rotate(-45deg); }
table.hoja td.rot-inclinar-abajo .txt, table.hoja td.rot-inclinar-abajo input.celda { transform: rotate(45deg); }
table.hoja td.rot-girar-arriba .txt, table.hoja td.rot-girar-arriba input.celda { transform: rotate(-90deg); }
table.hoja td.rot-girar-abajo .txt, table.hoja td.rot-girar-abajo input.celda { transform: rotate(90deg); }
table.hoja td.rot-vertical .txt { writing-mode: vertical-rl; text-orientation: upright; height: auto; line-height: 1; }
table.hoja td.con-nota::after {
  content: ''; position: absolute; top: 0; right: 0; border-style: solid; border-width: 0 6px 6px 0;
  border-color: transparent #202124 transparent transparent; pointer-events: none;
}
table.hoja td.con-vinculo .txt, table.hoja td.con-vinculo input.celda { color: #1155cc; text-decoration: underline; padding-right: 16px; }
table.hoja td .vinculo {
  position: absolute; right: 2px; top: 50%; transform: translateY(-50%); z-index: 1; font-size: 11px;
  color: #1155cc; text-decoration: none; background: rgba(255, 255, 255, .85); border-radius: 3px; padding: 0 2px;
}
table.hoja td .vinculo:hover { background: #e8f0fe; }
table.hoja td.combinada { vertical-align: middle; }

/* ---------- Crear un filtro (botones en los titulos) ---------- */
table.hoja td.con-filtro .txt { padding-right: 20px; }
table.hoja td .boton-filtro {
  position: absolute; right: 2px; top: 50%; transform: translateY(-50%); z-index: 1; width: 16px; height: 16px;
  border: 0; border-radius: 3px; background: #fff; color: #188038; font-size: 10px; line-height: 16px; padding: 0; cursor: pointer;
  box-shadow: 0 0 0 1px #c7c7c7;
}
table.hoja td .boton-filtro.activo { background: #188038; color: #fff; box-shadow: none; }
.menu-filtro {
  position: fixed; z-index: 80; width: 280px; max-height: 70vh; display: flex; flex-direction: column; gap: 6px;
  background: #fff; border-radius: 8px; padding: 8px 0; box-shadow: 0 2px 6px 2px rgba(60, 64, 67, .15), 0 1px 2px rgba(60, 64, 67, .3);
}
.menu-filtro .filtro-orden { border: 0; background: none; text-align: left; padding: 6px 16px; cursor: pointer; }
.menu-filtro .filtro-orden:hover { background: #f1f3f4; }
.menu-filtro .filtro-titulo { padding: 6px 16px 0; font-weight: 700; border-top: 1px solid #e0e0e0; margin-top: 2px; }
.menu-filtro .filtro-acciones { display: flex; gap: 12px; padding: 0 16px; }
.menu-filtro .filtro-acciones button { border: 0; background: none; color: #0b57d0; padding: 0; cursor: pointer; }
.menu-filtro .filtro-buscar { margin: 0 16px; height: 28px; border: 1px solid #c7c7c7; border-radius: 4px; padding: 0 8px; }
.menu-filtro .filtro-lista { overflow: auto; flex: 1; min-height: 80px; max-height: 260px; padding: 0 16px; }
.menu-filtro .filtro-valor { display: flex; align-items: center; gap: 6px; padding: 2px 0; cursor: pointer; }
.menu-filtro .filtro-valor span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-filtro .filtro-valor small { color: #80868b; }
.menu-filtro .filtro-pie { display: flex; justify-content: flex-end; gap: 8px; padding: 6px 16px 0; border-top: 1px solid #e0e0e0; }

/* ---------- Barra de herramientas completa ---------- */
.barra-formato { flex-wrap: wrap; row-gap: 2px; }
.bf.con-flecha { width: auto; padding: 0 2px 0 4px; gap: 0; }
.bf .flechita { font-size: 9px; margin-left: 1px; color: #5f6368; }
.bf .txt-boton { font-size: 14px; font-weight: 500; font-family: Arial, sans-serif; }
.bf .txt-boton.chico { font-size: 11px; letter-spacing: -.3px; }
.bf .txt-boton.sigma { font-size: 17px; }
.barra select.sel-barra {
  height: 28px; border: 0; border-radius: 4px; background: transparent; cursor: pointer; padding: 0 4px;
}
.barra select.sel-barra:hover { background: rgba(68, 71, 70, .08); }
.barra select.sel-fuente { width: 128px; }
.barra input.campo-tam {
  width: 38px; height: 26px; text-align: center; border: 1px solid #747775; border-radius: 4px; padding: 0 2px; -moz-appearance: textfield;
}
.campo-tam::-webkit-inner-spin-button, .campo-tam::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.menu-opciones { display: flex; flex-direction: column; min-width: 190px; margin: -4px -6px; }
.menu-opciones button {
  display: flex; align-items: center; gap: 10px; border: 0; background: none; text-align: left; padding: 6px 10px;
  border-radius: 4px; cursor: pointer; color: #202124;
}
.menu-opciones button:hover { background: #f1f3f4; }
.menu-opciones button.marcado { background: #e8f0fe; }
.menu-opciones svg { fill: #444746; flex: none; }
.menu-opciones .sin-icono { width: 18px; flex: none; }
.menu-opciones hr { border: 0; border-top: 1px solid #e0e0e0; margin: 4px 0; width: 100%; }

/* ---------- Barra de menus (Archivo, Editar, Ver...) ---------- */
.menu-doc button.abierto { background: #e8eaed; }
.menu-principal {
  position: fixed; z-index: 90; min-width: 260px; max-height: calc(100vh - 16px); overflow: auto;
  background: #fff; border-radius: 8px; padding: 6px 0;
  box-shadow: 0 2px 6px 2px rgba(60, 64, 67, .15), 0 1px 2px rgba(60, 64, 67, .3);
}
.menu-principal button {
  display: flex; align-items: center; width: 100%; border: 0; background: none; text-align: left;
  padding: 6px 16px 6px 8px; cursor: pointer; color: #202124; gap: 6px; white-space: nowrap;
}
.menu-principal button:hover:not(:disabled) { background: #f1f3f4; }
.menu-principal button:disabled { color: #a8abae; cursor: default; }
.menu-principal .marca { width: 18px; text-align: center; color: #0b57d0; flex: none; }
.menu-principal .texto { flex: 1; }
.menu-principal .atajo { color: #5f6368; font-size: 12px; margin-left: 24px; }
.menu-principal hr { border: 0; border-top: 1px solid #e0e0e0; margin: 6px 0; }

/* ---------- Buscar y reemplazar ---------- */
.panel-buscar {
  position: fixed; top: 120px; right: 24px; z-index: 85; width: 420px; max-width: calc(100vw - 32px);
  background: #fff; border-radius: 8px; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px;
  box-shadow: 0 2px 6px 2px rgba(60, 64, 67, .15), 0 1px 2px rgba(60, 64, 67, .3);
}
.panel-buscar input[type=search], .panel-buscar input[type=text] {
  flex: 1; height: 30px; border: 1px solid #c7c7c7; border-radius: 4px; padding: 0 8px; min-width: 0;
}
.panel-buscar .fila-buscar, .panel-buscar .fila-reemplazo { display: flex; gap: 4px; align-items: center; }
.panel-buscar .fila-reemplazo { display: none; }
.panel-buscar.con-reemplazo .fila-reemplazo { display: flex; }
.panel-buscar .opciones-buscar { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: #444746; }
.panel-buscar .opciones-buscar label { display: flex; align-items: center; gap: 6px; }
.panel-buscar .enlace { border: 0; background: none; color: #0b57d0; padding: 0; cursor: pointer; text-align: left; }

/* ---------- Totales de lo seleccionado (abajo a la derecha) ---------- */
.chip-totales {
  position: sticky; right: 0; margin-left: auto; flex: none; height: 30px; padding: 0 12px; border: 1px solid #c7c7c7;
  border-radius: 6px; background: #fff; cursor: pointer; color: #202124; font-size: 13px; display: inline-flex; gap: 8px; align-items: center;
}
.chip-totales:hover { background: #f1f3f4; }

/* ---------- Grafico y atajos ---------- */
.grafico { width: min(680px, 80vw); margin-top: 8px; }
.grafico svg { display: block; }
.tabla-atajos { border-collapse: collapse; }
.tabla-atajos td { padding: 4px 10px 4px 0; vertical-align: top; }
.tabla-atajos kbd {
  background: #f1f3f4; border: 1px solid #dadce0; border-radius: 4px; padding: 1px 6px; font-family: inherit; font-size: 12px; white-space: nowrap;
}
@media print {
  .menu-principal, .panel-buscar, .chip-totales, .menu-filtro { display: none !important; }
}
