:root {
  color-scheme: light;
  font-family: Arial, Helvetica, sans-serif;
  background: #edf1f4;
  color: #17202a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: #edf1f4;
}

button,
input,
select {
  font: inherit;
}

.dashboard-shell {
  display: grid;
  gap: 12px;
  grid-template-rows: auto auto minmax(320px, 42vh);
  min-height: 100vh;
  padding: 14px;
}

.top-bar {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  min-width: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.1;
  margin: 0;
}

.top-bar p {
  color: #5d6975;
  font-size: 13px;
  margin: 5px 0 0;
}

.system-status {
  background: #dde5ed;
  border: 1px solid #bcc8d4;
  border-radius: 4px;
  color: #2e3a46;
  font-size: 13px;
  font-weight: 700;
  padding: 8px 10px;
  white-space: nowrap;
}

.system-status.ok {
  background: #ddf3e4;
  border-color: #9fd3b2;
  color: #176235;
}

.system-status.warn,
.system-status.error {
  background: #fff0d9;
  border-color: #e2b569;
  color: #8a4a08;
}

.live-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr;
  min-height: 0;
}

.live-group {
  min-width: 0;
}

.live-group > h2 {
  color: #2f3b47;
  font-size: 15px;
  margin: 0 0 8px;
}

.live-group-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
}

.live-card {
  background: white;
  border: 1px solid #ced7df;
  border-left: 5px solid #155e75;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 178px;
  overflow: hidden;
  padding: 12px 14px 10px;
}

.live-card.error {
  border-left-color: #b45309;
}

.card-header {
  align-items: start;
  display: flex;
  gap: 10px;
  justify-content: space-between;
}

h2,
h3 {
  font-size: 17px;
  line-height: 1.2;
  margin: 0;
}

.card-header p {
  color: #687583;
  font-size: 12px;
  margin: 4px 0 0;
}

.card-header strong {
  background: #e8f3f6;
  border-radius: 4px;
  color: #155e75;
  font-size: 12px;
  padding: 5px 7px;
  white-space: nowrap;
}

.live-card.error .card-header strong {
  background: #fff0d9;
  color: #8a4a08;
}

.reading-tile,
.error-tile {
  background: #f6f8fa;
  border: 1px solid #dde4eb;
  border-radius: 5px;
  min-height: 76px;
  margin-top: 12px;
  padding: 10px 12px;
}

.reading-tile span,
.error-tile span {
  color: #5d6975;
  display: block;
  font-size: 12px;
}

.reading-tile b {
  align-items: baseline;
  display: flex;
  flex-wrap: nowrap;
  font-size: clamp(24px, 2.8vw, 34px);
  gap: 6px;
  line-height: 1;
  white-space: nowrap;
}

.reading-tile small {
  color: #4c5965;
  display: inline;
  font-size: 0.45em;
  font-weight: 700;
  line-height: 1;
  margin-top: 0;
}

.error-tile b {
  color: #8a4a08;
  display: block;
  font-size: 22px;
  margin-bottom: 6px;
}

.live-card footer {
  color: #687583;
  display: flex;
  font-size: 12px;
  gap: 8px;
  justify-content: space-between;
  margin-top: auto;
  padding-top: 8px;
  white-space: normal;
}

.live-card footer span:first-child {
  flex: 1 1 auto;
  min-width: 0;
}

.live-card footer span:last-child {
  flex: 0 0 auto;
  white-space: nowrap;
}

.history-panel {
  background: white;
  border: 1px solid #ced7df;
  border-radius: 6px;
  display: grid;
  gap: 10px;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  max-height: 42vh;
  padding: 12px;
}

.history-controls {
  align-items: end;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(160px, 1.1fr) minmax(170px, 1fr) minmax(170px, 1fr) minmax(120px, 0.7fr) auto;
}

label {
  color: #3e4a56;
  display: block;
  font-size: 12px;
  font-weight: 700;
}

input,
select {
  background: white;
  border: 1px solid #b7c2cc;
  border-radius: 4px;
  color: #17202a;
  display: block;
  margin-top: 5px;
  min-height: 36px;
  padding: 7px 8px;
  width: 100%;
}

button {
  background: #155e75;
  border: 1px solid #155e75;
  border-radius: 4px;
  color: white;
  cursor: pointer;
  font-weight: 700;
  min-height: 36px;
  padding: 8px 14px;
}

button:disabled {
  cursor: default;
  opacity: 0.55;
}

.history-content {
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(300px, 0.9fr) minmax(360px, 1.1fr);
  min-height: 0;
}

.chart-wrap {
  border: 1px solid #dde4eb;
  border-radius: 5px;
  height: 240px;
  min-height: 0;
  overflow: hidden;
}

svg {
  display: block;
  height: 100%;
  min-height: 0;
  width: 100%;
}

svg line {
  stroke: #a8b4bf;
  stroke-width: 1;
}

svg .grid-line {
  stroke: #e4e9ee;
  stroke-width: 1;
}

svg text {
  fill: #5d6975;
  font-size: 12px;
}

.table-window {
  border: 1px solid #dde4eb;
  border-radius: 5px;
  min-height: 0;
  overflow: auto;
}

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

th,
td {
  border-bottom: 1px solid #e6ebef;
  padding: 8px 9px;
  text-align: left;
  white-space: nowrap;
}

th {
  background: #f1f5f8;
  position: sticky;
  top: 0;
  z-index: 1;
}

@media (max-width: 980px) {
  .dashboard-shell {
    grid-template-rows: auto auto auto;
    height: auto;
    min-height: 100vh;
  }

  .live-grid,
  .history-content,
  .history-controls {
    grid-template-columns: 1fr;
  }

  .live-card {
    min-height: 190px;
  }

  .history-panel {
    max-height: none;
  }

  .history-content {
    grid-template-rows: 260px 320px;
  }

  .chart-wrap {
    height: 260px;
  }

  .table-window {
    max-height: 320px;
  }
}

@media (min-width: 1400px) {
  .live-group-grid {
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  }
}

/* Unavailable sensors retain their place without displaying invalid measurements. */
.live-card.placeholder { border-left-color: #a8b4bf; }
.live-card.placeholder .card-header strong { background: #edf1f4; color: #687583; }
.live-card.placeholder .reading-tile b { color: #8a959f; }
.history-message { margin: 0; color: #687583; font-size: 12px; }
@media (max-width: 360px) { .live-group-grid { grid-template-columns: minmax(0, 1fr); } }
