:root {
  --sidebar-width: 304px;
  --bg-deep: #0b1420;
  --bg-panel: #101d2c;
  --bg-card: rgba(255, 255, 255, 0.045);
  --border-soft: rgba(255, 255, 255, 0.08);
  --text-strong: #f2f7fb;
  --text-muted: #93a5b8;
  --text-faint: #6c8096;
  --accent: #10b981;
  --accent-soft: rgba(16, 185, 129, 0.14);
  --accent-line: rgba(16, 185, 129, 0.45);
  --danger: #f87171;
  --radius-lg: 18px;
  --radius-md: 12px;
  --shadow-panel: 0 24px 60px rgba(4, 12, 20, 0.28);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--font);
  background: var(--bg-deep);
  color: var(--text-strong);
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
p {
  margin: 0;
}

button {
  font: inherit;
  color: inherit;
}

.app {
  display: flex;
  height: 100%;
  overflow: hidden;
}

/* ---------------------------------------------------------------- Sidebar */

.sidebar {
  position: relative;
  z-index: 20;
  display: flex;
  flex: 0 0 var(--sidebar-width);
  flex-direction: column;
  width: var(--sidebar-width);
  background:
    radial-gradient(circle at 12% -8%, rgba(16, 185, 129, 0.22), transparent 46%),
    linear-gradient(180deg, var(--bg-panel), var(--bg-deep));
  border-right: 1px solid var(--border-soft);
  box-shadow: var(--shadow-panel);
}

.sidebar__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 22px 22px 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand__mark {
  display: grid;
  flex: 0 0 42px;
  place-items: center;
  width: 42px;
  height: 42px;
  color: #052e22;
  background: linear-gradient(140deg, #34d399, #10b981 62%, #059669);
  border-radius: 13px;
  box-shadow: 0 8px 20px rgba(16, 185, 129, 0.28);
}

.brand__mark svg {
  width: 24px;
  height: 24px;
}

.brand__text {
  min-width: 0;
}

.brand__text h1 {
  font-size: 1.04rem;
  font-weight: 650;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.brand__text p {
  margin-top: 3px;
  overflow: hidden;
  color: var(--text-muted);
  font-size: 0.71rem;
  letter-spacing: 0.01em;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.sidebar__body {
  flex: 1;
  overflow-y: auto;
  padding: 4px 16px 16px;
  scrollbar-color: rgba(255, 255, 255, 0.16) transparent;
  scrollbar-width: thin;
}

.section-label {
  padding: 0 6px;
  margin-bottom: 9px;
  color: var(--text-faint);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.menu {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 0;
  margin: 0 0 24px;
  list-style: none;
}

.menu__link {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  color: var(--text-muted);
  font-size: 0.88rem;
  font-weight: 500;
  text-align: left;
  text-decoration: none;
  background: transparent;
  border: 0;
  border-radius: var(--radius-md);
  transition: background-color 140ms ease, color 140ms ease;
}

.menu__link:not(:disabled) {
  cursor: pointer;
}

.menu__link:not(:disabled):hover {
  color: var(--text-strong);
  background: rgba(255, 255, 255, 0.05);
}

.menu__link.is-active {
  color: var(--text-strong);
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px rgba(16, 185, 129, 0.18);
}

.menu__link.is-active::before {
  position: absolute;
  top: 50%;
  left: 0;
  width: 3px;
  height: 18px;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
  transform: translateY(-50%);
  content: "";
}

.menu__link:disabled {
  cursor: default;
  opacity: 0.62;
}

.menu__icon {
  flex: 0 0 20px;
  width: 20px;
  height: 20px;
  color: var(--text-faint);
}

.menu__link.is-active .menu__icon {
  color: var(--accent);
}

.tag {
  padding: 2px 7px;
  margin-left: auto;
  color: var(--text-faint);
  font-size: 0.6rem;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 999px;
}

.data-card {
  padding: 16px;
  margin-bottom: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
}

.data-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.data-card__header h2 {
  color: var(--text-muted);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.status-light {
  width: 7px;
  height: 7px;
  background: var(--text-faint);
  border-radius: 50%;
  transition: background-color 200ms ease, box-shadow 200ms ease;
}

.status-light.is-ready {
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.16);
}

.status-light.is-error {
  background: var(--danger);
  box-shadow: 0 0 0 3px rgba(248, 113, 113, 0.15);
}

.data-card__metric {
  display: flex;
  align-items: baseline;
  gap: 7px;
}

.data-card__metric strong {
  color: var(--text-strong);
  font-size: 1.9rem;
  font-weight: 650;
  line-height: 1;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.data-card__metric span {
  color: var(--text-muted);
  font-size: 0.76rem;
  line-height: 1.25;
}

.data-card__meta {
  margin-top: 10px;
  color: var(--text-faint);
  font-size: 0.72rem;
  line-height: 1.45;
}

.data-card__local {
  margin-top: 4px;
  color: var(--text-muted);
}

.data-card__local[hidden] {
  display: none;
}

.map-info {
  padding: 0 6px;
}

.map-info__text {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 0.76rem;
}

.map-info__dot {
  width: 6px;
  height: 6px;
  background: var(--accent-line);
  border-radius: 50%;
}

.sidebar__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 22px;
  border-top: 1px solid var(--border-soft);
}

.connection {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-faint);
  font-size: 0.71rem;
}

.connection__dot {
  width: 6px;
  height: 6px;
  background: #fbbf24;
  border-radius: 50%;
  transition: background-color 200ms ease;
}

.connection.is-online .connection__dot {
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.14);
}

.connection.is-offline .connection__dot {
  background: var(--danger);
}

.version {
  color: var(--text-faint);
  font-size: 0.66rem;
  font-variant-numeric: tabular-nums;
}

/* ----------------------------------------------------------------- Botones */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 14px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  transition: background-color 150ms ease, border-color 150ms ease, opacity 150ms ease;
}

.button:disabled {
  cursor: progress;
  opacity: 0.72;
}

.button svg {
  width: 16px;
  height: 16px;
}

.button__icon {
  display: inline-flex;
}

.button__icon[hidden],
.spinner[hidden] {
  display: none;
}

.button--primary {
  color: #04281d;
  background: linear-gradient(140deg, #34d399, #10b981);
  border-color: rgba(16, 185, 129, 0.4);
  box-shadow: 0 8px 20px rgba(16, 185, 129, 0.16);
}

.button--primary:not(:disabled):hover {
  background: linear-gradient(140deg, #6ee7b7, #34d399);
}

.button--ghost {
  color: var(--text-muted);
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--border-soft);
}

.button--ghost:hover {
  color: var(--text-strong);
  background: rgba(255, 255, 255, 0.1);
}

.data-card__action {
  width: 100%;
  margin-top: 13px;
}

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 700ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ------------------------------------------------------ Ventana de descarga */

.download-dialog {
  width: min(660px, calc(100vw - 32px));
  max-height: min(780px, calc(100vh - 40px));
  padding: 0;
  overflow: hidden;
  color: var(--text-strong);
  background: linear-gradient(180deg, #132232, #0c1623 72%);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 18px;
  box-shadow: 0 32px 90px rgba(0, 0, 0, 0.55);
}

.download-dialog[open] {
  display: flex;
  flex-direction: column;
}

.download-dialog::backdrop {
  background: rgba(4, 12, 20, 0.62);
  backdrop-filter: blur(4px);
}

.download-dialog__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 22px 16px;
  border-bottom: 1px solid var(--border-soft);
}

.download-dialog__heading {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.download-dialog__mark {
  display: grid;
  flex: 0 0 40px;
  place-items: center;
  width: 40px;
  height: 40px;
  color: #052e22;
  background: linear-gradient(140deg, #34d399, #10b981 62%, #059669);
  border-radius: 12px;
  box-shadow: 0 8px 20px rgba(16, 185, 129, 0.24);
}

.download-dialog__mark svg {
  width: 20px;
  height: 20px;
}

.download-dialog__eyebrow {
  margin-bottom: 3px;
  color: var(--text-faint);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.download-dialog__header h2 {
  overflow: hidden;
  font-size: 1.05rem;
  font-weight: 650;
  letter-spacing: -0.01em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.download-dialog__close {
  flex: 0 0 auto;
  color: var(--text-muted);
}

.download-dialog__body {
  flex: 1;
  padding: 18px 22px 8px;
  overflow-y: auto;
  scrollbar-color: rgba(255, 255, 255, 0.16) transparent;
  scrollbar-width: thin;
}

.download-overview {
  padding: 14px 16px;
  margin-bottom: 14px;
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: 14px;
}

.download-overview__top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.download-overview__status {
  font-size: 0.85rem;
  font-weight: 600;
}

.download-overview__count {
  flex: 0 0 auto;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
}

.progress {
  height: 6px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
}

.progress__bar {
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, #10b981, #34d399);
  border-radius: inherit;
  transition: width 250ms ease;
}

.download-overview__meta {
  margin-top: 9px;
  color: var(--text-faint);
  font-size: 0.71rem;
  line-height: 1.4;
}

.download-overview__action {
  display: flex;
  gap: 7px;
  align-items: baseline;
  padding-top: 8px;
  margin-top: 8px;
  color: var(--text-muted);
  font-size: 0.69rem;
  line-height: 1.45;
  border-top: 1px dashed rgba(255, 255, 255, 0.07);
}

.download-overview__action::before {
  flex: 0 0 5px;
  width: 5px;
  height: 5px;
  margin-top: 0.33em;
  background: var(--accent);
  border-radius: 50%;
  animation: pulse 1.4s ease-in-out infinite;
  content: "";
}

.download-overview__action[hidden] {
  display: none;
}

@keyframes pulse {
  50% {
    opacity: 0.3;
  }
}

.download-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 310px;
  padding: 0;
  margin: 0 0 12px;
  overflow-y: auto;
  list-style: none;
  scrollbar-color: rgba(255, 255, 255, 0.16) transparent;
  scrollbar-width: thin;
}

.download-item {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 9px 10px;
  border-radius: 10px;
}

.download-item.is-active {
  background: rgba(16, 185, 129, 0.07);
}

.download-item__icon {
  display: grid;
  flex: 0 0 18px;
  place-items: center;
  width: 18px;
  height: 18px;
  margin-top: 1px;
  color: #052e22;
  font-size: 0.62rem;
  font-weight: 800;
  background: transparent;
  border-radius: 50%;
}

.download-item__icon .dot {
  width: 6px;
  height: 6px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 50%;
}

.download-item[data-status="downloading"] .download-item__icon,
.download-item[data-status="extracting"] .download-item__icon {
  color: var(--accent);
}

.download-item[data-status="done"] .download-item__icon {
  background: var(--accent);
}

.download-item[data-status="error"] .download-item__icon {
  color: #2a0b0b;
  background: var(--danger);
}

.download-item__main {
  flex: 1;
  min-width: 0;
}

.download-item__name {
  overflow: hidden;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.download-item.is-active .download-item__name,
.download-item[data-status="done"] .download-item__name {
  color: var(--text-strong);
}

.download-item__detail {
  margin-top: 2px;
  overflow: hidden;
  color: var(--text-faint);
  font-size: 0.67rem;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.download-item[data-status="error"] .download-item__detail {
  color: #fca5a5;
  white-space: normal;
}

.download-item__bar {
  display: none;
  height: 3px;
  margin-top: 6px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.07);
  border-radius: 999px;
}

.download-item[data-status="downloading"] .download-item__bar {
  display: block;
}

.download-item__bar span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--accent-line);
  border-radius: inherit;
  transition: width 200ms ease;
}

.download-log {
  padding-top: 10px;
  margin-bottom: 4px;
  border-top: 1px solid var(--border-soft);
}

.download-log summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 2px;
  color: var(--text-muted);
  font-size: 0.73rem;
  font-weight: 600;
  list-style: none;
  cursor: pointer;
}

.download-log summary::-webkit-details-marker {
  display: none;
}

.download-log summary::before {
  margin-right: 7px;
  content: "▸";
  transition: transform 150ms ease;
}

.download-log[open] summary::before {
  transform: rotate(90deg);
}

.download-log__count {
  margin-left: auto;
  color: var(--text-faint);
  font-size: 0.67rem;
  font-variant-numeric: tabular-nums;
}

.download-log__list {
  max-height: 170px;
  padding: 8px 10px;
  margin: 8px 0 0;
  overflow-y: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.66rem;
  line-height: 1.6;
  color: var(--text-faint);
  list-style: none;
  background: rgba(0, 0, 0, 0.22);
  border-radius: 9px;
}

.download-log__entry {
  display: flex;
  gap: 8px;
}

.download-log__time {
  flex: 0 0 auto;
  color: rgba(147, 165, 184, 0.65);
}

.download-log__entry[data-level="success"] .download-log__msg {
  color: #6ee7b7;
}

.download-log__entry[data-level="error"] .download-log__msg {
  color: #fca5a5;
}

.download-dialog__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 22px;
  background: rgba(0, 0, 0, 0.12);
  border-top: 1px solid var(--border-soft);
}

.download-dialog__hint {
  color: var(--text-faint);
  font-size: 0.7rem;
  line-height: 1.4;
}

.download-dialog__footer .button {
  flex: 0 0 auto;
  width: auto;
}

/* ------------------------------------------------------------ Líneas */

.lines-dialog__body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
}

.lines-back {
  align-self: flex-start;
  padding: 2px 0;
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 500;
  background: none;
  border: 0;
  cursor: pointer;
}

.lines-back:hover {
  color: var(--text-strong);
}

.lines-back[hidden] {
  display: none;
}

.lines-search {
  display: flex;
  flex: 0 0 auto;
  gap: 9px;
  align-items: center;
  padding: 9px 12px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  transition: border-color 150ms ease, box-shadow 150ms ease;
}

.lines-search svg {
  flex: 0 0 16px;
  width: 16px;
  height: 16px;
  color: var(--text-faint);
}

.lines-search input {
  flex: 1;
  min-width: 0;
  padding: 0;
  color: var(--text-strong);
  font: inherit;
  font-size: 0.78rem;
  background: transparent;
  border: 0;
  outline: none;
}

.lines-search input::placeholder {
  color: var(--text-faint);
}

.lines-search:focus-within {
  border-color: rgba(16, 185, 129, 0.45);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

.lines-status {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
  align-items: center;
  padding: 2px;
  color: var(--text-muted);
  font-size: 0.71rem;
  line-height: 1.4;
}

.lines-status[hidden] {
  display: none;
}

.lines-status.is-error {
  color: #fca5a5;
}

.lines-status .spinner {
  flex: 0 0 14px;
  color: var(--accent);
}

.lines-list {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 2px;
  min-height: 250px;
  max-height: 430px;
  padding: 0;
  margin: 0;
  overflow-y: auto;
  list-style: none;
  scrollbar-color: rgba(255, 255, 255, 0.16) transparent;
  scrollbar-width: thin;
}

.lines-list.is-busy {
  pointer-events: none;
  opacity: 0.55;
}

.lines-empty {
  padding: 24px 10px;
  color: var(--text-faint);
  font-size: 0.76rem;
  line-height: 1.5;
  text-align: center;
}

.lines-network-action {
  flex: 0 0 auto;
  width: 100%;
}

.lines-network-action[hidden] {
  display: none;
}

.operator-item,
.line-item {
  display: flex;
  gap: 11px;
  align-items: center;
  width: 100%;
  padding: 10px;
  text-align: left;
  cursor: pointer;
  background: transparent;
  border: 0;
  border-radius: 10px;
  transition: background-color 140ms ease;
}

.operator-item:not(:disabled):hover,
.line-item:hover {
  background: rgba(255, 255, 255, 0.05);
}

.operator-item:disabled {
  cursor: default;
  opacity: 0.42;
}

.operator-item__icon {
  display: grid;
  flex: 0 0 32px;
  place-items: center;
  width: 32px;
  height: 32px;
  color: #a7f3d0;
  font-size: 0.72rem;
  font-weight: 750;
  letter-spacing: 0.02em;
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.18);
  border-radius: 9px;
}

.operator-item__main,
.line-item__main {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.operator-item__name,
.line-item__name {
  overflow: hidden;
  color: var(--text-strong);
  font-size: 0.79rem;
  font-weight: 550;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.operator-item__meta,
.line-item__meta {
  overflow: hidden;
  color: var(--text-faint);
  font-size: 0.66rem;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.operator-item__arrow,
.line-item__arrow {
  flex: 0 0 auto;
  color: var(--text-faint);
  font-size: 1.05rem;
  line-height: 1;
}

.line-item__swatch {
  flex: 0 0 4px;
  width: 4px;
  height: 30px;
  background: var(--line-color);
  border-radius: 3px;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.06);
}

.line-item.is-selected {
  background: rgba(16, 185, 129, 0.09);
  box-shadow: inset 0 0 0 1px rgba(16, 185, 129, 0.18);
}

.line-item:hover .line-item__swatch {
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.16);
}

/* --------------------------------------------------- Línea activa (mapa) */

.active-line {
  position: absolute;
  top: 62px;
  left: 18px;
  z-index: 850;
  display: flex;
  gap: 10px;
  align-items: center;
  max-width: min(400px, calc(100% - 36px));
  padding: 8px 8px 8px 11px;
  background: rgba(12, 22, 35, 0.94);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(4, 12, 20, 0.3);
  backdrop-filter: blur(8px);
  color-scheme: dark;
}

.active-line[hidden] {
  display: none;
}

.active-line__swatch {
  flex: 0 0 5px;
  align-self: stretch;
  width: 5px;
  min-height: 34px;
  background: var(--line-color, var(--accent));
  border-radius: 3px;
}

.active-line__content {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.active-line__body {
  width: 100%;
  min-width: 0;
  padding: 0;
  text-align: left;
  cursor: pointer;
  background: none;
  border: 0;
}

.active-line__variant-trigger {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 4px 8px;
  color: var(--text-strong);
  font: inherit;
  font-size: 0.66rem;
  text-align: left;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 7px;
  transition: background-color 140ms ease;
}

.active-line__variant-trigger #active-line-variant-current {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.active-line__variant-trigger[hidden] {
  display: none;
}

.active-line__variant-trigger:hover {
  background: rgba(255, 255, 255, 0.09);
}

.active-line__variant-trigger svg {
  flex: 0 0 8px;
  width: 8px;
  height: 8px;
  color: var(--text-muted);
  transition: transform 150ms ease;
}

.active-line__variant-trigger[aria-expanded="true"] svg {
  transform: rotate(180deg);
}

.active-line__variants {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 2;
  width: 300px;
  max-width: calc(100vw - 48px);
  padding: 9px;
  background: rgba(12, 22, 35, 0.98);
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  box-shadow: 0 18px 45px rgba(4, 12, 20, 0.5);
  backdrop-filter: blur(10px);
  animation: variant-panel-in 130ms ease-out;
}

.active-line__variants[hidden] {
  display: none;
}

@keyframes variant-panel-in {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.active-line__variants-title {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 2px 4px 8px;
  color: var(--text-faint);
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.active-line__variants-count {
  color: var(--text-muted);
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
}

.active-line__variants-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: min(260px, calc(100vh - 240px));
  overflow-y: auto;
  scrollbar-color: rgba(255, 255, 255, 0.16) transparent;
  scrollbar-width: thin;
}

.variant-option {
  display: flex;
  gap: 9px;
  align-items: center;
  width: 100%;
  padding: 7px 8px;
  text-align: left;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid transparent;
  border-radius: 9px;
  transition: background-color 140ms ease, border-color 140ms ease;
}

.variant-option:hover {
  background: rgba(255, 255, 255, 0.07);
}

.variant-option[aria-checked="true"] {
  background: rgba(16, 185, 129, 0.1);
  border-color: rgba(16, 185, 129, 0.22);
}

.variant-option__swatch {
  flex: 0 0 8px;
  width: 8px;
  height: 8px;
  background: var(--line-color, var(--accent));
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.05);
}

.variant-option__main {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.variant-option__name {
  color: var(--text-strong);
  font-size: 0.7rem;
  font-weight: 550;
}

.variant-option__meta {
  color: var(--text-faint);
  font-size: 0.61rem;
}

.variant-option__check {
  flex: 0 0 auto;
  min-width: 10px;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 700;
  text-align: right;
}

/* ------------------------------------------------------ Leyenda de red */

.network-legend {
  position: absolute;
  top: 62px;
  left: 18px;
  z-index: 850;
  display: flex;
  flex-direction: column;
  width: 300px;
  max-width: calc(100% - 36px);
  max-height: min(600px, calc(100vh - 100px));
  padding: 10px;
  background: rgba(12, 22, 35, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(4, 12, 20, 0.3);
  backdrop-filter: blur(8px);
}

.network-legend[hidden] {
  display: none;
}

.network-legend__header {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  justify-content: space-between;
  padding: 2px 2px 8px;
  border-bottom: 1px solid var(--border-soft);
}

.network-legend__eyebrow {
  margin-bottom: 3px;
  color: var(--text-faint);
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.network-legend__title {
  overflow: hidden;
  color: var(--text-strong);
  font-size: 0.9rem;
  font-weight: 650;
  letter-spacing: -0.01em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.network-legend__meta {
  padding: 7px 2px;
  color: var(--text-faint);
  font-size: 0.66rem;
}

.network-legend__filter {
  align-self: flex-start;
  padding: 0 2px 7px;
  color: var(--accent);
  font: inherit;
  font-size: 0.65rem;
  cursor: pointer;
  background: none;
  border: 0;
}

.network-legend__filter:hover {
  color: #6ee7b7;
}

.network-legend__filter[hidden] {
  display: none;
}

.map-panel.is-network .leaflet-tile-pane {
  filter: grayscale(0.8) brightness(1.08) opacity(0.62);
  transition: filter 200ms ease;
}

.network-legend__list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-height: 0;
  overflow-y: auto;
  list-style: none;
  scrollbar-color: rgba(255, 255, 255, 0.16) transparent;
  scrollbar-width: thin;
}

.network-legend__list[hidden] {
  display: none;
}

.network-legend__actions {
  display: flex;
  gap: 4px;
  align-items: center;
}

.network-legend__close,
.network-legend__toggle {
  display: grid;
  flex: 0 0 28px;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  color: var(--text-muted);
  cursor: pointer;
  background: rgba(255, 255, 255, 0.05);
  border: 0;
  border-radius: 8px;
}

.network-legend__close:hover,
.network-legend__toggle:hover {
  color: var(--text-strong);
  background: rgba(255, 255, 255, 0.1);
}

.network-legend__close svg,
.network-legend__toggle svg {
  width: 14px;
  height: 14px;
}

.network-legend__toggle svg {
  transition: transform 150ms ease;
}

.network-legend__toggle[aria-expanded="true"] svg {
  transform: rotate(180deg);
}

.network-legend__item {
  display: flex;
  gap: 8px;
  align-items: center;
  min-height: 22px;
  padding: 3px 6px;
  border-radius: 6px;
}

.network-legend__item:hover {
  background: rgba(255, 255, 255, 0.04);
}

.network-legend__swatch {
  flex: 0 0 4px;
  width: 4px;
  height: 17px;
  background: var(--line-color);
  border-radius: 2px;
}

.network-legend__name {
  overflow: hidden;
  color: var(--text-muted);
  font-size: 0.69rem;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.active-line__name {
  display: block;
  overflow: hidden;
  color: var(--text-strong);
  font-size: 0.74rem;
  font-weight: 600;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.active-line__meta {
  display: block;
  margin-top: 2px;
  overflow: hidden;
  color: var(--text-muted);
  font-size: 0.64rem;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.active-line__close {
  display: grid;
  flex: 0 0 28px;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  color: var(--text-muted);
  cursor: pointer;
  background: rgba(255, 255, 255, 0.05);
  border: 0;
  border-radius: 8px;
}

.active-line__close:hover {
  color: var(--text-strong);
  background: rgba(255, 255, 255, 0.1);
}

.active-line__close svg {
  width: 14px;
  height: 14px;
}

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

/* ------------------------------------------------------------- Icon buttons */

.icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-soft);
  border-radius: 11px;
  transition: background-color 140ms ease;
}

.icon-button:hover {
  background: rgba(255, 255, 255, 0.1);
}

.icon-button svg {
  width: 20px;
  height: 20px;
}

.sidebar__close {
  display: none;
}

/* ------------------------------------------------------------------- Map */

.map-panel {
  position: relative;
  flex: 1;
  min-width: 0;
  background: #dfe6e2;
  /* Aísla los z-index de Leaflet para que el menú móvil quede por encima. */
  isolation: isolate;
}

#map {
  width: 100%;
  height: 100%;
  background: #dfe6e2;
}

.sidebar-toggle {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 1000;
  display: none;
  color: var(--bg-deep);
  background: #fff;
  border-color: rgba(15, 23, 42, 0.12);
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.16);
}

.sidebar-toggle:hover {
  background: #f4f7f6;
}

.map-caption {
  position: absolute;
  top: 18px;
  left: 18px;
  z-index: 800;
  display: inline-flex;
  gap: 8px;
  align-items: center;
  max-width: min(460px, calc(100% - 120px));
  padding: 8px 13px;
  color: #334155;
  font-size: 0.73rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  pointer-events: none;
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid rgba(15, 23, 42, 0.08);
  border-radius: 999px;
  box-shadow: 0 6px 18px rgba(15, 23, 42, 0.12);
  backdrop-filter: blur(8px);
}

.map-caption__text {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.map-caption__pin {
  flex: 0 0 auto;
  width: 7px;
  height: 7px;
  background: var(--caption-color, var(--accent));
  border-radius: 50%;
  box-shadow: 0 0 0 3px
    color-mix(in srgb, var(--caption-color, var(--accent)) 18%, transparent);
}

/* Leaflet tweaks */
.leaflet-container {
  font-family: var(--font);
  background: #dfe6e2;
}

.leaflet-control-zoom {
  overflow: hidden;
  border: 0 !important;
  border-radius: 11px !important;
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.18) !important;
}

.leaflet-control-zoom a {
  width: 36px !important;
  height: 36px !important;
  color: #1e293b !important;
  line-height: 36px !important;
  background: rgba(255, 255, 255, 0.95) !important;
  border-color: rgba(15, 23, 42, 0.08) !important;
}

.leaflet-control-zoom a:hover {
  background: #f4f7f6 !important;
}

.leaflet-control-scale {
  margin-bottom: 10px !important;
  margin-left: 16px !important;
}

.leaflet-control-scale-line {
  padding: 3px 6px !important;
  color: #334155 !important;
  font-size: 0.64rem !important;
  background: rgba(255, 255, 255, 0.82) !important;
  border-color: rgba(15, 23, 42, 0.3) !important;
  border-top: 0 !important;
  border-radius: 0 0 4px 4px;
  backdrop-filter: blur(6px);
}

.leaflet-control-attribution {
  padding: 2px 8px !important;
  font-size: 0.61rem !important;
  background: rgba(255, 255, 255, 0.82) !important;
  backdrop-filter: blur(6px);
}

/* Paradas de la línea seleccionada */
.stop-marker {
  cursor: pointer;
}

.stop-order-marker {
  background: none;
  border: 0;
  pointer-events: none;
}

.stop-order-marker span {
  display: inline-grid;
  place-items: center;
  min-width: 16px;
  height: 16px;
  padding: 0 3px;
  color: #ffffff;
  font-size: 0.58rem;
  font-weight: 700;
  line-height: 1;
  background: #475569;
  border-radius: 999px;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.28);
  font-variant-numeric: tabular-nums;
}

.leaflet-tooltip.stop-tooltip {
  padding: 6px 9px !important;
  color: #0f172a !important;
  font-size: 0.72rem !important;
  line-height: 1.2 !important;
  background: rgba(255, 255, 255, 0.96) !important;
  border: 1px solid rgba(15, 23, 42, 0.1) !important;
  border-radius: 8px !important;
  box-shadow: 0 8px 20px rgba(15, 23, 42, 0.16) !important;
}

.leaflet-tooltip-top.stop-tooltip::before {
  border-top-color: rgba(255, 255, 255, 0.96) !important;
}

.stop-label {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.stop-label__order {
  display: inline-grid;
  place-items: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  color: #ffffff;
  font-size: 0.6rem;
  font-weight: 700;
  line-height: 1;
  background: #475569;
  border-radius: 999px;
  font-variant-numeric: tabular-nums;
}

.stop-label__name {
  font-weight: 600;
}

.stop-label__code {
  color: #64748b;
  font-size: 0.66rem;
  font-variant-numeric: tabular-nums;
}

.stop-popup .leaflet-popup-content-wrapper {
  color: #0f172a;
  border-radius: 10px;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.2);
}

.stop-popup .leaflet-popup-content {
  margin: 8px 10px;
  font-size: 0.74rem;
}

.stop-popup .leaflet-popup-tip {
  box-shadow: 0 4px 10px rgba(15, 23, 42, 0.12);
}

.backdrop {
  position: fixed;
  inset: 0;
  z-index: 15;
  background: rgba(4, 12, 20, 0.5);
  border: 0;
  backdrop-filter: blur(2px);
}

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

@media (max-width: 860px) {
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 30;
    transform: translateX(-102%);
    transition: transform 240ms cubic-bezier(0.22, 1, 0.36, 1);
  }

  .app.is-open .sidebar {
    transform: translateX(0);
  }

  .sidebar__close {
    display: grid;
    color: var(--text-muted);
  }

  .sidebar-toggle {
    display: grid;
  }

  .map-caption {
    top: 16px;
    right: 16px;
    left: auto;
    max-width: calc(100% - 90px);
  }

  .download-dialog {
    width: calc(100vw - 24px);
    max-height: calc(100vh - 24px);
  }

  .download-dialog__header,
  .download-dialog__body,
  .download-dialog__footer {
    padding-right: 16px;
    padding-left: 16px;
  }

  .download-dialog__footer {
    flex-direction: column;
    align-items: stretch;
  }

  .download-dialog__footer .button {
    width: 100%;
  }

  .lines-list {
    min-height: 200px;
    max-height: calc(100vh - 390px);
  }

  .active-line {
    top: 62px;
    left: 16px;
    max-width: calc(100% - 32px);
  }

  .network-legend {
    top: 62px;
    left: 16px;
    max-width: calc(100% - 32px);
    max-height: calc(100vh - 150px);
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition-duration: 0.01ms !important;
  }
}
