/* ELETEK Gestión — estilos del panel.
   Pensado para escritorio (tablas densas) y para el celular a bordo
   (botones grandes, una columna). */

:root {
  --fondo: #f3f5f8;
  --superficie: #ffffff;
  --superficie-2: #f7f9fb;
  --borde: #dde3ea;
  --texto: #1b2733;
  --texto-2: #5b6b7c;
  --primario: #0f5da8;
  --primario-oscuro: #0b4a87;
  --barra: #0f2a44;
  --barra-texto: #e8eef5;
  --rojo: #c62828;       --rojo-suave: #fdecea;
  --naranja: #c25e00;    --naranja-suave: #fff1e0;
  --amarillo: #8a6d00;   --amarillo-suave: #fff8d6;
  --verde: #2e7d32;      --verde-suave: #e8f5e9;
  --azul: #0f5da8;       --azul-suave: #e6f0fa;
  --gris: #5b6b7c;       --gris-suave: #eef1f4;
  --radio: 8px;
  --sombra: 0 1px 2px rgba(16, 38, 60, .06), 0 1px 8px rgba(16, 38, 60, .04);
  --menu-ancho: 232px;
  font-size: 15px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fondo: #0f151c; --superficie: #17202a; --superficie-2: #1c2733; --borde: #2a3746;
    --texto: #e3e9ef; --texto-2: #9aabbc; --primario: #4b9be6; --primario-oscuro: #3a86cf;
    --barra: #0b1a2a; --barra-texto: #e3e9ef;
    --rojo: #ef6c6c; --rojo-suave: #3a1d1d; --naranja: #f0a050; --naranja-suave: #3a2a17;
    --amarillo: #e3c55a; --amarillo-suave: #332c12; --verde: #6cc070; --verde-suave: #1a2f1c;
    --azul: #6aaeea; --azul-suave: #16283a; --gris: #9aabbc; --gris-suave: #222d39;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--fondo); color: var(--texto); line-height: 1.45;
}
a { color: var(--primario); }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.05rem; margin-bottom: .75rem; }
h4 { font-size: .9rem; margin: .75rem 0 .4rem; color: var(--texto-2); }
small, .sub { color: var(--texto-2); }
p { margin: .4rem 0; }

/* ── Marco ─────────────────────────────────────────────────────────── */
.barra {
  position: sticky; top: 0; z-index: 20; height: 54px; display: flex; align-items: center; gap: .9rem;
  padding: 0 1rem; background: var(--barra); color: var(--barra-texto);
}
.barra .marca { display: flex; align-items: center; gap: .5rem; color: inherit; text-decoration: none; }
.logo {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border-radius: 7px;
  background: #1f7ad1; color: #fff; font-weight: 800;
}
.barra .empresa { opacity: .85; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hamburguesa { display: none; color: inherit; }
.usuario { position: relative; }
.usuario summary { cursor: pointer; list-style: none; padding: .35rem .6rem; border-radius: 6px; }
.usuario summary:hover { background: rgba(255, 255, 255, .1); }
.usuario-menu {
  position: absolute; right: 0; top: 110%; min-width: 220px; background: var(--superficie); color: var(--texto);
  border: 1px solid var(--borde); border-radius: var(--radio); box-shadow: var(--sombra); padding: .75rem;
  display: flex; flex-direction: column; gap: .5rem;
}
.cuerpo { display: flex; min-height: calc(100vh - 54px); }
.menu {
  width: var(--menu-ancho); flex-shrink: 0; background: var(--superficie); border-right: 1px solid var(--borde);
  padding: .75rem .5rem; position: sticky; top: 54px; height: calc(100vh - 54px); overflow-y: auto;
}
.menu a {
  display: flex; align-items: center; gap: .6rem; padding: .55rem .7rem; border-radius: 6px;
  color: var(--texto); text-decoration: none; font-size: .95rem;
}
.menu a:hover { background: var(--superficie-2); }
.menu a.activo { background: var(--azul-suave); color: var(--primario); font-weight: 600; }
.menu .icono { width: 1.3rem; text-align: center; }
main { flex: 1; min-width: 0; outline: none; }
.pagina { padding: 1.25rem 1.5rem 3rem; max-width: 1400px; }

/* ── Encabezados y bloques ─────────────────────────────────────────── */
.cabecera { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.cabecera .sub { margin: .2rem 0 0; }
.volver { display: inline-block; font-size: .85rem; margin-bottom: .3rem; text-decoration: none; }
.acciones, .acciones-fila, .botones-fila { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.acciones-fila { margin: .75rem 0; }
.botones-fila { justify-content: flex-end; }
.tarjeta {
  background: var(--superficie); border: 1px solid var(--borde); border-radius: var(--radio);
  padding: 1rem; margin-bottom: 1rem; box-shadow: var(--sombra);
}
.tarjeta.error { color: var(--rojo); }
.filtros { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; margin-bottom: .75rem; }
.filtros select { width: auto; }
.ayuda-caja { background: var(--azul-suave); border-radius: var(--radio); padding: .75rem 1rem; margin-bottom: 1rem; font-size: .92rem; }
.cargando { padding: 2rem; color: var(--texto-2); }
.vacio { color: var(--texto-2); text-align: center; padding: 1.25rem; }

.cifras { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.cifra {
  background: var(--superficie); border: 1px solid var(--borde); border-left: 4px solid var(--borde);
  border-radius: var(--radio); padding: .8rem 1rem; text-decoration: none; color: var(--texto); box-shadow: var(--sombra);
}
.cifra strong { display: block; font-size: 1.6rem; font-variant-numeric: tabular-nums; }
.cifra span { color: var(--texto-2); font-size: .88rem; }
.cifra.rojo { border-left-color: var(--rojo); } .cifra.rojo strong { color: var(--rojo); }
.cifra.naranja { border-left-color: var(--naranja); } .cifra.naranja strong { color: var(--naranja); }
.cifra.amarillo { border-left-color: var(--amarillo); }
.cifra.verde { border-left-color: var(--verde); }

.datos { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .6rem; margin-bottom: 1rem; }
.dato { background: var(--superficie); border: 1px solid var(--borde); border-radius: var(--radio); padding: .6rem .8rem; }
.dato span { display: block; font-size: .8rem; color: var(--texto-2); }
.dato strong { font-weight: 600; }
.tarjeta .datos .dato { background: var(--superficie-2); }

/* ── Insignias ─────────────────────────────────────────────────────── */
.insignia { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.insignia.rojo { background: var(--rojo-suave); color: var(--rojo); }
.insignia.naranja { background: var(--naranja-suave); color: var(--naranja); }
.insignia.amarillo { background: var(--amarillo-suave); color: var(--amarillo); }
.insignia.verde { background: var(--verde-suave); color: var(--verde); }
.insignia.azul { background: var(--azul-suave); color: var(--azul); }
.insignia.gris { background: var(--gris-suave); color: var(--gris); }
.texto-rojo { color: var(--rojo); font-weight: 600; }
.texto-largo { white-space: pre-wrap; }

/* ── Botones ───────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .5rem .9rem; border-radius: 6px; border: 1px solid var(--borde); background: var(--superficie);
  color: var(--texto); font: inherit; font-size: .92rem; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--superficie-2); }
.btn:disabled { opacity: .55; cursor: wait; }
.btn.primario { background: var(--primario); border-color: var(--primario); color: #fff; }
.btn.primario:hover { background: var(--primario-oscuro); }
.btn.peligro { color: var(--rojo); border-color: var(--rojo); }
.btn.chico { padding: .25rem .6rem; font-size: .84rem; }
.btn.grande { padding: .85rem 1.4rem; font-size: 1.05rem; }
.btn.ancho { width: 100%; }
.btn-icono { background: none; border: none; font-size: 1.3rem; line-height: 1; cursor: pointer; color: var(--texto-2); padding: .25rem .4rem; border-radius: 6px; }
.btn-icono:hover { background: var(--superficie-2); }
.barra .btn { background: transparent; color: var(--barra-texto); border-color: rgba(255, 255, 255, .3); }

/* ── Tablas ────────────────────────────────────────────────────────── */
.tabla-caja { overflow-x: auto; }
.tabla { width: 100%; border-collapse: collapse; font-size: .92rem; }
.tabla th, .tabla td { padding: .5rem .6rem; text-align: left; border-bottom: 1px solid var(--borde); vertical-align: middle; }
.tabla th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--texto-2); font-weight: 600; background: var(--superficie-2); }
.tabla .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tabla td[data-titulo="Código"], .tabla td[data-titulo="Cada"], .tabla td[data-titulo="N°"] { white-space: nowrap; }
.tabla tr.clic { cursor: pointer; }
.tabla tr.clic:hover td, .tabla tr.clic:focus td { background: var(--azul-suave); }
.tabla tr.alerta td { background: var(--naranja-suave); }
.buscador { margin-bottom: .6rem; max-width: 320px; }
.matriz td { vertical-align: top; }
.permiso { display: block; padding: .15rem 0; cursor: pointer; }

/* ── Formularios ───────────────────────────────────────────────────── */
input, select, textarea {
  width: 100%; padding: .5rem .6rem; border: 1px solid var(--borde); border-radius: 6px;
  font: inherit; background: var(--superficie); color: var(--texto);
}
input:focus, select:focus, textarea:focus, .btn:focus-visible, a:focus-visible { outline: 2px solid var(--primario); outline-offset: 1px; }
input[type="checkbox"] { width: auto; }
.form { display: flex; flex-wrap: wrap; gap: .75rem; }
.campo { flex: 1 1 100%; display: flex; flex-direction: column; gap: .25rem; margin-bottom: .1rem; }
.campo.medio { flex: 1 1 calc(50% - .75rem); min-width: 200px; }
.campo.tercio { flex: 1 1 calc(33% - .75rem); min-width: 150px; }
.campo label { font-size: .88rem; font-weight: 600; }
.campo small { font-size: .8rem; }
.campo.check { flex-direction: row; align-items: center; gap: .5rem; flex-wrap: wrap; cursor: pointer; }
.campo.check span { font-weight: 500; }
.campo.check small { flex-basis: 100%; padding-left: 1.6rem; }
.req { color: var(--rojo); }
.form-seccion { flex-basis: 100%; margin-top: .75rem; padding-top: .5rem; border-top: 1px solid var(--borde); }
.check-inline { display: inline-flex; align-items: center; gap: .3rem; }
.items { display: flex; flex-direction: column; gap: .4rem; margin-bottom: .5rem; }
.item { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }
.item > input:first-child, .item .crece { flex: 1 1 260px; }
.item input.corto { width: 110px; flex: 0 0 110px; }
.item .unidad { min-width: 2.5rem; color: var(--texto-2); font-size: .88rem; }
.item .info-exist { flex-basis: 100%; }
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .6rem; }
.chip { display: inline-flex; align-items: center; gap: .2rem; background: var(--gris-suave); border-radius: 999px; padding: .1rem .2rem .1rem .7rem; font-size: .88rem; }
.chip .btn-icono { font-size: 1rem; }

/* ── Pestañas ──────────────────────────────────────────────────────── */
.pestanas { display: flex; gap: .25rem; flex-wrap: wrap; border-bottom: 1px solid var(--borde); flex: 1 1 100%; }
.pestana {
  border: none; background: none; font: inherit; padding: .55rem .9rem; cursor: pointer; color: var(--texto-2);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.pestana.activa { color: var(--primario); border-bottom-color: var(--primario); font-weight: 600; }

/* ── Modal ─────────────────────────────────────────────────────────── */
.modal-fondo { position: fixed; inset: 0; background: rgba(10, 20, 30, .45); display: grid; place-items: center; z-index: 50; padding: 1rem; }
.modal {
  background: var(--superficie); border-radius: 10px; width: 100%; max-width: 520px; max-height: calc(100vh - 2rem);
  display: flex; flex-direction: column; box-shadow: 0 10px 40px rgba(0, 0, 0, .25);
}
.modal.ancho { max-width: 820px; }
.modal-cab { display: flex; justify-content: space-between; align-items: center; padding: .9rem 1.1rem; border-bottom: 1px solid var(--borde); }
.modal-cab h3 { font-size: 1.05rem; }
.modal-cuerpo { padding: 1rem 1.1rem; overflow-y: auto; }
.modal-pie { display: flex; justify-content: flex-end; gap: .5rem; padding: .8rem 1.1rem; border-top: 1px solid var(--borde); }
.modal-pie .peligro { margin-right: auto; }

/* ── Avisos ────────────────────────────────────────────────────────── */
#avisos { position: fixed; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 60; max-width: min(420px, calc(100vw - 2rem)); }
.aviso { background: var(--verde); color: #fff; padding: .7rem 1rem; border-radius: 8px; box-shadow: var(--sombra); transition: opacity .4s; }
.aviso.error { background: var(--rojo); }
.aviso.saliendo { opacity: 0; }

/* ── Login ─────────────────────────────────────────────────────────── */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; background: linear-gradient(160deg, #0f2a44, #16426b); }
.login-caja { background: var(--superficie); padding: 2rem; border-radius: 12px; width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 1rem; box-shadow: 0 20px 50px rgba(0, 0, 0, .3); }
.login-caja .marca { display: flex; align-items: center; gap: .7rem; margin-bottom: .5rem; }
.login-caja .marca span:last-child { display: block; color: var(--texto-2); font-size: .9rem; }
.error-login { color: var(--rojo); min-height: 1.2em; margin: 0; }

/* ── A bordo (celular) ─────────────────────────────────────────────── */
.accesos { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.acceso {
  display: flex; align-items: center; gap: .75rem; padding: 1.1rem; border-radius: 10px; background: var(--superficie);
  border: 1px solid var(--borde); color: var(--texto); text-decoration: none; font-weight: 600; box-shadow: var(--sombra);
}
.acceso span { font-size: 1.5rem; }
.acceso:hover { border-color: var(--primario); }
.lance-activo { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; background: var(--azul-suave); border-radius: 10px; padding: 1rem; margin-bottom: 1rem; }
.lance-activo small { display: block; }
.lista-simple { margin: 0; padding-left: 1.1rem; }
.lista-simple li { padding: .2rem 0; }
.lista-horometros { display: flex; flex-direction: column; gap: .6rem; }
.horometro { display: flex; align-items: center; gap: .75rem; justify-content: space-between; padding: .5rem 0; border-bottom: 1px solid var(--borde); }
.horometro span { display: flex; flex-direction: column; }
.horometro input { max-width: 150px; font-size: 1.1rem; }

/* ── Documento imprimible (orden de compra, parte) ─────────────────── */
.hoja { background: #fff; color: #111; max-width: 900px; padding: 2rem; border: 1px solid var(--borde); border-radius: var(--radio); }
.hoja-cab { display: flex; justify-content: space-between; border-bottom: 2px solid #111; padding-bottom: .75rem; margin-bottom: 1rem; }
.hoja-cab .derecha { text-align: right; }
.hoja-datos { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem 1.5rem; margin-bottom: 1rem; }
.hoja h3 { margin: 1rem 0 .5rem; }
.hoja-tabla th { background: #eee; color: #111; }
.hoja-tabla th, .hoja-tabla td { border: 1px solid #bbb; }
.firmas { display: flex; gap: 3rem; margin-top: 3rem; }
.firmas div { border-top: 1px solid #111; padding-top: .3rem; min-width: 220px; }

@media print {
  .barra, .menu, .no-imprimir, #avisos { display: none !important; }
  body, .pagina { background: #fff; padding: 0; }
  .hoja { border: none; padding: 0; max-width: none; }
}

/* ── Celular ───────────────────────────────────────────────────────── */
@media (max-width: 860px) {
  .hamburguesa { display: inline-block; }
  .barra .empresa { font-size: .85rem; }
  .menu {
    position: fixed; left: 0; top: 54px; z-index: 30; transform: translateX(-100%); transition: transform .2s;
    box-shadow: 4px 0 20px rgba(0, 0, 0, .15);
  }
  body.menu-abierto .menu { transform: none; }
  .pagina { padding: 1rem 1rem 3rem; }
  h1 { font-size: 1.25rem; }
  /* Tablas como tarjetas apiladas: cada celda con su título */
  .tabla thead { display: none; }
  .tabla, .tabla tbody, .tabla tr, .tabla td { display: block; width: 100%; }
  .tabla tr { border: 1px solid var(--borde); border-radius: var(--radio); margin-bottom: .5rem; padding: .35rem .2rem; background: var(--superficie); }
  .tabla td { border: none; padding: .2rem .6rem; display: flex; justify-content: space-between; gap: 1rem; text-align: right; }
  .tabla td::before { content: attr(data-titulo); color: var(--texto-2); font-size: .8rem; text-align: left; }
  .tabla td[data-titulo=""]::before { content: none; }
  .tabla td.vacio { justify-content: center; }
  .tabla td.vacio::before { content: none; }
  .hoja-tabla thead { display: table-header-group; }
  .campo.medio, .campo.tercio { flex-basis: 100%; }
  .a-bordo .btn { padding: .75rem 1rem; font-size: 1rem; }
  .a-bordo input, .a-bordo select, .a-bordo textarea { font-size: 16px; padding: .7rem; }
  .modal-fondo { padding: 0; align-items: end; }
  .modal { max-height: 92vh; border-radius: 14px 14px 0 0; }
  .hoja-datos { grid-template-columns: 1fr; }
}
