/* =====================================================================
   GrysERP — sistema de diseño base (Hito 0, punto 3)
   Colores Grystech: #2f89d9 azul · #7c8996 gris claro · #000000 negro · #494d58 gris azulado
   Las variables de tema (--primario, --lateral, --acento...) las puede sobrescribir cada
   empresa desde /e/<empresa>/tema.css; aquí van los valores de Grystech por defecto.
   ===================================================================== */

:root {
  /* Tema (personalizable por empresa; derivado con contraste AA en internal/dominio/tema.go) */
  --marca: #2f89d9; --primario: #2979bf; --primario-hover: #2366a2; --primario-suave: #e6f1fa; --sobre-primario: #fff;
  --lateral: #494d58; --lateral-texto: #fff; --lateral-tenue: #babbc0; --lateral-activo: #62666f;
  --acento: #7c8996; --acento-texto: #6b7681; --acento-suave: #edeef0;

  /* Fijos */
  --negro: #000; --texto: #15171b; --texto-2: #494d58; --texto-3: #5f6670;
  --borde: #dfe3e8; --borde-campo: #7c8996; --fondo: #f4f6f8; --superficie: #fff;
  --exito: #1a7f37; --exito-suave: #e7f5ec; --peligro: #c22f1f; --peligro-suave: #fdecea;
  --aviso: #8a5a00; --aviso-suave: #fff4db; --info: var(--primario); --info-suave: var(--primario-suave);

  --radio: 10px; --radio-s: 6px; --sombra: 0 1px 2px rgb(0 0 0 / .06), 0 1px 3px rgb(0 0 0 / .08);
  --sombra-alta: 0 10px 30px rgb(0 0 0 / .16);
  --ancho-lateral: 256px; --alto-barra: 60px; --alto-tabs: 64px;
  --fuente: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.5 var(--fuente); color: var(--texto); background: var(--fondo); }
h1, h2, h3 { color: var(--negro); line-height: 1.25; margin: 0 0 .5rem; font-weight: 700; }
strong, b { font-weight: 700; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1.05rem; }
p { margin: 0 0 1rem; }
a { color: var(--primario); }
a:hover { color: var(--primario-hover); }
code { font-family: var(--mono); font-size: .92em; background: var(--fondo); padding: .1em .35em; border-radius: 4px; }
:focus-visible { outline: 3px solid var(--marca); outline-offset: 2px; }
.oculto-visual { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[x-cloak] { display: none !important; }

/* Iconos (sprite /estatico/iconos.svg) */
.icono { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icono.g { width: 24px; height: 24px; }

/* Marca */
.logo { display: inline-flex; align-items: baseline; font-weight: 800; font-size: 1.3rem; letter-spacing: -.02em; text-decoration: none; color: var(--negro); }
.logo b { color: var(--marca); font-weight: 800; }
.lateral .logo { color: var(--lateral-texto); align-items: center; gap: .55rem; }
.icono-marca { width: 32px; height: 32px; border-radius: 7px; flex: none; }
.logo-completo { display: inline-flex; align-items: center; gap: .9rem; }
.logo-completo img { display: block; height: 64px; width: auto; }
.logo-completo .logo { padding-left: .9rem; border-left: 2px solid var(--borde); font-size: 1.5rem; }
.barra-simple .logo-completo img { height: 40px; }
.barra-simple .logo-completo .logo { font-size: 1.2rem; padding-left: .75rem; }

/* ---------------------------------------------------------------- Botones */
.boton {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: 44px; padding: 0 1.1rem; font: inherit; font-weight: 600; line-height: 1;
  color: var(--sobre-primario); background: var(--primario); border: 1px solid transparent; border-radius: var(--radio-s);
  cursor: pointer; text-decoration: none; white-space: nowrap; transition: background .15s, border-color .15s;
}
.boton:hover { background: var(--primario-hover); color: var(--sobre-primario); }
.boton.secundario { background: var(--superficie); color: var(--primario); border-color: var(--borde-campo); }
.boton.secundario:hover { background: var(--primario-suave); }
.boton.fantasma { background: transparent; color: var(--texto-2); }
.boton.fantasma:hover { background: var(--fondo); color: var(--texto); }
.boton.peligro { background: var(--peligro); }
.boton.peligro:hover { background: #a32617; }
.boton.bloque { width: 100%; }
.boton.chico { min-height: 36px; padding: 0 .8rem; font-size: .9rem; }
.boton[disabled], .boton.htmx-request { opacity: .6; pointer-events: none; }
.acciones { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }

/* ---------------------------------------------------------------- Formularios */
.campo { display: block; margin: 0 0 1.1rem; }
.campo > span, .etiqueta { display: block; margin-bottom: .35rem; font-weight: 600; font-size: .95rem; color: var(--texto); }
.campo .ayuda { display: block; margin-top: .3rem; font-size: .85rem; color: var(--texto-3); font-weight: 400; }
.campo .error { display: block; margin-top: .3rem; font-size: .85rem; color: var(--peligro); font-weight: 600; }
input:not([type=checkbox]):not([type=radio]):not([type=color]), select, textarea {
  display: block; width: 100%; min-height: 44px; padding: .6rem .75rem; font: inherit; color: var(--texto);
  background: var(--superficie); border: 1px solid var(--borde-campo); border-radius: var(--radio-s);
}
textarea { min-height: 96px; resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--texto-3); }
input:focus, select:focus, textarea:focus { outline: 3px solid var(--primario-suave); border-color: var(--primario); }
.campo.con-error input, .campo.con-error select { border-color: var(--peligro); }
input[type=color] { width: 56px; height: 44px; padding: 3px; border: 1px solid var(--borde-campo); border-radius: var(--radio-s); background: var(--superficie); cursor: pointer; }
.fila-campos { display: grid; gap: 0 1rem; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.casilla { display: flex; gap: .6rem; align-items: center; min-height: 44px; }
.casilla input { width: 20px; height: 20px; accent-color: var(--primario); }

/* ---------------------------------------------------------------- Tarjetas y avisos */
.tarjeta { background: var(--superficie); border: 1px solid var(--borde); border-radius: var(--radio); padding: 1.25rem; box-shadow: var(--sombra); }
.tarjeta + .tarjeta { margin-top: 1rem; }
.rejilla > .tarjeta + .tarjeta, .rejilla > * { margin-top: 0; }
.tarjeta > header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.tarjeta > header h2 { margin: 0; }
.rejilla { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.rejilla.dos { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.rejilla + .tarjeta, .tarjeta + .rejilla, .rejilla + .rejilla { margin-top: 1rem; }

.aviso { display: flex; gap: .65rem; align-items: flex-start; padding: .8rem 1rem; border-radius: var(--radio-s); border: 1px solid; margin: 0 0 1rem;
  background: var(--peligro-suave); color: var(--peligro); border-color: #f5c2bc; }
.aviso .icono { margin-top: 2px; }
.aviso.exito { background: var(--exito-suave); color: var(--exito); border-color: #b9e2c6; }
.aviso.info { background: var(--info-suave); color: var(--primario-hover); border-color: color-mix(in srgb, var(--primario) 30%, white); }
.aviso.alerta { background: var(--aviso-suave); color: var(--aviso); border-color: #f2d58f; }

.insignia { display: inline-flex; align-items: center; gap: .3rem; padding: .15rem .55rem; font-size: .8rem; font-weight: 600; border-radius: 999px; background: var(--acento-suave); color: var(--acento-texto); white-space: nowrap; }
.insignia.exito { background: var(--exito-suave); color: var(--exito); }
.insignia.peligro { background: var(--peligro-suave); color: var(--peligro); }
.insignia.alerta { background: var(--aviso-suave); color: var(--aviso); }
.insignia.info { background: var(--primario-suave); color: var(--primario-hover); }

/* Indicadores (KPI) */
.kpi { display: flex; flex-direction: column; gap: .25rem; border-top: 4px solid var(--acento); }
.kpi .titulo { font-size: .9rem; color: var(--texto-2); font-weight: 600; }
.kpi .valor { font-size: 1.7rem; font-weight: 750; color: var(--negro); font-variant-numeric: tabular-nums; }
.kpi .nota { font-size: .85rem; color: var(--texto-3); }

/* Estado vacío */
.vacio { text-align: center; padding: 2.5rem 1rem; color: var(--texto-2); }
.vacio .icono { width: 44px; height: 44px; color: var(--acento); margin-bottom: .5rem; stroke-width: 1.4; }
.vacio h3 { margin-bottom: .3rem; }
.vacio .acciones { justify-content: center; }
.vacio p { max-width: 46ch; margin-left: auto; margin-right: auto; }

/* ---------------------------------------------------------------- Tablas */
.tabla-envoltura { overflow-x: auto; border: 1px solid var(--borde); border-radius: var(--radio); background: var(--superficie); }
table.tabla { width: 100%; border-collapse: collapse; font-size: .95rem; }
.tabla th { text-align: left; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--texto-2); background: var(--fondo); font-weight: 700; }
.tabla th, .tabla td { padding: .75rem 1rem; border-bottom: 1px solid var(--borde); vertical-align: middle; }
.tabla tr:last-child td { border-bottom: 0; }
.tabla tbody tr:hover { background: var(--primario-suave); }
.tabla .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
/* En celular cada fila es una tarjeta: las celdas muestran su encabezado vía data-titulo */
@media (max-width: 720px) {
  .tabla-envoltura.apilar { border: 0; background: none; overflow: visible; }
  .apilar .tabla thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .apilar .tabla tr { display: block; background: var(--superficie); border: 1px solid var(--borde); border-radius: var(--radio); margin-bottom: .75rem; padding: .4rem 0; }
  .apilar .tabla td { display: flex; justify-content: space-between; gap: 1rem; border: 0; padding: .4rem 1rem; text-align: right; }
  .apilar .tabla td::before { content: attr(data-titulo); font-weight: 600; color: var(--texto-2); text-align: left; }
}

/* ---------------------------------------------------------------- Pasos guiados */
.pasos { list-style: none; margin: 0; padding: 0; }
.pasos li { display: flex; gap: .9rem; align-items: center; padding: .8rem 0; border-bottom: 1px solid var(--borde); }
.pasos li:last-child { border-bottom: 0; }
.pasos .marca-paso { display: grid; place-items: center; width: 32px; height: 32px; flex: none; border-radius: 50%; border: 2px solid var(--borde-campo); color: var(--texto-2); font-weight: 700; font-size: .9rem; }
.pasos .hecho .marca-paso { background: var(--exito); border-color: var(--exito); color: #fff; }
.pasos .texto-paso { flex: 1; min-width: 0; }
.pasos .texto-paso strong { display: block; }
.pasos .texto-paso small { color: var(--texto-3); }
progress.progreso { display: block; width: 100%; height: 10px; margin: .25rem 0 1rem; border: 0; border-radius: 999px; background: var(--acento-suave); overflow: hidden; accent-color: var(--primario); }
progress.progreso::-webkit-progress-bar { background: var(--acento-suave); }
progress.progreso::-webkit-progress-value { background: var(--primario); border-radius: 999px; }
progress.progreso::-moz-progress-bar { background: var(--primario); border-radius: 999px; }

/* ---------------------------------------------------------------- Cáscara de la app */
.app { min-height: 100vh; }
.lateral {
  position: fixed; inset: 0 auto 0 0; z-index: 40; width: var(--ancho-lateral); display: flex; flex-direction: column;
  background: var(--lateral); color: var(--lateral-texto); overflow-y: auto; overscroll-behavior: contain;
}
.lateral .cabeza { display: flex; align-items: center; justify-content: space-between; height: var(--alto-barra); padding: 0 1.1rem; flex: none; }
.lateral .empresa-actual { margin: .25rem .75rem 1rem; padding: .75rem; border-radius: var(--radio-s); background: var(--lateral-activo); }
.lateral .empresa-actual strong { display: block; font-size: .95rem; line-height: 1.3; }
.lateral .empresa-actual small { color: var(--lateral-tenue); }
.lateral .empresa-actual a { display: inline-flex; gap: .3rem; align-items: center; margin-top: .4rem; color: var(--lateral-texto); font-size: .85rem; }
.lateral nav { flex: 1; padding: 0 .6rem 1rem; }
.lateral .grupo { margin: .9rem 0 .3rem; padding: 0 .6rem; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--lateral-tenue); }
.lateral nav a {
  display: flex; align-items: center; gap: .75rem; min-height: 42px; padding: 0 .65rem; margin: 1px 0;
  color: var(--lateral-texto); text-decoration: none; border-radius: var(--radio-s); font-weight: 500;
}
.lateral nav a:hover { background: var(--lateral-activo); }
.lateral nav a[aria-current=page] { background: var(--lateral-activo); box-shadow: inset 3px 0 0 var(--marca); font-weight: 650; }
.lateral nav a .pronto { margin-left: auto; font-size: .68rem; font-weight: 600; color: var(--lateral-tenue); border: 1px solid currentColor; border-radius: 999px; padding: 0 .4rem; }
.lateral .pie { padding: .9rem 1.1rem; border-top: 1px solid var(--lateral-activo); font-size: .9rem; }
.lateral .pie .quien { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lateral .pie form { margin: 0; }
.lateral .pie button { margin-top: .4rem; display: inline-flex; align-items: center; gap: .4rem; padding: 0; min-height: 32px; background: none; border: 0; font: inherit; color: var(--lateral-tenue); cursor: pointer; }
.lateral .pie button:hover { color: var(--lateral-texto); }
.lateral .cerrar-menu { display: none; }

.principal { margin-left: var(--ancho-lateral); min-height: 100vh; display: flex; flex-direction: column; }
.barra-sup {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: .75rem; height: var(--alto-barra);
  padding: 0 1.5rem; background: color-mix(in srgb, var(--superficie) 92%, transparent); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--borde);
}
.barra-sup .titulo-barra { font-weight: 700; font-size: 1.05rem; color: var(--negro); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.barra-sup .abrir-menu { display: none; }
.barra-sup .derecha { margin-left: auto; display: flex; gap: .5rem; align-items: center; }
.contenido { width: 100%; max-width: 1200px; margin: 0 auto; padding: 1.5rem; flex: 1; }
.encabezado { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; }
.encabezado h1 { margin: 0; }
.encabezado p { margin: .25rem 0 0; color: var(--texto-2); }
.migas { font-size: .85rem; color: var(--texto-3); margin-bottom: .3rem; }
.migas a { color: var(--texto-3); }

.tabs-inf { display: none; }
.velo { display: none; }

/* Celular y tableta vertical */
@media (max-width: 900px) {
  .lateral { transform: translateX(-100%); visibility: hidden; transition: transform .2s ease, visibility .2s; box-shadow: var(--sombra-alta); width: min(86vw, 320px); }
  .lateral.abierto { transform: none; visibility: visible; }
  .lateral .cerrar-menu { display: inline-grid; }
  .velo.abierto { display: block; position: fixed; inset: 0; z-index: 35; background: rgb(0 0 0 / .4); }
  .principal { margin-left: 0; padding-bottom: calc(var(--alto-tabs) + env(safe-area-inset-bottom)); }
  .barra-sup { padding: 0 .5rem 0 .25rem; }
  .barra-sup .abrir-menu { display: inline-grid; }
  .contenido { padding: 1rem; }
  h1 { font-size: 1.3rem; }
  .tabs-inf {
    display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; inset: auto 0 0 0; z-index: 30;
    height: calc(var(--alto-tabs) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
    background: var(--superficie); border-top: 1px solid var(--borde);
  }
  .tabs-inf a, .tabs-inf button {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    font: inherit; font-size: .72rem; font-weight: 600; color: var(--texto-2); text-decoration: none; background: none; border: 0; cursor: pointer;
  }
  .tabs-inf [aria-current=page] { color: var(--primario); }
  .tabs-inf .icono { width: 24px; height: 24px; }
}
.boton-icono { display: inline-grid; place-items: center; width: 44px; height: 44px; padding: 0; background: none; border: 0; border-radius: var(--radio-s); color: inherit; cursor: pointer; }
.boton-icono:hover { background: color-mix(in srgb, currentColor 10%, transparent); }

/* Notificación flotante */
.notificacion { position: fixed; z-index: 60; right: 1rem; bottom: 1rem; max-width: min(420px, calc(100vw - 2rem)); box-shadow: var(--sombra-alta); animation: entrar .2s ease; }
.notificacion button { margin-left: auto; background: none; border: 0; color: inherit; cursor: pointer; padding: 0; }
@media (max-width: 900px) { .notificacion { bottom: calc(var(--alto-tabs) + 1rem); left: 1rem; right: 1rem; } }
@keyframes entrar { from { opacity: 0; transform: translateY(8px); } }

/* ---------------------------------------------------------------- Pantallas de acceso */
.acceso { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem 1rem; background:
  radial-gradient(1200px 500px at 0% 0%, color-mix(in srgb, var(--marca) 16%, transparent), transparent 60%),
  radial-gradient(900px 400px at 100% 100%, color-mix(in srgb, var(--lateral) 14%, transparent), transparent 60%), var(--fondo); }
.acceso .caja { width: 100%; max-width: 420px; }
.acceso .logo-completo { margin: 0 0 1.25rem .25rem; }
.acceso .tarjeta { padding: 1.75rem; }
.acceso .tarjeta h1 { font-size: 1.35rem; }
.acceso .pie-acceso { margin-top: 1rem; text-align: center; font-size: .85rem; color: var(--texto-3); }
.acceso details { margin-top: 1.25rem; } .acceso summary { cursor: pointer; color: var(--primario); margin-bottom: .75rem; }
.qr { display: block; margin: .5rem auto 1rem; border: 1px solid var(--borde); border-radius: var(--radio-s); padding: 6px; background: #fff; }
.secreto { font-family: var(--mono); letter-spacing: .05em; word-break: break-all; }
.codigos { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; list-style: none; padding: 0; margin: 0 0 1.25rem; }
.codigos li code { display: block; text-align: center; padding: .5rem; font-size: 1rem; border: 1px dashed var(--borde-campo); background: var(--fondo); }

/* Selector de empresas */
.lista-empresas { list-style: none; padding: 0; margin: 0; display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.lista-empresas a { display: flex; gap: .9rem; align-items: center; padding: 1.1rem; background: var(--superficie); border: 1px solid var(--borde); border-radius: var(--radio); color: inherit; text-decoration: none; box-shadow: var(--sombra); transition: border-color .15s, transform .15s; }
.lista-empresas a:hover { border-color: var(--primario); transform: translateY(-1px); color: inherit; }
.lista-empresas .inicial { display: grid; place-items: center; width: 44px; height: 44px; flex: none; border-radius: var(--radio-s); background: var(--primario-suave); color: var(--primario); font-weight: 800; font-size: 1.1rem; }
.lista-empresas strong { display: block; color: var(--negro); }
.lista-empresas small { color: var(--texto-3); }
.lista-empresas .icono { margin-left: auto; color: var(--texto-3); }
.solo { max-width: 960px; margin: 0 auto; padding: 1.5rem 1rem; }
.barra-simple { display: flex; align-items: center; gap: 1rem; height: var(--alto-barra); padding: 0 1rem; background: var(--superficie); border-bottom: 1px solid var(--borde); }
.barra-simple .derecha { margin-left: auto; display: flex; align-items: center; gap: .75rem; color: var(--texto-2); }
.barra-simple form { margin: 0; }

/* Apariencia: vista previa */
.colores { display: grid; gap: 1rem; margin-bottom: 1.25rem; }
.color-fila { display: flex; gap: .9rem; align-items: center; }
.color-fila .texto-color { flex: 1; }
.color-fila small { display: block; color: var(--texto-3); }
.vista-previa { border: 1px solid var(--borde); border-radius: var(--radio); overflow: hidden; display: grid; grid-template-columns: 150px 1fr; min-height: 230px; background: var(--fondo); }
.vista-previa .vp-lateral { background: var(--lateral); color: var(--lateral-texto); padding: .9rem .6rem; font-size: .85rem; }
.vista-previa .vp-lateral .vp-logo { font-weight: 800; margin: 0 .4rem .8rem; }
.vista-previa .vp-lateral .vp-logo b { color: var(--marca); }
.vista-previa .vp-item { padding: .45rem .5rem; border-radius: 5px; margin-bottom: 2px; }
.vista-previa .vp-item.activo { background: var(--lateral-activo); box-shadow: inset 3px 0 0 var(--marca); }
.vista-previa .vp-item.tenue { color: var(--lateral-tenue); }
.vista-previa .vp-cuerpo { padding: 1rem; display: flex; flex-direction: column; gap: .75rem; align-items: flex-start; }
.vista-previa .vp-cuerpo .kpi { width: 100%; background: var(--superficie); padding: .75rem; border-radius: 8px; }
.notas-contraste { font-size: .85rem; color: var(--texto-3); margin: .75rem 0 0; padding-left: 1.1rem; }

/* Guía de componentes */
.muestra { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }
.paleta { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .75rem; }
.paleta div { border: 1px solid var(--borde); border-radius: var(--radio-s); overflow: hidden; font-size: .8rem; background: var(--superficie); }
.paleta div i { display: block; height: 52px; }
.paleta div span { display: block; padding: .4rem .6rem; }
.c-marca i { background: var(--marca); } .c-primario i { background: var(--primario); } .c-lateral i { background: var(--lateral); }
.c-acento i { background: var(--acento); } .c-negro i { background: var(--negro); } .c-gris i { background: var(--texto-2); }
.c-exito i { background: var(--exito); } .c-peligro i { background: var(--peligro); } .c-aviso i { background: var(--aviso); }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition: none !important; animation: none !important; } }
