/* ============================================================
   OPL · Solicitudes de Entrega — hoja de estilos v2.2.2
   Una sola capa coherente (sin !important en pugna).
   - Tema claro fijo (color-scheme) para que ningún navegador
     "oscurezca" por su cuenta los formularios.
   - Fuentes con respaldo del sistema si Google Fonts no carga.
   - Texto mínimo 13 px, controles de 44 px, contraste AA.
   - Escritorio: barra lateral fija · Tablet/móvil: menú
     desplegable · Móvil: tablas convertidas en tarjetas.
   ============================================================ */

:root {
  color-scheme: light;

  --font: "Space Grotesk", system-ui, -apple-system, "Segoe UI", Roboto,
          "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas,
          "Liberation Mono", monospace;
  --emoji: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif;

  --bg: #eef2f7;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #f1f5f9;
  --border: #d8dee9;
  --border-strong: #b9c4d8;

  --text: #0f172a;
  --text-2: #1e293b;
  --text-3: #334155;
  --muted: #5a6b81;

  --accent: #0b7285;
  --accent-hover: #095c6b;
  --link: #1d4ed8;
  --focus: #2563eb;

  /* Semáforo (texto oscuro sobre fondo claro: contraste AA) */
  --rojo: #b91c1c;
  --rojo-bg: #fee2e2;
  --rojo-line: #fca5a5;
  --amarillo: #a16207;
  --amarillo-text: #854d0e;
  --amarillo-bg: #fef3c7;
  --amarillo-line: #fcd34d;
  --verde: #15803d;
  --verde-text: #166534;
  --verde-bg: #dcfce7;
  --verde-line: #86efac;
  --violeta: #7c3aed;
  --violeta-text: #6d28d9;
  --violeta-bg: #ede9fe;
  --violeta-line: #c4b5fd;

  --nav-bg: #0f172a;
  --nav-text: #cbd5e1;
  --nav-muted: #94a3b8;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.08), 0 2px 8px rgba(15, 23, 42, 0.05);
  --shadow: 0 12px 40px rgba(15, 23, 42, 0.18);

  --sidebar-w: 250px;
  --control-h: 44px;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  font-size: 100%;
}

/* El atributo hidden SIEMPRE gana (antes lo anulaban display:flex/inline-flex) */
[hidden] { display: none !important; }

body {
  font-family: var(--font);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.app { display: block; min-height: 100vh; min-height: 100dvh; }
#vista-portal { width: 100%; }

img, svg { max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
pre { font-family: var(--mono); }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.muted { color: var(--muted); font-size: 0.9rem; line-height: 1.5; }
strong { font-weight: 700; }

/* ---------- Sidebar ---------- */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--nav-bg);
  color: var(--nav-text);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  z-index: 100;
  -webkit-overflow-scrolling: touch;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 18px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}
.brand-icon {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, #0e90a8, #2563eb);
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  flex-shrink: 0;
}
.brand-icon svg { width: 22px; height: 22px; display: block; }
.brand h1 {
  font-family: var(--mono);
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.2;
  color: #fff;
}
.brand-sub {
  display: block;
  margin-top: 2px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--nav-muted);
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px 8px;
  flex: 1;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: var(--control-h);
  padding: 10px 12px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--nav-text);
  font-size: 0.95rem;
  font-weight: 500;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }
.nav-item.active {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  font-weight: 700;
  box-shadow: inset 3px 0 0 #22d3ee;
}
.nav-icon {
  width: 22px;
  text-align: center;
  font-size: 1.05rem;
  font-family: var(--emoji);
  flex-shrink: 0;
}

.sidebar-footer {
  margin-top: auto;
  padding: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(0, 0, 0, 0.18);
}
.cliente-info {
  font-size: 0.9rem;
  line-height: 1.4;
  color: #e2e8f0;
  margin-bottom: 12px;
  overflow-wrap: anywhere;
}
.sidebar .muted { color: var(--nav-muted); font-size: 0.82rem; }
.sidebar .btn-secondary {
  background: transparent;
  color: #e2e8f0;
  border-color: rgba(255, 255, 255, 0.35);
}
.sidebar .btn-secondary:hover { background: rgba(255, 255, 255, 0.1); }

.status-legend { margin-top: 16px; }
.status-legend h4 {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--nav-muted);
  margin-bottom: 8px;
}
.legend-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 0.82rem;
  line-height: 1.35;
  color: var(--nav-text);
  margin: 6px 0;
}
.legend-item .dot { margin-top: 5px; }

.dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot.rojo { background: #ef4444; }
.dot.amarillo { background: #eab308; }
.dot.verde { background: #22c55e; }

.sidebar-backdrop {
  position: fixed;
  top: 0; right: 0; bottom: 0; left: 0;
  background: rgba(15, 23, 42, 0.5);
  z-index: 90;
}

/* ---------- Main + header ---------- */
.main {
  margin-left: var(--sidebar-w);
  min-width: 0;
  min-height: 100vh;
  min-height: 100dvh;
  padding-bottom: 24px;
}

.header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 14px 24px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 6px rgba(15, 23, 42, 0.05);
}
.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1 1 260px;
}
.header h2 {
  font-size: 1.3rem;
  font-weight: 700;
  line-height: 1.25;
  color: var(--text);
}
.subtitle {
  font-size: 0.92rem;
  line-height: 1.4;
  color: var(--muted);
  margin-top: 2px;
}
.header-actions { display: flex; align-items: center; gap: 8px; }

.btn-menu {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: var(--control-h); height: var(--control-h);
  padding: 11px;
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  background: #fff;
  flex-shrink: 0;
}
.btn-menu span {
  display: block;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
}

.panel {
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 24px 12px;
}
#panel-tablero, #panel-usuarios { max-width: 1400px; }
#panel-solicitar { max-width: 880px; }
#panel-cuenta { max-width: 880px; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.25;
  text-align: center;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, filter 0.15s;
}
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-block { width: 100%; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-secondary,
.btn-ghost {
  background: #fff;
  color: var(--text-2);
  border-color: var(--border-strong);
}
.btn-secondary:hover, .btn-ghost:hover { background: var(--surface-3); }

.btn-amarillo { background: var(--amarillo); color: #fff; }
.btn-verde    { background: var(--verde); color: #fff; }
.btn-rojo     { background: var(--rojo); color: #fff; }
.btn-amarillo:hover, .btn-verde:hover, .btn-rojo:hover { filter: brightness(0.92); }

.btn-ver {
  min-height: 36px;
  padding: 6px 14px;
  color: var(--link);
  background: #fff;
  border-color: var(--border-strong);
}

.link-btn {
  background: none;
  border: 0;
  padding: 6px 4px;
  color: var(--link);
  font-size: inherit;
  font-weight: 600;
  text-decoration: underline;
}
.link-btn.danger { color: var(--rojo); }

/* ---------- Tarjetas ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: 16px; }
.card h3 {
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: 6px;
  color: var(--text);
}
.card-narrow { max-width: 460px; }
.card-head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px 16px;
  margin-bottom: 16px;
}
.card-head-row h3 { margin-bottom: 2px; }

/* ---------- Formularios ---------- */
label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text-3);
}

input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="hidden"]),
select,
textarea {
  display: block;
  width: 100%;
  min-height: var(--control-h);
  padding: 10px 12px;
  font-size: 1rem;              /* 16px: evita el zoom automático de iOS */
  line-height: 1.35;
  color: var(--text);
  background-color: #fff;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}
textarea { min-height: 88px; resize: vertical; }

select {
  padding-right: 38px;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='9' viewBox='0 0 14 9'%3E%3Cpath d='M1 1.5l6 6 6-6' fill='none' stroke='%23475569' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 14px 9px;
  text-overflow: ellipsis;
}
select option { color: var(--text); background: #fff; }

input[type="date"], input[type="time"] {
  -webkit-appearance: none;
  appearance: none;
  min-width: 0;
}
input[type="date"]::-webkit-date-and-time-value,
input[type="time"]::-webkit-date-and-time-value { text-align: left; min-height: 1.4em; }

::placeholder { color: #6b7a90; opacity: 1; }

input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(11, 114, 133, 0.25);
}

input[readonly], .input-readonly {
  background-color: var(--surface-3);
  color: var(--text-3);
  cursor: default;
}
input:disabled, select:disabled, textarea:disabled {
  background-color: var(--surface-3);
  color: var(--text-3);
  -webkit-text-fill-color: var(--text-3);   /* Safari/iOS aclaran el texto deshabilitado */
  opacity: 1;
  cursor: not-allowed;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px 20px;
  margin-top: 16px;
}
.form-grid > * { min-width: 0; }
.span-2 { grid-column: 1 / -1; }

.field-hint { margin-top: 6px; }
.field-sede-first {
  padding: 14px 16px;
  background: #fef2f2;
  border: 1px solid var(--rojo-line);
  border-radius: 10px;
}
.field-sede-first label { font-size: 1rem; color: var(--text); }

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 20px;
}
.form-grid > .form-actions { grid-column: 1 / -1; margin-top: 4px; }

.form-msg {
  min-height: 1.4em;
  margin-top: 14px;
  font-size: 0.95rem;
  font-weight: 600;
  overflow-wrap: anywhere;
}
.form-msg.ok { color: var(--verde-text); }
.form-msg.error { color: var(--rojo); }
.form-error {
  margin-top: 12px;
  padding: 10px 12px;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--rojo);
  background: var(--rojo-bg);
  border: 1px solid var(--rojo-line);
  border-radius: var(--radius-sm);
}

#form-password label { margin-top: 16px; }
#form-password .btn { margin-top: 20px; }

/* Dropzone + lista de archivos */
.dropzone {
  margin-top: 4px;
  padding: 22px 16px;
  text-align: center;
  background: var(--surface-2);
  border: 2px dashed var(--border-strong);
  border-radius: 10px;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone.drag { border-color: var(--focus); background: #eff6ff; }
.dropzone p { margin: 4px 0; font-size: 0.95rem; }

.file-list { list-style: none; margin: 12px 0 0; }
.file-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.92rem;
}
.file-list .file-label { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }

/* ---------- Tablero ---------- */
.board-help {
  margin-bottom: 16px;
  border-left: 4px solid var(--rojo);
}
.board-help > strong { display: block; font-size: 1.05rem; margin-bottom: 10px; }
.board-flow { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.board-flow li {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 10px;
  font-size: 0.95rem;
  line-height: 1.4;
  color: var(--text-3);
}

.filters {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 14px 16px;
  align-items: end;
  margin-bottom: 16px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.filter-group { min-width: 0; }
.filter-group label {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}
.stat-card {
  padding: 6px 8px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 3px solid var(--border-strong);
  border-radius: 8px;
  box-shadow: none;
  min-height: 0;
}
.stat-card.rojo { border-top-color: var(--rojo); }
.stat-card.amarillo { border-top-color: var(--amarillo); }
.stat-card.verde { border-top-color: var(--verde); }
.stat-num {
  display: block;
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
}
.stat-card.rojo .stat-num { color: var(--rojo); }
.stat-card.amarillo .stat-num { color: var(--amarillo); }
.stat-card.verde .stat-num { color: var(--verde); }
.stat-label {
  display: block;
  margin-top: 2px;
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1.2;
  color: var(--text-3);
}

.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 11px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.4;
  white-space: nowrap;
}
.status-badge.rojo     { background: var(--rojo-bg);     color: #991b1b;              border-color: var(--rojo-line); }
.status-badge.amarillo { background: var(--amarillo-bg); color: var(--amarillo-text); border-color: var(--amarillo-line); }
.status-badge.verde    { background: var(--verde-bg);    color: var(--verde-text);    border-color: var(--verde-line); }

.docs-badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--link);
  background: #eff6ff;
  white-space: nowrap;
}

/* ---------- Tablas ---------- */
.table-scroll {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
#panel-tablero .table-scroll {
  max-height: 70vh;
  max-height: max(420px, calc(100vh - 380px));
}

.data-table {
  width: 100%;
  border-collapse: separate;   /* bordes visibles también con celdas sticky (Safari/Firefox) */
  border-spacing: 0;
  font-size: 0.92rem;
  color: var(--text-2);
}
#tabla-solicitudes { min-width: 940px; }
#tabla-usuarios { min-width: 680px; }

.data-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 12px 10px;
  text-align: left;
  white-space: nowrap;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-3);
  background: var(--surface-3);
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 12px 10px;
  vertical-align: middle;
  line-height: 1.4;
  overflow-wrap: anywhere;
  background: #fff;
  border-bottom: 1px solid #e8edf4;
}
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table td strong { color: var(--text); }
.data-table .row-entrega { cursor: pointer; }
.data-table .row-entrega:hover td { background: var(--surface-2); }

/* Primera columna fija al desplazar en horizontal (solo tablero) */
#tabla-solicitudes th:first-child,
#tabla-solicitudes td:first-child {
  position: sticky;
  left: 0;
  box-shadow: 1px 0 0 var(--border);
}
#tabla-solicitudes th:first-child { z-index: 3; }
#tabla-solicitudes td:first-child { z-index: 1; }

#tabla-solicitudes td:nth-child(1),
#tabla-solicitudes td:nth-child(5),
#tabla-solicitudes td:nth-child(6),
#tabla-solicitudes td:nth-child(7),
#tabla-solicitudes td:nth-child(8),
#tabla-solicitudes td:nth-child(9) { white-space: nowrap; overflow-wrap: normal; }
#tabla-solicitudes td:nth-child(2),
#tabla-solicitudes td:nth-child(3),
#tabla-solicitudes td:nth-child(4) { min-width: 150px; }

.data-table td.empty-cell {
  padding: 32px 16px;
  text-align: center;
  white-space: normal;
  color: var(--muted);
}

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  top: 0; right: 0; bottom: 0; left: 0;
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(15, 23, 42, 0.55);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
}
.modal-overlay.open { display: flex; }

.modal {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 720px;
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 {
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.3;
  overflow-wrap: anywhere;
}
.modal-close {
  flex-shrink: 0;
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--surface-3);
  color: var(--text-3);
  font-size: 1.6rem;
  line-height: 1;
}
.modal-close:hover { background: #e2e8f0; color: var(--text); }
.modal-body {
  flex: 1 1 auto;
  padding: 18px 22px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  font-size: 0.97rem;
}
.modal-footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 22px;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
}
.modal-footer label.btn { margin-bottom: 0; cursor: pointer; }

.detalle-resumen {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-bottom: 8px;
}
.detail-row {
  display: grid;
  grid-template-columns: minmax(130px, 200px) minmax(0, 1fr);
  gap: 4px 16px;
  align-items: start;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  overflow-wrap: anywhere;
}
.detail-label {
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.4;
  color: var(--muted);
}
.detail-block {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.detail-block .detail-label { display: block; margin-bottom: 8px; }
.adjuntos-list { display: flex; flex-wrap: wrap; gap: 8px; }
.btn-adjunto { font-size: 0.88rem; max-width: 100%; overflow-wrap: anywhere; text-align: left; }
.correo-cuerpo {
  max-height: 260px;
  overflow: auto;
  padding: 12px;
  font-size: 0.85rem;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--bg);
}
.login-card {
  width: 100%;
  max-width: 440px;
  padding: 32px 28px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.brand-login { padding: 0; border: 0; margin-bottom: 20px; }
.brand-login h1 { font-size: 1.5rem; color: var(--text); }
.brand-login .brand-sub { color: var(--muted); }
.login-desc {
  margin-bottom: 20px;
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--text-3);
}
.login-card input:not([type="hidden"]) { margin-bottom: 16px; }
.login-note { margin-top: 14px; }
.semaforo-mini {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
  color: var(--text-3);
}
.semaforo-mini span { display: inline-flex; align-items: center; gap: 6px; }

/* ============================================================
   Responsive
   ============================================================ */

/* Tablet y menores: la barra lateral pasa a menú desplegable */
@media (max-width: 960px) {
  .btn-menu { display: flex; }

  .sidebar {
    width: min(290px, 86vw);
    transform: translateX(-105%);
    visibility: hidden;
    transition: transform 0.22s ease, visibility 0.22s;
  }
  body.nav-open .sidebar {
    transform: translateX(0);
    visibility: visible;
    box-shadow: 8px 0 32px rgba(15, 23, 42, 0.3);
  }
  body.nav-open { overflow: hidden; }

  .main { margin-left: 0; }
  .header { padding: 12px 16px; }
  .panel { padding: 16px 16px 12px; }
}
@media (min-width: 961px) {
  .sidebar-backdrop { display: none !important; }
}

@media (max-width: 900px) {
  /* Tablas → tarjetas */
  #tabla-solicitudes, #tabla-usuarios { min-width: 0; }
  #panel-tablero .table-scroll,
  .table-scroll {
    max-height: none;
    overflow: visible;
    background: transparent;
    border: 0;
    border-radius: 0;
  }
  .data-table, .data-table tbody, .data-table tr, .data-table td { display: block; width: 100%; }
  .data-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0, 0, 0, 0); }
  .data-table tbody tr {
    margin-bottom: 12px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
  }
  .data-table td,
  #tabla-solicitudes td:nth-child(n) {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-width: 0;
    padding: 10px 14px;
    text-align: right;
    white-space: normal;
    overflow-wrap: anywhere;
    border-bottom: 1px solid #eef1f6;
  }
  .data-table td[data-label]::before {
    content: attr(data-label);
    flex: 0 0 auto;
    max-width: 48%;
    overflow-wrap: normal;
    text-align: left;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--muted);
  }
  .data-table td:not([data-label]) { justify-content: flex-end; }
  .data-table tbody tr td:last-child { border-bottom: 0; }
  #tabla-solicitudes th:first-child,
  #tabla-solicitudes td:first-child { position: static; box-shadow: none; }
  .data-table td.empty-cell { display: block; text-align: center; }
  .data-table tbody tr:has(td.empty-cell) { box-shadow: none; }
}

@media (max-width: 720px) {
  .header h2 { font-size: 1.15rem; }
  .subtitle { font-size: 0.88rem; }

  .card { padding: 16px; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }

  .board-flow li { align-items: flex-start; flex-direction: column; }

  .filters { grid-template-columns: minmax(0, 1fr); padding: 14px; }

  /* Contadores compactos en 2x2 */
  .stats { grid-template-columns: 1fr 1fr; gap: 6px; }
  .stat-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    padding: 6px 8px;
    text-align: center;
  }
  .stat-num { font-size: 1.15rem; min-width: 0; text-align: center; }
  .stat-label { margin-top: 2px; font-size: 0.65rem; }

  .detail-row { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .modal-overlay { padding: 8px; align-items: flex-end; }
  .modal { max-height: calc(100vh - 16px); max-height: calc(100dvh - 16px); border-radius: 14px 14px 10px 10px; }
  .modal-header, .modal-body, .modal-footer { padding-left: 16px; padding-right: 16px; }
  .modal-footer { flex-direction: column; align-items: stretch; }
  .modal-footer .btn { width: 100%; }

  .login-wrap { padding: 12px; align-items: flex-start; }
  .login-card { padding: 24px 18px; margin-top: 8px; }
}

/* Pantallas muy angostas */
@media (max-width: 360px) {
  .panel { padding-left: 10px; padding-right: 10px; }
  .header { padding-left: 10px; padding-right: 10px; }
}

/* Safe area (notch / barra de inicio) */
@supports (padding: env(safe-area-inset-bottom)) {
  .sidebar { padding-bottom: env(safe-area-inset-bottom); }
  .modal-footer { padding-bottom: max(14px, env(safe-area-inset-bottom)); }
  .login-wrap { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

@media print {
  .sidebar, .sidebar-backdrop, .btn-menu, .header-actions { display: none !important; }
  .main { margin-left: 0; }
  .table-scroll { max-height: none !important; overflow: visible; }
}

/* Modal edición admin v2.3.2 */
.modal-footer-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}
.form-edit-solicitud {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 14px;
  margin-top: 8px;
}
.form-edit-solicitud .span-2 { grid-column: 1 / -1; }
.form-edit-solicitud label {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  color: #64748b;
  margin-bottom: 4px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.form-edit-solicitud input,
.form-edit-solicitud select,
.form-edit-solicitud textarea {
  width: 100%;
  box-sizing: border-box;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid #c5cfe0;
  border-radius: 8px;
  font-size: 0.95rem;
  background: #fff;
  color: #0f172a;
}
.form-edit-solicitud textarea { min-height: 72px; resize: vertical; }
.btn-danger {
  background: #fee2e2 !important;
  color: #b91c1c !important;
  border: 1px solid #fecaca !important;
}
.btn-danger:hover {
  background: #dc2626 !important;
  color: #fff !important;
}
.detalle-origen {
  font-size: 0.8rem;
  color: #64748b;
  margin: 0 0 10px;
}
@media (max-width: 600px) {
  .form-edit-solicitud { grid-template-columns: 1fr; }
}


/* ===== Tablero color + sort v2.3.5 ===== */
.stat-card {
  cursor: pointer;
  border: none;
  font-family: inherit;
  transition: transform 0.12s, box-shadow 0.12s, outline 0.12s;
}
.stat-card:hover { transform: none; box-shadow: 0 1px 4px rgba(15,23,42,0.08); filter: brightness(0.98); }
.stat-card.active {
  outline: 2px solid #0f172a;
  outline-offset: 1px;
}
.stat-card.todos {
  border-top: 3px solid #64748b !important;
  background: #f8fafc !important;
}
.stat-card.todos .stat-num { color: #475569 !important; font-size: 1.25rem !important; }

.row-entrega.row-estado-rojo td:first-child {
  box-shadow: inset 4px 0 0 #dc2626;
}
.row-entrega.row-estado-amarillo td:first-child {
  box-shadow: inset 4px 0 0 #ca8a04;
}
.row-entrega.row-estado-verde td:first-child {
  box-shadow: inset 4px 0 0 #16a34a;
}
.row-entrega.row-estado-rojo:hover td { background: #fef2f2 !important; }
.row-entrega.row-estado-amarillo:hover td { background: #fffbeb !important; }
.row-entrega.row-estado-verde:hover td { background: #f0fdf4 !important; }

.th-sort {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.th-sort:hover { color: #0f172a !important; background: #e2e8f0 !important; }
.th-sort.sorted { color: #0f172a !important; }
.sort-ind { font-size: 0.7em; opacity: 0.8; }

/* Modal detalle coloreado por estado */
.modal.estado-rojo {
  border-top: 5px solid #dc2626;
}
.modal.estado-amarillo {
  border-top: 5px solid #ca8a04;
}
.modal.estado-verde {
  border-top: 5px solid #16a34a;
}
.detalle-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 10px;
  margin-bottom: 14px;
}
.detalle-banner.rojo { background: #fee2e2; border: 1px solid #fca5a5; }
.detalle-banner.amarillo { background: #fef3c7; border: 1px solid #fcd34d; }
.detalle-banner.verde { background: #dcfce7; border: 1px solid #86efac; }
.detalle-banner-text {
  flex: 1;
  font-size: 0.9rem;
  color: #334155;
  font-weight: 500;
}

@media (max-width: 900px) {
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)) !important; gap: 6px !important; }
  .stat-label { font-size: 0.62rem !important; }
  .stat-num { font-size: 1.1rem !important; }
}
@media (max-width: 640px) {
  .stats { grid-template-columns: 1fr 1fr !important; }
}


/* v2.3.6 — color de etapa en filas + meta actualización */
.board-help { display: none !important; }

.tablero-meta {
  margin: 0 0 8px !important;
  font-size: 0.75rem !important;
  color: #64748b !important;
  padding: 4px 10px;
  background: #f1f5f9;
  border-radius: 6px;
  border: 1px solid #e2e8f0;
  line-height: 1.35;
}
.tablero-meta.loading {
  color: #0369a1 !important;
  background: #e0f2fe;
  border-color: #7dd3fc;
}
.tablero-meta.ok {
  color: #166534 !important;
  background: #ecfdf5;
  border-color: #86efac;
}
.tablero-meta.error {
  color: #991b1b !important;
  background: #fef2f2;
  border-color: #fecaca;
}

/* Relleno de color por etapa (fila completa) */
.row-entrega.row-estado-rojo td {
  background: #fef2f2 !important;
}
.row-entrega.row-estado-amarillo td {
  background: #fffbeb !important;
}
.row-entrega.row-estado-verde td {
  background: #f0fdf4 !important;
}
.row-entrega.row-estado-rojo td:first-child {
  box-shadow: inset 5px 0 0 #dc2626 !important;
  border-left: 5px solid #dc2626 !important;
}
.row-entrega.row-estado-amarillo td:first-child {
  box-shadow: inset 5px 0 0 #ca8a04 !important;
  border-left: 5px solid #ca8a04 !important;
}
.row-entrega.row-estado-verde td:first-child {
  box-shadow: inset 5px 0 0 #16a34a !important;
  border-left: 5px solid #16a34a !important;
}
.row-entrega.row-estado-rojo:hover td { background: #fee2e2 !important; }
.row-entrega.row-estado-amarillo:hover td { background: #fef3c7 !important; }
.row-entrega.row-estado-verde:hover td { background: #dcfce7 !important; }

/* Badge semáforo más visible en tabla */
#tabla-solicitudes .status-badge {
  font-weight: 700 !important;
  min-width: 7.5rem;
  display: inline-block;
  text-align: center;
}

/* Evidencia foto transportador · modal detalle */
.foto-evidencia-wrap {
  margin-top: 6px;
}
.foto-evidencia {
  display: block;
  max-width: 100%;
  max-height: 320px;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  object-fit: contain;
  background: #0f172a08;
  cursor: zoom-in;
}


/* v2.4.8 — evidencia transportador */
.docs-badge.docs-foto {
  background: #dcfce7;
  color: #166534;
  border: 1px solid #86efac;
  margin-left: 4px;
}
.evidencia-box {
  background: #f0fdf4;
  border: 1px solid #86efac;
  border-radius: 10px;
  padding: 12px 14px !important;
  margin-top: 8px;
}
.foto-evidencia-wrap { margin-top: 8px; }
.foto-evidencia {
  max-width: min(100%, 420px);
  max-height: 320px;
  width: auto;
  height: auto;
  border-radius: 10px;
  border: 2px solid #16a34a;
  object-fit: contain;
  background: #fff;
  cursor: zoom-in;
  box-shadow: 0 4px 14px rgba(22, 163, 74, 0.2);
}
.foto-hint { margin: 8px 0 0; font-size: 0.8rem; }
.foto-fallo { margin-top: 8px; }


/* v2.4.9 — contadores compactos: más espacio para la tabla */
.stats {
  grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
  gap: 8px !important;
  margin-bottom: 8px !important;
}
.stat-card {
  padding: 5px 8px !important;
  border-radius: 8px !important;
  border-top-width: 3px !important;
}
.stat-num {
  font-size: 1.2rem !important;
  line-height: 1.1 !important;
}
.stat-label {
  font-size: 0.68rem !important;
  margin-top: 1px !important;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tablero-meta {
  margin-bottom: 6px !important;
  padding: 3px 8px !important;
  font-size: 0.72rem !important;
}

#sol-cliente-otro, .input-cliente-otro {
  width: 100%;
  box-sizing: border-box;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid #c5cfe0;
  border-radius: 8px;
  font-size: 0.95rem;
  margin-top: 8px;
}


/* v2.4.13 — violeta novedad + gestión */
.dot.violeta { background: var(--violeta); }
.btn-violeta { background: var(--violeta); color: #fff; border: none; }
.btn-violeta:hover { filter: brightness(0.92); }
.status-badge.violeta {
  background: var(--violeta-bg);
  color: var(--violeta-text);
  border-color: var(--violeta-line);
}
.stat-card.violeta { border-top-color: var(--violeta) !important; }
.stat-card.violeta .stat-num { color: var(--violeta) !important; }
.row-entrega.row-estado-violeta td { background: #f5f3ff !important; }
.row-entrega.row-estado-violeta td:first-child {
  box-shadow: inset 5px 0 0 var(--violeta) !important;
  border-left: 5px solid var(--violeta) !important;
}
.row-entrega.row-estado-violeta:hover td { background: #ede9fe !important; }
.detalle-banner.violeta { background: #ede9fe; border: 1px solid #c4b5fd; }
.modal.estado-violeta { border-top: 5px solid var(--violeta); }

.gestion-kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0;
}
.kpi-card {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 10px 8px;
  text-align: center;
}
.kpi-card.violeta { border-top: 3px solid var(--violeta); }
.kpi-card.warn { border-top: 3px solid #dc2626; }
.kpi-card.ok { border-top: 3px solid #16a34a; }
.kpi-num { display: block; font-size: 1.35rem; font-weight: 700; color: #0f172a; }
.kpi-label { font-size: 0.72rem; color: #64748b; font-weight: 600; }

.ind-gestion {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  border: 1px solid transparent;
}
.ind-gestion.ok { background: #dcfce7; color: #166534; border-color: #86efac; }
.ind-gestion.pendiente { background: #ede9fe; color: #6d28d9; border-color: #c4b5fd; }
.ind-gestion.vencido { background: #fee2e2; color: #991b1b; border-color: #fca5a5; }
.ind-gestion.sin-plazo { background: #f1f5f9; color: #475569; border-color: #cbd5e1; }

.gestion-form {
  display: grid;
  gap: 10px;
  margin-top: 12px;
  padding: 12px;
  background: #f5f3ff;
  border: 1px solid #c4b5fd;
  border-radius: 10px;
}
.gestion-form label { font-weight: 600; font-size: 0.85rem; }
.gestion-form input, .gestion-form textarea, .gestion-form select {
  width: 100%; box-sizing: border-box; padding: 8px; border-radius: 8px; border: 1px solid #c5cfe0;
}
@media (max-width: 900px) {
  .gestion-kpis { grid-template-columns: 1fr 1fr; }
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; }
}

/* v2.4.13 stats 5 cols */
.stats {
  grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
}
@media (max-width: 900px) {
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; }
}
@media (max-width: 640px) {
  .stats { grid-template-columns: 1fr 1fr !important; }
}

.novedad-motivo-row { align-items: flex-start !important; }
.novedad-motivo-texto {
  white-space: pre-wrap;
  word-break: break-word;
  display: block;
  line-height: 1.4;
}


/* v2.4.17 — indicador de cumplimiento por rol */
.cumplimiento-banner {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  margin: 12px 0 14px;
}
.cumplimiento-main {
  display: flex;
  flex-direction: column;
  min-width: 120px;
}
.cumplimiento-pct {
  font-size: 2rem;
  font-weight: 800;
  line-height: 1.1;
  color: #0f172a;
}
.cumplimiento-nivel {
  font-size: 0.85rem;
  font-weight: 700;
  color: #475569;
}
.cumplimiento-meta { flex: 1; min-width: 180px; }
.cumplimiento-banner.nivel-excelente {
  background: #ecfdf5; border-color: #86efac;
}
.cumplimiento-banner.nivel-excelente .cumplimiento-pct { color: #15803d; }
.cumplimiento-banner.nivel-bueno {
  background: #f0fdf4; border-color: #bbf7d0;
}
.cumplimiento-banner.nivel-bueno .cumplimiento-pct { color: #16a34a; }
.cumplimiento-banner.nivel-regular {
  background: #fffbeb; border-color: #fcd34d;
}
.cumplimiento-banner.nivel-regular .cumplimiento-pct { color: #b45309; }
.cumplimiento-banner.nivel-bajo {
  background: #fef2f2; border-color: #fca5a5;
}
.cumplimiento-banner.nivel-bajo .cumplimiento-pct { color: #b91c1c; }
.cumplimiento-banner.nivel-sin {
  background: #f8fafc; border-color: #e2e8f0;
}


/* v2.4.18 — filtro sede + gráfico cumplimiento */
.cumplimiento-filtros {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin: 8px 0 4px;
}
.cumplimiento-filtros label {
  font-size: 0.85rem;
  font-weight: 600;
  color: #475569;
  margin: 0;
}
.cumplimiento-filtros select {
  min-width: 220px;
  padding: 8px 10px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #fff;
  font-size: 0.9rem;
}
.cumplimiento-chart-wrap {
  margin-top: 16px;
  padding: 14px;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  background: #fff;
}
.cumplimiento-chart-wrap .chart-title {
  margin: 0 0 8px;
  font-size: 0.95rem;
}
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 0.75rem;
  color: #64748b;
  margin-bottom: 10px;
}
.chart-legend i {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-right: 4px;
  vertical-align: middle;
}
.chart-legend .lg-ok { background: #16a34a; }
.chart-legend .lg-bad { background: #7c3aed; }
.chart-legend .lg-wait { background: #94a3b8; }
.cumplimiento-chart {
  width: 100%;
  overflow-x: auto;
}
.cumplimiento-chart svg { display: block; max-width: 100%; }
.cumplimiento-chart .chart-label {
  font-size: 11px;
  fill: #334155;
  font-family: system-ui, sans-serif;
}
.cumplimiento-chart .chart-pct {
  font-size: 11px;
  font-weight: 700;
  fill: #0f172a;
  font-family: system-ui, sans-serif;
}
.cumplimiento-chart .bar-ok { fill: #16a34a; }
.cumplimiento-chart .bar-bad { fill: #7c3aed; }
.cumplimiento-chart .bar-wait { fill: #94a3b8; }
.chart-empty { margin: 8px 0 0; font-size: 0.85rem; }
