/* RV Bodega — tokens de color (paleta validada, claro/oscuro) */
:root {
  color-scheme: light;
  --page:           #f9f9f7;
  --surface-1:      #fcfcfb;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --grid:           #e1e0d9;
  --baseline:       #c3c2b7;
  --border:         rgba(11, 11, 11, 0.10);
  --series-1:       #2a78d6;   /* barras del gráfico */
  --status-good:    #006300;   /* texto de éxito (claro) */
  --status-good-bg: rgba(12, 163, 12, 0.12);
  --status-warn:    #8a5a00;
  --status-warn-bg: rgba(250, 178, 25, 0.16);
  --status-crit:    #d03b3b;
  --status-crit-bg: rgba(208, 59, 59, 0.10);
  --series-out:     #e0a021;   /* tramo fuera de bodega en las barras */
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page:           #0d0d0d;
    --surface-1:      #1a1a19;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --grid:           #2c2c2a;
    --baseline:       #383835;
    --border:         rgba(255, 255, 255, 0.10);
    --series-1:       #3987e5;
    --status-good:    #0ca30c;
    --status-good-bg: rgba(12, 163, 12, 0.18);
    --status-warn:    #fab219;
    --status-warn-bg: rgba(250, 178, 25, 0.14);
    --status-crit:    #e66767;
    --status-crit-bg: rgba(208, 59, 59, 0.20);
    --series-out:     #fab219;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.5;
}

/* ---- barra superior ---- */
.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 10px 24px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 17px; }
.brand-sub { color: var(--text-secondary); font-weight: 500; }
.topbar nav { display: flex; gap: 4px; flex: 1; }
.topbar nav a {
  padding: 6px 12px; border-radius: 6px;
  color: var(--text-secondary); text-decoration: none;
}
.topbar nav a:hover { background: var(--page); color: var(--text-primary); }
.topbar nav a.active { background: var(--page); color: var(--text-primary); font-weight: 600; }
.userbox { color: var(--text-secondary); font-size: 13.5px; }
.userbox a { color: var(--text-secondary); }

main { max-width: 1040px; margin: 0 auto; padding: 24px; }
h1 { font-size: 22px; margin: 4px 0 16px; }
h2 { font-size: 15px; margin: 0 0 12px; }
h3 { margin-top: 0; }

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  margin-bottom: 20px;
}
.grid-2 {
  display: grid; grid-template-columns: 1fr 1fr; gap: 20px;
}
@media (max-width: 800px) { .grid-2 { grid-template-columns: 1fr; } }

.muted { color: var(--text-muted); }
.small { font-size: 13px; }
.right { text-align: right; }
code { font-size: 13px; white-space: nowrap; }

/* ---- tiles ---- */
.tiles {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px;
  margin-bottom: 20px;
}
@media (max-width: 800px) { .tiles { grid-template-columns: repeat(2, 1fr); } }
.tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 18px;
}
.tile-value { font-size: 32px; font-weight: 700; }
.tile-label { color: var(--text-secondary); font-size: 13.5px; }
.tile-alert .tile-value { color: var(--status-crit); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; vertical-align: 1px; }
.dot-in  { background: #0ca30c; }
.dot-out { background: var(--series-1); }

/* ---- gráfico de barras ---- */
.barlist { display: flex; flex-direction: column; gap: 10px; }
.barrow { display: grid; grid-template-columns: 180px 1fr 46px; gap: 10px; align-items: center; }
.barlabel {
  font-size: 13px; color: var(--text-secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bartrack { display: block; height: 14px; }
.bar {
  display: block; height: 14px; min-width: 3px;
  background: var(--series-1);
  border-radius: 0 4px 4px 0;   /* extremo de dato redondeado, base recta */
}
.barrow:hover .bar { filter: brightness(1.15); }
.barvalue { font-size: 13px; color: var(--text-secondary); font-variant-numeric: tabular-nums; }

/* ---- tablas ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-size: 12.5px; color: var(--text-muted);
  font-weight: 600; padding: 6px 10px;
  border-bottom: 1px solid var(--baseline);
}
td { padding: 8px 10px; border-bottom: 1px solid var(--grid); vertical-align: top; }
tr:last-child td { border-bottom: none; }

/* ---- badges de estado (color + icono + texto, nunca solo color) ---- */
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 12.5px; font-weight: 600; white-space: nowrap;
}
.badge-in    { background: var(--status-good-bg); color: var(--status-good); }
.badge-out   { background: var(--status-warn-bg); color: var(--status-warn); }
.badge-alert { background: var(--status-crit-bg); color: var(--status-crit); }
.ok-note { color: var(--status-good); font-weight: 600; }
.chip {
  display: inline-block; padding: 1px 8px; border-radius: 999px;
  background: var(--page); border: 1px solid var(--border);
  font-size: 12px; color: var(--text-secondary);
}
.chip-error { color: var(--status-crit); }

/* ---- formularios ---- */
input, button {
  font: inherit; color: inherit;
}
input[type="text"], input:not([type]), input[type="password"] {
  width: 100%; padding: 8px 10px;
  border: 1px solid var(--baseline); border-radius: 8px;
  background: var(--page);
}
input:focus { outline: 2px solid var(--series-1); outline-offset: 1px; border-color: transparent; }
label { display: block; margin-bottom: 12px; font-size: 13.5px; color: var(--text-secondary); }
label input { margin-top: 4px; }
.field { max-width: 420px; }
.inline-form { display: flex; gap: 10px; }
.inline-form input { flex: 1; }

button {
  padding: 8px 16px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--baseline); background: var(--surface-1);
}
button:hover { filter: brightness(0.96); }
button.primary, a.button.primary {
  background: var(--series-1); border-color: var(--series-1);
  color: #fff; font-weight: 600;
}
a.button {
  display: inline-block; padding: 8px 16px; border-radius: 8px;
  text-decoration: none;
}
button.danger { background: var(--status-crit); border-color: var(--status-crit); color: #fff; }
.small-btn { padding: 4px 10px; font-size: 13px; }

/* ---- checklist de salida/entrega ---- */
.checklist {
  display: flex; flex-direction: column; gap: 2px;
  margin: 6px 0 16px;
  max-height: 380px; overflow-y: auto;
  border: 1px solid var(--grid); border-radius: 8px; padding: 6px;
}
.check-item {
  display: flex; align-items: center; gap: 10px;
  margin: 0; padding: 8px 10px; border-radius: 6px;
  color: var(--text-primary); cursor: pointer;
}
.check-item:hover { background: var(--page); }
.check-item input { width: 16px; height: 16px; margin: 0; }

/* ---- mensajes flash ---- */
.flash {
  padding: 10px 14px; border-radius: 8px; margin-bottom: 14px;
  border: 1px solid var(--border);
}
.flash-ok    { background: var(--status-good-bg); color: var(--status-good); }
.flash-error { background: var(--status-crit-bg); color: var(--status-crit); }

/* ---- login ---- */
.login-wrap { display: flex; justify-content: center; padding-top: 8vh; }
.login-card { width: 360px; }

/* ---- diálogo ---- */
dialog {
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-1); color: var(--text-primary);
  padding: 20px 22px; max-width: 380px;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 14px; }

/* ---- listas de datos ---- */
.datalist { display: grid; grid-template-columns: 140px 1fr; gap: 4px 12px; margin: 0 0 16px; }
.datalist dt { color: var(--text-muted); font-size: 13.5px; }
.datalist dd { margin: 0; }

/* ---- filtros por área + buscador ---- */
.filtros {
  display: flex; gap: 6px; align-items: center; flex-wrap: wrap;
  margin: 0 0 16px;
}
.filtros a {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px; border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-secondary); text-decoration: none; font-size: 13.5px;
}
.filtros a:hover { border-color: var(--baseline); color: var(--text-primary); }
.filtros a.on {
  background: var(--series-1); border-color: var(--series-1);
  color: #fff; font-weight: 600;
}
.filtro-n {
  font-variant-numeric: tabular-nums; font-size: 12px;
  padding: 0 6px; border-radius: 999px;
  background: var(--page); color: var(--text-secondary);
}
.filtros a.on .filtro-n { background: rgba(255, 255, 255, 0.22); color: #fff; }
.buscador { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.buscador input { width: 220px; padding: 5px 10px; }
.limpiar { padding: 5px 9px !important; }

/* ---- inventario ---- */
.num { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.nota {
  margin-top: 3px; font-size: 12.5px; color: var(--text-secondary);
  border-left: 2px solid var(--baseline); padding-left: 8px;
}
.nota-alerta { border-left-color: var(--status-crit); color: var(--status-crit); }
tfoot th {
  border-top: 1px solid var(--baseline); border-bottom: none;
  color: var(--text-primary); font-size: 13px; padding-top: 8px;
}

.form-alta {
  display: grid; grid-template-columns: 1.6fr 1fr 90px 1.2fr 1.6fr auto;
  gap: 10px; align-items: end;
}
.form-alta label { margin-bottom: 0; }
@media (max-width: 900px) { .form-alta { grid-template-columns: 1fr 1fr; } }
select {
  width: 100%; padding: 8px 10px; font: inherit; color: inherit;
  border: 1px solid var(--baseline); border-radius: 8px; background: var(--page);
}
input[type="number"] {
  width: 100%; padding: 8px 10px; font: inherit; color: inherit;
  border: 1px solid var(--baseline); border-radius: 8px; background: var(--page);
}

/* ---- filas con cantidad (salida / entrega) ---- */
.lista-cabecera {
  display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap;
  margin-bottom: 6px;
}
.lista-cabecera h2 { margin: 0; }
.lista-cabecera input { width: 200px; padding: 5px 10px; margin-left: auto; }

.qty-row {
  display: grid; grid-template-columns: 72px 1fr auto 74px;
  gap: 10px; align-items: center;
  padding: 5px 10px; border-radius: 6px;
}
.qty-row[hidden] { display: none; }   /* display:grid gana sobre el [hidden] del navegador */
.qty-row:hover { background: var(--page); }
.qty-row .qty-input { width: 72px; padding: 5px 8px; text-align: right; }
.qty-label { margin: 0; color: var(--text-primary); cursor: pointer; }
.qty-max {
  font-size: 12.5px; color: var(--text-muted);
  font-variant-numeric: tabular-nums; text-align: right;
}
.todas { padding: 3px 9px; font-size: 12px; }
@media (max-width: 640px) {
  .qty-row { grid-template-columns: 64px 1fr; }
  .todas, .qty-max { display: none; }
}

.resumen {
  margin: 10px 0 14px; font-size: 13.5px; color: var(--text-muted);
}
.resumen-activo { color: var(--text-primary); font-weight: 600; }

/* ---- barras apiladas del dashboard ---- */
.bartrack { position: relative; }
.bar { position: absolute; inset: 0 auto 0 0; }
.bar-out { background: var(--series-out); z-index: 1; }
.barnote { grid-column: 2 / -1; margin: -4px 0 4px; }
.barlist .barnote:last-child { margin-bottom: 0; }

.tile-sub { margin-top: 2px; }
.mt { margin-top: 20px; }

/* ---- listas de novedades ---- */
.lista-notas { list-style: none; margin: 0; padding: 0; }
.lista-notas li {
  padding: 8px 0; border-bottom: 1px solid var(--grid); font-size: 13.5px;
}
.lista-notas li:last-child { border-bottom: none; }
.lista-notas a { color: var(--text-primary); text-decoration: none; }
.lista-notas a:hover { text-decoration: underline; }

/* ---- barra superior: roles y sesión ---- */
a.brand { color: var(--text-primary); text-decoration: none; }
.nav-sep { width: 1px; height: 18px; background: var(--baseline); margin: 0 6px; align-self: center; }
.userbox { display: flex; align-items: center; gap: 8px; }
.userbox a { text-decoration: none; }
.userbox a.active { color: var(--text-primary); font-weight: 600; }
.chip-admin { background: var(--series-1); border-color: var(--series-1); color: #fff; }
.chip-warn { color: var(--status-warn); }
form.inline { display: inline; margin: 0; }
button.link {
  border: none; background: none; padding: 0; color: var(--text-secondary);
  text-decoration: underline; cursor: pointer; font-size: 13.5px;
}
button.link:hover { filter: none; color: var(--text-primary); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.wide { width: 100%; }
.login-brand { font-weight: 700; font-size: 22px; margin-bottom: 4px; }
.card.narrow { max-width: 560px; }
.flash-warn { background: var(--status-warn-bg); color: var(--status-warn); }
tr.inactivo td { color: var(--text-muted); }
.form-usuario { grid-template-columns: 1.4fr 1.4fr 1fr auto; }
td form.inline select { width: auto; padding: 4px 8px; font-size: 13px; }
@media (max-width: 800px) {
  .topbar nav { order: 3; width: 100%; flex-wrap: wrap; }
  .userbox { margin-left: auto; }
}

/* ---- cabecera del formulario de salida / entrega ---- */
.form-mov { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 12px; }
@media (max-width: 800px) { .form-mov { grid-template-columns: 1fr; } }
label select { margin-top: 4px; }

/* ---- pantallas táctiles (tabletas): controles más grandes ---- */
@media (pointer: coarse) {
  button, .filtros a, .topbar nav a { min-height: 42px; padding-top: 10px; padding-bottom: 10px; }
  input, select { min-height: 42px; font-size: 16px; }   /* 16px evita el zoom automático en iOS */
  .qty-row { padding: 8px 10px; }
  .qty-row .qty-input { width: 84px; }
  .small-btn { min-height: 36px; }
  .checklist { max-height: 60vh; }
}
