/* ── BreedersBridge Dashboard ─────────────────────────────────────────── */

:root {
  --bg: #0c0e14;
  --surface: #14171f;
  --surface2: #1c2029;
  --surface3: #242834;
  --border: #2a2f3d;
  --border-hover: #3a4055;
  --text: #eaecf0;
  --text-mid: #b0b4c3;
  --text-dim: #6b7189;
  --accent: #5b8def;
  --accent-dim: rgba(91,141,239,.12);
  --green: #3dd68c;
  --green-dim: rgba(61,214,140,.12);
  --orange: #fb923c;
  --orange-dim: rgba(251,146,60,.10);
  --red: #f87171;
  --red-dim: rgba(248,113,113,.12);
  --blue: #60a5fa;
  --blue-dim: rgba(96,165,250,.10);
  --purple: #a78bfa;
  --temp-color: #fb923c;
  --hum-color: #60a5fa;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.15);
  --shadow-lg: 0 4px 32px rgba(0,0,0,.4);
  --transition: .2s cubic-bezier(.4,0,.2,1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; }

body {
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── Login overlay ───────────────────────────────────────────────────── */

.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(12,14,20,.92);
  backdrop-filter: blur(20px);
}

.login-overlay.visible { display: flex; }

body.no-scroll { overflow: hidden; }

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 36px 32px;
  width: 380px;
  max-width: 92vw;
  box-shadow: 0 16px 64px rgba(0,0,0,.6);
  animation: loginIn .3s ease-out;
}

@keyframes loginIn {
  from { opacity: 0; transform: translateY(16px) scale(.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.login-logo {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}

.login-title {
  font-size: 22px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 6px;
  letter-spacing: -0.02em;
}

.login-sub {
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  margin-bottom: 28px;
}

.login-field {
  margin-bottom: 16px;
}

.login-field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.login-field input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.login-field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.login-error {
  color: var(--red);
  font-size: 13px;
  font-weight: 500;
  min-height: 20px;
  margin-bottom: 8px;
  text-align: center;
}

.login-submit {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition);
}

.login-submit:hover { background: #4a7de0; }
.login-submit:active { transform: scale(.98); }
.login-submit:disabled { opacity: .6; cursor: wait; }

.login-lang {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 24px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.login-lang-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 14px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 6px;
}

.login-lang-btn:hover { color: var(--text); border-color: var(--border-hover); }

/* ── Login divider + demo button ─────────────────────────────────────── */

.login-divider {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 20px 0 16px;
  color: var(--text-dim);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .06em;
  font-weight: 600;
}

.login-divider::before,
.login-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.login-demo-btn {
  width: 100%;
  padding: 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface2);
  color: var(--text-mid);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: var(--transition);
}

.login-demo-btn:hover {
  color: var(--text);
  border-color: var(--accent);
  background: var(--accent-dim);
}

.login-demo-btn svg { color: var(--accent); }

/* ── Demo badge ──────────────────────────────────────────────────────── */

.demo-badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
  background: linear-gradient(135deg, #f59e0b, #ef4444);
  color: #fff;
  animation: demoPulse 2s ease-in-out infinite;
}

@keyframes demoPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(245,158,11,.4); }
  50% { box-shadow: 0 0 0 6px rgba(245,158,11,0); }
}

/* ── Language picker ─────────────────────────────────────────────────── */

.lang-picker {
  position: relative;
}

.lang-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-mid);
  transition: var(--transition);
}

.lang-btn:hover { border-color: var(--border-hover); color: var(--text); }

.lang-flag { font-size: 16px; line-height: 1; }
.lang-code { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }

.lang-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  min-width: 140px;
  display: none;
  overflow: hidden;
}

.lang-menu.open { display: block; }

.lang-opt {
  width: 100%;
  background: none;
  border: none;
  padding: 10px 14px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background var(--transition);
  text-align: left;
}

.lang-opt:hover { background: var(--surface2); }
.lang-opt + .lang-opt { border-top: 1px solid var(--border); }

/* ── Logout button ───────────────────────────────────────────────────── */

.logout-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 34px; height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-dim);
  transition: var(--transition);
}

.logout-btn:hover {
  color: var(--red);
  border-color: rgba(248,113,113,.3);
  background: var(--red-dim);
}

/* ── Generic icon-btn (push toggle, install) ────────────────────────── */
.icon-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 34px; height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-dim);
  transition: var(--transition);
}
.icon-btn:hover {
  color: var(--text);
  border-color: var(--border-hover);
  background: var(--surface3);
}
.icon-btn.hidden { display: none !important; }
.icon-btn.active {
  color: var(--orange);
  border-color: rgba(251,146,60,.45);
  background: var(--orange-dim);
}
.icon-btn.active svg { fill: currentColor; stroke: none; }
.push-toggle.pulse svg { animation: bell-pulse 1.6s ease-in-out infinite; }
@keyframes bell-pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.12); }
}

@media (max-width: 768px) {
  .icon-btn { width: 32px; height: 32px; }
  .install-btn { display: none !important; } /* PWA install handled via menu on mobile */
}

/* ── Header ──────────────────────────────────────────────────────────── */

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 28px;
  height: 60px;
  display: flex;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
  background: rgba(20,23,31,.85);
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--orange-dim);
}

header h1 {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text);
}

.header-subtitle {
  font-size: 11px;
  color: var(--text-dim);
  letter-spacing: .02em;
  display: block;
  margin-top: -2px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 20px;
}

.status-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 5px 14px;
  border-radius: 99px;
  background: var(--red-dim);
  color: var(--red);
  transition: var(--transition);
}

.status-pill.online {
  background: var(--green-dim);
  color: var(--green);
}

.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.status-pill.online .status-dot {
  animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: .5; transform: scale(.75); }
}

.clock {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
  min-width: 72px;
  text-align: right;
}

/* ── Device tabs nav ─────────────────────────────────────────────────── */

nav#device-tabs {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 28px;
  display: flex;
  gap: 2px;
  max-width: 1440px;
  margin: 0 auto;
}

nav#device-tabs button {
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 12px 22px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: var(--transition);
  position: relative;
}

nav#device-tabs button:hover { color: var(--text-mid); }
nav#device-tabs button.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

/* ── Alert banner ────────────────────────────────────────────────────── */

.alert-banner {
  max-width: 1440px;
  margin: 0 auto;
  padding: 14px 28px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: var(--red-dim);
  border-bottom: 1px solid color-mix(in srgb, var(--red) 30%, transparent);
}
.alert-banner.hidden { display: none; }
.alert-banner.critical {
  background: color-mix(in srgb, var(--red) 22%, var(--bg));
  border-bottom: 2px solid var(--red);
  padding: 18px 28px;
  animation: alert-pulse 2.5s ease-in-out infinite;
}

@keyframes alert-pulse {
  0%, 100% { background: color-mix(in srgb, var(--red) 22%, var(--bg)); }
  50%      { background: color-mix(in srgb, var(--red) 32%, var(--bg)); }
}

.alert-banner-icon {
  flex-shrink: 0;
  color: var(--red);
  margin-top: 2px;
}

.alert-banner-body {
  flex: 1;
  font-size: .87rem;
  line-height: 1.5;
  color: var(--text);
}
.alert-banner-body .alert-line {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 2px 0;
}
.alert-banner-body .alert-type {
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--red-dim);
  color: var(--red);
  white-space: nowrap;
}
.alert-banner-body .alert-type.warn {
  background: var(--orange-dim);
  color: var(--orange);
}
.alert-banner-body .alert-msg {
  color: var(--text-mid);
}

.alert-banner-dismiss {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 2px 4px;
  line-height: 1;
  transition: color var(--transition);
}
.alert-banner-dismiss:hover { color: var(--text); }

/* bell shake when alerts are active */
@keyframes bell-shake {
  0%,100% { transform: rotate(0); }
  15% { transform: rotate(12deg); }
  30% { transform: rotate(-10deg); }
  45% { transform: rotate(6deg); }
  60% { transform: rotate(-4deg); }
  75% { transform: rotate(2deg); }
}
.bell-alert #bell-icon { animation: bell-shake .6s ease-in-out; color: var(--red); }

/* ── Main ────────────────────────────────────────────────────────────── */

main {
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px 28px 48px;
}

.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 100px 0;
  color: var(--text-dim);
}

.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Hero cards (Temp / Humidity / Device) ────────────────────────────── */

.hero-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.hero-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px 18px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.hero-card:hover {
  border-color: var(--border-hover);
  box-shadow: var(--shadow-lg);
}

.hero-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
}

.hero-temp::before { background: linear-gradient(90deg, var(--orange), #f59e0b); }
.hero-hum::before { background: linear-gradient(90deg, var(--blue), #818cf8); }
.hero-device::before { background: linear-gradient(90deg, var(--accent), var(--purple)); }
.hero-power::before { background: linear-gradient(90deg, var(--green), #34d399); }

.hero-top {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.hero-icon {
  width: 34px; height: 34px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.hero-temp .hero-icon { background: var(--orange-dim); color: var(--orange); }
.hero-hum .hero-icon { background: var(--blue-dim); color: var(--blue); }
.hero-device .hero-icon { background: var(--accent-dim); color: var(--accent); }
.hero-power .hero-icon { background: var(--green-dim); color: var(--green); }

.hero-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-dim);
}

.hero-center {
  display: flex;
  align-items: center;
  gap: 20px;
}

/* ── Gauge ───────────────────────────────────────────────────────────── */

.gauge-wrap {
  position: relative;
  width: 110px; height: 110px;
  flex-shrink: 0;
}

.gauge-svg { width: 100%; height: 100%; }

.gauge-arc {
  transition: stroke-dasharray 1s cubic-bezier(.4,0,.2,1);
}

.gauge-center {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.hero-value {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.hero-temp .hero-value { color: var(--temp-color); }
.hero-hum .hero-value { color: var(--hum-color); }

/* ── Detail rows beside gauge ────────────────────────────────────────── */

.hero-details {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 10px;
  background: var(--surface2);
  border-radius: 6px;
}

.detail-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-dim);
}

.detail-value {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.detail-delta { font-family: 'JetBrains Mono', monospace; font-size: 12px; }

.sparkline-wrap {
  height: 32px;
  margin-top: 4px;
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface2);
}

.sparkline-wrap svg { width: 100%; height: 100%; display: block; }

/* ── Device info grid ────────────────────────────────────────────────── */

.device-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.dg-item {
  display: flex;
  flex-direction: column;
  padding: 8px 10px;
  background: var(--surface2);
  border-radius: 6px;
  gap: 2px;
  overflow: hidden;
}

.dg-key {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-dim);
}

.dg-val {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dg-mono { font-family: 'JetBrains Mono', monospace; font-size: 12px; }

/* ── Power bars + data source badge ──────────────────────────────────── */

.source-badge {
  margin-left: auto;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 2px 8px;
  border-radius: 4px;
  line-height: 1.4;
}
.source-badge.src-live {
  background: var(--green-dim);
  color: var(--green);
}
.source-badge.src-ftp {
  background: var(--orange-dim);
  color: var(--orange);
}

.power-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 14px;
}

.power-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.power-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-dim);
  width: 72px;
  flex-shrink: 0;
}

.power-bar-wrap {
  flex: 1;
  min-width: 0;
}

.power-bar {
  height: 18px;
  background: var(--surface2);
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}

.power-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width .8s cubic-bezier(.4,0,.2,1);
  width: 0%;
}

.power-bar-heat .power-bar-fill {
  background: linear-gradient(90deg, #f59e0b, #ef4444);
}

.power-bar-cool .power-bar-fill {
  background: linear-gradient(90deg, #3b82f6, #818cf8);
}

.power-val {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  width: 36px;
  text-align: right;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

/* ── PID row ─────────────────────────────────────────────────────────── */

.pid-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 22px;
  box-shadow: var(--shadow);
  transition: border-color var(--transition);
}

.card:hover { border-color: var(--border-hover); }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.card-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-dim);
}

.card-accent-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
}
.dot-temp { background: var(--orange); }
.dot-hum { background: var(--blue); }

.pid-grid {
  display: grid;
  grid-template-columns: auto 1fr auto 1fr auto 1fr;
  gap: 4px 10px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.pid-key {
  color: var(--text-dim);
  font-weight: 500;
  font-size: 12px;
}

/* ── Tab section ─────────────────────────────────────────────────────── */

.tab-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}

.tab-bar {
  display: flex;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  background: var(--surface2);
}

.tab-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  padding: 14px 22px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 7px;
}

.tab-btn svg { opacity: .6; transition: opacity var(--transition); }
.tab-btn:hover { color: var(--text-mid); background: rgba(255,255,255,.02); }
.tab-btn:hover svg { opacity: .8; }
.tab-btn.active {
  color: var(--text);
  border-bottom-color: var(--accent);
  background: rgba(91,141,239,.04);
}
.tab-btn.active svg { opacity: 1; color: var(--accent); }

.tab-content {
  display: none;
  padding: 24px;
}

.tab-content.active { display: block; }

/* ── History controls ─────────────────────────────────────────────────── */

.history-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
  margin-bottom: 18px;
}

.range-btns {
  display: flex;
  gap: 3px;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  padding: 3px;
  border: 1px solid var(--border);
}

.range-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  padding: 6px 14px;
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  transition: var(--transition);
}

.range-btn:hover { color: var(--text); background: var(--surface3); }
.range-btn.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(91,141,239,.3);
}

.history-stats {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.stat-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 99px;
  font-size: 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
}

.stat-chip .stat-label {
  color: var(--text-dim);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .03em;
}

.chip-temp { border-color: rgba(251,146,60,.2); }
.chip-temp strong { color: var(--orange); }
.chip-hum { border-color: rgba(96,165,250,.2); }
.chip-hum strong { color: var(--blue); }
.chip-heat { border-color: rgba(61,214,140,.2); }
.chip-heat strong { color: var(--green); }

.history-table-wrap {
  margin-top: 20px;
  max-height: 320px;
  overflow-y: auto;
  overflow-x: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  -webkit-overflow-scrolling: touch;
}

.history-table { min-width: 100%; }
.history-table .td-time { white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ── D3 Chart ────────────────────────────────────────────────────────── */

.chart-wrap {
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg);
}

.d3-chart { width: 100%; height: 380px; position: relative; }
.d3-chart svg { width: 100%; height: 100%; display: block; }
.d3-chart .axis text { fill: var(--text-dim); font-size: 11px; font-family: 'DM Sans', sans-serif; }
.d3-chart .axis line, .d3-chart .axis path { stroke: #1c2029; }
.d3-chart .grid line { stroke: #1c2029; stroke-dasharray: 2,3; }
.d3-chart .grid path { display: none; }
.d3-chart .line { fill: none; stroke-width: 2; }
.d3-chart .line-dashed { stroke-dasharray: 5,4; stroke-width: 1.2; }
.d3-chart .area { opacity: .08; }
.d3-chart .legend { font-size: 12px; font-weight: 600; font-family: 'DM Sans', sans-serif; }

.chart-tooltip {
  position: absolute;
  pointer-events: none;
  background: rgba(20,23,31,.92);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 12px;
  color: var(--text);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(8px);
  z-index: 10;
  white-space: nowrap;
  opacity: 0;
  transition: opacity .15s;
}

.chart-tooltip.visible { opacity: 1; }
.chart-tooltip .tt-time { color: var(--text-dim); font-size: 11px; margin-bottom: 4px; }
.chart-tooltip .tt-row { display: flex; align-items: center; gap: 6px; }
.chart-tooltip .tt-dot { width: 8px; height: 8px; border-radius: 50%; }
.chart-tooltip .tt-val { font-weight: 700; font-variant-numeric: tabular-nums; }

.crosshair-line { stroke: var(--border-hover); stroke-width: 1; stroke-dasharray: 3,3; }
.hover-dot { stroke: var(--bg); stroke-width: 2; }

/* ── Data table (shared by I/O + History) ────────────────────────────── */

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

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.data-table th {
  text-align: left;
  padding: 10px 14px;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface2);
}

.data-table td {
  padding: 8px 14px;
  border-bottom: 1px solid rgba(42,47,61,.5);
  color: var(--text-mid);
}

.data-table tbody tr { transition: background var(--transition); }
.data-table tbody tr:hover td { background: var(--surface2); }

.io-dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  vertical-align: middle;
}

.io-dot.on { background: var(--green); box-shadow: 0 0 8px var(--green); }
.io-dot.off { background: #444; }

/* ── Visu canvas ─────────────────────────────────────────────────────── */

.visu-container {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  justify-content: center;
}

.visu-canvas {
  background: #d4d4d4;
  border-radius: var(--radius-sm);
  image-rendering: crisp-edges;
  box-shadow: 0 2px 16px rgba(0,0,0,.4);
}

/* ── File tree ───────────────────────────────────────────────────────── */

.file-tree {
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
  line-height: 1.9;
  max-height: 500px;
  overflow-y: auto;
  padding: 4px;
}

.ft-dir {
  cursor: pointer;
  user-select: none;
  padding: 2px 6px;
  border-radius: 4px;
  transition: background var(--transition);
}
.ft-dir:hover { background: var(--surface2); }
.ft-dir::before { content: "\1F4C1 "; }
.ft-file { padding: 2px 6px; }
.ft-file::before { content: "\1F4C4 "; }
.ft-children { padding-left: 22px; border-left: 1px solid var(--border); margin-left: 10px; }
.ft-size { color: var(--text-dim); font-size: 11px; margin-left: 8px; }

/* ── Raw JSON ────────────────────────────────────────────────────────── */

.raw-json {
  background: var(--bg);
  padding: 20px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px;
  max-height: 600px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--text-dim);
  line-height: 1.7;
}

/* ── PID cards layout ────────────────────────────────────────────────── */

.pid-cards { display: flex; flex-direction: column; gap: 16px; }

/* ── Responsive ──────────────────────────────────────────────────────── */

@media (max-width: 1024px) {
  .hero-row { grid-template-columns: 1fr 1fr; }
  .hero-device, .hero-power { grid-column: 1 / -1; }
  header { padding: 0 20px; }
  .header-right { gap: 12px; }
  .header-subtitle { display: none; }
}

@media (max-width: 768px) {
  html { font-size: 14px; }
  body { overflow-x: hidden; }
  .hero-row { grid-template-columns: 1fr; }
  .pid-row { grid-template-columns: 1fr; }
  main { padding: 16px; }
  nav#device-tabs { padding: 0 16px; }
  .tab-btn { padding: 12px 14px; font-size: 12px; }
  .hero-value { font-size: 20px; }
  .gauge-wrap { width: 90px; height: 90px; }
  .hero-center { gap: 14px; }
  .history-controls { flex-direction: column; align-items: flex-start; gap: 10px; }
  .history-stats { gap: 4px; }
  .stat-chip { padding: 4px 9px; font-size: 11px; }
  .stat-chip .stat-label { font-size: 10px; }
  .pid-grid { grid-template-columns: auto 1fr auto 1fr; }
  .device-grid { grid-template-columns: 1fr; }
  .d3-chart { height: 260px; }
  .d3-chart .axis text { font-size: 10px; }
  .data-table { font-size: 12px; }
  .data-table th { padding: 8px 8px; font-size: 10px; letter-spacing: .02em; }
  .data-table td { padding: 6px 8px; }

  /* Compact header — keep everything on one row, no horizontal scroll */
  header { padding: 0 12px; height: 56px; }
  .header-content { gap: 8px; }
  .header-left { gap: 8px; min-width: 0; flex: 1 1 auto; }
  .header-left > div:last-child { min-width: 0; overflow: hidden; }
  .logo { width: 32px; height: 32px; flex-shrink: 0; }
  header h1 {
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .header-subtitle { display: none; }
  .header-right { gap: 8px; flex-shrink: 0; }
  .lang-btn { padding: 5px 8px; }
  .lang-code { display: none; }
  .clock { display: none; }
  .status-pill {
    padding: 5px 8px;
    font-size: 0;
    gap: 0;
  }
  .status-pill .status-dot { margin: 0; }
  #status-text { display: none; }
  .demo-badge { padding: 3px 8px; font-size: 10px; }
  .logout-btn { width: 32px; height: 32px; }
}

@media (max-width: 640px) {
  /* Hide redundant table columns (setpoint + delta) — they're available in tooltip / charts */
  .col-mobile-hide { display: none !important; }
  .data-table th, .data-table td { padding: 6px 6px; }
  .history-table .td-time { font-size: 11px; }
  .d3-chart { height: 240px; }
}

@media (max-width: 380px) {
  header { padding: 0 10px; }
  header h1 { font-size: 14px; }
  .header-right { gap: 6px; }
  .logo { width: 28px; height: 28px; }
  .lang-btn { padding: 4px 6px; }
  .lang-flag { font-size: 14px; }
  .demo-badge { display: none; }
  .d3-chart { height: 220px; }
  .d3-chart .axis text { font-size: 9px; }
}

/* ── Scrollbar ───────────────────────────────────────────────────────── */

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-hover); }
