:root {
  --ink: #102029;
  --muted: #65737e;
  --line: #dce6e2;
  --paper: #ffffff;
  --soft: #f4f8f6;
  --teal: #00856f;
  --green: #5cb85c;
  --amber: #b7791f;
  --red: #b42318;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  color: var(--ink);
  background: #f6faf8;
  font-family: Inter, Arial, sans-serif;
}

.login-shell {
  position: relative;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  overflow: hidden;
  background: #173f47;
}

.login-shell::before {
  content: "";
  position: absolute;
  inset: -14px;
  background:
    linear-gradient(90deg, rgba(8, 31, 38, 0.24), rgba(8, 31, 38, 0.02)),
    url("/ushuaia-login-bg.png") center / cover no-repeat;
  filter: blur(3px) saturate(1.15) contrast(1.06);
  transform: scale(1.012);
}

.login-shell::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 39% 49%, rgba(255,255,255,.18), transparent 30%),
    linear-gradient(180deg, rgba(255,255,255,.04), rgba(0,46,48,.16));
}

.login-card {
  position: relative;
  z-index: 1;
  width: min(380px, 100%);
  padding: 28px;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.58);
  border-radius: 8px;
  box-shadow: 0 26px 80px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(14px);
}

.login-card img { width: 230px; max-width: 100%; margin-bottom: 18px; display: block; }
.eyebrow {
  margin: 0;
  color: var(--teal);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}
h1, h2, p { margin-top: 0; }
.login-card h1 { margin: 6px 0 22px; font-size: 24px; }
.login-copy {
  margin: -12px 0 20px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}
label { display: block; margin-bottom: 8px; font-size: 12px; font-weight: 800; color: var(--muted); }
input, select {
  width: 100%;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  font: inherit;
  font-weight: 700;
  background: var(--soft);
}
button {
  border: 0;
  border-radius: 8px;
  height: 42px;
  padding: 0 14px;
  font: inherit;
  font-size: 12px;
  font-weight: 900;
  cursor: pointer;
}
button:hover { filter: brightness(.98); }
.login-card button { width: 100%; margin-top: 14px; color: white; background: var(--teal); }
.error, .message { min-height: 18px; color: #a33b24; font-size: 12px; font-weight: 800; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,0.96);
}
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand img { height: 48px; max-width: 250px; object-fit: contain; }
.brand .divider { width: 1px; height: 32px; background: var(--line); }
.brand span { display: block; font-size: 10px; font-weight: 900; color: #8a969f; text-transform: uppercase; }
.brand strong { display: block; font-size: 14px; }
nav { display: flex; gap: 6px; overflow-x: auto; }
.tab, .ghost { background: transparent; color: var(--muted); white-space: nowrap; }
.tab.active { color: var(--ink); background: #e9f1ee; }
.ghost { border: 1px solid var(--line); }

.page-head {
  max-width: 1260px;
  margin: 0 auto;
  padding: 22px 18px 14px;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: end;
}
.page-head.compact { padding-top: 18px; }
.page-head h1 { margin: 4px 0 4px; font-size: 28px; }
.page-head p:last-child { color: var(--muted); font-size: 13px; font-weight: 600; }
.badges { display: flex; gap: 8px; flex-wrap: wrap; justify-content: end; }
.badges span {
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}
.badges .ok { color: white; background: var(--green); border-color: var(--green); }
.badges .warn { color: var(--amber); background: #fff7e6; border-color: #f2d69a; }
.badges .danger { color: white; background: var(--red); border-color: var(--red); }

.grid {
  max-width: 1260px;
  margin: 0 auto;
  padding: 0 18px 28px;
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 16px;
}
.history-grid {
  max-width: 1260px;
  margin: 0 auto;
  padding: 0 18px 28px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 16px;
}
.panel, .metrics article, .map-panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(16, 32, 41, 0.06);
}
.panel { padding: 16px; margin-bottom: 14px; }
.panel-title {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin-bottom: 12px;
}
.panel-title h2,
.panel-title > span:first-child {
  margin: 0;
  font-size: 13px;
  text-transform: uppercase;
  color: var(--ink);
  font-weight: 900;
}
.panel-title span:last-child {
  padding: 6px 8px;
  border-radius: 999px;
  background: #eef5f2;
  color: var(--muted);
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
}
.telemetry-panel { margin-top: 14px; }
.telemetry-panel summary { cursor: pointer; list-style: none; }
.telemetry-panel summary::-webkit-details-marker { display: none; }
.telemetry-panel:not([open]) { margin-bottom: 14px; }
.telemetry-panel:not([open]) .panel-title { margin-bottom: 0; }
.telemetry-panel dl {
  display: grid;
  grid-template-columns: minmax(105px, .9fr) minmax(0, 1.1fr);
  gap: 0;
  max-height: 360px;
  overflow: auto;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.telemetry-panel dt,
.telemetry-panel dd {
  margin: 0;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  font-size: 11px;
}
.telemetry-panel dt {
  color: #74828a;
  background: #f5faf7;
  font-weight: 900;
  text-transform: uppercase;
}
.telemetry-panel dd {
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 800;
}
.vehicle-card { display: flex; gap: 12px; align-items: center; }
.car-icon {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #e5f4ee;
  color: var(--teal);
  font-size: 24px;
}
.vehicle-card h2 { margin: 0 0 4px; font-size: 15px; }
.vehicle-card p { margin: 0; color: #8a969f; font-size: 12px; font-weight: 800; }
.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.metrics.vertical { grid-template-columns: 1fr; margin-bottom: 14px; }
.metrics article { min-height: 82px; padding: 13px; }
.metrics article.wide-metric { grid-column: 1 / -1; }
.metrics span { display: block; color: #8a969f; font-size: 10px; font-weight: 900; text-transform: uppercase; }
.metrics strong { display: block; margin-top: 10px; font-size: 16px; }

.map-panel { overflow: hidden; }
.map-head {
  min-height: 64px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}
.map-head h2 { margin: 0; font-size: 13px; text-transform: uppercase; }
.map-head p { margin: 3px 0 0; color: #8a969f; font-size: 12px; font-weight: 700; }
.map-head span { padding: 7px 10px; background: #eef3f1; border-radius: 999px; font-size: 11px; font-weight: 900; color: var(--muted); }
.map {
  position: relative;
  min-height: 620px;
  background: #dbe9e4;
  overflow: hidden;
}
.history-map { min-height: 560px; }
.leaflet-map {
  position: absolute;
  inset: 0;
  z-index: 0;
}
.leaflet-map + .map-grid { display: none; }
.map-grid {
  position: absolute;
  inset: -40px;
  background-image:
    linear-gradient(rgba(255,255,255,.6) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.6) 1px, transparent 1px);
  background-size: 44px 44px;
  transform: rotate(-4deg) scale(1.1);
}
.empty-map {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  gap: 8px;
  color: #51636d;
  pointer-events: none;
  z-index: 1;
}
.empty-map strong { font-size: 18px; }
.empty-map span { font-size: 13px; font-weight: 700; }
.marker {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: grid;
  gap: 8px;
  justify-items: center;
}
.marker span {
  width: 28px;
  height: 28px;
  border: 6px solid white;
  border-radius: 50% 50% 50% 0;
  background: var(--teal);
  transform: rotate(-45deg);
  box-shadow: 0 10px 20px rgba(0,0,0,.18);
}
.marker strong {
  padding: 7px 10px;
  border-radius: 8px;
  background: white;
  font-size: 12px;
  box-shadow: 0 10px 20px rgba(0,0,0,.12);
}

.history-actions {
  display: grid;
  grid-template-columns: 170px 170px auto auto auto;
  gap: 8px;
  align-items: end;
}
.history-actions input { height: 42px; background: var(--paper); }
.history-actions button:not(.ghost) { color: white; background: var(--teal); }
.table-panel h2 {
  margin: 0 0 12px;
  font-size: 13px;
  text-transform: uppercase;
}
.table-wrap {
  max-height: 350px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
th, td {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}
th {
  position: sticky;
  top: 0;
  background: #eef5f2;
  color: #55656d;
  font-size: 10px;
  text-transform: uppercase;
}
td a { color: var(--teal); font-weight: 800; text-decoration: none; }
.cards-row {
  max-width: 1260px;
  margin: 0 auto;
  padding: 0 18px 28px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}
.info-card {
  min-height: 160px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: 0 8px 24px rgba(16, 32, 41, 0.06);
}
.info-card span {
  color: var(--teal);
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
}
.info-card strong {
  display: block;
  margin-top: 10px;
  font-size: 20px;
}
.info-card p {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}
.info-card.good { border-color: #bfe2cf; background: #f1faf5; }
.info-card.attention { border-color: #f0d39d; background: #fff8ea; }

@media (max-width: 880px) {
  .topbar, .page-head { align-items: flex-start; flex-direction: column; }
  .brand .divider, .brand div:last-child { display: none; }
  .grid, .history-grid, .cards-row { grid-template-columns: 1fr; }
  .history-actions { grid-template-columns: 1fr 1fr; width: 100%; }
  .map { min-height: 480px; }
}
