:root {
  /* Tema por defecto: ocean-blue (ver bloque de temas más abajo) */
  --bg: #eef6fb;
  --surface: #ffffff;
  --border: #cfe3ef;
  --text: #0b2942;
  --text-muted: #5b7d92;
  --primary: #0284c7;
  --primary-dark: #075985;
  --secondary: #0e4f75;
  --secondary-dark: #17527a;
  --danger: #dc2626;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.06);
  --font-family: "Blinker", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* ---------- Temas de color ---------- */

:root[data-theme="ocean-blue"] {
  --bg: #eef6fb;
  --surface: #ffffff;
  --border: #cfe3ef;
  --text: #0b2942;
  --text-muted: #5b7d92;
  --primary: #0284c7;
  --primary-dark: #075985;
  --secondary: #0e4f75;
  --secondary-dark: #17527a;
  --danger: #dc2626;
}

:root[data-theme="minimalist-light"] {
  --bg: #fafafa;
  --surface: #ffffff;
  --border: #e4e4e7;
  --text: #18181b;
  --text-muted: #71717a;
  --primary: #3f3f46;
  --primary-dark: #27272a;
  --secondary: #52525b;
  --secondary-dark: #27272a;
  --danger: #dc2626;
}

:root[data-theme="minimalist-dark"] {
  --bg: #18181b;
  --surface: #232326;
  --border: #3f3f46;
  --text: #fafafa;
  --text-muted: #a1a1aa;
  --primary: #60a5fa;
  --primary-dark: #3b82f6;
  --secondary: #e4e4e7;
  --secondary-dark: #09090b;
  --danger: #f87171;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.5), 0 1px 2px rgba(0, 0, 0, 0.4);
}

:root[data-theme="nature-green"] {
  --bg: #f1f8f2;
  --surface: #ffffff;
  --border: #d3e8d6;
  --text: #1b3a1e;
  --text-muted: #5b7360;
  --primary: #2e7d32;
  --primary-dark: #1b5e20;
  --secondary: #33691e;
  --secondary-dark: #1b3a1e;
  --danger: #c62828;
}

:root[data-theme="corporate-navy"] {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #dde3ec;
  --text: #14213d;
  --text-muted: #5c6b84;
  --primary: #14213d;
  --primary-dark: #0b1526;
  --secondary: #1d3461;
  --secondary-dark: #0b1526;
  --danger: #c0392b;
}

:root[data-theme="warm-sand"] {
  --bg: #faf3e8;
  --surface: #fffdf9;
  --border: #ecdcc0;
  --text: #4a3728;
  --text-muted: #8a7358;
  --primary: #c07a3e;
  --primary-dark: #9c5f2c;
  --secondary: #8a5a3b;
  --secondary-dark: #5c3a22;
  --danger: #c0392b;
}

:root[data-theme="modern-purple"] {
  --bg: #f6f3fc;
  --surface: #ffffff;
  --border: #e2d9f5;
  --text: #2e1a47;
  --text-muted: #7a6a92;
  --primary: #7c3aed;
  --primary-dark: #6d28d9;
  --secondary: #5b21b6;
  --secondary-dark: #3b0764;
  --danger: #dc2626;
}

:root[data-theme="monochrome-pro"] {
  --bg: #f5f5f5;
  --surface: #ffffff;
  --border: #d4d4d4;
  --text: #171717;
  --text-muted: #737373;
  --primary: #171717;
  --primary-dark: #000000;
  --secondary: #404040;
  --secondary-dark: #171717;
  --danger: #dc2626;
}

:root[data-theme="teal-focus"] {
  --bg: #eefaf8;
  --surface: #ffffff;
  --border: #c8ece6;
  --text: #0a3d36;
  --text-muted: #4f8a80;
  --primary: #0d9488;
  --primary-dark: #0f766e;
  --secondary: #115e59;
  --secondary-dark: #0a3d36;
  --danger: #dc2626;
}

:root[data-theme="soft-coral"] {
  --bg: #fff3f0;
  --surface: #ffffff;
  --border: #ffd9cf;
  --text: #5c2a1e;
  --text-muted: #a06b5c;
  --primary: #ff6f59;
  --primary-dark: #e5533f;
  --secondary: #c04a37;
  --secondary-dark: #7a2e21;
  --danger: #c0392b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-family);
  background: var(--bg);
  color: var(--text);
}

/* El tablero queda acotado a la altura visible de la ventana: así, cuando
   hay muchos leads, la barra de scroll horizontal (para ver columnas que no
   entran en el ancho) queda siempre alcanzable en pantalla, en vez de
   quedar pegada al final de un contenido larguísimo. Todas las columnas
   siguen scrolleando juntas como una sola unidad (igual que antes), no cada
   una por separado. */
.dashboard-body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.dashboard-body .board,
.dashboard-body .board-tareas,
.dashboard-body .board-fletes,
.dashboard-body .board-historial {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

/* ---------- Login ---------- */

.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--secondary), var(--secondary-dark));
}

.login-card {
  background: var(--surface);
  padding: 2.5rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.login-logo {
  max-width: 220px;
  height: auto;
  margin-bottom: 1rem;
}

.login-card h1 {
  margin: 0 0 0.25rem;
  font-size: 1.5rem;
  color: var(--secondary);
}

.login-subtitle {
  margin: 0 0 1.5rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.login-card form {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  text-align: left;
}

.login-usuarios-lista {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.login-usuario-btn {
  width: 100%;
}

.login-password-box {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

.login-password-box label {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.login-password-acciones {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
}

.login-form-tipeado label {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.4rem;
}

.login-form-tipeado button[type="submit"] {
  margin-top: 1rem;
}

.error-banner {
  background: #fef2f2;
  color: var(--danger);
  border: 1px solid #fecaca;
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

/* ---------- Shared form controls ---------- */

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: 0.4rem 0.2rem;
  border: none;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-bottom-color: var(--primary);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 8px;
  padding: 0.55rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
  vertical-align: middle;
}

.btn[hidden] {
  display: none;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-secondary {
  background: transparent;
  color: var(--text-muted);
  border: none;
  font-size: 0.69rem;
}

.btn-secondary:hover {
  background: var(--bg);
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover {
  filter: brightness(0.88);
}

/* Espaciado del botón de submit, solo dentro del formulario de login */
.login-card form button[type="submit"] {
  margin-top: 1rem;
}

/* ---------- Topbar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.3rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar-actions .btn,
.topbar-brand .btn {
  padding: 0.3rem 0.7rem;
  font-size: 0.78rem;
}

.topbar-user-stack .btn {
  padding: 0.15rem 0.6rem;
  font-size: 0.72rem;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex: 1 1 auto;
  min-width: 0;
  flex-wrap: wrap;
}

.topbar-brand .buscador {
  max-width: 320px;
}

.topbar-logo {
  height: 32px;
  width: auto;
}

.topbar h1 {
  font-size: 1.25rem;
  margin: 0;
  color: var(--secondary);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.topbar-user-stack {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.05rem;
}

.topbar-user-stack .logout-form {
  display: flex;
}

.topbar-user-stack .logout-form button {
  width: 100%;
}

.theme-select {
  width: auto;
  padding: 0.5rem 0.65rem;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.69rem;
  font-weight: 400;
  font-family: inherit;
  cursor: pointer;
}

.user-badge {
  margin-right: 0.5rem;
}

.user-switcher-wrap {
  position: relative;
}

.user-switcher-panel {
  position: absolute;
  z-index: 40;
  top: calc(100% + 0.45rem);
  left: 0;
  min-width: 160px;
  padding: 0.4rem;
  margin: 0;
  list-style: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 12px 30px rgb(15 23 42 / 16%);
}

.user-switcher-panel[hidden] {
  display: none;
}

.user-switcher-panel li {
  padding: 0.45rem 0.6rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
}

.user-switcher-panel li:hover {
  background: var(--bg);
}

/* ---------- Subbar (buscador) ---------- */

.subbar {
  padding: 0.25rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  flex-wrap: wrap;
  position: sticky;
  top: 40px;
  z-index: 9;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.vista-tabs {
  display: flex;
  gap: 0.25rem;
}

.vista-menu-contextual {
  display: flex;
  align-items: center;
}

.vista-tab {
  border: none;
  background: transparent;
  padding: 0.25rem 0.85rem;
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.vista-tab:hover {
  color: var(--text);
}

.vista-tab[aria-selected="true"] {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.vista-tareas-orden {
  padding: 0 0.5rem;
}

.vista-tareas-orden .tareas-list {
  max-height: none;
  overflow-y: visible;
}

.metricas-filtros {
  padding: 0.75rem 1.5rem 0;
  display: flex;
  align-items: flex-end;
  gap: 1.25rem;
  flex-wrap: wrap;
}

.subbar-metricas {
  justify-content: space-between;
}

.subbar-metricas .metricas-filtros {
  padding: 0;
  align-items: center;
}

.metricas-rango {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.metricas-main {
  padding: 1.25rem 1.5rem;
}

.metricas-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.metricas-card {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.9rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.metricas-card-titulo {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.metricas-card-valor {
  font-size: 1.4rem;
}

.metricas-tabla {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.metricas-tabla th,
.metricas-tabla td {
  padding: 0.6rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}

.metricas-tabla th {
  background: color-mix(in srgb, var(--primary) 8%, transparent);
  font-weight: 600;
}

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

.filtros-wrap {
  position: relative;
}

/* Ancho fijo: que el contador "Filtros (N)" no corra al botón "Vistas"
   (ni el panel, que se posiciona relativo a .filtros-wrap) al aparecer. */
#btn-filtros {
  min-width: 5.6rem;
}

.config-wrap {
  position: relative;
}

.btn-config {
  min-width: 2.5rem;
  padding-inline: 0.7rem;
  font-size: 1.15rem;
}

.config-panel {
  position: absolute;
  z-index: 40;
  top: calc(100% + 0.45rem);
  right: 0;
  width: 360px;
  max-height: calc(100vh - 5rem);
  overflow-y: auto;
  padding: 0.6rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 12px 30px rgb(15 23 42 / 16%);
}

.config-panel[hidden] {
  display: none;
}

.config-panel strong {
  display: block;
  margin-bottom: 0.3rem;
  color: var(--text-muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.config-panel-grupo {
  margin-top: 0.4rem;
  padding-top: 0.3rem;
  border-top: 1px solid var(--border);
}

.config-panel .config-panel-grupo-riesgo {
  color: var(--danger);
}

.config-version {
  display: block;
  margin-bottom: 0.3rem;
  color: var(--text-muted);
  font-size: 0.72rem;
}

.config-panel .btn {
  display: block;
  width: 100%;
  margin-top: 0.15rem;
  padding: 0.35rem 0.5rem;
  text-align: left;
}

.config-panel-fila {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.15rem;
  font-size: 0.69rem;
  color: var(--text-muted);
}

.config-panel .theme-select {
  display: block;
  width: auto;
  margin-top: 0;
  padding: 0.35rem 0.5rem;
}

.filtros-panel {
  position: absolute;
  z-index: 30;
  top: calc(100% + 0.4rem);
  right: 0;
  width: 230px;
  padding: 0.8rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 12px 30px rgb(15 23 42 / 16%);
}

.filtros-panel[hidden] {
  display: none;
}

.filtros-grupo {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.filtros-grupo[hidden] {
  display: none;
}

.filtros-grupo + .filtros-grupo {
  margin-top: 0.8rem;
  padding-top: 0.8rem;
  border-top: 1px solid var(--border);
}

.filtros-grupo strong {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.filtros-grupo input[type="date"] {
  width: auto;
}

.ctz-revision-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  margin-bottom: 0.75rem;
}

.ctz-revision-pares {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 0.6rem;
}

.ctz-revision-lead {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
}

.ctz-revision-lead strong {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-transform: uppercase;
}

.ctz-revision-acciones {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.filtros-grupo label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.88rem;
}

#filtros-categorias {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.filtros-grupo input {
  width: auto;
  margin: 0;
}

.buscador {
  width: 100%;
  max-width: 420px;
  padding: 0.55rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: inherit;
}

.buscador:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

/* ---------- Board ---------- */

.board {
  display: flex;
  gap: 1rem;
  padding: 1.25rem;
  overflow-x: auto;
  overflow-y: auto;
  align-items: flex-start;
}

#board[hidden],
#board-tareas[hidden],
#board-fletes[hidden],
#board-historial[hidden] {
  display: none;
}


.fletes-filtros {
  display: flex;
  gap: 1rem;
  align-items: flex-end;
  flex-shrink: 0;
}

.fletes-filtros label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.fletes-lista {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  max-width: 900px;
  width: 100%;
}

.fletes-card {
  cursor: pointer;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.fletes-card:hover {
  border-color: var(--primary);
}

.fletes-card-cerrado {
  opacity: 0.6;
}

.fletes-card-titulo {
  font-weight: 600;
  flex: 1 1 auto;
}

.fletes-card-detalle {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.fletes-card-estado {
  font-size: 0.8rem;
  white-space: nowrap;
}

.column,
.column-tarea {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius);
  width: 280px;
  min-width: 140px;
  max-width: 640px;
  flex-shrink: 0;
  padding: 0.85rem;
  padding-right: 1.1rem;
  box-shadow: var(--shadow);
  min-height: 200px;
}

.column-tarea-hoy {
  border: 2px solid var(--primary);
}

.resize-handle {
  position: absolute;
  top: 0;
  right: -4px;
  width: 10px;
  height: 100%;
  cursor: col-resize;
  touch-action: none;
  z-index: 5;
}

.resize-handle::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 4px;
  width: 2px;
  border-radius: 2px;
  background: transparent;
}

.resize-handle:hover::after,
.resize-handle.resizing::after {
  background: var(--primary);
}

.column h2,
.column-tarea h2 {
  font-size: 0.95rem;
  font-weight: 700;
  margin: 0 0 0.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--secondary);
}

.column-titulo-link {
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}

.column-titulo-link:hover {
  text-decoration: underline;
}

.column-h2-derecha {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.column-orden-btn {
  border: none;
  background: transparent;
  color: var(--text-muted, #94a3b8);
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
  padding: 0.1rem 0.15rem;
  border-radius: 4px;
}

.column-orden-btn:hover {
  background: rgba(15, 23, 42, 0.08);
}

.column-orden-btn.activo {
  color: var(--primary);
  font-weight: 700;
}

.column-orden-grupo {
  display: flex;
  align-items: center;
  gap: 0.05rem;
}

.column-orden-criterio {
  margin-right: 0.1rem;
}

.column-tarea-h2-acciones {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.orden-tareas-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  border-radius: 6px;
  width: 1.5rem;
  height: 1.5rem;
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
}

.orden-tareas-btn:hover {
  background: var(--bg);
  color: var(--text);
}

.column-tarea-vencidas {
  border: 2px solid #dc2626;
}

.column-tarea-vencidas h2 {
  color: #dc2626;
}

.count {
  background: var(--bg);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
}

.column-total {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--primary);
  margin: -0.4rem 0 0.15rem;
}

/* Columnas fusionadas (Total Ganado, Perdido): el título ocupa el mismo
   lugar que en cualquier columna (h2 ya reparte título a la izquierda y
   badge a la derecha vía space-between); solo cambia su contenido según la
   vista activa (todos / eligiendo / un subconjunto). */
.ganado-filtro-link {
  font-size: 0.95rem;
  font-weight: 400;
  color: var(--text-muted);
  text-decoration: none;
  cursor: pointer;
}

.ganado-filtro-link:hover {
  text-decoration: underline;
}

.fusion-volver {
  font-weight: 700;
}

.cards,
.cards-tarea {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  min-height: 60px;
}

.cards[hidden] {
  display: none;
}

.btn-mostrar-mas {
  align-self: stretch;
  text-align: center;
  font-size: 0.8rem;
  padding: 0.5rem;
}

/* Las dos mitades de una columna fusionada (Ganado/FC sin CTZ,
   Perdido/Desestimados) se muestran una debajo de la otra en la vista
   "todos". Si una mitad está vacía, que no reserve sus 60px de alto mínimo
   (eso dejaba un hueco antes de la primera tarjeta de la otra mitad). Solo
   aplica en esa vista combinada: al elegir una mitad sola, conserva el alto
   mínimo para poder soltar una tarjeta arrastrada aunque esté vacía. */
.cards-fusion.cards-fusion-combinada {
  min-height: 0;
}

.column.drop-target {
  outline: 2px dashed var(--primary);
  outline-offset: -4px;
}

.card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0;
  cursor: grab;
  touch-action: none;
  user-select: none;
  perspective: 1000px;
  overflow: hidden;
}

.card-banda-pago {
  position: absolute;
  top: 11px;
  right: -34px;
  width: 130px;
  padding: 2px 0;
  text-align: center;
  font-size: 0.62rem;
  font-weight: 700;
  color: #fff;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  transform: rotate(45deg);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  z-index: 3;
  pointer-events: none;
}

.card-banda-impago {
  background: #dc2626;
}

.card-banda-parcial {
  background: #f97316;
}

.card-banda-pagado {
  background: #16a34a;
}

.card-agrupada {
  position: relative;
  padding: 0.6rem;
  cursor: pointer;
  box-shadow:
    4px 4px 0 0 var(--surface),
    4px 4px 0 1px var(--border),
    8px 8px 0 0 var(--surface),
    8px 8px 0 1px var(--border);
  margin-right: 8px;
  margin-bottom: 8px;
}

.card-agrupada-badge {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  margin-bottom: 0.35rem;
}

.leads-grupo-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.leads-grupo-item {
  flex: 1 1 200px;
  max-width: 240px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.leads-grupo-item:hover {
  border-color: var(--primary);
  background: rgba(242, 146, 0, 0.06);
}

.card.card-antiguedad-verde {
  background: #f0fdf4;
  border-color: #86efac;
}

.card.card-antiguedad-naranja {
  background: #fff7ed;
  border-color: #fdba74;
}

.card.card-antiguedad-rojo {
  background: #fef2f2;
  border-color: #fca5a5;
}

.card-inner {
  display: grid;
  transform-style: preserve-3d;
  transition: transform 0.45s ease;
}

.card.flipped .card-inner {
  transform: rotateY(180deg);
}

.card-face {
  grid-area: 1 / 1;
  min-width: 0;
  padding: 0.65rem 0.75rem;
  padding-bottom: 2.2rem;
  position: relative;
  backface-visibility: hidden;
}

.card-back {
  transform: rotateY(180deg);
  background: var(--surface);
}

.card.flipped .card-front,
.card:not(.flipped) .card-back {
  pointer-events: none;
}

.card-flip-btn {
  margin-top: 0.55rem;
  padding: 0.25rem 0.45rem;
  border: 0;
  border-radius: 6px;
  background: color-mix(in srgb, var(--primary) 10%, transparent);
  color: var(--primary);
  font: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
}

.card-back-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.card-front-footer,
.card-back-footer {
  position: absolute;
  left: 50%;
  bottom: 10px;
  transform: translateX(-50%);
}

.card-front-footer .card-flip-btn,
.card-flip-volver {
  margin-top: 0;
}

.card-tarea {
  cursor: default;
}

.card-tarea .card-face {
  padding-bottom: 0.65rem;
}

.card-front-footer-tarea {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.4rem;
  margin-top: 0.6rem;
}

.card-front-footer-tarea .card-flip-btn {
  margin-top: 0;
}

.card-tarea-clickable {
  cursor: pointer;
}

.card-back-tareas {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  color: var(--text-muted);
  font-size: 0.75rem;
}

.card-back-tarea {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.35rem 0.45rem;
  border-left: 3px solid var(--primary);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
}

.card-back-tarea-fecha {
  flex: 0 0 auto;
  color: var(--text-muted);
  font-size: 0.7rem;
  white-space: nowrap;
}

.card-back-tarea-clickable {
  cursor: pointer;
}

.card-back-tarea-clickable:hover {
  filter: brightness(0.95);
}

.card-back-tarea.hecha {
  opacity: 0.55;
}

.card-back-tarea.hecha,
.card-back-tarea.hecha .card-back-tarea-fecha {
  text-decoration: line-through;
}

.card:hover {
  border-color: var(--primary);
}

.card.dragging {
  position: fixed;
  z-index: 1000;
  box-shadow: 0 8px 24px rgba(16, 24, 40, 0.25);
  opacity: 0.95;
}

.card.card-bloqueada {
  cursor: default;
  background: var(--bg);
}

.card.card-bloqueada:hover {
  border-color: var(--border);
}

.card-nombre {
  font-weight: 600;
  font-size: 0.92rem;
  margin-bottom: 0.2rem;
}

.card-detalle {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.card-categoria {
  display: inline-block;
  margin-top: 0.35rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--primary) 12%, transparent);
  color: var(--primary);
  font-size: 0.7rem;
  font-weight: 600;
  border: 1px solid transparent;
}

.card-fecha {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

.card-monto {
  margin-top: 0.35rem;
  font-weight: 700;
  color: var(--primary);
  font-size: 0.85rem;
}

.card-presupuesto {
  margin-top: 0.15rem;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.card-creador {
  margin-top: 0.35rem;
  font-size: 0.72rem;
  color: var(--text-muted);
  font-style: italic;
}

.card-seguimiento {
  margin-top: 0.15rem;
  font-size: 0.72rem;
  color: var(--primary);
  font-weight: 600;
}

.creador-info {
  margin: -0.5rem 0 0.75rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.lead-cerrado-aviso {
  margin: 0 0 0.75rem;
  padding: 0.6rem 0.75rem;
  border: 1px solid #f59e0b;
  border-radius: 0.5rem;
  background: #fffbeb;
  color: #92400e;
  font-size: 0.82rem;
  font-weight: 600;
}

.lead-solo-lectura #archivo-dropzone,
.lead-solo-lectura .archivo-borrar {
  display: none !important;
}

.lead-form-footer {
  position: sticky;
  bottom: 0;
  background: var(--surface);
  padding-top: 0.5rem;
  margin-top: 0.35rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.lead-acciones-estado {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.lead-acciones-estado[hidden] {
  display: none;
}

.lead-seccion-box {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.6rem 0.7rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.lead-seccion-box-titulo {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.lead-seccion-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.5rem;
}

.lead-seccion-acciones {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.lead-grid-pago {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}

.lead-grid-pago[hidden] {
  display: none;
}

.lead-grid-pago .btn {
  grid-column: 1 / -1;
}

.btn-outline-primary {
  color: var(--primary);
  background: transparent;
  border: 1px solid var(--primary);
}

.btn-outline-primary:hover {
  background: rgba(37, 99, 235, 0.08);
}

.btn-vendido {
  color: #fff;
  background: #16a34a;
  border-color: #15803d;
}

.btn-vendido:hover {
  background: #15803d;
}

.btn-perdido {
  color: #fff;
  background: #dc2626;
  border-color: #b91c1c;
}

.btn-perdido:hover {
  background: #b91c1c;
}

.btn-coordinar-pago {
  color: #fff;
  background: #0891b2;
  border-color: #0e7490;
}

.btn-coordinar-pago:hover {
  background: #0e7490;
}

.btn-pago-coordinado {
  color: #fff;
  background: #0891b2;
  border-color: #0e7490;
}

.btn-pago-coordinado:hover {
  background: #0e7490;
}

/* ---------- Modal ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 100;
}

.modal-overlay[hidden] {
  display: none;
}

#lead-modal-overlay {
  z-index: 110;
}

/* Se abren desde arriba del modal de lead (que ya tiene z-index: 110), no
   debajo. */
#unificar-lead-modal-overlay,
#motivo-perdida-elegir-modal-overlay {
  z-index: 120;
}

#tareas-modal-overlay {
  padding: 1cm;
}

#tareas-modal-overlay .modal {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
}

#historial-general-modal-overlay .modal {
  overflow: visible;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 100%;
  max-width: 840px;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}

.modal.modal-chico {
  max-width: 360px;
}

.modal.modal-ancho {
  max-width: 1000px;
}

.modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.9rem;
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
}

.modal h2 {
  margin-top: 0;
  font-size: 1.15rem;
}

.modal-header-row {
  padding-right: 2.2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.modal-header-row h2 {
  margin: 0;
}

.tareas-header-acciones {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.contactar-tarea-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

#buscador-tareas {
  margin-top: 0.9rem;
}

.tareas-contador {
  margin: 0.6rem 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.modal h3 {
  font-size: 0.95rem;
  margin: 1.25rem 0 0.5rem;
}

.modal form {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.modal form label {
  font-size: 0.82rem;
  font-weight: 600;
  margin-top: 0.4rem;
}

/* Formularios simples "título -> campo": la etiqueta va a la izquierda y el
   campo a completar a la derecha, en la misma fila.
   Selectores con "form" a propósito: ".modal form"/".modal form label" ya
   definidos arriba tienen la misma o mayor especificidad que ".campos-grid"
   solo, así que sin el elemento "form" acá estas reglas pierden y no aplican. */
form.campos-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  column-gap: 0.75rem;
  row-gap: 0.4rem;
}

/* Ficha del lead: renglones más compactos que el resto de los formularios. */
#lead-form.campos-grid {
  row-gap: 0.15rem;
}

.icono-telefono-contactado {
  font-size: 1.3em;
  color: #16a34a;
}

form.campos-grid label {
  margin: 0;
  text-align: left;
}

form.campos-grid > button,
form.campos-grid > .lead-form-footer,
form.campos-grid > .check-linea,
form.campos-grid > .campo-ancho {
  grid-column: 1 / -1;
}

#nuevo-tipo-tarea-regla.campo-ancho:not([hidden]) {
  display: contents;
}

/* ---------- Modal de lead: 3 columnas ---------- */

.modal-lead {
  max-width: 1080px;
}

.lead-modal-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0;
}

.lead-modal-col {
  padding: 0 1.5rem;
  min-width: 0;
}

.lead-modal-titulo-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.lead-modal-titulo-row h2 {
  margin: 0;
}

.lead-nav-arrows {
  display: flex;
  gap: 0.3rem;
}

.lead-nav-arrows button {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 0.2rem 0.5rem;
  line-height: 1;
}

.lead-nav-arrows button:hover {
  background: var(--bg);
  color: var(--text);
}

.lead-modal-col:first-child {
  padding-left: 0;
}

.lead-modal-col:last-child {
  padding-right: 0;
}

.lead-modal-col-divisoria {
  border-left: 1px solid var(--border);
}

.lead-modal-col h3:first-child {
  margin-top: 0;
}

@media (min-width: 901px) {
  .lead-existente .modal-lead {
    height: min(86vh, 760px);
    overflow: hidden;
  }

  .lead-existente .lead-modal-grid {
    height: 100%;
  }

  .lead-existente .lead-modal-col {
    overflow-y: auto;
  }

  .lead-existente .lead-modal-col-central {
    display: grid;
    grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
    overflow: hidden;
  }

  .lead-existente #historial-section,
  .lead-existente #archivos-section {
    display: flex;
    min-height: 0;
    flex-direction: column;
    overflow: hidden;
  }

  /* Ganado/Vendido directo: todo el tercio derecho (Fechas de seguimiento +
     Novedades) queda oculto y lo reemplaza el menú de Envío a pantalla
     completa — sin este [hidden] el "display: flex" de más abajo le gana
     al atributo hidden y las secciones se siguen viendo igual. */
  .lead-existente #fechas-seguimiento-section[hidden],
  .lead-existente #novedades-section[hidden] {
    display: none;
  }

  .lead-existente.lead-envio-activo .lead-modal-col-derecha {
    grid-template-rows: 1fr;
  }

  .lead-existente.lead-envio-activo #envio-section {
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow-y: auto;
  }

  .lead-existente #historial-section {
    padding-bottom: 0.8rem;
    border-bottom: 1px solid var(--border);
  }

  .lead-existente #archivos-section {
    padding-top: 0.8rem;
  }

  .lead-existente #historial-list,
  .lead-existente #archivos-list {
    flex: 1;
    max-height: none;
    overflow-y: auto;
  }

  /* Fechas de seguimiento y novedades comparten el 40% superior (más
     compactas y pegadas entre sí); la ficha de envío/flete ocupa el 60%
     inferior de la columna. */
  .lead-existente .lead-modal-col-derecha {
    display: grid;
    grid-template-rows: minmax(0, 0.7fr) minmax(0, 0.7fr) auto;
    overflow: hidden;
  }

  .lead-existente #fechas-seguimiento-section,
  .lead-existente #novedades-section {
    display: flex;
    min-height: 0;
    flex-direction: column;
    overflow: hidden;
  }

  .lead-existente #fechas-seguimiento-section {
    padding-bottom: 0.4rem;
  }

  .lead-existente #novedades-section {
    padding-top: 0.4rem;
    padding-bottom: 0.6rem;
    border-bottom: 1px solid var(--border);
  }

  .lead-existente #fechas-seguimiento-list,
  .lead-existente #novedades-list {
    flex: 1;
    max-height: none;
    overflow-y: auto;
  }

  .lead-existente #envio-section {
    padding-top: 0.6rem;
    overflow: visible;
    min-height: 0;
  }
}

.envio-flete-opciones {
  display: flex;
  gap: 1rem;
}

#envio-section {
  transition: background-color 0.15s ease;
  border-radius: 8px;
  padding: 0.4rem 0.5rem;
  margin: -0.4rem -0.5rem;
}

.envio-section-cobrado {
  background-color: rgba(22, 163, 74, 0.12);
}

.envio-section-no-cobrado {
  background-color: rgba(220, 38, 38, 0.1);
}

.envio-flete-leyenda {
  font-weight: 600;
  margin: 0.5rem 0 0;
}

.envio-section-cobrado .envio-flete-leyenda {
  color: #16a34a;
}

.envio-section-no-cobrado .envio-flete-leyenda {
  color: #dc2626;
}

.fecha-picker {
  position: relative;
  display: flex;
  align-items: stretch;
  gap: 0.35rem;
}

.fecha-picker-texto {
  flex: 1;
  font: inherit;
  text-align: left;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border-color, #ccc);
  border-radius: 6px;
  background: var(--bg-card, #fff);
  color: var(--text);
  cursor: pointer;
}

.fecha-picker-flechas {
  display: flex;
  flex-direction: column;
}

.fecha-picker-flecha {
  font-size: 0.6rem;
  line-height: 1;
  padding: 0.15rem 0.4rem;
  border: 1px solid var(--border-color, #ccc);
  background: var(--bg-card, #fff);
  color: var(--text);
  cursor: pointer;
}

.fecha-picker-flecha:first-child {
  border-radius: 6px 6px 0 0;
  border-bottom: none;
}

.fecha-picker-flecha:last-child {
  border-radius: 0 0 6px 6px;
}

.fecha-picker.fecha-picker-disabled .fecha-picker-texto,
.fecha-picker.fecha-picker-disabled .fecha-picker-flecha {
  opacity: 0.6;
  pointer-events: none;
}

.fecha-picker-calendario {
  position: absolute;
  top: calc(100% + 0.3rem);
  left: 0;
  z-index: 30;
  background: var(--bg-card, #fff);
  border: 1px solid var(--border-color, #ccc);
  border-radius: 8px;
  padding: 0.6rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.18);
  width: 15.5rem;
}

.fecha-picker-calendario-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  margin-bottom: 0.4rem;
}

.fecha-picker-calendario-header button {
  border: none;
  background: transparent;
  font-size: 1rem;
  cursor: pointer;
  padding: 0.1rem 0.5rem;
  color: var(--text);
}

.fecha-picker-calendario-dow {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  text-align: center;
  margin-bottom: 0.2rem;
}

.fecha-picker-dow-domingo {
  color: #dc2626;
}

.fecha-picker-calendario-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.15rem;
}

.fecha-picker-dia {
  border: none;
  background: transparent;
  border-radius: 6px;
  padding: 0.35rem 0;
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
  color: var(--text);
}

.fecha-picker-dia:hover {
  background: var(--bg-hover, rgba(0, 0, 0, 0.06));
}

.fecha-picker-dia-vacio {
  cursor: default;
  pointer-events: none;
}

.fecha-picker-dia-domingo {
  color: #dc2626;
}

.fecha-picker-dia-hoy {
  font-weight: 700;
  text-decoration: underline;
}

.fecha-picker-dia-seleccionado {
  background: var(--primary);
  color: #fff;
}

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

  .lead-modal-col {
    padding: 0;
  }

  .lead-modal-col-divisoria {
    border-left: none;
    border-top: 1px solid var(--border);
    padding-top: 1rem;
    margin-top: 1rem;
  }
}

.btn-agregar-novedad {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.4rem;
  height: 1.4rem;
  margin-left: 0.4rem;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--bg);
  color: var(--primary, #2563eb);
  font-size: 0.95rem;
  line-height: 1;
  cursor: pointer;
  vertical-align: middle;
}

.btn-agregar-novedad:hover {
  background: var(--primary, #2563eb);
  color: #fff;
}

.historial-list {
  list-style: none;
  margin: 0 0 0.5rem;
  padding: 0;
  max-height: 180px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.board-historial {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1.25rem;
  max-width: 900px;
}

.board-historial .historial-list {
  max-height: none;
  overflow-y: visible;
}

.historial-list li {
  background: var(--bg);
  border-radius: 6px;
  padding: 0.5rem 0.6rem;
  font-size: 0.82rem;
}

.historial-item {
  border-left: 3px solid var(--border);
}

.historial-creacion { border-left-color: #16a34a; }
.historial-movimiento { border-left-color: #2563eb; }
.historial-modificacion { border-left-color: #ea580c; }
.historial-tarea { border-left-color: #7c3aed; }
.historial-archivo { border-left-color: #0891b2; }
.historial-seguimiento { border-left-color: #db2777; }
.historial-nota { border-left-color: #d97706; }
.historial-derivacion { border-left-color: #0891b2; }
.historial-ganado { border-left-color: #16a34a; }
.historial-perdido { border-left-color: #dc2626; }
.historial-revision { border-left-color: #d97706; }
.historial-motivo-perdida { border-left-color: #dc2626; font-weight: 600; color: #dc2626; }

.usuario-row,
.usuarios-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.usuarios-list {
  list-style: none;
  margin: 0 0 0.5rem;
  padding: 0;
  max-height: 260px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.usuarios-list li {
  background: var(--bg);
  border-radius: 6px;
  padding: 0.5rem 0.6rem;
  font-size: 0.82rem;
}

.usuarios-list li.usuario-inactivo {
  opacity: 0.55;
}

.usuario-controles {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.usuario-controles select {
  width: auto;
}

.usuario-permiso {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  cursor: pointer;
}

.usuario-card {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  background: var(--bg);
  border-radius: 8px;
  padding: 0.7rem 0.8rem;
  font-size: 0.82rem;
}

.usuario-card.usuario-inactivo {
  opacity: 0.55;
}

.usuario-card-cabecera {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.usuario-card-nombre {
  font-weight: 600;
}

.usuario-card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.5rem 0.8rem;
}

.usuario-card-campo {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.usuario-card-campo label {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.usuario-card-campo-inline {
  display: flex;
  gap: 0.35rem;
}

.usuario-card-campo-inline input {
  flex: 1;
}

.envio-remito-fila {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
  font-size: 0.82rem;
}

.historial-list .historial-fecha {
  display: block;
  color: var(--text-muted);
  font-size: 0.72rem;
  margin-top: 0.15rem;
}

.columnas-list {
  list-style: none;
  margin: 0 0 1rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 280px;
  overflow-y: auto;
}

.columna-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.columna-row input[type="text"] {
  flex: 1;
}

.columna-row input[type="color"] {
  width: 2.5rem;
  min-width: 2.5rem;
  height: 2.2rem;
  padding: 0.15rem;
  cursor: pointer;
}

.columna-row.oculta {
  opacity: 0.5;
}

.columna-row input.categoria-dias-input {
  width: 4.2rem;
  min-width: 4.2rem;
  flex: 0 0 auto;
}

.columna-row .btn {
  padding: 0.45rem 0.6rem;
  font-size: 0.78rem;
  white-space: nowrap;
}

.tipos-tarea-list {
  max-height: 360px;
  margin: 0 0 1rem;
  padding: 0;
  overflow-y: auto;
  list-style: none;
}

.tipo-tarea-row {
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--border);
}

.tipo-tarea-row.oculta {
  opacity: 0.55;
}

.tipo-tarea-principal,
.tipo-tarea-regla {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.tipo-tarea-principal input[type="text"] {
  flex: 1;
}

.tipo-tarea-principal input[type="color"] {
  width: 2.5rem;
  min-width: 2.5rem;
  height: 2.2rem;
  padding: 0.15rem;
}

.tipo-tarea-regla {
  margin-top: 0.45rem;
}

.tipo-tarea-regla label,
.check-linea {
  display: flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: 0.35rem;
}

.tipo-tarea-regla input[type="checkbox"],
.check-linea input {
  width: auto;
}

.tipo-tarea-regla select {
  flex: 1;
}

.tipo-tarea-regla input[type="number"] {
  width: 75px;
}

#nuevo-tipo-tarea-regla[hidden],
.tipo-tarea-regla [hidden] {
  display: none;
}

.archivo-dropzone {
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 1rem;
  text-align: center;
  font-size: 0.82rem;
  color: var(--text-muted);
  cursor: pointer;
  margin-bottom: 0.6rem;
  transition: border-color 0.15s, background-color 0.15s, color 0.15s;
}

.archivo-dropzone.dragover {
  border-color: var(--primary);
  background: rgba(242, 146, 0, 0.08);
  color: var(--primary);
}

.archivo-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.archivo-item a {
  color: var(--secondary);
  font-weight: 600;
  text-decoration: none;
}

.archivo-item a:hover {
  text-decoration: underline;
}

.archivo-item a.archivo-accion {
  color: var(--text-muted);
  font-weight: 400;
}

.archivo-item a.archivo-accion:hover {
  text-decoration: none;
  background: var(--bg);
}

.archivo-borrar {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0 0.2rem;
}

/* ---------- Chat interno (historial del sistema) ---------- */

.chat-mensajes {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 50vh;
  min-height: 220px;
  overflow-y: auto;
  margin: 0.5rem 0 0.75rem;
  padding-right: 0.2rem;
}

.chat-mensaje {
  background: var(--bg);
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
  font-size: 0.85rem;
}

.chat-mensaje.propio {
  background: rgba(242, 146, 0, 0.12);
  align-self: flex-end;
}

.chat-mensaje.sistema {
  background: transparent;
  border: 1px dashed var(--border);
  color: var(--text-muted);
  font-style: italic;
  font-size: 0.78rem;
  text-align: center;
}

.chat-hora {
  display: block;
  color: var(--text-muted);
  font-size: 0.7rem;
  margin-top: 0.15rem;
}

.chat-punto-lectura {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin-left: 0.35rem;
  background: #9ca3af;
  vertical-align: middle;
}

.chat-punto-lectura.chat-punto-parcial {
  background: #2563eb;
}

.chat-punto-lectura[hidden] {
  display: none;
}

/* ---------- Chat privado (panel lateral) ---------- */

.chat-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 30vw;
  height: 100vh;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  z-index: 90;
}

body.chat-abierto .chat-panel {
  transform: translateX(0);
}

.chat-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}

.chat-panel-usuarios {
  flex: 1;
  overflow-y: auto;
}

.chat-crear-grupo-btn {
  display: block;
  width: calc(100% - 2rem);
  margin: 0.75rem 1rem;
}

.chat-usuarios-lista {
  list-style: none;
  margin: 0;
  padding: 0;
}

.chat-usuarios-lista:empty {
  display: none;
}

.grupo-crear-miembros {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 260px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.grupo-crear-miembros li {
  padding: 0.4rem 0.7rem;
  border-bottom: 1px solid var(--border);
}

.grupo-crear-miembros li:last-child {
  border-bottom: none;
}

.grupo-crear-miembros label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 400;
  margin: 0;
  cursor: pointer;
}

.chat-usuario-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
}

.chat-usuario-item:hover {
  background: var(--bg);
}

.chat-usuario-nombre {
  font-size: 0.8rem;
}

.chat-usuario-estado {
  width: 10px;
  height: 10px;
  min-width: 10px;
  border-radius: 50%;
  background: #dc2626;
  display: inline-block;
}

.chat-usuario-estado.chat-usuario-online {
  background: #16a34a;
}

.chat-panel-conversacion {
  flex: 1;
  min-height: 0;
}

.chat-panel-conversacion:not([hidden]) {
  display: flex;
  flex-direction: column;
}

.chat-conversacion-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--border);
}

.chat-conversacion-volver {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--secondary);
  padding: 0;
}

.chat-conversacion-mensajes {
  flex: 4 1 0;
  overflow-y: auto;
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-height: 0;
}

.chat-conversacion-form {
  flex: 1 1 0;
  display: flex;
  gap: 0.5rem;
  padding: 0.6rem;
  border-top: 1px solid var(--border);
  min-height: 0;
}

.chat-conversacion-form textarea {
  flex: 1;
  resize: none;
  min-height: 0;
}

.chat-lead-adjunto {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.4rem 0.75rem;
  background: #eef2ff;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  color: #3730a3;
}

.chat-lead-adjunto button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1rem;
  color: #3730a3;
  line-height: 1;
}

.chat-lead-picker-wrap {
  position: relative;
}

.chat-lead-picker {
  position: absolute;
  bottom: 100%;
  left: 0.6rem;
  right: 0.6rem;
  margin: 0 0 0.3rem;
  padding: 0.3rem 0;
  list-style: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.15);
  max-height: 180px;
  overflow-y: auto;
  z-index: 10;
}

.chat-lead-picker li {
  padding: 0.4rem 0.75rem;
  cursor: pointer;
  font-size: 0.85rem;
}

.chat-lead-picker li:hover,
.chat-lead-picker li.activo {
  background: var(--bg);
}

.chat-lead-picker li.chat-lead-picker-vacio {
  color: var(--text-muted);
  cursor: default;
}

.chat-lead-picker li.chat-lead-picker-vacio:hover {
  background: transparent;
}

.chat-lead-link {
  display: inline-block;
  margin-top: 0.3rem;
  font-size: 0.8rem;
  color: var(--secondary);
  text-decoration: underline;
  cursor: pointer;
}

.chat-asignacion-acciones {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

.chat-asignacion-acciones .btn {
  padding: 0.3rem 0.7rem;
  font-size: 0.8rem;
}

/* ---------- Notificación de mensaje nuevo ---------- */

.chat-notificacion {
  position: fixed;
  top: 5.5rem;
  right: 0;
  width: 280px;
  max-width: calc(100vw - 1rem);
  background: #e5e7eb;
  color: #1f2937;
  border-radius: 8px 0 0 8px;
  box-shadow: -2px 3px 12px rgba(15, 23, 42, 0.25);
  padding: 0.75rem 1rem;
  transform: translateX(100%);
  transition: transform 0.4s ease;
  cursor: pointer;
  z-index: 150;
}

.chat-notificacion.visible {
  transform: translateX(0);
}

.chat-notificacion[hidden] {
  display: none;
}

.chat-notificacion-cerrar {
  position: absolute;
  top: 0.4rem;
  right: 0.6rem;
  background: none;
  border: none;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  color: #4b5563;
}

.chat-notificacion-titulo {
  font-weight: 700;
  padding-right: 1.2rem;
  margin-bottom: 0.25rem;
}

.chat-notificacion-preview {
  font-size: 0.85rem;
  color: #4b5563;
  overflow-wrap: break-word;
}

.chat-config-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 1rem 0 0.5rem;
}

@keyframes parpadeo-chat-rojo {
  0%,
  100% {
    background: var(--surface);
    color: inherit;
    border-color: var(--border);
  }
  50% {
    background: #dc2626;
    color: white;
    border-color: #dc2626;
  }
}

#btn-chat.chat-parpadeo {
  animation: parpadeo-chat-rojo 1s ease-in-out infinite;
}

@keyframes parpadeo-texto-rojo {
  0%,
  100% {
    color: inherit;
    font-weight: 400;
  }
  50% {
    color: #dc2626;
    font-weight: 700;
  }
}

.chat-usuario-nombre.chat-usuario-parpadeo {
  animation: parpadeo-texto-rojo 1s ease-in-out infinite;
}

@keyframes parpadeo-campo-rojo {
  0%,
  100% {
    border-color: var(--border);
    background: var(--bg-card, #fff);
  }
  50% {
    border-color: #dc2626;
    background: rgba(220, 38, 38, 0.12);
  }
}

.campo-error-parpadeo {
  animation: parpadeo-campo-rojo 0.7s ease-in-out 3;
}

@keyframes parpadeo-config-verde {
  0%,
  100% {
    background: var(--surface);
    color: inherit;
    border-color: transparent;
  }
  50% {
    background: #16a34a;
    color: #fff;
    border-color: #16a34a;
  }
}

#btn-config.config-parpadeo {
  animation: parpadeo-config-verde 1s ease-in-out infinite;
}

/* ---------- Tareas ---------- */

.tareas-list {
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  max-height: 420px;
  overflow-y: auto;
}

.tarea-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.6rem;
}

.tarea-item.hecha {
  opacity: 0.6;
}

.tarea-item.tarea-vencida {
  border-color: #fecaca;
  background: #fef2f2;
}

.tarea-item.tarea-vence-hoy {
  border-color: #fde68a;
  background: #fffbeb;
}

.tarea-badge {
  display: inline-block;
  flex: 0 0 auto;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.tarea-badge-vencida {
  background: #fecaca;
  color: #991b1b;
}

.tarea-badge-vence-hoy {
  background: #fde68a;
  color: #92400e;
}

.tarea-badge-pago {
  display: inline-block;
  flex: 0 0 auto;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  white-space: nowrap;
  color: #fff;
}

.tarea-badge-pago-impago {
  background: #dc2626;
}

.tarea-badge-pago-parcial {
  background: #f97316;
}

.tarea-badge-pago-pagado {
  background: #16a34a;
}

.tarea-fila {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35rem 0.6rem;
}

.tarea-tipo {
  flex: 0 0 auto;
  font-weight: 700;
  font-size: 0.85rem;
  white-space: nowrap;
}

.tarea-tipo.tachado {
  text-decoration: line-through;
}

.tarea-categoria {
  flex: 0 0 auto;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  background: color-mix(in srgb, var(--primary) 12%, transparent);
  font-size: 0.72rem;
  font-weight: 600;
  white-space: nowrap;
}

.tarea-lead-link {
  flex: 0 1 auto;
  min-width: 0;
  overflow-wrap: anywhere;
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--secondary);
  cursor: pointer;
  text-decoration: underline;
}

.tarea-lead-link:hover {
  color: var(--primary);
}

span.tarea-lead-link {
  color: var(--text-muted);
  font-weight: 400;
  cursor: default;
  text-decoration: none;
}

.tarea-fecha {
  flex: 0 0 auto;
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
  margin-left: auto;
}

.tarea-acciones {
  display: flex;
  flex: 0 0 auto;
  gap: 0.35rem;
  flex-wrap: nowrap;
}

.tarea-acciones .btn {
  padding: 0.25rem 0.55rem;
  font-size: 0.74rem;
  white-space: nowrap;
}

.contactar-fecha-opciones {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.3rem 0 0.6rem;
}

.contactar-fecha-opcion {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
}

.contactar-fecha-opcion input {
  width: auto;
  margin: 0;
}

.contactar-fecha-opcion.seleccionada {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 10%, transparent);
  color: var(--primary);
}

#contactar-tarea-fecha-manual[hidden] {
  display: none;
}

.contactar-tarea-acciones {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 0.9rem;
}

.contactar-tarea-acciones .btn {
  flex: 1 1 140px;
}

.tarea-lead-resultados {
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: 160px;
  overflow-y: auto;
  margin-top: -0.15rem;
  background: var(--surface);
}

.tarea-lead-resultado-item {
  padding: 0.45rem 0.6rem;
  font-size: 0.82rem;
  cursor: pointer;
}

.tarea-lead-resultado-item:hover {
  background: var(--bg);
}

.tarea-lead-seleccionado {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  background: var(--bg);
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
  font-size: 0.85rem;
}

.tarea-lead-seleccionado[hidden] {
  display: none;
}

/* ---------- Responsive ---------- */

@media (max-width: 640px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.6rem;
  }

  .topbar-actions {
    flex-wrap: wrap;
  }

  .board {
    padding: 0.75rem;
  }

  .column {
    min-width: 82vw;
    max-width: 82vw;
  }
}
.logout-form {
  display: inline;
  margin: 0;
}

/* ---------- Vista mobile del transportista ---------- */

.transportista-body {
  background: var(--bg, #f1f5f9);
  min-height: 100vh;
}

.transportista-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.transportista-logo {
  height: 2.2rem;
  width: auto;
}

.transportista-header-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  line-height: 1.25;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.transportista-header-info strong {
  font-size: 1rem;
  color: var(--text);
}

.transportista-main {
  max-width: 480px;
  margin: 0 auto;
  padding: 1rem;
}

.transportista-vacio {
  text-align: center;
  color: var(--text-muted);
  margin-top: 3rem;
}

.transportista-lista {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.transportista-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.transportista-card-hecho {
  opacity: 0.7;
}

.transportista-card-nombre {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
}

.transportista-card-fecha {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.transportista-card-link {
  color: var(--primary);
  text-decoration: none;
  font-size: 0.95rem;
}

.transportista-card-link:hover {
  text-decoration: underline;
}

.transportista-card-btn {
  margin-top: 0.5rem;
  width: 100%;
  padding: 0.75rem;
  font-size: 1rem;
}

.transportista-card-badge {
  margin-top: 0.4rem;
  font-weight: 700;
  color: #16a34a;
}

.transportista-foto-btn {
  display: block;
  width: 100%;
  text-align: center;
  padding: 0.9rem;
  font-size: 1rem;
  cursor: pointer;
  margin-top: 0.5rem;
}

.transportista-remito-preview {
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin-top: 0.75rem;
}

#transportista-recibido-confirmar {
  width: 100%;
  padding: 0.85rem;
  font-size: 1.05rem;
  margin-top: 1rem;
}
