:root {
  color-scheme: dark;
  --portal-bg: #050811;
  --portal-surface: #0a1220;
  --portal-surface-strong: #0d1728;
  --portal-line: rgba(0, 229, 255, .2);
  --portal-line-soft: rgba(140, 184, 211, .14);
  --portal-text: #f3f8ff;
  --portal-muted: #8293aa;
  --portal-cyan: #20e2f2;
  --portal-blue: #0879ff;
  --portal-orange: #ff9168;
  font-family: Inter, "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  color: var(--portal-text);
  background: var(--portal-bg);
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--portal-bg); }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--portal-text);
  background:
    radial-gradient(circle at 17% 25%, rgba(0, 200, 255, .09), transparent 24rem),
    radial-gradient(circle at 88% 80%, rgba(44, 98, 255, .1), transparent 28rem),
    linear-gradient(135deg, #05070d 0%, #070b14 48%, #03050a 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  opacity: .24;
  background-image:
    linear-gradient(rgba(45, 202, 255, .035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(45, 202, 255, .035) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: linear-gradient(to bottom, black, transparent 72%);
}

.top {
  min-height: 70px;
  padding: 0 clamp(18px, 5vw, 70px);
  border-bottom: 1px solid var(--portal-line-soft);
  background: rgba(3, 7, 13, .88);
  box-shadow: 0 12px 36px rgba(0, 0, 0, .22);
  backdrop-filter: blur(18px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: #eef9ff;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: .08em;
}

.brand::before {
  content: "M";
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  color: #03121a;
  border-radius: 9px 3px 9px 3px;
  background: linear-gradient(135deg, var(--portal-cyan), #fff 54%, var(--portal-blue));
  box-shadow: 0 0 24px rgba(0, 229, 255, .28);
  font-size: 15px;
  font-weight: 900;
  letter-spacing: 0;
  transform: skewX(-7deg);
}

.portal-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 9px;
}

.portal-actions .button {
  white-space: nowrap;
  text-decoration: none;
}

.wrap {
  width: min(1180px, calc(100% - 36px));
  margin: 0 auto;
  padding: 46px 0 72px;
}

.login {
  position: relative;
  overflow: hidden;
  width: min(440px, 100%);
  max-width: none;
  margin: clamp(28px, 7vh, 84px) auto 0;
  padding: 34px 32px 30px;
  border: 1px solid rgba(0, 229, 255, .3);
  border-radius: 22px;
  background: linear-gradient(145deg, rgba(17, 27, 45, .97), rgba(7, 13, 24, .98));
  box-shadow: 0 30px 75px rgba(0, 0, 0, .55), 0 0 42px rgba(0, 194, 255, .09), inset 0 1px rgba(255, 255, 255, .025);
}

.login::before {
  content: "";
  position: absolute;
  width: 240px;
  height: 240px;
  top: -170px;
  right: -90px;
  border-radius: 50%;
  background: rgba(0, 229, 255, .18);
  filter: blur(42px);
  pointer-events: none;
}

.login h1 {
  position: relative;
  margin: 0 0 8px;
  color: #f6fbff;
  font-size: 23px;
  line-height: 1.25;
  letter-spacing: -.02em;
}

.login > .hint { margin: 0 0 22px; }

.hint,
.muted,
.meta {
  color: var(--portal-muted);
  line-height: 1.65;
}

.hint { font-size: 12px; }

.field {
  margin: 15px 0 7px;
  color: #52d8e8;
  font-size: 12px;
  font-weight: 650;
}

.input {
  width: 100%;
  min-height: 43px;
  padding: 10px 13px;
  border: 1px solid rgba(118, 159, 188, .2);
  border-radius: 8px;
  outline: none;
  color: #f5f9ff;
  background: rgba(2, 8, 17, .7);
  box-shadow: inset 0 1px 4px rgba(0, 0, 0, .32);
  transition: border-color .2s, box-shadow .2s, background .2s;
}

.input:hover { border-color: rgba(0, 229, 255, .34); }

.input:focus {
  border-color: rgba(0, 229, 255, .7);
  background: rgba(4, 13, 25, .92);
  box-shadow: 0 0 0 3px rgba(0, 229, 255, .09), inset 0 1px 4px rgba(0, 0, 0, .32);
}

select.input {
  appearance: auto;
  color-scheme: dark;
}

.button {
  min-height: 39px;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: #fff;
  background: linear-gradient(100deg, var(--portal-blue), #00d8f3);
  box-shadow: 0 10px 24px rgba(0, 120, 255, .2);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .18s, filter .18s, border-color .18s, background .18s;
}

.button:hover {
  background: linear-gradient(100deg, #168aff, #1deaf4);
  filter: brightness(1.07);
  transform: translateY(-1px);
}

.button:focus-visible { outline: 2px solid var(--portal-cyan); outline-offset: 3px; }
.button:disabled { opacity: .55; cursor: wait; transform: none; }

.button.secondary {
  color: #96e8f2;
  border-color: rgba(0, 229, 255, .24);
  background: rgba(5, 21, 34, .78);
  box-shadow: none;
}

.button.secondary:hover {
  color: #fff;
  border-color: rgba(0, 229, 255, .5);
  background: rgba(9, 43, 62, .82);
}

.login form > .button[type="submit"] {
  width: 100%;
  margin-top: 24px;
  background: linear-gradient(100deg, #0877ff 3%, #00e4ee 98%);
}

.login > p:last-child {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin: 8px 0 0;
}

.login > p:last-child .button { flex: 1 1 170px; }

.status {
  min-height: 20px;
  margin: 12px 0 0;
  color: #ff8b80;
  font-size: 12px;
  line-height: 1.55;
}

.hidden { display: none !important; }

#dashboard-view > #welcome {
  margin: 0 0 28px;
  color: #eef6ff;
  font-size: clamp(19px, 2.2vw, 28px);
  font-weight: 650;
  letter-spacing: -.02em;
}

#dashboard-view > #welcome::first-letter { color: var(--portal-cyan); }

.grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.card {
  position: relative;
  min-width: 0;
  overflow: hidden;
  padding: 21px;
  border: 1px solid var(--portal-line-soft);
  border-radius: 13px;
  color: var(--portal-text);
  background: linear-gradient(145deg, rgba(11, 23, 38, .94), rgba(5, 14, 26, .95));
  box-shadow: 0 18px 42px rgba(0, 0, 0, .2), inset 0 1px rgba(255, 255, 255, .022);
}

.card::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: radial-gradient(circle at 100% 0, rgba(0, 213, 255, .1), transparent 36%);
}

.card > * { position: relative; z-index: 1; }

.card h2 {
  margin: 0 0 14px;
  color: #f4f9ff;
  font-size: 14px;
  font-weight: 650;
}

.grid > .card:nth-child(-n+3) {
  min-height: 178px;
  border-color: rgba(0, 229, 255, .17);
}

.grid > .card:nth-child(1) .metric { color: #5ee7f2; }
.grid > .card:nth-child(2) .metric { color: #45c9ff; }
.grid > .card:nth-child(3) .metric { color: #9fd7ff; }

.metric {
  margin: 3px 0 8px;
  font-size: 30px;
  font-weight: 760;
  line-height: 1;
  text-shadow: 0 0 22px rgba(0, 229, 255, .18);
}

.wide { grid-column: span 2; }
.full { grid-column: 1 / -1; }

.card p:last-child { margin-bottom: 0; }
.card .button + .button { margin-left: 7px; }

.list {
  display: grid;
  gap: 0;
  margin: 0;
  padding: 0;
  list-style: none;
}

.item {
  padding: 12px 0;
  border-top: 1px solid rgba(139, 179, 205, .1);
}

.item:first-child { padding-top: 0; border-top: 0; }

.item-title {
  color: #dcecff;
  font-size: 13px;
  font-weight: 650;
  line-height: 1.5;
  word-break: break-word;
}

.meta { font-size: 12px; }

.device-button {
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  color: inherit;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.device-button:hover .item-title { color: var(--portal-cyan); }

.detail {
  margin-top: 18px;
  padding: 18px;
  border: 1px solid rgba(0, 229, 255, .25);
  border-radius: 10px;
  color: var(--portal-text);
  background: rgba(1, 11, 22, .75);
}

.detail h3 { margin: 0 0 13px; color: #78e9f3; font-size: 15px; }

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 11px 20px;
}

.detail-grid div { min-width: 0; }
.detail-grid span { display: block; color: var(--portal-muted); font-size: 11px; }
.detail-grid strong { color: #e9f5ff; font-size: 12px; word-break: break-word; }

#bind-wizard {
  width: min(580px, 100%);
  justify-self: center;
  padding: 26px;
  border-color: rgba(0, 229, 255, .34);
  box-shadow: 0 28px 70px rgba(0, 0, 0, .46), 0 0 36px rgba(0, 194, 255, .08);
}

#bind-wizard h2 { color: #57e6f1; font-size: 17px; }
#bind-wizard .input { max-width: 100%; }
#bind-wizard input[type="checkbox"] { accent-color: var(--portal-cyan); }

@media (max-width: 800px) {
  .top { min-height: 62px; padding: 0 16px; }
  .brand { font-size: 12px; letter-spacing: .03em; }
  .brand::before { width: 28px; height: 28px; }
  .wrap { width: min(100% - 24px, 1180px); padding: 24px 0 50px; }
  .login { margin-top: 18px; padding: 27px 20px 23px; border-radius: 17px; }
  .grid { grid-template-columns: 1fr; gap: 12px; }
  .wide, .full { grid-column: auto; }
  .grid > .card:nth-child(-n+3) { min-height: 0; }
  .detail-grid { grid-template-columns: 1fr; }
  .card { padding: 18px; }
  .card .button + .button { margin: 7px 0 0; }
  #logout { min-height: 34px; padding: 7px 10px; font-size: 11px; }
  .portal-actions { gap: 6px; }
  .portal-actions .button { min-height: 34px; padding: 7px 9px; font-size: 11px; }
}

@media (max-width: 430px) {
  .brand { max-width: 230px; }
  .top { align-items: flex-start; flex-direction: column; gap: 10px; padding-top: 13px; padding-bottom: 13px; }
  .portal-actions { width: 100%; justify-content: flex-start; }
  .login > p:last-child { display: grid; }
  .login > p:last-child .button { width: 100%; }
  .button { max-width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
