/* ================================================================
   SEMIESPACIO — Sistema de Diseño: Alto Contraste y Alta Legibilidad
   Paleta "Alabaster / Powder / Pacific / Charcoal / Carbon" (Coolors)
   ================================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Ubuntu:wght@700&display=swap');

:root {
  /* ================================================================
     PALETA — "Alabaster / Powder / Pacific / Charcoal / Carbon"
     Todo el aspecto visual de la web sale de estas variables. Para
     cambiar de paleta en el futuro, basta con sustituir los valores
     de este bloque: el resto del CSS no necesita tocarse porque todas
     las reglas usan var(--nombre) en vez de colores sueltos.
     ================================================================ */

  /* --- Colores base de la paleta (Coolors) --- */
  --palette-alabaster: #d8dbe2;
  --palette-powder:    #a9bcd0;
  --palette-pacific:   #58a4b0;
  --palette-charcoal:  #373f51;
  --palette-carbon:    #1b1b1e;

  /* --- Fondos --- */
  --bg:          var(--palette-alabaster);
  --surface:     #ffffff;
  --surface-alt: #eef1f5;
  --panel:       #ffffff;
  --panel-alt:   #eef1f5;
  --line:        #c3cbd6;
  --line-strong: #92a3b6;

  /* --- Texto --- */
  --text:        var(--palette-carbon);
  --text-sec:    var(--palette-charcoal);
  --muted:       #5c6577;

  /* --- Colores de Acción/Estado ---
     El Pacific Blue de la paleta (#58a4b0) no da suficiente contraste
     como fondo de botón con texto blanco (2.9:1, por debajo del mínimo
     legible de 4.5:1), así que --accent usa una versión oscurecida del
     mismo tono para que el texto se lea bien sin perder su identidad
     "teal". El Pacific Blue original queda disponible en
     --accent-bright para usos decorativos (iconos, gráficos) donde no
     hay texto encima. */
  --accent:        #2f6e77;
  --accent-dark:   #204d54;
  --accent-bg:     #e9f4f5;
  --accent-bright: var(--palette-pacific);
  --ok:          #2f7a54;
  --ok-bg:       #eaf7f0;
  --bad:         #c0392b;
  --bad-bg:      #fdecea;
  --warn:        #a3690a;
  --warn-bg:     #fdf3e3;
  --info:        #4c6a89;
  --info-bg:     #eaf0f6;

  /* --- Tipografía --- */
  --font:        'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono:        'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;

  /* --- Espaciado / Radios --- */
  --radius:      10px;
  --radius-sm:   6px;
  --shadow:      0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md:   0 4px 12px rgba(0,0,0,0.10), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg:   0 10px 30px rgba(0,0,0,0.14), 0 4px 8px rgba(0,0,0,0.06);
}

/* ================================================================
   RESET Y BASE
   ================================================================ */
*, *::before, *::after { box-sizing: border-box; }

html {
  font-size: 15px;
  /* Reserva siempre el hueco de la barra de scroll vertical, tenga o no
     scroll la página, para que el contenido centrado (.app-wrapper) no se
     desplace unos píxeles al cambiar de pestaña según haya o no contenido
     suficiente para hacer scroll. scrollbar-gutter es el método moderno;
     overflow-y:scroll es el equivalente para navegadores que no lo soportan. */
  overflow-y: scroll;
  scrollbar-gutter: stable;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.9333rem;   /* ~14px */
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 { margin: 0; font-weight: 700; color: var(--text); }

/* ================================================================
   LAYOUT PRINCIPAL
   ================================================================ */
.app-wrapper {
  max-width: 1320px;
  margin: 0 auto;
  padding: 20px 24px 40px;
}

/* ================================================================
   CABECERA / TÍTULO
   ================================================================ */
.title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 24px;
  padding: 14px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.brand-icon { flex-shrink: 0; }

.brand-text {
  font-family: 'Ubuntu', sans-serif;
  font-weight: 700;
  letter-spacing: 0.8px;
  font-size: 1.25rem;    /* 18.75px */
  color: var(--accent);
}

.brand-login .brand-text { font-size: 1.6rem; }
.brand-login { justify-content: center; margin-bottom: 10px; }

.user-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.867rem;
  font-weight: 600;
  color: var(--text-sec);
  background: var(--surface-alt);
  border: 1px solid var(--line);
  padding: 5px 12px;
  border-radius: 999px;
}

/* ================================================================
   PESTAÑAS DE NAVEGACIÓN
   ================================================================ */
.tabs {
  display: flex;
  gap: 2px;
  margin-bottom: 22px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 5px;
  box-shadow: var(--shadow);
}

.tab-btn {
  background: transparent;
  color: var(--muted);
  border: none;
  border-radius: var(--radius-sm);
  padding: 9px 18px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s ease;
  font-family: var(--font);
}

.tab-btn:hover {
  background: var(--panel-alt);
  color: var(--text-sec);
}

.tab-btn.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 6px rgba(47,110,119,0.35);
}

/* ================================================================
   PANELES Y TARJETAS
   ================================================================ */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}

.panel > label:first-child,
.panel > .panel-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-bottom: 18px;
}

@media (max-width: 860px) { .grid { grid-template-columns: 1fr; } }

.sub {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 0 18px;
}

/* ================================================================
   FORMULARIOS E INPUTS
   ================================================================ */
input, textarea, select {
  font-family: var(--font);
}

.field-label, .field-label-block {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-sec);
  margin-bottom: 5px;
}

.panel label.field-label,
.cab-grid .field-label {
  text-transform: none;
  letter-spacing: 0;
}

textarea,
input[type="text"],
input[type="password"],
input[type="number"],
input[type="date"],
select {
  width: 100%;
  background: var(--surface-alt);
  color: var(--text);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 0.933rem;
  line-height: 1.5;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

textarea {
  height: 220px;
  font-family: var(--mono);
  font-size: 0.867rem;
  resize: vertical;
}

textarea::placeholder,
input::placeholder { color: #9aa4b3; }

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47,110,119,0.12);
}

.login-input {
  background: var(--surface-alt);
  color: var(--text);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 1rem;
  width: 100%;
}
.login-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(47,110,119,0.12);
}

.hint {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 6px;
  line-height: 1.4;
}

/* ================================================================
   BOTONES
   ================================================================ */
button {
  font-family: var(--font);
  background: var(--accent);
  color: #fff;
  border: 1.5px solid transparent;
  border-radius: var(--radius-sm);
  padding: 9px 20px;
  font-size: 0.933rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
  white-space: nowrap;
}

button:hover {
  background: var(--accent-dark);
  box-shadow: 0 3px 10px rgba(47,110,119,0.30);
}

button:active { transform: translateY(1px); }

button.secondary {
  background: var(--surface);
  color: var(--text-sec);
  border-color: var(--line);
  font-weight: 600;
}

button.secondary:hover {
  background: var(--panel-alt);
  border-color: var(--line-strong);
  box-shadow: var(--shadow);
}

button.danger {
  background: var(--bad);
  color: #fff;
  border-color: transparent;
}

button.danger:hover { background: #9c2f22; }

button.success {
  background: var(--ok);
  color: #fff;
}

button.success:hover { background: #245f42; }

button.small {
  padding: 6px 13px;
  font-size: 0.8rem;
}

button:disabled { opacity: 0.45; cursor: not-allowed; pointer-events: none; }

/* Grupo de botones horizontales */
.actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0 18px;
  flex-wrap: wrap;
}

.cat-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}

/* Botones de icono / acción pequeña */
.icon-btn {
  background: var(--surface);
  border: 1.5px solid var(--line);
  color: var(--bad);
  border-radius: var(--radius-sm);
  width: 30px;
  height: 30px;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
  font-family: var(--font);
}

.icon-btn:hover { background: var(--bad-bg); border-color: var(--bad); }

.icon-btn.edit { color: var(--accent); }
.icon-btn.edit:hover { background: var(--accent-bg); border-color: var(--accent); }

.icon-btn.ok-btn { color: var(--ok); }
.icon-btn.ok-btn:hover { background: var(--ok-bg); border-color: var(--ok); }

/* ================================================================
   BADGES / PILLS DE ESTADO
   ================================================================ */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  border: 1.5px solid var(--line);
  background: var(--surface-alt);
  color: var(--text-sec);
}

.pill.ok    { border-color: #9fd4b6; background: var(--ok-bg);   color: var(--ok);   }
.pill.bad   { border-color: #eeb4ab; background: var(--bad-bg);  color: var(--bad);  }
.pill.warn  { border-color: #e9c48a; background: var(--warn-bg); color: var(--warn); }
.pill.info  { border-color: #b6c9dc; background: var(--info-bg); color: var(--info); }
.pill.accent { border-color: #a7d3d7; background: var(--accent-bg); color: var(--accent); }

/* Stock badges (más prominentes) */
.badge-stock {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 700;
}
.badge-ok    { background: var(--ok-bg);   color: var(--ok);   border: 1.5px solid #9fd4b6; }
.badge-warn  { background: var(--warn-bg); color: var(--warn); border: 1.5px solid #e9c48a; }
.badge-bad   { background: var(--bad-bg);  color: var(--bad);  border: 1.5px solid #eeb4ab; }

/* ================================================================
   TABLAS
   ================================================================ */
.table-wrap {
  max-height: 540px;
  overflow: auto;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  background: var(--surface);
}

thead th {
  text-align: left;
  background: var(--surface-alt);
  color: var(--text-sec);
  font-weight: 700;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 10px 14px;
  border-bottom: 2px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 1;
}

tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }

tbody tr:hover td { background: var(--surface-alt); }

/* Filas de estado en el Comparador */
tbody tr.missing td { background: #fdf0ef; color: var(--bad); }
tbody tr.missing:hover td { background: #fbdbd8; }

tbody tr.articulo-row td {
  background: var(--accent-bg);
  color: var(--accent-dark);
  font-weight: 600;
  border-top: 2px solid #cfe7e9;
}
tbody tr.articulo-row:hover td { background: #ddf0f1; }

/* ================================================================
   TOGGLE (expandir/colapsar comparador)
   ================================================================ */
.toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border: 1.5px solid var(--accent);
  border-radius: 4px;
  margin-right: 8px;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
  user-select: none;
  color: var(--accent);
  background: var(--accent-bg);
  transition: background 0.15s;
}
.toggle:hover { background: #cfe7e9; }

.code { color: var(--accent); font-family: var(--mono); font-weight: 600; }

/* ================================================================
   FILTROS
   ================================================================ */
#filterBar {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
  align-items: center;
  flex-wrap: wrap;
}

#filterBar input[type=text] {
  flex: 1;
  min-width: 220px;
}

#filterBar label {
  font-size: 0.867rem;
  color: var(--text-sec);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
  cursor: pointer;
}

.almacen-filter-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
  align-items: center;
  flex-wrap: wrap;
}

#empty {
  color: var(--muted);
  font-size: 0.93rem;
  padding: 36px;
  text-align: center;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

/* ================================================================
   GENERADOR: TARJETAS DE LÍNEA
   ================================================================ */
.cab-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-top: 8px;
}

@media (max-width: 820px) { .cab-grid { grid-template-columns: 1fr !important; } }

.linea-card {
  background: var(--surface);
  border: 1.5px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
  transition: border-color 0.15s;
}

.linea-card:hover { border-color: #7fb8bd; }

.linea-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.linea-card-header strong {
  font-size: 0.933rem;
  color: var(--accent);
  font-weight: 700;
}

.linea-fields {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

@media (max-width: 820px) { .linea-fields { grid-template-columns: repeat(2, 1fr); } }

.linea-fields > div.span2 { grid-column: span 2; }

/* Tabla de componentes internos de línea */
.componentes-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 8px;
  font-size: 0.867rem;
}

.componentes-table th {
  text-align: left;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 700;
  padding: 5px 7px;
  border-bottom: 2px solid var(--line);
  background: var(--surface-alt);
}

.componentes-table td { padding: 5px 7px; vertical-align: middle; }

.componentes-table input {
  padding: 5px 8px;
  font-size: 0.867rem;
  font-family: var(--mono);
}

.comp-name-preview {
  font-size: 0.78rem;
  color: var(--muted);
  display: block;
  margin-top: 2px;
  max-width: 200px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ================================================================
   ESTADO DE BLOQUEO
   ================================================================ */
.estado-bloqueado {
  color: var(--warn);
  font-weight: 700;
  font-size: 0.85rem;
}

/* ================================================================
   ESTADÍSTICAS / RESÚMENES DE ALMACÉN
   ================================================================ */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}

@media (max-width: 900px) { .stat-cards { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 480px) { .stat-cards { grid-template-columns: 1fr; } }

.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat-card .stat-label {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}

.stat-card .stat-value {
  font-size: 1.7rem;
  font-weight: 800;
  color: var(--text);
  line-height: 1.1;
}

.stat-card.accent-card { border-left: 4px solid var(--accent); }
.stat-card.ok-card     { border-left: 4px solid var(--ok); }
.stat-card.warn-card   { border-left: 4px solid var(--warn); }
.stat-card.bad-card    { border-left: 4px solid var(--bad); }

/* ================================================================
   MODAL
   ================================================================ */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.50);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(3px);
}

.modal-overlay.open { display: flex; }

.modal-box {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  max-width: 820px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 28px 30px;
  box-shadow: var(--shadow-lg);
  position: relative;
}

.modal-box h2 {
  font-size: 1.15rem;
  margin: 0 0 6px;
  color: var(--text);
}

.modal-box h3 {
  font-size: 0.78rem;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
  margin: 20px 0 8px;
}

.modal-box p, .modal-box li {
  font-size: 0.933rem;
  line-height: 1.65;
  color: var(--text-sec);
  margin: 0 0 6px;
}

.modal-box ul { margin: 0; padding-left: 22px; }

.modal-box code {
  background: var(--surface-alt);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 2px 6px;
  font-family: var(--mono);
  font-size: 0.84rem;
  color: var(--accent-dark);
}

.modal-close-row {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

/* ================================================================
   ADMINISTRACIÓN: TABLA DE USUARIOS
   ================================================================ */
#usersTable {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

#usersTable th {
  text-align: left;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-sec);
  font-weight: 700;
  padding: 8px 10px;
  border-bottom: 2px solid var(--line);
  background: var(--surface-alt);
}

#usersTable td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

#usersTable input[type=text],
#usersTable input[type=password] {
  padding: 6px 9px;
  font-size: 0.867rem;
}

#usersTable input[type=checkbox] {
  width: 17px;
  height: 17px;
  accent-color: var(--accent);
}

/* ================================================================
   PANEL DE LOGIN
   ================================================================ */
.login-wrapper {
  max-width: 420px;
  margin: 70px auto 0;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 36px 36px 30px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.login-card h2 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 24px;
  letter-spacing: 0.03em;
}

/* ================================================================
   MISCELLANEOUS
   ================================================================ */
#status { font-size: 0.867rem; color: var(--muted); }
#genOutput { height: 260px; }

.subtabs {
  display: flex;
  gap: 4px;
  margin-bottom: 16px;
  border-bottom: 2px solid var(--line);
  padding-bottom: 0;
}

.subtab-btn {
  background: transparent;
  color: var(--muted);
  border: none;
  border-bottom: 3px solid transparent;
  padding: 7px 14px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: -2px;
  font-family: var(--font);
  transition: color 0.15s, background 0.15s;
}

/* Sin esta regla propia, el botón heredaba el :hover genérico de
   <button> (fondo oscuro), lo que dejaba el texto verde-teal de la
   pestaña activa sobre un fondo verde-teal oscuro: ilegible (1.6:1
   de contraste). Con su propio :hover, se queda en un gris neutro. */
.subtab-btn:hover {
  background: var(--surface-alt);
  color: var(--text-sec);
}

.subtab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.subtab-btn.active:hover {
  background: transparent;
  color: var(--accent);
}

/* Separador horizontal */
hr.section-sep {
  border: none;
  border-top: 1px solid var(--line);
  margin: 18px 0;
}

/* Aviso de movimiento en historial */
.mov-entrada { color: var(--ok);   font-weight: 700; }
.mov-salida  { color: var(--bad);  font-weight: 700; }
.mov-ajuste  { color: var(--warn); font-weight: 700; }

/* Tabla de Stock: fila de filtros bajo la cabecera */
.filter-row th {
  padding: 4px 8px;
  background: var(--surface-alt);
}
.col-filter-input {
  width: 100%;
  padding: 5px 7px;
  font-size: 0.82rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font);
}
.sortable-th {
  cursor: pointer;
  user-select: none;
}
.sortable-th:hover { color: var(--accent); }
.sort-icon {
  font-size: 0.7rem;
  color: var(--accent);
  margin-left: 2px;
}

/* Edición rápida en línea en la tabla de Stock */
.stock-inline-input {
  width: 72px;
  padding: 4px 6px;
  font-size: 0.85rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font-family: var(--font);
}
.stock-inline-input:hover,
.stock-inline-input:focus {
  border-color: var(--line);
  background: var(--surface-alt);
}

/* Dashboard de Almacén Tejido: barras horizontales de coste/m² */
.bar-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.bar-label {
  width: 160px;
  flex-shrink: 0;
  font-size: 0.85rem;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bar-line {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
}
.bar-track {
  flex: 1;
  height: 10px;
  background: var(--surface-alt);
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--line);
}
.bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 6px 0 0 6px;
}
.bar-value {
  width: 90px;
  flex-shrink: 0;
  text-align: right;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
}

/* ================================================================
   RESPONSIVE MÓVIL / TABLET
   ================================================================ */
@media (max-width: 860px) {
  .app-wrapper { padding: 14px 12px 30px; }

  /* Cabecera: apila el logo y el bloque de usuario/botones si no caben */
  .title-row {
    flex-wrap: wrap;
    gap: 10px;
    padding: 12px 14px;
  }
  .title-row > div:last-child { width: 100%; justify-content: flex-end; }
  .brand-text { font-size: 1.05rem; }

  /* Barra de pestañas principal: scroll horizontal en vez de desbordarse */
  .tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab-btn {
    flex: none;
    white-space: nowrap;
    padding: 8px 14px;
    font-size: 0.82rem;
  }

  /* Submenús (Administración, Almacén Tejido): mismo tratamiento */
  .subtabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 6px;
  }
  .subtabs::-webkit-scrollbar { display: none; }
  .subtab-btn { flex: none; white-space: nowrap; }

  /* Formularios en rejilla: una sola columna */
  .linea-fields { grid-template-columns: 1fr !important; }

  /* Filas de cabecera "título + botón" (inline style con space-between):
     que puedan bajar el botón a una segunda línea si no caben */
  [style*="justify-content:space-between"] { flex-wrap: wrap; gap: 8px; }

  .panel { padding: 14px; }

  /* Tablas: más compactas y con scroll táctil suave */
  table { font-size: 0.82rem; }
  table th, table td { padding: 7px 8px; }
  .table-wrap { -webkit-overflow-scrolling: touch; }

  /* Modales: ocupan casi todo el ancho, con menos padding */
  .modal-box { padding: 20px 16px; max-width: 94vw; }

  /* Login: se ajusta al ancho disponible en vez de forzar 420px */
  .login-wrapper { max-width: 94vw; margin-top: 40px; }
  .login-card { padding: 26px 20px 22px; }
}

@media (max-width: 480px) {
  .brand-text { font-size: 0.95rem; }
  .user-badge { font-size: 0.78rem; padding: 5px 9px; }
  .title-row .secondary.small { padding: 7px 10px; font-size: 0.8rem; }
  .stat-card .stat-value { font-size: 1.3rem; }
}

/* Scrollbar personalizada */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--surface-alt); }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-sec); }
