:root {
  --iot-ink: #17263c;
  --iot-slate: #526477;
  --iot-ocean: #126e82;
  --iot-signal: #1f9d78;
  --iot-mist: #f3f7f8;
  --iot-line: #dce6e8;
  --iot-surface: #ffffff;
  --iot-amber: #d38a24;
  --iot-shadow: 0 16px 36px rgba(23, 38, 60, 0.08), 0 2px 7px rgba(23, 38, 60, 0.05);
  --ion-color-primary: #126e82;
  --ion-color-primary-rgb: 18, 110, 130;
  --ion-font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
}

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

html,
body,
#_root,
.product-app {
  min-height: 100%;
  color: var(--iot-ink);
  background: var(--iot-mist);
}

body {
  margin: 0;
  font-family: var(--ion-font-family);
  background: var(--iot-mist);
  -webkit-font-smoothing: antialiased;
}

button,
select,
input {
  font: inherit;
}

.app-header {
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.12), 0 8px 24px rgba(8, 49, 63, 0.16);
}

.app-toolbar {
  --background: #0e6478;
  --color: #fff;
  --min-height: 66px;
}

.app-header__inner {
  width: 100%;
  min-height: 66px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 20px;
  padding: 8px clamp(12px, 2.4vw, 36px);
}

.app-header__utilities,
.app-header__actions {
  display: flex;
  align-items: center;
}

.app-header__utilities {
  justify-self: end;
  gap: 12px;
}

.app-header__actions { gap: 7px; }

.header-action {
  --color: #fff;
  --background: rgba(255, 255, 255, 0.08);
  --background-hover: rgba(255, 255, 255, 0.18);
  --border-radius: 11px;
  width: 40px;
  height: 40px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 11px;
  margin: 0;
}

.app-brand {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  justify-self: start;
  gap: 11px;
  min-width: 0;
}

.app-brand__mark,
.account-intro__signal {
  height: 28px;
  display: inline-flex;
  align-items: flex-end;
  gap: 3px;
}

.app-brand__mark i,
.account-intro__signal i {
  display: block;
  width: 4px;
  border-radius: 8px;
  background: #7ee2c3;
}

.app-brand__mark i:nth-child(1),
.account-intro__signal i:nth-child(1) { height: 10px; }
.app-brand__mark i:nth-child(2),
.account-intro__signal i:nth-child(2) { height: 19px; }
.app-brand__mark i:nth-child(3),
.account-intro__signal i:nth-child(3) { height: 27px; }

.app-brand__title {
  position: static;
  width: auto;
  padding: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.01em;
  line-height: 1.2;
}

.app-brand__subtitle {
  display: block;
  margin-top: 2px;
  color: rgba(255, 255, 255, 0.68);
  font: 600 9px/1.2 "IBM Plex Mono", monospace;
  letter-spacing: 0.16em;
}

.language-select {
  justify-self: end;
  min-height: 38px;
  padding: 0 32px 0 12px;
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 10px;
  background: #0e6478;
  outline: none;
  cursor: pointer;
}

.language-select:focus-visible,
.header-action:focus-visible,
.chart-action:focus-visible {
  outline: 3px solid rgba(126, 226, 195, 0.8);
  outline-offset: 2px;
}

ion-content {
  --background: var(--iot-mist);
}

.dashboard-shell {
  width: min(100%, 1920px);
  min-height: 100%;
  margin: 0 auto;
  padding: clamp(18px, 2.2vw, 34px);
}

.dashboard-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 24px;
  padding: 0 2px 18px;
  border-bottom: 1px solid var(--iot-line);
}

.dashboard-heading__eyebrow,
.account-intro__eyebrow,
.device-card__meta {
  color: var(--iot-ocean);
  font: 600 10px/1.4 "IBM Plex Mono", monospace;
  letter-spacing: 0.13em;
}

.dashboard-heading h1,
.account-intro h1 {
  margin: 5px 0 4px;
  color: var(--iot-ink);
  font-size: clamp(24px, 2.2vw, 34px);
  font-weight: 700;
  letter-spacing: -0.035em;
}

.dashboard-heading p,
.account-intro p {
  margin: 0;
  color: var(--iot-slate);
  font-size: 14px;
}

.device-count {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 10px 14px;
  color: var(--iot-slate);
  border: 1px solid var(--iot-line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.78);
  white-space: nowrap;
}

.device-count strong {
  color: var(--iot-ink);
  font: 600 20px/1 "IBM Plex Mono", monospace;
}

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

.dashboard-tool {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 13px;
  color: var(--iot-ocean);
  border: 1px solid #c9dde0;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.86);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: border-color 150ms ease, background 150ms ease, transform 150ms ease;
}

.dashboard-tool:hover {
  border-color: var(--iot-ocean);
  background: #fff;
  transform: translateY(-1px);
}

.dashboard-tool:focus-visible,
.password-visibility:focus-visible {
  outline: 3px solid rgba(18, 110, 130, 0.24);
  outline-offset: 2px;
}

.dashboard-tool ion-icon { font-size: 17px; }

.device-count__pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--iot-signal);
  box-shadow: 0 0 0 5px rgba(31, 157, 120, 0.12);
}

.device-wall {
  column-count: 4;
  column-gap: 18px;
  padding: 2px;
  background-image: radial-gradient(circle, rgba(18, 110, 130, 0.08) 1px, transparent 1px);
  background-size: 20px 20px;
}

.device-tile {
  display: inline-block;
  width: 100%;
  margin: 0 0 18px;
  break-inside: avoid;
  vertical-align: top;
}

.device-card,
.device-tile > ion-card {
  width: 100%;
  margin: 0;
  overflow: hidden;
  color: var(--iot-ink);
  border: 1px solid rgba(18, 110, 130, 0.13);
  border-radius: 16px;
  background: var(--iot-surface);
  box-shadow: var(--iot-shadow);
}

.device-card::before,
.device-tile > ion-card::before {
  content: "";
  display: block;
  width: 100%;
  height: 4px;
  background: linear-gradient(90deg, var(--iot-ocean), var(--iot-signal));
}

.device-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 17px 16px 14px 18px;
}

.device-card__identity {
  min-width: 0;
}

.device-card__identity ion-card-title {
  margin-top: 4px;
  overflow: hidden;
  color: var(--iot-ink);
  font-size: 19px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chart-action {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  margin: 0;
  --color: var(--iot-ocean);
  --background: #eaf5f5;
  --background-hover: #d8eeee;
  --border-radius: 12px;
}

.device-card__section {
  margin: 0;
  padding: 0 12px 10px;
  background: transparent;
}

.device-card__section--control {
  margin: 4px 12px 14px;
  padding: 4px;
  border: 1px solid #dfe9e8;
  border-radius: 14px;
  background: #f7faf9;
}

.resource-row--control {
  --min-height: 72px;
  --padding-start: 10px;
  --inner-padding-end: 10px;
}

.device-control {
  width: 100%;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 22px;
  padding: 8px 0;
}

.device-control__copy {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.device-control__name {
  color: var(--iot-ink);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
}

.device-control__status {
  color: var(--iot-slate);
  font: 600 10px/1.2 "IBM Plex Mono", monospace;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.device-card__section-title {
  min-height: auto;
  padding: 10px 7px 6px;
  color: var(--iot-slate);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
}

.resource-row {
  --min-height: 45px;
  --padding-start: 7px;
  --inner-padding-end: 7px;
  --background: transparent;
  --border-color: var(--iot-line);
  font-size: 14px;
}

.resource-row:not(:last-child) {
  border-bottom: 1px solid var(--iot-line);
}

.resource-row ion-icon {
  color: var(--iot-ocean);
  font-size: 18px;
}

.resource-row ion-label:last-of-type {
  color: var(--iot-ink) !important;
  font-family: "IBM Plex Mono", "Noto Sans TC", monospace;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.resource-row ion-avatar {
  width: 38px;
  height: 38px;
}

.resource-row ion-select {
  min-width: 96px;
  color: var(--iot-ink);
}

.resource-row hr {
  display: none;
}

.device-switch {
  position: relative;
  flex: 0 0 auto;
  width: 52px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: #cbd6d9;
  box-shadow: inset 0 0 0 1px rgba(23, 38, 60, 0.08);
  cursor: pointer;
  transition: background 160ms ease, box-shadow 160ms ease;
}

.device-switch__thumb {
  position: absolute;
  top: 4px;
  left: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 7px rgba(23, 38, 60, 0.25);
  transition: transform 160ms ease;
}

.device-switch--on {
  background: var(--iot-signal);
  box-shadow: 0 0 0 4px rgba(31, 157, 120, 0.11);
}

.device-switch--on .device-switch__thumb {
  transform: translateX(22px);
}

.device-switch:focus-visible {
  outline: 3px solid rgba(18, 110, 130, 0.28);
  outline-offset: 3px;
}

.dashboard-state {
  min-height: 240px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--iot-ocean);
  border: 1px dashed #b9ced2;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.62);
}

.dashboard-state ion-icon {
  font-size: 32px;
}

.dashboard-state strong,
.dashboard-state span {
  display: block;
}

.dashboard-state strong { color: var(--iot-ink); }
.dashboard-state span { margin-top: 3px; color: var(--iot-slate); font-size: 13px; }

.app-tab-bar {
  width: min(100%, 480px);
  min-height: calc(62px + env(safe-area-inset-bottom, 0px));
  margin: 0 auto;
  border: 1px solid var(--iot-line);
  border-bottom: 0;
  border-radius: 18px 18px 0 0;
  --background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 -8px 28px rgba(23, 38, 60, 0.08);
}

.app-tab-bar ion-tab-button {
  --color: #71808f;
  --color-selected: var(--iot-ocean);
  --ripple-color: rgba(18, 110, 130, 0.18);
  font-weight: 600;
}

.app-tab-bar--guest ion-tab-button {
  max-width: 240px;
  margin: 0 auto;
}

.account-shell {
  width: min(100% - 32px, 980px);
  min-height: calc(100% - 40px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 430px);
  align-items: center;
  gap: clamp(36px, 8vw, 100px);
  margin: 20px auto;
  padding: clamp(20px, 5vw, 64px);
  border-radius: 24px;
  background-color: #eaf3f3;
  background-image: radial-gradient(circle at 18% 22%, rgba(31, 157, 120, 0.14), transparent 28%),
    linear-gradient(135deg, rgba(255,255,255,0.84), rgba(234,243,243,0.9));
}

.account-intro__signal {
  height: 46px;
  margin-bottom: 20px;
}

.account-intro__signal i { width: 7px; background: var(--iot-signal); }
.account-intro__signal i:nth-child(1) { height: 18px; }
.account-intro__signal i:nth-child(2) { height: 31px; }
.account-intro__signal i:nth-child(3) { height: 45px; }

.account-card {
  margin: 0;
  border: 1px solid rgba(18, 110, 130, 0.13);
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 22px 54px rgba(23, 38, 60, 0.14);
}

.account-card ion-card-content {
  padding: 24px;
}

.field-label {
  display: block;
  margin: 0 0 7px 2px;
  color: var(--iot-slate);
  font-size: 12px;
  font-weight: 600;
}

.account-field {
  margin-bottom: 18px;
  --min-height: 52px;
  --padding-start: 14px;
  --inner-padding-end: 12px;
  --background: #f5f8f8;
  --border-radius: 11px;
  border: 1px solid var(--iot-line);
  border-radius: 11px;
}

.account-field:focus-within {
  border-color: var(--iot-ocean);
  box-shadow: 0 0 0 3px rgba(18, 110, 130, 0.11);
}

.account-field ion-icon { color: var(--iot-ocean); }

.password-visibility {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  padding: 0;
  color: var(--iot-ocean);
  border: 0;
  border-radius: 9px;
  background: transparent;
  cursor: pointer;
}

.password-visibility:hover { background: #e8f2f3; }
.password-visibility ion-icon { font-size: 21px; }

.primary-action,
.secondary-action {
  height: 48px;
  margin: 10px 0 0;
  font-weight: 700;
  --border-radius: 11px;
}

.primary-action {
  --background: var(--iot-ocean);
  --background-hover: #0c5a6c;
  --box-shadow: 0 9px 20px rgba(18, 110, 130, 0.22);
}

.secondary-action {
  --color: var(--iot-ocean);
  --border-color: #b8cfd3;
}

/* Historical data page */
#i1ykj,
#if2ku {
  width: min(100% - 32px, 1540px);
  margin: 20px auto;
  padding: 18px;
  border: 1px solid var(--iot-line);
  border-radius: 16px;
  background: #fff;
  box-shadow: var(--iot-shadow);
}

#i1ykj ion-row {
  align-items: end;
  gap: 12px 0;
}

#i1ykj ion-label {
  display: block;
  margin-bottom: 8px;
  color: var(--iot-slate);
  font-size: 12px;
  font-weight: 600;
}

#i508h {
  width: 100%;
  height: 44px;
  margin: 0;
  --background: var(--iot-ocean);
  --border-radius: 10px;
}

#i8rbm {
  position: relative;
  height: clamp(360px, 64vh, 680px);
  min-height: 360px !important;
}

#i8rbm canvas {
  width: 100% !important;
  height: 100% !important;
}

@media (max-width: 1450px) {
  .device-wall { column-count: 3; }
}

@media (max-width: 980px) {
  .device-wall { column-count: 2; }
  .account-shell {
    grid-template-columns: 1fr;
    max-width: 620px;
    gap: 28px;
  }
  .account-intro { text-align: center; }
}

@media (max-width: 640px) {
  .app-toolbar { --min-height: 58px; }
  .app-header__inner {
    min-height: 58px;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    padding: 6px 8px;
  }
  .app-header__utilities { gap: 7px; }
  .app-header__actions { gap: 4px; }
  .header-action { width: 34px; height: 34px; }
  .app-brand { gap: 7px; }
  .app-brand__mark { display: none; }
  .app-brand__title { font-size: 16px; }
  .app-brand__subtitle { display: none; }
  .language-select {
    width: 68px;
    min-height: 34px;
    padding: 0 6px;
    font-size: 12px;
  }
  .dashboard-shell { padding: 16px 12px 84px; }
  .dashboard-heading {
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 14px;
  }
  .dashboard-heading h1 { font-size: 22px; }
  .dashboard-heading p { display: none; }
  .dashboard-heading__tools { flex-wrap: nowrap; gap: 6px; }
  .dashboard-tool { width: 38px; min-height: 38px; padding: 0; }
  .dashboard-tool span { display: none; }
  .device-count { padding: 8px 11px; }
  .device-count strong { font-size: 17px; }
  .device-count span:last-child { display: none; }
  .device-wall { column-count: 1; background: none; }
  .device-tile { margin-bottom: 12px; }
  .device-card,
  .device-tile > ion-card { border-radius: 14px; }
  .device-card__header { padding: 14px 12px 11px 15px; }
  .device-card__identity ion-card-title { font-size: 18px; }
  .account-shell {
    width: 100%;
    min-height: 100%;
    margin: 0;
    padding: 32px 16px 90px;
    border-radius: 0;
  }
  .account-intro__signal { display: none; }
  .account-intro h1 { font-size: 25px; }
  .account-card ion-card-content { padding: 20px 16px; }
  #i1ykj,
  #if2ku {
    width: calc(100% - 20px);
    margin: 10px auto;
    padding: 12px;
    border-radius: 13px;
  }
  #i8rbm { height: 52vh; min-height: 320px !important; }
}

@media (prefers-reduced-motion: no-preference) {
  .device-tile {
    animation: device-enter 360ms ease both;
  }
  .device-tile:nth-child(2n) { animation-delay: 35ms; }
  .device-tile:nth-child(3n) { animation-delay: 70ms; }
  @keyframes device-enter {
    from { opacity: 0; transform: translateY(7px); }
    to { opacity: 1; transform: translateY(0); }
  }
}

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