/* ==========================================================================
   AxiomForge · 数理经纬 — App Shell, 56px Topbar, Lobby & Drawers Layout
   ========================================================================== */

.app-shell {
  max-width: var(--af-shell-max);
  width: 100%;
  margin: 0 auto;
  padding: 14px 28px 60px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ==================== 1. STRICT 56PX SINGLE-ROW TOPBAR ==================== */

.topbar {
  position: sticky;
  top: 10px;
  z-index: 400;
  height: var(--af-topbar-h);
  min-height: var(--af-topbar-h);
  padding: 0 12px;
  margin-bottom: 18px;
  border-radius: 14px;
  background: color-mix(in srgb, var(--af-surface) 90%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--af-border);
  box-shadow: var(--af-shadow-xs);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
}

.topbar-brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 4px 6px 4px 4px;
  border: none;
  background: transparent;
  cursor: pointer;
  flex-shrink: 0;
  border-radius: 10px;
  transition: background-color 0.15s ease;
}

.topbar-brand:hover {
  background: var(--af-surface-2);
}

.brand-mark {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: var(--af-ink);
  color: #FAFAF9;
}

html[data-theme="dark"] .brand-mark {
  background: linear-gradient(135deg, #6366F1 0%, #4338CA 100%);
  color: #FFFFFF;
}

.brand-text {
  display: flex;
  align-items: baseline;
  gap: 6px;
  white-space: nowrap;
}

.brand-name {
  font-size: 14.5px;
  font-weight: 760;
  letter-spacing: -0.02em;
  color: var(--af-ink);
}

.brand-en {
  font-family: var(--af-font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: var(--af-ink-3);
}

/* Primary 6-Tab Navigation */
.nav-tabs {
  display: flex;
  align-items: center;
  gap: 3px;
  flex-wrap: nowrap;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.nav-tabs::-webkit-scrollbar {
  display: none;
}

.nav-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 11px;
  border-radius: 9px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--af-ink-2);
  font-size: 13px;
  font-weight: 560;
  white-space: nowrap;
  flex-shrink: 0;
  cursor: pointer;
  transition: background-color 0.14s ease, color 0.14s ease, border-color 0.14s ease;
}

.nav-btn:hover {
  background: var(--af-surface-2);
  color: var(--af-ink);
}

html[data-theme="light"] .nav-btn.active {
  background: var(--af-ink);
  color: #FAFAF9;
  border-color: var(--af-ink);
}

html[data-theme="dark"] .nav-btn.active {
  background: rgba(255, 255, 255, 0.12);
  color: #FFFFFF;
  border-color: rgba(255, 255, 255, 0.14);
}

.nav-icon {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  opacity: 0.85;
}

.nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--af-crimson);
  color: #FFFFFF;
  font-family: var(--af-font-mono);
  font-size: 10.5px;
  font-weight: 700;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.nav-badge[hidden] {
  display: none;
}

.nav-ai-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--af-ink-3);
  flex-shrink: 0;
  transition: background-color 0.2s ease, box-shadow 0.2s ease;
}

.nav-ai-dot.ready,
.nav-ai-dot.online,
.nav-ai-dot[data-ready="true"] {
  background: var(--af-emerald);
  box-shadow: 0 0 0 3px var(--af-emerald-soft);
}

/* Topbar Right Utility Actions */
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.topbar-tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 10px;
  border-radius: 9px;
  border: 1px solid var(--af-border-strong);
  background: var(--af-surface);
  color: var(--af-ink-2);
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.14s ease, color 0.14s ease, border-color 0.14s ease;
}

.topbar-tool-btn:hover {
  background: var(--af-surface-2);
  color: var(--af-ink);
  border-color: var(--af-ink-3);
}

.topbar-icon-btn {
  width: 34px;
  padding: 0;
}

#btn-open-account {
  max-width: 170px;
  overflow: hidden;
}

#account-btn-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 118px;
}

html[data-theme="light"] .theme-icon-sun { display: none; }
html[data-theme="light"] .theme-icon-moon { display: inline-flex; }
html[data-theme="dark"] .theme-icon-sun { display: inline-flex; }
html[data-theme="dark"] .theme-icon-moon { display: none; }

/* ==================== 2. VIEW SWITCHING SHELL ==================== */

.view {
  display: none;
  flex: 1 1 auto;
  min-width: 0;
  animation: afViewFade 0.18s ease;
}

.view.active {
  display: block;
}

@keyframes afViewFade {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ==================== 3. LOBBY DUAL-COLUMN HERO ==================== */

.af-hero {
  display: grid;
  grid-template-columns: minmax(0, 0.94fr) minmax(0, 1.06fr);
  gap: 44px;
  align-items: center;
  padding: 26px 0 36px;
}

.af-hero-left {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 0;
}

.af-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--af-font-mono);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--af-accent);
  padding: 4px 11px 4px 9px;
  border-radius: 999px;
  background: var(--af-accent-soft);
  border: 1px solid var(--af-accent-border);
  margin-bottom: 20px;
}

.af-eyebrow::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--af-accent);
  flex-shrink: 0;
}

.af-display-title {
  font-size: clamp(32px, 3.8vw, 50px);
  font-weight: 820;
  letter-spacing: -0.032em;
  line-height: 1.14;
  color: var(--af-ink);
  margin: 0 0 18px;
}

.af-title-accent {
  color: var(--af-accent);
}

.af-hero-lead {
  font-size: 15.5px;
  line-height: 1.66;
  color: var(--af-ink-2);
  max-width: 48ch;
  margin: 0 0 28px;
  font-weight: 450;
}

.af-hero-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 24px;
}

.af-hero-traits {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 10px;
}

.af-trait-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--af-surface);
  border: 1px solid var(--af-border);
  font-size: 12px;
  font-weight: 560;
  color: var(--af-ink-2);
}

.af-trait-dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--af-emerald);
  flex-shrink: 0;
}

.af-hero-right {
  min-width: 0;
}

#hero-sandbox-host {
  width: 100%;
  min-width: 0;
  border-radius: var(--af-radius-xl);
  overflow: hidden;
  box-shadow: var(--af-shadow-stage);
}

/* ==================== 4. STRIPE 4-COLUMN HAIRLINE KPI STRIP ==================== */

.af-kpi-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  background: var(--af-surface);
  border: 1px solid var(--af-border);
  border-radius: var(--af-radius-lg);
  box-shadow: var(--af-shadow-xs);
  overflow: hidden;
  margin-bottom: 32px;
}

.af-kpi-item {
  padding: 18px 20px;
  position: relative;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.af-kpi-item + .af-kpi-item::before {
  content: '';
  position: absolute;
  left: 0;
  top: 18%;
  bottom: 18%;
  width: 1px;
  background: var(--af-border);
}

.af-kpi-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--af-ink-3);
  letter-spacing: 0.01em;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.af-kpi-value {
  font-size: 26px;
  font-weight: 780;
  letter-spacing: -0.025em;
  line-height: 1.15;
  color: var(--af-ink);
  font-variant-numeric: tabular-nums;
}

.af-kpi-denom {
  font-size: 13px;
  font-weight: 560;
  color: var(--af-ink-3);
  margin-left: 2px;
}

.af-kpi-sub {
  font-size: 12px;
  color: var(--af-ink-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.af-kpi-accent .af-kpi-value { color: var(--af-accent); }
.af-kpi-emerald .af-kpi-value { color: var(--af-emerald); }
.af-kpi-amber .af-kpi-value { color: var(--af-amber); }
.af-kpi-crimson .af-kpi-value { color: var(--af-crimson); }

/* ==================== 5. LOBBY 4-DIMENSION CLOSED-LOOP CARDS ==================== */

.af-loop-section {
  margin-bottom: 36px;
}

.af-loop-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.af-loop-head h2 {
  margin: 0;
  font-size: 19px;
  font-weight: 760;
  letter-spacing: -0.02em;
  color: var(--af-ink);
}

.af-loop-head p {
  margin: 4px 0 0;
  font-size: 13.5px;
  color: var(--af-ink-2);
}

.af-loop-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.af-loop-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 14px;
  padding: 20px;
  border-radius: var(--af-radius-lg);
  background: var(--af-surface);
  border: 1px solid var(--af-border);
  box-shadow: var(--af-shadow-xs);
  transition: transform 0.16s ease, border-color 0.16s ease, box-shadow 0.16s ease;
  min-width: 0;
}

.af-loop-card:hover {
  transform: translateY(-2px);
  border-color: var(--af-accent-border);
  box-shadow: var(--af-shadow-sm);
}

.af-loop-num {
  font-family: var(--af-font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--af-accent);
  margin-bottom: 8px;
  display: inline-block;
}

.af-loop-card h3 {
  margin: 0 0 8px;
  font-size: 16px;
  font-weight: 740;
  letter-spacing: -0.015em;
  color: var(--af-ink);
}

.af-loop-card p {
  margin: 0;
  font-size: 13px;
  line-height: 1.58;
  color: var(--af-ink-2);
}

.af-loop-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.af-loop-tag {
  font-family: var(--af-font-mono);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 6px;
  background: var(--af-surface-2);
  color: var(--af-ink-2);
}

.af-loop-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding-top: 10px;
  border-top: 1px solid var(--af-border);
}

/* ==================== 6. FOOTER ==================== */

.af-footer {
  margin-top: 28px;
  padding-top: 18px;
  border-top: 1px solid var(--af-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px 20px;
  font-size: 12.5px;
  color: var(--af-ink-3);
}

.af-footer-brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 560;
}

.af-footer-link {
  color: var(--af-ink-2);
  font-weight: 600;
  text-decoration: underline;
  text-decoration-color: var(--af-border-strong);
  text-underline-offset: 3px;
  transition: color 0.14s ease, text-decoration-color 0.14s ease;
}

.af-footer-link:hover {
  color: var(--af-accent);
  text-decoration-color: var(--af-accent);
}

/* ==================== 7. SLIDE-OUT RIGHT DRAWERS ==================== */

.af-drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: 700;
  background: rgba(9, 10, 15, 0.44);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.af-drawer-backdrop.open,
.af-drawer-backdrop[data-open="true"] {
  opacity: 1;
  pointer-events: auto;
}

.af-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 750;
  width: min(460px, 100vw);
  max-width: 100vw;
  background: var(--af-surface);
  border-left: 1px solid var(--af-border-strong);
  box-shadow: var(--af-shadow-drawer);
  display: flex;
  flex-direction: column;
  transform: translateX(102%);
  transition: transform 0.24s cubic-bezier(0.22, 1, 0.36, 1);
  pointer-events: none;
}

.af-drawer.open,
.af-drawer[aria-hidden="false"] {
  transform: translateX(0);
  pointer-events: auto;
}

.af-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--af-border);
  flex-shrink: 0;
}

.af-drawer-title {
  margin: 0;
  font-size: 16px;
  font-weight: 740;
  letter-spacing: -0.015em;
  color: var(--af-ink);
}

.af-drawer-sub {
  margin: 2px 0 0;
  font-size: 12px;
  color: var(--af-ink-3);
}

.af-drawer-close {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--af-border);
  background: var(--af-surface-2);
  color: var(--af-ink-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color 0.14s ease, color 0.14s ease;
}

.af-drawer-close:hover {
  background: var(--af-surface-hover);
  color: var(--af-ink);
}

.af-drawer-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 18px 20px 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ==================== 8. GLOBAL TOASTS ==================== */

.af-toast-container {
  position: fixed;
  top: 76px;
  right: 24px;
  z-index: 950;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(360px, calc(100vw - 32px));
  pointer-events: none;
}

.af-toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 11px 15px;
  border-radius: 12px;
  background: var(--af-surface);
  border: 1px solid var(--af-border-strong);
  box-shadow: var(--af-shadow-md);
  color: var(--af-ink);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
  animation: afToastIn 0.2s ease;
}

.af-toast.success {
  border-color: var(--af-emerald-border);
  color: var(--af-emerald);
}

.af-toast.error {
  border-color: var(--af-crimson-border);
  color: var(--af-crimson);
}

.af-toast.warn,
.af-toast.warning {
  border-color: var(--af-amber-border);
  color: var(--af-amber);
}

@keyframes afToastIn {
  from {
    opacity: 0;
    transform: translateY(-8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* ==================== 9. RESPONSIVE ADAPTATION (0PX OVERFLOW AT 390PX) ==================== */

@media (max-width: 1120px) {
  .af-hero {
    grid-template-columns: 1fr;
    gap: 28px;
    padding: 18px 0 28px;
  }

  .af-loop-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .brand-en {
    display: none;
  }
}

@media (max-width: 860px) {
  .app-shell {
    padding: 10px 14px 44px;
  }

  .topbar {
    height: auto;
    min-height: 52px;
    padding: 8px 10px;
    flex-wrap: wrap;
    row-gap: 8px;
    top: 6px;
  }

  .topbar-brand {
    order: 1;
  }

  .topbar-actions {
    order: 2;
    margin-left: auto;
  }

  .nav-tabs {
    order: 3;
    flex-basis: 100%;
    width: 100%;
    padding-top: 6px;
    border-top: 1px solid var(--af-border);
    gap: 4px;
  }

  .af-kpi-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .af-kpi-item:nth-child(3)::before {
    display: none;
  }

  .af-kpi-item:nth-child(3),
  .af-kpi-item:nth-child(4) {
    border-top: 1px solid var(--af-border);
  }
}

@media (max-width: 520px) {
  .app-shell {
    padding: 8px 12px 40px;
  }

  .brand-name {
    font-size: 13.5px;
  }

  .topbar-tool-btn .btn-label-hide-sm {
    display: none;
  }

  #btn-open-account {
    max-width: 112px;
    padding: 0 8px;
  }

  .af-display-title {
    font-size: 30px;
  }

  .af-hero-lead {
    font-size: 14.5px;
    margin-bottom: 20px;
  }

  .af-hero-actions {
    width: 100%;
  }

  .af-hero-actions > button {
    flex: 1 1 auto;
  }

  .af-loop-grid {
    grid-template-columns: 1fr;
  }

  .af-kpi-item {
    padding: 14px 14px;
  }

  .af-kpi-value {
    font-size: 22px;
  }

  .af-toast-container {
    right: 12px;
    left: 12px;
    max-width: none;
    top: 116px;
  }
}
