/* ─────────── Reset i bazowe ─────────── */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: #111418;
  color: #e5e7eb;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.4;
}
a { color: #60a5fa; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─────────── Nagłówek ─────────── */
header {
  background: #1a1f25;
  padding: 12px 16px;
  border-bottom: 1px solid #2a2f36;
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand {
  font-size: 20px;
  font-weight: 600;
  color: #f3f4f6;
  margin-bottom: 8px;
}
nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
nav a {
  padding: 6px 14px;
  background: #232930;
  border-radius: 6px;
  color: #cbd5e1;
  font-size: 14px;
}
nav a.active {
  background: #3b82f6;
  color: white;
}
nav a:hover { text-decoration: none; background: #2d343d; }
nav a.active:hover { background: #2563eb; }

/* ─────────── Główny kontener ─────────── */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 16px;
}

/* ─────────── Sekcje ─────────── */
.sec {
  margin-bottom: 32px;
}
.sec h2 {
  font-size: 18px;
  font-weight: 600;
  margin: 0 0 12px 0;
  color: #f3f4f6;
  border-left: 3px solid #3b82f6;
  padding-left: 10px;
}

/* ─────────── Kafelki ─────────── */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 12px;
}
.tile {
  display: block;
  background: #1a1f25;
  border: 1px solid #2a2f36;
  border-radius: 8px;
  padding: 12px;
  color: inherit;
  transition: border-color 0.15s;
}
.tile:hover { border-color: #3b82f6; text-decoration: none; }
.tile.ok  { border-left: 4px solid #22c55e; }
.tile.err { border-left: 4px solid #ef4444; }

.tile-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid #2a2f36;
}
.dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: #22c55e;
  flex-shrink: 0;
}
.tile.err .dot { background: #ef4444; }
.tile-title {
  font-weight: 600;
  flex: 1;
  color: #f3f4f6;
}
.tile-time {
  font-size: 12px;
  color: #6b7280;
}

.tile-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
.tile-table tr { border-bottom: 1px solid #232930; }
.tile-table tr:last-child { border-bottom: none; }
.tile-table td { padding: 4px 0; }
.meas-name { color: #9ca3af; }
.meas-value {
  text-align: right;
  color: #f3f4f6;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}
.unit {
  color: #6b7280;
  font-weight: 400;
  font-size: 12px;
  margin-left: 2px;
}

/* ─────────── Widok urządzenia ─────────── */
.object-table {
  width: 100%;
  border-collapse: collapse;
  background: #1a1f25;
  border-radius: 8px;
  overflow: hidden;
}
.object-table th, .object-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid #2a2f36;
}
.object-table th {
  background: #232930;
  font-weight: 600;
  color: #9ca3af;
  font-size: 13px;
  text-transform: uppercase;
}
.object-table td.meas-value { text-align: right; }
.object-table td.meas-time {
  color: #6b7280;
  font-size: 13px;
  text-align: right;
}

/* ─────────── Wykresy ─────────── */
.chart-block {
  background: #1a1f25;
  border: 1px solid #2a2f36;
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 16px;
}
.chart-block h3 {
  margin: 0 0 8px 0;
  font-size: 15px;
  font-weight: 600;
  color: #e5e7eb;
}
.chart-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}
.chart-controls button {
  background: #232930;
  border: 1px solid #2a2f36;
  color: #cbd5e1;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
}
.chart-controls button:hover { background: #2d343d; }
.chart-controls button.active {
  background: #3b82f6;
  border-color: #3b82f6;
  color: white;
}

.chart {
  width: 100%;
  min-height: 360px;
}
.chart-empty {
  color: #6b7280;
  text-align: center;
  padding: 40px 0;
  font-style: italic;
}

/* Legenda z checkboxami pod wykresem */
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid #2a2f36;
}
.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 13px;
  color: #cbd5e1;
  user-select: none;
}
.legend-item input { cursor: pointer; }
.legend-dot {
  width: 10px; height: 10px;
  border-radius: 2px;
  display: inline-block;
}

/* ─────────── Komunikaty ─────────── */
.loading, .error {
  text-align: center;
  padding: 40px 20px;
  color: #9ca3af;
}
.error { color: #ef4444; }

/* ─────────── Mobile ─────────── */
@media (max-width: 600px) {
  .brand { font-size: 17px; }
  nav a { padding: 5px 10px; font-size: 13px; }
  main { padding: 12px; }
  .tiles { grid-template-columns: 1fr; }
  .chart-block { padding: 8px; }
  .sec h2 { font-size: 16px; }
}
/* ─────────── Toolbar nad wykresem (MIN/MAX) ─────────── */
.chart-toolbar {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}
.chart-toolbar button {
  background: #232930;
  border: 1px solid #2a2f36;
  color: #cbd5e1;
  padding: 4px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
}
.chart-toolbar button:hover { background: #2d343d; }
.chart-toolbar button.active {
  background: #3b82f6;
  border-color: #3b82f6;
  color: white;
}

/* ─────────── Tooltip pod kursorem ─────────── */
.u-tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(20, 24, 30, 0.96);
  border: 1px solid #3b82f6;
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 12px;
  color: #e5e7eb;
  box-shadow: 0 4px 12px rgba(0,0,0,0.6);
  z-index: 100;
  min-width: 150px;
  font-family: inherit;
}
.u-tt-time {
  font-weight: 600;
  margin-bottom: 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid #2a2f36;
  color: #f3f4f6;
}
.u-tt-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
}
.u-tt-dot {
  width: 8px; height: 8px; border-radius: 2px;
  flex-shrink: 0;
}
.u-tt-name {
  flex: 1;
  color: #9ca3af;
  white-space: nowrap;
}
.u-tt-val {
  color: #f3f4f6;
  font-variant-numeric: tabular-nums;
  font-weight: 500;
}

/* ─────────── Legenda — klikalna nazwa ─────────── */
.legend-item:hover .legend-name { color: #f3f4f6; }
.legend-name { transition: color 0.1s; }

/* ─────────── Legenda — toggle MIN/MAX per seria ─────────── */
.legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 4px;
  border-radius: 4px;
}
.legend-vis {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
}
.legend-mm {
  background: transparent;
  border: 1px solid #2a2f36;
  color: #6b7280;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 3px;
  cursor: pointer;
  font-family: inherit;
  line-height: 1.2;
}
.legend-mm:hover { border-color: #6b7280; color: #cbd5e1; }
.legend-mm.active {
  background: #3b82f6;
  border-color: #3b82f6;
  color: white;
}
.meas-value.ok   { color: #22c55e; }
.meas-value.warn { color: #f59e0b; }
.meas-value.err  { color: #ef4444; }
.legend-vis input[type="checkbox"] { display: none; }
.legend-vis { cursor: pointer; }