:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #5c6b80;
  --line: #d7dee8;
  --paper: #f4f7fb;
  --card: #ffffff;
  --field: #ffffff;
  --blue: #155eef;
  --blue-hover: #0f3fad;
  --blue-dark: #0f3fad;
  --blue-soft: #e8f0ff;
  --blue-line: #b9cdfb;
  --sos: #d92d20;
  --ok: #067647;
  --warn: #b54708;
  --shadow: 0 18px 50px rgba(23, 32, 51, 0.12);
  --chip: #eef2f7;
  --ok-bg: #e7f6ee;
  --sos-bg: #feeceb;
  --sos-line: #f3c4c0;
  --sos-soft: #fff8f7;
  --hover: #f3f7ff;
  --row: #ffffff;
  --row-alt: #f4f7fb;
  --icon: #8b97a8;
  --focus: rgba(21, 94, 239, 0.2);
  --veil: rgba(23, 32, 51, 0.35);
  --map-bg: #d5dde8;
  --label-bg: rgba(255, 255, 255, 0.94);
  --label-ink: #111;
  --label-line: rgba(0, 0, 0, 0.28);
  --notice-ok: #b7ebc9;
  --notice-bad: #f3b4ae;
  --pin: #000000;
  --pin-stroke: #ffffff;
  font-family: "Segoe UI", sans-serif;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --ink: #e7eef8;
  --muted: #9aabc2;
  --line: #2c3a4e;
  --paper: #10161f;
  --card: #1b2636;
  --field: #121a26;
  --blue: #6b9bff;
  --blue-hover: #2f5fcc;
  --blue-dark: #9dbaff;
  --blue-soft: #1c3054;
  --blue-line: #3d5f99;
  --sos: #ff746c;
  --ok: #3dce8a;
  --warn: #f5a524;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
  --chip: #243246;
  --ok-bg: #123528;
  --sos-bg: #3a1d1c;
  --sos-line: #7a3834;
  --sos-soft: #2a1818;
  --hover: #243246;
  --row: #1b2636;
  --row-alt: #15202e;
  --icon: #9aabc2;
  --focus: rgba(107, 155, 255, 0.35);
  --veil: rgba(0, 0, 0, 0.62);
  --map-bg: #111;
  --label-bg: #f4f7fb;
  --label-ink: #121820;
  --label-line: rgba(255, 255, 255, 0.72);
  --notice-ok: #1f6b45;
  --notice-bad: #8a3a36;
  --pin: #f7f9fc;
  --pin-stroke: #0b0e14;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  color: var(--ink);
  background: var(--paper);
}

/* La barra de ProxySession es fija. El espaciador queda en el flujo y la app usa el resto. */
body {
  display: flex;
  flex-direction: column;
}

body > #ps-session-spacer {
  flex: 0 0 auto !important;
}

button, input, select { font: inherit; }

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

.login-view {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(180deg, rgba(21, 94, 239, 0.08), transparent 280px),
    var(--paper);
}

.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  padding: 28px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.login-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.theme-toggle { padding: 6px 10px; font-size: 0.82rem; }

.brand {
  margin: 0;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--blue-dark);
}

.login-card h1 {
  margin: 0;
  font-size: 1.7rem;
}

.lede, .who, .status, .meta {
  color: var(--muted);
}

.who {
  max-width: 320px;
  text-align: right;
  line-height: 1.25;
}

.lede { margin: 0; }

label {
  display: grid;
  gap: 6px;
  font-size: 0.92rem;
  font-weight: 650;
}

input, select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--field);
  color: var(--ink);
}

input:focus, select:focus {
  outline: 3px solid var(--focus);
  border-color: var(--blue);
}

button {
  border: 0;
  border-radius: 10px;
  padding: 11px 14px;
  background: var(--blue);
  color: white;
  font-weight: 700;
  cursor: pointer;
}

button:hover { background: var(--blue-hover); }

button:disabled { opacity: 0.65; }

html.busy,
html.busy * { cursor: wait !important; }

button.ghost, button.quiet {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

button.quiet, button.compact { padding: 6px 10px; font-size: 0.82rem; }

button.danger {
  background: transparent;
  color: var(--sos);
  border: 1px solid var(--sos-line);
  padding: 6px 10px;
  font-size: 0.82rem;
}

button.danger:hover { background: var(--sos-bg); }

.form-error {
  margin: 0;
  color: var(--sos);
  font-size: 0.92rem;
}

.app {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px 16px;
  padding: 10px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.brand-lockup, .top-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.status {
  font-size: 0.85rem;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--chip);
}

.status.ok { color: var(--ok); background: var(--ok-bg); }
.status.bad { color: var(--sos); background: var(--sos-bg); }

.modules { display: flex; gap: 6px; }

.module {
  padding: 6px 10px;
  background: transparent;
  color: var(--ink);
  border: 1px solid transparent;
}

.module.active,
button.quiet.active {
  background: var(--blue-soft);
  color: var(--blue-dark);
  border-color: var(--blue-line);
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: 1fr 360px;
}

.workspace.report-wide { grid-template-columns: 1fr; }

.map-wrap {
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
}

.draw-tools {
  position: absolute;
  z-index: 500;
  top: 12px;
  left: 52px;
  display: flex;
  gap: 6px;
}

.draw-tools-group {
  display: flex;
  gap: 6px;
}

.draw-tools button.quiet {
  background: var(--card);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22);
}

.draw-tools button.quiet.active {
  background: var(--blue-soft);
}

.veh-pin {
  position: relative;
  width: 28px;
  height: 28px;
}

.veh-label {
  position: absolute;
  left: 50%;
  top: 24px;
  transform: translateX(-50%);
  padding: 0 3px;
  border: 1px solid var(--label-line);
  border-radius: 3px;
  background: var(--label-bg);
  color: var(--label-ink);
  font: 700 11px/1.3 ui-sans-serif, system-ui, sans-serif;
  white-space: nowrap;
  pointer-events: none;
}

.map.drawing { cursor: crosshair; }

.selection {
  display: grid;
  gap: 8px;
  max-height: 240px;
  padding: 10px 12px;
  background: var(--card);
  border-top: 1px solid var(--line);
}

.table-wrap { overflow: auto; }

.selection table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.selection th,
.selection td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

.selection tbody tr { cursor: pointer; }
.selection tbody tr:hover { background: var(--hover); }
.selection tbody tr.sos { background: var(--sos-soft); }

.map { flex: 1; min-height: 240px; background: var(--map-bg); }

.player {
  display: grid;
  gap: 8px;
  padding: 10px 12px 12px;
  background: var(--card);
  border-top: 1px solid var(--line);
}

.player-controls,
.speeds { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.hist-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 22px;
  align-items: end;
}

.hist-stats p {
  margin: 0;
  display: grid;
  gap: 1px;
}

.hist-stats span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.hist-stats strong {
  color: var(--ink);
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.1;
}

.slider { margin: 0; }

.slider input { padding: 0; }

.player-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 0.85rem;
}

.multi-player {
  max-height: 40vh;
  min-height: 0;
  overflow: hidden;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.multi-board {
  display: grid;
  gap: 4px;
  min-height: 0;
  overflow: hidden;
  grid-template-rows: auto minmax(0, 1fr);
}

.multi-scale {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-left: 148px;
  width: calc((100% - 148px) * 0.96);
  color: var(--muted);
  font-size: 0.75rem;
}

.multi-scale span { white-space: nowrap; }

.multi-body {
  display: grid;
  grid-template-columns: 148px 1fr;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.multi-labels { display: grid; align-content: start; }

button.multi-label {
  width: 100%;
  height: 32px;
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  padding: 0 8px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 650;
  text-align: left;
}

button.multi-label span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

button.multi-label.active { background: var(--blue-soft); }

.multi-sheet {
  position: relative;
  width: 96%;
  justify-self: start;
  min-height: 32px;
  cursor: ew-resize;
  touch-action: none;
}

.multi-sheet canvas { display: block; width: 100%; cursor: pointer; }

.multi-head {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 2px;
  margin-left: -1px;
  background: var(--ink);
  pointer-events: none;
}

.multi-head::before {
  content: "";
  position: absolute;
  top: 0;
  left: -4px;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid var(--ink);
}

.swatch {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  flex: none;
  vertical-align: middle;
}

.hint { margin: 8px 0 0; color: var(--muted); font-size: 0.86rem; }

.range-form { display: grid; gap: 10px; margin-top: 10px; }

.report-main {
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px;
}

.report-kinds { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

.report-range { grid-template-columns: 1fr 1fr; align-items: end; }

.report-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

.report-main.fleet-list { overflow: hidden; }

.report-main.fleet-list .report-result.selection {
  flex: 1 1 auto;
  min-height: 0;
  grid-template-rows: auto minmax(0, 1fr);
}

.report-main.fleet-list .report-result .table-wrap {
  max-height: none;
  min-height: 0;
}

.report-list { max-height: none; }

.report-result.selection { max-height: none; }

.report-result .table-wrap {
  overflow: auto;
  max-height: calc(30px + 15 * 30px + 2px);
}

.report-check {
  display: flex;
  gap: 8px;
  align-items: center;
  font-weight: 600;
}

.side {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px;
  overflow: auto;
  background: var(--paper);
  border-left: 1px solid var(--line);
}

#multiSide {
  overflow: hidden;
}

#multiSide .side-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#multiVehicleList.list {
  max-height: none;
  overflow: visible;
}

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
}

.panel.grow { min-height: 220px; }

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.panel-head h2 {
  margin: 0;
  font-size: 0.95rem;
}

.head-tools {
  display: flex;
  align-items: center;
  gap: 6px;
}

button.icon-btn {
  width: 26px;
  height: 26px;
  padding: 0;
  display: grid;
  place-items: center;
  background: transparent;
  color: var(--icon);
  border-radius: 8px;
}

button.icon-btn svg { width: 15px; height: 15px; display: block; }

button.icon-btn:hover { background: var(--chip); color: var(--ink); }

.count {
  min-width: 1.6rem;
  text-align: center;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--chip);
  color: var(--ink);
  font-size: 0.8rem;
  font-weight: 700;
}

.count.hot { background: var(--sos-bg); color: var(--sos); }

.search { margin: 10px 0; font-weight: 500; }

.list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
  max-height: 280px;
  overflow: auto;
}

.item {
  width: 100%;
  text-align: left;
  display: grid;
  gap: 2px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--field);
  color: inherit;
}

.item strong { font-size: 0.92rem; }
.item span, .detail p { color: var(--muted); font-size: 0.82rem; font-weight: 500; }

.item.active { border-color: var(--blue); box-shadow: inset 0 0 0 1px var(--blue); }
.item.sos { border-color: var(--notice-bad); background: var(--sos-soft); }

.item-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.empty {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.detail h3 { margin: 0 0 8px; font-size: 1rem; }
.detail p { margin: 4px 0; }
.detail b { color: var(--ink); }

.veh-icon {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
}

.veh-icon svg {
  width: 26px;
  height: 26px;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.35));
}

.veh-icon.sos svg { animation: pulse 1.2s ease-in-out infinite; }

@keyframes pulse {
  50% { transform: scale(1.18); }
}

.vehicle-menu {
  position: fixed;
  z-index: 3000;
  min-width: 196px;
  padding: 6px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 2px;
}

.vehicle-menu button {
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  background: transparent;
  color: var(--ink);
  font-weight: 600;
  border-radius: 8px;
}

.vehicle-menu button:hover { background: var(--blue-soft); }

.notice-stack {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 4500;
  display: grid;
  gap: 8px;
  width: min(380px, calc(100vw - 32px));
  pointer-events: none;
}

.notice {
  pointer-events: auto;
  display: grid;
  gap: 6px;
  padding: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.notice.waiting { border-color: var(--blue-line); }
.notice.ok { border-color: var(--notice-ok); }
.notice.bad { border-color: var(--notice-bad); }

.notice header {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}

.notice h3 { margin: 0; font-size: 0.92rem; }
.notice p { margin: 0; color: var(--muted); font-size: 0.84rem; }

.notice pre {
  margin: 0;
  max-height: 160px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font: 12px/1.4 ui-monospace, monospace;
  color: var(--ink);
}

.command-dialog {
  position: fixed;
  inset: 0;
  z-index: 4600;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--veil);
}

.command-card {
  width: min(440px, 100%);
  display: grid;
  gap: 12px;
  padding: 22px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.command-card h2 { margin: 0; font-size: 1.15rem; }

.user-card {
  width: min(520px, 100%);
  max-height: min(92vh, 760px);
  overflow: auto;
}

.user-profiles {
  display: grid;
  gap: 8px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
}

#userProfiles { display: flex; flex-wrap: wrap; gap: 8px 16px; }

.user-profiles legend { font-weight: 650; padding: 0 4px; }

#usersMain { min-width: 0; }
#usersMain tbody tr { cursor: default; }
#usersMain td.wrap { white-space: normal; max-width: 240px; }
#usersMain tr.muted-row td { color: var(--muted); }
#usersMain .user-meta { color: var(--muted); font-size: 0.78rem; font-weight: 500; }
.row-actions { display: flex; gap: 6px; }

.pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
}

.pill.ok { color: var(--ok); background: var(--ok-bg); }
.pill.bad { color: var(--sos); background: var(--sos-bg); }

html[data-theme="dark"] .leaflet-container {
  background: #111;
}

html[data-theme="dark"] .leaflet-tile-pane {
  filter: invert(100%) hue-rotate(180deg) brightness(95%) contrast(90%);
}

html[data-theme="dark"] .leaflet-bar a,
html[data-theme="dark"] .leaflet-control-attribution {
  background: var(--card);
  color: var(--ink);
  border-color: var(--line);
}

html[data-theme="dark"] .leaflet-bar a:hover,
html[data-theme="dark"] .leaflet-bar a:focus {
  background: var(--chip);
  color: var(--ink);
}

html[data-theme="dark"] .leaflet-control-attribution a {
  color: var(--blue-dark);
}

html[data-theme="dark"] .leaflet-popup-content-wrapper,
html[data-theme="dark"] .leaflet-popup-tip {
  background: var(--card);
  color: var(--ink);
}

html[data-theme="dark"] .leaflet-popup-content-wrapper {
  border: 1px solid var(--line);
  border-radius: 12px;
}

html[data-theme="dark"] .leaflet-container a.leaflet-popup-close-button {
  color: var(--muted);
}

html[data-theme="dark"] .leaflet-container a.leaflet-popup-close-button:hover {
  color: var(--ink);
}

@media (max-width: 860px) {
  .workspace { grid-template-columns: 1fr; grid-template-rows: minmax(180px, 1fr) minmax(0, 1fr); }
  .workspace.report-wide { grid-template-rows: minmax(0, 1fr); }
  .side { border-left: 0; border-top: 1px solid var(--line); }
  .map { min-height: 220px; }
  .multi-scale { margin-left: 112px; width: calc((100% - 112px) * 0.96); font-size: 0.68rem; }
  .multi-body { grid-template-columns: 112px 1fr; }
}
