:root {
  --jm-blue: #1E80C8;
  --jm-blue-dark: #1668A3;
  --jm-navy: #0F2A4E;
  --jm-navy-2: #1A3866;
  --jm-gray: #3F3F3F;
  --jm-gray-soft: #6B7280;
  --jm-bg: #F4F6F8;
  --jm-border: #E5E7EB;

  /* ── Medidas de layout (se ajustan por breakpoint más abajo) ── */
  --sidebar-w:    240px;  /* ancho del sidebar fijo         */
  --topbar-h:      58px;  /* alto de la barra superior      */
  --container-max: 1180px; /* ancho máximo del contenido     */
  --container-pad:  24px;  /* padding lateral del contenido  */
}

* { box-sizing: border-box; }

body {
  font-family: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  background: var(--jm-bg);
  color: var(--jm-gray);
  margin: 0;
  padding: 0;
  line-height: 1.45;
}

.container {
  width: 100%;
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 0 var(--container-pad) 32px;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 0 calc(var(--container-pad) * -1) 28px;
  padding: 18px 32px;
  background: linear-gradient(90deg, var(--jm-navy) 0%, var(--jm-navy-2) 100%);
  border-bottom: 4px solid var(--jm-blue);
  color: #fff;
}

header h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: .02em;
  color: #fff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}
.brand-logo {
  width: 44px;
  height: 44px;
  background: #fff;
  border-radius: 8px;
  padding: 4px;
  box-shadow: 0 2px 6px rgba(0,0,0,.15);
  object-fit: contain;
  flex-shrink: 0;
}

.user-bar {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-right: 10px;
  padding: 4px 6px 4px 12px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 999px;
}
.user-email {
  color: #fff;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: .02em;
}
.user-logout {
  background: rgba(255,255,255,0.08);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.25);
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  cursor: pointer;
}
.user-logout:hover { background: rgba(255,255,255,0.18); }

.rol-pill {
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 2px 8px;
  border-radius: 999px;
}
.rol-pill.rol-admin {
  background: #fef3c7;
  color: #92400e;
}

/* Campanita de notificaciones */
.notif-wrapper {
  position: relative;
  display: inline-block;
  margin-right: 10px;
}
.notif-btn {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.25);
  color: #fff;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.notif-btn:hover { background: rgba(255,255,255,0.18); }
.notif-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #dc2626;
  color: #fff;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
  padding: 1px 6px;
  min-width: 16px;
  text-align: center;
  border: 2px solid var(--jm-navy);
  display: none;
}
.notif-badge.show { display: inline-block; }

.notif-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 360px;
  max-height: 480px;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 12px 36px rgba(15,42,78,.25);
  border: 1px solid var(--jm-border);
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 1000;
}
.notif-panel.show { display: flex; }
.notif-panel .head {
  background: #f9fafb;
  padding: 10px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--jm-border);
}
.notif-panel .head h4 {
  margin: 0;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--jm-navy);
}
.notif-panel .head .mark-all {
  background: transparent;
  border: none;
  color: var(--jm-blue);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}
.notif-panel .head .mark-all:hover { text-decoration: underline; }
.notif-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}
.notif-empty {
  padding: 24px 16px;
  text-align: center;
  color: var(--jm-gray-soft);
  font-size: 13px;
  font-style: italic;
}
.notif-item {
  padding: 10px 14px;
  border-bottom: 1px solid var(--jm-border);
  cursor: pointer;
  display: block;
  text-decoration: none;
  color: inherit;
}
.notif-item:hover { background: #f9fafb; }
.notif-item.unread { background: #eaf4fb; }
.notif-item.unread:hover { background: #dbeafe; }
.notif-tipo {
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 1px 7px;
  border-radius: 999px;
  margin-right: 6px;
}
.notif-tipo.mencion     { background: #ede9fe; color: #5b21b6; }
.notif-tipo.responsable { background: #dcfce7; color: #166534; }
.notif-tipo.aprobacion  { background: #fef3c7; color: #92400e; }
.notif-mensaje {
  font-size: 13px;
  color: #1f2937;
  margin: 4px 0 2px;
  line-height: 1.35;
}
.notif-meta {
  font-size: 11px;
  color: var(--jm-gray-soft);
}

/* ============= Layout: sidebar siempre expandido ============= */
body.with-sidebar {
  padding-left: var(--sidebar-w);
}

/* ── Sidebar ──────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  width: var(--sidebar-w);
  background: linear-gradient(180deg, var(--jm-navy) 0%, var(--jm-navy-2) 100%);
  color: #fff;
  z-index: 100;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  border-right: 1px solid rgba(255,255,255,0.07);
}

/* Bloque logo */
.sidebar-logo {
  padding: 16px 18px 14px;
  display: flex;
  align-items: center;
  gap: 11px;
  border-bottom: 1px solid rgba(255,255,255,0.09);
  flex-shrink: 0;
}
.sidebar-logo img {
  width: 36px; height: 36px;
  border-radius: 8px;
  background: #fff;
  padding: 3px;
  object-fit: contain;
  flex-shrink: 0;
}
.sidebar-logo-text {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: rgba(255,255,255,0.9);
  line-height: 1.2;
}
.sidebar-logo-sub {
  font-size: 10px;
  font-weight: 700;
  color: rgba(30,128,200,0.82);
  letter-spacing: .12em;
  text-transform: uppercase;
}

/* Bloque usuario */
.sidebar-user {
  padding: 13px 18px;
  display: flex;
  align-items: center;
  gap: 11px;
  border-bottom: 1px solid rgba(255,255,255,0.09);
  flex-shrink: 0;
}
.sidebar-avatar {
  width: 36px; height: 36px;
  background: rgba(30,128,200,0.32);
  border: 1.5px solid rgba(30,128,200,0.55);
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 800;
  color: #fff;
  flex-shrink: 0;
  letter-spacing: .03em;
}
.sidebar-user-info { min-width: 0; }
.sidebar-user-name {
  font-size: 12.5px; font-weight: 700;
  color: #fff;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-user-role {
  font-size: 10.5px;
  color: rgba(255,255,255,0.48);
  margin-top: 1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Etiquetas de sección */
.sidebar-section-label {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.36);
  padding: 14px 18px 5px;
}

/* Nav */
.sidebar-nav {
  display: flex;
  flex-direction: column;
  flex: 1;
  padding-bottom: 4px;
}
.sidebar-spacer { flex: 1; }

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 18px;
  color: rgba(255,255,255,0.72);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  border-left: 3px solid transparent;
  transition: background .14s, color .14s, border-color .14s;
}
.sidebar-link .icon {
  width: 20px; height: 20px;
  font-size: 14px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  color: rgba(255,255,255,0.42);
  transition: color .14s;
}
.sidebar-link .label { flex: 1; }
.sidebar-link:hover { background: rgba(255,255,255,0.07); color: #fff; }
.sidebar-link:hover .icon { color: rgba(255,255,255,0.75); }
.sidebar-link.active {
  background: rgba(30,128,200,0.22);
  border-left-color: var(--jm-blue);
  color: #fff;
}
.sidebar-link.active .icon { color: var(--jm-blue); }

/* Botón cerrar sesión */
.sidebar-logout {
  padding: 10px 18px 14px;
  border-top: 1px solid rgba(255,255,255,0.09);
  flex-shrink: 0;
}
.sidebar-logout-btn {
  width: 100%;
  display: flex; align-items: center; gap: 9px;
  padding: 8px 12px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 7px;
  color: rgba(255,255,255,0.6);
  font: inherit; font-size: 12.5px; font-weight: 600;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.sidebar-logout-btn:hover { background: rgba(220,38,38,0.18); color: #fca5a5; border-color: rgba(220,38,38,0.3); }

/* Firma */
.sidebar-firma {
  padding: 8px 0 10px;
  display: flex; justify-content: center;
  opacity: .14; transition: opacity .3s;
}
.sidebar-firma:hover { opacity: .45; }
.sidebar-firma img { width: 26px; height: 26px; object-fit: contain; filter: brightness(0) invert(1); }

.sidebar-divider {
  margin: 4px 18px;
  border-top: 1px solid rgba(255,255,255,0.1);
}

/* ── Top bar fija (header en modo sidebar) ─────────────────── */
body.with-sidebar header {
  position: fixed;
  top: 0;
  left: var(--sidebar-w);
  right: 0;
  height: var(--topbar-h);
  z-index: 90;
  background: #fff;
  border-bottom: 1px solid var(--jm-border);
  box-shadow: 0 1px 4px rgba(0,0,0,.05);
  padding: 0 var(--container-pad);
  margin: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: none;
  gap: 12px;
}
body.with-sidebar header h1 {
  font-size: 17px;
  font-weight: 700;
  color: #111827;
  letter-spacing: .01em;
}
body.with-sidebar .brand { gap: 0; }
body.with-sidebar .brand-logo { display: none; }
body.with-sidebar .container { padding-top: calc(var(--topbar-h) + 20px); }
/* Grids más compactos con sidebar presente */
body.with-sidebar .grid { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
@media (min-width: 1024px) and (max-width: 1380px) {
  body.with-sidebar .grid-5col { grid-template-columns: repeat(3, 1fr) !important; }
}

/* Bell en top bar blanca */
body.with-sidebar .notif-wrapper { margin-right: 0; }
body.with-sidebar .notif-btn {
  background: transparent;
  border: none;
  color: #374151;
  border-radius: 9px;
  transition: background .15s;
}
body.with-sidebar .notif-btn:hover { background: #f3f4f6; }
body.with-sidebar .notif-badge { border-color: #fff; }
body.with-sidebar .notif-panel { top: calc(100% + 6px); }

/* Sticky bar de tracking — respeta sidebar y top bar */
body.with-sidebar .sticky-bar { top: var(--topbar-h) !important; left: var(--sidebar-w) !important; }
@media (max-width: 1023px) {
  body.with-sidebar .sticky-bar { left: 0 !important; }
}

/* User bar simplificada en top bar */
body.with-sidebar .user-bar {
  background: transparent;
  border: none;
  padding: 0;
  gap: 6px;
}
body.with-sidebar .user-email { color: #6b7280; font-size: 12px; }
body.with-sidebar .rol-pill { display: none; }
body.with-sidebar .user-logout { display: none; }

/* Iconos FontAwesome dentro de botones/badges con un poco de espacio */
.row-btn i { font-size: 13px; }
.row-edit i { color: var(--jm-blue); }
.row-del i { color: #b91c1c; }
.user-logout i { margin-right: 2px; }
.user-email i { margin-right: 2px; opacity: 0.85; }
.notif-btn i { font-size: 16px; }
.archivo-uploader i { margin-right: 2px; }
.archivos-label i { color: var(--jm-blue); margin-right: 4px; }
.resp-label i, .chat-label i { color: var(--jm-blue); margin-right: 4px; }
.archivo-item .icono i { font-size: 16px; color: var(--jm-blue); }

.badge {
  background: var(--jm-blue);
  color: #fff;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .03em;
  text-transform: uppercase;
}

.card {
  background: #fff;
  border-radius: 10px;
  padding: 22px 26px;
  margin-bottom: 20px;
  box-shadow: 0 1px 3px rgba(15,42,78,.08);
  border-top: 3px solid var(--jm-blue);
}

.card h2 {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--jm-navy);
  margin: 0 0 18px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--jm-border);
  font-weight: 700;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px 18px;
}

.field {
  display: flex;
  flex-direction: column;
}

.field.full {
  grid-column: 1 / -1;
}

label {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
  color: #374151;
}

label .req {
  color: #dc2626;
  margin-left: 2px;
}

input, select, textarea {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--jm-blue);
  box-shadow: 0 0 0 3px rgba(30,128,200,.18);
}

input[readonly] {
  background: #f3f4f6;
  color: #6b7280;
}

textarea { min-height: 70px; resize: vertical; }

.actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 8px;
}

button {
  font: inherit;
  padding: 9px 22px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-weight: 600;
  transition: background .15s;
}

.primary {
  background: var(--jm-blue);
  color: #fff;
  letter-spacing: .03em;
}
.primary:hover { background: var(--jm-blue-dark); }
button.primary:disabled { background: #9ca3af; cursor: not-allowed; }

.secondary {
  background: #fff;
  color: #374151;
  border: 1px solid #d1d5db;
}
.secondary:hover { background: #f9fafb; }

.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  padding: 12px 18px;
  border-radius: 6px;
  color: #fff;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
  opacity: 0;
  transform: translateY(-10px);
  transition: opacity .25s, transform .25s;
  pointer-events: none;
  z-index: 1000;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { background: #15803d; }
.toast.error { background: #b91c1c; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th, td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid #e5e7eb;
}
th {
  background: #f9fafb;
  font-weight: 600;
  color: #374151;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .03em;
}
tbody tr:hover { background: #f9fafb; }
tbody tr[data-numero] { cursor: pointer; }
tbody tr[data-numero]:hover { background: #eaf4fb; }

.empty {
  padding: 24px;
  text-align: center;
  color: #6b7280;
  font-style: italic;
}

.config-error {
  background: #fee2e2;
  border: 1px solid #fca5a5;
  color: #991b1b;
  padding: 14px 18px;
  border-radius: 6px;
  margin-bottom: 20px;
}

.hint {
  font-size: 12px;
  margin-top: 4px;
  min-height: 14px;
  color: #6b7280;
}
.hint.ok { color: #15803d; }
.hint.warn { color: #b45309; }

.link-btn {
  display: inline-block;
  padding: 6px 14px;
  margin-right: 8px;
  border-radius: 6px;
  background: #fff;
  color: var(--jm-blue);
  border: 1px solid var(--jm-blue);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
}
.link-btn:hover { background: #eff6ff; }

.auto-filled {
  background: #eaf4fb !important;
  border-color: #9ec9e8 !important;
}

.producto-subtitle {
  font-size: 13px;
  font-weight: 600;
  color: #374151;
  margin: 8px 0 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.producto2-block {
  border-top: 1px dashed #e5e7eb;
  margin-top: 18px;
  padding-top: 14px;
}

.link-action {
  background: none;
  border: none;
  color: #b91c1c;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  padding: 4px 8px;
  border-radius: 4px;
}
.link-action:hover { background: #fee2e2; }

.total-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(90deg, var(--jm-navy) 0%, var(--jm-navy-2) 100%);
  color: #fff;
  padding: 12px 18px;
  border-radius: 8px;
  margin-top: 14px;
  border-left: 4px solid var(--jm-blue);
}
.total-bar-label {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: .06em;
  font-weight: 600;
  opacity: .9;
}
.total-bar-value {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: .02em;
}

.checks-group {
  margin-top: 18px;
  padding: 8px 18px 14px;
  border: 1px solid var(--jm-border);
  border-radius: 8px;
  background: #fafbfc;
}
.checks-group legend {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--jm-navy);
  padding: 0 8px;
}
.checks-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 6px 18px;
  align-items: center;
}
.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 500;
  color: #1f2937;
  cursor: pointer;
  padding: 6px 4px;
  user-select: none;
}
.check input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--jm-blue);
  cursor: pointer;
}
.check:hover { color: var(--jm-blue-dark); }

.row-actions {
  white-space: nowrap;
  text-align: center;
}
.row-btn {
  background: transparent;
  border: 1px solid var(--jm-border);
  border-radius: 6px;
  padding: 4px 9px;
  font-size: 14px;
  cursor: pointer;
  margin: 0 2px;
  transition: background .15s, border-color .15s;
}
.row-btn:hover { background: #f3f4f6; }
.row-edit { color: var(--jm-blue); border-color: var(--jm-blue); }
.row-edit:hover { background: #eaf4fb; }
.row-del { color: #b91c1c; border-color: #fca5a5; }
.row-del:hover { background: #fee2e2; }

.status-pill {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  white-space: nowrap;
}
.status-creado       { background: #e0f2fe; color: #075985; }
.status-confirmacion { background: #ede9fe; color: #5b21b6; }
.status-proceso      { background: #fef3c7; color: #92400e; }
.status-completado   { background: #dcfce7; color: #166534; }
.status-terminado    { background: #064e3b; color: #ffffff; }
.status-cancelado    { background: #fee2e2; color: #991b1b; }
.status-rechazado    { background: #fff1f2; color: #be123c; border: 1px solid #fda4af; }
.status-stand-by     { background: #fff7ed; color: #c2410c; border: 1px solid #fed7aa; }
.status-default      { background: #e5e7eb; color: #374151; }

.editing-banner {
  background: #fef3c7;
  color: #92400e;
  border: 1px solid #fcd34d;
  border-left: 4px solid #d97706;
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 12px;
  font-weight: 600;
  font-size: 14px;
}

/* ============= Botón hamburguesa móvil ============= */
.sidebar-hamburger {
  display: none;
  background: rgba(0,0,0,0.06);
  border: none;
  color: #374151;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-right: 8px;
}
.sidebar-hamburger:hover { background: rgba(0,0,0,0.11); }

/* Overlay oscuro cuando sidebar abierto en móvil */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.50);
  z-index: 98;
}
.sidebar-overlay.show { display: block; }

/* =====================================================================
   RESPONSIVE — el layout se adapta solo al tamaño de pantalla.
   Todo se controla desde las variables de :root (--sidebar-w,
   --container-max, --container-pad), así que basta redefinirlas
   por breakpoint y el resto del CSS se acomoda automáticamente.

   ≥1920px  Monitor grande / 4K   sidebar 264 · contenido 1560
   ≥1600px  Monitor amplio        sidebar 252 · contenido 1400
   ≥1381px  Escritorio estándar   sidebar 240 · contenido 1180  (base)
   ≥1280px  Laptop grande         sidebar 240 · contenido fluido
   ≥1024px  Laptop chica          sidebar 208 · contenido fluido
   <1024px  Tablet / celular      sidebar oculto (hamburguesa)
   ===================================================================== */

/* ── Monitores grandes: aprovechar el espacio disponible ─────────── */
@media (min-width: 1920px) {
  :root {
    --sidebar-w:     264px;
    --container-max: 1560px;
    --container-pad:   34px;
  }
  body.with-sidebar .grid { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
}

@media (min-width: 1600px) and (max-width: 1919px) {
  :root {
    --sidebar-w:     252px;
    --container-max: 1400px;
    --container-pad:   30px;
  }
  body.with-sidebar .grid { grid-template-columns: repeat(auto-fit, minmax(215px, 1fr)); }
}

/* ── Laptops: el contenido usa todo el ancho útil ────────────────── */
@media (min-width: 1024px) and (max-width: 1380px) {
  :root { --container-max: 100%; }
}

@media (min-width: 1024px) and (max-width: 1279px) {
  :root {
    --sidebar-w:     208px;
    --container-pad:   18px;
  }
  .sidebar-logo   { padding: 14px 14px 12px; gap: 9px; }
  .sidebar-user   { padding: 11px 14px; gap: 9px; }
  .sidebar-link   { padding: 8px 14px; font-size: 12.5px; gap: 10px; }
  .sidebar-logout { padding: 9px 14px 12px; }
  .sidebar-section-label { padding: 12px 14px 4px; }
}

/* ── Tablet y abajo: sidebar se vuelve cajón deslizante ──────────── */
@media (max-width: 1023px) {
  :root {
    --sidebar-w:     240px;   /* ancho del cajón cuando se abre */
    --container-max: 100%;
    --container-pad:   16px;
  }

  body.with-sidebar        { padding-left: 0 !important; }
  body.with-sidebar header { left: 0 !important; }

  .sidebar {
    transform: translateX(-100%);
    transition: transform .25s ease, box-shadow .25s ease;
    z-index: 99;
  }
  .sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: 8px 0 32px rgba(0,0,0,.4);
  }
  .sidebar-hamburger { display: inline-flex; }

  /* Sin sidebar el contenido respira: grids con más columnas */
  body.with-sidebar .grid { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

  /* Cualquier tabla ancha se desplaza dentro de su contenedor,
     nunca empuja el ancho de la página */
  .table-responsive, .table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
}

/* ── Celulares ───────────────────────────────────────────────────── */
@media (max-width: 640px) {
  :root { --container-pad: 12px; }

  /* Header compacto */
  header h1        { font-size: 15px; }
  .brand           { gap: 8px; }
  .brand-logo      { width: 34px; height: 34px; }
  .user-email      { display: none; }
  .rol-pill        { display: none; }
  .badge           { font-size: 11px; padding: 4px 11px; }

  /* Cards con menos aire lateral */
  .card    { padding: 15px 13px; }
  .card h2 { font-size: 12px; margin-bottom: 12px; }

  /* Formularios en una sola columna… */
  .grid:not(.grid-5col),
  body.with-sidebar .grid:not(.grid-5col) { grid-template-columns: 1fr !important; }
  /* …salvo los campos numéricos cortos, que caben de dos en dos */
  .grid-5col,
  body.with-sidebar .grid-5col { grid-template-columns: repeat(2, 1fr) !important; }

  /* Campos a 16px: evita que iOS haga zoom al enfocar un input */
  input, select, textarea { font-size: 16px; padding: 10px 12px; }

  /* Botones cómodos para el dedo */
  button           { padding: 11px 20px; min-height: 44px; }
  .actions         { flex-wrap: wrap; gap: 8px; }
  .actions button  { flex: 1 1 140px; }
  .row-btn         { padding: 7px 11px; min-height: 36px; }

  /* Tablas: desplazamiento horizontal de borde a borde */
  .table-responsive, .table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 calc(var(--container-pad) * -1);
    padding: 0 var(--container-pad);
  }
  table { min-width: 520px; }

  /* Aviso flotante abajo, ancho completo */
  .toast { top: auto; bottom: 16px; right: 12px; left: 12px; text-align: center; }

  /* Panel de notificaciones a lo ancho de la pantalla */
  .notif-panel { width: calc(100vw - 24px); right: -8px; max-height: 70vh; }

  /* Barra de total apilada */
  .total-bar { flex-direction: column; align-items: flex-start; gap: 4px; }

  .checks-row { grid-template-columns: 1fr 1fr; }
}

/* ── Celulares chicos ────────────────────────────────────────────── */
@media (max-width: 420px) {
  header h1       { font-size: 13.5px; }
  .checks-row     { grid-template-columns: 1fr; }
  .card           { padding: 13px 11px; }
  .actions        { flex-direction: column; }
  .actions button { width: 100%; flex: none; }
}

/* ── Impresión: sin sidebar ni barras ────────────────────────────── */
@media print {
  .sidebar, .sidebar-overlay, .sidebar-hamburger,
  .notif-wrapper, .actions, .toast { display: none !important; }
  body.with-sidebar        { padding-left: 0 !important; }
  body.with-sidebar header { position: static !important; left: 0 !important; }
  body.with-sidebar .container { padding-top: 0 !important; }
  .card { box-shadow: none; border: 1px solid #d1d5db; break-inside: avoid; }
}
