/* Gestión — estilos de la aplicación */
:root {
  --g-sidebar: 248px;
  --g-sidebar-mini: 64px;
  --g-topbar: 56px;
  --g-primario: #1f5fbf;
  --g-primario-suave: #e8f0fc;
  --g-fondo: #f4f6fa;
  --g-borde: #dfe3ea;
  --g-texto-suave: #6b7280;
  --g-sidebar-bg: #16213a;
  --g-sidebar-texto: #c7d0e0;
  --g-sidebar-activo: #2b3b5e;
}
[data-bs-theme="dark"] {
  --g-fondo: #0f1420;
  --g-borde: #2a3245;
  --g-primario-suave: #1b2a45;
  --g-texto-suave: #9aa4b5;
  --g-sidebar-bg: #0b111c;
}

html, body { height: 100%; }
body { background: var(--g-fondo); font-size: .925rem; }

/* --- Estructura --- */
.g-topbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--g-topbar); z-index: 1030;
  display: flex; align-items: center; gap: .75rem; padding: 0 1rem;
  background: var(--bs-body-bg); border-bottom: 1px solid var(--g-borde);
}
.g-marca { font-weight: 700; color: var(--g-primario); text-decoration: none; white-space: nowrap; }
.g-marca small { font-weight: 500; color: var(--g-texto-suave); }
.g-busqueda { position: relative; flex: 1; max-width: 560px; }
.g-busqueda .form-control { padding-left: 2.2rem; background: var(--g-fondo); border-color: transparent; }
.g-busqueda .form-control:focus { background: var(--bs-body-bg); border-color: var(--g-primario); }
.g-busqueda > .bi-search { position: absolute; left: .75rem; top: 50%; transform: translateY(-50%); color: var(--g-texto-suave); }
.g-busqueda kbd { position: absolute; right: .5rem; top: 50%; transform: translateY(-50%); font-size: .7rem; opacity: .6; }
.g-resultados {
  position: absolute; top: 110%; left: 0; right: 0; max-height: 70vh; overflow-y: auto; z-index: 1050;
  background: var(--bs-body-bg); border: 1px solid var(--g-borde); border-radius: .5rem; box-shadow: 0 10px 30px rgba(0,0,0,.15);
}
.g-resultados:empty { display: none; }
.g-resultados .grupo { padding: .4rem .9rem; font-size: .75rem; text-transform: uppercase; color: var(--g-texto-suave); background: var(--g-fondo); }
.g-resultados a { display: block; padding: .45rem .9rem; color: inherit; text-decoration: none; }
.g-resultados a:hover, .g-resultados a.activo { background: var(--g-primario-suave); }

.g-sidebar {
  position: fixed; top: var(--g-topbar); bottom: 0; left: 0; width: var(--g-sidebar); z-index: 1020;
  background: var(--g-sidebar-bg); color: var(--g-sidebar-texto); overflow-y: auto; transition: width .15s;
  padding: .5rem 0 2rem;
}
.g-sidebar a, .g-sidebar button {
  display: flex; align-items: center; gap: .65rem; width: 100%; padding: .45rem 1rem; border: 0; background: none;
  color: var(--g-sidebar-texto); text-decoration: none; text-align: left; font-size: .9rem; white-space: nowrap;
}
.g-sidebar a:hover, .g-sidebar button:hover { background: var(--g-sidebar-activo); color: #fff; }
.g-sidebar a.activo { background: var(--g-primario); color: #fff; }
.g-sidebar .bi { font-size: 1.05rem; width: 1.2rem; text-align: center; flex-shrink: 0; }
.g-sidebar .submenu a { padding-left: 2.8rem; font-size: .86rem; }
.g-sidebar .submenu .submenu a { padding-left: 3.8rem; }
.g-sidebar .carpeta .chevron { margin-left: auto; transition: transform .15s; font-size: .75rem; }
.g-sidebar .carpeta[aria-expanded="true"] .chevron { transform: rotate(90deg); }

.g-contenido { margin-left: var(--g-sidebar); padding: calc(var(--g-topbar) + 1rem) 1.25rem 3rem; transition: margin .15s; min-height: 100%; }

body.menu-mini .g-sidebar { width: var(--g-sidebar-mini); }
body.menu-mini .g-sidebar .texto, body.menu-mini .g-sidebar .chevron, body.menu-mini .g-sidebar .submenu { display: none !important; }
body.menu-mini .g-contenido { margin-left: var(--g-sidebar-mini); }

@media (max-width: 991.98px) {
  .g-sidebar { transform: translateX(-100%); transition: transform .2s; width: var(--g-sidebar); }
  body.menu-abierto .g-sidebar { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.4); }
  .g-contenido, body.menu-mini .g-contenido { margin-left: 0; padding-left: .75rem; padding-right: .75rem; }
  .g-busqueda kbd { display: none; }
}

/* --- Cabecera de página y barra de acciones --- */
.g-cabecera {
  display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; margin-bottom: 1rem;
  position: sticky; top: var(--g-topbar); z-index: 1010; background: var(--g-fondo); padding: .5rem 0;
}
.g-cabecera h1 { font-size: 1.35rem; margin: 0; font-weight: 600; }
.g-cabecera .subtitulo { color: var(--g-texto-suave); font-size: .85rem; }
.g-cabecera .acciones { margin-left: auto; display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }

.g-tarjeta { background: var(--bs-body-bg); border: 1px solid var(--g-borde); border-radius: .6rem; }
.g-tarjeta > .titulo { padding: .6rem 1rem; border-bottom: 1px solid var(--g-borde); font-weight: 600; font-size: .9rem; display: flex; align-items: center; gap: .5rem; }
.g-tarjeta > .cuerpo { padding: 1rem; }

/* --- Formularios --- */
.form-label { font-size: .78rem; color: var(--g-texto-suave); margin-bottom: .2rem; font-weight: 500; }
.form-control:disabled, .form-select:disabled { background-color: var(--g-fondo); opacity: 1; }
.campo-obligatorio .form-label::after { content: " *"; color: var(--bs-danger); }
.errorlist { list-style: none; padding: 0; margin: .2rem 0 0; color: var(--bs-danger); font-size: .8rem; }
.campo-error .form-control, .campo-error .form-select { border-color: var(--bs-danger); }
.form-check-input + .form-label { margin-left: .35rem; }
.g-check { display: flex; align-items: center; gap: .4rem; padding-top: 1.55rem; }
.g-check .form-label { margin: 0; font-size: .875rem; color: inherit; }

/* --- Tablas --- */
.g-tabla { margin: 0; }
.g-tabla thead th { position: sticky; top: 0; background: var(--bs-body-bg); font-size: .78rem; text-transform: uppercase; letter-spacing: .02em; color: var(--g-texto-suave); white-space: nowrap; border-bottom-width: 1px; }
.g-tabla thead th a { color: inherit; text-decoration: none; }
.g-tabla tbody tr { cursor: pointer; }
.g-tabla tbody tr:hover { background: var(--g-primario-suave); }
.g-tabla td.num, .g-tabla th.num { text-align: right; font-variant-numeric: tabular-nums; }
.g-tabla tfoot td { font-weight: 600; background: var(--g-fondo); }
.g-tabla-contenedor { overflow: auto; max-height: calc(100vh - 230px); }

/* Rejillas de líneas editables */
.g-rejilla td { padding: .2rem .25rem; vertical-align: middle; }
.g-rejilla .form-control-sm, .g-rejilla .form-select-sm { min-width: 70px; }
.g-rejilla tr.borrada { opacity: .4; text-decoration: line-through; }
.g-rejilla .ts-wrapper { min-width: 220px; }

/* Resumen / totales */
.g-resumen { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .6rem; margin-bottom: 1rem; }
.g-resumen .item { background: var(--bs-body-bg); border: 1px solid var(--g-borde); border-radius: .5rem; padding: .5rem .8rem; }
.g-resumen .item .etiqueta { font-size: .72rem; text-transform: uppercase; color: var(--g-texto-suave); }
.g-resumen .item .valor { font-size: 1.15rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.g-resumen .item.destacado { background: var(--g-primario); color: #fff; border-color: var(--g-primario); }
.g-resumen .item.destacado .etiqueta { color: rgba(255,255,255,.8); }

/* Indicadores del panel */
.g-indicador { display: block; text-decoration: none; color: inherit; padding: 1rem; border-radius: .6rem; background: var(--bs-body-bg); border: 1px solid var(--g-borde); border-left: 4px solid var(--bs-success); }
.g-indicador .valor { font-size: 1.8rem; font-weight: 700; }
.g-indicador.aviso { border-left-color: var(--bs-warning); }
.g-indicador.alarma { border-left-color: var(--bs-danger); }
.g-indicador:hover { box-shadow: 0 4px 14px rgba(0,0,0,.08); }

/* Diseñador */
.dz-seccion { border: 1px dashed var(--g-borde); border-radius: .5rem; padding: .5rem; margin-bottom: 1rem; background: var(--bs-body-bg); }
.dz-seccion > .dz-titulo { font-weight: 600; display: flex; align-items: center; gap: .5rem; margin-bottom: .4rem; }
.dz-campos { display: flex; flex-wrap: wrap; gap: .4rem; min-height: 44px; }
.dz-campo { border: 1px solid var(--g-borde); border-radius: .4rem; padding: .35rem .5rem; background: var(--g-fondo); cursor: grab; font-size: .82rem; display: flex; align-items: center; gap: .35rem; }
.dz-campo.oculto { opacity: .45; text-decoration: line-through; }
.dz-campo.seleccionado { outline: 2px solid var(--g-primario); }
.dz-campo .bi-lock { color: var(--bs-warning); }

/* Kiosco */
.kiosco { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; background: var(--g-sidebar-bg); color: #fff; padding: 2rem; }
.kiosco .reloj { font-size: 4rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.kiosco input { font-size: 2rem; text-align: center; max-width: 420px; }
.kiosco .mensaje { font-size: 1.5rem; min-height: 4rem; margin-top: 1.5rem; }

/* TPV */
.tpv-total { font-size: 2.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* Impresión */
@media print {
  .g-topbar, .g-sidebar, .g-cabecera .acciones, .no-imprimir { display: none !important; }
  .g-contenido { margin: 0; padding: 0; }
}

.cursor-pointer { cursor: pointer; }
.texto-suave { color: var(--g-texto-suave); }
.htmx-indicator { opacity: 0; transition: opacity .2s; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }
