:root {
  --verde:    #397f44;
  --verde-l:  #dbe7dd;
  --verde-d:  #234e2a;
  --surface:  #ffffff;
  --bg:       #f4f6f4;
  --text:     #1a1a1a;
  --muted:    #6b7280;
  --border:   #e0e0e0;
  --radius:   8px;
  --shadow:   0 2px 8px rgba(0,0,0,.08);
}

/* ── MODO OSCURO ──────────────────────────────────────────────────────────
   Se activa poniendo data-theme="dark" en <html> (ver theme.js). El verde
   de marca (sidebar, botones, header de tarjetas) se mantiene igual en
   ambos temas; lo que cambia es el fondo, las superficies (tarjetas,
   inputs) y el texto, para que sigan siendo legibles sobre fondo oscuro. */
html[data-theme="dark"] {
  --surface:  #1e2422;
  --bg:       #141816;
  --text:     #e8eae9;
  --muted:    #9aa39e;
  --border:   #343d39;
  --shadow:   0 2px 8px rgba(0,0,0,.35);
  color-scheme: dark;
}
html[data-theme="dark"] .card-body input::placeholder,
html[data-theme="dark"] .form-control::placeholder { color: #6b756f; }
html[data-theme="dark"] .login-card { background: #ffffff; } /* el login se queda igual siempre */
html[data-theme="dark"] img.login-logo-img,
html[data-theme="dark"] .sidebar-brand img { filter: none; }


* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body { font-family: 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); font-size: 14px; overflow-x: hidden; }
body.no-scroll { overflow: hidden; }

/* ── LAYOUT ── */
.layout { display: flex; min-height: 100vh; }

/* ── TOPBAR (móvil/tablet) ── */
.topbar {
  display: none;
  align-items: center;
  gap: 12px;
  background: var(--verde-d);
  color: white;
  padding: 10px 14px;
  position: sticky;
  top: 0;
  left: 0;
  right: 0;
  z-index: 150;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.topbar-menu-btn {
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 6px;
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  cursor: pointer;
}
.topbar-menu-btn span {
  display: block;
  width: 18px;
  height: 2px;
  background: white;
  border-radius: 1px;
}
.topbar-brand { font-weight: 700; font-size: 15px; letter-spacing: .4px; text-transform: uppercase; }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 199;
}
.sidebar-overlay.show { display: block; }

/* ── SIDEBAR ── */
.sidebar {
  width: 220px;
  min-width: 220px;
  background: var(--verde-d);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  box-shadow: 2px 0 8px rgba(0,0,0,.15);
  z-index: 100;
  transition: width .24s ease, min-width .24s ease, transform .25s ease;
}
.sidebar-brand {
  padding: 20px 16px 16px;
  font-weight: 700;
  font-size: 14px;
  color: white;
  letter-spacing: .4px;
  border-bottom: 1px solid rgba(255,255,255,.1);
}
.sidebar-logo-completo {
  display: block;
  width: 120px;
  height: auto;
  margin: 0 auto;
}
.sidebar-logo-compacto {
  display: none;
  width: 44px;
  height: 44px;
  margin: 0 auto;
  object-fit: contain;
  border-radius: 10px;
}
.sidebar-collapse-btn { display: none; }
.sidebar-nav {
  display: flex;
  flex-direction: column;
  padding: 12px 8px;
  flex: 1;
  gap: 2px;
}
.sidebar-nav a {
  color: rgba(255,255,255,.8);
  text-decoration: none;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .5px;
  transition: background .15s;
  display: flex;
  align-items: center;
  gap: 10px;
}
.nav-icon { width: 18px; height: 18px; flex-shrink: 0; }
.sidebar-nav a:hover { background: rgba(255,255,255,.12); color: white; }
.sidebar-nav a.active { background: rgba(255,255,255,.18); color: white; font-weight: 600; }
.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid rgba(255,255,255,.12);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.sidebar-user-row {
  display: flex;
  align-items: center;
  gap: 6px;
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  padding: 6px;
  margin: -6px;
  border-radius: var(--radius);
  transition: background .15s;
  flex: 1;
  min-width: 0;
}
.sidebar-user:hover { background: rgba(255,255,255,.08); }
.sidebar-admin-btn {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  background: rgba(255,255,255,.08);
  color: rgba(255,255,255,.8);
  text-decoration: none;
  font-size: 16px;
  border: 1px solid rgba(255,255,255,.12);
  transition: background .15s, color .15s, transform .15s;
}
.sidebar-admin-btn:hover { background: rgba(255,255,255,.18); color: white; transform: rotate(45deg); }
.sidebar-admin-btn.active { background: var(--verde); color: white; border-color: transparent; }
.sidebar-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,.15);
  color: white;
  font-weight: 700;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: 2px solid rgba(255,255,255,.3);
  letter-spacing: 0;
}
.sidebar-user-info { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.sidebar-nombre { color: white; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.2; }
.btn-logout {
  background: rgba(255,255,255,.08);
  color: rgba(255,255,255,.75);
  border: 1px solid rgba(255,255,255,.15);
  padding: 7px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  text-decoration: none;
  font-size: 12px;
  text-align: center;
  transition: background .15s, color .15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn-logout:hover { background: rgba(220,38,38,.5); color: white; border-color: transparent; }

/* ── MAIN ── */
.main-content { flex: 1; padding: 24px; overflow-y: auto; overflow-x: hidden; min-width: 0; max-width: 100%; }
.page-header { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.page-header h2 { font-size: 20px; font-weight: 600; color: var(--verde-d); text-transform: uppercase; letter-spacing: .4px; }
html[data-theme="dark"] .page-header h2 { color: #6fcf97; }
.page-date { color: var(--muted); font-size: 13px; }

/* ── CARD ── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-header {
  background: var(--verde);
  color: white;
  padding: 10px 16px;
  font-weight: 600;
  font-size: 14px;
}
.card-body { padding: 16px; }
.mt-2 { margin-top: 14px; }

/* ── FORMS ── */
.form-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; }
/* Variante que siempre mantiene 2 columnas en la misma fila, sin importar el
   ancho de pantalla (usa grid para que nunca se apile, a diferencia de
   .form-row que sí se apila en móviles). */
.form-row-nowrap { display: grid !important; grid-template-columns: 1fr 1fr !important; gap: 10px !important; align-items: end !important; }
.form-row-nowrap .form-group { width: auto !important; min-width: 0 !important; }
.form-group { display: flex; flex-direction: column; gap: 4px; min-width: 130px; }
.form-group label { font-size: 12px; color: var(--muted); font-weight: 500; }
.form-group-btn { flex-direction: row; flex-wrap: wrap; justify-content: flex-end; }
.form-group-noflex { flex: 0 0 auto !important; }
.form-control {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 7px 10px;
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border .15s;
  width: 100%;
  min-width: 0;
}
.form-control:focus { border-color: var(--verde); }
.form-control:disabled {
  background: #f0f1ef;
  color: var(--muted);
  cursor: not-allowed;
  border-color: var(--border);
}
html[data-theme="dark"] .form-control:disabled { background: #262b28; }

/* ── PASSWORD INPUT (con toggle mostrar/ocultar) ── */
.pw-wrap { position: relative; display: flex; }
.pw-wrap .form-control { flex: 1; padding-right: 36px; }
.pw-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 15px;
  color: var(--muted);
  padding: 4px 6px;
  line-height: 1;
}
.pw-toggle:hover { color: var(--text); }
.pw-toggle-icon { display: block; }
.area-sala-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 2px;
  border-bottom: 1px solid var(--border);
}
.area-sala-row:last-child { border-bottom: none; }
.area-sala-nombre { font-size: 14px; color: var(--text); }
.area-sala-input-wrap { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.area-sala-input-wrap .form-control { width: 90px; text-align: right; }
.area-sala-unidad { font-size: 13px; color: var(--muted); }
.admin-search-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 12px;
  margin: 14px 0;
  max-width: 480px;
}
.admin-search-icon { color: var(--muted); flex-shrink: 0; }
.admin-search-wrap .form-control { border: none; padding: 9px 0; }
.admin-search-wrap .form-control:focus { border: none; }
#admin-search-clear {
  background: none; border: none; cursor: pointer; color: var(--muted);
  font-size: 13px; padding: 4px 6px; flex-shrink: 0;
}
#admin-search-clear:hover { color: var(--text); }
.admin-card-header { cursor: pointer; display: flex; align-items: center; gap: 6px; user-select: none; }
.admin-chevron { margin-left: auto; transition: transform .15s; flex-shrink: 0; }
.card.admin-collapsed .admin-chevron { transform: rotate(-90deg); }
.card.admin-collapsed > .card-body { display: none !important; }
.card.admin-search-hidden { display: none !important; }

/* ── Íconos SVG en línea (reemplazo de emojis en todo el sistema) ── */
.ico-inline { width: 14px; height: 14px; vertical-align: -2px; margin: 0 2px 0 0; flex-shrink: 0; }

/* ── INDICADOR DE FUERZA DE CONTRASEÑA ── */
.pw-hint { font-size: 11px; color: var(--muted); margin-top: 2px; }
.pw-strength {
  display: flex;
  gap: 4px;
  margin-top: 6px;
  height: 4px;
}
.pw-strength-bar {
  flex: 1;
  border-radius: 2px;
  background: var(--border);
  transition: background .15s;
}
.pw-strength-label {
  font-size: 11px;
  font-weight: 500;
  margin-top: 4px;
}
.pw-strength-label.weak   { color: #dc2626; }
.pw-strength-label.medium { color: #b45309; }
.pw-strength-label.strong { color: var(--verde); }

/* ── BUTTONS ── */
.btn {
  padding: 8px 16px;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  font-weight: 500;
  transition: opacity .15s;
  white-space: nowrap;
}
.btn:hover { opacity: .88; }
.btn-primary  { background: var(--verde);  color: white; }
.btn-success  { background: #1a7742;       color: white; }
.btn-secondary{ background: #6b7280;       color: white; }
.btn-danger   { background: #dc2626;       color: white; }
.btn-sm       { padding: 4px 10px; font-size: 12px; }
.btn-block    { width: 100%; }
.btn-icon     { background: none; border: none; cursor: pointer; color: var(--muted); font-size: 13px; }
.btn-icon:hover { color: #dc2626; }

/* ── TABLE ── */
.table-responsive { overflow-x: auto; width: 100%; max-width: 100%; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; }
.table thead tr { background: var(--verde); color: white; }
.table th { padding: 10px 12px; text-align: left; font-weight: 600; font-size: 13px; text-transform: uppercase; letter-spacing: .3px; user-select: none; -webkit-user-select: none; -moz-user-select: none; }
.table td { padding: 8px 12px; border-bottom: 1px solid var(--border); font-size: 13px; user-select: none; -webkit-user-select: none; -moz-user-select: none; }
.table tbody tr:hover { background: rgba(0,0,0,.03); }
.th-check, .td-check { display: none; width: 34px; padding-left: 10px !important; padding-right: 0 !important; text-align: center; }
.row-check { width: 18px; height: 18px; cursor: pointer; accent-color: var(--verde); }
html[data-theme="dark"] .table tbody tr:hover { background: rgba(255,255,255,.05); }
.text-right { text-align: right; }
.table th.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--muted); }
.table-footer {
  padding: 10px 14px;
  border-top: 2px solid var(--border);
  display: flex;
  justify-content: flex-end;
  font-size: 13px;
  color: var(--verde-d);
  font-weight: 500;
}
html[data-theme="dark"] .table-footer { color: #6fcf97; }

/* ── PRODUCCION CARDS ── */
.prod-card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.prod-header {
  background: var(--verde);
  color: white;
  padding: 10px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.prod-sala  { font-weight: 700; font-size: 15px; }
.prod-fechas { font-size: 12px; opacity: .9; }
.prod-table { width: 100%; }
.prod-table th { padding: 8px 14px; background: var(--verde); color: white; font-size: 13px; }
.prod-table td { padding: 7px 14px; border-bottom: 1px solid var(--border); font-size: 13px; }
.fila-total td { font-weight: 700; }
html[data-theme="dark"] { --chart-text: #cfd6d2; --chart-axis: #4a544e; }

/* Producción por Sala -- rediseño con tarjetas de resumen, grid y paginación */
.prod-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin: 14px 0;
}
.prod-stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.prod-stat-icon {
  width: 40px; height: 40px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.prod-stat-valor { font-size: 18px; font-weight: 700; color: var(--text); line-height: 1.2; }
.prod-stat-label { font-size: 11px; color: var(--muted); line-height: 1.3; margin-top: 2px; }

.prod-aviso-banner {
  display: flex; align-items: center; gap: 10px;
  background: #fffbeb; border: 1px solid #fde68a; color: #92400e;
  border-radius: 10px; padding: 12px 16px; font-size: 13px;
}
.prod-aviso-icon { flex-shrink: 0; color: #d97706; }
.prod-aviso-btn { margin-left: auto; background: #fff; border: 1px solid #d97706; color: #92400e; }
html[data-theme="dark"] .prod-aviso-banner { background: #2a1f00; border-color: #78530a; color: #ffcc80; }

.prod-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 14px;
}
.prod-cards-grid .prod-card.mt-2 { margin-top: 0; }
.prod-card-top { display: flex; align-items: flex-start; gap: 10px; padding: 14px 16px 10px; }
.prod-card-icon {
  width: 38px; height: 38px; border-radius: 50%; flex-shrink: 0;
  background: var(--verde-l); color: var(--verde-d);
  display: flex; align-items: center; justify-content: center;
}
html[data-theme="dark"] .prod-card-icon { background: #16301e; color: #6fcf97; }
.prod-card-titles { flex: 1; min-width: 0; }
.prod-card-top .prod-sala { color: var(--text); font-size: 16px; }
.prod-card-top .prod-fechas { color: var(--muted); display: flex; align-items: center; gap: 4px; margin-top: 2px; }
.prod-badge-oleadas {
  background: var(--verde-l); color: var(--verde-d);
  font-size: 11px; font-weight: 600; padding: 3px 10px; border-radius: 20px;
  flex-shrink: 0; white-space: nowrap;
}
html[data-theme="dark"] .prod-badge-oleadas { background: #16301e; color: #6fcf97; }

.prod-kgm2-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 16px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--border);
}
.prod-badge-cat {
  display: inline-block; font-size: 11px; font-weight: 600;
  padding: 2px 9px; border-radius: 20px; margin-top: 2px;
}

.prod-pagination {
  display: flex; align-items: center; justify-content: center; gap: 6px;
  flex-wrap: wrap; margin: 20px 0;
}
.prod-page-num, .prod-page-arrow {
  min-width: 32px; height: 32px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  cursor: pointer; font-size: 13px;
}
.prod-page-num.active { background: var(--verde); border-color: var(--verde); color: white; font-weight: 700; }
.prod-page-arrow:disabled { opacity: .4; cursor: not-allowed; }
.prod-page-size-wrap { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); margin-left: 10px; }
.prod-page-size-wrap select { width: auto; padding: 4px 8px; }

/* Comparar Salas -- rediseño con tarjetas de columna, stats y gráficos */
.cmp-columnas-container { display: flex; flex-wrap: wrap; gap: 14px; }
.cmp-col-card {
  flex: 1; min-width: 220px;
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px; display: flex; flex-direction: column; gap: 10px;
}
.cmp-col-titulo { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; color: var(--text); }
.cmp-col-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.cmp-col-quitar { align-self: flex-start; }

.cmp-stats-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px;
}
.cmp-stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px; display: flex; align-items: flex-start; gap: 12px;
}
.cmp-stat-icon { width: 40px; height: 40px; border-radius: 10px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.cmp-stat-label { font-size: 11px; font-weight: 700; color: var(--muted); letter-spacing: .3px; }
.cmp-stat-valor { font-size: 17px; font-weight: 700; color: var(--text); line-height: 1.3; margin-top: 2px; }
.cmp-stat-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }

.cmp-th-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; }
.cmp-td-bar { min-width: 90px; text-align: left; }
.cmp-bar-value { font-size: 13px; margin-bottom: 4px; }
.cmp-bar-track { width: 100%; max-width: 130px; height: 5px; background: var(--border); border-radius: 4px; overflow: hidden; }
.cmp-bar-fill { height: 100%; border-radius: 4px; }
.text-left { text-align: left; }
.cmp-diff-kg { font-weight: 600; }
.cmp-diff-badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 20px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.cmp-fila-total td { background: #dcfce7; font-size: 15px; padding-top: 12px; padding-bottom: 12px; }
html[data-theme="dark"] .cmp-fila-total td { background: #0d2212; }

.cmp-charts-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; }
.cmp-legend { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 8px; justify-content: center; }
.cmp-legend-item { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--muted); }
.cmp-legend-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }

.prod-toolbar { display: flex; align-items: flex-start; flex-wrap: wrap; gap: 18px; }
.prod-toolbar-group { display: flex; flex-direction: column; gap: 8px; }
.prod-toolbar-label { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .3px; }
.prod-toolbar-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.prod-toolbar-divider { width: 1px; align-self: stretch; background: var(--border); margin-top: 22px; }
@media (max-width: 720px) {
  .prod-toolbar-divider { display: none; }
  .prod-toolbar { gap: 14px; }
}

.prod-adjuntos { padding: 10px 16px; border-top: 1px solid var(--border); background: #fafafa; }
html[data-theme="dark"] .prod-adjuntos { background: #1a1f1c; }
.prod-adjuntos-header { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--text); font-weight: 600; }
.btn-outline { background: #6b7280; border: 1px solid #6b7280; color: #fff; cursor: pointer; font-weight: 600; }
.btn-outline:hover { background: #4b5563; border-color: #4b5563; color: #fff; }
html[data-theme="dark"] .btn-outline { background: #6b7280; border-color: #6b7280; color: #fff; }
html[data-theme="dark"] .btn-outline:hover { background: #4b5563; color: #fff; }
.btn-outline-active { background: #6b7280 !important; color: #fff !important; border-color: #6b7280 !important; }
html[data-theme="dark"] .btn-outline-active { background: #6b7280 !important; color: #fff !important; border-color: #6b7280 !important; }
.btn-tablero-ver { background: var(--verde); border: 1px solid var(--verde); color: #fff; cursor: pointer; font-weight: 600; }
.btn-tablero-ver:hover { background: var(--verde-d); border-color: var(--verde-d); color: #fff; }
.adjunto-lista { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.adjunto-item { display: flex; justify-content: space-between; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 5px 10px; font-size: 13px; }
.adjunto-item a { color: var(--verde); text-decoration: none; word-break: break-all; }
.adjunto-item a:hover { text-decoration: underline; }
.btn-adjunto-eliminar { background: none; border: none; color: #b71c1c; font-weight: 700; cursor: pointer; font-size: 13px; padding: 0 4px; }
.btn-adjunto-eliminar:hover { color: #7f0000; }
.adjunto-vacio { font-size: 12px; color: var(--text-muted, #888); margin-top: 6px; }

/* Colores de clasificación */
.cat-excelente { background: #e3f2fd; color: #0d47a1; }
.cat-buena     { background: #e8f5e9; color: #1b5e20; }
.cat-regular   { background: #fffde7; color: #e65100; }
.cat-mala      { background: #ffebee; color: #b71c1c; }
html[data-theme="dark"] .cat-excelente { background: #0d1f33; color: #90caf9; }
html[data-theme="dark"] .cat-buena     { background: #0d2212; color: #a5d6a7; }
html[data-theme="dark"] .cat-regular   { background: #2a1f00; color: #ffcc80; }
html[data-theme="dark"] .cat-mala      { background: #2a0a0a; color: #ef9a9a; }

/* Colores de filas en Desempeño por Cosechadora (oro/plata/bronce/último) */
.desemp-oro    { background: #fff8e1; color: #7c5200; }
.desemp-plata  { background: #f5f5f5; color: #4a4a4a; }
.desemp-bronce { background: #fbe9e7; color: #7c2d00; }
.desemp-ultimo { background: #fce4ec; color: #880e4f; }
html[data-theme="dark"] .desemp-oro    { background: #332a0d; color: #ffd54f; }
html[data-theme="dark"] .desemp-plata  { background: #2a2a2a; color: #d0d0d0; }
html[data-theme="dark"] .desemp-bronce { background: #2e1a0d; color: #ffab91; }
html[data-theme="dark"] .desemp-ultimo { background: #2e0d1c; color: #f48fb1; }
.desemp-oro a, .desemp-plata a, .desemp-bronce a, .desemp-ultimo a { color: inherit; }

/* ── MODALES (global) ── */
.modal-overlay { position:fixed; inset:0; background:rgba(0,0,0,.45); display:flex; align-items:center; justify-content:center; z-index:999; }
.modal-box { background:white; border-radius:10px; width:660px; max-width:95vw; box-shadow:0 8px 32px rgba(0,0,0,.25); overflow:hidden; }
html[data-theme="dark"] .modal-box { background:#1e2421; }
.modal-header { background:var(--verde); color:white; padding:14px 18px; font-weight:600; font-size:15px; }
.modal-body { padding:18px; }
.modal-footer { padding:12px 18px; border-top:1px solid var(--border); display:flex; justify-content:flex-end; gap:10px; }
@media(max-width:640px) {
  .modal-box { width:100%; max-width:96vw; max-height:92vh; overflow-y:auto; }
  .modal-body { padding:14px; }
  .modal-footer { flex-wrap:wrap; }
  .modal-footer .btn { flex:1; }
}

/* ── Menú contextual (clic derecho en filas) ── */
.ctx-menu {
  position:fixed; z-index:1200; background:white; border-radius:8px;
  box-shadow:0 6px 24px rgba(0,0,0,.22); overflow:hidden; min-width:170px;
  border:1px solid var(--border);
}
html[data-theme="dark"] .ctx-menu { background:#1e2421; }
.ctx-menu-item {
  padding:10px 16px; font-size:14px; cursor:pointer; user-select:none;
  display:flex; align-items:center;
}
.ctx-menu-item:hover { background:var(--verde); color:white; }
.ctx-menu-icon { width:16px; height:16px; margin-right:9px; flex-shrink:0; }

/* ── Comprobante de pago (Ventas) ── */
.badge-comprobante {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .4px;
  border: none;
  cursor: pointer;
  font-family: inherit;
  transition: filter .15s;
  user-select: none;
  -webkit-user-select: none;
  white-space: nowrap;
}
.badge-comprobante:hover { filter: brightness(0.93); }
.badge-cancelado    { background: var(--verde); color: white; }
.badge-por-cancelar { background: #dc2626; color: white; }
.badge-credito-vencido { background: #dc2626; color: white; }
.badge-pendiente-naranja { background: #f97316; color: white; }
.badge-pendiente-detraccion { background: #6b8e23; color: white; }

/* Mini ventana con el PDF del comprobante */
.comprobante-modal-box {
  background: var(--surface); border-radius: 8px; width: 100%; max-width: 560px;
  box-shadow: 0 8px 32px rgba(0,0,0,.25); overflow: hidden; display: flex; flex-direction: column;
  max-height: 90vh;
}
.comprobante-modal-head {
  background: var(--verde); color: white; padding: 12px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.comprobante-modal-head h4 { margin: 0; font-size: 15px; }
.comprobante-modal-head .cerrar { cursor: pointer; font-size: 20px; line-height: 1; background: none; border: none; color: white; }
.comprobante-modal-body { flex: 1; min-height: 0; background: #525659; }
.comprobante-modal-body iframe { width: 100%; height: 70vh; border: none; display: block; }
.comprobante-modal-foot { padding: 10px 16px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
@media(max-width:640px) {
  .comprobante-modal-body iframe { height: 60vh; }
}

/* ── Filas de información (modal Información) ── */
.info-row {
  display:flex; justify-content:space-between; align-items:center;
  padding:10px 0; border-bottom:1px solid var(--border);
}
.info-row:last-child { border-bottom:none; }
.info-label { color:var(--text-muted,#6b7280); font-size:13px; }
.info-valor { font-weight:600; font-size:14px; text-align:right; }

/* ── BITÁCORA DE MOVIMIENTOS ── */
.bit-accion { display:inline-block; padding:2px 8px; border-radius:4px; font-size:11px; font-weight:600; }
.bit-creado    { background:#d1fae5; color:#065f46; }
.bit-editado   { background:#dbeafe; color:#1e40af; }
.bit-eliminado { background:#fee2e2; color:#991b1b; }
.bit-pdf       { background:#ede9fe; color:#5b21b6; }
html[data-theme="dark"] .bit-creado    { background:#064e3b; color:#6ee7b7; }
html[data-theme="dark"] .bit-editado   { background:#1e3a5f; color:#93c5fd; }
html[data-theme="dark"] .bit-eliminado { background:#450a0a; color:#fca5a5; }
html[data-theme="dark"] .bit-pdf       { background:#2e1065; color:#c4b5fd; }
.bit-tabla { width:100%; border-collapse:collapse; font-size:13px; }
.bit-tabla th { background:var(--verde); color:white; padding:8px 10px; text-align:left; font-size:12px; text-transform: uppercase; letter-spacing: .3px; }
.bit-tabla td { padding:7px 10px; border-bottom:1px solid var(--border); vertical-align:top; color:var(--text); }
.bit-tabla tr:hover td { background:rgba(0,0,0,.04); }
html[data-theme="dark"] .bit-tabla tr:hover td { background:rgba(255,255,255,.04); }
/* Tooltip fecha/hora de ingreso en filas del historial */
tr[data-creado] { position:relative; }
tr[data-creado]:hover::after {
  content: attr(data-creado);
  position:absolute; left:50%; transform:translateX(-50%);
  top:-30px; background:#1b4332; color:#fff;
  padding:4px 10px; border-radius:5px; font-size:11px;
  white-space:nowrap; z-index:100; pointer-events:none;
  box-shadow:0 2px 8px rgba(0,0,0,.3);
}

/* ── TOTAL GENERAL BAR ── */
.total-general-bar {
  position: sticky;
  bottom: 0;
  background: var(--verde-d);
  color: white;
  padding: 12px 20px;
  display: flex;
  justify-content: flex-end;
  font-size: 15px;
  margin-top: 14px;
  border-radius: var(--radius);
  box-shadow: 0 -2px 8px rgba(0,0,0,.15);
}

/* ── BADGES ── */
.badge-rol {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .4px;
  line-height: 1.4;
  align-self: flex-start;
}
.badge-admin     { background: rgba(254,243,199,.9); color: #78350f; }
.badge-moderador { background: rgba(219,234,254,.9); color: #1e3a8a; }
.badge-normal    { background: rgba(216,243,220,.9); color: var(--verde-d); }
.badge-desarrollador { background: rgba(237,233,254,.9); color: #4c1d95; }
.badge-puesto {
  background: rgba(255,255,255,.16);
  color: rgba(255,255,255,.9);
  border-radius: 6px;
  white-space: normal;
  text-align: center;
  line-height: 1.35;
  letter-spacing: .2px;
  padding: 3px 8px;
  max-width: 100%;
}

/* ── AVATAR COLORES POR ROL ── */
.avatar-admin     { background: #6d28d9 !important; border-color: #c4b5fd !important; }
.avatar-moderador { background: #1d4ed8 !important; border-color: #93c5fd !important; }
.avatar-normal    { background: var(--verde) !important; border-color: var(--verde-l) !important; }

/* ── FIELD FEEDBACK (éxito / error inline) ── */
.form-control.field-ok    { border-color: #16a34a !important; background: #f0fdf4; }
.form-control.field-error { border-color: #dc2626 !important; background: #fef2f2; }
html[data-theme="dark"] .form-control.field-ok    { background: #12271a; color: var(--text); }
html[data-theme="dark"] .form-control.field-error { background: #2e1518; color: var(--text); }
.field-feedback {
  font-size: 11px;
  font-weight: 500;
  margin-top: 3px;
  display: none;
}
.field-feedback.ok    { color: #16a34a; display: block; }
.field-feedback.error { color: #dc2626; display: block; }
/* Variante flotante: no empuja ni descuadra los demás campos de la misma
   fila (usada en formularios de 2 columnas, como Agregar cliente). */
.field-feedback-float { position: absolute; top: 100%; left: 0; margin-top: 3px; white-space: nowrap; z-index: 2; }

/* ── TOOLTIP USUARIO ── */
.field-hint {
  font-size: 11px;
  color: var(--muted);
  margin-top: 3px;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ── ADMIN ── */
.admin-listas { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 20px; }
.lista-group h4 { font-size: 13px; color: var(--verde-d); margin-bottom: 8px; font-weight: 600; text-transform: capitalize; }
html[data-theme="dark"] .lista-group h4 { color: #6fcf97; }
.lista-group-h4 { cursor: pointer; user-select: none; display: flex; align-items: center; justify-content: space-between; }
.lista-group-h4:hover { opacity: .8; }
.lista-chevron { font-size: 11px; transition: transform .15s; }
.config-list { list-style: none; display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.config-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 10px;
  background: var(--bg);
  border-radius: 6px;
  font-size: 13px;
}
.config-list li.puesto-li {
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  padding: 8px 10px;
}
.puesto-li-nombre { font-weight: 600; }
.puesto-li-acciones { display: flex; align-items: center; gap: 6px; }
.puesto-li-acciones .puesto-area-select { flex: 1; font-size: 12px; padding: 5px 8px; }
.permisos-grid { overflow-x: auto; }
.perm-check { width: 16px; height: 16px; cursor: pointer; accent-color: var(--verde); }

/* ── LOGIN ── */
.login-body {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--verde-d);
  padding: 16px;
  box-sizing: border-box;
}
.login-split {
  display: flex;
  width: 100%;
  max-width: 860px;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0,0,0,.25);
}
.login-panel-brand {
  flex: 1;
  background: linear-gradient(160deg, #163a24, #3c6a35);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px;
  position: relative;
  overflow: hidden;
}
.login-panel-brand::before {
  content: "";
  position: absolute;
  inset: 0;
  opacity: .55;
  background-image: url("/static/img/login-mushrooms-bg.png");
  background-size: cover;
  background-position: center;
  pointer-events: none;
}
.login-panel-brand > * { position: relative; z-index: 1; }
.login-panel-brand .login-logo-img { max-width: 360px; filter: drop-shadow(0 4px 10px rgba(0,0,0,.18)); }
.login-brand-caption { color: #ece7d5; font-size: 18px; font-weight: 400; margin-top: 10px; text-align: center; }
.login-brand-caption::after {
  content: "";
  display: block;
  width: 40px;
  height: 2px;
  background: #d9c530;
  margin: 10px auto 0;
}
.login-input-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0 10px;
  background: var(--surface);
  transition: border .15s;
}
.login-input-wrap:focus-within { border-color: var(--verde); }
.login-input-wrap .form-control { border: none; padding: 7px 0; background: transparent; }
.login-input-wrap .form-control:focus { border: none; }
.login-input-icon { color: var(--muted); flex-shrink: 0; }
.login-input-wrap-pw #togglePassword { margin-left: auto; }
.login-panel-form {
  flex: 1;
  background: white;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 32px;
}
.login-welcome { font-size: 22px; font-weight: 600; color: var(--verde-d); margin: 0 0 4px; text-align: center; }
.login-welcome-sub { font-size: 13px; color: var(--muted); margin: 0 0 24px; text-align: center; }
.login-card {
  background: white;
  border-radius: 12px;
  padding: 24px 36px 36px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 8px 32px rgba(0,0,0,.25);
}
.login-panel-form .login-card {
  box-shadow: none;
  padding: 0;
  max-width: 320px;
}
@media (max-width: 720px) {
  .login-split { flex-direction: column; max-width: 400px; min-height: 0; }
  .login-panel-brand { flex: none; padding: 32px 28px 18px; }
  .login-panel-brand .login-logo-img { max-width: 170px; }
  .login-panel-brand .login-logo { margin-top: 0; margin-bottom: 0; }
  .login-panel-form { padding: 24px; }
  .login-brand-caption { display: none; }
}
.login-logo  { font-size: 48px; text-align: center; margin-bottom: 16px; }
.login-panel-brand .login-logo { margin-top: -25px; }
.login-logo-img { display: block; margin: 0 auto; width: 100%; max-width: 200px; height: auto; }
.login-title { text-align: center; font-size: 22px; color: var(--verde-d); margin-bottom: 4px; }
.login-sub   { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 24px; }
.login-card form .form-group { margin-bottom: 22px; gap: 8px; }
.login-card form .form-group label { font-size: 13px; margin-bottom: 0; }
.login-card form .form-control { padding: 11px 12px; }
.login-card form button[type="submit"] {
  margin-top: 12px;
  box-shadow: 0 4px 14px rgba(57,127,68,.35);
  transition: transform .12s, box-shadow .12s;
}
.login-card form button[type="submit"]:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(57,127,68,.45);
}

.login-remember-row {
  display: block;
  text-align: left;
  margin-bottom: 18px !important;
}
.login-remember-inner {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}
.login-remember-inner input[type="checkbox"] {
  appearance: none;
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  margin: 0;
  cursor: pointer;
  border: 1.5px solid var(--border);
  border-radius: 4px;
  background: white;
  flex-shrink: 0;
  position: relative;
  transition: background .12s, border-color .12s;
}
.login-remember-inner input[type="checkbox"]:checked {
  background: var(--verde);
  border-color: var(--verde);
}
.login-remember-inner input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 1px;
  width: 5px;
  height: 9px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.login-remember-inner span {
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
}
.login-forgot-link {
  display: block;
  text-align: center;
  margin-top: 24px;
  font-size: 13px;
  color: var(--verde);
  text-decoration: underline;
  font-weight: 500;
}
.login-forgot-link:hover { color: var(--verde-d); }

.login-info-box {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 13px;
  color: #166534;
  margin-bottom: 18px;
  line-height: 1.5;
}
.login-back-link {
  display: block;
  text-align: center;
  margin-top: 18px;
  font-size: 13px;
  color: var(--muted);
  text-decoration: none;
}
.login-back-link:hover { text-decoration: underline; color: var(--verde-d); }

/* ── SUB-TABS ── */
.sub-tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 0;
}
.sub-tab {
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  transition: color .15s, border-color .15s;
  border-radius: 0;
  white-space: nowrap;
  text-transform: uppercase;
  letter-spacing: .4px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.tab-icon { width: 16px; height: 16px; flex-shrink: 0; }
.sub-tab:hover { color: var(--verde); }
.sub-tab.active {
  color: var(--verde);
  border-bottom-color: var(--verde);
  font-weight: 600;
}

/* En escritorio el texto de las pestañas inactivas se veía muy tenue;
   se oscurece y engrosa un poco solo aquí (en móvil se deja intacto). */
@media (min-width: 901px) {
  .sub-tab { color: var(--text); font-weight: 600; opacity: .68; }
  .sub-tab:hover { opacity: 1; }
  .sub-tab.active { opacity: 1; color: var(--verde); }

  .sidebar-collapse-btn {
    position: absolute;
    top: 94px;
    right: -14px;
    z-index: 120;
    display: flex;
    width: 30px;
    height: 30px;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 2px solid var(--bg);
    border-radius: 50%;
    background: var(--verde);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 3px 10px rgba(0,0,0,.24);
    transition: background .15s ease, transform .24s ease;
  }
  .sidebar-collapse-btn:hover { background: #2f6d39; }
  .sidebar-collapse-btn:focus-visible { outline: 3px solid rgba(57,127,68,.3); outline-offset: 2px; }
  .sidebar-collapse-btn svg {
    width: 17px;
    height: 17px;
    transition: transform .24s ease;
  }

  html.sidebar-collapsed .sidebar {
    width: 74px;
    min-width: 74px;
  }
  html.sidebar-collapsed .sidebar-brand { padding: 18px 8px 16px; }
  html.sidebar-collapsed .sidebar-logo-completo { display: none; }
  html.sidebar-collapsed .sidebar-logo-compacto { display: block; }
  html.sidebar-collapsed .sidebar-collapse-btn { top: 77px; }
  html.sidebar-collapsed .sidebar-collapse-btn svg { transform: rotate(180deg); }

  html.sidebar-collapsed .sidebar-nav { padding-right: 8px; padding-left: 8px; }
  html.sidebar-collapsed .sidebar-nav a {
    position: relative;
    justify-content: center;
    min-height: 42px;
    padding-right: 0;
    padding-left: 0;
    gap: 0;
  }
  html.sidebar-collapsed .sidebar-nav-label { display: none; }
  html.sidebar-collapsed .sidebar-nav .nav-icon { width: 20px; height: 20px; }

  html.sidebar-collapsed .sidebar-nav a::after {
    content: attr(data-sidebar-label);
    position: absolute;
    top: 50%;
    left: calc(100% + 12px);
    z-index: 130;
    padding: 7px 10px;
    border-radius: 6px;
    background: #1f2922;
    color: #fff;
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0;
    line-height: 1.2;
    text-transform: none;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transform: translateY(-50%) translateX(-4px);
    transition: opacity .12s ease, transform .12s ease;
    box-shadow: 0 4px 12px rgba(0,0,0,.22);
  }
  html.sidebar-collapsed .sidebar-nav a:hover::after,
  html.sidebar-collapsed .sidebar-nav a:focus-visible::after {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
  }

  html.sidebar-collapsed .sidebar-footer { padding: 10px 8px 12px; }
  html.sidebar-collapsed .sidebar-user-row {
    flex-direction: column;
    justify-content: center;
    gap: 8px;
  }
  html.sidebar-collapsed .sidebar-user {
    flex: 0 0 auto;
    justify-content: center;
    width: 44px;
    margin: 0;
    padding: 4px;
  }
  html.sidebar-collapsed .sidebar-user-info { display: none; }
  html.sidebar-collapsed .sidebar-admin-btn { width: 38px; height: 38px; }
  html.sidebar-collapsed .btn-logout {
    width: 40px;
    height: 38px;
    margin: 0 auto;
    padding: 0;
  }
  html.sidebar-collapsed .sidebar-logout-label { display: none; }
}

/* ── ALERTS ── */
.alert { padding: 10px 14px; border-radius: var(--radius); font-size: 13px; margin-bottom: 12px; display: flex; align-items: center; justify-content: space-between; }
.alert-danger  { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }

/* ── Aviso de crédito vencido / mora (Editar factura) ── */
.ef-mora-box { background:#fef2f2; border:1px solid #fca5a5; border-radius:8px; padding:10px 12px; }
.ef-mora-box .ef-mora-titulo { color:#b91c1c; font-weight:600; }
html[data-theme="dark"] .ef-mora-box { background:#4a1a1a; border-color:#b91c1c; }
html[data-theme="dark"] .ef-mora-box .ef-mora-titulo { color:#fca5a5; }

/* ── TOAST ── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--verde-d);
  color: white;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: 13px;
  opacity: 0;
  transition: opacity .3s;
  pointer-events: none;
  z-index: 9999;
}
.toast.show { opacity: 1; }
.toast.error { background: #dc2626; }

.cmp-adjuntos { margin-top: 4px; font-size: 12px; font-weight: 400; }
.cmp-adjuntos a { color: #d8f3dc; text-decoration: none; margin: 0 3px; }
.cmp-adjuntos a:hover { text-decoration: underline; color: #fff; }

/* ════════════════════════════════════════════════════════════
   RESPONSIVE — tablets, iPads, móviles (Android / iOS)
   ════════════════════════════════════════════════════════════ */

/* ── Tablets / iPad / pantallas medianas (≤ 1024px) ── */
@media (max-width: 1024px) {
  .sidebar { width: 195px; min-width: 195px; }
  .main-content { padding: 20px; }
  .stats-col { width: 170px; min-width: 170px; }
}

/* ── Sidebar pasa a menú off-canvas (≤ 900px: tablets en vertical, móviles) ── */
@media (max-width: 900px) {
  .layout { flex-direction: column; }

  .topbar { display: flex; }

  /* El título de la sección ya se muestra en la topbar, así que se oculta
     aquí para no repetirlo dos veces en pantallas chicas. */
  .page-header { display: none; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    height: 100dvh;
    width: 260px;
    min-width: 260px;
    max-width: 82vw;
    transform: translateX(-100%);
    transition: transform .25s ease;
    z-index: 200;
    overflow-y: auto;
  }
  .sidebar.open { transform: translateX(0); }

  .main-content { padding: 16px; width: 100%; }

  /* Formularios: una columna fluida en vez de filas forzadas */
  .form-row { gap: 10px; }
  .form-group { flex: 1 1 220px; min-width: 160px; }

  /* Layout de cosecha (tabla + tarjetas de stats) se apila */
  .cosecha-layout { flex-direction: column; }
  .stats-col {
    width: 100%;
    min-width: 0;
    flex-direction: row;
    flex-wrap: wrap;
  }
  .stat-card { flex: 1 1 150px; }

  /* Columnas de comparación se apilan */
  .cmp-columnas-container { flex-direction: column; }
  .cmp-col-card { width: 100%; }

  .admin-listas { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; }
}

/* ── Móviles (≤ 640px) ── */
@media (max-width: 640px) {
  body { font-size: 13px; }

  .main-content { padding: 14px; }

  .page-header { gap: 10px; }
  .page-header h2 { font-size: 18px; }

  /* Tarjetas y formularios */
  .card-body { padding: 12px; }
  .form-row { flex-direction: column; align-items: stretch; gap: 12px; }
  .form-group { flex: none; min-width: 0; width: 100%; height: auto; }
  .form-group-btn { justify-content: stretch; }
  .form-group-btn .btn { width: 100%; }

  /* Botones de acción en bloque dentro de barras */
  .acciones-bar { flex-direction: column; align-items: stretch; gap: 8px; }
  .acciones-bar > div { display: flex; gap: 8px; }
  .acciones-bar > div .btn { flex: 1; }

  /* Tablas: scroll horizontal explícito con indicación visual */
  .table-responsive { overflow-x: auto; width: 100%; max-width: 100%; -webkit-overflow-scrolling: touch; }
  .table th, .table td { padding: 8px; font-size: 12px; }
  .prod-table th, .prod-table td { padding: 6px 10px; font-size: 12px; }
  .th-check, .td-check { display: table-cell; }

  /* Stats en columna única en pantallas muy angostas */
  .stats-col { flex-direction: column; }
  .stat-card { flex: 1 1 auto; }

  /* Modales ocupan casi toda la pantalla */
  .modal-box { width: 100%; max-width: 96vw; max-height: 92vh; overflow-y: auto; }
  .modal-body { padding: 14px; }
  .modal-footer { flex-wrap: wrap; }
  .modal-footer .btn { flex: 1; }

  /* Campos múltiples (reportes) en columna */
  .multi-field-row { flex-direction: column; align-items: flex-start; gap: 4px; }
  .multi-label { width: auto; }
  .multi-field-row .form-control { width: 100%; }

  /* Sub-tabs: scroll horizontal en vez de desbordar */
  .sub-tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap; }
  .sub-tab { padding: 10px 14px; }

  /* Admin */
  .admin-listas { grid-template-columns: 1fr; }
  .permisos-grid { overflow-x: auto; }

  /* Login: reducir alturas verticales para que quepa sin scroll en pantallas
     de celular más bajas */
  .login-card { padding: 16px 22px 20px; }
  .login-logo-img { max-width: 160px; margin-bottom: 2px; }
  .login-card form .form-group { margin-bottom: 12px; }
  .login-remember-row { margin-bottom: 10px !important; }

  /* Total general / barra inferior */
  .total-general-bar { padding: 10px 14px; font-size: 14px; flex-wrap: wrap; gap: 6px; }

  .alert { flex-wrap: wrap; gap: 8px; }
  .alert button { margin-left: 0 !important; }

  /* Toast a ancho completo en móvil */
  .toast { left: 14px; right: 14px; bottom: 14px; text-align: center; }
}

/* ── Móviles pequeños (≤ 400px) ── */
@media (max-width: 400px) {
  .sidebar-brand img { width: 90px; }
  .stat-icon { font-size: 22px; }
  .stat-value { font-size: 15px; }
}

/* ── Accesibilidad táctil: objetivos de toque más grandes en pantallas táctiles ── */
@media (max-width: 900px) {
  .btn { padding: 10px 16px; }
  .btn-sm { padding: 8px 12px; }
  .form-control { padding: 10px 12px; font-size: 14px; }
  .sub-tab { font-size: 13px; }
}

/* ── TOGGLE MODO OSCURO ── */
.theme-switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.theme-switch-label { font-weight: 600; font-size: 14px; color: var(--text); }
.theme-switch-sub { font-size: 12px; margin-top: 2px; }

.theme-switch {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 26px;
  flex-shrink: 0;
}
.theme-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.theme-switch-slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: #ccc;
  border-radius: 999px;
  transition: background-color .2s;
}
.theme-switch-slider::before {
  position: absolute;
  content: "";
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  border-radius: 50%;
  transition: transform .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.3);
}
.theme-switch input:checked + .theme-switch-slider { background-color: var(--verde); }
.theme-switch input:checked + .theme-switch-slider::before { transform: translateX(20px); }
.theme-switch input:focus-visible + .theme-switch-slider { outline: 2px solid var(--verde); outline-offset: 2px; }


/* ── Sin conexión (soporte offline) ────────────────────────────────────────
   Cuando el navegador detecta que no hay internet, se muestra un aviso fijo
   arriba y se deshabilitan visualmente las acciones de guardar/registrar/
   editar/eliminar (no tiene sentido intentarlas sin conexión: el sitio usa
   una estrategia "primero red", así que sin internet solo puede mostrar la
   última información que ya se había cargado). Ver los botones marcados
   como .btn-primary/.btn-danger/.btn-warning en cada pantalla. */
#offline-banner {
  display: none;
  position: sticky;
  top: 0;
  z-index: 3000;
  background: #b45309;
  color: #fff;
  padding: 8px 14px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
}
body.is-offline .btn-primary,
body.is-offline .btn-danger,
body.is-offline .btn-warning {
  pointer-events: none !important;
  opacity: .45 !important;
  filter: grayscale(40%);
}
