/* IoTCar v2 — giao diện theo BAT Ai Brand Kit v2.1
 * Nền trắng · đỏ #DA251D chỉ cho logo + điểm nhấn nhỏ · chữ đen #111 / xám #4A4A4A
 * Vàng #FFCD00 chỉ dành cho ngôi sao trong logo · font Montserrat · không gradient, không bóng đổ
 * Xanh/cam chỉ dùng làm chấm trạng thái (online / cảnh báo), không dùng cho chữ hay mảng màu.
 */
:root {
  color-scheme: light;
  --red: #DA251D;
  --red-press: #B91F18;
  --red-tint: #FDF1F0;
  --ink: #111111;
  --ink-2: #4A4A4A;
  --muted: #8C8C8C;
  --line: #E6E6E6;
  --line-2: #F0F0F0;
  --bg: #FFFFFF;
  --surface: #FAFAFA;
  --ok: #1E8E3E;
  --warn: #D97706;
  --radius: 6px;
  --font: "Montserrat", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}
* { box-sizing: border-box; }
html, body { background: var(--bg); }
body { margin: 0; color: var(--ink); font: 400 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
a { color: var(--red); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }

/* ---------- Nút ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: var(--radius); cursor: pointer;
  font-weight: 600; font-size: 13px; letter-spacing: .02em; white-space: nowrap;
  background: var(--bg); color: var(--ink); border: 1px solid var(--ink);
}
.btn:hover { background: var(--surface); }
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-red { background: var(--red); border-color: var(--red); color: #fff; }
.btn-red:hover { background: var(--red-press); border-color: var(--red-press); }
.btn-ghost { border-color: var(--line); color: var(--ink-2); }
.btn-ghost:hover { border-color: var(--ink-2); }
.btn-stop {
  height: 44px; padding: 0 22px; background: var(--red); border: 0; color: #fff;
  font-weight: 800; letter-spacing: .12em; text-transform: uppercase;
}
.btn-stop:hover { background: var(--red-press); }

input[type=password], input[type=number], input[type=datetime-local], select {
  height: 36px; padding: 0 10px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius);
}
input[type=password]:focus, input[type=number]:focus, select:focus, input[type=datetime-local]:focus { border-color: var(--ink-2); outline: none; }
input[type=number] { width: 68px; }
input[type=range] { width: 100%; accent-color: var(--red); }
input[type=checkbox] { accent-color: var(--red); width: 16px; height: 16px; }

/* ---------- Header ---------- */
.top { position: sticky; top: 0; z-index: 1000; background: var(--bg); }
.top-inner {
  max-width: 1440px; margin: 0 auto; padding: 14px 24px 12px;
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 18px; color: var(--ink); text-decoration: none; }
.brand:hover { text-decoration: none; }
.brand img { height: 34px; width: auto; display: block; }  /* ≈ 100 px ngang — đúng mức tối thiểu của logo số */
.brand-sep { width: 1px; height: 34px; background: var(--line); }
.brand-title { display: flex; flex-direction: column; gap: 2px; }
.brand-title b { font-size: 15px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }
.brand-title span { font-size: 10.5px; font-weight: 600; letter-spacing: .28em; text-transform: uppercase; color: var(--red); }
.nav { display: flex; gap: 4px; margin-left: 8px; }
.nav a {
  padding: 8px 12px; border-radius: var(--radius); color: var(--ink-2); font-weight: 600; font-size: 13px;
}
.nav a:hover { background: var(--surface); text-decoration: none; color: var(--ink); }
.nav a.active { color: var(--ink); box-shadow: inset 0 -2px 0 var(--red); border-radius: 0; }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.login { display: flex; gap: 8px; }
.login input { width: 150px; }
.authed { display: flex; align-items: center; gap: 10px; font-size: 13px; font-weight: 600; }

/* Vạch nhận diện: đoạn đỏ ngắn nối đường kẻ xám (như header ấn phẩm) */
.rule { max-width: 1440px; margin: 0 auto; padding: 0 24px; }
.rule div { height: 2px; background: linear-gradient(to right, var(--red) 0 120px, var(--line) 120px); }

/* ---------- Thanh trạng thái ---------- */
.pills { max-width: 1440px; margin: 0 auto; padding: 10px 24px 0; display: flex; flex-wrap: wrap; gap: 6px 18px; }
.pill { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #CFCFCF; flex: none; }
.pill.ok::before { background: var(--ok); }
.pill.warn::before { background: var(--warn); }
.pill.bad::before { background: var(--red); }
.pill.bad { color: var(--red); }

/* ---------- Bố cục ---------- */
.grid {
  max-width: 1440px; margin: 0 auto; padding: 18px 24px 32px; display: grid; gap: 20px;
  grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr); align-items: start;
}
.col { display: grid; gap: 20px; min-width: 0; }
.full { grid-column: 1 / -1; }

.card { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; min-width: 0; }
.sec-h { display: flex; align-items: baseline; gap: 10px; margin: 0 0 14px; flex-wrap: wrap; }
.sec-h .star { color: var(--red); font-size: 15px; line-height: 1; transform: translateY(1px); }
.sec-h h2 { margin: 0; font-size: 14px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
.sec-h .sub { font-size: 10.5px; font-weight: 600; letter-spacing: .22em; text-transform: uppercase; color: var(--red); }
.sec-h .right { margin-left: auto; display: flex; align-items: center; gap: 14px; font-size: 13px; }

/* ---------- Video ---------- */
.video-wrap { position: relative; background: var(--surface); border: 1px solid var(--line-2); border-radius: 4px; overflow: hidden; aspect-ratio: 4 / 3; }
#video { width: 100%; height: 100%; object-fit: contain; display: block; }
#video:not([src]) { visibility: hidden; }  /* chưa có ảnh: không hiện chữ alt / icon ảnh vỡ */
.nosignal {
  position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 24px;
  color: var(--ink-2); font-size: 13px; font-weight: 500; background: rgba(250, 250, 250, .88);
}
.nosignal::before { content: "★"; display: block; color: var(--red); font-size: 22px; margin-bottom: 6px; }
.hud {
  position: absolute; left: 10px; top: 10px; background: rgba(255,255,255,.92); color: var(--ink);
  padding: 4px 10px; border-radius: 4px; font: 500 12px/1.4 var(--mono); border: 1px solid var(--line);
}
.hud:empty { display: none; }
.paused {
  position: absolute; inset: 0; z-index: 2; display: grid; place-content: center; gap: 8px; text-align: center;
  background: rgba(255, 255, 255, .94); border: 0; cursor: pointer; padding: 24px; font: inherit; color: var(--ink-2);
}
.paused::before { content: "★"; color: var(--red); font-size: 24px; line-height: 1; }
.paused b { color: var(--ink); font-size: 15px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
.paused span { font-size: 13px; line-height: 1.6; }
.driver-badge {
  position: absolute; right: 10px; top: 10px; background: var(--red); color: #fff;
  padding: 5px 10px; border-radius: 4px; font-size: 11px; font-weight: 800; letter-spacing: .14em;
}

/* ---------- Điều khiển ---------- */
.ctrl { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line-2); }
.ctrl-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.ctrl-row + .ctrl-row, .ctrl-main + .ctrl-row { margin-top: 14px; }
.driver-info { font-size: 13px; color: var(--ink-2); font-weight: 500; }
.ctrl-main { display: flex; gap: 28px; align-items: center; flex-wrap: wrap; margin-top: 16px; }
.joy {
  width: 180px; height: 180px; border-radius: 50%; flex: none; position: relative; touch-action: none; cursor: grab;
  background: var(--surface); border: 1px solid var(--line);
}
.joy::before, .joy::after { content: ""; position: absolute; background: var(--line); }
.joy::before { left: 50%; top: 14px; bottom: 14px; width: 1px; }
.joy::after { top: 50%; left: 14px; right: 14px; height: 1px; }
.knob {
  width: 62px; height: 62px; border-radius: 50%; position: absolute; left: 59px; top: 59px; z-index: 1;
  background: var(--red); border: 4px solid #fff; outline: 1px solid var(--red); pointer-events: none;
}
.sliders { flex: 1; min-width: 240px; display: grid; gap: 12px; }
.field { display: block; font-size: 12px; font-weight: 600; letter-spacing: .04em; color: var(--ink-2); text-transform: uppercase; }
.field b { color: var(--ink); font-size: 13px; letter-spacing: 0; text-transform: none; margin-left: 4px; }
.field input[type=range] { display: block; margin-top: 6px; }
.chk { display: inline-flex; gap: 8px; align-items: center; font-size: 13px; font-weight: 500; color: var(--ink-2); cursor: pointer; }
.cam-row label { display: inline-flex; gap: 6px; align-items: center; font-size: 12px; font-weight: 600; color: var(--ink-2); }
.keys { margin: 14px 0 0; font-size: 12px; color: var(--muted); line-height: 1.7; }
.keys kbd {
  font: 600 11px var(--mono); color: var(--ink); background: var(--surface); border: 1px solid var(--line);
  border-bottom-width: 2px; border-radius: 4px; padding: 1px 5px;
}
.lockmsg { display: none; }
.ctrl.locked .ctrl-main, .ctrl.locked .cam-row, .ctrl.locked .keys { opacity: .35; pointer-events: none; }
.ctrl.locked .lockmsg {
  display: block; margin-top: 14px; padding: 10px 12px; border-left: 3px solid var(--red);
  background: var(--red-tint); color: var(--ink); font-size: 13px; font-weight: 500;
}

/* ---------- Bản đồ, bảng key-value, bảng cảm biến ---------- */
#map, #hmap { border-radius: 4px; border: 1px solid var(--line-2); background: var(--surface); }
#map { height: 300px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 0; margin-top: 4px; font-size: 13px; }
.kv .k, .kv .v { padding: 7px 0; border-bottom: 1px solid var(--line-2); }
.kv .k { color: var(--ink-2); font-weight: 500; padding-right: 16px; }
.kv .v { font-family: var(--mono); font-size: 12.5px; word-break: break-word; color: var(--ink); }
#gpsKv { margin-top: 10px; }
.table-wrap { max-height: 460px; overflow: auto; border: 1px solid var(--line-2); border-radius: 4px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--line-2); vertical-align: top; }
th {
  position: sticky; top: 0; background: var(--bg); color: var(--ink-2); z-index: 1;
  font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; border-bottom: 1px solid var(--line);
}
tbody tr:hover td { background: var(--surface); }
td.v { font-family: var(--mono); font-size: 12.5px; }
td .small { font-size: 11.5px; }

/* ---------- Chân trang ---------- */
.foot { border-top: 6px solid var(--red); margin-top: 8px; }
.foot-inner {
  max-width: 1440px; margin: 0 auto; padding: 14px 24px 18px; display: flex; gap: 16px; flex-wrap: wrap;
  justify-content: space-between; font-size: 11.5px; color: var(--ink-2);
}
.foot-inner b { color: var(--ink); font-weight: 700; letter-spacing: .04em; }
.foot-inner .slogan { color: var(--red); font-weight: 600; letter-spacing: .28em; }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 2000; max-width: calc(100% - 32px);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: var(--radius); font-size: 13px; font-weight: 500;
}

/* Leaflet theo bảng màu */
.leaflet-container { font-family: var(--font); }
.leaflet-bar a { color: var(--ink) !important; }

/* ---------- Trang lịch sử ---------- */
.hist { max-width: 1440px; margin: 0 auto; padding: 18px 24px 32px; display: grid; gap: 20px; }
.bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.bar label { display: inline-flex; gap: 8px; align-items: center; font-size: 12px; font-weight: 600; color: var(--ink-2); text-transform: uppercase; letter-spacing: .04em; }
.bar .sp { flex: 1; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.seg button { height: 34px; padding: 0 12px; border: 0; background: var(--bg); cursor: pointer; font-weight: 600; font-size: 12.5px; color: var(--ink-2); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button:hover { background: var(--surface); color: var(--ink); }
#hmap { height: 440px; }
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 20px; }
.chart-box { position: relative; height: 220px; }
pre.sample {
  margin: 0; white-space: pre-wrap; word-break: break-word; max-height: 380px; overflow: auto;
  font: 12px/1.5 var(--mono); background: var(--surface); border: 1px solid var(--line-2); border-radius: 4px; padding: 12px;
}

/* ---------- Màn hình nhỏ ---------- */
@media (max-width: 980px) {
  .grid { grid-template-columns: minmax(0, 1fr); padding: 14px 16px 24px; gap: 16px; }
  .col { gap: 16px; }
  .top-inner, .pills, .rule, .hist, .foot-inner { padding-left: 16px; padding-right: 16px; }
  .top-inner { gap: 12px; }
  .brand { gap: 12px; }
  .brand-title b { font-size: 13px; }
  .nav { margin-left: 0; order: 3; width: 100%; }
  .top-right { margin-left: 0; width: 100%; }
  .login { flex: 1; }
  .login input { flex: 1; width: auto; }
  .card { padding: 14px; }
  .ctrl-main { gap: 18px; justify-content: center; }
  .joy { width: 168px; height: 168px; }
  .knob { left: 53px; top: 53px; }
}
@media (max-width: 420px) {
  .brand-sep, .brand-title span { display: none; }
  .btn-stop { width: 100%; }
}
