body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  font-family: "Segoe UI", Tahoma, sans-serif;
  background: linear-gradient(135deg, #dbeafe 0%, #eff6ff 100%);
  color: #0f172a;
}

.card {
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 14px;
  width: min(1250px, 96vw);
  max-width: 96vw;
  padding: 20px 24px;
  box-shadow: 0 8px 24px rgba(2, 6, 23, 0.1);
  max-height: 90vh;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ── top bar ── */
.top-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.top-bar h1 {
  margin: 0;
  font-size: 24px;
  flex: 1;
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.top-bar h1 img {
  width: 32px;
  height: 32px;
  border-radius: 4px;
  flex-shrink: 0;
}

.top-bar-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

#dataTimeOutput {
  min-width: 190px;
}

#loadDataBtn {
  padding: 8px 16px;
  border: none;
  border-radius: 10px;
  background: #2563eb;
  color: #ffffff;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

#loadDataBtn:hover {
  background: #1d4ed8;
}

#loadDataBtn:disabled {
  background: #94a3b8;
  color: #e2e8f0;
  cursor: not-allowed;
  opacity: 0.8;
}

#autoUpdateBtn {
  padding: 8px 16px;
  border: none;
  border-radius: 10px;
  background: #16a34a;
  color: #ffffff;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

#autoUpdateBtn:hover {
  filter: brightness(0.9);
}

#autoUpdateBtn.stopped {
  background: #9ca3af;
}

#loadHistoricalBtn {
  padding: 8px 16px;
  border: none;
  border-radius: 10px;
  background: #0f766e;
  color: #ffffff;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

#loadHistoricalBtn:hover {
  background: #115e59;
}

/* ── data-time ── */
.data-time-box {
  box-sizing: border-box;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

#dataTimeText {
  font-family: "Courier New", Courier, monospace;
}

#status {
  max-width: 320px;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.75);
  color: #e2e8f0;
  font-size: 12px;
  line-height: 1.3;
  box-shadow: 0 8px 18px rgba(2, 6, 23, 0.25);
  margin: 0;
}

/* ── controls bar ── */
.controls-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.search-box {
  flex: 1;
  min-width: 180px;
  display: flex;
}

.search-filter-buttons {
  display: none;
}

.clear-search-btn {
  display: none;
}

.search-box input {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  background: #f8fafc;
  outline: none;
}

.search-box input:focus {
  border-color: #2563eb;
  background: #fff;
}

.pagination-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  flex-wrap: wrap;
}

.page-size-row,
.page-nav-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pagination-controls label {
  white-space: nowrap;
}

.pagination-controls select {
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 5px 8px;
  font-size: 12px;
  background: #ffffff;
}

.pagination-controls button {
  padding: 5px 10px;
  border: none;
  border-radius: 8px;
  background: #2563eb;
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  font-size: 12px;
  margin: 0;
}

.pagination-controls button:hover {
  background: #1d4ed8;
}

#pageInfo {
  min-width: 90px;
  text-align: center;
}

/* ── table ── */
.table-wrap {
  flex: 1;
  overflow: auto;
  min-height: 0;
  border-radius: 10px;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

th,
td {
  border: 1px solid #cbd5e1;
  padding: 7px 8px;
  text-align: left;
  vertical-align: top;
  word-break: break-word;
}

th {
  position: sticky;
  top: 0;
  background: #e2e8f0;
  font-weight: 700;
}

.empty-result {
  padding: 10px;
  font-size: 12px;
}

/* ── footer ── */
#totalCount {
  font-size: 12px;
  color: #64748b;
  margin: 0;
  text-align: right;
}

/* ── dots ── */
.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #9ca3af;
  flex-shrink: 0;
}

.dot--green-blink { background: #22c55e; animation: blink 1s infinite; }
.dot--green       { background: #16a34a; }
.dot--yellow      { background: #f59e0b; }
.dot--red         { background: #dc2626; }
.dot--neutral     { background: #9ca3af; }

@keyframes blink {
  0%   { opacity: 1; }
  50%  { opacity: 0.3; }
  100% { opacity: 1; }
}

.status-cell {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: 0 0 auto;
  background: #9ca3af;
}

.status-dot--green  { background: #16a34a; }
.status-dot--yellow { background: #f59e0b; }
.status-dot--red    { background: #dc2626; }
.status-dot--gray   { background: #9ca3af; }

.adapt-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #1d4ed8;
  color: #fff;
  border-radius: 4px;
  width: 22px;
  height: 22px;
  font-size: 15px;
  line-height: 1;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
}

.modal-overlay.open {
  display: flex;
}

.modal-card {
  width: min(92vw, 420px);
  background: #ffffff;
  border-radius: 12px;
  border: 1px solid #cbd5e1;
  box-shadow: 0 10px 30px rgba(2, 6, 23, 0.25);
  padding: 16px;
  display: grid;
  gap: 10px;
}

.modal-card h2 {
  margin: 0;
  font-size: 16px;
}

.modal-card p {
  margin: 0;
  font-size: 12px;
  color: #475569;
}

#historicalDateInput {
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
  background: #f8fafc;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.modal-actions button {
  padding: 7px 12px;
  border: none;
  border-radius: 8px;
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

#cancelHistoricalBtn {
  background: #64748b;
}

#confirmHistoricalBtn {
  background: #2563eb;
}

#bottomTooltips {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 1100;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-end;
  pointer-events: none;
}

#status,
#preloadTooltip {
  pointer-events: auto;
  cursor: pointer;
  transition: opacity 0.2s ease;
}

#status.chip-hidden,
#preloadTooltip.chip-hidden {
  display: none;
}

#preloadTooltip {
  max-width: 320px;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.9);
  color: #e2e8f0;
  font-size: 12px;
  line-height: 1.3;
  box-shadow: 0 8px 18px rgba(2, 6, 23, 0.25);
  overflow-wrap: anywhere;
}

#preloadTooltip.success {
  background: rgba(21, 128, 61, 0.9);
}

#preloadTooltip.error {
  background: rgba(153, 27, 27, 0.92);
}

@media (min-width: 769px) and (max-width: 1200px) {
  th.col-refresh,
  td.col-refresh,
  th.col-lat,
  td.col-lat,
  th.col-lon,
  td.col-lon {
    display: none;
  }
}

@media (min-width: 769px) and (max-width: 980px) {
  .top-bar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    column-gap: 8px;
    row-gap: 8px;
    align-items: center;
  }

  .top-bar h1 {
    min-width: 0;
  }

  #dataTimeOutput {
    justify-self: end;
  }

  .top-bar-right {
    grid-column: 1 / -1;
    width: 100%;
    flex-wrap: nowrap;
    gap: 6px;
  }

  #autoUpdateBtn,
  #loadHistoricalBtn,
  #loadDataBtn {
    padding: 7px 10px;
    font-size: 12px;
  }
}

@media (max-width: 768px) {
  body {
    min-height: 100dvh;
    place-items: stretch;
    padding: 8px;
    box-sizing: border-box;
  }

  .card {
    width: 100%;
    max-width: 100%;
    max-height: calc(100dvh - 16px);
    padding: 12px;
    gap: 8px;
  }

  .top-bar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    column-gap: 6px;
    row-gap: 6px;
    align-items: center;
  }

  .top-bar h1 {
    font-size: 18px;
    min-width: 0;
  }

  .top-bar-right {
    grid-column: 1 / -1;
    width: 100%;
    gap: 6px;
  }

  #dataTimeOutput {
    justify-self: end;
    min-width: 170px;
    max-width: 100%;
  }

  #loadDataBtn,
  #autoUpdateBtn,
  #loadHistoricalBtn {
    flex: 1 1 140px;
  }

  .data-time-box {
    align-items: center;
    flex-direction: row;
    flex-wrap: nowrap;
  }

  .controls-bar {
    align-items: stretch;
    flex-direction: column;
  }

  .search-box {
    min-width: 0;
    gap: 6px;
    align-items: center;
  }

  .search-box input {
    flex: 1;
    min-width: 0;
  }

  .clear-search-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    border: 1px solid #cbd5e1;
    background: #ffffff;
    color: #334155;
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 12px;
    line-height: 1;
    font-weight: 700;
    cursor: pointer;
  }

  .clear-search-btn:hover {
    border-color: #94a3b8;
    background: #f8fafc;
  }

  .search-filter-buttons {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex: 0 0 auto;
  }

  .search-filter-label {
    display: inline-flex;
    align-items: center;
    font-size: 14px;
    line-height: 1;
    margin: 0;
  }

  .search-filter-buttons button {
    border: 1px solid #cbd5e1;
    background: #ffffff;
    color: #334155;
    border-radius: 8px;
    padding: 6px 8px;
    font-size: 11px;
    line-height: 1;
    font-weight: 700;
    text-transform: lowercase;
    cursor: pointer;
  }

  .search-filter-buttons button.active {
    border-color: #2563eb;
    background: #2563eb;
    color: #ffffff;
  }

  .pagination-controls {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
  }

  .page-size-row {
    justify-content: space-between;
  }

  .table-wrap {
    border-radius: 8px;
  }

  .page-nav-row {
    flex-wrap: wrap;
    justify-content: space-between;
  }

  .page-nav-row #totalCount {
    flex: 0 0 100%;
    order: 1;
    text-align: left;
  }

  .page-nav-row #prevPageBtn {
    order: 2;
  }

  .page-nav-row #pageInfo {
    order: 3;
    flex: 1;
    min-width: 0;
  }

  .page-nav-row #nextPageBtn {
    order: 4;
  }

  table,
  tbody,
  tr,
  td {
    display: block;
    width: 100%;
  }

  thead {
    display: none;
  }

  tr {
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    background: #ffffff;
    margin: 0 0 8px;
    padding: 6px;
  }

  td {
    border: none;
    border-bottom: 1px solid #e2e8f0;
    padding: 5px 2px;
    display: grid;
    grid-template-columns: 82px 1fr;
    gap: 6px;
    align-items: center;
  }

  td:last-child {
    border-bottom: none;
  }

  td::before {
    content: attr(data-label);
    font-weight: 700;
    color: #334155;
    font-size: 11px;
    text-transform: uppercase;
  }

  th.col-refresh,
  td.col-refresh,
  th.col-lat,
  td.col-lat,
  th.col-lon,
  td.col-lon {
    display: none;
  }
}

@media (max-width: 560px) {
  .top-bar {
    grid-template-columns: 1fr;
  }

  #dataTimeOutput {
    grid-column: 1 / -1;
    justify-self: stretch;
    width: 100%;
  }
}