:root {
  font-family: "Segoe UI", system-ui, sans-serif;
  background: #12141a;
  color: #e8eaef;
}
html {
  height: 100%;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
/* Main app only — no document-level scrollbar; inner panels scroll */
body.app-shell {
  height: 100%;
  min-height: 100%;
  overflow: hidden;
}
header {
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid #2a3040;
  flex-shrink: 0;
}
header h1 {
  margin: 0;
  font-size: 1.15rem;
}
.app-version {
  margin: 0.25rem 0 0;
  font-size: 0.75rem;
  color: #8b93a8;
  font-weight: normal;
}
.app-version strong {
  color: #c5cad6;
  font-weight: 600;
}
.hdr-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}
.hdr-auth {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}
.hdr-user {
  font-size: 0.82rem;
  max-width: 16rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.sub {
  margin: 0.25rem 0 0;
  font-size: 0.8rem;
  color: #9aa3b5;
}

.tab-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  border-bottom: 1px solid #2a3040;
  background: #161922;
  flex-shrink: 0;
}
.tab-btn {
  padding: 0.55rem 1rem;
  border: none;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: #9aa3b5;
  cursor: pointer;
  font-size: 0.88rem;
}
.tab-btn:hover {
  color: #e8eaef;
  background: #1e2433;
}
.tab-btn.active {
  color: #7eb8ff;
  border-bottom-color: #2d6cb5;
  background: #1a1f2e;
}

.tab-main {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  position: relative;
}
.tab-panel {
  display: none;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  padding: 0;
}
.tab-panel.active {
  display: flex;
}
.tab-panel > .panel-inner {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  overflow-x: hidden;
  overflow-y: auto;
}
.tab-panel > .panel-inner.flex-col {
  overflow: hidden;
}
/*
 * Config tab: natural height, no scrollbar.
 * Do not mix overflow-x: hidden with overflow-y: visible — per CSS, the other
 * axis becomes auto and shows a vertical scrollbar even when content fits.
 */
#tab-config > .panel-inner {
  flex: 0 1 auto;
  align-self: flex-start;
  width: 100%;
  overflow: hidden;
}
.panel-inner {
  padding: 1rem 1.25rem 1.5rem;
  max-width: 1280px;
}
.panel-inner.flex-col {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 280px;
}

.h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}
.head-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  margin-bottom: 1rem;
}
.head-row .h1 {
  margin-right: auto;
}
.kpi-key {
  font-size: 0.82rem;
  color: #9aa3b5;
}

label {
  display: block;
  font-size: 0.78rem;
  color: #9aa3b5;
  margin-top: 0.5rem;
}
input[type="text"],
input[type="password"] {
  width: 100%;
  max-width: 480px;
  padding: 0.45rem 0.6rem;
  border-radius: 6px;
  border: 1px solid #3d4558;
  background: #1a1f2e;
  color: inherit;
}
input.grow {
  flex: 1;
  min-width: 140px;
  max-width: none;
}
.row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.35rem;
  flex-wrap: wrap;
}
.row.end {
  justify-content: flex-end;
  margin-top: 0.75rem;
}
button {
  padding: 0.45rem 0.85rem;
  border-radius: 6px;
  border: 1px solid #4a5570;
  background: #2a3348;
  color: inherit;
  cursor: pointer;
  font-size: 0.88rem;
}
button:disabled,
button.cmd:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
button.cmd {
  background: #1e4d7a;
  border-color: #2d6cb5;
}

.state {
  font-size: 0.85rem;
  color: #c9b27a;
  margin: 0.5rem 0 0;
}
.state.mqtt {
  color: #8ecae6;
}
.state.mqtt.bad {
  color: #f77;
}
.state.mqtt.ok {
  color: #8f8;
}

.cards3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
}
.card {
  background: #1a1f2e;
  border: 1px solid #2f3548;
  border-radius: 10px;
  padding: 0.75rem 1rem;
}
.card h3 {
  margin: 0 0 0.65rem;
  font-size: 0.9rem;
  color: #b8c0d4;
}
table.kpi {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}
table.kpi td {
  padding: 0.28rem 0;
  vertical-align: top;
}
table.kpi td.k {
  color: #8b93a8;
  width: 42%;
  padding-right: 0.5rem;
}
table.kpi td.v {
  word-break: break-all;
  font-family: Consolas, "Courier New", monospace;
  color: #e8eaef;
}

/* Config tab: one full-width KPI table — avoid 42% label column (huge gap). */
#tab-config table.kpi td.k {
  width: 1%;
  max-width: none;
  white-space: nowrap;
  padding-right: 1rem;
  vertical-align: top;
}
#tab-config table.kpi td.v {
  width: auto;
}

.table-wrap {
  overflow: auto;
  border: 1px solid #2f3548;
  border-radius: 8px;
  max-height: min(58vh, 520px);
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}
.data-table th {
  background: #232838;
  padding: 0.45rem 0.5rem;
  text-align: left;
  position: sticky;
  top: 0;
  z-index: 1;
}
.data-table td {
  padding: 0.35rem 0.5rem;
  border-top: 1px solid #2a3040;
}
.data-table tbody tr:nth-child(even) {
  background: #151820;
}

.form-grid {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 0.5rem 0.75rem;
  align-items: center;
  margin-top: 0.5rem;
}
.form-grid label {
  margin: 0;
}
.form-grid input[type="text"] {
  max-width: none;
}

.mono-block,
pre#log {
  margin: 0.5rem 0 0;
  padding: 0.75rem;
  background: #0c0e12;
  border-radius: 8px;
  font-size: 0.75rem;
  line-height: 1.35;
  white-space: pre-wrap;
  word-break: break-all;
  border: 1px solid #2a3040;
  font-family: Consolas, "Courier New", monospace;
}
.log-grow {
  flex: 1;
  min-height: 200px;
  overflow: auto;
}
.panel-inner.flex-col .log-grow {
  min-height: 0;
}

/* Rounded scrollbars — Raw log & FOTA JSON box */
pre#log,
.fota-raw-scroll {
  scrollbar-width: thin;
  scrollbar-color: #4a5568 #161922;
}
pre#log::-webkit-scrollbar,
.fota-raw-scroll::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
pre#log::-webkit-scrollbar-track,
.fota-raw-scroll::-webkit-scrollbar-track {
  background: #161922;
  border-radius: 999px;
}
pre#log::-webkit-scrollbar-thumb,
.fota-raw-scroll::-webkit-scrollbar-thumb {
  background: #3d4a66;
  border-radius: 999px;
}
pre#log::-webkit-scrollbar-thumb:hover,
.fota-raw-scroll::-webkit-scrollbar-thumb:hover {
  background: #556178;
}
pre#log::-webkit-scrollbar-corner,
.fota-raw-scroll::-webkit-scrollbar-corner {
  background: transparent;
}

.sign-bad {
  color: #f66;
}

.muted {
  color: #9aa3b5;
  line-height: 1.5;
  max-width: 720px;
}

.connect-lead {
  margin: 0.35rem 0 1rem;
}
.connect-status {
  margin-top: 0.75rem;
  padding-top: 0.5rem;
  border-top: 1px solid #2a3040;
}
.connect-status .state:first-child {
  margin-top: 0;
}

.watch-history.card {
  margin-top: 1rem;
  padding: 0.65rem 0.85rem 0.75rem;
}
.watch-history-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.35rem;
  margin-bottom: 0.3rem;
}
.watch-history-title-wrap {
  min-width: 0;
  flex: 1 1 auto;
}
.watch-history-title {
  margin: 0;
  font-size: 0.86rem;
  font-weight: 600;
  line-height: 1.25;
}
.btn-text {
  border: none;
  background: transparent;
  color: #8b93a8;
  font-size: 0.8rem;
  cursor: pointer;
  padding: 0.25rem 0.35rem;
  border-radius: 4px;
}
.btn-text:hover {
  color: #e8eaef;
  background: #252a38;
}
.watch-history-remove-btn {
  margin-left: auto;
  flex-shrink: 0;
  align-self: flex-start;
  font-size: 0.76rem;
  line-height: 1.2;
  padding: 0.15rem 0.3rem;
}
.watch-history-empty {
  margin: 0;
  font-size: 0.76rem;
  line-height: 1.35;
}
.watch-history-list {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}
.watch-history-colhead {
  display: grid;
  gap: 0.28rem 0.42rem;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #8b93a8;
  /* Same padding + border box as .watch-history-row so columns (incl. checkbox) line up */
  padding: 0.32rem 0.55rem;
  border: 1px solid transparent;
  border-radius: 5px;
  box-sizing: border-box;
  line-height: 1.2;
}
.watch-history-colhead-prose {
  text-transform: none;
  letter-spacing: 0.02em;
}
.watch-history-colhead,
.watch-history-row {
  grid-template-columns:
    minmax(5.5rem, 1fr) minmax(3.2rem, 1fr) minmax(4.2rem, 1fr) minmax(6rem, 1fr) 2rem;
}
.watch-history-row {
  display: grid;
  gap: 0.28rem 0.42rem;
  align-items: center;
  width: 100%;
  margin: 0;
  padding: 0.32rem 0.55rem;
  text-align: left;
  font: inherit;
  font-size: 0.78rem;
  line-height: 1.25;
  color: #e8eaef;
  background: #1a1e2a;
  border: 1px solid #2a3040;
  border-radius: 5px;
  cursor: pointer;
}
.watch-h-col-sel,
.watch-h-sel {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  cursor: pointer;
}
.watch-h-col-sel input,
.watch-h-sel input {
  width: 0.9rem;
  height: 0.9rem;
  margin: 0;
  cursor: pointer;
  accent-color: #4a8fd8;
}
.watch-history-row:hover {
  border-color: #3d4d6b;
  background: #222836;
}
/* Dòng khớp IMEI trong ô Connect (đang Watch) — tô cả hàng */
.watch-history-row.watch-history-row--watching {
  background: #16261f;
  border-color: #3d8f66;
  box-shadow: inset 0 0 0 1px rgba(125, 206, 148, 0.2);
}
.watch-history-row.watch-history-row--watching:hover {
  background: #1a2e24;
  border-color: #47a072;
}
.watch-history-row.watch-history-row--watching .watch-h-imei,
.watch-history-row.watch-history-row--watching .watch-h-station,
.watch-history-row.watch-history-row--watching .watch-h-fw,
.watch-history-row.watch-history-row--watching .watch-h-ts {
  color: #8ee9a8;
}
/* Đã nhận DSTATUS (ký OK) — Last connected xanh (hàng không phải dòng đang watch) */
.watch-history-row.watch-row--dstatus-ok:not(.watch-history-row--watching) .watch-h-ts {
  color: #7dce94;
}
.watch-h-imei {
  font-variant-numeric: tabular-nums;
  word-break: break-all;
}
.watch-h-station {
  color: #b4bccf;
  text-transform: lowercase;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.watch-h-fw {
  font-size: 0.72rem;
  color: #c5cad6;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.watch-h-ts {
  font-size: 0.7rem;
  font-variant-numeric: tabular-nums;
  color: #9aa3b5;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
@media (max-width: 640px) {
  .watch-history-colhead,
  .watch-history-row {
    grid-template-columns: 1fr;
    gap: 0.2rem;
  }
  .watch-history-colhead,
  .watch-history-row {
    padding: 0.4rem 0.55rem;
  }
  .watch-h-ts,
  .watch-h-fw,
  .watch-h-station {
    white-space: normal;
    word-break: break-word;
  }
}

.statusbar {
  flex-shrink: 0;
  padding: 0.35rem 1.25rem;
  border-top: 1px solid #2a3040;
  background: #161922;
  font-size: 0.78rem;
  color: #9aa3b5;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}
.statusbar .sep {
  opacity: 0.5;
}
.statusbar-ver {
  margin-left: auto;
  opacity: 0.9;
  font-variant-numeric: tabular-nums;
}
#bar-ws.status-ok {
  color: #8f8;
}
#bar-ws.status-bad {
  color: #f77;
}
#bar-mqtt.status-ok {
  color: #8ecae6;
}
#bar-mqtt.status-bad {
  color: #f77;
}

/* FOTA: URL flexes; SHA fixed ~64 hex — avoids two equal “grow” slabs + empty right */
#tab-fota .fota-cmd-row {
  align-items: center;
}
#tab-fota .fota-sha-field {
  flex: 0 1 38rem;
  width: auto;
  min-width: min(14rem, 100%);
  max-width: min(38rem, 100%);
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.8rem;
}

/* FOTA dashboard */
.fota-panel-title {
  margin: 1.25rem 0 0.75rem;
  font-size: 1rem;
}
.fota-dashboard.card {
  padding: 1rem 1.1rem;
  margin-bottom: 0.75rem;
}
.fota-empty {
  margin: 0;
  padding: 0.35rem 0;
}
.fota-status-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  margin-bottom: 0.35rem;
}
.fota-state-badge {
  display: inline-block;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  background: #2a3040;
  color: #c5cad6;
}
.fota-state-badge.fota-state--success {
  background: #1e4d2a;
  color: #a8e6b0;
}
.fota-state-badge.fota-state--error {
  background: #4d1e24;
  color: #ffb4b4;
}
.fota-state-badge.fota-state--progress {
  background: #1a3a5c;
  color: #9fd4ff;
}
.fota-state-badge.fota-state--neutral {
  background: #2a3040;
  color: #9aa3b5;
}
.fota-state-label {
  font-size: 0.88rem;
  color: #b4bccf;
  flex: 1 1 12rem;
  min-width: 0;
}
.fota-state-label[hidden] {
  display: none !important;
}
.fota-msg {
  margin: 0 0 0.75rem;
  font-size: 0.82rem;
  line-height: 1.45;
}
.fota-msg[hidden] {
  display: none !important;
}
.fota-progress-wrap {
  margin-bottom: 1rem;
}
.fota-progress-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.35rem 0.75rem;
  font-size: 0.78rem;
  color: #9aa3b5;
  margin-bottom: 0.35rem;
}
.fota-p-text {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: #e8eaef;
}
.fota-bytes-text {
  font-variant-numeric: tabular-nums;
}
.fota-progress-track {
  height: 0.45rem;
  border-radius: 999px;
  background: #252a38;
  overflow: hidden;
}
.fota-progress-track.fota-progress-indeterminate {
  background: linear-gradient(90deg, #252a38, #3d4d6b, #252a38);
  background-size: 180% 100%;
  animation: fota-shimmer 1.4s linear infinite;
}
.fota-progress-track.fota-progress-indeterminate .fota-progress-bar {
  display: none;
}
@keyframes fota-shimmer {
  0% {
    background-position: 100% 0;
  }
  100% {
    background-position: -100% 0;
  }
}
.fota-progress-bar {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, #2a6a9e, #4a9fd8);
  transition: width 0.25s ease-out;
}
.fota-dl {
  margin: 0;
  display: grid;
  gap: 0.45rem 1rem;
  font-size: 0.82rem;
}
.fota-dl > div {
  display: grid;
  grid-template-columns: 10rem 1fr;
  gap: 0.5rem;
  align-items: start;
}
@media (max-width: 520px) {
  .fota-dl > div {
    grid-template-columns: 1fr;
  }
}
.fota-dl dt {
  margin: 0;
  color: #8b93a8;
  font-weight: 500;
}
.fota-dl dd {
  margin: 0;
  color: #e8eaef;
  word-break: break-word;
}
.fota-ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}
.fota-url {
  font-size: 0.75rem;
  color: #b4bccf;
}
.fota-raw-wrap {
  margin-top: 0.5rem;
  font-size: 0.85rem;
}
.fota-raw-wrap summary {
  cursor: pointer;
  color: #8b93a8;
  user-select: none;
}
.fota-raw-wrap summary:hover {
  color: #c5cad6;
}
.fota-raw-scroll {
  margin-top: 0.5rem;
  max-height: min(48vh, 22rem);
  overflow: auto;
  border: 1px solid #2a3040;
  border-radius: 8px;
  background: #0c0e12;
}
.fota-raw-scroll > pre#fota-last {
  margin: 0;
  border: none;
  border-radius: 0;
  max-height: none;
  overflow: visible;
}

/* rtu24fw admin tab */
.rtu24fw-hint {
  margin: 0 0 0.75rem;
  max-width: 56rem;
  line-height: 1.45;
  font-size: 0.85rem;
}
.rtu24fw-hint code {
  font-size: 0.8rem;
  word-break: break-all;
}
.rtu24fw-upload-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.35rem;
}
#rtu24fw-table .rtu24fw-url-cell {
  font-size: 0.75rem;
  max-width: 18rem;
  word-break: break-all;
}
#rtu24fw-table .btn-text {
  margin-right: 0.35rem;
}
