/* ==========================================================================
   MeteoStation · design system
   ========================================================================== */

:root {
  --bg: #06111d;
  --bg-deep: #040b13;
  --bg-soft: #0a1c2c;
  --panel: rgba(12, 29, 46, 0.74);
  --panel-solid: #0c1d2e;
  --panel-raised: rgba(17, 39, 61, 0.78);
  --border: rgba(148, 197, 255, 0.12);
  --border-strong: rgba(148, 197, 255, 0.24);
  --text: #eaf5ff;
  --text-soft: #c7d9ea;
  --muted: #8ba6c0;
  --faint: #607b96;
  --cyan: #38bdf8;
  --cyan-bright: #7dd3fc;
  --cyan-deep: #0284c7;
  --teal: #2dd4bf;
  --green: #34d399;
  --amber: #fbbf24;
  --orange: #fb923c;
  --rose: #fb7185;
  --violet: #a78bfa;
  --blue: #60a5fa;
  --danger: #fb7185;
  --shadow-lg: 0 32px 80px -40px rgba(0, 0, 0, 0.9);
  --shadow-md: 0 18px 44px -28px rgba(0, 0, 0, 0.8);
  --radius-xl: 26px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, "Noto Sans", sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --ease: cubic-bezier(0.2, 0.75, 0.25, 1);
  color-scheme: dark;
}

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

html {
  min-height: 100%;
  scroll-behavior: smooth;
}

body {
  min-height: 100%;
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

h1,
h2,
h3 {
  line-height: 1.15;
  letter-spacing: -0.025em;
  font-weight: 650;
}

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

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

[hidden] {
  display: none !important;
}

::selection {
  background: rgba(56, 189, 248, 0.32);
  color: #fff;
}

:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 3px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--cyan);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

/* --------------------------------------------------------------------------
   Shared brand / buttons
   -------------------------------------------------------------------------- */

.logo-badge {
  flex: 0 0 auto;
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  border: 1px solid rgba(125, 211, 252, 0.2);
  background:
    radial-gradient(circle at 28% 18%, rgba(125, 211, 252, 0.18), transparent 55%),
    rgba(8, 24, 39, 0.75);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.logo-badge svg {
  width: 32px;
  height: 32px;
}

.logo-badge-lg {
  width: 62px;
  height: 62px;
  border-radius: 19px;
}

.logo-badge-lg svg {
  width: 48px;
  height: 48px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: var(--text);
}

.brand-name {
  font-size: 19px;
  font-weight: 680;
  letter-spacing: -0.03em;
}

.brand-name span {
  color: var(--cyan-bright);
}

.brand:hover .logo-badge {
  border-color: rgba(125, 211, 252, 0.42);
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 46px;
  padding: 0 20px;
  border: 0;
  border-radius: 13px;
  color: #03121d;
  background: linear-gradient(135deg, #7dd3fc 0%, #38bdf8 45%, #0ea5e9 100%);
  font-weight: 720;
  letter-spacing: 0.01em;
  box-shadow:
    0 12px 28px -12px rgba(56, 189, 248, 0.7),
    inset 0 1px 0 rgba(255, 255, 255, 0.45);
  transition:
    transform 0.18s var(--ease),
    box-shadow 0.18s var(--ease),
    filter 0.18s var(--ease);
}

.btn-primary:hover {
  transform: translateY(-1px);
  filter: brightness(1.04);
  box-shadow:
    0 18px 34px -14px rgba(56, 189, 248, 0.8),
    inset 0 1px 0 rgba(255, 255, 255, 0.45);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-primary svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.btn-small {
  min-height: 38px;
  padding: 0 16px;
  border-radius: 11px;
  font-size: 13px;
}

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 14px;
  color: var(--text-soft);
  background: rgba(15, 35, 54, 0.66);
  border: 1px solid var(--border);
  border-radius: 11px;
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  transition:
    border-color 0.18s,
    background 0.18s,
    color 0.18s;
}

.btn-ghost:hover {
  color: var(--text);
  background: rgba(23, 49, 75, 0.8);
  border-color: var(--border-strong);
}

.btn-ghost svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.btn-ghost[aria-disabled="true"] {
  opacity: 0.45;
  pointer-events: none;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  color: var(--muted);
  background: rgba(12, 30, 48, 0.6);
  border: 1px solid var(--border);
  border-radius: 11px;
  transition:
    color 0.18s,
    border-color 0.18s,
    background 0.18s;
}

.icon-btn:hover {
  color: var(--text);
  border-color: var(--border-strong);
  background: rgba(20, 44, 68, 0.8);
}

.icon-btn svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ==========================================================================
   Login
   ========================================================================== */

.login-page {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 40px 20px;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 50% 115%, rgba(14, 116, 144, 0.2), transparent 58%),
    linear-gradient(165deg, #040c15 0%, #071827 46%, #0a2236 100%);
}

.login-sky {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.sky-glow {
  position: absolute;
  border-radius: 50%;
  filter: blur(40px);
  opacity: 0.55;
}

.sky-glow-one {
  top: -18vmax;
  left: -10vmax;
  width: 52vmax;
  height: 52vmax;
  background: radial-gradient(circle, rgba(14, 165, 233, 0.3), transparent 68%);
  animation: drift-slow 22s ease-in-out infinite alternate;
}

.sky-glow-two {
  right: -16vmax;
  bottom: -24vmax;
  width: 58vmax;
  height: 58vmax;
  background: radial-gradient(circle, rgba(245, 158, 11, 0.14), transparent 66%);
  animation: drift-slow 28s ease-in-out infinite alternate-reverse;
}

.sky-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(125, 211, 252, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(125, 211, 252, 0.045) 1px, transparent 1px);
  background-size: 68px 68px;
  mask-image: radial-gradient(ellipse at 50% 42%, black 0%, transparent 74%);
  -webkit-mask-image: radial-gradient(ellipse at 50% 42%, black 0%, transparent 74%);
}

.cloud {
  position: absolute;
  height: 70px;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(186, 230, 253, 0.12), rgba(56, 189, 248, 0.04));
  border: 1px solid rgba(186, 230, 253, 0.07);
  filter: blur(9px);
  opacity: 0.75;
}

.cloud::before,
.cloud::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  background: inherit;
  border: inherit;
}

.cloud::before {
  width: 120px;
  height: 120px;
  left: 22%;
  bottom: 10px;
}

.cloud::after {
  width: 80px;
  height: 80px;
  right: 16%;
  bottom: 5px;
}

.cloud-one {
  top: 18%;
  left: -220px;
  width: 320px;
  animation: cloud-drift 42s linear infinite;
}

.cloud-two {
  top: 34%;
  left: -320px;
  width: 400px;
  height: 86px;
  opacity: 0.45;
  animation: cloud-drift 58s linear 8s infinite;
}

.cloud-three {
  top: 72%;
  left: -180px;
  width: 260px;
  opacity: 0.35;
  animation: cloud-drift 48s linear 18s infinite;
}

.sky-line {
  position: absolute;
  left: 8%;
  right: 8%;
  bottom: 13%;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(56, 189, 248, 0.35), transparent);
  box-shadow: 0 0 30px rgba(56, 189, 248, 0.25);
}

.login-shell {
  position: relative;
  z-index: 2;
  width: min(100%, 442px);
}

.login-card {
  position: relative;
  padding: 36px 36px 28px;
  border: 1px solid rgba(148, 197, 255, 0.14);
  border-radius: var(--radius-xl);
  background:
    radial-gradient(circle at 12% 0%, rgba(56, 189, 248, 0.1), transparent 38%),
    linear-gradient(170deg, rgba(15, 36, 56, 0.93), rgba(6, 17, 29, 0.96));
  box-shadow:
    var(--shadow-lg),
    inset 0 1px 0 rgba(255, 255, 255, 0.055);
  backdrop-filter: blur(22px);
  -webkit-backdrop-filter: blur(22px);
  animation: card-in 0.65s var(--ease) both;
}

.login-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 12%;
  right: 12%;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(125, 211, 252, 0.6), transparent);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 15px;
}

.login-brand-text h1 {
  font-size: 28px;
  letter-spacing: -0.04em;
}

.login-brand-text h1 span {
  color: var(--cyan-bright);
}

.login-lead {
  margin: 22px 0 24px;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.65;
}

.login-form {
  display: grid;
  gap: 17px;
}

.field {
  display: grid;
  gap: 7px;
}

.field label {
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 620;
  letter-spacing: 0.015em;
}

.input-wrap {
  position: relative;
  display: flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: rgba(4, 14, 24, 0.58);
  transition:
    border-color 0.18s,
    box-shadow 0.18s,
    background 0.18s;
}

.input-wrap:focus-within {
  border-color: rgba(56, 189, 248, 0.65);
  background: rgba(5, 18, 30, 0.85);
  box-shadow:
    0 0 0 3px rgba(56, 189, 248, 0.11),
    inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.input-icon {
  flex: 0 0 auto;
  width: 17px;
  height: 17px;
  margin-left: 15px;
  color: var(--faint);
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: color 0.18s;
}

.input-wrap:focus-within .input-icon {
  color: var(--cyan);
}

.input-wrap input {
  width: 100%;
  min-height: 50px;
  padding: 0 15px 0 12px;
  color: var(--text);
  background: transparent;
  border: 0;
  outline: 0;
  font-size: 14px;
}

.input-wrap input::placeholder {
  color: #4e687f;
}

.input-wrap input:-webkit-autofill,
.input-wrap input:-webkit-autofill:hover,
.input-wrap input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--text);
  -webkit-box-shadow: 0 0 0 1000px #08192a inset;
  transition: background-color 9999s ease-out;
}

.reveal {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  margin-right: 4px;
  padding: 0;
  color: var(--faint);
  background: transparent;
  border: 0;
  border-radius: 9px;
  transition: color 0.18s, background 0.18s;
}

.reveal:hover {
  color: var(--text-soft);
  background: rgba(125, 211, 252, 0.07);
}

.reveal svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.reveal .eye-closed {
  display: none;
}

.reveal.is-visible .eye-open {
  display: none;
}

.reveal.is-visible .eye-closed {
  display: block;
}

.btn-login {
  width: 100%;
  margin-top: 5px;
  min-height: 51px;
  font-size: 14px;
}

.btn-login svg {
  transition: transform 0.18s var(--ease);
}

.btn-login:hover svg {
  transform: translateX(3px);
}

.form-error {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  margin: 0 0 18px;
  padding: 11px 13px;
  color: #fecdd3;
  background: rgba(127, 29, 29, 0.22);
  border: 1px solid rgba(251, 113, 133, 0.28);
  border-radius: 11px;
  font-size: 12.5px;
  line-height: 1.45;
}

.form-error svg {
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  margin-top: 1px;
  fill: none;
  stroke: var(--rose);
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.login-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid rgba(148, 197, 255, 0.08);
  color: var(--faint);
  font-size: 11.5px;
}

.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.1);
  animation: pulse-dot 2.4s ease-in-out infinite;
}

.login-foot {
  margin-top: 20px;
  color: rgba(139, 166, 192, 0.7);
  font-size: 11px;
  text-align: center;
  letter-spacing: 0.015em;
}

/* ==========================================================================
   App shell
   ========================================================================== */

.app-page {
  min-height: 100vh;
  background:
    radial-gradient(ellipse at 15% -10%, rgba(14, 165, 233, 0.13), transparent 45%),
    radial-gradient(ellipse at 95% 18%, rgba(245, 158, 11, 0.06), transparent 38%),
    linear-gradient(180deg, #06111d 0%, #06101b 60%, #040b13 100%);
}

.app-backdrop {
  position: fixed;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
}

.app-glow {
  position: absolute;
  border-radius: 50%;
  filter: blur(70px);
  opacity: 0.5;
}

.app-glow-a {
  top: -30vh;
  left: 25%;
  width: 55vw;
  height: 55vw;
  background: radial-gradient(circle, rgba(2, 132, 199, 0.18), transparent 65%);
}

.app-glow-b {
  right: -15vw;
  top: 40vh;
  width: 40vw;
  height: 40vw;
  background: radial-gradient(circle, rgba(168, 85, 247, 0.07), transparent 65%);
}

.app-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(125, 211, 252, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(125, 211, 252, 0.025) 1px, transparent 1px);
  background-size: 80px 80px;
  mask-image: linear-gradient(180deg, black, transparent 75%);
  -webkit-mask-image: linear-gradient(180deg, black, transparent 75%);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 20px;
  min-height: 68px;
  padding: 10px clamp(18px, 3vw, 42px);
  background: rgba(5, 15, 25, 0.72);
  border-bottom: 1px solid rgba(148, 197, 255, 0.08);
  backdrop-filter: blur(18px) saturate(130%);
  -webkit-backdrop-filter: blur(18px) saturate(130%);
}

.topbar-center {
  display: flex;
  justify-content: center;
}

.conn-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  padding: 0 11px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(9, 24, 39, 0.6);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.conn-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--faint);
  box-shadow: 0 0 0 3px rgba(96, 123, 150, 0.1);
}

.conn-pill.is-online {
  color: #b6f7d9;
  border-color: rgba(52, 211, 153, 0.25);
  background: rgba(6, 78, 59, 0.18);
}

.conn-pill.is-online .conn-dot {
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.12);
  animation: pulse-dot 2.4s ease-in-out infinite;
}

.conn-pill.is-error {
  color: #fed7aa;
  border-color: rgba(251, 146, 60, 0.25);
  background: rgba(124, 45, 18, 0.15);
}

.conn-pill.is-error .conn-dot {
  background: var(--orange);
  box-shadow: 0 0 0 3px rgba(251, 146, 60, 0.12);
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-width: 0;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 180px;
  padding: 0 10px;
  min-height: 36px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: rgba(10, 27, 44, 0.55);
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 600;
  overflow: hidden;
}

.user-chip span {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.user-chip svg {
  flex: 0 0 auto;
  width: 14px;
  height: 14px;
  color: var(--cyan);
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.logout-form {
  margin: 0;
}

.app-main {
  position: relative;
  z-index: 1;
  width: min(100%, 1480px);
  margin: 0 auto;
  padding: 30px clamp(18px, 3vw, 42px) 54px;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 22px;
  margin-bottom: 24px;
}

.page-head h1 {
  font-size: clamp(27px, 3vw, 36px);
  letter-spacing: -0.045em;
}

.page-sub {
  margin-top: 7px;
  color: var(--muted);
  font-size: 13px;
}

.head-actions {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.refresh-label {
  margin-right: 2px;
  color: var(--faint);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.refresh-btn.is-spinning svg {
  animation: spin 0.8s linear infinite;
}

/* --------------------------------------------------------------- station tabs */

.station-tabs {
  display: flex;
  gap: 9px;
  margin-bottom: 18px;
  padding: 3px 1px 8px;
  overflow-x: auto;
  scrollbar-width: none;
}

.station-tabs::-webkit-scrollbar {
  display: none;
}

.station-tab {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 48px;
  padding: 7px 15px 7px 13px;
  color: var(--muted);
  text-align: left;
  background: rgba(10, 27, 44, 0.58);
  border: 1px solid var(--border);
  border-radius: 14px;
  transition:
    color 0.18s,
    background 0.18s,
    border-color 0.18s,
    transform 0.18s;
}

.station-tab:hover {
  color: var(--text-soft);
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

.station-tab.is-active {
  color: var(--text);
  background:
    radial-gradient(circle at 10% 0%, rgba(56, 189, 248, 0.16), transparent 70%),
    rgba(14, 38, 60, 0.86);
  border-color: rgba(56, 189, 248, 0.4);
  box-shadow:
    0 10px 28px -18px rgba(56, 189, 248, 0.7),
    inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.station-tab-inner {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}

.station-tab-name {
  max-width: 210px;
  font-size: 12.5px;
  font-weight: 650;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.station-tab-id {
  color: var(--faint);
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.02em;
}

.station-tab.is-active .station-tab-id {
  color: rgba(125, 211, 252, 0.7);
}

.station-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--faint);
  box-shadow: 0 0 0 4px rgba(96, 123, 150, 0.09);
}

.station-status-dot.is-online {
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.1);
}

.station-status-dot.is-stale {
  background: var(--amber);
  box-shadow: 0 0 0 4px rgba(251, 191, 36, 0.1);
}

.station-status-dot.is-offline {
  background: var(--rose);
  box-shadow: 0 0 0 4px rgba(251, 113, 133, 0.1);
}

.demo-pill {
  padding: 1px 5px;
  border: 1px solid rgba(251, 191, 36, 0.25);
  border-radius: 5px;
  color: #fcd34d;
  background: rgba(120, 53, 15, 0.2);
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.tab-skeleton {
  display: block;
  width: 160px;
  height: 48px;
  border-radius: 14px;
  background: linear-gradient(90deg, rgba(20, 43, 65, 0.5), rgba(30, 58, 84, 0.65), rgba(20, 43, 65, 0.5));
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}

/* ---------------------------------------------------------------------- KPIs */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 13px;
  margin-bottom: 16px;
}

.kpi {
  --accent: var(--cyan);
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 158px;
  padding: 17px 18px 15px;
  overflow: hidden;
  background:
    radial-gradient(circle at 8% -12%, color-mix(in srgb, var(--accent) 17%, transparent), transparent 52%),
    linear-gradient(165deg, rgba(15, 35, 55, 0.76), rgba(7, 20, 34, 0.84));
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow-md), inset 0 1px 0 rgba(255, 255, 255, 0.035);
}

.kpi::after {
  content: "";
  position: absolute;
  top: 0;
  left: 14%;
  right: 14%;
  height: 1px;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--accent) 60%, transparent), transparent);
  opacity: 0.7;
}

.kpi-temp { --accent: #38bdf8; }
.kpi-humidity { --accent: #60a5fa; }
.kpi-pressure { --accent: #a78bfa; }
.kpi-wind { --accent: #34d399; }
.kpi-battery { --accent: #fbbf24; }

.kpi-head {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 26px;
}

.kpi-icon {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 9px;
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 11%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 18%, transparent);
}

.kpi-icon svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.kpi-label {
  color: var(--text-soft);
  font-size: 11.5px;
  font-weight: 650;
  letter-spacing: 0.01em;
}

.sensor-tag {
  margin-left: auto;
  padding: 2px 6px;
  border: 1px solid rgba(148, 197, 255, 0.12);
  border-radius: 6px;
  color: var(--faint);
  background: rgba(6, 19, 32, 0.48);
  font-size: 8.5px;
  font-weight: 650;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.kpi-main {
  display: flex;
  align-items: baseline;
  gap: 5px;
  margin-top: 13px;
}

.kpi-value {
  color: var(--text);
  font-size: clamp(30px, 2.6vw, 40px);
  font-weight: 640;
  line-height: 1;
  letter-spacing: -0.055em;
  font-variant-numeric: tabular-nums;
}

.kpi-unit {
  color: var(--faint);
  font-size: 12px;
  font-weight: 600;
}

.kpi-sub {
  margin-top: auto;
  padding-top: 12px;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.45;
}

.kpi-sub .sensor-value {
  color: var(--text-soft);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.sensor-dot {
  display: inline-block;
  width: 5px;
  height: 5px;
  margin: 0 4px 1px 0;
  border-radius: 50%;
  vertical-align: middle;
}

.sensor-dot.sht { background: var(--cyan); }
.sensor-dot.bme { background: var(--amber); }

.kpi-sub .sensor-sep {
  display: inline-block;
  width: 1px;
  height: 9px;
  margin: 0 7px;
  background: rgba(148, 197, 255, 0.14);
  vertical-align: middle;
}

.battery-track {
  position: relative;
  height: 4px;
  margin-top: 10px;
  overflow: hidden;
  background: rgba(148, 197, 255, 0.1);
  border-radius: 99px;
}

.battery-track span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, #f59e0b, #fbbf24, #fde68a);
  border-radius: inherit;
  transition: width 0.6s var(--ease);
}

.battery-track span.is-low {
  background: linear-gradient(90deg, #e11d48, #fb7185);
}

.battery-track span.is-mid {
  background: linear-gradient(90deg, #d97706, #fbbf24);
}

.battery-track span.is-high {
  background: linear-gradient(90deg, #059669, #34d399);
}

/* --------------------------------------------------------------- main layout */

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

.panel {
  position: relative;
  background:
    linear-gradient(168deg, rgba(13, 32, 51, 0.8), rgba(6, 18, 31, 0.86));
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md), inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

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

.panel-head h2 {
  font-size: 18px;
  letter-spacing: -0.03em;
}

.panel-sub {
  margin-top: 4px;
  color: var(--faint);
  font-size: 11px;
}

.chart-panel {
  padding: 21px 22px 15px;
  min-width: 0;
}

.chart-head {
  align-items: flex-start;
}

.range-group {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: rgba(5, 17, 29, 0.62);
  border: 1px solid rgba(148, 197, 255, 0.09);
  border-radius: 10px;
}

.range-group button {
  min-width: 41px;
  min-height: 28px;
  padding: 0 9px;
  color: var(--faint);
  background: transparent;
  border: 0;
  border-radius: 7px;
  font-size: 10.5px;
  font-weight: 650;
  transition: color 0.16s, background 0.16s, box-shadow 0.16s;
}

.range-group button:hover {
  color: var(--text-soft);
}

.range-group button.is-active {
  color: #dff6ff;
  background: rgba(14, 116, 144, 0.28);
  box-shadow: inset 0 0 0 1px rgba(56, 189, 248, 0.22);
}

.metric-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin: 17px 0 3px;
  padding-bottom: 1px;
}

.metric-tabs button {
  flex: 0 0 auto;
  min-height: 31px;
  padding: 0 11px;
  color: var(--faint);
  background: transparent;
  border: 0;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 600;
  transition: color 0.16s, background 0.16s;
}

.metric-tabs button:hover {
  color: var(--text-soft);
  background: rgba(125, 211, 252, 0.05);
}

.metric-tabs button.is-active {
  color: var(--cyan-bright);
  background: rgba(56, 189, 248, 0.09);
}

.chart-wrap {
  position: relative;
  height: 340px;
  min-height: 280px;
  margin-top: 7px;
}

#chart {
  display: block;
  width: 100%;
  height: 340px;
  touch-action: pan-y;
}

.chart-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  text-align: center;
  color: var(--muted);
  background: radial-gradient(circle at 50% 45%, rgba(9, 26, 42, 0.55), transparent 65%);
  pointer-events: none;
}

.chart-empty svg {
  width: 34px;
  height: 34px;
  margin-bottom: 5px;
  fill: none;
  stroke: var(--faint);
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.7;
}

.chart-empty strong {
  color: var(--text-soft);
  font-size: 13px;
  font-weight: 600;
}

.chart-empty span {
  max-width: 280px;
  color: var(--faint);
  font-size: 11px;
}

.chart-tooltip {
  position: absolute;
  z-index: 5;
  min-width: 142px;
  padding: 9px 11px;
  border: 1px solid rgba(148, 197, 255, 0.2);
  border-radius: 10px;
  background: rgba(5, 17, 29, 0.96);
  box-shadow: 0 16px 34px -18px rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(12px);
  pointer-events: none;
  transform: translate(-50%, calc(-100% - 13px));
}

.chart-tooltip.is-below {
  transform: translate(-50%, 13px);
}

.tt-time {
  margin-bottom: 5px;
  color: var(--faint);
  font-size: 9.5px;
  font-variant-numeric: tabular-nums;
}

.tt-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 3px;
  color: var(--muted);
  font-size: 10.5px;
  white-space: nowrap;
}

.tt-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
}

.tt-label {
  color: var(--faint);
}

.tt-value {
  margin-left: auto;
  padding-left: 12px;
  color: var(--text);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.chart-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  min-height: 38px;
  margin-top: 4px;
  padding-top: 11px;
  border-top: 1px solid rgba(148, 197, 255, 0.07);
}

.legend {
  display: flex;
  align-items: center;
  gap: 15px;
  flex-wrap: wrap;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 550;
}

.legend-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

.chart-stats {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  color: var(--faint);
  font-size: 10px;
}

.stat-item {
  display: inline-flex;
  gap: 4px;
}

.stat-item b {
  color: var(--text-soft);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* -------------------------------------------------------------------- side */

.side-stack {
  display: grid;
  gap: 16px;
}

.compass-card {
  padding: 19px 20px 17px;
}

.compass-deg {
  color: var(--cyan-bright);
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
}

.compass {
  width: min(100%, 226px);
  margin: 10px auto 4px;
}

.compass svg {
  display: block;
  width: 100%;
  height: auto;
}

.compass-ring {
  fill: none;
  stroke: rgba(148, 197, 255, 0.16);
  stroke-width: 1;
}

.compass-ring-inner {
  fill: none;
  stroke: rgba(148, 197, 255, 0.06);
  stroke-width: 1;
  stroke-dasharray: 2 5;
}

.compass-ticks {
  fill: none;
  stroke: rgba(148, 197, 255, 0.22);
  stroke-width: 1.2;
  stroke-linecap: round;
}

.compass-letter {
  fill: #6d88a2;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 650;
  text-anchor: middle;
}

.compass-n {
  fill: var(--cyan-bright);
}

.compass-needle {
  transform-origin: 110px 110px;
  transition: transform 1.1s cubic-bezier(0.22, 0.8, 0.24, 1);
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.35));
}

.compass-tail {
  fill: rgba(148, 197, 255, 0.22);
}

.compass-center {
  fill: #0b2033;
  stroke: rgba(148, 197, 255, 0.5);
  stroke-width: 1.5;
}

.compass-readout {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 5px;
  padding-top: 3px;
  color: var(--faint);
  font-size: 11px;
}

.compass-readout strong {
  color: var(--text);
  font-size: 19px;
  font-weight: 650;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.compass-dir {
  display: block;
  flex-basis: 100%;
  margin-top: 3px;
  color: var(--muted);
  font-size: 10.5px;
  text-align: center;
}

.station-card {
  padding: 19px 20px 17px;
}

.details-list {
  display: grid;
  gap: 0;
  margin: 15px 0 0;
}

.details-list > div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(148, 197, 255, 0.055);
}

.details-list > div:last-child {
  border-bottom: 0;
}

.details-list dt {
  color: var(--faint);
  font-size: 10.5px;
  white-space: nowrap;
}

.details-list dd {
  margin: 0;
  color: var(--text-soft);
  font-size: 11.5px;
  font-weight: 550;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.demo-note {
  margin-top: 13px;
  padding: 8px 10px;
  color: #fcd34d;
  background: rgba(120, 53, 15, 0.14);
  border: 1px solid rgba(251, 191, 36, 0.14);
  border-radius: 8px;
  font-size: 10px;
  line-height: 1.45;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 23px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(7, 20, 33, 0.55);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  white-space: nowrap;
}

.status-badge::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
}

.status-badge.is-online {
  color: #6ee7b7;
  border-color: rgba(52, 211, 153, 0.22);
  background: rgba(6, 78, 59, 0.18);
}

.status-badge.is-stale {
  color: #fcd34d;
  border-color: rgba(251, 191, 36, 0.22);
  background: rgba(120, 53, 15, 0.18);
}

.status-badge.is-offline {
  color: #fda4af;
  border-color: rgba(251, 113, 133, 0.22);
  background: rgba(127, 29, 29, 0.16);
}

.status-badge.is-unknown {
  color: var(--muted);
}

/* -------------------------------------------------------------------- table */

.table-panel {
  margin-top: 16px;
  padding: 21px 22px 9px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 23px;
  padding: 0 8px;
  border: 1px solid rgba(148, 197, 255, 0.12);
  border-radius: 6px;
  color: var(--faint);
  background: rgba(5, 17, 29, 0.48);
  font-size: 9px;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.table-scroll {
  margin-top: 12px;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  white-space: nowrap;
}

thead th {
  padding: 8px 10px;
  color: var(--faint);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-align: right;
  text-transform: uppercase;
  border-bottom: 1px solid rgba(148, 197, 255, 0.09);
}

thead th:first-child {
  text-align: left;
}

tbody td {
  padding: 9px 10px;
  color: var(--text-soft);
  font-family: var(--mono);
  font-size: 10.5px;
  text-align: right;
  border-bottom: 1px solid rgba(148, 197, 255, 0.045);
  font-variant-numeric: tabular-nums;
}

tbody td:first-child {
  color: var(--muted);
  font-family: var(--font);
  font-size: 10.5px;
  text-align: left;
}

tbody tr:hover td {
  background: rgba(56, 189, 248, 0.035);
}

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

td .value-bad {
  color: var(--faint);
}

.table-empty {
  padding: 26px 10px !important;
  color: var(--faint) !important;
  font-family: var(--font) !important;
  text-align: center !important;
}

/* ------------------------------------------------------------------- footer */

.app-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 30px;
  padding-top: 18px;
  border-top: 1px solid rgba(148, 197, 255, 0.06);
  color: rgba(96, 123, 150, 0.75);
  font-size: 10px;
}

/* -------------------------------------------------------------------- toast */

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 50;
  max-width: min(90vw, 360px);
  padding: 11px 15px;
  color: var(--text-soft);
  background: rgba(9, 27, 44, 0.96);
  border: 1px solid var(--border-strong);
  border-radius: 11px;
  box-shadow: var(--shadow-lg);
  font-size: 12px;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.22s, transform 0.22s;
}

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

.toast.is-error {
  color: #fecdd3;
  border-color: rgba(251, 113, 133, 0.3);
}

/* -------------------------------------------------------------------- error */

.error-page {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
  background:
    radial-gradient(circle at 50% -10%, rgba(14, 165, 233, 0.16), transparent 50%),
    #06111d;
}

.error-card {
  width: min(100%, 420px);
  padding: 34px;
  text-align: center;
  background: linear-gradient(165deg, rgba(15, 35, 55, 0.85), rgba(6, 18, 31, 0.92));
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
}

.error-card .logo-badge {
  margin-bottom: 14px;
}

.error-code {
  margin-top: 7px;
  color: rgba(125, 211, 252, 0.38);
  font-size: 54px;
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.06em;
}

.error-card h1 {
  margin: 8px 0 22px;
  font-size: 18px;
  font-weight: 550;
  color: var(--text-soft);
  letter-spacing: -0.02em;
}

.error-foot {
  margin-top: 20px;
  color: var(--faint);
  font-size: 10px;
}

/* ---------------------------------------------------------------- animations */

@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes drift-slow {
  from { transform: translate3d(-2%, -1%, 0) scale(1); }
  to { transform: translate3d(3%, 2%, 0) scale(1.06); }
}

@keyframes cloud-drift {
  from { transform: translateX(0); }
  to { transform: translateX(calc(100vw + 620px)); }
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

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

@keyframes shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

/* --------------------------------------------------------------- responsive */

@media (max-width: 1240px) {
  .kpi-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 1080px) {
  .dashboard-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .side-stack {
    grid-template-columns: minmax(0, 0.85fr) minmax(0, 1.15fr);
  }
}

@media (max-width: 760px) {
  .topbar {
    grid-template-columns: 1fr auto;
    gap: 10px;
  }

  .topbar-center {
    display: none;
  }

  .user-chip {
    max-width: 120px;
  }

  .page-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 14px;
  }

  .head-actions {
    justify-content: flex-start;
  }

  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .side-stack {
    grid-template-columns: minmax(0, 1fr);
  }

  .app-footer {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .chart-panel,
  .table-panel {
    padding-left: 16px;
    padding-right: 16px;
  }

  .chart-wrap,
  #chart {
    height: 300px;
  }

  .range-group button {
    min-width: 36px;
    padding: 0 7px;
  }

  .refresh-label {
    display: none;
  }
}

@media (max-width: 520px) {
  .app-main {
    padding-top: 22px;
  }

  .login-card {
    padding: 28px 22px 22px;
  }

  .login-brand-text h1 {
    font-size: 24px;
  }

  .kpi-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .kpi {
    min-height: 138px;
  }

  .chart-head {
    flex-direction: column;
  }

  .chart-foot {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .details-list > div {
    padding: 7px 0;
  }

  .brand-name {
    display: none;
  }

  .user-chip {
    display: none;
  }

  .toast {
    right: 12px;
    bottom: 12px;
    left: 12px;
  }
}

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