/* Invoko — estilos de la interfaz local. Limpio, tipo panel de administración. */
:root {
  --azul: #1f6feb;
  --azul-osc: #144a99;
  --verde: #1a7f37;
  --rojo: #cf222e;
  --gris-bg: #f6f8fa;
  --gris-borde: #d0d7de;
  --gris-texto: #57606a;
  --texto: #1f2328;
  --amarillo: #fff8c5;
  --radio: 8px;
  --sombra: 0 1px 3px rgba(0,0,0,.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--texto);
  background: var(--gris-bg);
  font-size: 15px;
  line-height: 1.5;
}
a { color: var(--azul); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Estructura: barra lateral + contenido */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 220px;
  background: #0d1117;
  color: #e6edf3;
  padding: 20px 0;
  flex-shrink: 0;
}
.sidebar .marca {
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
  padding: 0 20px 16px; text-align: left;
}
.sidebar .marca .marca-logo {
  width: 150px; max-width: 100%; height: auto; display: block;
}
.sidebar .marca .marca-nombre {
  font-size: 22px; font-weight: 700; letter-spacing: .5px;
}
.sidebar .marca .marca-nombre span { color: #58a6ff; }
.sidebar nav a {
  display: block; padding: 10px 20px; color: #c9d1d9;
}
.sidebar nav a:hover { background: #161b22; text-decoration: none; }
.sidebar nav a.activo { background: var(--azul); color: #fff; }

/* Grupo desplegable (Configuración) */
.sidebar .nav-grupo summary {
  display: block; padding: 10px 20px; color: #c9d1d9; cursor: pointer;
  list-style: none; position: relative; user-select: none;
}
.sidebar .nav-grupo summary::-webkit-details-marker { display: none; }
.sidebar .nav-grupo summary::after {
  content: "\25B8"; position: absolute; right: 20px; color: #8b949e;
  transition: transform .15s ease;
}
.sidebar .nav-grupo[open] summary::after { transform: rotate(90deg); }
.sidebar .nav-grupo summary:hover { background: #161b22; }
.sidebar .nav-grupo summary.activo { color: #fff; }
.sidebar .nav-grupo a { padding-left: 36px; font-size: 14px; }
.sidebar .lema { padding: 16px 20px 0; font-size: 12px; color: #8b949e; }

.contenido { flex: 1; padding: 28px 36px; max-width: 1100px; }

/* Encabezados */
.pagina-titulo {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px; gap: 12px;
}
h1 { font-size: 24px; margin: 0; }
h2 { font-size: 18px; margin: 24px 0 12px; }

/* Botones */
.btn {
  display: inline-block; padding: 8px 16px; border-radius: var(--radio);
  border: 1px solid var(--gris-borde); background: #fff; color: var(--texto);
  cursor: pointer; font-size: 14px; font-weight: 500; line-height: 1.4;
}
.btn:hover { background: var(--gris-bg); text-decoration: none; }
.btn-primario { background: var(--azul); border-color: var(--azul); color: #fff; }
.btn-primario:hover { background: var(--azul-osc); color: #fff; }
.btn-peligro { color: var(--rojo); border-color: #f1c0c4; }
.btn-peligro:hover { background: #ffebe9; }
.btn-mini { padding: 4px 10px; font-size: 13px; }

/* Tarjetas */
.tarjetas { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px,1fr)); gap: 16px; margin-bottom: 24px; }
.tarjeta {
  background: #fff; border: 1px solid var(--gris-borde);
  border-radius: var(--radio); padding: 18px 20px; box-shadow: var(--sombra);
}
.tarjeta .num { font-size: 32px; font-weight: 700; }
.tarjeta .etq { color: var(--gris-texto); font-size: 14px; }
.tarjeta a { display: block; }

/* Tablas */
.tabla-caja {
  background: #fff; border: 1px solid var(--gris-borde);
  border-radius: var(--radio); overflow: hidden; box-shadow: var(--sombra);
}
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--gris-borde); }
th { background: var(--gris-bg); font-size: 13px; text-transform: uppercase; color: var(--gris-texto); letter-spacing: .3px; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f9fbff; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Formularios */
.tarjeta-form {
  background: #fff; border: 1px solid var(--gris-borde);
  border-radius: var(--radio); padding: 24px; box-shadow: var(--sombra);
  margin-bottom: 20px;
}
.campos { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.campo { display: flex; flex-direction: column; gap: 4px; }
.campo.ancho { grid-column: 1 / -1; }
label { font-size: 13px; font-weight: 600; color: var(--gris-texto); }
input, select, textarea {
  padding: 8px 10px; border: 1px solid var(--gris-borde);
  border-radius: 6px; font-size: 14px; font-family: inherit; background: #fff;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--azul); border-color: var(--azul); }
textarea { resize: vertical; min-height: 60px; }
.grupo-titulo { grid-column: 1/-1; font-weight: 600; color: var(--texto); border-top: 1px solid var(--gris-borde); padding-top: 14px; margin-top: 4px; }
.acciones { display: flex; gap: 10px; margin-top: 20px; align-items: center; }

/* Ojo para ver/ocultar contraseña */
.campo-clave { position: relative; display: flex; }
.campo-clave input { flex: 1; padding-right: 38px; }
.campo-clave .ojo {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; font-size: 16px;
  padding: 4px 6px; line-height: 1; opacity: .55;
}
.campo-clave .ojo:hover { opacity: 1; }

/* Búsqueda */
.barra-busqueda { display: flex; gap: 8px; margin-bottom: 16px; }
.barra-busqueda input { flex: 1; max-width: 360px; }

/* Avisos */
.aviso { padding: 10px 16px; border-radius: var(--radio); margin-bottom: 16px; font-size: 14px; }
.aviso-ok { background: #dafbe1; border: 1px solid #a3e2b3; color: var(--verde); }
.aviso-err { background: #ffebe9; border: 1px solid #f1c0c4; color: var(--rojo); }

/* Etiquetas de tipo */
.pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pill-quimica { background: #ddf4ff; color: var(--azul-osc); }
.pill-reventa { background: #fff1e5; color: #bc4c00; }
.pill-pagada { background: #dafbe1; color: var(--verde); }
.pill-pendiente { background: var(--amarillo); color: #7a5c00; }
/* Pill clickeable: alterna el estado de la factura al hacer clic. */
button.pill-toggle { border: none; cursor: pointer; font-family: inherit; line-height: 1.4; }
button.pill-toggle:hover { filter: brightness(0.94); text-decoration: underline; }

.vacio { text-align: center; color: var(--gris-texto); padding: 40px; }

/* Informes */
.tarjeta .valor { font-size: 30px; font-weight: 700; margin-top: 4px; }
.filtros { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 14px; margin-bottom: 22px; }
.filtros .campo { display: flex; flex-direction: column; gap: 4px; }
.filtros input, .filtros select { padding: 8px 10px; border: 1px solid var(--gris-borde); border-radius: var(--radio); }
.dos-columnas { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; margin-top: 8px; }
@media (max-width: 820px) { .dos-columnas { grid-template-columns: 1fr; } }
.ayuda { font-size: 12px; color: var(--gris-texto); font-weight: 400; }
.dinero::before { content: "$"; }

/* Ícono "i" de información + tooltip (mismo diseño que el de gastos). El tooltip
   usa position:fixed (lo posiciona el JS) para no recortarse dentro de tablas
   con overflow:hidden. */
.info-i {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--azul); color: #fff;
  font-size: 10px; font-weight: 700; font-style: italic;
  text-transform: none; cursor: pointer; vertical-align: middle; line-height: 1;
}
.info-i:focus { outline: 2px solid var(--azul); outline-offset: 1px; }
.info-tip {
  position: fixed; display: none; z-index: 1000;
  background: var(--azul); color: #fff; padding: 6px 10px; border-radius: 6px;
  font-size: 12px; line-height: 1.35; max-width: 240px;
  font-weight: 400; font-style: normal; text-align: left; white-space: normal;
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
}

/* Totales del formulario de factura */
.totales { margin-left: auto; width: 300px; margin: 8px 0 20px auto; }
.totales div { display: flex; justify-content: space-between; padding: 6px 4px; font-size: 15px; }
.totales .grande { border-top: 2px solid var(--texto); font-weight: 700; font-size: 18px; margin-top: 4px; padding-top: 10px; }

/* Factura — documento estilo QuickBooks */
.factura-toolbar { display: flex; gap: 10px; margin-bottom: 16px; align-items: center; flex-wrap: wrap; }
.factura-doc {
  background: #fff; border: 1px solid var(--gris-borde); border-radius: var(--radio);
  box-shadow: var(--sombra); padding: 40px; max-width: 820px;
}
.factura-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; margin-bottom: 28px; }
.factura-head .empresa { font-size: 13px; line-height: 1.5; }
.factura-head .empresa .nombre { font-weight: 700; font-size: 15px; }
.factura-head .logo { font-weight: 800; font-style: italic; font-size: 26px; color: #0d1117; }
.factura-head .logo span { color: var(--azul); }
.factura-head .logo-img img { max-height: 80px; max-width: 220px; object-fit: contain; }

/* Nueva factura: aviso de inventario por línea */
#lineas .stock { color: var(--gris-texto); font-size: 13px; }
#lineas .stock.agotado { color: var(--rojo); font-weight: 700; }
#lineas input.malo { border-color: var(--rojo); background: #ffebe9; }
#lineas .aviso-stock { color: var(--rojo); font-size: 12px; font-weight: 600; margin-top: 3px; }
#lineas .sel-unidad { width: 100%; font-size: 12px; margin-top: 4px; padding: 2px; }
.factura-head .titulo { font-size: 30px; font-weight: 700; letter-spacing: 1px; color: #333; text-align: right; }
.bill-ship { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 18px; }
.bill-ship .caja { border: 1px solid var(--gris-borde); border-radius: 6px; overflow: hidden; }
.bill-ship .caja .etq { background: var(--gris-bg); font-size: 11px; font-weight: 700; text-transform: uppercase; color: var(--gris-texto); padding: 5px 10px; letter-spacing: .5px; }
.bill-ship .caja .cuerpo { padding: 10px; font-size: 13px; line-height: 1.55; }
.meta-bar { display: grid; grid-template-columns: repeat(5, 1fr); border: 1px solid var(--gris-borde); border-radius: 6px; overflow: hidden; margin-bottom: 20px; }
.meta-bar > div { padding: 7px 10px; border-right: 1px solid var(--gris-borde); font-size: 13px; }
.meta-bar > div:last-child { border-right: none; }
.meta-bar .etq { font-size: 10px; font-weight: 700; text-transform: uppercase; color: var(--gris-texto); letter-spacing: .3px; }
.factura-tot { margin-left: auto; width: 300px; margin-top: 10px; }
.factura-tot div { display: flex; justify-content: space-between; padding: 5px 10px; font-size: 14px; }
.factura-tot .balance { border-top: 2px solid #333; font-weight: 700; font-size: 17px; margin-top: 4px; padding-top: 9px; }
.factura-notas { margin-top: 18px; font-size: 13px; color: var(--gris-texto); }

@media print {
  body { background: #fff; }
  .sidebar, .factura-toolbar, .no-print, .aviso { display: none !important; }
  .contenido { padding: 0; max-width: none; }
  .factura-doc { border: none; box-shadow: none; padding: 0; max-width: none; }
}

/* Firmas de la orden de compra (Issued by / Authorized by) */
.factura-firmas { display: flex; gap: 40px; margin-top: 26px; }
.factura-firmas > div { flex: 1; border-top: 1px solid var(--gris-borde); padding-top: 8px; font-size: 13px; }
.factura-firmas .etq { font-size: 10px; font-weight: 700; text-transform: uppercase; color: var(--gris-texto); letter-spacing: .3px; }

.pill-admin { background: #ddf4ff; color: var(--azul-osc); }
.pill-facturador { background: #fff1e5; color: #bc4c00; }
.pill-inactivo { background: #eaeef2; color: var(--gris-texto); }

/* Usuario logueado en la barra lateral */
.sidebar .usuario-box {
  margin-top: auto; padding: 16px 20px 0; font-size: 13px;
  border-top: 1px solid #21262d;
}
.sidebar .usuario-box .quien { color: #e6edf3; font-weight: 600; }
.sidebar .usuario-box .rol { color: #8b949e; font-size: 12px; }
.sidebar .usuario-box a { color: #58a6ff; display: inline-block; margin-top: 6px; }
.sidebar { display: flex; flex-direction: column; }

/* Selector de idioma */
.idioma-switch { padding: 10px 20px 0; display: flex; gap: 6px; font-size: 12px; }
.idioma-switch a {
  color: #8b949e; border: 1px solid #21262d; border-radius: 4px;
  padding: 2px 8px; font-weight: 600;
}
.idioma-switch a:hover { background: #161b22; text-decoration: none; }
.idioma-switch a.activo { background: var(--azul); color: #fff; border-color: var(--azul); }
.auth-idioma { display: flex; gap: 6px; justify-content: center; margin-top: 18px; font-size: 12px; }
.auth-idioma a {
  color: var(--gris-texto); border: 1px solid var(--gris-borde); border-radius: 4px;
  padding: 2px 8px; font-weight: 600;
}
.auth-idioma a.activo { background: var(--azul); color: #fff; border-color: var(--azul); }
.auth-idioma a:hover { text-decoration: none; }

/* Login / configuración inicial */
.auth-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.auth-card {
  background: #fff; border: 1px solid var(--gris-borde); border-radius: var(--radio);
  box-shadow: var(--sombra); padding: 32px; width: 100%; max-width: 380px;
}
.auth-card .marca {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  margin-bottom: 8px;
}
.auth-card .marca .marca-logo { width: 160px; max-width: 70%; height: auto; }
.auth-card .marca .marca-nombre { font-size: 28px; font-weight: 700; }
.auth-card .marca .marca-nombre span { color: var(--azul); }
.auth-card .sub { color: var(--gris-texto); margin-bottom: 20px; font-size: 14px; }
.auth-card .campo { margin-bottom: 14px; }
.auth-card label { display: block; margin-bottom: 4px; }
.auth-card input, .auth-card select { width: 100%; }
.auth-card .btn-primario { width: 100%; margin-top: 6px; }

/* --- Inventario clickeable + modal de nueva fabricación --- */
.inv-link {
  font: inherit; cursor: pointer;
  background: #ddf4ff; color: var(--azul-osc);
  border: 1px solid transparent; border-radius: 999px;
  padding: 2px 12px; font-weight: 600;
}
.inv-link:hover { background: var(--azul); color: #fff; }

dialog.modal {
  width: min(520px, 92vw);
  border: 1px solid var(--gris-borde); border-radius: var(--radio);
  padding: 20px 22px; box-shadow: 0 10px 40px rgba(0,0,0,.2);
  color: var(--texto);
}
dialog.modal::backdrop { background: rgba(0,0,0,.45); }
dialog.modal .modal-cab { display: flex; align-items: center; justify-content: space-between; }
dialog.modal .modal-cab h3 { margin: 0; }
dialog.modal .modal-x {
  border: none; background: none; cursor: pointer;
  font-size: 26px; line-height: 1; color: var(--gris-texto); padding: 0 4px;
}
dialog.modal .modal-x:hover { color: var(--rojo); }
dialog.modal .tarjeta-form { border: none; padding: 0; box-shadow: none; background: none; margin: 0; }

/* Casilla "Aplicar impuesto" en nueva factura */
.check-impuesto {
  display: flex; align-items: center; gap: 8px;
  font-weight: 400; cursor: pointer; padding: 8px 0;
}
.check-impuesto input { width: auto; margin: 0; cursor: pointer; }

/* Descripción por línea en la factura */
.detalle-linea { width: 100%; font-size: 13px; }
.linea-detalle { font-size: 13px; color: var(--gris-texto); margin-top: 2px; white-space: pre-wrap; }

/* Botones de acción en la fila de la lista de facturas */
.acciones-fila { white-space: nowrap; }
.acciones-fila .btn-mini { margin-left: 4px; }

/* Líneas de la factura: layout fijo para que la columna del ✕ (borrar) siempre
   se vea y los campos se ajusten al ancho de su celda sin desbordar. */
#lineas { table-layout: fixed; }
#lineas th, #lineas td { overflow: hidden; }
#lineas select, #lineas input { max-width: 100%; }

/* Deuda vencida: badge del menú, banner del dashboard y marcas en la lista. */
.nav-badge {
  display: inline-block; min-width: 18px; margin-left: 6px; padding: 0 6px;
  background: var(--rojo); color: #fff; font-size: 12px; font-weight: 700;
  line-height: 18px; text-align: center; border-radius: 9px;
}
.nav-badge-term { background: var(--amarillo); color: #7a5c00; margin-left: 4px; }

.banner-deuda {
  background: #ffebe9; border: 1px solid #f1c0c4; border-left: 4px solid var(--rojo);
  border-radius: var(--radio); padding: 12px 16px; margin-bottom: 20px;
}
.banner-deuda-cab {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  color: var(--rojo); font-size: 15px;
}
.banner-deuda-icono { font-size: 18px; }
.banner-deuda-sep { color: #f1846c; }
.banner-deuda-ver { margin-left: auto; }
.banner-deuda-tabla { margin-top: 10px; width: 100%; border-collapse: collapse; }
.banner-deuda-tabla td { padding: 4px 8px; border-top: 1px solid #f1c0c4; font-size: 14px; }
.banner-deuda-tabla td:first-child { padding-left: 0; }
.banner-deuda-atraso { color: var(--rojo); font-size: 13px; }

.btn-vencidas { color: var(--rojo); border-color: #f1c0c4; }
.btn-vencidas.btn-primario { color: #fff; }

.fila-vencida { background: #fff5f4; }
.venc-rojo { color: var(--rojo); font-weight: 600; }
.venc-etq {
  display: inline-block; margin-left: 6px; padding: 1px 6px;
  background: var(--rojo); color: #fff; font-size: 11px; font-weight: 700;
  border-radius: 4px; text-transform: uppercase;
}
.term-etq {
  display: inline-block; margin-left: 6px; padding: 1px 6px;
  background: var(--amarillo); color: #7a5c00; border: 1px solid #e6d78a;
  font-size: 11px; font-weight: 700; border-radius: 4px; text-transform: uppercase;
}

/* Deuda del cliente en el formulario de nueva/editar factura. */
.deuda-cliente {
  border-radius: var(--radio); padding: 10px 14px; margin: 0 0 18px;
  border: 1px solid; border-left-width: 4px;
}
.deuda-cliente.con-vencida { background: #ffebe9; border-color: #f1c0c4; border-left-color: var(--rojo); }
.deuda-cliente.solo-pendiente { background: var(--amarillo); border-color: #e6d78a; border-left-color: #caa300; }
.deuda-cliente-cab {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 14px;
}
.deuda-cliente.con-vencida .deuda-cliente-cab { color: var(--rojo); }
.deuda-cliente.solo-pendiente .deuda-cliente-cab { color: #7a5c00; }
.deuda-icono { font-size: 16px; }
.deuda-sep { opacity: .5; }
.deuda-vencido { font-weight: 700; }
.deuda-cliente-tabla { margin-top: 8px; width: 100%; border-collapse: collapse; }
.deuda-cliente-tabla td { padding: 3px 8px; font-size: 13px; border-top: 1px solid rgba(0,0,0,.08); }
.deuda-cliente-tabla td:first-child { padding-left: 0; }
