:root {
  --red: #e30613;
  --ink: #37372d;
  --muted: #6b6a64;
  --line: #e4e2de;
  --bg: #f3f3f3;
  --card: #fff;
  --ok: #1f7a4d;
  --mid: #b86e00;
  --low: #e30613;
  --shadow: 0 10px 30px rgba(55, 55, 45, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Kanit, "Segoe UI", sans-serif;
  font-weight: 400;
}

.top {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 14px 22px 12px;
  background: #fff;
  border-bottom: 3px solid var(--red);
}

.brand img {
  display: block;
  height: 78px;
  width: auto;
}

.brand-name { flex: 1; }

.brand-name h1 {
  margin: 0;
  font-size: 32px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.02em;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--red);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

main {
  width: min(1040px, calc(100% - 32px));
  margin: 28px auto 48px;
}

.panel, .card {
  background: var(--card);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.panel {
  max-width: 460px;
  margin: 12px auto;
  padding: 28px 28px 22px;
}

h2 {
  margin: 0;
  font-size: 28px;
  font-weight: 600;
}

.lead, .muted {
  color: var(--muted);
  line-height: 1.45;
}

label {
  display: block;
  margin: 16px 0 6px;
  font-weight: 600;
}

input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid #d5d3ce;
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: 16px;
}

input:focus {
  outline: 2px solid var(--red);
  border-color: transparent;
}

button, .text-btn {
  font: inherit;
  cursor: pointer;
}

.primary, .secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 0 18px;
  border: 0;
  border-radius: 10px;
  font-weight: 600;
}

.primary {
  width: 100%;
  margin-top: 18px;
  background: var(--red);
  color: #fff;
}

.primary:disabled { opacity: 0.7; }

.secondary {
  margin-top: 16px;
  background: #fff;
  color: var(--ink);
  border: 1px solid #d5d3ce;
}

.text-btn {
  border: 0;
  background: transparent;
  color: var(--red);
  font-weight: 600;
}

.hint {
  margin-top: 22px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 14px;
}

.hint p { margin: 4px 0 10px; }

.account {
  display: flex;
  justify-content: space-between;
  width: 100%;
  margin-top: 8px;
  padding: 10px 12px;
  border: 1px solid #d5d3ce;
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  font-weight: 600;
  text-align: left;
}

.account span {
  color: var(--muted);
  font-weight: 400;
}

.account:hover { border-color: var(--red); }

.error {
  margin: 12px 0 0;
  color: var(--red);
  font-weight: 600;
}

.banner {
  margin: 0 0 16px;
  padding: 12px 14px;
  border-radius: 12px;
  background: #fff6e8;
  color: #6d4a10;
}

.identity {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 22px 24px;
}

.sim {
  margin: 0;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0.04em;
}

.grid {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 16px;
  margin-top: 16px;
}

.card { padding: 22px 24px; }

.battery-row {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 12px 0 8px;
}

.battery {
  display: flex;
  align-items: center;
}

.battery-body {
  width: 92px;
  height: 42px;
  padding: 4px;
  border: 3px solid var(--ink);
  border-radius: 8px;
}

.battery-fill {
  height: 100%;
  width: 0;
  border-radius: 3px;
  background: var(--ok);
}

.battery-fill.mid { background: var(--mid); }
.battery-fill.low { background: var(--low); }

.battery-cap {
  width: 6px;
  height: 16px;
  margin-left: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--ink);
}

.pct {
  margin: 0;
  font-size: 42px;
  font-weight: 600;
  line-height: 1;
}

.facts { margin: 8px 0 0; }

.facts div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; }

.map-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.map-head a {
  color: var(--red);
  font-weight: 600;
  text-decoration: none;
}

#map {
  height: 360px;
  margin-top: 10px;
  border-radius: 12px;
  background: #e7e5e1;
}

.gps-dot {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--red);
  background: #fff;
  color: var(--ink);
  font-family: Kanit, "Segoe UI", sans-serif;
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
}

.gps-dot.latest {
  background: var(--brand, var(--red));
  color: #fff;
}

.unit-card { padding-bottom: 10px; }

.unit-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  max-height: 420px;
  overflow: auto;
}

.unit {
  display: grid;
  width: 100%;
  gap: 2px;
  margin: 0 0 8px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  text-align: left;
  color: var(--ink);
}

.unit.selected { border-color: var(--red); background: #fff5f5; }
.unit.low .unit-battery { color: var(--low); }

.unit-name { font-weight: 600; }
.unit-meta { color: var(--muted); font-size: 14px; }

.unit-pin {
  display: grid;
  place-items: center;
  min-width: 46px;
  height: 26px;
  padding: 0 6px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-family: Kanit, "Segoe UI", sans-serif;
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
}

.unit-pin.selected { background: var(--red); }

#org-map {
  height: 460px;
  margin-top: 10px;
  border-radius: 12px;
  background: #e7e5e1;
}

body.org-mode {
  background: #eef3f1;
}

body.org-mode .top {
  background: #10211c;
  color: #fff;
  border-bottom-color: var(--brand);
}

body.org-mode .eyebrow,
body.org-mode .text-btn { color: #d5e4df; }

body.org-mode main { width: min(1180px, calc(100% - 28px)); }

.fleet-bar {
  display: flex;
  align-items: center;
  gap: 18px;
  margin: 18px 0 14px;
  padding: 18px 20px;
  border-radius: 18px;
  background: var(--brand);
  color: #fff;
}

.fleet-bar img {
  height: 54px;
  width: auto;
  max-width: 140px;
  object-fit: contain;
  background: #fff;
  border-radius: 10px;
  padding: 4px;
}

.fleet-title { flex: 1; }
.fleet-title h2 { margin: 0; font-size: 32px; font-weight: 600; }
.fleet-kicker { margin: 0; font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; opacity: 0.85; }
.fleet-title p { margin: 2px 0 0; }

.fleet-stats { display: flex; gap: 18px; }
.fleet-stats p { margin: 0; text-align: right; }
.fleet-stats span { display: block; font-size: 28px; font-weight: 600; line-height: 1; }
.fleet-stats small { font-size: 13px; }

.fleet-gear {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 50%;
  background: transparent;
  color: #fff;
}

.fleet-gear svg { width: 22px; height: 22px; }

.fleet-settings {
  display: grid;
  gap: 12px;
  margin-bottom: 14px;
  padding: 14px 16px;
  border-radius: 14px;
  background: #fff;
}

.rule-block {
  margin: 0;
  padding: 12px 0 0;
  border: 0;
  border-top: 1px solid var(--line);
}

.rule-block h3, .rule-switch { margin: 0 0 8px; font-size: 16px; font-weight: 600; }
.rule-switch { display: flex; align-items: center; gap: 8px; }
.rule-fields { display: flex; flex-wrap: wrap; gap: 12px 16px; }
.rule-fields label { display: grid; gap: 4px; font-size: 14px; font-weight: 400; }
.fleet-settings input[type="number"] { width: 84px; }
.rule-actions { display: flex; align-items: center; gap: 12px; }
.fleet-settings p { margin: 0; color: var(--muted); }
.rule-block.is-off .rule-fields { opacity: 0.45; }

.fleet-notices {
  margin-bottom: 14px;
  padding: 14px 16px;
  border-radius: 14px;
}

.fleet-warnings { background: #f4f7fb; border: 1px solid #d5deea; }
.fleet-warnings button { color: #24507a; }
.fleet-faults { background: #fff8ee; border: 1px solid #f0d7b0; }
.fleet-faults button { color: #8a4b00; }
.fleet-errors { background: #fff1f1; border: 1px solid #f0c2c2; }
.fleet-errors button { color: #9d1c1c; }

.fleet-notices h3 { margin: 0 0 8px; font-size: 16px; }
.fleet-notices ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.fleet-notices button {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 0;
  font: inherit;
}

.fleet-layout {
  display: grid;
  grid-template-columns: 1.15fr 0.85fr;
  gap: 14px;
}

.fleet-table-wrap, .fleet-map-card {
  background: #fff;
  border-radius: 16px;
  padding: 12px;
}

.fleet-table { width: 100%; border-collapse: collapse; }
.fleet-table th, .fleet-table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}
.fleet-table th { font-size: 13px; color: var(--muted); font-weight: 400; }
.fleet-table td small { display: block; color: var(--muted); font-size: 12px; }
.fleet-table tr { cursor: pointer; }
.fleet-table tr.selected { background: color-mix(in srgb, var(--brand) 12%, white); }
.fleet-table tr.warn td:last-child { color: #24507a; font-weight: 600; }
.fleet-table tr.alert td:last-child { color: #8a4b00; font-weight: 600; }
.fleet-table tr.error td:last-child { color: #9d1c1c; font-weight: 600; }
.fleet-table .soh-low { color: #8a4b00; font-weight: 600; }

.fleet-map-card #org-map { height: 420px; margin-top: 8px; }
#org-hint { margin: 8px 0 0; color: var(--muted); }

@media (max-width: 800px) {
  .top { align-items: flex-start; }
  .brand img { height: 58px; }
  .grid, .identity, .fleet-layout { grid-template-columns: 1fr; display: grid; }
  .fleet-bar { align-items: flex-start; flex-wrap: wrap; }
  .identity { display: grid; }
  #map, #org-map { height: 280px; }
}
