/* ==========================================================================
   DonaTrack · Servicio de Logística + Administración
   Sistema de diseño "Manifiesto de ruta"
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:ital,wght@0,400;0,500;0,600;0,700;0,800;1,500;1,600&display=swap');

:root {
  /* --- Color: paleta con nombre --- */
  --ink:          #1E2749; /* texto principal, azul noche */
  --paper:        #B9D4F5; /* fondo de página, celeste pastel */
  --surface:      #FFFFFF; /* tarjetas y paneles */
  --surface-2:    #F1F6FD; /* paneles secundarios / hover */
  --route:        #2F6FE4; /* azul — primario, acciones, enlaces */
  --route-dark:   #1F56C4;
  --route-tint:   #E1EBFB;
  --cargo:        #5B4FE0; /* índigo — acento de selección, "en tránsito" */
  --cargo-dark:   #4636C4;
  --cargo-tint:   #ECEAFC;
  --alert:        #D6455A; /* rojo — errores, entrega fallida */
  --alert-dark:   #A82F42;
  --alert-tint:   #FBE4E8;
  --caution:      #C98A1D; /* ámbar oscuro — pendiente / atención */
  --caution-tint: #FBEFD7;
  --mist:         #45507A; /* texto secundario / bordes */
  --mist-2:       #8B98BE; /* texto terciario / placeholders */
  --line:         #D3E1F5; /* bordes sutiles */

  /* --- Tipografía --- */
  --font-display: 'Inter', system-ui, sans-serif;
  --font-body:    'Inter', system-ui, sans-serif;
  --font-mono:    'Inter', system-ui, sans-serif;

  /* --- Espaciado (escala de 4px) --- */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-7: 32px;
  --sp-8: 40px;
  --sp-9: 56px;
  --sp-10: 72px;

  /* --- Bordes y sombras --- */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 14px;
  --radius-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(30, 39, 73, 0.07), 0 1px 1px rgba(30, 39, 73, 0.05);
  --shadow-md: 0 8px 20px rgba(30, 39, 73, 0.12), 0 2px 6px rgba(30, 39, 73, 0.06);
  --shadow-lg: 0 20px 44px rgba(30, 39, 73, 0.20);

  --sidebar-w: 248px;
  --topbar-h: 68px;
}

/* ==========================================================================
   Reset & base
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--paper);
  line-height: 1.5;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 700;
  line-height: 1.2;
  margin: 0 0 var(--sp-2);
  letter-spacing: -0.005em;
}
h1 { font-size: clamp(1.6rem, 1.3rem + 1.2vw, 2.2rem); font-weight: 800; }
h2 { font-size: 1.375rem; }
h3 { font-size: 1.1rem; }
p { margin: 0 0 var(--sp-3); color: var(--mist); }
a { color: var(--route-dark); text-decoration-thickness: 1.5px; text-underline-offset: 2px; }
a:hover { color: var(--route); }
ul { margin: 0; padding: 0; list-style: none; }
img { max-width: 100%; display: block; }
button { font-family: inherit; }
code, .mono { font-family: var(--font-mono); }

/* Foco visible accesible en toda la app */
:focus-visible {
  outline: 3px solid var(--cargo);
  outline-offset: 2px;
  border-radius: 4px;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; scroll-behavior: auto !important; }
}

/* Utilidades de accesibilidad */
.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;
}
.skip-link {
  position: absolute; left: var(--sp-3); top: -60px;
  background: var(--ink); color: #fff; padding: var(--sp-2) var(--sp-4);
  border-radius: var(--radius-sm); z-index: 200; transition: top .15s ease;
}
.skip-link:focus { top: var(--sp-3); }

/* Toda superficie interactiva respeta el hit-area mínimo de 48x48 */
.tap-target { min-width: 48px; min-height: 48px; display: inline-flex; align-items: center; justify-content: center; }

.icon { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }

/* ==========================================================================
   Botones
   ========================================================================== */
.btn {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.94rem;
  border-radius: var(--radius-md);
  border: 1.5px solid transparent;
  padding: var(--sp-3) var(--sp-5);
  min-height: 48px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, transform .05s ease;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--route); color: #fff; }
.btn-primary:hover { background: var(--route-dark); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn-secondary:hover { background: var(--surface-2); border-color: var(--mist-2); }
.btn-ghost { background: transparent; color: var(--route-dark); border-color: transparent; }
.btn-ghost:hover { background: var(--route-tint); }
.btn-danger { background: var(--alert); color: #fff; }
.btn-danger:hover { background: var(--alert-dark); }
.btn-cargo { background: var(--cargo); color: #fff; }
.btn-cargo:hover { background: var(--cargo-dark); }
.btn-block { width: 100%; }
.btn-sm { min-height: 40px; padding: var(--sp-2) var(--sp-4); font-size: 0.85rem; }
.btn-icon { padding: 0; width: 48px; height: 48px; border-radius: var(--radius-md); }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* ==========================================================================
   Formularios
   ========================================================================== */
.field { margin-bottom: var(--sp-5); }
.field label {
  display: block; font-weight: 600; font-size: 0.85rem;
  margin-bottom: var(--sp-2); color: var(--ink);
}
.hint, .field .hint { font-size: 0.82rem; color: var(--mist); margin: var(--sp-1) 0 0; }
.field .error-msg { font-size: 0.8rem; color: var(--alert-dark); margin-top: var(--sp-1); font-weight: 600; }
input:not([type]), input[type="search"], input[type="url"], input[type="time"],
input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="tel"], input[type="date"], select, textarea {
  width: 100%; font-size: 1rem; font-family: var(--font-body);
  padding: var(--sp-3) var(--sp-4); min-height: 48px;
  border: 1.5px solid #C3D3E9; border-radius: 10px;
  background: #F8FAFE; color: var(--ink); min-width: 0;
  box-shadow: inset 0 1px 2px rgba(30,39,73,.025);
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
textarea { min-height: 96px; resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--mist-2); }
input:focus, select:focus, textarea:focus {
  border-color: var(--route); background-color: var(--surface);
  box-shadow: 0 0 0 4px rgba(47,111,228,.12);
}
select {
  appearance: none; padding-right: 44px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%2345507A' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m7 10 5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center;
}
input:disabled, textarea:disabled, select:disabled { cursor: not-allowed; opacity: .65; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--route); width: 18px; height: 18px; flex-shrink: 0; }
.field:focus-within > label { color: var(--route-dark); }
.field > input, .field > select, .field > textarea { display: block; }
.field input:required:user-invalid, .field textarea:required:user-invalid, .field select:required:user-invalid {
  border-color: var(--alert); background-color: #FFF9FA;
}
.input-with-icon { position: relative; }
.input-with-icon .icon { position: absolute; left: var(--sp-4); top: 50%; transform: translateY(-50%); color: var(--mist-2); }
.input-with-icon input { padding-left: var(--sp-9); }
.checkbox-row { display: flex; align-items: center; gap: var(--sp-2); }
.checkbox-row input { width: 20px; height: 20px; min-height: unset; accent-color: var(--route); }

/* ==========================================================================
   Layout de la consola (post-login)
   ========================================================================== */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; background: var(--surface); color: var(--ink);
  display: flex; flex-direction: column; position: fixed; top: 0; left: 0; bottom: 0;
  z-index: 60; transition: transform .2s ease; border-right: 1px solid var(--line);
}
.sidebar-brand {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-5) var(--sp-5) var(--sp-4); font-family: var(--font-display);
  font-weight: 700; font-size: 1.1rem; color: var(--ink);
}
.sidebar-brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--cargo); }
.sidebar-nav { flex: 1; overflow-y: auto; padding: var(--sp-2) var(--sp-3); }
.sidebar-section { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--mist-2); padding: var(--sp-4) var(--sp-3) var(--sp-1); }
.sidebar a { text-decoration: none; }

.sidebar-link {
  display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-3);
  border-radius: var(--radius-md); color: var(--ink); font-weight: 500; font-size: 0.92rem;
  min-height: 48px; position: relative;
}
.sidebar-link:hover { background: var(--surface-2); }
.sidebar-link[aria-current="page"] { background: var(--route); color: #fff; }
.sidebar-link.is-stub { color: var(--mist); }
.sidebar-link.is-stub .stub-tag {
  margin-left: auto; font-size: 0.65rem; font-weight: 700; text-transform: uppercase;
  background: var(--surface-2); padding: 2px 6px; border-radius: var(--radius-pill);
}
.sidebar-foot { padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--line); font-size: 0.78rem; color: var(--mist); }

.topbar {
  height: var(--topbar-h); background: var(--surface); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4);
  padding: 0 var(--sp-6); position: sticky; top: 0; z-index: 40;
}
.topbar-title { font-family: var(--font-display); font-weight: 700; font-size: 1.05rem; }
.topbar-eyebrow { font-size: 0.8rem; color: var(--mist); font-weight: 600; font-style: italic; }
.topbar-user { display: flex; align-items: center; gap: var(--sp-3); }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--route-tint); color: var(--route-dark); display: flex; align-items: center; justify-content: center; font-weight: 700; font-family: var(--font-display); }
.menu-toggle { display: none; }

.main { margin-left: var(--sidebar-w); flex: 1; min-width: 0; padding: clamp(16px, 2.2vw, 40px); max-width: 1680px; }
.main-header { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--sp-4); margin-bottom: var(--sp-6); flex-wrap: wrap; }
.title-card {
  background: var(--surface); border-radius: var(--radius-lg); padding: var(--sp-5) var(--sp-6);
  box-shadow: var(--shadow-sm); border: 1px solid var(--line);
}
.title-card p:last-child { margin-bottom: 0; }

@media (max-width: 980px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.is-open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .main { margin-left: 0; padding: clamp(14px, 4vw, 24px); }
  .menu-toggle { display: inline-flex; }
  .topbar { padding: 0 var(--sp-4); }
}

.overlay-scrim {
  position: fixed; inset: 0; background: rgba(16,35,31,0.45); z-index: 55; opacity: 0;
  pointer-events: none; transition: opacity .15s ease;
}
.overlay-scrim.is-visible { opacity: 1; pointer-events: auto; }

/* ==========================================================================
   Tarjetas / KPIs
   ========================================================================== */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  padding: var(--sp-5); box-shadow: var(--shadow-sm);
}
.card-header { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); margin-bottom: var(--sp-4); }
.card-header h2, .card-header h3 { margin: 0; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: var(--sp-4); margin-bottom: var(--sp-6); }
.kpi-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: var(--sp-5); border-left: 4px solid var(--route); }
.kpi-card.cargo { border-left-color: var(--cargo); }
.kpi-card.caution { border-left-color: var(--caution); }
.kpi-card.alert { border-left-color: var(--alert); }
.kpi-label { font-size: 0.8rem; font-weight: 600; color: var(--mist); text-transform: uppercase; letter-spacing: .04em; margin-bottom: var(--sp-2); }
.kpi-value { font-family: var(--font-display); font-size: 2rem; font-weight: 700; }
.kpi-sub { font-size: 0.82rem; color: var(--mist); margin-top: var(--sp-1); }

/* ==========================================================================
   Chips / estados
   ========================================================================== */
.chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: 0.78rem; font-weight: 700;
  padding: 5px 12px; border-radius: var(--radius-pill); white-space: nowrap; line-height: 1.4;
}
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip-route   { background: var(--route-tint);  color: var(--route-dark); }
.chip-cargo   { background: var(--cargo-tint);  color: var(--cargo-dark); }
.chip-caution { background: var(--caution-tint); color: var(--caution); }
.chip-alert   { background: var(--alert-tint);  color: var(--alert-dark); }
.chip-neutral { background: var(--surface-2);   color: var(--mist); }

/* ==========================================================================
   Tabla
   ========================================================================== */
.table-wrap { overflow-x: auto; max-width: 100%; border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow-sm); scrollbar-color: #A4B9D8 var(--surface-2); }
table { width: 100%; border-collapse: collapse; min-width: 640px; }
th, td { text-align: left; padding: 18px 12px; font-size: 0.875rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
thead, thead tr { background: var(--route); }
th { font-size: 0.75rem; letter-spacing: .045em; color: #fff; background: var(--route); font-weight: 700; white-space: nowrap; padding-top: 17px; padding-bottom: 17px; }
td { line-height: 1.55; }
tbody tr:nth-child(even) { background: #F8FAFE; }
th:first-child { border-top-left-radius: var(--radius-md); }
th:last-child { border-top-right-radius: var(--radius-md); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
td.mono { font-family: var(--font-mono); font-size: 0.85rem; }
.row-actions { display: table-cell; text-align: right; }
.row-actions > form { display: inline-block; vertical-align: middle; margin: 4px; }
.table-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.table-actions > form { margin: 0; }
.table-primary { display: flex; align-items: center; gap: 12px; min-width: 150px; }
.table-primary strong { display: block; font-weight: 600; max-width: 230px; overflow-wrap: anywhere; }
.table-primary > a { flex-shrink: 0; }
.table-secondary { display: block; margin-top: 3px; color: var(--mist); font-size: .78rem; }
.table-action-menu { min-width: 150px; text-align: left; }
.table-action-menu[open] { width: min(300px, 70vw); }
.table-action-menu > summary { font-size: .82rem; padding: 9px 12px; }
.table-action-menu .field { margin: 12px 0; }
.table-action-menu form { margin-top: 12px; }
.table-action-menu input[type="file"] { width: 100%; }
.table-action-menu .btn { width: 100%; }
.table-wrap .fotos-recepcion { max-width: 180px; }
.table-wrap td .hint { display: block; }
.table-wrap .foto-mini { width: 52px; height: 52px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }
.table-wrap td > .chip { white-space: nowrap; }
.table-wrap td > details > form { min-width: 220px; }
.table-wrap td > details[open] { padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
details > summary { cursor: pointer; font-weight: 600; color: var(--route-dark); border-radius: 8px; padding: 8px 0; }
details > summary::marker { color: var(--route); }
details > summary:hover { color: var(--route); }
.form-section { border: 1px solid var(--line); border-radius: 14px; padding: 20px; background: var(--surface); }
.form-section-heading { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.form-section-heading .icon { color: var(--route); width: 24px; height: 24px; }
.form-section-heading h2, .form-section-heading h3 { margin: 0; }
.form-section > summary .icon { vertical-align: middle; margin-right: 8px; color: var(--route); }
.catalog-tags { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 16px; }
.catalog-tags li { border: 1px solid var(--line); border-radius: 999px; background: var(--surface-2); padding: 6px 12px; font-size: .82rem; color: var(--ink); }
.form-section .grid-2 { gap: 16px 24px; }
.form-section .grid-2 .field { margin-bottom: 0; }
.form-footer { display: flex; align-items: center; gap: 12px; justify-content: flex-end; border-top: 1px solid var(--line); padding-top: 16px; margin-top: 20px; }
@media (max-width: 640px) {
  th, td { padding: 14px 12px; }
  .table-actions { align-items: stretch; }
  .form-footer { flex-wrap: wrap; }
  .form-footer .btn { width: 100%; }
}

/* ==========================================================================
   Componente firma: Route Stepper (manifiesto de ruta)
   ========================================================================== */
.route-stepper { display: flex; flex-direction: column; gap: 0; }
.stop {
  display: grid; grid-template-columns: 32px 1fr; gap: var(--sp-4);
  position: relative;
}
.stop-track { position: relative; display: flex; flex-direction: column; align-items: center; }
.stop-node {
  width: 32px; height: 32px; border-radius: 50%; border: 2.5px solid var(--line);
  background: var(--surface); display: flex; align-items: center; justify-content: center;
  color: var(--mist); font-family: var(--font-mono); font-size: 0.75rem; font-weight: 700; z-index: 2;
  flex-shrink: 0;
}
.stop-line { flex: 1; width: 2px; min-height: 32px; background-image: linear-gradient(var(--line) 60%, transparent 0%); background-size: 2px 8px; background-repeat: repeat-y; }
.stop.is-done .stop-node { background: var(--route); border-color: var(--route); color: #fff; }
.stop.is-done .stop-line { background-image: linear-gradient(var(--route) 60%, transparent 0%); background-size: 2px 8px; }
.stop.is-current .stop-node { background: var(--cargo); border-color: var(--cargo); color: #fff; box-shadow: 0 0 0 5px var(--cargo-tint); }
.stop.is-failed .stop-node { background: var(--alert); border-color: var(--alert); color: #fff; }
.stop-body { padding-bottom: var(--sp-6); }
.stop-body h4 { margin-bottom: 2px; font-size: 0.98rem; }
.stop-meta { font-size: 0.82rem; color: var(--mist); margin-bottom: var(--sp-2); }
.stop-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; margin-top: var(--sp-3); }
.stop:last-child .stop-body { padding-bottom: 0; }
.stop:last-child .stop-line { display: none; }

.truck-flag {
  display: inline-flex; align-items: center; gap: 6px; background: var(--cargo); color: #fff;
  font-family: var(--font-mono); font-size: 0.72rem; font-weight: 600; padding: 3px 10px 3px 6px;
  border-radius: var(--radius-pill); position: relative; top: -1px;
}
.truck-flag .icon { width: 14px; height: 14px; }

/* ==========================================================================
   Modal
   ========================================================================== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(16,35,31,0.5); display: none;
  align-items: center; justify-content: center; padding: var(--sp-4); z-index: 100;
}
.modal-overlay.is-open { display: flex; }
.modal {
  background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto; padding: var(--sp-6);
}
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-4); margin-bottom: var(--sp-4); }
.modal-close { background: transparent; border: none; color: var(--mist); cursor: pointer; border-radius: 50%; }
.modal-footer { display: flex; justify-content: flex-end; gap: var(--sp-3); margin-top: var(--sp-6); }

/* ==========================================================================
   Toasts
   ========================================================================== */
.toast-region {
  position: fixed; bottom: var(--sp-5); right: var(--sp-5); z-index: 150;
  display: flex; flex-direction: column; gap: var(--sp-2); max-width: min(360px, calc(100vw - 32px));
}
.toast {
  background: var(--ink); color: #fff; padding: var(--sp-3) var(--sp-4); border-radius: var(--radius-md);
  box-shadow: var(--shadow-md); display: flex; align-items: flex-start; gap: var(--sp-2);
  font-size: 0.88rem; animation: toast-in .18s ease;
}
.toast .icon { color: var(--route); flex-shrink: 0; margin-top: 1px; }
.toast.toast-alert .icon { color: #FF8A9B; }
.toast.toast-caution .icon { color: var(--caution); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ==========================================================================
   Tooltip
   ========================================================================== */
[data-tooltip] { position: relative; }
[data-tooltip]::after {
  content: attr(data-tooltip); position: absolute; bottom: calc(100% + 8px); left: 50%;
  transform: translateX(-50%) scale(0.96); background: var(--ink); color: #fff; font-size: 0.75rem;
  padding: 6px 10px; border-radius: var(--radius-sm); white-space: nowrap; opacity: 0; pointer-events: none;
  transition: opacity .12s ease, transform .12s ease; z-index: 50; font-weight: 500;
}
[data-tooltip]:hover::after, [data-tooltip]:focus-visible::after { opacity: 1; transform: translateX(-50%) scale(1); }

/* ==========================================================================
   Skeleton / loaders
   ========================================================================== */
.skeleton {
  background: linear-gradient(100deg, var(--surface-2) 30%, #E5EDFB 50%, var(--surface-2) 70%);
  background-size: 240% 100%; animation: shimmer 1.3s ease-in-out infinite; border-radius: var(--radius-sm);
  color: transparent !important;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -40% 0; } }
.spinner {
  width: 18px; height: 18px; border: 2.5px solid rgba(255,255,255,0.35); border-top-color: #fff;
  border-radius: 50%; animation: spin .7s linear infinite; display: inline-block;
}
.spinner.on-light { border-color: var(--route-tint); border-top-color: var(--route); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ==========================================================================
   Tabs
   ========================================================================== */
.tabs { display: flex; gap: var(--sp-1); background: var(--surface-2); padding: 4px; border-radius: var(--radius-md); }
.tab {
  flex: 1; text-align: center; padding: var(--sp-3) var(--sp-3); border-radius: var(--radius-sm);
  font-weight: 600; font-size: 0.86rem; color: var(--mist); background: transparent; border: none;
  cursor: pointer; min-height: 44px;
}
.tab[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }

/* Selector de tipo de cuenta: botones apilados, igual al patrón "Persona Física / Jurídica" */
.toggle-stack { display: flex; flex-direction: column; gap: var(--sp-3); }
.toggle-stack [hidden] { display: none; }
.toggle-stack[hidden] { display: none; }
.toggle-stack input[type="radio"] { position: absolute; opacity: 0; width: 1px; height: 1px; }
.toggle-option {
  display: flex; align-items: center; justify-content: center; text-align: center; min-height: 48px;
  padding: var(--sp-3) var(--sp-4); border-radius: var(--radius-md); border: 1.5px solid var(--line);
  background: var(--surface); color: var(--ink); font-weight: 600; font-size: 0.94rem; cursor: pointer;
}
.toggle-stack input:checked + .toggle-option { background: var(--cargo); border-color: var(--cargo); color: #fff; }
.toggle-stack input:focus-visible + .toggle-option { outline: 3px solid var(--route); outline-offset: 2px; }
.role-hint { display: none; font-size: 0.82rem; color: var(--mist); background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-md); padding: var(--sp-3) var(--sp-4); margin-bottom: var(--sp-5); }
.auth-form-card:has(#rol-donante:checked) .role-hint.hint-donante { display: block; }
.auth-form-card:has(#rol-beneficiaria:checked) .role-hint.hint-beneficiaria { display: block; }
.auth-form-card:has(#rol-admin:checked) .role-hint.hint-admin { display: block; }

/* ==========================================================================
   Página pública de acceso (login)
   ========================================================================== */
.auth-shell { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-brand {
  background: var(--paper); color: var(--ink); padding: var(--sp-9) var(--sp-8);
  display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden;
}
.auth-brand-top .brand-mark { display: flex; align-items: center; gap: var(--sp-2); font-family: var(--font-display); font-size: 1.2rem; font-weight: 700; color: var(--ink); margin-bottom: var(--sp-8); }
.brand-mark .dot { width: 11px; height: 11px; border-radius: 50%; background: var(--cargo); }
.auth-brand h1 { color: var(--ink); font-size: 2rem; max-width: 15ch; }
.auth-brand .lede { color: var(--mist); max-width: 40ch; font-size: 1.02rem; }
.auth-journey { margin-top: var(--sp-8); }
.auth-foot { font-size: 0.8rem; color: var(--mist); }
.auth-foot a { color: var(--route-dark); }

.auth-panel { display: flex; align-items: center; justify-content: center; padding: var(--sp-6); background: var(--surface); }
.auth-form-card { width: 100%; max-width: 400px; }
.eyebrow, .auth-form-card .eyebrow { font-size: 0.85rem; font-weight: 700; font-style: italic; color: var(--route-dark); margin: 0 0 var(--sp-2); }
.auth-links { display: flex; align-items: center; justify-content: space-between; font-size: 0.85rem; margin-top: var(--sp-2); flex-wrap: wrap; gap: var(--sp-2); }
.divider-or { display: flex; align-items: center; gap: var(--sp-3); color: var(--mist); font-size: 0.8rem; margin: var(--sp-5) 0; }
.divider-or::before, .divider-or::after { content: ""; flex: 1; height: 1px; background: var(--line); }

@media (max-width: 860px) {
  .auth-shell { grid-template-columns: 1fr; }
  .auth-brand { padding: var(--sp-6); }
  .auth-brand h1 { font-size: 1.6rem; }
}


/* ==========================================================================
   Mapa
   ========================================================================== */
.map-layout { display: grid; grid-template-columns: 320px 1fr; gap: var(--sp-5); align-items: start; }
#map { position: relative; z-index: 0; isolation: isolate; height: 560px; border-radius: var(--radius-lg); border: 1px solid var(--line); box-shadow: var(--shadow-sm); background: var(--surface-2); }
.map-legend-item { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-2) 0; font-size: 0.88rem; }
.legend-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.leaflet-popup-content-wrapper { border-radius: var(--radius-md); font-family: var(--font-body); }
.map-pin { width: 30px; height: 30px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: #fff; border: 3px solid #fff; box-shadow: var(--shadow-md); }
.map-pin svg { width: 15px; height: 15px; }
.map-pin-deposito { background: var(--ink); }
.map-pin-camion { background: var(--cargo); }
.map-pin-entregada { background: var(--route); }
.map-popup h4 { margin: 0 0 4px; font-family: var(--font-display); }
.map-popup p { margin: 0 0 4px; font-size: 0.85rem; }
.map-popup .chip { margin-top: 4px; }
@media (max-width: 900px) { .map-layout { grid-template-columns: 1fr; } #map { height: 380px; } }

/* ==========================================================================
   Uploader de fotos
   ========================================================================== */
.uploader {
  border: 2px dashed var(--line); border-radius: var(--radius-lg); padding: var(--sp-8);
  text-align: center; background: var(--surface-2); cursor: pointer;
}
.uploader:hover, .uploader.is-drag { border-color: var(--route); background: var(--route-tint); }
.uploader .icon { width: 32px; height: 32px; margin: 0 auto var(--sp-3); color: var(--route-dark); }
.upload-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: var(--sp-3); margin-top: var(--sp-4); }
.upload-thumb { position: relative; aspect-ratio: 1; border-radius: var(--radius-md); overflow: hidden; border: 1px solid var(--line); }
.upload-thumb img { width: 100%; height: 100%; object-fit: cover; }
.upload-thumb button { position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; min-height: unset; border-radius: 50%; background: rgba(30,39,73,0.72); color: #fff; border: none; display: flex; align-items: center; justify-content: center; padding: 0; }

/* ==========================================================================
   Vista chofer (mobile-first)
   ========================================================================== */
.driver-shell { max-width: 460px; margin: 0 auto; min-height: 100vh; background: var(--paper); display: flex; flex-direction: column; }
.driver-topbar { background: var(--route); color: #fff; padding: var(--sp-5) var(--sp-5) var(--sp-6); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.driver-topbar .eyebrow { color: #D7E6FE; font-size: 0.8rem; font-weight: 700; font-style: italic; }
.driver-main { padding: var(--sp-5); flex: 1; }
.driver-stat-row { display: flex; gap: var(--sp-5); margin-top: var(--sp-4); }
.driver-stat .num { font-family: var(--font-display); font-size: 1.5rem; font-weight: 700; }
.driver-stat .lbl { font-size: 0.75rem; color: #CBDDFC; }

/* ==========================================================================
   Empty state
   ========================================================================== */
.empty-state { text-align: center; padding: var(--sp-9) var(--sp-5); color: var(--mist); }
.empty-state .icon { width: 40px; height: 40px; margin: 0 auto var(--sp-3); color: var(--mist-2); }
.empty-state h3 { color: var(--ink); }

/* ==========================================================================
   Placeholder (secciones de otro equipo)
   ========================================================================== */
.stub-banner {
  display: flex; align-items: center; gap: var(--sp-3); background: var(--caution-tint); color: var(--caution);
  border: 1px solid #EBD9AE; padding: var(--sp-4) var(--sp-5); border-radius: var(--radius-md); margin-bottom: var(--sp-6);
  font-size: 0.9rem; font-weight: 600;
}

/* Grillas de ayuda */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-4); }
@media (max-width: 640px) { .grid-2 { grid-template-columns: 1fr; } }
.stack { display: flex; flex-direction: column; gap: var(--sp-4); }
.text-mist { color: var(--mist); }
.mt-6 { margin-top: var(--sp-6); }

/* ==========================================================================
   Barra de progreso (necesidades materiales, misiones)
   ========================================================================== */
.progress-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--sp-2); font-size: 0.85rem; font-weight: 600; }
.progress-row .value { color: var(--mist); font-weight: 500; }
.progress-track { height: 10px; border-radius: var(--radius-pill); background: var(--surface-2); overflow: hidden; }
.progress-fill { height: 100%; border-radius: var(--radius-pill); background: var(--route); transition: width .3s ease; }
.progress-fill.cargo { background: var(--cargo); }
.progress-fill.alert { background: var(--alert); }

/* ==========================================================================
   Categoría de donante (Colaborador / Sostenedor / Transformador)
   ========================================================================== */
.category-badge {
  display: inline-flex; align-items: center; gap: var(--sp-2); font-family: var(--font-display);
  font-weight: 700; font-size: 0.85rem; padding: 7px 16px; border-radius: var(--radius-pill);
  background: var(--cargo-tint); color: var(--cargo-dark); border: 1.5px solid #D8D2FA;
}
.category-badge .icon { width: 16px; height: 16px; }
.category-track { display: flex; align-items: center; gap: var(--sp-2); margin: var(--sp-4) 0; }
.category-step { flex: 1; text-align: center; padding: var(--sp-3) var(--sp-2); border-radius: var(--radius-md); font-size: 0.8rem; font-weight: 700; background: var(--surface-2); color: var(--mist); border: 1.5px solid var(--line); }
.category-step.is-current { background: var(--cargo); color: #fff; border-color: var(--cargo); }
.category-step.is-done { background: var(--route-tint); color: var(--route-dark); border-color: var(--route-tint); }

/* ==========================================================================
   Misiones e insignias
   ========================================================================== */
.mission-card { display: flex; gap: var(--sp-4); align-items: flex-start; padding: var(--sp-4); border: 1px solid var(--line); border-radius: var(--radius-lg); background: var(--surface); }
.mission-card.is-locked { opacity: 0.55; }
.mission-icon {
  width: 44px; height: 44px; border-radius: var(--radius-md); background: var(--route-tint); color: var(--route-dark);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.mission-card.is-locked .mission-icon { background: var(--surface-2); color: var(--mist-2); }
.mission-card.is-done .mission-icon { background: var(--route); color: #fff; }
.mission-body { flex: 1; min-width: 0; }
.mission-body h4 { margin-bottom: 2px; }

.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: var(--sp-4); }
.badge-item { display: flex; flex-direction: column; align-items: center; gap: var(--sp-2); text-align: center; }
.badge-icon {
  width: 60px; height: 60px; border-radius: 50%; background: var(--cargo-tint); color: var(--cargo-dark);
  display: flex; align-items: center; justify-content: center; border: 2px solid #E3DEFC;
}
.badge-icon.is-locked { background: var(--surface-2); color: var(--mist-2); border-color: var(--line); }
.badge-item .label { font-size: 0.75rem; font-weight: 600; color: var(--mist); }

/* ==========================================================================
   Gráfico de barras simple (evolución de donaciones)
   ========================================================================== */
.bar-chart { display: flex; align-items: flex-end; gap: var(--sp-3); height: 160px; padding-top: var(--sp-4); }
.bar-chart .bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: var(--sp-2); }
.bar-chart .bar { width: 100%; max-width: 36px; border-radius: 6px 6px 0 0; background: var(--route); }
.bar-chart .bar.is-peak { background: var(--cargo); }
.bar-chart .bar-label { font-size: 0.72rem; color: var(--mist); font-weight: 600; }

/* ==========================================================================
   Notificaciones
   ========================================================================== */
.notif-item { display: flex; gap: var(--sp-3); padding: var(--sp-4); border-bottom: 1px solid var(--line); }
.notif-item:last-child { border-bottom: none; }
.notif-item.is-unread { background: var(--route-tint); border-radius: var(--radius-md); }
.notif-icon { width: 38px; height: 38px; border-radius: 50%; display: flex; align-items: center; justify-content: center; flex-shrink: 0; background: var(--surface-2); color: var(--mist); }
.notif-icon.route { background: var(--route-tint); color: var(--route-dark); }
.notif-icon.cargo { background: var(--cargo-tint); color: var(--cargo-dark); }
.notif-icon.alert { background: var(--alert-tint); color: var(--alert-dark); }
.notif-body { flex: 1; min-width: 0; }
.notif-time { font-size: 0.75rem; color: var(--mist-2); white-space: nowrap; }

/* ==========================================================================
   Necesidad material (entidad beneficiaria)
   ========================================================================== */
.necesidad-card { border: 1px solid var(--line); border-radius: var(--radius-lg); padding: var(--sp-5); background: var(--surface); }
.necesidad-card .card-header { margin-bottom: var(--sp-3); }

/* Bell / notificación con contador */
.bell-wrap { position: relative; }
.bell-dot { position: absolute; top: 6px; right: 6px; width: 9px; height: 9px; border-radius: 50%; background: var(--alert); border: 2px solid var(--surface); }

/* ==========================================================================
   Selección de entidad beneficiaria (algoritmos de asignación)
   ========================================================================== */
.candidate-row {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4); border: 1.5px solid var(--line); border-radius: var(--radius-md);
  margin-bottom: var(--sp-2); background: var(--surface);
}
.candidate-row.is-match { border-color: var(--route); background: var(--route-tint); }
.candidate-row:has(input:checked) { border-color: var(--route); background: var(--route-tint); }
.candidate-row:focus-within { outline: 2px solid var(--route); outline-offset: 2px; }
.candidate-row:has(input) { cursor: pointer; }
.candidate-row input[type="radio"] { width: 20px; height: 20px; flex-shrink: 0; accent-color: var(--route); }
.candidate-rank { font-family: var(--font-mono); font-weight: 700; color: var(--mist); width: 28px; flex-shrink: 0; }
.candidate-name { flex: 1; font-weight: 600; }
.match-badge { font-size: 0.72rem; font-weight: 700; color: var(--route-dark); background: var(--surface); padding: 2px 9px; border-radius: var(--radius-pill); border: 1px solid var(--route); }

/* ==========================================================================
   Línea de bien dentro de una donación (registrar donación)
   ========================================================================== */
.line-item { border: 1.5px solid var(--line); border-radius: var(--radius-lg); padding: var(--sp-4); position: relative; background: var(--surface-2); }
.line-item .remove-line { position: absolute; top: var(--sp-3); right: var(--sp-3); }

/* Zona de carga de archivos (CSV) reutiliza .uploader; icono de archivo */
.file-chip {
  display: inline-flex; align-items: center; gap: var(--sp-2); background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius-md); padding: var(--sp-2) var(--sp-4); font-size: 0.88rem; font-weight: 600;
}

/* ==========================================================================
   Landing pública
   ========================================================================== */
.public-nav {
  position: sticky; top: 0; z-index: 40; background: var(--surface); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between; padding: var(--sp-4) clamp(20px, 5vw, 64px);
}
.public-nav .brand-mark { font-family: var(--font-display); font-weight: 700; font-size: 1.15rem; color: var(--ink); display: flex; align-items: center; gap: var(--sp-2); text-decoration: none; }
.public-nav .brand-mark .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--cargo); }
.public-nav-links { display: flex; align-items: center; gap: var(--sp-6); }
.public-nav-links a:not(.btn) { color: var(--ink); font-weight: 600; font-size: 0.94rem; text-decoration: none; }
.public-nav-links a:not(.btn):hover { color: var(--route-dark); }
@media (max-width: 860px) {
  .public-nav-links { display: none; }
}

.hero {
  background: var(--paper); padding: var(--sp-9) clamp(20px, 5vw, 64px); display: grid; grid-template-columns: 1.1fr 1fr;
  gap: var(--sp-8); align-items: center;
}
.hero h1 { font-size: clamp(2rem, 1.5rem + 2vw, 3rem); margin-bottom: var(--sp-4); }
.hero .lede { font-size: 1.1rem; color: var(--mist); max-width: 46ch; margin-bottom: var(--sp-6); }
.hero-ctas { display: flex; gap: var(--sp-3); flex-wrap: wrap; }
@media (max-width: 900px) { .hero { grid-template-columns: 1fr; } }

.section { padding: var(--sp-9) clamp(20px, 5vw, 64px); max-width: 1440px; margin: 0 auto; }
.section-heading { text-align: center; max-width: 640px; margin: 0 auto var(--sp-7); }
.section-heading .eyebrow { display: block; text-align: center; }

.highlight-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: var(--sp-5); }
.highlight-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-sm); }
.highlight-photo {
  aspect-ratio: 4 / 3; width: 100%; object-fit: cover; display: block; background: var(--route-tint);
}
.highlight-body { padding: var(--sp-5); }
.highlight-body h3 { margin-bottom: 4px; font-size: 1.05rem; }

.cta-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: var(--sp-5); }
.cta-tile {
  display: flex; flex-direction: column; gap: var(--sp-3); padding: var(--sp-6); border-radius: var(--radius-lg);
  border: 1.5px solid var(--line); background: var(--surface); text-decoration: none; color: var(--ink);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.cta-tile:hover { border-color: var(--route); box-shadow: var(--shadow-md); }
.cta-tile .cta-icon { width: 44px; height: 44px; border-radius: var(--radius-md); background: var(--route-tint); color: var(--route-dark); display: flex; align-items: center; justify-content: center; }
.cta-tile h3 { margin: 0; font-size: 1.05rem; }
.cta-tile p { margin: 0; }

.impact-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: var(--sp-6); text-align: center; }
.impact-stats .num { font-family: var(--font-display); font-weight: 800; font-size: 2.4rem; color: var(--route-dark); }
.impact-stats .lbl { color: var(--mist); font-weight: 600; font-size: 0.9rem; }

.public-footer { background: var(--ink); color: #C9D3EE; padding: var(--sp-8) clamp(20px, 5vw, 64px) var(--sp-6); }
.public-footer .brand-mark { color: #fff; font-family: var(--font-display); font-weight: 700; font-size: 1.1rem; display: flex; align-items: center; gap: var(--sp-2); margin-bottom: var(--sp-3); }
.public-footer a { color: #C9D3EE; text-decoration: none; }
.public-footer a:hover { color: #fff; }
.footer-grid { display: flex; flex-wrap: wrap; gap: var(--sp-8); justify-content: space-between; max-width: 1200px; margin: 0 auto; }
.footer-links { display: flex; flex-direction: column; gap: var(--sp-2); }
.footer-bottom { text-align: center; font-size: 0.82rem; color: #8C99C2; margin-top: var(--sp-7); padding-top: var(--sp-5); border-top: 1px solid rgba(255,255,255,0.1); max-width: 1200px; margin-left: auto; margin-right: auto; }

/* Popup del mapa público con foto */
.public-map-photo {
  width: 100%; aspect-ratio: 4/3; border-radius: var(--radius-sm); margin-bottom: var(--sp-2);
  object-fit: cover; display: block; background: var(--route-tint);
}

/* ==========================================================================
   Utilidades de layout y espaciado (reemplazan estilos en línea)
   ========================================================================== */
.u-flex { display: flex; }
.u-flex-col { display: flex; flex-direction: column; }
.u-inline-flex { display: inline-flex; }
.u-items-center { align-items: center; }
.u-items-start { align-items: flex-start; }
.u-justify-between { justify-content: space-between; }
.u-justify-center { justify-content: center; }
.u-justify-end { justify-content: flex-end; }
.u-flex-wrap { flex-wrap: wrap; }
.u-flex-1 { flex: 1; }
.u-flex-shrink-0 { flex-shrink: 0; }
.u-min-w-0 { min-width: 0; }
.u-block { display: block; }
.u-hidden { display: none; }

.u-gap-1 { gap: var(--sp-1); }
.u-gap-2 { gap: var(--sp-2); }
.u-gap-3 { gap: var(--sp-3); }
.u-gap-4 { gap: var(--sp-4); }
.u-gap-5 { gap: var(--sp-5); }
.u-gap-6 { gap: var(--sp-6); }
.u-gap-0 { gap: 0; }

.u-m-0 { margin: 0; }
.u-mt-1 { margin-top: var(--sp-1); } .u-mt-2 { margin-top: var(--sp-2); } .u-mt-3 { margin-top: var(--sp-3); }
.u-mt-4 { margin-top: var(--sp-4); } .u-mt-5 { margin-top: var(--sp-5); } .u-mt-6 { margin-top: var(--sp-6); }
.u-mt-7 { margin-top: var(--sp-7); } .u-mt-neg-sm { margin-top: -8px; }
.u-mb-0 { margin-bottom: 0; } .u-mb-1 { margin-bottom: var(--sp-1); } .u-mb-2 { margin-bottom: var(--sp-2); }
.u-mb-3 { margin-bottom: var(--sp-3); } .u-mb-4 { margin-bottom: var(--sp-4); } .u-mb-5 { margin-bottom: var(--sp-5); }
.u-mb-6 { margin-bottom: var(--sp-6); } .u-mb-7 { margin-bottom: var(--sp-7); }
.u-ml-1 { margin-left: var(--sp-1); }

.u-p-2 { padding: var(--sp-2); } .u-p-4 { padding: var(--sp-4); }
.u-pt-7 { padding-top: var(--sp-7); } .u-pb-7 { padding-bottom: var(--sp-7); }

.u-w-full { width: 100%; }
.u-h-full { height: 100%; }
.u-max-w-xs { max-width: 220px; }
.u-max-w-sm { max-width: 360px; }
.u-max-w-smd { max-width: 420px; }
.u-max-w-md { max-width: 460px; }
.u-max-w-lg { max-width: 640px; }
.u-max-w-xl { max-width: 720px; }
.u-max-w-xxl { max-width: 760px; }
.u-max-w-2xl { max-width: 800px; }
.u-max-w-3xl { max-width: 820px; }
.u-max-w-prose { max-width: 32ch; }
.u-max-w-section { max-width: 1200px; }
.u-max-w-wide { max-width: 1400px; }
.u-max-w-none { max-width: none; }
.u-min-w-sm { min-width: 200px; }
.u-min-w-md { min-width: 220px; }
.u-mx-auto { margin-left: auto; margin-right: auto; }

.u-text-center { text-align: center; }
.u-font-normal { font-weight: 400; }
.u-font-semibold { font-weight: 600; }
.u-font-bold { font-weight: 700; }
.u-text-sm { font-size: 0.85rem; }
.u-text-base { font-size: 0.9rem; }
.u-text-lg { font-size: 1rem; }
.u-no-underline { text-decoration: none; }
.u-border-0 { border: none; }
.u-icon-sm { width: 16px; height: 16px; }
.u-rounded-img { border-radius: var(--radius-md); overflow: hidden; border: 1px solid var(--line); display: block; }
.u-list-disc { list-style: disc; padding-left: 20px; }

/* Colores de texto sobre fondos oscuros (héroes, footers) */
.u-text-onDark { color: #fff; }
.u-text-onDark-muted { color: #CBDDFC; }

/* Contenedores estándar para páginas sin sidebar (login, registro, confirmación, legal) */
.standalone-topbar { position: static; }
.standalone-main { max-width: var(--standalone-max, 720px); margin: 0 auto; padding: var(--sp-6) var(--sp-4) var(--sp-9); }
.standalone-main.is-wide { --standalone-max: 820px; }
.standalone-main.is-narrow { --standalone-max: 640px; }

/* Columna de contenido junto al sidebar (reemplaza flex:1;min-width:0 inline) */
.shell-content { flex: 1; min-width: 0; }

/* Fila flex genérica con separación estándar, el patrón más repetido */
.row { display: flex; align-items: center; gap: var(--sp-3); }
.row-wrap { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; }

/* Utilidades adicionales de ajuste fino */
.u-inline-block { display: inline-block; }
.u-static { position: static; }
.u-text-ink { color: var(--ink); }
.u-mb-2px { margin-bottom: 2px; }
.u-mb-4px { margin-bottom: 4px; }
.u-ml-6px { margin-left: 6px; }
.u-mt-hint { margin: 2px 0 0; }
.u-max-w-2xs { max-width: 200px; }
.u-icon-badge-onDark { color: #fff; background: rgba(255,255,255,0.1); }
.u-chip-onDark { background: rgba(255,255,255,0.12); color: #fff; }

/* Utilidades puntuales adicionales (colores de fondo, paddings compuestos) */
.u-bg-cargo { background: var(--cargo); }
.u-bg-route { background: var(--route); }
.u-bg-ink { background: var(--ink); }
.u-bg-route-tint { background: var(--route-tint); }
.u-bg-surface-2 { background: var(--surface-2); }
.u-bg-minimap { background: #E9F0FB; }
.u-p-hero { padding: var(--sp-9) var(--sp-4); }
.u-p-standalone { padding: var(--sp-6) var(--sp-4) var(--sp-9); }
.u-banner-success { background: var(--route-tint); color: var(--route-dark); border-color: #BFD3F5; }

/* ==========================================================================
   Menú de usuario (desplegable desde el avatar del topbar)
   ========================================================================== */
.user-menu { position: relative; }
.avatar-trigger {
  width: 40px; height: 40px; border-radius: 50%; border: none; padding: 0; cursor: pointer;
  background: var(--route-tint); color: var(--route-dark); font-weight: 700; font-family: var(--font-display);
  display: flex; align-items: center; justify-content: center; overflow: hidden; position: relative; font-size: 0.95rem;
}
.avatar-trigger img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar-trigger[aria-expanded="true"] { box-shadow: 0 0 0 3px var(--route-tint), 0 0 0 5px var(--route); }

.user-menu-panel {
  position: absolute; top: calc(100% + 10px); right: 0; width: 288px; max-width: calc(100vw - 32px);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); z-index: 120; padding: var(--sp-4);
}
.user-menu-panel[hidden] { display: none; }

.user-menu-header { display: flex; align-items: center; gap: var(--sp-3); padding-bottom: var(--sp-4); margin-bottom: var(--sp-3); border-bottom: 1px solid var(--line); }
.user-menu-photo { width: 48px; height: 48px; border-radius: 50%; object-fit: cover; background: var(--route-tint); flex-shrink: 0; }
.user-menu-name { margin: 0; font-weight: 700; font-size: 0.95rem; }
.user-menu-role { margin: 0; font-size: 0.8rem; color: var(--mist); }

.user-menu-section { padding: var(--sp-3) 0; border-bottom: 1px solid var(--line); }
.user-menu-section-title { margin: 0 0 var(--sp-2); font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--mist-2); }
.user-menu-field { display: flex; justify-content: space-between; gap: var(--sp-3); font-size: 0.85rem; padding: 3px 0; }
.user-menu-field .label { color: var(--mist); }
.user-menu-field .value { font-weight: 600; text-align: right; }

.user-menu-list { list-style: none; margin: 0; padding: var(--sp-2) 0 0; }
.user-menu-item {
  display: flex; align-items: center; gap: var(--sp-3); width: 100%; text-align: left; background: none; border: none;
  padding: var(--sp-2) var(--sp-2); border-radius: var(--radius-md); font-size: 0.88rem; font-weight: 600; color: var(--ink);
  cursor: pointer; min-height: 44px; font-family: inherit;
}
.user-menu-item:hover { background: var(--surface-2); }
.user-menu-item.is-danger { color: var(--alert-dark); }
.user-menu-item .icon { color: var(--mist); flex-shrink: 0; }
.user-menu-item.is-danger .icon { color: var(--alert-dark); }
.role-switcher { margin: 4px 0; }
.role-option { border: 1px solid var(--line); border-radius: 10px; }
.role-option.is-active { background: #E8F0FF; border-color: var(--route); color: var(--route-dark); opacity: 1; cursor: default; }
.role-active-label { margin-left: auto; font-size: .72rem; font-weight: 700; }
/* Cerrar sesión es un <form method="post">: el botón se ve como el link/ítem de menú que reemplaza. */
.logout-form { margin: 0; }
.link-button { background: none; border: 0; padding: 0; min-height: 48px; font: inherit; color: inherit; text-decoration: underline; cursor: pointer; }

/* Foto real dentro de un popup de mapa */
.public-map-photo {
  width: 100%; aspect-ratio: 4/3; border-radius: var(--radius-sm); margin-bottom: var(--sp-2);
  object-fit: cover; display: block; background: var(--route-tint);
}

.foto-mini { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; vertical-align: middle; margin-right: 8px; }
.fotos-recepcion { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.fotos-recepcion img { width: 120px; height: 90px; object-fit: cover; border-radius: 8px; }
.user-menu-photo img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.misiones-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); gap: var(--sp-5); }
.mision-card { min-width: 0; overflow-wrap: anywhere; }
.mision-imagen { height: 160px; display: flex; align-items: center; justify-content: center; background: var(--route-tint); border-radius: var(--radius-sm); margin-bottom: var(--sp-4); overflow: hidden; }
.mision-imagen img { width: 100%; height: 100%; object-fit: contain; }
.mision-imagen .icon { width: 64px; height: 64px; color: var(--route); }

input[type="file"] {
  width: 100%; min-width: 0; max-width: 100%; padding: var(--sp-3); border: 1px dashed #A9BFE0;
  border-radius: var(--radius-sm); background: var(--surface-2); color: var(--mist);
  font: inherit; font-size: 0.875rem;
}
input[type="file"]::file-selector-button {
  margin-right: var(--sp-3); padding: 10px 16px; border: 1px solid var(--route);
  border-radius: 8px; background: var(--route-tint); color: var(--route-dark);
  font: inherit; font-weight: 600; cursor: pointer; transition: background 150ms, color 150ms;
}
input[type="file"]::file-selector-button:hover { background: var(--route); color: white; }
input[type="file"]:focus-visible { outline: 3px solid var(--route); outline-offset: 3px; }
.donante-search-bar { display: flex; align-items: stretch; gap: var(--sp-3); }
.donante-search-input { display: flex; flex: 1; min-width: 0; align-items: center; gap: var(--sp-3); padding-left: var(--sp-4); background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); }
.donante-search-input:focus-within { border-color: var(--route); box-shadow: 0 0 0 3px var(--route-tint); }
.donante-search-input > .icon { color: var(--route); flex-shrink: 0; }
.donante-search-input input { min-width: 0; width: 100%; margin: 0; border: none; box-shadow: none; background: transparent; }
.donante-search-input input:focus { box-shadow: none; }
.donante-results { display: grid; gap: var(--sp-2); }
.donante-result { width: 100%; display: flex; justify-content: space-between; align-items: center; gap: var(--sp-4); padding: var(--sp-4); border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); color: var(--ink); font: inherit; text-align: left; cursor: pointer; }
.donante-result:hover, .donante-result:focus-visible { border-color: var(--route); background: var(--surface-2); outline: 2px solid var(--route-tint); }
.donante-result span { color: var(--route); font-size: 0.875rem; font-weight: 600; white-space: nowrap; }
.donante-selected { display: flex; justify-content: space-between; align-items: center; gap: var(--sp-4); padding: var(--sp-4); border: 1px solid var(--route); border-radius: var(--radius-sm); background: var(--route-tint); }
.donante-selected strong { display: block; overflow-wrap: anywhere; }
.donante-selected[hidden] { display: none; }
@media (max-width: 600px) {
  .donante-search-bar { flex-direction: column; }
  .donante-result { align-items: flex-start; flex-direction: column; gap: var(--sp-2); }
  .donante-selected { align-items: flex-start; }
}

/* Resultado de operaciones: visible también sin JavaScript, sin cierre automático. */
.aviso {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  padding: 1rem 1.25rem;
  border: 1px solid;
  border-left-width: 5px;
  border-radius: 12px;
  overflow-wrap: anywhere;
  scroll-margin-top: 6rem;
}
.aviso-exito { background: #edf9f1; border-color: #21824a; color: #14532d; }
.aviso-error { background: #fff1f2; border-color: #be123c; color: #881337; }
.aviso:focus-visible { outline: 3px solid currentColor; outline-offset: 3px; }
.aviso-icono { font-size: 1.35rem; font-weight: 800; line-height: 1.3; flex-shrink: 0; }
.aviso-titulo { margin: 0 0 0.35rem; font-weight: 700; }
.aviso-detalle { margin: 0; }
.aviso-ayuda { margin: 0.6rem 0 0; font-size: 0.9rem; }
