:root {
  /* Marca Castelló — granate como color primario/interactivo */
  --azul: #782020;
  --azul-osc: #5c1818;
  --primario: #782020;
  --acento: #AB2328;   /* rojo Pantone 7621C — logo y detalles puntuales */
  --oro: #D7BC8C;      /* dorado — acentos finos */
  --azul-info: #2563eb; /* azul "info" reservado para el badge de estado "en progreso" (no es color de marca) */
  --verde: #16a34a;
  --rojo: #dc2626;
  --naranja: #ea580c;
  --amarillo: #ca8a04;
  --gris: #6b7280;
  --bg: #f4f6f9;
  --texto: #1f2937;
  --borde: #e2e8f0;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--texto);
}

a { color: var(--azul); text-decoration: none; }
a:hover { text-decoration: underline; }

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px;
  background: #0d0605;
  background-image: linear-gradient(180deg, #170a09 0%, #000 100%);
  color: #e5e7eb;
  flex-shrink: 0;
  padding: 1.25rem 0;
}
.sidebar .brand {
  font-weight: 700;
  font-size: 1.05rem;
  padding: 0 1.25rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,0.12);
  margin-bottom: 0.75rem;
  text-align: center;
}
.sidebar .brand img { height: 26px; display: block; margin: 0 auto; }
.sidebar .brand-nombre {
  margin-top: 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #e5e7eb;
}
.sidebar nav a {
  display: block;
  position: relative;
  padding: 0.6rem 1.25rem;
  color: #cbd5e1;
  font-size: 0.92rem;
  transition: background-color 0.25s ease, color 0.25s ease, padding-left 0.25s ease;
}
/* Franja fina dorada pegada al borde izquierdo: oculta en reposo (escala 0),
   "crece" verticalmente al pasar el ratón, y se queda marcada de forma
   permanente en la sección activa (mismo selector que el fondo granate). */
.sidebar nav a::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--oro);
  transform: scaleY(0);
  transition: transform 0.25s ease;
}
.sidebar nav a:hover, .sidebar nav a.active {
  background: var(--azul);
  color: #fff;
  text-decoration: none;
  padding-left: 1.6rem;
}
.sidebar nav a:hover::before, .sidebar nav a.active::before {
  transform: scaleY(1);
}
.sidebar .user-box {
  margin-top: 1.5rem;
  padding: 0.9rem 1.25rem;
  border-top: 1px solid rgba(255,255,255,0.12);
  font-size: 0.85rem;
  color: #9ca3af;
}
.sidebar .user-box strong { color: #f3f4f6; display: block; }
.sidebar .logout { margin-top: 0.5rem; display: inline-block; color: #fca5a5; font-size: 0.85rem; }

.main { flex: 1; padding: 1.5rem 2rem; max-width: 1440px; }

h1, h2, h3 { margin-top: 0; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 1.25rem; flex-wrap: wrap; gap: 0.75rem;
}

.btn {
  display: inline-block;
  background: var(--azul);
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: var(--azul-osc); text-decoration: none; }
.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.8rem; }
.btn-secondary { background: #6b7280; }
.btn-secondary:hover { background: #4b5563; }
.btn-success { background: var(--verde); }
.btn-danger { background: var(--rojo); }
.btn-outline { background: transparent; border: 1px solid var(--borde); color: var(--texto); }

.card {
  background: white;
  border: 1px solid var(--borde);
  border-radius: 10px;
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.grid { display: grid; gap: 1rem; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 900px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

.stat {
  text-align: left;
}
.stat .num { font-size: 1.9rem; font-weight: 700; }
.stat .label { color: var(--gris); font-size: 0.85rem; }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
table th, table td { text-align: left; padding: 0.55rem 0.6rem; border-bottom: 1px solid var(--borde); }
table th { color: var(--gris); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; }
table th a { color: var(--gris); text-decoration: none; }
table th a:hover { color: var(--primario); }
table th.th-sorted { color: var(--primario); background: #faeeed; }
table tr:hover { background: #f8fafc; }

/* Tabla de órdenes de trabajo: el título necesita más espacio y las fechas
   (planificada / creada) deben verse siempre en una sola línea. Si no caben
   todas las columnas, se desplaza en horizontal en vez de aplastarlas. */
.tabla-scroll { overflow-x: auto; }
.tabla-ordenes th:nth-child(2),
.tabla-ordenes td:nth-child(2) { min-width: 220px; }
.tabla-ordenes th:nth-child(9),
.tabla-ordenes td:nth-child(9),
.tabla-ordenes th:nth-child(10),
.tabla-ordenes td:nth-child(10) { white-space: nowrap; }

.pagination-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--borde);
}
.pagination-info { font-size: 0.85rem; color: var(--gris); }
.pagination-controls { display: flex; gap: 0.35rem; align-items: center; flex-wrap: wrap; }
.pg-btn {
  display: inline-block;
  min-width: 2rem;
  text-align: center;
  padding: 0.4rem 0.7rem;
  border-radius: 6px;
  border: 1px solid var(--borde);
  background: white;
  color: var(--texto);
  font-size: 0.85rem;
  text-decoration: none;
  cursor: pointer;
}
.pg-btn:hover { background: #f1f5f9; text-decoration: none; }
.pg-active, .pg-active:hover { background: var(--azul); border-color: var(--azul); color: white; }
.pg-disabled { color: #cbd5e1; cursor: default; background: #f8fafc; }
.pg-disabled:hover { background: #f8fafc; }
.pg-ellipsis { padding: 0.4rem 0.3rem; color: var(--gris); font-size: 0.85rem; }
@media (max-width: 600px) {
  .pagination-bar { flex-direction: column; align-items: flex-start; }
}

.badge {
  display: inline-block; padding: 0.2rem 0.6rem; border-radius: 999px;
  font-size: 0.75rem; font-weight: 600; color: white;
}
.badge-pendiente { background: var(--gris); }
.badge-asignada { background: var(--amarillo); }
.badge-en_progreso { background: var(--azul-info); } /* se conserva azul: es un color de estado, no de marca */
.badge-completada { background: var(--verde); }
.badge-cancelada { background: var(--rojo); }

.badge-baja { background: #94a3b8; }
.badge-media { background: var(--amarillo); }
.badge-alta { background: var(--naranja); }
.badge-urgente { background: var(--rojo); }

.badge-ubicacion { background: #475569; }

.badge-vigente { background: var(--verde); }
.badge-aviso { background: var(--naranja); }
.badge-caducado { background: var(--rojo); }
.badge-sustituido { background: var(--azul-info); }
.badge-devuelto { background: #94a3b8; }

/* Origen de una tarea: hecha en el momento (móvil) vs. añadida/corregida después */
.badge-origen-movil { background: var(--verde); }
.badge-origen-manual { background: var(--naranja); }

form .field { margin-bottom: 1rem; }
form label { display: block; margin-bottom: 0.3rem; font-size: 0.85rem; font-weight: 600; color: #374151; }
form input, form select, form textarea {
  width: 100%; padding: 0.55rem 0.7rem; border: 1px solid var(--borde); border-radius: 6px;
  font-size: 0.92rem; font-family: inherit;
}
form textarea { resize: vertical; min-height: 80px; }
.form-row { display: flex; gap: 1rem; }
.form-row .field { flex: 1; }

.flash { padding: 0.75rem 1rem; border-radius: 6px; margin-bottom: 1rem; font-size: 0.9rem; }
.flash-success { background: #dcfce7; color: #166534; }
.flash-danger { background: #fee2e2; color: #991b1b; }
.flash-warning { background: #fef3c7; color: #92400e; }
.flash-info { background: #dbeafe; color: #1e40af; }

.login-page {
  display: flex; align-items: center; justify-content: center; min-height: 100vh;
  background: #0d0605;
  background-image: linear-gradient(160deg, #1a0a09 0%, #000 100%);
}
.login-box {
  background: white; padding: 2.5rem; border-radius: 12px; width: 360px; text-align: center;
}
.login-box h1 { text-align: center; margin-bottom: 1.5rem; font-size: 1.3rem; }
.login-box .logo { height: 34px; margin-bottom: 0.9rem; }
.login-box .logo-underline { height: 3px; width: 40px; background: var(--oro); margin: 0 auto 1.4rem; border-radius: 2px; }
.login-hint { font-size: 0.78rem; color: var(--gris); margin-top: 1.2rem; line-height: 1.5; text-align: center; }

.empty-state { text-align: center; padding: 2.5rem; color: var(--gris); }

.bar-chart { display: flex; flex-direction: column; gap: 0.6rem; }
.bar-row { display: flex; align-items: center; gap: 0.6rem; font-size: 0.85rem; }
.bar-row .bar-label { width: 130px; flex-shrink: 0; color: var(--gris); }
.bar-row .bar-track { flex: 1; background: #eef2f7; border-radius: 4px; height: 10px; overflow: hidden; }
.bar-row .bar-fill { height: 100%; border-radius: 4px; background: var(--azul); }
.bar-row .bar-value { width: 40px; text-align: right; font-weight: 600; }

.filters { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
/* Usar form .filters para superar la especificidad de "form select { width:100% }" */
form .filters select,
form .filters input,
.filters select,
.filters input {
  width: auto;
  flex: 0 0 auto;
  min-width: 130px;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--borde);
  border-radius: 6px;
  font-size: 0.85rem;
}

/* Resalta visualmente los campos de filtro que tienen un valor seleccionado */
form select.filtro-activo,
form input.filtro-activo,
select.filtro-activo,
input.filtro-activo {
  background: #f1d1d0;
  border-color: var(--azul);
}

.timeline { border-left: 2px solid var(--borde); padding-left: 1rem; margin-left: 0.4rem; }
.timeline-item { margin-bottom: 1rem; position: relative; }
.timeline-item::before {
  content: ""; position: absolute; left: -1.5rem; top: 0.25rem; width: 8px; height: 8px;
  background: var(--azul); border-radius: 50%;
}
.timeline-meta { font-size: 0.75rem; color: var(--gris); }

.text-muted { color: var(--gris); }
.text-sm { font-size: 0.85rem; }
.mt-0 { margin-top: 0; }
.detail-grid { display: grid; grid-template-columns: 3fr 1fr; gap: 1.25rem; }
@media (max-width: 900px) { .detail-grid { grid-template-columns: 1fr; } }

/* ----------------------------------------------------------- Calendario --- */
.calendario-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.4rem;
}
.calendario-cabecera {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--gris);
  text-transform: uppercase;
  margin-bottom: 0.4rem;
  text-align: center;
}
.calendario-dia {
  min-height: 110px;
  min-width: 0; /* evita que un título largo sin espacios ensanche la columna y descuadre la cuadrícula del mes */
  border: 1px solid var(--borde);
  border-radius: 8px;
  padding: 0.4rem;
  background: #fafbfc;
  display: flex;
  flex-direction: column;
  margin-bottom: 0.4rem;
}
.calendario-dia-vacio {
  background: transparent;
  border: none;
}
.calendario-dia.calendario-hoy {
  border-color: var(--azul);
  background: #faeeed;
}
.calendario-dia-numero {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--gris);
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.3rem;
}
.calendario-add {
  background: var(--azul);
  color: white;
  border-radius: 4px;
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  line-height: 1;
  text-decoration: none;
}
.calendario-add:hover { background: var(--azul-osc); text-decoration: none; }
.calendario-ordenes {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  overflow-y: auto;
  max-height: 110px;
}
.calendario-chip {
  display: block;
  font-size: 0.72rem;
  padding: 0.25rem 0.45rem;
  border-radius: 4px;
  color: white;
  /* sin background fijo: lo pone el badge-* de prioridad */
  cursor: grab;
  line-height: 1.3;
}
.calendario-chip:hover { text-decoration: none; opacity: 0.85; }
.chip-titulo {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip-sub {
  font-size: 0.67rem;
  opacity: 0.88;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Orden completada — vista día del calendario */
.orden-dia-card.orden-completada {
  border-color: var(--verde);
  background: #f0fdf4;
}
.orden-dia-card.orden-completada .orden-dia-titulo { color: var(--verde); }

/* Fila completada en la tabla de órdenes */
.fila-completada td { background: #f0fdf4; }
tr.fila-completada:hover td { background: #dcfce7; }

/* Fila con una tarea abierta del usuario actual (bloquea iniciar cualquier
   otra hasta cerrarla) — resaltada en rojo para encontrarla y entrar de un
   vistazo, sin tener que leer fila por fila. */
.fila-tarea-abierta td { background: #fee2e2; border-top: 1px solid #fca5a5; border-bottom: 1px solid #fca5a5; }
.fila-tarea-abierta td:first-child { border-left: 3px solid var(--rojo); }
tr.fila-tarea-abierta:hover td { background: #fecaca; }
.badge-tarea-abierta {
  display: inline-block; margin-left: 0.4rem; padding: 0.15rem 0.5rem; border-radius: 999px;
  font-size: 0.72rem; font-weight: 600; color: white; background: var(--rojo); white-space: nowrap;
}

/* Botón de dictado por voz (static/js/dictado-voz.js), debajo de un textarea */
.btn-dictado-voz {
  display: inline-block; margin-top: 0.4rem; padding: 0.4rem 0.8rem; border-radius: 6px;
  border: 1px solid var(--borde); background: #fff; color: var(--texto);
  font-size: 0.82rem; font-weight: 600; cursor: pointer;
}
.btn-dictado-voz:hover { background: #f8fafc; }
.btn-dictado-voz.btn-dictado-grabando {
  background: var(--rojo); border-color: var(--rojo); color: #fff;
  animation: dictado-pulso 1.1s ease-in-out infinite;
}
@keyframes dictado-pulso {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.45); }
  50% { box-shadow: 0 0 0 6px rgba(220, 38, 38, 0); }
}

.calendario-dia[ondragover] { transition: background 0.15s; }
.calendario-dia.drag-over { background: #f1d1d0; }

/* -------------------------------------------------------- Fotos de orden --- */
.foto-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.75rem;
}
.foto-item {
  border: 1px solid var(--borde);
  border-radius: 8px;
  overflow: hidden;
  background: white;
}
.foto-item img {
  width: 100%;
  height: 110px;
  object-fit: cover;
  display: block;
}
.foto-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.35rem 0.5rem;
  font-size: 0.75rem;
  color: var(--gris);
}
.btn-link-danger {
  background: none;
  border: none;
  color: var(--rojo);
  font-size: 0.75rem;
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}

/* -------------------------------------------------------- Almacén --- */
.almacen-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem;
}
@media (max-width: 900px) { .almacen-cards { grid-template-columns: 1fr; } }

.almacen-card {
  display: block;
  background: white;
  border: 2px solid var(--borde);
  border-radius: 12px;
  padding: 1.5rem;
  text-decoration: none;
  color: var(--texto);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.almacen-card:hover {
  border-color: var(--azul);
  box-shadow: 0 4px 16px rgba(120,32,32,0.16);
  text-decoration: none;
  color: var(--texto);
}
.almacen-card-icon { font-size: 2.5rem; margin-bottom: 0.75rem; }
.almacen-card-titulo { font-size: 1.15rem; font-weight: 700; margin-bottom: 0.6rem; }
.almacen-card-stats { color: var(--gris); font-size: 0.88rem; line-height: 1.8; }
.almacen-card-barra { margin-top: 1rem; }
.almacen-card-barra-track {
  background: #eef2f7;
  border-radius: 4px;
  height: 7px;
  margin-top: 0.3rem;
  overflow: hidden;
}
.almacen-card-barra-fill {
  height: 100%;
  border-radius: 4px;
  background: var(--rojo);
  transition: width 0.5s ease;
  min-width: 0;
}
.almacen-card-barra-fill.empty { background: var(--verde); }

/* Estanterías grid */
.estanteria-scroll { overflow-x: auto; padding-bottom: 0.75rem; }
.estanteria-container { display: inline-block; }

.estanteria-header-row {
  display: flex;
  margin-left: 36px;
  margin-bottom: 2px;
}
.estanteria-col-label {
  width: 36px;
  height: 22px;
  text-align: center;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--gris);
  text-transform: uppercase;
  flex-shrink: 0;
}

.estanteria-row {
  display: flex;
  align-items: center;
  margin-bottom: 2px;
}
.estanteria-nivel-label {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--gris);
  background: #f8fafc;
  border-radius: 4px;
  margin-right: 0;
}

.hueco {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: 5px;
  margin: 1px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  transition: transform 0.1s, box-shadow 0.1s;
}
.hueco-vacio {
  background: #dcfce7;
  border: 1px solid #86efac;
}
.hueco-vacio:hover { background: #bbf7d0; }
.hueco-ocupado {
  background: #fee2e2;
  border: 1px solid #fca5a5;
  cursor: pointer;
  color: #991b1b;
}
.hueco-ocupado:hover {
  background: #fecaca;
  transform: scale(1.12);
  box-shadow: 0 2px 8px rgba(220,38,38,0.25);
  z-index: 1;
  position: relative;
}

/* Modal almacén */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-box {
  background: white;
  border-radius: 12px;
  padding: 1.5rem;
  max-width: 460px;
  width: 92%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  animation: modal-in 0.15s ease;
}
@keyframes modal-in {
  from { transform: scale(0.95); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1rem;
}
.modal-header h2 { margin: 0; font-size: 1.05rem; }
.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.5rem;
  color: var(--gris);
  padding: 0;
  line-height: 1;
  flex-shrink: 0;
}
.modal-close:hover { color: var(--rojo); }

.modal-material-item {
  padding: 0.75rem;
  border: 1px solid var(--borde);
  border-radius: 8px;
  margin-bottom: 0.6rem;
}
.modal-material-item:last-child { margin-bottom: 0; }
.modal-material-codigo { font-size: 0.75rem; color: var(--gris); margin-bottom: 0.15rem; }
.modal-material-nombre { font-weight: 600; margin-bottom: 0.2rem; font-size: 0.95rem; }
.modal-material-stock { font-size: 0.82rem; color: var(--gris); }
.stock-bajo { color: var(--rojo) !important; font-weight: 600; }

/* ================================================================= FOTOS UPLOAD === */
.foto-upload-opciones {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.foto-upload-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.55rem 1rem;
  border: 1.5px solid var(--borde);
  border-radius: 8px;
  background: white;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--texto);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  user-select: none;
}
.foto-upload-btn:hover {
  border-color: var(--azul);
  background: #faeeed;
  color: var(--azul);
}
.foto-upload-camara {
  border-color: var(--verde);
  color: var(--verde);
}
.foto-upload-camara:hover {
  background: #dcfce7;
  border-color: var(--verde);
  color: var(--verde);
}

/* ========================================================= FOTO PREVIEW GRID === */
.foto-preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 0.5rem;
  margin-top: 0.5rem;
}
.foto-preview-item {
  position: relative;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--borde);
  background: #f8fafc;
}
.foto-preview-item img {
  width: 100%;
  height: 100px;
  object-fit: cover;
  display: block;
}

/* ============================================================= CALENDARIO TABS === */
.vista-tabs {
  display: flex;
  border: 1px solid var(--borde);
  border-radius: 6px;
  overflow: hidden;
}
.vista-tab {
  padding: 0.4rem 0.9rem;
  font-size: 0.85rem;
  color: var(--gris);
  text-decoration: none;
  background: white;
  border-right: 1px solid var(--borde);
  transition: background 0.1s;
}
.vista-tab:last-child { border-right: none; }
.vista-tab:hover { background: #f8fafc; text-decoration: none; color: var(--texto); }
.vista-tab.activa { background: var(--azul); color: white; font-weight: 600; }

/* Número de día en mes — enlace a vista día */
.calendario-dia-link { color: var(--texto); font-size: 0.8rem; font-weight: 600; }
.calendario-dia-link:hover { color: var(--azul); text-decoration: none; }

/* ─────────────── Vista DÍA ─────────────── */
.orden-dia-card {
  padding: 0.85rem;
  border: 1px solid var(--borde);
  border-radius: 8px;
  margin-bottom: 0.6rem;
  transition: box-shadow 0.15s;
}
.orden-dia-card:last-child { margin-bottom: 0; }
.orden-dia-card:hover { box-shadow: 0 2px 10px rgba(0,0,0,0.07); }
.orden-dia-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.4rem;
  flex-wrap: wrap;
}
.orden-dia-titulo {
  font-weight: 600;
  font-size: 0.97rem;
  color: var(--texto);
  flex: 1;
  min-width: 0;
}
.orden-dia-titulo:hover { color: var(--azul); text-decoration: none; }
.orden-dia-badges { display: flex; gap: 0.35rem; flex-shrink: 0; flex-wrap: wrap; }
.orden-dia-meta {
  display: flex;
  gap: 0.85rem;
  font-size: 0.82rem;
  color: var(--gris);
  flex-wrap: wrap;
}
.orden-dia-desc { font-style: italic; }

/* ─────────────── Vista SEMANA ─────────────── */
.semana-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 0.5rem; }
.semana-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(120px, 1fr));
  gap: 0.5rem;
  min-width: 700px;
}
.semana-col {
  border: 1px solid var(--borde);
  border-radius: 8px;
  overflow: hidden;
  background: white;
}
.semana-hoy { border-color: var(--azul); border-width: 2px; }
.semana-col-header {
  padding: 0.45rem 0.4rem;
  text-align: center;
  border-bottom: 1px solid var(--borde);
  background: #f8fafc;
}
.semana-dia-nombre {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--gris);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.semana-dia-num { font-size: 1.2rem; font-weight: 700; color: var(--texto); line-height: 1.2; }
.semana-num-hoy { color: var(--azul); }
.semana-col-body {
  padding: 0.4rem;
  min-height: 130px;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.semana-col-body.drag-over { background: #f1d1d0; transition: background 0.15s; }
.semana-col-ordenes {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  max-height: 410px; /* ~10 órdenes visibles; el resto se ve haciendo scroll */
  overflow-y: auto;
}
.semana-add {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px; height: 20px;
  background: #f1f5f9;
  border-radius: 4px;
  color: var(--azul);
  font-size: 1rem;
  text-decoration: none;
  margin-top: auto;
  align-self: flex-start;
  line-height: 1;
}
.semana-add:hover { background: #f1d1d0; text-decoration: none; }

/* ====================================================== MÓVIL / RESPONSIVE === */

/* Evitar que ningún elemento amplíe el ancho de la página */
html { max-width: 100%; }
.layout, .main { min-width: 0; }

/* Barra superior (solo visible en móvil) */
.mobile-topbar {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 54px;
  background: #0d0605;
  color: #e5e7eb;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  z-index: 150;
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
}
.mobile-brand { font-weight: 700; font-size: 1.05rem; color: #fff; letter-spacing: 0.01em; display: flex; align-items: center; }
.mobile-brand img { height: 22px; display: block; }
.mobile-topbar-right { display: flex; align-items: center; gap: 0.75rem; }
.mobile-user { font-size: 0.8rem; color: #9ca3af; max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hamburger {
  background: none; border: none; color: #fff;
  font-size: 1.45rem; cursor: pointer;
  padding: 0.3rem 0.45rem; border-radius: 6px; line-height: 1;
}
.hamburger:hover { background: var(--azul); }

/* Fondo oscuro detrás del menú */
.nav-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 140;
}
.nav-backdrop.visible { display: block; }

@media (max-width: 768px) {
  /* Mostrar topbar, ocultar sidebar en reposo */
  .mobile-topbar { display: flex; }

  .layout {
    display: block;
    padding-top: 54px; /* espacio para la topbar fija */
  }

  /* Sidebar pasa a ser panel deslizante desde la izquierda */
  .sidebar {
    position: fixed;
    top: 54px; left: 0; bottom: 0;
    width: 270px;
    transform: translateX(-100%);
    transition: transform 0.24s ease;
    z-index: 145;
    overflow-y: auto;
    padding-top: 0.5rem;
  }
  .sidebar.nav-open { transform: translateX(0); }

  /* Contenido principal ocupa todo el ancho */
  .main {
    padding: 1rem;
    max-width: 100%;
  }

  /* Tablas con scroll horizontal — aplica a TODAS las tablas (también dentro de cards) */
  .main table,
  .card table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }
  /* El contenido de las celdas sí puede romper línea (salvo las cabeceras) */
  .main table td,
  .card table td {
    white-space: normal;
    min-width: 60px;
  }

  /* Botones más grandes (zona de toque de al menos 44px) */
  .btn { padding: 0.65rem 1.1rem; font-size: 0.95rem; }
  .btn-sm { padding: 0.5rem 0.85rem; font-size: 0.85rem; }

  /* Filas de formulario apiladas */
  .form-row { flex-direction: column; gap: 0; }

  /* Filtros en columnas más manejables */
  .filters { gap: 0.45rem; }
  form .filters select,
  form .filters input,
  .filters select,
  .filters input { font-size: 0.9rem; padding: 0.5rem 0.6rem; min-width: 110px; }

  /* Topbar de páginas (título + botón) */
  .topbar { gap: 0.5rem; }
  .topbar h1 { font-size: 1.2rem; }

  /* Grids se vuelven una sola columna */
  .grid-4,
  .grid-3,
  .grid-2 { grid-template-columns: 1fr; }

  /* Detalle: una sola columna — !important para anular inline styles */
  .detail-grid { grid-template-columns: 1fr !important; }

  /* Flex containers que pueden desbordarse */
  .form-row { flex-wrap: wrap; }
  .topbar { flex-wrap: wrap; }

  /* Filtros con inputs de ancho fijo: no superar el ancho disponible */
  input[type="text"][style*="width"] { max-width: 100%; width: 100% !important; }
  input[type="number"][style*="width"] { max-width: 120px; }

  /* Calendario */
  .calendario-grid { grid-template-columns: repeat(7, minmax(42px, 1fr)); }
  .calendario-dia { min-height: 64px; padding: 0.25rem; }
  .calendario-chip { font-size: 0.65rem; }

  /* Almacén */
  .almacen-cards { grid-template-columns: 1fr; }

  /* Stats del dashboard: 2 columnas en móvil */
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
}
