:root {
  --bg-0: #050811;
  --bg-1: #0a1020;
  --bg-2: rgba(13, 21, 38, 0.78);
  --bg-card: rgba(14, 23, 42, 0.72);
  --bg-card-hover: rgba(20, 32, 58, 0.85);
  --border: rgba(56, 189, 248, 0.16);
  --border-strong: rgba(56, 189, 248, 0.38);
  --text-0: #eef4ff;
  --text-1: #9cb0cc;
  --text-2: #647999;
  --cyan: #22d3ee;
  --cyan-glow: rgba(34, 211, 238, 0.22);
  --indigo: #6366f1;
  --emerald: #10b981;
  --amber: #f59e0b;
  --rose: #f43f5e;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 8px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  max-width: 100%;
  overflow-x: clip;
  background: var(--bg-0);
  color: var(--text-0);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

/* Futuristic subtle cyber-grid + radial ambient light */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(circle at 12% 10%, rgba(34, 211, 238, 0.11), transparent 36%),
    radial-gradient(circle at 88% 18%, rgba(99, 102, 241, 0.12), transparent 40%),
    radial-gradient(circle at 50% 95%, rgba(16, 185, 129, 0.06), transparent 42%),
    linear-gradient(rgba(56, 189, 248, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(56, 189, 248, 0.03) 1px, transparent 1px);
  background-size: 100% 100%, 100% 100%, 100% 100%, 36px 36px, 36px 36px;
}

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

.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--text-1); }
.dim { color: var(--text-2); font-size: 12px; }
.hidden { display: none !important; }

/* Top HUD Header */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  background: rgba(5, 8, 17, 0.86);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  font-size: 15px;
}

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--cyan), var(--indigo));
  display: grid;
  place-items: center;
  color: #040812;
  font-weight: 900;
  font-size: 13px;
  box-shadow: 0 0 18px var(--cyan-glow);
}

.brand-sub {
  font-size: 11px;
  color: var(--cyan);
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.hud-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 11px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-1);
}

.pill-cyan { border-color: rgba(34, 211, 238, 0.45); color: var(--cyan); }
.pill-amber { border-color: rgba(245, 158, 11, 0.45); color: #fcd34d; background: rgba(245, 158, 11, 0.1); }
.pill-emerald { border-color: rgba(16, 185, 129, 0.45); color: #6ee7b7; background: rgba(16, 185, 129, 0.1); }
.pill-rose { border-color: rgba(244, 63, 94, 0.45); color: #fda4af; background: rgba(244, 63, 94, 0.1); }

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--emerald);
  box-shadow: 0 0 8px var(--emerald);
}
.dot-amber { background: var(--amber); box-shadow: 0 0 8px var(--amber); }
.dot-rose { background: var(--rose); box-shadow: 0 0 8px var(--rose); }

/* App Shell: Modular Sidebar + Focused Main View */
.app-shell {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  min-height: calc(100vh - 57px);
}

.sidebar {
  padding: 18px 12px;
  border-right: 1px solid var(--border);
  background: rgba(7, 11, 22, 0.72);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.nav-section-label {
  padding: 8px 12px 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-2);
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 13px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-1);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: all 0.16s ease;
}

.nav-btn:hover {
  background: rgba(34, 211, 238, 0.06);
  color: var(--text-0);
}

.nav-btn.active {
  background: linear-gradient(90deg, rgba(34, 211, 238, 0.16), rgba(99, 102, 241, 0.1));
  border-color: rgba(34, 211, 238, 0.36);
  color: var(--text-0);
  box-shadow: inset 2px 0 0 var(--cyan);
}

.nav-icon {
  width: 20px;
  text-align: center;
  font-size: 15px;
  opacity: 0.9;
}

.main-pane {
  padding: 24px 28px 60px;
  max-width: 1220px;
  width: 100%;
  margin: 0 auto;
}

.section-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.section-title {
  margin: 0;
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.section-desc {
  margin: 4px 0 0;
  color: var(--text-1);
  font-size: 13px;
}

/* Cards & Grids */
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  transition: border-color 0.2s ease;
}

.card:hover { border-color: rgba(56, 189, 248, 0.28); }

.card-title {
  margin: 0 0 12px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-0);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.kpi-label { font-size: 12px; color: var(--text-1); margin-bottom: 6px; }
.kpi-value { font-size: 22px; font-weight: 700; font-family: var(--font-mono); letter-spacing: -0.02em; }
.kpi-sub { font-size: 12px; color: var(--text-2); margin-top: 6px; }

/* Timeline track */
.timeline {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.tl-node {
  padding: 14px;
  border-radius: var(--radius-md);
  background: rgba(8, 14, 28, 0.8);
  border: 1px solid var(--border);
  position: relative;
}

.tl-node.active {
  border-color: var(--cyan);
  box-shadow: 0 0 20px rgba(34, 211, 238, 0.14);
}
.tl-node.done { border-color: rgba(16, 185, 129, 0.45); }
.tl-time { font-family: var(--font-mono); font-size: 17px; font-weight: 700; color: var(--cyan); }
.tl-label { font-size: 13px; font-weight: 600; margin-top: 4px; }
.tl-sub { font-size: 11.5px; color: var(--text-2); margin-top: 2px; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: rgba(15, 23, 42, 0.9);
  color: var(--text-0);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn:hover:not(:disabled) {
  border-color: var(--cyan);
  background: rgba(34, 211, 238, 0.12);
}

.btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(135deg, #06b6d4, #4f46e5);
  border-color: transparent;
  color: #ffffff;
  box-shadow: 0 4px 18px rgba(34, 211, 238, 0.22);
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.1);
  background: linear-gradient(135deg, #22d3ee, #6366f1);
}

.btn-danger {
  border-color: rgba(244, 63, 94, 0.45);
  background: rgba(244, 63, 94, 0.12);
  color: #fda4af;
}
.btn-danger:hover:not(:disabled) { background: rgba(244, 63, 94, 0.24); border-color: var(--rose); }

.btn-emerald {
  border-color: rgba(16, 185, 129, 0.45);
  background: rgba(16, 185, 129, 0.14);
  color: #6ee7b7;
}

.btn-sm { padding: 6px 11px; font-size: 12px; }

/* Forms */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field label { font-size: 12px; color: var(--text-1); font-weight: 500; }

input, select, textarea {
  width: 100%;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(6, 10, 20, 0.85);
  color: var(--text-0);
  font-family: inherit;
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s ease;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 2px rgba(34, 211, 238, 0.14);
}

.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-20 { margin-top: 20px; }

/* Tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; border-radius: var(--radius-md); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid rgba(56, 189, 248, 0.08); }
th { background: rgba(8, 14, 28, 0.88); color: var(--text-1); font-weight: 600; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: rgba(34, 211, 238, 0.03); }

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font-mono);
}
.b-ok { background: rgba(16, 185, 129, 0.16); color: #6ee7b7; border: 1px solid rgba(16, 185, 129, 0.35); }
.b-warn { background: rgba(245, 158, 11, 0.16); color: #fcd34d; border: 1px solid rgba(245, 158, 11, 0.35); }
.b-err { background: rgba(244, 63, 94, 0.16); color: #fda4af; border: 1px solid rgba(244, 63, 94, 0.35); }
.b-info { background: rgba(34, 211, 238, 0.14); color: var(--cyan); border: 1px solid rgba(34, 211, 238, 0.35); }
.b-muted { background: rgba(100, 121, 153, 0.16); color: var(--text-1); border: 1px solid rgba(100, 121, 153, 0.3); }

/* Banners & Alerts */
.notice {
  padding: 12px 15px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: rgba(34, 211, 238, 0.06);
  font-size: 12.5px;
  color: var(--text-1);
}
.notice-warn { border-color: rgba(245, 158, 11, 0.4); background: rgba(245, 158, 11, 0.08); color: #fde68a; }
.notice-err { border-color: rgba(244, 63, 94, 0.45); background: rgba(244, 63, 94, 0.08); color: #fecdd3; }
.notice-ok { border-color: rgba(16, 185, 129, 0.45); background: rgba(16, 185, 129, 0.08); color: #a7f3d0; }

/* Code / Address box */
.addr-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: rgba(4, 8, 17, 0.9);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 12px;
  word-break: break-all;
}

/* Toast notifications */
#toast-stack {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 99;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 380px;
}
.toast {
  padding: 11px 15px;
  border-radius: var(--radius-md);
  background: rgba(9, 15, 29, 0.96);
  border: 1px solid var(--border-strong);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  font-size: 13px;
}
.toast-ok { border-color: var(--emerald); color: #a7f3d0; }
.toast-err { border-color: var(--rose); color: #fecdd3; }

/* Step cards for 3-step authorization */
.step-card {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}
.step-num {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-family: var(--font-mono);
  font-weight: 700;
  background: rgba(34, 211, 238, 0.14);
  border: 1px solid rgba(34, 211, 238, 0.4);
  color: var(--cyan);
}
.step-num.done { background: rgba(16, 185, 129, 0.18); border-color: var(--emerald); color: #6ee7b7; }

/* Responsive mobile layout (390px friendly, zero zoom detachment & zero horizontal overflow) */
@media (max-width: 920px) {
  .topbar {
    position: static;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px 14px;
    backdrop-filter: none;
    background: rgba(7, 11, 22, 0.96);
  }
  .brand {
    white-space: nowrap;
    justify-content: flex-start;
  }
  .hud-group {
    width: 100%;
    gap: 6px;
  }
  .hud-group .pill,
  .hud-group .btn {
    font-size: 11.5px;
    padding: 5px 10px;
  }
  .app-shell {
    display: block;
    min-height: auto;
    width: 100%;
    max-width: 100%;
  }
  .sidebar {
    position: static;
    flex-direction: row;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 6px;
    padding: 8px 12px;
    border-right: none;
    border-bottom: 1px solid var(--border);
    background: rgba(7, 11, 22, 0.92);
  }
  .sidebar::-webkit-scrollbar { display: none; }
  .nav-section-label { display: none; }
  .nav-btn {
    width: auto;
    flex: 0 0 auto;
    white-space: nowrap;
    padding: 8px 12px;
    font-size: 12.5px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: rgba(14, 23, 42, 0.72);
  }
  .nav-btn.active {
    box-shadow: none;
    border-color: var(--cyan);
  }
  .main-pane {
    padding: 14px 12px 48px;
    max-width: 100%;
  }
  .card {
    padding: 14px;
    max-width: 100%;
    overflow-wrap: anywhere;
  }
  .section-title { font-size: 18px; }
  .grid-2, .grid-3, .grid-4, .timeline { grid-template-columns: 1fr; }
  /* Prevent iOS Safari / OKX WKWebView auto-zoom on input focus */
  input, select, textarea { font-size: 16px; }
  .addr-box { flex-wrap: wrap; }
  #toast-stack {
    left: 12px;
    right: 12px;
    bottom: 14px;
    max-width: none;
  }
}

/* Interactive Toggle Switch */
.switch-wrap {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}
.switch-wrap input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}
.switch-track {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 26px;
  border-radius: 999px;
  background: rgba(100, 121, 153, 0.36);
  border: 1px solid rgba(148, 163, 184, 0.35);
  transition: background 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
  flex-shrink: 0;
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #e2e8f0;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  transition: transform 0.18s ease, background 0.18s ease;
}
.switch-wrap input[type="checkbox"]:checked + .switch-track {
  background: rgba(16, 185, 129, 0.85);
  border-color: var(--emerald);
  box-shadow: 0 0 12px rgba(16, 185, 129, 0.35);
}
.switch-wrap input[type="checkbox"]:checked + .switch-track::after {
  transform: translateX(20px);
  background: #ffffff;
}
.switch-wrap input[type="checkbox"]:disabled + .switch-track {
  opacity: 0.55;
  cursor: wait;
}
.switch-text {
  font-weight: 600;
  font-size: 13px;
  color: var(--text-0);
}

/* Clickable table rows & Detail Modal */
tr.clickable-row {
  cursor: pointer;
  transition: background 0.14s ease;
}
tr.clickable-row:hover {
  background: rgba(34, 211, 238, 0.08);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 900;
  background: rgba(2, 6, 18, 0.78);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-backdrop.hidden {
  display: none;
}
.modal-dialog {
  width: 100%;
  max-width: 980px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  background: #0b1224;
  border: 1px solid rgba(56, 189, 248, 0.32);
  border-radius: var(--radius-lg);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.65);
  overflow: hidden;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.85);
}
.modal-body {
  padding: 18px 20px 22px;
  overflow-y: auto;
}
.copy-chip {
  cursor: pointer;
  border-bottom: 1px dashed rgba(148, 163, 184, 0.45);
}
.copy-chip:hover {
  color: var(--cyan);
  border-bottom-color: var(--cyan);
}
