:root {
  color-scheme: dark;
  --bg: #0b1220;
  --surface: rgba(17, 24, 39, 0.92);
  --surface-strong: rgba(15, 23, 42, 0.98);
  --surface-soft: rgba(30, 41, 59, 0.72);
  --line: rgba(148, 163, 184, 0.22);
  --line-strong: rgba(203, 213, 225, 0.34);
  --text: #edf5ff;
  --muted: #9fb0c6;
  --quiet: #64748b;
  --green: #2dd4bf;
  --green-strong: #14b8a6;
  --blue: #38bdf8;
  --blue-strong: #0ea5e9;
  --amber: #f59e0b;
  --red: #ef4444;
  --shadow: 0 18px 46px rgba(0, 0, 0, 0.34);
}

body[data-theme="light"] {
  color-scheme: light;
  --bg: #eef3f8;
  --surface: rgba(255, 255, 255, 0.94);
  --surface-strong: rgba(248, 250, 252, 0.98);
  --surface-soft: rgba(226, 232, 240, 0.76);
  --line: rgba(71, 85, 105, 0.18);
  --line-strong: rgba(51, 65, 85, 0.32);
  --text: #132033;
  --muted: #52657d;
  --quiet: #7c8ca1;
  --shadow: 0 16px 36px rgba(15, 23, 42, 0.16);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  min-width: 1120px;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", Arial, Helvetica, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

button:hover {
  transform: translateY(-1px);
}

#container {
  min-height: 100vh;
  display: grid;
  grid-template-rows: 72px 1fr;
  background:
    linear-gradient(135deg, rgba(20, 184, 166, 0.12), transparent 34%),
    linear-gradient(315deg, rgba(56, 189, 248, 0.09), transparent 30%),
    var(--bg);
}

#topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 12px 18px 12px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(8, 13, 24, 0.94);
  backdrop-filter: blur(14px);
}

body[data-theme="light"] #topbar {
  background: rgba(255, 255, 255, 0.94);
}

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

.brand-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: linear-gradient(135deg, #14b8a6, #2563eb);
  box-shadow: 0 10px 22px rgba(20, 184, 166, 0.22);
  color: #fff;
  font-size: 20px;
  font-weight: 900;
}

.brand h1 {
  margin: 0;
  color: var(--text);
  font-size: 18px;
  font-weight: 800;
}

.brand p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.top-stats {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.top-chip,
.operator-chip {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.86);
  color: var(--text);
  padding: 0 12px;
}

button.top-chip {
  cursor: pointer;
}

.top-chip span {
  width: 9px;
  height: 9px;
  border-radius: 99px;
}

.top-chip strong {
  font-size: 18px;
}

.top-chip small,
.operator-chip span {
  color: var(--muted);
  font-size: 12px;
}

.top-chip.online span { background: var(--green); }
.top-chip.alert span { background: var(--amber); }
.top-chip.message span { background: var(--blue); }
.top-chip.task span { background: var(--green); }
.top-chip.theme span { background: var(--quiet); }
.top-chip.clickable:hover { border-color: rgba(56, 189, 248, 0.7); }

.operator-chip {
  min-width: 112px;
  justify-content: space-between;
}

.operator-chip strong {
  color: var(--text);
  font-size: 13px;
}

#workspace {
  height: calc(100vh - 72px);
  display: grid;
  grid-template-columns: 304px minmax(620px, 1fr) 364px;
  gap: 10px;
  padding: 10px;
  overflow: hidden;
}

#sidebar,
#opsPanel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}

#opsTabs {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
  flex: 0 0 auto;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(8, 19, 39, 0.94);
}

#opsTabs button {
  min-height: 38px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 7px;
  background: rgba(30, 41, 59, 0.82);
  color: #cbd5e1;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
}

#opsTabs button.active {
  border-color: rgba(45, 212, 191, 0.62);
  background: linear-gradient(135deg, #0f766e, #0ea5e9);
  color: #fff;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, var(--surface), var(--surface-strong));
  box-shadow: var(--shadow);
  padding: 14px;
  overflow: auto;
}

#sidebar .panel:first-child,
#opsPanel [data-ops-panel].active {
  flex: 1;
  min-height: 0;
}

#opsPanel [data-ops-panel] {
  display: none;
}

#opsPanel [data-ops-panel].active {
  display: block;
}

.panel.compact {
  flex: 0 0 auto;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel h2 {
  margin: 2px 0 0;
  color: var(--text);
  font-size: 14px;
  font-weight: 800;
}

.eyebrow {
  display: block;
  color: var(--green);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.panel-title button,
.tool-button,
.panel-actions button {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(30, 41, 59, 0.82);
  color: #dbeafe;
  padding: 8px 10px;
  cursor: pointer;
}

.panel-title button:hover,
.tool-button:hover,
.panel-actions button:hover {
  border-color: var(--line-strong);
  background: rgba(51, 65, 85, 0.92);
}

.panel-actions {
  display: flex;
  gap: 6px;
}

.fleet-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  margin-bottom: 12px;
}

.fleet-stats div {
  min-height: 68px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: rgba(15, 23, 42, 0.74);
}

.fleet-stats span {
  color: var(--muted);
  font-size: 11px;
}

.fleet-stats strong {
  color: var(--text);
  font-size: 25px;
  line-height: 1;
}

.fleet-stats .online { border-color: rgba(45, 212, 191, 0.45); }
.fleet-stats .alert { border-color: rgba(245, 158, 11, 0.48); }
.fleet-stats .offline { border-color: rgba(148, 163, 184, 0.24); }

#unitSearch,
.panel select,
.panel textarea,
.panel input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(2, 6, 23, 0.66);
  color: var(--text);
  padding: 10px 11px;
  outline: none;
}

#unitSearch:focus,
.panel select:focus,
.panel textarea:focus,
.panel input:focus {
  border-color: rgba(56, 189, 248, 0.75);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.13);
}

.panel label {
  display: block;
  margin: 10px 0 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

#listaUnidades {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
}

#listaUnidades li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 9px;
  min-height: 46px;
  margin: 0 0 7px;
  padding: 8px 9px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: rgba(30, 41, 59, 0.62);
  color: #e2e8f0;
  cursor: pointer;
}

#listaUnidades li:hover,
#listaUnidades li.selected {
  border-color: rgba(56, 189, 248, 0.42);
  background: rgba(14, 165, 233, 0.17);
}

.unit-avatar {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 7px;
  background: linear-gradient(135deg, var(--green-strong), #0284c7);
  color: #fff;
  font-size: 11px;
  font-weight: 900;
}

.unit-name {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  font-weight: 700;
}

.unit-name small {
  display: block;
  max-width: 138px;
  margin-top: 2px;
  overflow: hidden;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.unit-state {
  color: var(--muted);
  font-size: 12px;
}

.unit-state.online { color: var(--green); }
.unit-state.offline { color: #cbd5e1; }
#listaUnidades li.offline .unit-avatar { background: #475569; }

.history-replay {
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.history-replay summary {
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
}

.history-replay[open] summary {
  margin-bottom: 8px;
}

.history-replay .tool-button {
  width: 100%;
  margin-bottom: 8px;
}

#mapStage {
  position: relative;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: #0f172a;
  box-shadow: var(--shadow);
}

#map {
  width: 100%;
  height: 100%;
  filter: saturate(0.9) brightness(0.82) contrast(1.08);
}

body[data-theme="light"] #map {
  filter: saturate(1) brightness(1.02) contrast(0.98);
}

body[data-theme="light"] #mapStage::after {
  background:
    linear-gradient(180deg, rgba(248, 250, 252, 0.26), transparent 20%, transparent 78%, rgba(248, 250, 252, 0.32)),
    linear-gradient(90deg, rgba(248, 250, 252, 0.18), transparent 22%, transparent 78%, rgba(248, 250, 252, 0.16));
}

#mapStage::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(8, 13, 24, 0.58), transparent 22%, transparent 74%, rgba(8, 13, 24, 0.68)),
    linear-gradient(90deg, rgba(8, 13, 24, 0.34), transparent 22%, transparent 78%, rgba(8, 13, 24, 0.28));
  z-index: 420;
}

#mapStats,
#mapStatus,
#mapTools {
  position: absolute;
  z-index: 700;
}

#mapStats {
  top: 14px;
  left: 14px;
  display: grid;
  grid-template-columns: repeat(4, minmax(118px, 1fr));
  gap: 8px;
  width: min(660px, calc(100% - 28px));
}

.metric {
  min-width: 0;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  background: rgba(15, 23, 42, 0.82);
  backdrop-filter: blur(12px);
  color: var(--text);
}

button.metric {
  cursor: pointer;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  margin-top: 3px;
  color: var(--text);
  font-size: 28px;
  line-height: 1;
}

.metric small {
  display: block;
  margin-top: 5px;
  color: #cbd5e1;
  font-size: 11px;
}

.metric.online { border-color: rgba(45, 212, 191, 0.55); }
.metric.alert { border-color: rgba(245, 158, 11, 0.62); }
.metric.task { border-color: rgba(45, 212, 191, 0.58); }
.metric.message { border-color: rgba(56, 189, 248, 0.58); }
.metric.clickable:hover { background: rgba(14, 165, 233, 0.24); }

#mapStatus {
  left: 14px;
  right: 14px;
  bottom: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  pointer-events: none;
}

#mapStatus > div:first-child {
  min-width: 210px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.84);
  backdrop-filter: blur(12px);
  padding: 10px 12px;
}

#mapStatus span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

#mapStatus strong {
  display: block;
  margin-top: 2px;
  color: #fff;
  font-size: 14px;
}

.map-legend {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.84);
  backdrop-filter: blur(12px);
  padding: 10px 12px;
}

.map-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #dbeafe;
  font-size: 12px;
  white-space: nowrap;
}

.legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 99px;
}

.legend-dot.online { background: var(--green); }
.legend-dot.offline { background: #94a3b8; }
.legend-dot.alert { background: var(--red); }

#mapTools {
  top: 112px;
  right: 14px;
  display: flex;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.86);
  backdrop-filter: blur(12px);
}

#mapTools button {
  min-height: 38px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: #e2e8f0;
  padding: 0 13px;
  cursor: pointer;
  font-weight: 800;
}

#mapTools button:last-child {
  border-right: 0;
}

#mapTools button:hover {
  background: rgba(56, 189, 248, 0.18);
}

body[data-map-layer="satellite"] #map {
  filter: saturate(1.1) brightness(0.92) contrast(1.05);
}

body[data-map-layer="satellite"] #mapLayerToggle {
  background: rgba(14, 165, 233, 0.3);
  color: #fff;
}

.leaflet-control-container {
  position: relative;
  z-index: 720;
}

.leaflet-control-zoom a {
  background: rgba(15, 23, 42, 0.92) !important;
  border-color: var(--line) !important;
  color: #fff !important;
}

.leaflet-control-attribution {
  background: rgba(15, 23, 42, 0.72) !important;
  color: #cbd5e1 !important;
}

#unitDetail {
  color: #cbd5e1;
}

#unitDetail h3 {
  margin: 10px 0 4px;
  color: #fff;
  font-size: 24px;
}

#unitDetail p {
  margin: 0;
  color: var(--muted);
}

.unit-actions button.danger {
  border-color: rgba(244, 63, 94, 0.55);
  background: rgba(159, 18, 57, 0.22);
  color: #fecdd3;
}

.status-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(45, 212, 191, 0.14);
}

.status-dot.offline {
  background: #94a3b8;
  box-shadow: 0 0 0 4px rgba(148, 163, 184, 0.14);
}

.unit-detail-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.unit-detail-grid span {
  color: var(--muted);
  font-size: 12px;
}

.unit-detail-grid strong {
  margin-bottom: 8px;
  color: #e2e8f0;
  font-size: 13px;
}

.unit-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
}

.unit-actions button {
  border: 0;
  border-radius: 7px;
  color: #fff;
  padding: 10px;
  cursor: pointer;
}

.unit-actions button:first-child { background: #0f766e; }
.unit-actions button:last-child { background: #1d4ed8; }

.panel-action {
  width: 100%;
  margin-top: 10px;
  border: 0;
  border-radius: 8px;
  background: linear-gradient(135deg, #0284c7, #0ea5e9);
  color: #fff;
  padding: 12px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 10px 18px rgba(14, 165, 233, 0.18);
}

.panel-action.destination {
  background: linear-gradient(135deg, #0f766e, #14b8a6);
  box-shadow: 0 10px 18px rgba(20, 184, 166, 0.18);
}

.panel-action.secondary {
  background: #334155;
  box-shadow: none;
  padding: 9px;
}

.panel-action.ghost {
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid var(--line);
  box-shadow: none;
  color: #cbd5e1;
  padding: 9px;
}

.panel-action.secondary.active {
  background: var(--amber);
  color: #111827;
}

.panel-focus {
  outline: 2px solid rgba(56, 189, 248, 0.72);
}

#messagesPanel.active #messageList,
#tasksPanel.active #taskList {
  max-height: calc(100vh - 430px);
}

#map.picking-destination {
  cursor: crosshair;
}

#destinationCoords,
#destinationStatus,
#messageStatus,
#replyContext {
  min-height: 18px;
  margin-top: 6px;
  color: #a7f3d0;
  font-size: 12px;
}

#destinationCoords,
#replyContext {
  padding: 8px;
  border: 1px solid rgba(56, 189, 248, 0.16);
  border-radius: 7px;
  background: rgba(2, 8, 23, 0.62);
  color: #bae6fd;
}

#siteLiveStatus {
  padding: 9px;
  border: 1px solid rgba(56, 189, 248, 0.16);
  border-radius: 7px;
  background: rgba(2, 8, 23, 0.62);
  color: #bae6fd;
  font-size: 12px;
}

#siteLiveStatus strong,
#siteLiveStatus span,
#siteLiveStatus small {
  display: block;
}

#siteLiveStatus strong {
  color: #fff;
  font-size: 14px;
}

#siteLiveStatus small {
  margin-top: 4px;
  color: #fbbf24;
}

#siteLiveDetail {
  margin-top: 10px;
}

.site-live-head {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.86);
  border: 1px solid var(--line);
}

.site-live-head > span {
  width: 12px;
  height: 12px;
  border-radius: 999px;
  background: var(--red);
  box-shadow: 0 0 0 5px rgba(239, 68, 68, 0.12);
}

.site-live-head.online > span {
  background: var(--green);
  box-shadow: 0 0 0 5px rgba(45, 212, 191, 0.14);
}

.site-live-head strong,
.site-live-head small {
  display: block;
}

.site-live-head strong {
  color: #fff;
}

.site-live-head small {
  color: var(--muted);
  font-size: 12px;
}

.site-metric-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.site-metric-grid div {
  min-height: 62px;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid rgba(148, 163, 184, 0.16);
  background: rgba(15, 23, 42, 0.72);
}

.site-metric-grid span,
.site-metric-grid strong {
  display: block;
}

.site-metric-grid span {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  font-weight: 800;
}

.site-metric-grid strong {
  margin-top: 5px;
  color: #fff;
  font-size: 18px;
}

#sitePanel.active .site-metric-grid {
  gap: 10px;
}

#sitePanel.active .site-metric-grid div {
  min-height: 82px;
}

#sitePanel.active .site-metric-grid strong {
  font-size: 22px;
}

.site-series {
  display: grid;
  gap: 5px;
  margin-top: 10px;
  color: var(--muted);
}

.destination-pin {
  position: relative;
  width: 34px;
  height: 34px;
  border-radius: 50% 50% 50% 0;
  background: #0f766e;
  transform: rotate(-45deg);
  box-shadow: 0 0 0 5px rgba(15, 118, 110, 0.22);
}

.destination-pin span {
  position: absolute;
  width: 14px;
  height: 14px;
  top: 10px;
  left: 10px;
  border-radius: 50%;
  background: #fff;
}

#messageTray {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.message-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.message-tabs button {
  border: 0;
  border-radius: 7px;
  background: #334155;
  color: #fff;
  padding: 8px;
  cursor: pointer;
}

.message-tabs button.active {
  background: #0ea5e9;
  font-weight: 800;
}

#messageList {
  max-height: 220px;
  overflow-y: auto;
  padding-right: 4px;
}

.message-empty {
  padding: 10px 8px;
  color: var(--muted);
  font-size: 13px;
}

.message-item {
  margin-bottom: 8px;
  padding: 10px;
  border-radius: 7px;
  background: rgba(15, 23, 42, 0.92);
  cursor: pointer;
}

.message-item:hover {
  background: #172033;
}

.message-item.reply {
  border-left: 3px solid var(--green);
}

.message-item.sent {
  border-left: 3px solid var(--blue-strong);
}

.message-item strong {
  display: inline;
  margin: 0;
  color: #fff;
}

.message-item span {
  float: right;
  color: var(--muted);
  font-size: 11px;
}

.message-item p {
  clear: both;
  margin: 5px 0 0;
  color: #d1fae5;
  font-size: 13px;
}

.message-item.sent p {
  color: #dbeafe;
}

.message-delete {
  margin-top: 10px;
  border: 1px solid rgba(248, 113, 113, 0.45);
  border-radius: 7px;
  background: rgba(127, 29, 29, 0.2);
  color: #fecaca;
  padding: 7px 10px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
}

.message-delete:hover {
  background: rgba(185, 28, 28, 0.34);
  color: #fff;
}

.task-summary-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.task-summary-grid div,
.task-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.66);
  padding: 10px;
}

body[data-theme="light"] .task-summary-grid div,
body[data-theme="light"] .task-item {
  background: rgba(241, 245, 249, 0.86);
}

.task-summary-grid span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.task-summary-grid strong {
  display: block;
  margin-top: 4px;
  color: var(--text);
  font-size: 26px;
}

.task-item {
  margin-bottom: 9px;
}

.task-item-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.task-item-head strong {
  color: var(--text);
}

.task-item-head span {
  border-radius: 999px;
  background: rgba(45, 212, 191, 0.14);
  color: var(--green);
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 900;
}

.task-meta {
  display: grid;
  gap: 3px;
  margin-top: 8px;
}

.task-meta b {
  color: var(--text);
}

.task-meta small,
.task-item p {
  color: var(--muted);
}

.task-item p {
  margin: 8px 0 0;
  font-size: 13px;
}

.closed-report-timeline {
  display: grid;
  gap: 6px;
  margin-top: 10px;
}

.closed-report-timeline small {
  display: grid;
  grid-template-columns: 84px 1fr;
  gap: 8px;
  align-items: center;
  color: var(--muted);
}

.closed-report-timeline span {
  color: var(--cyan);
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
}

.closed-report-timeline b {
  color: var(--text);
  font-size: 11px;
}

.task-evidence-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 10px;
}

.task-evidence {
  min-height: 86px;
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: 8px;
  background: rgba(2, 8, 23, 0.42);
  color: var(--muted);
  padding: 8px;
  overflow: hidden;
}

button.task-evidence {
  width: 100%;
  cursor: pointer;
  text-align: left;
}

.task-evidence span,
.task-evidence strong {
  display: block;
}

.task-evidence span {
  color: var(--text);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.task-evidence strong {
  margin-top: 5px;
  font-size: 11px;
  color: var(--muted);
}

.task-evidence.ready {
  border-color: rgba(45, 212, 191, 0.55);
  background: rgba(20, 184, 166, 0.13);
}

.task-evidence.ready img {
  width: 100%;
  height: 48px;
  margin-top: 6px;
  display: block;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid rgba(255, 255, 255, 0.18);
}

.task-evidence.empty {
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.task-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.task-actions button {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(30, 41, 59, 0.82);
  color: #e2e8f0;
  padding: 9px;
  cursor: pointer;
}

.task-actions button:last-child {
  background: #0f766e;
  border-color: transparent;
  color: #fff;
  font-weight: 800;
}

.marker-container {
  position: relative;
  width: 50px;
  height: 50px;
  transform-origin: center center;
}

.label {
  position: absolute;
  top: -20px;
  left: 50%;
  transform: translateX(-50%);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 6px;
  background: rgba(15, 23, 42, 0.86);
  color: white;
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
  pointer-events: none;
}

.vehiculo {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.marker-img {
  position: absolute;
  width: 36px;
  height: 36px;
  left: 7px;
  top: 7px;
  z-index: 2;
  filter: drop-shadow(0 8px 10px rgba(0, 0, 0, 0.45));
}

.popup-custom {
  min-width: 120px;
  padding: 4px 6px;
  text-align: center;
  font-size: 12px;
}

.popup-custom .on {
  color: var(--green);
  font-weight: bold;
}

.popup-custom .off {
  color: #f87171;
  font-weight: bold;
}

.leaflet-popup-content-wrapper {
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.92);
  color: white;
  box-shadow: 0 16px 28px rgba(0, 0, 0, 0.35);
}

.leaflet-popup-tip {
  background: rgba(15, 23, 42, 0.92);
}

.wave {
  position: absolute;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  opacity: 0.6;
  animation: pulse 1.5s infinite;
  z-index: 1;
}

.wave.blue { border: 2px solid #00eaff; }
.wave.red { border: 2px solid #ff0033; }

@keyframes pulse {
  0% { transform: scale(0.5); opacity: 0.8; }
  100% { transform: scale(2); opacity: 0; }
}

.emergency-marker {
  position: relative;
  width: 84px;
  height: 84px;
}

.emergency-marker .emergency-ring {
  position: absolute;
  inset: 0;
  border: 3px solid rgba(220, 38, 38, 0.75);
  border-radius: 50%;
  animation: emergencyPulse 1.2s ease-out infinite;
}

.emergency-marker .emergency-ring:nth-child(2) { animation-delay: 0.35s; }
.emergency-marker .emergency-ring:nth-child(3) { animation-delay: 0.7s; }

.emergency-marker .emergency-core {
  position: absolute;
  left: 28px;
  top: 28px;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #dc2626;
  border: 4px solid white;
  box-shadow: 0 0 18px rgba(220, 38, 38, 0.9);
}

.emergency-marker .emergency-label {
  position: absolute;
  top: -18px;
  left: 50%;
  transform: translateX(-50%);
  background: #dc2626;
  color: white;
  font-size: 11px;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: 5px;
  white-space: nowrap;
}

.emergency-marker.operational-alert .emergency-ring {
  border-color: rgba(245, 158, 11, 0.78);
}

.emergency-marker.operational-alert .emergency-core {
  background: #f59e0b;
  box-shadow: 0 0 18px rgba(245, 158, 11, 0.9);
}

.emergency-marker.operational-alert .emergency-label {
  background: #f59e0b;
  color: #111827;
}

@keyframes emergencyPulse {
  0% { transform: scale(0.35); opacity: 0.95; }
  100% { transform: scale(1.45); opacity: 0; }
}

.unit-emergency {
  background: #dc2626 !important;
  color: white;
  font-weight: 800;
  animation: emergencyListBlink 0.9s ease-in-out infinite alternate;
}

.unit-emergency.unit-operational-alert {
  background: #92400e !important;
  animation: none;
}

@keyframes emergencyListBlink {
  from { box-shadow: inset 4px 0 0 #fca5a5; }
  to { box-shadow: inset 12px 0 0 #991b1b; }
}

.close-alert-btn {
  margin-top: 8px;
  border: 0;
  border-radius: 6px;
  background: #dc2626;
  color: white;
  font-weight: 800;
  padding: 7px 10px;
  cursor: pointer;
}

.close-alert-btn:hover {
  background: #991b1b;
}

#emergencyPanel {
  position: fixed;
  top: 86px;
  right: 18px;
  z-index: 5000;
  width: min(420px, calc(100vw - 36px));
  border: 2px solid #fecaca;
  border-radius: 8px;
  background: rgba(127, 29, 29, 0.96);
  color: white;
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.35);
  display: none;
  overflow: hidden;
}

#emergencyPanel.visible {
  display: block;
  animation: panelAlertPulse 1s ease-in-out infinite alternate;
}

#emergencyPanel.operational-alert {
  border-color: rgba(252, 211, 77, 0.9);
  background: rgba(120, 53, 15, 0.96);
}

#emergencyPanel.operational-alert.visible {
  animation: none;
}

.emergency-panel-header {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #dc2626;
  padding: 10px 12px;
  font-size: 14px;
}

.emergency-panel-header strong {
  flex: 1;
}

.emergency-panel-header span {
  min-width: 24px;
  height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 12px;
  background: white;
  color: #991b1b;
  font-weight: 800;
}

.emergency-panel-item {
  padding: 10px 12px;
  border-top: 1px solid rgba(254, 202, 202, 0.45);
}

.emergency-panel-item > button:first-child {
  text-align: left;
  border: 0;
  background: transparent;
  color: white;
  font-weight: 800;
  cursor: pointer;
}

.emergency-panel-item small {
  color: #fee2e2;
  font-weight: 400;
}

.silence-alert-btn {
  border: 0;
  border-radius: 6px;
  background: #7f1d1d;
  color: white;
  font-weight: 800;
  padding: 7px 9px;
  cursor: pointer;
}

.silence-alert-btn:hover {
  background: #450a0a;
}

#emergencyPanel.operational-alert .emergency-panel-header {
  background: #f59e0b;
  color: #111827;
}

#emergencyPanel.operational-alert .emergency-panel-header span {
  color: #92400e;
}

#emergencyPanel.operational-alert .emergency-panel-item {
  border-top-color: rgba(252, 211, 77, 0.45);
}

#emergencyPanel.operational-alert .emergency-panel-item small {
  color: #fde68a;
}

#emergencyPanel.operational-alert .silence-alert-btn {
  background: #92400e;
}

#emergencyPanel.operational-alert .silence-alert-btn:hover {
  background: #78350f;
}

#emergencyDock {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 5000;
  display: none;
  border: 0;
  border-radius: 8px;
  background: #dc2626;
  color: white;
  font-weight: 800;
  max-width: min(360px, calc(100vw - 48px));
  padding: 10px 14px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.28);
  cursor: pointer;
}

#emergencyDock.operational-alert {
  background: #f59e0b;
  color: #111827;
}

#emergencyDock.visible {
  display: block;
}

.emergency-popup span {
  display: block;
  max-width: 260px;
  margin: 4px 0;
  color: #fee2e2;
}

body[data-theme="light"] .top-chip,
body[data-theme="light"] .operator-chip,
body[data-theme="light"] .metric,
body[data-theme="light"] #mapStatus > div:first-child,
body[data-theme="light"] .map-legend,
body[data-theme="light"] #mapTools,
body[data-theme="light"] #opsTabs {
  background: rgba(255, 255, 255, 0.94);
  border-color: rgba(71, 85, 105, 0.22);
  color: #0f172a;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.12);
}

body[data-theme="light"] #opsTabs button {
  background: #e2e8f0;
  border-color: #cbd5e1;
  color: #0f172a;
}

body[data-theme="light"] #opsTabs button.active {
  background: linear-gradient(135deg, #0f766e, #0284c7);
  border-color: rgba(15, 118, 110, 0.35);
  color: #fff;
}

body[data-theme="light"] .top-chip strong,
body[data-theme="light"] .operator-chip strong,
body[data-theme="light"] .metric strong,
body[data-theme="light"] #mapStatus strong,
body[data-theme="light"] #unitDetail h3,
body[data-theme="light"] .unit-detail-grid strong,
body[data-theme="light"] .message-item strong {
  color: #0f172a;
}

body[data-theme="light"] .top-chip small,
body[data-theme="light"] .operator-chip span,
body[data-theme="light"] .metric span,
body[data-theme="light"] .metric small,
body[data-theme="light"] #mapStatus span,
body[data-theme="light"] .map-legend span,
body[data-theme="light"] #unitDetail,
body[data-theme="light"] #unitDetail p,
body[data-theme="light"] .unit-detail-grid span {
  color: #475569;
}

body[data-theme="light"] .panel-title button,
body[data-theme="light"] .tool-button,
body[data-theme="light"] .panel-actions button,
body[data-theme="light"] .panel-action.secondary,
body[data-theme="light"] .panel-action.ghost,
body[data-theme="light"] .message-tabs button,
body[data-theme="light"] .task-actions button {
  background: #e2e8f0;
  border-color: #cbd5e1;
  color: #0f172a;
}

body[data-theme="light"] .panel-title button:hover,
body[data-theme="light"] .tool-button:hover,
body[data-theme="light"] .panel-actions button:hover,
body[data-theme="light"] .panel-action.secondary:hover,
body[data-theme="light"] .panel-action.ghost:hover,
body[data-theme="light"] .task-actions button:hover {
  background: #cbd5e1;
}

body[data-theme="light"] #unitSearch,
body[data-theme="light"] .panel select,
body[data-theme="light"] .panel textarea,
body[data-theme="light"] .panel input,
body[data-theme="light"] #destinationCoords,
body[data-theme="light"] #replyContext,
body[data-theme="light"] #siteLiveStatus {
  background: #ffffff;
  border-color: #cbd5e1;
  color: #0f172a;
}

body[data-theme="light"] #unitSearch::placeholder,
body[data-theme="light"] .panel textarea::placeholder,
body[data-theme="light"] .panel input::placeholder {
  color: #64748b;
}

body[data-theme="light"] .fleet-stats div,
body[data-theme="light"] #listaUnidades li,
body[data-theme="light"] .message-item {
  background: #f8fafc;
  border-color: #d8e1ec;
  color: #0f172a;
}

body[data-theme="light"] #siteLiveStatus strong,
body[data-theme="light"] .site-live-head strong,
body[data-theme="light"] .site-metric-grid strong {
  color: #0f172a;
}

body[data-theme="light"] .site-live-head,
body[data-theme="light"] .site-metric-grid div {
  background: #f8fafc;
  border-color: #d8e1ec;
}

body[data-theme="light"] .site-live-head small,
body[data-theme="light"] .site-metric-grid span,
body[data-theme="light"] .site-series {
  color: #475569;
}

body[data-theme="light"] #listaUnidades li:hover,
body[data-theme="light"] #listaUnidades li.selected {
  background: #dbeafe;
  border-color: #38bdf8;
}

body[data-theme="light"] .unit-name {
  color: #102033;
}

body[data-theme="light"] .unit-state.offline {
  color: #64748b;
}

body[data-theme="light"] .message-item p,
body[data-theme="light"] .message-item.sent p {
  color: #334155;
}

body[data-theme="light"] .message-item.read {
  background: #ecfdf5;
  border-color: rgba(20, 184, 166, 0.45);
}

body[data-theme="light"] .leaflet-popup-content-wrapper,
body[data-theme="light"] .leaflet-popup-tip {
  background: #ffffff;
  color: #0f172a;
}

body[data-theme="light"] .leaflet-control-zoom a {
  background: #ffffff !important;
  color: #0f172a !important;
}

.read-state {
  display: block;
  clear: both;
  margin-top: 7px;
  font-size: 11px;
  font-weight: 800;
}

.read-state.pending {
  color: var(--amber);
}

.read-state.read {
  color: var(--green);
}

@keyframes panelAlertPulse {
  from { box-shadow: 0 18px 42px rgba(0, 0, 0, 0.35), 0 0 0 rgba(220, 38, 38, 0); }
  to { box-shadow: 0 18px 42px rgba(0, 0, 0, 0.35), 0 0 26px rgba(220, 38, 38, 0.75); }
}

@media (max-width: 1280px) {
  body {
    min-width: 1024px;
  }

  #workspace {
    grid-template-columns: 280px minmax(520px, 1fr) 330px;
  }

  #mapStats {
    grid-template-columns: repeat(4, minmax(102px, 1fr));
    width: min(540px, calc(100% - 28px));
  }

  .metric small {
    display: none;
  }
}
