:root {
  color-scheme: dark;
  --bg: #070b14;
  --bg-soft: #0b1222;
  --panel: rgba(15, 23, 40, 0.78);
  --panel-strong: #0f172a;
  --border: rgba(148, 163, 184, 0.14);
  --border-strong: rgba(148, 163, 184, 0.26);
  --text: #e9effc;
  --muted: #8b9bb8;
  --grid: rgba(148, 163, 184, 0.13);
  --accent: #5eead4;
  --accent-soft: rgba(94, 234, 212, 0.12);
  --ok: #34d399;
  --warn: #fbbf24;
  --danger: #fb7185;
  --shadow: 0 24px 60px -32px rgba(2, 6, 23, 0.95);
  --radius: 18px;
  --radius-sm: 11px;
  --font: "Inter", "Segoe UI Variable", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", "Cascadia Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #eef2f9;
  --bg-soft: #f7f9fd;
  --panel: rgba(255, 255, 255, 0.86);
  --panel-strong: #ffffff;
  --border: rgba(15, 23, 42, 0.1);
  --border-strong: rgba(15, 23, 42, 0.18);
  --text: #0f172a;
  --muted: #5a6b85;
  --grid: rgba(15, 23, 42, 0.09);
  --accent: #0f9d8a;
  --accent-soft: rgba(15, 157, 138, 0.1);
  --shadow: 0 22px 48px -34px rgba(15, 23, 42, 0.45);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1000px 520px at 12% -8%, rgba(94, 234, 212, 0.1), transparent 62%),
    radial-gradient(900px 520px at 88% -4%, rgba(183, 155, 255, 0.1), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
p,
figure {
  margin: 0;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button,
select {
  font: inherit;
  color: inherit;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 16px;
  top: -60px;
  z-index: 20;
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--accent);
  color: #04231f;
  font-weight: 600;
  transition: top 0.2s ease;
}

.skip-link:focus {
  top: 12px;
}

/* ---------- Üst çubuk ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px clamp(16px, 4vw, 40px);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(18px) saturate(140%);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 13px;
  background: linear-gradient(150deg, rgba(94, 234, 212, 0.22), rgba(183, 155, 255, 0.16));
  border: 1px solid rgba(94, 234, 212, 0.3);
  color: var(--accent);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.brand-mark svg {
  width: 24px;
  height: 24px;
}

.brand h1 {
  font-size: 1.18rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.brand h1 span {
  color: var(--accent);
}

.subtitle {
  margin-top: 2px;
  font-size: 0.76rem;
  color: var(--muted);
  letter-spacing: 0.01em;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.field {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel);
  font-size: 0.78rem;
  color: var(--muted);
}

.field select {
  appearance: none;
  padding: 4px 26px 4px 4px;
  border: 0;
  border-radius: 7px;
  background:
    linear-gradient(45deg, transparent 50%, currentColor 50%) calc(100% - 12px) 52% / 5px 5px no-repeat,
    linear-gradient(-45deg, transparent 50%, currentColor 50%) calc(100% - 7px) 52% / 5px 5px no-repeat;
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 550;
  cursor: pointer;
  outline: none;
}

.field select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.field select option {
  background: var(--panel-strong);
  color: var(--text);
}

.conn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 13px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel);
  font-size: 0.78rem;
  font-weight: 550;
  color: var(--muted);
  white-space: nowrap;
}

.conn .pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warn);
  box-shadow: 0 0 0 0 rgba(251, 191, 36, 0.55);
  animation: pulse 2.2s infinite;
}

.conn[data-state="live"] {
  color: var(--ok);
  border-color: rgba(52, 211, 153, 0.35);
  background: rgba(52, 211, 153, 0.08);
}

.conn[data-state="live"] .pulse {
  background: var(--ok);
  animation: none;
  box-shadow: 0 0 10px rgba(52, 211, 153, 0.8);
}

.conn[data-state="offline"] {
  color: var(--danger);
  border-color: rgba(251, 113, 133, 0.35);
  background: rgba(251, 113, 133, 0.08);
}

.conn[data-state="polling"] {
  color: var(--warn);
  border-color: rgba(251, 191, 36, 0.35);
  background: rgba(251, 191, 36, 0.08);
}

.conn[data-state="polling"] .pulse {
  background: var(--warn);
}

.conn[data-state="offline"] .pulse {
  background: var(--danger);
  animation: none;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--panel);
  font-size: 0.79rem;
  font-weight: 550;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.18s ease, background 0.18s ease, transform 0.18s ease;
}

.btn svg {
  width: 15px;
  height: 15px;
}

.btn:hover {
  border-color: var(--border-strong);
  background: color-mix(in srgb, var(--panel) 75%, var(--accent) 6%);
}

.btn:active {
  transform: translateY(1px);
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn[aria-pressed="true"] {
  border-color: rgba(251, 191, 36, 0.4);
  background: rgba(251, 191, 36, 0.12);
  color: var(--warn);
}

.btn .icon-play,
.btn[aria-pressed="true"] .icon-pause {
  display: none;
}

.btn[aria-pressed="true"] .icon-play {
  display: inline;
}

.btn.icon-only {
  padding: 9px;
}

/* ---------- Yerleşim ---------- */

main {
  max-width: 1440px;
  margin: 0 auto;
  padding: clamp(18px, 3vw, 30px) clamp(16px, 4vw, 40px) 34px;
  display: grid;
  gap: 18px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

.metric {
  position: relative;
  overflow: hidden;
  padding: 18px 20px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background:
    radial-gradient(120% 100% at 100% 0%, color-mix(in srgb, var(--metric) 12%, transparent), transparent 62%),
    var(--panel);
  box-shadow: var(--shadow);
  transition: border-color 0.2s ease, transform 0.2s ease;
}

.metric:hover {
  border-color: color-mix(in srgb, var(--metric) 34%, var(--border));
  transform: translateY(-2px);
}

.metric-head {
  display: flex;
  align-items: center;
  gap: 9px;
}

.metric-icon {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: color-mix(in srgb, var(--metric) 15%, transparent);
  color: var(--metric);
}

.metric-icon svg {
  width: 17px;
  height: 17px;
}

.metric-head h2 {
  font-size: 0.83rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--muted);
  text-transform: uppercase;
}

.metric-tag {
  margin-left: auto;
  max-width: 110px;
  overflow: hidden;
  padding: 3px 8px;
  border: 1px solid color-mix(in srgb, var(--metric) 26%, transparent);
  border-radius: 999px;
  color: color-mix(in srgb, var(--metric) 82%, var(--text));
  font-family: var(--mono);
  font-size: 0.66rem;
  letter-spacing: 0.02em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metric-value {
  margin-top: 10px;
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.metric-value [data-value] {
  font-size: clamp(2.1rem, 3.4vw, 2.7rem);
  font-weight: 640;
  letter-spacing: -0.035em;
}

.metric-value [data-value].flash {
  animation: valueFlash 0.55s ease;
}

.metric-unit {
  font-size: 0.95rem;
  font-weight: 550;
  color: var(--muted);
}

.metric-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 6px 10px;
  margin: 8px 0 10px;
  font-size: 0.71rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.metric-meta [data-delta] {
  color: color-mix(in srgb, var(--metric) 85%, var(--text));
  font-weight: 600;
}

.spark {
  display: block;
  width: 100%;
  height: 42px;
}

.panel {
  padding: 18px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px 16px;
  margin-bottom: 14px;
}

.panel-head h2 {
  font-size: 0.98rem;
  font-weight: 620;
  letter-spacing: -0.01em;
}

.panel-sub {
  margin-top: 3px;
  font-size: 0.74rem;
  color: var(--muted);
}

.panel-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.legend {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.71rem;
  color: var(--muted);
}

.legend i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--metric);
  box-shadow: 0 0 8px color-mix(in srgb, var(--metric) 70%, transparent);
}

.badge {
  padding: 4px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: color-mix(in srgb, var(--panel-strong) 70%, transparent);
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.charts {
  display: grid;
  gap: 14px;
}

.chart {
  position: relative;
  padding-top: 6px;
  border-top: 1px dashed var(--grid);
}

.chart:first-child {
  border-top: 0;
  padding-top: 0;
}

.chart figcaption {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.73rem;
  font-weight: 600;
  color: var(--muted);
}

.chart figcaption span {
  padding: 2px 6px;
  border-radius: 5px;
  background: color-mix(in srgb, var(--panel-strong) 80%, transparent);
  font-family: var(--mono);
  font-size: 0.64rem;
  font-weight: 500;
}

.chart canvas {
  display: block;
  width: 100%;
  height: 178px;
}

.empty-hint {
  margin-top: 12px;
  padding: 11px 14px;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  font-size: 0.78rem;
  color: var(--muted);
  text-align: center;
}

.empty-hint code {
  padding: 2px 6px;
  border-radius: 5px;
  background: rgba(0, 0, 0, 0.25);
  font-family: var(--mono);
  font-size: 0.74rem;
  color: var(--accent);
}

.lower-grid {
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

/* ---------- Tablolar ---------- */

.table-wrap {
  overflow: auto;
  max-height: 380px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 9px 12px;
  background: color-mix(in srgb, var(--panel-strong) 92%, transparent);
  border-bottom: 1px solid var(--border);
  font-size: 0.67rem;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  text-align: right;
  white-space: nowrap;
}

thead th:first-child,
thead th:nth-child(2) {
  text-align: left;
}

tbody td,
tbody th {
  padding: 9px 12px;
  border-bottom: 1px solid var(--grid);
  text-align: right;
  white-space: nowrap;
}

tbody th {
  font-weight: 550;
  text-align: left;
  color: var(--text);
}

tbody tr:last-child td,
tbody tr:last-child th {
  border-bottom: 0;
}

tbody tr:hover {
  background: color-mix(in srgb, var(--accent) 5%, transparent);
}

.stats tbody th {
  color: var(--muted);
}

.stats td {
  font-weight: 550;
}

.readings td:first-child {
  color: var(--muted);
  text-align: left;
}

.readings td:nth-child(2) {
  text-align: left;
}

.readings .placeholder td {
  padding: 22px 12px;
  color: var(--muted);
  text-align: center;
}

.chip {
  display: inline-block;
  max-width: 160px;
  overflow: hidden;
  padding: 2px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: color-mix(in srgb, var(--panel-strong) 70%, transparent);
  font-family: var(--mono);
  font-size: 0.66rem;
  color: color-mix(in srgb, var(--accent) 75%, var(--text));
  text-overflow: ellipsis;
  vertical-align: middle;
}

.readings [data-metric] {
  font-weight: 600;
}

.readings [data-metric="temperature"] {
  color: #ffab73;
}

.readings [data-metric="humidity"] {
  color: #6fd4f5;
}

.readings [data-metric="pressure"] {
  color: #c1aaff;
}

[data-theme="light"] .readings [data-metric="temperature"] {
  color: #b45309;
}

[data-theme="light"] .readings [data-metric="humidity"] {
  color: #0369a1;
}

[data-theme="light"] .readings [data-metric="pressure"] {
  color: #6d28d9;
}

/* ---------- Alt bilgi ---------- */

.footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px 20px;
  padding: 4px 2px;
  font-size: 0.73rem;
  color: var(--muted);
}

.footer strong {
  color: var(--text);
  font-weight: 600;
}

.footer-note code {
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--panel);
  font-family: var(--mono);
  font-size: 0.68rem;
}

/* ---------- Bildirim ---------- */

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 30;
  max-width: min(360px, calc(100vw - 40px));
  padding: 12px 16px;
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  background: var(--panel-strong);
  box-shadow: 0 20px 40px -20px rgba(0, 0, 0, 0.7);
  font-size: 0.8rem;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.toast[data-kind="error"] {
  border-color: rgba(251, 113, 133, 0.4);
  color: #fecdd3;
}

.noscript {
  margin: 20px;
  padding: 14px;
  border: 1px solid var(--danger);
  border-radius: 10px;
  text-align: center;
}

/* ---------- Animasyonlar ---------- */

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(251, 191, 36, 0.45);
  }
  65% {
    box-shadow: 0 0 0 8px rgba(251, 191, 36, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(251, 191, 36, 0);
  }
}

@keyframes valueFlash {
  0% {
    opacity: 0.55;
    transform: translateY(-2px);
  }
  100% {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ---------- Duyarlı ---------- */

@media (max-width: 1080px) {
  .lower-grid {
    grid-template-columns: 1fr;
  }

  .table-wrap {
    max-height: 330px;
  }
}

@media (max-width: 820px) {
  .cards {
    grid-template-columns: 1fr;
  }

  .metric {
    padding: 16px 18px 10px;
  }

  .topbar {
    gap: 12px;
  }

  .toolbar {
    width: 100%;
  }

  .conn {
    order: -1;
  }

  .field {
    flex: 1 1 auto;
  }

  .field select {
    width: 100%;
  }

  .chart canvas {
    height: 160px;
  }
}

@media (max-width: 520px) {
  .panel,
  .metric {
    border-radius: 14px;
  }

  .btn span {
    display: none;
  }

  .btn {
    padding: 9px 11px;
  }

  .panel-tools .legend {
    display: none;
  }

  .charts-panel {
    padding: 16px 12px;
  }
}
