:root {
  color-scheme: dark;
  --card-opacity: .82;
  --bg: #070b10;
  --panel: rgba(17, 24, 34, .86);
  --panel-solid: #101822;
  --line: rgba(255, 255, 255, .13);
  --line-strong: rgba(255, 255, 255, .24);
  --text: #f6f8fb;
  --muted: #a8b3c2;
  --soft: #d8e0ea;
  --green: #5ee0a0;
  --blue: #7cb7ff;
  --gold: #f5c15f;
  --red: #ff7d88;
  --shadow: 0 22px 70px rgba(0, 0, 0, .38);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  font-family: Inter, "Microsoft YaHei", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
  overflow-x: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button,
.open-link {
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
  background: rgba(255, 255, 255, .075);
  padding: 9px 13px;
  cursor: pointer;
  text-decoration: none;
  transition: transform .14s ease, background .14s ease, border-color .14s ease;
}

button:hover,
.open-link:hover {
  transform: translateY(-1px);
  border-color: var(--line-strong);
  background: rgba(255, 255, 255, .13);
}

button:disabled {
  opacity: .45;
  cursor: default;
}

.hidden {
  display: none !important;
}

.login {
  width: 100vw;
  height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(390px, 100%);
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(12, 18, 27, .9);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.login-panel h1 {
  margin: 0 0 8px;
  font-size: 28px;
  letter-spacing: 0;
}

.login-panel p {
  margin: 0 0 22px;
  color: var(--muted);
}

.login-panel input,
.dialog-body input,
.dialog-body textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, .075);
  color: var(--text);
  padding: 12px;
  outline: none;
}

.login-panel input:focus,
.dialog-body input:focus,
.dialog-body textarea:focus {
  border-color: rgba(94, 224, 160, .72);
}

.login-panel button {
  width: 100%;
  margin-top: 14px;
}

.error {
  min-height: 22px;
  margin-top: 12px;
  color: var(--red);
}

.app {
  width: 100vw;
  height: 100vh;
  padding: clamp(12px, 1.6vw, 24px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  flex: 0 0 auto;
  height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(8, 13, 20, .68);
  box-shadow: 0 14px 42px rgba(0, 0, 0, .24);
  backdrop-filter: blur(16px);
}

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

.brand-icon,
.monogram {
  display: grid;
  place-items: center;
  border-radius: 16px;
  color: #071117;
  background: linear-gradient(145deg, #eff6ff, #9fe7c2);
  font-weight: 800;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.68), 0 10px 28px rgba(0,0,0,.22);
}

.brand-icon {
  width: 48px;
  height: 48px;
  font-size: 25px;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(22px, 2vw, 30px);
  letter-spacing: 0;
}

.topbar p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.icon-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 14px;
  font-size: 19px;
}

.notice {
  margin: 12px 0;
  padding: 11px 13px;
  border: 1px solid rgba(94, 224, 160, .34);
  border-radius: 14px;
  background: rgba(94, 224, 160, .12);
}

.grid {
  position: relative;
  width: 100%;
  flex: 1 1 auto;
  min-height: 180px;
  height: auto;
  margin-top: 16px;
  border: 1px solid rgba(255, 255, 255, .08);
  border-radius: 20px;
  overflow-y: auto;
  overflow-x: hidden;
  background: transparent;
}

.card {
  position: absolute;
  min-width: 180px;
  min-height: 150px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(16, 24, 35, var(--card-opacity));
  box-shadow: var(--shadow);
  overflow: hidden;
  outline: none;
  backdrop-filter: blur(16px);
  user-select: none;
  touch-action: none;
  transition: border-color .14s ease, transform .14s ease, box-shadow .14s ease;
}

.card:hover,
.card:focus {
  border-color: rgba(124, 183, 255, .54);
  box-shadow: 0 30px 90px rgba(0, 0, 0, .46);
}

.card.dragging,
.card.resizing {
  z-index: 50;
  transform: scale(1.015);
}

.card.snapping {
  border-color: rgba(94, 224, 160, .76);
}

.card-scale {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr;
}

.card-visual {
  position: relative;
  height: clamp(62px, 28%, 112px);
  padding: 14px;
  display: flex;
  align-items: center;
  background:
    linear-gradient(135deg, rgba(255, 125, 136, .92), rgba(174, 42, 58, .82)),
    linear-gradient(180deg, #32131a, #15090d);
  background-position: center;
  background-size: cover;
}

.online .card-visual {
  background:
    linear-gradient(135deg, rgba(94, 224, 160, .88), rgba(124, 183, 255, .78)),
    linear-gradient(180deg, #172331, #0f1722);
}

.monogram {
  position: relative;
  z-index: 1;
  width: 48px;
  height: 48px;
  font-size: 23px;
}

.card-content {
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  background-position: center;
  background-size: cover;
}

.has-card-image .card-content {
  background-image: var(--card-image);
}

.status-badge {
  position: absolute;
  z-index: 1;
  right: 58px;
  top: 13px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 10px;
  border: 1px solid rgba(255, 255, 255, .22);
  border-radius: 999px;
  background: rgba(5, 9, 14, .42);
  font-size: 12px;
  font-weight: 700;
}

.card-gear {
  position: absolute;
  z-index: 2;
  right: 12px;
  top: 10px;
  width: 38px;
  height: 38px;
  border-radius: 13px;
  background: rgba(5, 9, 14, .44);
}

.card-header {
  padding: 13px 14px 5px;
}

.card h2 {
  margin: 0;
  font-size: clamp(17px, calc(14px + var(--scale) * 4px), 22px);
  line-height: 1.22;
  letter-spacing: 0;
}

.card .desc {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.card-body {
  min-height: 0;
  padding: 5px 14px 14px;
  display: grid;
  align-content: space-between;
  gap: 11px;
}

.meta {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
}

.meta span {
  min-width: 0;
  padding: 7px;
  border: 1px solid rgba(255, 255, 255, .07);
  border-radius: 12px;
  background: rgba(255, 255, 255, .045);
  overflow: hidden;
  text-overflow: ellipsis;
}

.meta b {
  display: block;
  margin-bottom: 3px;
  color: var(--soft);
}

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 0 4px rgba(255, 125, 136, .16);
}

.online .dot {
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(94, 224, 160, .16);
}

.card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.open-link {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
  color: var(--text);
}

.resize {
  position: absolute;
  right: 9px;
  bottom: 9px;
  width: 20px;
  height: 20px;
  border-right: 2px solid rgba(255, 255, 255, .58);
  border-bottom: 2px solid rgba(255, 255, 255, .58);
  cursor: nwse-resize;
}

.metrics-panel {
  flex: 0 0 auto;
  margin-top: 16px;
}

.metrics-shell {
  border: 1px solid var(--line);
  border-radius: 22px;
  background: rgba(8, 13, 20, .58);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  overflow: hidden;
}

.metrics-shell.unavailable {
  padding-bottom: 0;
}

.metrics-head {
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.metrics-identity,
.metrics-status,
.metric-pill,
.metric-card-title,
.metric-health,
.metric-row,
.metric-ranges {
  display: flex;
  align-items: center;
}

.metrics-identity {
  min-width: 0;
  gap: 14px;
}

.metrics-logo {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, .14);
  background: rgba(5, 9, 14, .52);
  font-weight: 800;
  font-size: 25px;
}

.metrics-identity strong {
  min-width: 0;
  color: #ff5f67;
  font-size: clamp(18px, 2vw, 26px);
  font-weight: 650;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metrics-status {
  justify-content: flex-end;
  gap: 9px;
  color: var(--soft);
}

.metric-pill {
  min-height: 42px;
  gap: 8px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, .045);
  font-weight: 700;
}

.metric-pill.ip {
  color: #75a8ff;
  font-weight: 800;
}

.metric-pill.offline .dot {
  background: var(--red);
  box-shadow: 0 0 0 4px rgba(255, 125, 136, .16);
}

.metric-clock {
  color: var(--soft);
  white-space: nowrap;
}

.metrics-grid {
  display: grid;
  grid-template-columns: minmax(320px, .9fr) minmax(360px, 1.1fr);
  gap: 16px;
  padding: 16px;
}

.metric-card {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(16, 24, 35, calc(var(--card-opacity) * .78));
  box-shadow: 0 18px 55px rgba(0, 0, 0, .28);
  backdrop-filter: blur(16px);
  padding: 18px;
}

.metric-card-title {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.metric-card-title h2,
.traffic-head h3 {
  margin: 0;
  letter-spacing: 0;
}

.metric-card-title h2 {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: clamp(19px, 2vw, 28px);
}

.metric-title-icon {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(124, 183, 255, .16);
  color: var(--blue);
  font-size: 18px;
}

.metric-health {
  gap: 9px;
  color: var(--soft);
  white-space: nowrap;
}

.metric-uptime {
  color: var(--muted);
}

.cpu-panel {
  min-height: 190px;
  display: grid;
  grid-template-columns: 190px 1fr;
  align-items: center;
  gap: 18px;
  padding: 18px;
  border: 1px solid rgba(255, 255, 255, .09);
  border-radius: 16px;
  background: rgba(255, 255, 255, .035);
}

.cpu-ring {
  width: min(160px, 100%);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background:
    radial-gradient(circle at center, rgba(16, 24, 35, .9) 0 57%, transparent 58%),
    conic-gradient(var(--green) calc(var(--cpu) * 1%), rgba(255, 255, 255, .12) 0);
  box-shadow: inset 0 0 0 12px rgba(255, 255, 255, .035);
}

.cpu-ring span {
  font-size: clamp(28px, 4vw, 42px);
  font-weight: 800;
}

.cpu-copy {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.cpu-copy span,
.metric-row {
  color: var(--soft);
}

.cpu-copy strong {
  font-size: 24px;
}

.cpu-copy small {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
}

.metric-progress-block {
  display: grid;
  gap: 10px;
  margin-top: 16px;
  padding: 14px;
  border: 1px solid rgba(255, 255, 255, .09);
  border-radius: 16px;
  background: rgba(255, 255, 255, .035);
}

.metric-row {
  justify-content: space-between;
  gap: 12px;
}

.metric-row strong {
  color: var(--soft);
}

.metric-row.muted {
  color: var(--muted);
}

.metric-progress {
  height: 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .14);
  overflow: hidden;
}

.metric-progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
}

.metric-progress .green {
  background: linear-gradient(90deg, #80e27e, #67d391);
}

.metric-progress .blue {
  background: linear-gradient(90deg, #6ea1ff, #4f83ff);
}

.metric-ranges {
  gap: 4px;
  padding: 4px;
  border: 1px solid rgba(245, 193, 95, .46);
  border-radius: 14px;
  background: rgba(255, 255, 255, .035);
}

.metric-range-btn {
  min-width: 70px;
  border-color: transparent;
  border-radius: 10px;
  background: transparent;
  padding: 9px 12px;
}

.metric-range-btn.active {
  color: #ffe07c;
  border-color: rgba(245, 193, 95, .54);
  background: rgba(245, 193, 95, .13);
}

.traffic-block {
  display: grid;
  gap: 8px;
  padding: 16px 18px 12px;
  border: 1px solid rgba(255, 255, 255, .09);
  border-radius: 16px;
  background: rgba(255, 255, 255, .035);
}

.traffic-block + .traffic-block {
  margin-top: 14px;
}

.traffic-head h3 {
  font-size: 18px;
}

.traffic-head > div {
  display: flex;
  gap: 18px;
  color: var(--muted);
  white-space: nowrap;
}

.metric-chart-svg {
  width: 100%;
  height: 136px;
  display: block;
}

.metric-chart-grid {
  stroke: rgba(255, 255, 255, .1);
  stroke-width: 1;
}

.metric-chart-area {
  fill: var(--metric-line);
  opacity: .2;
}

.metric-chart-line {
  fill: none;
  stroke: var(--metric-line);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.metric-axis {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 13px;
}

dialog {
  width: min(620px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--panel-solid);
  color: var(--text);
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(0, 0, 0, .58);
}

.settings-dialog {
  width: min(720px, calc(100vw - 28px));
}

.logs-dialog {
  width: min(980px, calc(100vw - 28px));
  height: min(720px, calc(100vh - 28px));
  resize: both;
  overflow: auto;
}

.dialog-body {
  display: grid;
  gap: 16px;
}

.dialog-titlebar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.dialog-body h2,
.settings-section h3 {
  margin: 0;
  letter-spacing: 0;
}

.settings-section {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, .045);
}

.settings-actions,
.quick-backgrounds,
.file-row {
  display: flex;
  gap: 9px;
  flex-wrap: wrap;
}

.settings-note {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.totp-setup {
  display: grid;
  gap: 12px;
}

.totp-qr-wrap {
  display: flex;
  justify-content: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, .92);
}

.totp-qr {
  width: min(260px, 100%);
  aspect-ratio: 1;
  image-rendering: pixelated;
}

#totpSecret,
#totpUri {
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  word-break: break-all;
}

.dialog-body label {
  display: grid;
  gap: 7px;
  color: var(--muted);
}

.dialog-body input[type="range"] {
  padding: 0;
}

.device-form {
  min-width: min(560px, calc(100vw - 48px));
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.dialog-actions.split {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
}

.danger-button {
  border-color: rgba(255, 125, 136, .45);
  color: #ffd8dc;
}

.logs {
  min-height: 0;
  max-height: none;
  overflow: auto;
  display: grid;
  gap: 8px;
}

.log-row {
  display: grid;
  grid-template-columns: 180px 80px 1fr;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--muted);
  background: rgba(255, 255, 255, .045);
}

.log-row .ok {
  color: var(--green);
}

.log-row .bad {
  color: var(--red);
}

.log-pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.empty {
  padding: 18px;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 12px;
}

@media (max-width: 760px) {
  body {
    overflow: auto;
  }

  .app {
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .topbar {
    height: auto;
    align-items: flex-start;
  }

  .brand {
    align-items: flex-start;
  }

  .metrics-head,
  .metrics-status,
  .metric-card-title,
  .metric-row,
  .traffic-head > div {
    align-items: flex-start;
  }

  .metrics-head,
  .metrics-status,
  .metric-card-title,
  .traffic-head > div {
    flex-direction: column;
  }

  .metrics-grid,
  .cpu-panel {
    grid-template-columns: 1fr;
  }

  .metrics-grid {
    padding: 12px;
  }

  .metrics-identity strong {
    white-space: normal;
  }

  .metric-ranges {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metric-range-btn {
    min-width: 0;
  }

  .cpu-ring {
    width: 150px;
  }

  .grid {
    height: 1150px;
  }

  .meta,
  .form-grid,
  .log-row {
    grid-template-columns: 1fr;
  }

  .dialog-actions.split {
    grid-template-columns: 1fr;
  }
}
