:root {
  color-scheme: dark;
  --bg: #08111f;
  --surface: rgba(17, 29, 50, 0.78);
  --surface-strong: rgba(24, 39, 67, 0.96);
  --line: rgba(148, 163, 184, 0.18);
  --text: #eef6ff;
  --muted: #90a4c3;
  --primary: #38bdf8;
  --primary-strong: #0ea5e9;
  --accent: #a78bfa;
  --success: #34d399;
  --warning: #fbbf24;
  --danger: #fb7185;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.36);
  font-family: Inter, "Microsoft YaHei", "PingFang SC", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  height: 100%;
  touch-action: manipulation;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(56, 189, 248, 0.28), transparent 34rem),
    radial-gradient(circle at 80% 20%, rgba(167, 139, 250, 0.22), transparent 30rem),
    linear-gradient(135deg, #07101d 0%, #0b1220 52%, #101827 100%);
  -webkit-font-smoothing: antialiased;
}

body.view-login {
  overflow: hidden;
  height: 100dvh;
  min-height: 100dvh;
  max-height: 100dvh;
}

body.view-dashboard {
  overflow-x: hidden;
  overflow-y: auto;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

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

button:active:not(:disabled) {
  transform: scale(0.98);
}

[hidden] {
  display: none !important;
}

.app-main {
  display: grid;
  place-items: start center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 34px 20px 32px;
  padding:
    max(16px, env(safe-area-inset-top, 0px))
    max(16px, env(safe-area-inset-right, 0px))
    max(16px, env(safe-area-inset-bottom, 0px))
    max(16px, env(safe-area-inset-left, 0px));
}

body.view-login .app-main {
  place-items: center;
  min-height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  padding:
    max(12px, env(safe-area-inset-top, 0px))
    max(14px, env(safe-area-inset-right, 0px))
    max(12px, env(safe-area-inset-bottom, 0px))
    max(14px, env(safe-area-inset-left, 0px));
}

body.view-dashboard .app-main {
  place-items: start center;
  min-height: 100dvh;
}

.dashboard-card {
  width: min(100%, 420px);
  padding: 24px 20px 20px;
  border-radius: 28px;
  border: 1px solid rgba(148, 163, 184, 0.22);
  background: linear-gradient(180deg, rgba(24, 39, 67, 0.92) 0%, rgba(17, 29, 50, 0.88) 100%);
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px);
}

body.view-dashboard .dashboard-card {
  width: min(100%, 420px);
  margin-bottom: 16px;
}

.dashboard-head {
  display: flex;
  align-items: stretch;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.dashboard-head-device {
  flex-direction: column;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.14);
}

.dashboard-head-device .head-block-device {
  width: 100%;
}

.head-block-device input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid rgba(148, 163, 184, 0.16);
  border-radius: 14px;
  background: rgba(8, 17, 31, 0.72);
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
  text-align: center;
}

.head-block-device input:focus {
  outline: none;
  border-color: rgba(56, 189, 248, 0.45);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.12);
}

.dashboard-head-stats {
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(148, 163, 184, 0.14);
}

.head-block {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 0;
  text-align: center;
}

.head-block-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.head-block-value {
  width: 100%;
  color: var(--text);
  font-size: 18px;
  font-weight: 800;
  line-height: 1.3;
  word-break: break-all;
}

.head-block-value.gradient {
  font-size: 22px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.action-row.two-cols {
  grid-template-columns: 1fr 1fr;
}

.action-row.three-cols {
  grid-template-columns: 1fr 1fr 1fr;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
}

.dashboard-section + .dashboard-section {
  margin-top: 14px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.section-head-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.section-head-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.section-toggle-label {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.switch-compact {
  width: 38px;
  height: 22px;
}

.switch-compact .switch-slider::before {
  width: 16px;
  height: 16px;
  left: 3px;
  bottom: 3px;
}

.switch-compact input:checked + .switch-slider::before {
  transform: translateX(16px);
}

.section-head .link-btn {
  margin-left: auto;
}

.section-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.45);
  flex-shrink: 0;
}

.section-title-text {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.link-btn {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--primary);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  text-decoration: none;
}

body.view-dashboard .dashboard-card {
  display: flex;
  flex-direction: column;
  max-height: calc(100dvh - 24px);
}

body.view-dashboard #accountSection {
  flex: 1 1 auto;
  min-height: 0;
}

.dashboard-section {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.account-list-scroll {
  flex: 1 1 auto;
  min-height: 120px;
  max-height: min(48vh, 360px);
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  padding-right: 2px;
}

.account-list-scroll.has-items {
  display: grid;
  gap: 8px;
  align-content: start;
}

.account-list-scroll:not(.has-items) {
  display: block;
}

.account-item {
  display: flex;
  align-items: stretch;
  gap: 10px;
  width: 100%;
  padding: 10px 11px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  background: rgba(8, 17, 31, 0.55);
  color: var(--text);
  text-align: left;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.account-item.is-unused {
  border-color: rgba(56, 189, 248, 0.28);
  background: linear-gradient(135deg, rgba(8, 28, 48, 0.72) 0%, rgba(8, 20, 36, 0.62) 100%);
  box-shadow: inset 0 0 0 1px rgba(56, 189, 248, 0.08);
}

.account-item.is-unused .account-item-name {
  color: #e0f2fe;
}

.account-item.is-unused .account-item-meta {
  color: #7dd3fc;
}

.account-item.is-used {
  border-color: rgba(148, 163, 184, 0.14);
  background: rgba(10, 16, 26, 0.42);
}

.account-item.is-used .account-item-name {
  color: #94a3b8;
}

.account-item.is-used .account-item-meta {
  color: #64748b;
}

.account-item-body {
  flex: 1;
  min-width: 0;
}

.account-item-actions {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
  width: 46px;
  margin-top: 0;
}

.account-delete-btn:disabled {
  opacity: 0.55;
}

.account-used-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.account-used-label {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.switch {
  position: relative;
  display: inline-block;
  width: 42px;
  height: 24px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
  margin: 0;
  padding: 0;
}

.switch-slider {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.28);
  transition: background 0.2s ease;
  cursor: pointer;
}

.switch-slider::before {
  content: "";
  position: absolute;
  left: 3px;
  bottom: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.2s ease;
}

.switch input:checked + .switch-slider {
  background: linear-gradient(135deg, var(--primary), var(--success));
}

.switch input:checked + .switch-slider::before {
  transform: translateX(18px);
}

.switch input:disabled + .switch-slider {
  opacity: 0.55;
  cursor: not-allowed;
}

.account-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.account-item-name {
  font-size: 13px;
  font-weight: 700;
  line-height: 1.35;
}

.account-item-sub {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
}

.account-item-meta {
  margin-top: 10px;
  color: #64748b;
  font-size: 11px;
  line-height: 1.45;
}

.account-item-meta-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.account-item-meta-row .account-item-remark {
  flex: 1;
  min-width: 0;
  text-align: right;
  word-break: break-all;
}

.confirm-mask {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(0, 0, 0, 0.62);
  touch-action: none;
}

.confirm-mask[hidden] {
  display: none !important;
}

.confirm-dialog {
  width: min(100%, 320px);
  padding: 22px 20px 18px;
  border-radius: 18px;
  border: 1px solid rgba(148, 163, 184, 0.24);
  background: #152238;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

.confirm-title {
  margin: 0 0 12px;
  color: #eef6ff;
  font-size: 17px;
  font-weight: 800;
  line-height: 1.4;
  text-align: center;
}

.confirm-message {
  margin: 0 0 18px;
  min-height: 48px;
  color: #eef6ff;
  font-size: 15px;
  line-height: 1.7;
  text-align: center;
  word-break: break-word;
}

.confirm-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.confirm-actions .btn {
  padding: 12px 16px;
  font-size: 14px;
}

.confirm-actions .btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.empty-hint {
  margin: 0;
  padding: 16px;
  border-radius: 16px;
  border: 1px dashed rgba(148, 163, 184, 0.22);
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
  text-align: center;
  background: rgba(8, 17, 31, 0.28);
}

.loading-hint {
  margin: 0;
  padding: 16px;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 38px;
  padding: 3px 6px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  background: rgba(148, 163, 184, 0.12);
  color: var(--muted);
  flex-shrink: 0;
}

.status-badge[data-state="yes"] {
  background: rgba(52, 211, 153, 0.15);
  color: var(--success);
}

.status-badge[data-state="no"] {
  background: rgba(56, 189, 248, 0.16);
  color: var(--primary);
}

.status-badge-btn {
  margin: 0;
  border: 0;
  padding: 3px 6px;
  cursor: pointer;
  font-size: 10px;
  font-weight: 700;
  line-height: 1.2;
  appearance: none;
  -webkit-appearance: none;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.status-badge-btn:active:not(:disabled) {
  transform: scale(0.96);
  opacity: 0.88;
}

.result-panel {
  margin-top: 14px;
  padding: 16px;
  border-radius: 18px;
  border: 1px solid rgba(148, 163, 184, 0.14);
  background: rgba(8, 17, 31, 0.62);
}

.result-title {
  margin: 0 0 10px;
  font-size: 16px;
  font-weight: 800;
  line-height: 1.4;
}

.qr-preview {
  display: flex;
  justify-content: center;
  margin: 12px 0 16px;
}

.qr-preview img {
  width: 200px;
  height: 200px;
  border-radius: 16px;
  border: 1px solid rgba(148, 163, 184, 0.18);
  background: #fff;
  padding: 8px;
}

.url-box {
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(8, 17, 31, 0.72);
  color: #c9e6ff;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 11px;
  line-height: 1.55;
  word-break: break-all;
}

.action-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 14px;
}

.btn {
  width: 100%;
  padding: 14px 24px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 800;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.btn.primary {
  color: #03111f;
  background: linear-gradient(135deg, var(--primary), var(--success));
  box-shadow: 0 16px 36px rgba(56, 189, 248, 0.26);
}

.btn.ghost {
  color: var(--text);
  border: 1px solid var(--line);
  background: rgba(148, 163, 184, 0.12);
}

.account-item-actions .btn {
  width: 100%;
  min-width: 0;
  padding: 5px 0;
  font-size: 11px;
  font-weight: 700;
  min-height: 28px;
  border-radius: 8px;
  white-space: nowrap;
}

.account-item-actions .btn.primary {
  box-shadow: 0 4px 12px rgba(56, 189, 248, 0.18);
}

.account-item-actions .account-delete-btn {
  color: #fff;
  background: linear-gradient(135deg, #fb7185, #e11d48);
  box-shadow: 0 4px 12px rgba(251, 113, 133, 0.16);
}

.details-panel {
  margin-top: 14px;
  border-radius: 16px;
  border: 1px solid rgba(148, 163, 184, 0.14);
  background: rgba(8, 17, 31, 0.38);
  overflow: hidden;
}

.details-panel summary {
  padding: 12px 14px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.details-panel summary::-webkit-details-marker {
  display: none;
}

.details-body {
  padding: 0 14px 14px;
  display: grid;
  gap: 8px;
}

.detail-row {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.02);
}

.detail-key {
  color: var(--primary);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.detail-value {
  color: var(--text);
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  word-break: break-all;
}

.detail-note {
  color: var(--muted);
  font-size: 11px;
}

.dashboard-toast {
  position: fixed;
  top: 50%;
  left: 50%;
  z-index: 1000;
  min-width: min(88vw, 280px);
  max-width: 420px;
  padding: 14px 18px;
  border-radius: 16px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.5;
  text-align: center;
  color: #ecfdf5;
  background: rgba(16, 36, 32, 0.94);
  border: 1px solid rgba(52, 211, 153, 0.35);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.38);
  backdrop-filter: blur(16px);
  transform: translate(-50%, calc(-50% + 10px));
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
}

.dashboard-toast.is-visible {
  opacity: 1;
  transform: translate(-50%, -50%);
}

.dashboard-toast.is-warning {
  color: #ffe4e6;
  background: rgba(40, 18, 24, 0.94);
  border-color: rgba(251, 113, 133, 0.35);
}

.login-card {
  width: min(100%, 360px);
  max-width: calc(100vw - 28px);
  max-height: calc(100dvh - 24px);
  padding: 20px 18px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(22px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

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

.login-header h2 {
  margin: 0;
  font-size: 24px;
  letter-spacing: -0.03em;
}

.login-subtitle {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.login-subtitle.access-url {
  margin-top: 8px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.55);
  word-break: break-all;
}

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

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

.field span {
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}

.field input {
  width: 100%;
  padding: 13px 15px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(8, 17, 31, 0.55);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.field input:focus {
  border-color: rgba(56, 189, 248, 0.45);
  box-shadow: 0 0 0 4px rgba(56, 189, 248, 0.12);
}

.field input::placeholder {
  color: #64748b;
}

.form-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
}

.checkbox input {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
}

.form-error {
  margin: 0;
  padding: 12px 14px;
  border-radius: 16px;
  color: #fecdd3;
  font-size: 14px;
  background: rgba(251, 113, 133, 0.12);
  border: 1px solid rgba(251, 113, 133, 0.28);
}

.btn.stop {
  color: #fff;
  background: linear-gradient(135deg, #fb7185, #e11d48);
  box-shadow: 0 16px 36px rgba(251, 113, 133, 0.24);
}

.dashboard-actions {
  margin-top: 8px;
}

@media (max-width: 375px) {
  .login-header h2 {
    font-size: 22px;
  }

  .login-subtitle {
    font-size: 13px;
  }

  .field input {
    padding: 12px 14px;
    font-size: 16px;
  }

  .btn {
    padding: 13px 18px;
    font-size: 14px;
  }

  .dashboard-card {
    padding: 18px 16px 16px;
    border-radius: 22px;
  }

  .head-block-value {
    font-size: 16px;
  }

  .account-item {
    padding: 9px 10px;
    gap: 8px;
  }

  .account-item-name {
    font-size: 12px;
  }

  .account-item-meta {
    font-size: 10px;
  }

  .account-item-actions {
    gap: 4px;
    width: 42px;
  }

  .account-item-actions .btn {
    min-height: 26px;
    padding: 4px 8px;
    font-size: 10px;
  }
}

@media (max-height: 667px) {
  body.view-login .app-main {
    padding-top: max(8px, env(safe-area-inset-top, 0px));
    padding-bottom: max(8px, env(safe-area-inset-bottom, 0px));
  }

  .login-card {
    padding: 16px 14px;
  }

  .login-form {
    gap: 12px;
  }

  .login-header {
    margin-bottom: 12px;
  }
}
