:root {
  --azul: #1a56ff;
  --azul-osc: #0a1030;
  --azul-hover: #0d3fd6;
  --azul-clr: #eef2ff;
  --borde: #dde3ef;
  --borde-input: #c9d1e3;
  --linea: #e4e8f1;
  --texto: #141a2b;
  --gris: #5a6480;
  --rojo: #a3261a;
  --verde: #0f6b3a;
  --fondo: #eef1f6;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  color: var(--texto);
  background: var(--fondo);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: "Space Grotesk", "IBM Plex Sans", sans-serif; }

/* Login */
.login-body { background: linear-gradient(160deg, var(--azul-osc) 0 38%, var(--fondo) 38% 100%); }
.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; }
.login-card {
  background: #fff; padding: 2rem; border-radius: 14px; width: 100%; max-width: 360px;
  border: 1px solid var(--borde); box-shadow: 0 20px 48px -20px rgba(10,16,48,.35);
  display: flex; flex-direction: column; gap: .4rem;
}
.login-logo { width: 88px; height: 88px; object-fit: contain; align-self: center; margin-bottom: .6rem; }
.login-card h1 { margin: 0; color: var(--azul-osc); font-size: 1.4rem; text-align: center; }
.login-sub { text-align: center; font-size: .7rem; letter-spacing: .12em; text-transform: uppercase; color: var(--gris); margin-bottom: 1rem; }
.login-card label { font-size: .75rem; font-weight: 600; color: #3a4460; margin-top: .5rem; }
.login-card input {
  height: 44px; padding: 0 .75rem; border: 1px solid var(--borde-input); border-radius: 8px; font: inherit; font-size: .9rem;
}
.login-card input:focus { outline: none; border-color: var(--azul); box-shadow: 0 0 0 3px rgba(26,86,255,.15); }
.login-card button { margin-top: 1rem; height: 44px; font-size: .9rem; font-weight: 600; }
.error { color: var(--rojo); font-size: .85rem; margin-top: .5rem; }

/* Layout general: menú lateral + contenido */
.layout { display: flex; min-height: 100vh; }
.side {
  width: 248px; flex-shrink: 0;
  background: var(--azul-osc); color: #e6eaf5;
  display: flex; flex-direction: column; gap: 28px;
  padding: 28px 18px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.marca { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 14px; padding: 4px 8px 0; }
.marca .logo {
  width: 120px; height: 120px; object-fit: contain; border-radius: 18px; background: #fff; padding: 8px;
  box-shadow: 0 8px 24px -10px rgba(0,0,0,.5);
}
.marca-texto { display: flex; flex-direction: column; align-items: center; gap: 2px; }
.marca h1 { margin: 0; font-size: 18px; font-weight: 700; color: #fff; }
.marca-texto span { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: #9aa6c9; }

.tabs { display: flex; flex-direction: column; gap: 4px; }
.tabs button {
  font: inherit; font-size: 14px; text-align: left;
  min-height: 44px; padding: 0 12px; border: none; border-radius: 8px;
  background: transparent; color: #d4dbef; cursor: pointer;
  transition: background .15s, color .15s;
}
.tabs button:hover { background: rgba(255,255,255,.07); color: #fff; }
.tabs button.activo { background: var(--azul); color: #fff; font-weight: 600; }

.topbar-usuario { margin-top: auto; display: flex; flex-direction: column; gap: 6px; padding: 0 8px; font-size: 12px; color: #9aa6c9; }
.topbar-usuario #nombre-usuario { color: #e6eaf5; font-weight: 600; font-size: 13px; }
.topbar-usuario a { color: #c7d2ff; font-size: 13px; text-decoration: none; }
.topbar-usuario a:hover { text-decoration: underline; }
.topbar-usuario .credito { margin-top: 10px; }
.topbar-usuario .credito strong { color: #c7d2ff; }

.contenido { flex-grow: 1; min-width: 0; padding: 28px 40px 60px; }
.subtabs { display: flex; flex-wrap: wrap; gap: 6px; max-width: 1600px; margin: 0 auto 20px; }
.subtabs button {
  font: inherit; font-size: 14px; font-weight: 500; height: 38px; padding: 0 16px; border-radius: 999px;
  border: 1px solid var(--borde); background: #fff; color: var(--gris); cursor: pointer;
}
.subtabs button.activo { background: var(--azul-osc); border-color: var(--azul-osc); color: #fff; font-weight: 600; }
.subtabs button:hover:not(.activo) { color: var(--texto); border-color: var(--borde-input); background: #fff; }

main { max-width: 1600px; margin: 0 auto; }

.card {
  background: #fff; border: 1px solid var(--borde); border-radius: 12px;
  padding: 1.4rem 1.5rem; margin-bottom: 1.2rem;
}
.card h2 { margin: 0 0 1rem; font-size: 1.2rem; font-weight: 700; color: var(--azul-osc); }

label { display: block; font-size: .75rem; font-weight: 600; color: #3a4460; margin: .7rem 0 .3rem; }
label.check { display: flex; align-items: center; gap: .4rem; font-size: .9rem; font-weight: 400; color: var(--texto); }
label.check input { margin: 0; }
.nota { font-weight: normal; color: var(--gris); font-size: .8rem; }
.nota-ean { color: var(--rojo); font-size: .8rem; margin-top: .25rem; }
.bloque-ajuste { margin-top: .8rem; padding: .7rem .8rem; border: 1px solid var(--rojo); border-radius: 8px; }
.nota-ajuste { color: var(--rojo); font-size: .85rem; margin-bottom: .4rem; }

input[type="text"], input[type="date"], input[type="number"], input[type="password"], input:not([type]), textarea, select {
  width: 100%; height: 42px; padding: 0 .75rem; border: 1px solid var(--borde-input); border-radius: 8px;
  font: inherit; font-size: .9rem; color: var(--texto); background: #fff;
}
textarea { min-height: 4rem; height: auto; padding: .6rem .75rem; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--azul); box-shadow: 0 0 0 3px rgba(26,86,255,.15); }

.fila-cliente { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .8rem; }

.autocomplete { position: relative; }
.autocomplete-lista {
  position: absolute; z-index: 10; background: #fff; border: 1px solid var(--borde);
  border-radius: 8px; width: 100%; max-height: 240px; overflow-y: auto; box-shadow: 0 12px 28px -12px rgba(10,16,48,.3);
}
.autocomplete-lista div { padding: .55rem .75rem; cursor: pointer; font-size: .9rem; }
.autocomplete-lista div:hover { background: var(--azul-clr); }

.factura-lookup { position: relative; margin-top: .8rem; }
.factura-lookup .factura-elegida { margin-top: .4rem; }
.factura-referencia { margin-top: .6rem; }
.factura-referencia table.tabla { font-size: .85rem; }
.btn-copiar-factura { margin: .4rem 0; }

.lineas-header {
  display: flex; align-items: center; justify-content: space-between; margin-top: 1.2rem;
}
.linea {
  border: 1px solid var(--borde); border-radius: 10px; padding: .8rem; margin-bottom: .6rem; background: #f7f9fc;
}
.linea-grid { display: grid; grid-template-columns: 2fr 1fr auto; gap: .6rem; align-items: start; }
.linea-combo {
  margin-top: .5rem; font-size: .85rem; color: var(--azul-osc); background: var(--azul-clr);
  border-radius: 8px; padding: .5rem .7rem;
}
.linea-combo ul { margin: .3rem 0 0; padding-left: 1.1rem; }
.linea-quitar { background: none !important; border: none !important; color: var(--rojo) !important; cursor: pointer; font-size: 1.3rem; height: auto !important; padding: .2rem .4rem !important; }

button {
  height: 42px; padding: 0 1.1rem; border: 1px solid var(--azul); background: var(--azul); color: #fff;
  border-radius: 8px; cursor: pointer; font: inherit; font-size: .9rem; font-weight: 600;
  transition: background .15s, transform .1s;
}
button:hover { background: var(--azul-hover); border-color: var(--azul-hover); }
button:active { transform: translateY(1px); }
button.secundario { background: #fff; color: var(--azul); border-color: var(--borde-input); }
button.secundario:hover { background: var(--azul-clr); border-color: var(--azul); }

.form-acciones { display: flex; gap: .6rem; margin-top: 1.2rem; }

.tabla-toolbar { display: flex; flex-wrap: wrap; gap: .6rem; align-items: end; margin-bottom: .8rem; }
.tabla-toolbar > div { min-width: 140px; }
.tabla-toolbar label { margin-top: 0; }
.tabla-toolbar button { margin-left: auto; }
.tabla-toolbar button + button { margin-left: 0; }

.dep-grupo-titulo { margin: 1.2rem 0 .4rem; font-size: 1rem; color: var(--azul-osc); }
.dep-grupo-titulo:first-child { margin-top: 0; }

.tabla-scroll { overflow-x: auto; }
table.tabla { width: 100%; border-collapse: collapse; font-size: .88rem; }
table.tabla th, table.tabla td { padding: .6rem .75rem; border-bottom: 1px solid var(--linea); text-align: left; }
table.tabla th {
  color: var(--gris); font-weight: 600; font-size: .7rem; letter-spacing: .06em; text-transform: uppercase;
  background: #f4f6fb; white-space: nowrap;
}
table.tabla tbody tr:hover td { background: #fafbff; }
table.tabla td.acciones { white-space: nowrap; }
table.tabla td.acciones button { height: 34px; padding: 0 .7rem; font-size: .8rem; margin-right: .3rem; }

.msg { font-size: .85rem; margin-top: .6rem; }
.msg.ok { color: var(--verde); }
.msg.error { color: var(--rojo); }

.permisos-grupos { display: flex; flex-wrap: wrap; gap: .6rem; margin-top: .6rem; }
.permisos-grupos fieldset, dialog.permisos-dialog fieldset {
  border: 1px solid var(--borde); border-radius: 8px; padding: .5rem .8rem; margin: 0;
}
.permisos-grupos legend, dialog.permisos-dialog legend {
  padding: 0 .4rem; font-weight: 600; font-size: .7rem; letter-spacing: .06em; text-transform: uppercase; color: var(--gris);
}
.permisos-grupos label, dialog.permisos-dialog label {
  display: flex; align-items: center; gap: .4rem; font-size: .85rem; font-weight: 400; padding: .2rem 0;
  white-space: nowrap; margin: 0; color: var(--texto);
}
dialog.permisos-dialog {
  border: 1px solid var(--borde); border-radius: 12px; padding: 1.4rem;
  max-width: 420px; width: 90%; background: #fff; color: var(--texto);
}
dialog.permisos-dialog::backdrop { background: rgba(10,16,48,.45); }
dialog.permisos-dialog h2 { margin: 0 0 .8rem; font-size: 1.1rem; color: var(--azul-osc); }
dialog.permisos-dialog .permisos-grupos { flex-direction: column; }
.permisos-dialog-acciones { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1rem; }

footer { text-align: center; color: var(--gris); font-size: .75rem; padding: 1.5rem; }
footer strong { color: var(--texto); font-weight: 600; }

@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .side { width: auto; height: auto; position: static; gap: 14px; padding: 16px; }
  .marca { flex-direction: row; text-align: left; gap: 12px; padding: 0; }
  .marca .logo { width: 48px; height: 48px; border-radius: 10px; padding: 3px; }
  .marca-texto { align-items: flex-start; }
  .tabs { flex-direction: row; flex-wrap: wrap; }
  .topbar-usuario { flex-direction: row; flex-wrap: wrap; gap: 12px; }
  .topbar-usuario .credito { display: none; }
  .contenido { padding: 20px 16px 40px; }
  .linea-grid { grid-template-columns: 1fr 1fr auto; }
}

[hidden] { display: none !important; }
