:root {
  --bg: #f2f3f1;
  --surface: #fff;
  --surface-2: #f7f8f6;
  --border: #e3e5e0;
  --border-strong: #d2d5ce;
  --ink: #15171a;
  --ink-2: #3a3f45;
  --muted: #686e75;
  --subtle: #9aa0a6;
  --sidebar: #131517;
  --sidebar-2: #1b1e21;
  --sidebar-border: #2a2e32;
  --sidebar-text: #a1a7ad;
  --sidebar-active-bg: #ecedea;
  --sidebar-active-ink: #131517;
  --accent: #0f766e;
  --accent-hover: #115e59;
  --accent-soft: #e3f2ef;
  --ring: rgba(15, 118, 110, 0.22);
  --ok: #047857;
  --ok-bg: #ecfdf5;
  --ok-bd: #a7f3d0;
  --warn: #b45309;
  --warn-bg: #fffbeb;
  --warn-bd: #fde68a;
  --danger: #be123c;
  --danger-bg: #fff1f2;
  --danger-bd: #fecdd3;
  --info: #0369a1;
  --info-bg: #f0f9ff;
  --info-bd: #bae6fd;
  --neutral: #475569;
  --neutral-bg: #f1f5f9;
  --neutral-bd: #e2e8f0;
  --radius-sm: 8px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-xl: 16px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-md: 0 4px 16px -4px rgba(16, 24, 40, 0.08);
  --shadow-lg: 0 24px 48px -12px rgba(16, 24, 40, 0.25);
  --font: 'Geist', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: 'Geist Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --sidebar-w: 248px;
  --c-text-muted: var(--muted);
  --c-border: var(--border);
  --c-ok: var(--ok);
  --c-warn: var(--warn);
  --c-danger: var(--danger);
  --c-text: var(--ink);
}

.report-chart {
  display: grid;
  gap: 0.6rem;
}

.report-bar {
  display: grid;
  grid-template-columns: minmax(90px, 140px) 1fr minmax(80px, 110px);
  align-items: center;
  gap: 0.75rem;
}

.report-bar > div {
  height: 0.8rem;
  background: var(--surface-2);
  border-radius: 999px;
  overflow: hidden;
}

.report-bar i {
  display: block;
  height: 100%;
  background: var(--accent);
}

.report-bar strong {
  text-align: right;
}

.negative {
  color: var(--danger);
}
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
html {
  min-width: 0;
}
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
button,
input,
select,
textarea {
  font: inherit;
}
button {
  cursor: pointer;
}
button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--ring);
}
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 10px;
}
.icon {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-sm {
  width: 16px;
  height: 16px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.text-muted {
  color: var(--muted);
}
.text-subtle {
  color: var(--subtle);
}
.text-ok {
  color: var(--ok);
}
.text-warn {
  color: var(--warn);
}
.text-danger {
  color: var(--danger);
}
.fw-600 {
  font-weight: 600;
}
.mono {
  font-family: var(--mono);
}
.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.empty-row td {
  text-align: center;
  padding: 40px;
  color: var(--muted);
}
.mb-16 {
  margin-bottom: 16px;
}
.mb-24 {
  margin-bottom: 24px;
}
/* Anchos de controles en barras de filtro (más específicos que .form-control { width:100% }) */
.filters-bar .w-160,
.page-actions .w-160 {
  width: 160px;
}
.filters-bar .w-180 {
  width: 180px;
}
.filters-bar .w-200 {
  width: 220px;
}
.filters-bar .w-240 {
  width: 260px;
}
.app-container {
  display: flex;
  min-height: 100vh;
}
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  background: var(--sidebar);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  z-index: 50;
}
.brand {
  height: 64px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--sidebar-border);
  color: #fff;
}
.brand > span:last-child {
  display: flex;
  flex-direction: column;
}
.brand strong {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
}
.brand small {
  font: 500 10px/1.4 var(--mono);
  letter-spacing: 0.14em;
  color: var(--sidebar-text);
}
.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--accent);
  display: grid;
  place-items: center;
  color: #fff;
}
.nav-section-label {
  font: 500 10px var(--mono);
  letter-spacing: 0.14em;
  color: #6b7177;
  padding: 22px 12px 8px;
}
.nav-links {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 0 12px;
  flex: 1;
}
.nav-link {
  height: 36px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px;
  color: var(--sidebar-text);
  background: transparent;
  border: 0;
  border-radius: 8px;
  text-align: left;
  font-size: 13.5px;
  font-weight: 500;
  transition: 150ms;
}
.nav-link:hover {
  background: rgba(255, 255, 255, 0.05);
  color: #fff;
}
.nav-link.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-ink);
}
.user-profile {
  border-top: 1px solid var(--sidebar-border);
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--sidebar-2);
  border: 1px solid var(--sidebar-border);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 600;
  flex: none;
}
.user-info {
  min-width: 0;
  flex: 1;
}
.user-name {
  color: #fff;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-role {
  font: 500 10px var(--mono);
  letter-spacing: 0.08em;
  color: var(--sidebar-text);
}
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
}
.topbar {
  height: 64px;
  position: sticky;
  top: 0;
  z-index: 20;
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
}
.crumb-root {
  color: var(--muted);
}
.crumb-separator {
  color: var(--subtle);
  padding: 0 9px;
}
.topbar-title {
  font-weight: 600;
}
.env-pill {
  font: 500 11px var(--mono);
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
.dot {
  width: 7px;
  height: 7px;
  background: var(--ok);
  border-radius: 50%;
}
.env-pill[data-state='connecting'] .dot {
  background: var(--warn);
}
.env-pill[data-state='offline'] .dot {
  background: var(--danger);
}
.env-pill[data-state='online'] .dot {
  animation: realtime-pulse 2s ease-in-out infinite;
}
@keyframes realtime-pulse {
  50% {
    opacity: 0.45;
  }
}
.toast-region {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 360px;
}
.toast {
  background: var(--ink);
  color: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 12px 16px;
  font-size: 13px;
  animation: toast-in 0.2s ease-out;
}
@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
@media (prefers-reduced-motion: reduce) {
  .env-pill[data-state='online'] .dot {
    animation: none;
  }
  .toast {
    animation: none;
  }
}
@media (max-width: 640px) {
  .toast-region {
    left: 12px;
    right: 12px;
    bottom: 12px;
    max-width: none;
  }
}
.tab-pane {
  max-width: 1440px;
  padding: 28px 32px 48px;
}
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}
.page-header h1 {
  font-size: 22px;
  line-height: 1.25;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.page-desc {
  color: var(--muted);
  font-size: 13.5px;
  margin-top: 5px;
}
.page-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.panel-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 0;
  overflow: hidden;
  margin-bottom: 24px;
}
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.panel-header h3 {
  font-size: 14.5px;
  font-weight: 600;
}
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.metrics-grid.compact {
  /* 180px: cabe "12.795,23 USD2" en una línea */
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}
.metrics-grid.compact .metric-card {
  padding: 14px 16px;
}
.metrics-grid.compact .value {
  font-size: 20px;
}
/* Montos en tarjetas: el número no se parte; la moneda baja de línea si no cabe */
.metric-card .value-num {
  white-space: nowrap;
}
.metric-card .value-cur {
  display: inline-block;
  margin-left: 6px;
  font: 500 11px var(--mono);
  letter-spacing: 0.06em;
  color: var(--muted);
  white-space: nowrap;
}
/* Total convertido sin tasa BCV: "Pendiente" en lugar de 0,00, o nota de total parcial */
.metric-card .value-pending {
  color: var(--warn);
}
.metric-card .value-note {
  margin-top: 4px;
  font: 500 11px var(--mono);
  color: var(--warn);
}
.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
  /* Columna: la etiqueta arriba y el número siempre abajo, alineado entre tarjetas */
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.metric-card .label {
  font: 500 10.5px/1.4 var(--mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  display: flex;
  align-items: flex-start;
  gap: 7px;
  margin-bottom: 8px;
  /* Reserva dos líneas: una etiqueta larga no empuja el número */
  min-height: 2.8em;
}
.metric-card .label:before {
  content: '';
  flex: none;
  width: 7px;
  height: 7px;
  margin-top: calc((1.4em - 7px) / 2);
  border-radius: 50%;
  background: var(--subtle);
}
.metric-card.primary .label:before {
  background: var(--accent);
}
.metric-card.ok .label:before {
  background: var(--ok);
}
.metric-card.warn .label:before {
  background: var(--warn);
}
.metric-card.danger .label:before {
  background: var(--danger);
}
.metric-card .value {
  margin-top: auto;
  font-size: 28px;
  line-height: 1.1;
  font-weight: 600;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.filters-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px 20px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.input-icon {
  position: relative;
}
.input-icon .icon-sm {
  position: absolute;
  left: 11px;
  top: 10px;
  color: var(--muted);
  pointer-events: none;
}
.input-icon input {
  padding-left: 34px;
}
.table-responsive {
  overflow-x: auto;
}
table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
table.data-table th {
  font: 500 10.5px var(--mono);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--surface-2);
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  white-space: nowrap;
  text-align: left;
}
/* Columnas numéricas: el título alineado con los montos (a la derecha) */
table.data-table th.num {
  text-align: right;
}
/* Montos, tasas y su fecha en una sola línea */
table.data-table td.num {
  white-space: nowrap;
}
table.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--ink-2);
  vertical-align: middle;
}
table.data-table tbody tr:last-child td {
  border-bottom: 0;
}
table.data-table tbody tr:hover {
  background: #fafaf8;
}
table.data-table td strong {
  font: 500 13px var(--mono);
  color: var(--ink);
}
table.data-table .nowrap {
  white-space: nowrap;
}
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px;
  border: 1px solid;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
}
.badge:before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}
.badge-pagada,
.badge-processed,
.badge-resuelta {
  color: var(--ok);
  background: var(--ok-bg);
  border-color: var(--ok-bd);
}
.badge-pagada_con_diferencias,
.badge-needs_review,
.badge-media {
  color: var(--warn);
  background: var(--warn-bg);
  border-color: var(--warn-bd);
}
.badge-no_pagada,
.badge-error,
.badge-alta,
.badge-abierta {
  color: var(--danger);
  background: var(--danger-bg);
  border-color: var(--danger-bd);
}
.badge-baja {
  color: var(--info);
  background: var(--info-bg);
  border-color: var(--info-bd);
}
.badge-pendiente,
.badge-ignored,
.badge-descartada {
  color: var(--neutral);
  background: var(--neutral-bg);
  border-color: var(--neutral-bd);
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 36px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 500;
  transition: 150ms;
}
.btn-primary {
  background: var(--ink);
  color: #fff;
}
.btn-primary:hover {
  background: #2a2e33;
}
.btn-secondary {
  background: #fff;
  border-color: var(--border-strong);
  color: var(--ink);
}
.btn-secondary:hover {
  background: var(--surface-2);
}
.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-sm {
  height: 30px;
  padding: 0 10px;
  font-size: 12.5px;
}
.btn-whatsapp {
  border-color: #128c4b;
  color: #128c4b;
}
.btn-whatsapp:hover:not(:disabled) {
  background: #f0faf4;
}
.btn-icon {
  width: 32px;
  padding: 0;
  background: transparent;
  border-color: transparent;
  color: var(--sidebar-text);
}
.btn-icon:hover {
  background: rgba(255, 255, 255, 0.05);
  color: #fff;
}
.nav-toggle {
  display: none;
}
.btn-wide {
  width: 100%;
  height: 40px;
}
.form-group {
  margin-bottom: 16px;
}
.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink-2);
}
.form-control,
.form-select {
  width: 100%;
  height: 36px;
  padding: 0 12px;
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  color: var(--ink);
  font-size: 13.5px;
}
.form-control::placeholder {
  color: var(--subtle);
}
.form-control:focus,
.form-select:focus {
  border-color: var(--accent);
  outline: none;
  box-shadow: 0 0 0 3px var(--ring);
}
.form-select {
  appearance: none;
  padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23686E75' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
.form-select.form-select-sm {
  width: auto;
  min-width: 140px;
  height: 30px;
  font-size: 12.5px;
}
textarea.form-control {
  height: auto;
  padding: 10px 12px;
  resize: vertical;
}
input[type='date'] {
  color-scheme: light;
}
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(15, 17, 20, 0.45);
  backdrop-filter: blur(2px);
}
.modal-dialog {
  width: 100%;
  max-width: 650px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  animation: modal-in 160ms ease-out;
}
.modal-dialog > form {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.modal-dialog-wide {
  max-width: 850px;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 {
  font-size: 16px;
  font-weight: 600;
}
.modal-close {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
}
.modal-close:hover {
  background: var(--surface-2);
  color: var(--ink);
}
.modal-body {
  padding: 22px;
  overflow-y: auto;
  flex: 1;
}
.modal-body .table-responsive {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 24px;
}
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 14px 22px;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
}
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 24px;
  margin-bottom: 24px;
}
.detail-item small {
  display: block;
  color: var(--muted);
  font: 500 10.5px var(--mono);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 2px;
}
.detail-item > div {
  color: var(--ink-2);
}
.section-title {
  font-size: 13px;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
  margin-bottom: 12px;
}
.alert {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 16px;
}
.alert-danger {
  color: var(--danger);
  background: var(--danger-bg);
  border: 1px solid var(--danger-bd);
}
.alert-success {
  color: var(--ok);
  background: var(--ok-bg);
  border: 1px solid var(--ok-bd);
}
.alert-warn {
  color: var(--warn);
  background: var(--warn-bg);
  border: 1px solid var(--warn-bd);
}
.metric-clickable {
  cursor: pointer;
}
.filter-check {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
  color: var(--ink-2);
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
/* Formularios sueltos dentro de una tarjeta (.panel-card no tiene padding): mismo margen que el
   encabezado, y el botón alineado con los campos (Precio del gasoil, Configuración de nómina). */
.panel-card > form.form-grid {
  padding: 16px 20px 20px;
  align-items: end;
}
#fuel-price-card > #fuel-current-price {
  margin: 0;
  padding: 14px 20px 0;
}
.clickable-row {
  cursor: pointer;
}
.clickable-row:hover {
  background: var(--surface-2);
}
.detail-description {
  white-space: pre-wrap;
  margin-bottom: 20px;
}
.detail-edit {
  display: grid;
  gap: 10px;
  margin: 20px 0;
  padding: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.detail-edit label {
  display: grid;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
}
.attachment-gallery {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  min-height: 46px;
  margin-bottom: 20px;
}
.attachment-gallery img {
  width: 84px;
  height: 84px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  cursor: zoom-in;
}
.attachment-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 12px;
}
.attachment-list span {
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.text-strike {
  text-decoration: line-through;
}
.btn-danger {
  color: var(--danger);
  border-color: var(--danger-bd);
  background: var(--danger-bg);
}
body.role-operator .admin-only {
  display: none !important;
}
.topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
}
.bcv-chip {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--ink-2);
  font: 500 11.5px var(--mono);
  white-space: nowrap;
}
.bcv-chip:hover {
  background: var(--border);
}
.bcv-chip.is-stale {
  color: var(--danger);
  background: var(--danger-bg);
  border-color: var(--danger-bd);
}
.badge-warning-line {
  color: var(--warn);
  background: var(--warn-bg);
  border-color: var(--warn-bd);
  margin-top: 4px;
  font-size: 11px;
}
.settings-section-body {
  padding: 20px;
  border-bottom: 1px solid var(--border);
}
.bcv-sync-meta {
  margin-top: auto;
  font-size: 13px;
  line-height: 1.4;
  color: var(--ink-2);
}
.bcv-manual-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  align-items: end;
}
.bcv-manual-submit {
  display: flex;
  align-items: flex-end;
}
@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
.login-screen {
  position: fixed;
  inset: 0;
  display: flex;
  background: var(--surface);
  z-index: 1000;
}
.login-aside {
  width: 44%;
  padding: 0 8%;
  display: flex;
  flex-direction: column;
  color: #fff;
  background-color: var(--sidebar);
  background-image: radial-gradient(circle at 80% 20%, rgba(15, 118, 110, 0.18), transparent 35%),
    linear-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.04) 1px, transparent 1px);
  background-size:
    auto,
    36px 36px,
    36px 36px;
}
.login-aside .brand {
  margin: 0;
  padding: 40px 0 0;
  height: auto;
  border-bottom: 0;
}
.login-aside-content {
  margin: auto 0;
}
.login-aside h1 {
  font-size: 28px;
  line-height: 1.2;
  font-weight: 600;
  max-width: 420px;
}
.login-aside ul {
  list-style: none;
  margin-top: 28px;
  display: grid;
  gap: 16px;
  color: var(--sidebar-text);
  font-size: 13.5px;
}
.login-aside li {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}
.login-aside li .icon {
  color: #14b8a6;
}
.login-aside-footer {
  padding: 24px 0;
  font: 500 10px var(--mono);
  color: var(--sidebar-text);
}
.login-main {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: 100%;
  max-width: 380px;
}
.login-card h2 {
  font-size: 24px;
  font-weight: 600;
}
.login-card > p {
  color: var(--muted);
  font-size: 13.5px;
  margin: 5px 0 28px;
}
@media (max-width: 1100px) {
  .tab-pane {
    padding: 24px;
  }
}
@media (max-width: 900px) {
  .sidebar {
    position: sticky;
    inset: auto;
    width: 100%;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    /* Marca, avatar/salir y ☰ centrados en la misma línea */
    align-items: center;
  }
  .sidebar .brand {
    order: 1;
    width: auto;
    border: 0;
  }
  .nav-toggle {
    display: inline-flex;
    order: 3;
    color: var(--sidebar-text);
    margin-right: 12px;
  }
  .nav-section-label {
    display: none;
  }
  .nav-links {
    order: 4;
    display: none;
    width: 100%;
    flex-direction: column;
    padding: 8px 12px 12px;
    flex: none;
    background: var(--sidebar);
    border-bottom: 1px solid var(--sidebar-border);
  }
  .sidebar.nav-open .nav-links {
    display: flex;
  }
  .nav-link {
    width: 100%;
    min-height: 44px;
    flex: none;
  }
  .user-profile {
    order: 2;
    margin-left: auto;
    border: 0;
    padding: 16px;
  }
  .user-info {
    display: none;
  }
  .main-content {
    margin-left: 0;
  }
  .topbar {
    display: none;
  }
  .app-container {
    flex-direction: column;
  }
  .login-aside {
    display: none;
  }
  /* En pantallas estrechas las tablas se desplazan de lado en vez de partir cada celda */
  table.data-table td {
    white-space: nowrap;
  }
}
@media (max-width: 640px) {
  .tab-pane {
    padding: 16px;
  }
  .page-header {
    flex-direction: column;
  }
  .page-actions {
    width: 100%;
  }
  .page-actions > * {
    flex: 1;
  }
  .metrics-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }
  .metric-card {
    padding: 14px;
  }
  .metric-card .value {
    font-size: 24px;
  }
  .filters-bar {
    align-items: stretch;
  }
  .filters-bar > * {
    width: 100% !important;
  }
  .filters-bar button {
    width: auto !important;
    flex: 1;
  }
  .detail-grid {
    grid-template-columns: 1fr;
  }
  .modal-backdrop {
    padding: 10px;
  }
  .modal-body {
    padding: 16px;
  }
  .modal-header {
    padding: 14px 16px;
  }
  .modal-footer {
    padding: 12px 16px;
  }
  .login-main {
    padding: 20px;
  }
  .form-grid {
    grid-template-columns: 1fr;
  }
  .page-actions {
    flex-wrap: wrap;
  }
  .page-actions > * {
    min-width: 0;
  }
}
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
/* Botón Refrescar: ícono girando mientras carga, confirmación al terminar */
@keyframes refresh-spin {
  to {
    transform: rotate(360deg);
  }
}
.btn .btn-label {
  white-space: nowrap;
}
.btn.is-refreshing {
  cursor: progress;
  opacity: 0.85;
}
.btn.is-refreshing svg {
  animation: refresh-spin 0.8s linear infinite;
}
.btn.is-done {
  color: var(--ok);
  border-color: var(--ok);
}
.btn.is-failed {
  color: var(--danger);
  border-color: var(--danger);
}
/* Página del chofer */
/* .btn y otros fijan display: el atributo hidden debe ganar siempre. */
.driver-page [hidden] {
  display: none !important;
}
.driver-app-panel {
  background: white;
  border: 1px solid #dfe5ea;
  border-radius: 0.75rem;
  padding: 1rem;
  margin: 1rem 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}
.driver-app-panel > strong {
  display: block;
}
.driver-app-panel > button {
  margin: 0.75rem 0.5rem 0 0;
}
.driver-app-panel form {
  margin-top: 0.75rem;
}
.driver-app-panel form label {
  display: block;
  margin-bottom: 0.5rem;
}
.driver-pair-code {
  display: inline-block;
  font-family: var(--mono);
  font-size: 1.5rem;
  letter-spacing: 0.15em;
  margin: 0.5rem 0;
}
.driver-page {
  background: #f5f7f9;
  color: #18212b;
}
.driver-shell {
  max-width: 560px;
  margin: 0 auto;
  padding: 1rem;
}
.driver-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.driver-header h1 {
  font-size: 1.5rem;
  margin: 0;
}
.driver-header p {
  color: #5c6875;
  margin: 0.35rem 0 0;
}
.driver-message {
  min-height: 1.5rem;
  margin: 1rem 0;
}
.driver-day h2 {
  font-size: 1.1rem;
  margin: 1.4rem 0 0.6rem;
}
.driver-card {
  background: white;
  border: 1px solid #dfe5ea;
  border-radius: 0.75rem;
  padding: 1rem;
  margin-bottom: 0.8rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}
.driver-card--focus {
  border: 2px solid #14b8a6;
}
.driver-card h3 {
  margin: 0 0 0.4rem;
}
.driver-card p {
  margin: 0.3rem 0;
  color: #526170;
}
.driver-stage {
  border-top: 1px solid #edf0f2;
  margin-top: 0.8rem;
  padding-top: 0.7rem;
}
.driver-stage > div {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0.45rem 0;
}
.driver-chip {
  display: inline-block;
  background: #e6f4f2;
  color: #12665f;
  padding: 0.3rem 0.55rem;
  border-radius: 999px;
}
.driver-empty {
  color: #6c7782;
  font-style: italic;
}
.driver-change {
  min-height: 44px;
}
.driver-editor {
  width: min(92vw, 520px);
  border: 0;
  border-radius: 0.75rem;
  padding: 1.2rem;
}
.driver-editor::backdrop {
  background: rgba(0, 0, 0, 0.4);
}
.driver-helper-hint {
  margin: 0.4rem 0;
  color: var(--muted);
  font-size: 0.9rem;
}
.driver-helper-select {
  margin: 0 0 0.8rem;
}
/* En el diálogo del chofer la lista se despliega dentro del flujo para que no la recorte el modal */
.driver-editor .ms-dropdown {
  position: static;
  margin-top: 4px;
}
.driver-editor .ms-option {
  min-height: 44px;
  display: flex;
  align-items: center;
}
.driver-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: 1rem;
}
.driver-actions .btn,
.driver-header .btn {
  min-height: 44px;
}
.driver-page #driver-report-incident {
  width: 100%;
  min-height: 48px;
  margin: 0 0 1rem;
  font-size: 1rem;
}
#driver-incident-dialog {
  max-width: 390px;
  width: calc(100% - 20px);
  max-height: 92vh;
  overflow: auto;
}
#driver-incident-dialog form {
  display: grid;
  gap: 0.8rem;
}
#driver-incident-dialog label {
  display: grid;
  gap: 0.3rem;
}
#driver-incident-dialog select,
#driver-incident-dialog textarea,
#driver-incident-dialog input[type='file'] {
  width: 100%;
  min-height: 44px;
  padding: 0.65rem;
  border: 1px solid #dfe5ea;
  border-radius: 0.45rem;
  background: #fff;
}
#driver-incident-dialog textarea {
  min-height: 90px;
}

.crew-editor-stages {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
  margin: 1rem 0;
}

.ms-container {
  position: relative;
}
.ms-control {
  position: relative;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
  min-height: 42px;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  transition: border-color 120ms, box-shadow 120ms;
}
.ms-control:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 138, 126, 0.12);
}
.ms-chips {
  display: contents;
}
.ms-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 100%;
  padding: 4px 7px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink-2);
  font-size: 12px;
}
.ms-chip button {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
}
.ms-search {
  flex: 1;
  min-width: 130px;
  min-height: 28px;
  padding: 3px 2px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}
.ms-search:disabled {
  cursor: not-allowed;
}
/* El foco se marca en la caja completa (.ms-control:focus-within), no en el buscador interno */
.ms-search:focus-visible {
  box-shadow: none;
}
/* Separación entre "Copiar de carga" y el campo de Notas */
.crew-editor-stages + .btn {
  margin-bottom: 16px;
}
.ms-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  left: 0;
  z-index: 110;
  max-height: 220px;
  overflow-y: auto;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
}
.ms-option {
  padding: 9px 10px;
  border-radius: var(--radius);
  cursor: pointer;
}
.ms-option:hover,
.ms-option.is-highlighted {
  background: var(--surface-2);
}
.ms-empty {
  padding: 9px 10px;
  color: var(--muted);
}

.crew-detail {
  margin-bottom: 24px;
}

.crew-detail p {
  margin: 0 0 6px;
}

.crew-detail .badge {
  margin: 0.15rem;
}

@media (max-width: 640px) {
  .ms-search {
    min-width: 100px;
  }
}

/* Fase 2: el contador de la pestaña se oculta cuando no hay abiertas */
.nav-link .badge[hidden] {
  display: none !important;
}
/* Fase 2: filtros de incidencias de viaje y gastos en una fila que se adapta */
#trips-filter-form > .form-control,
#trips-filter-form > .form-select,
#tab-expenses .filters-bar > .form-control,
#tab-expenses .filters-bar > .form-select {
  flex: 0 1 190px;
  width: auto;
  min-width: 150px;
}
@media (max-width: 600px) {
  #trips-filter-form > .form-control,
  #trips-filter-form > .form-select,
  #tab-expenses .filters-bar > .form-control,
  #tab-expenses .filters-bar > .form-select {
    flex: 1 1 100%;
  }
}

/* Fase 3: botones con atributo hidden (cerrar/reabrir semana) */
.btn[hidden] {
  display: none !important;
}
#report-export {
  white-space: nowrap;
}
#report-chart {
  padding: 4px 20px 18px;
}
