/* ==========================================================================
   Application Shell, Multi-Pane Workbench Grid, Drawers & Responsive Breakpoints
   ========================================================================== */

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---------- 1. Global Command Bar (52px Sticky Top) ---------- */
.cmd-header {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  background: color-mix(in srgb, var(--bg-surface) 94%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-default);
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.035);
}

.cmd-bar {
  max-width: var(--container-max);
  margin: 0 auto;
  height: var(--cmd-h);
  padding: 0 var(--sp-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
}

.cmd-bar-left {
  display: flex;
  align-items: center;
  gap: 14px;
  height: 100%;
  min-width: 0;
}

.brand-link {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--ink-primary);
  text-decoration: none;
  flex-shrink: 0;
}

.brand-link:hover {
  text-decoration: none;
}

.brand-logo {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  display: block;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.28);
  transition: transform 240ms var(--ease-spring), box-shadow 240ms var(--ease-spring);
}

.brand-link:hover .brand-logo {
  transform: scale(1.08) rotate(-4deg);
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.42);
}

.brand-name {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.brand-cn {
  font-weight: 800;
  font-size: 16.5px;
  letter-spacing: -0.02em;
  color: var(--ink-primary);
}

.brand-domain {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  padding: 2px 7px;
  border-radius: var(--r-pill);
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent-border);
}

.header-vsep {
  width: 1px;
  height: 18px;
  background: var(--border-default);
  flex-shrink: 0;
}

/* Seamless Underline Navigation (Zero heavy pill box) */
.ws-nav {
  display: flex;
  align-items: stretch;
  height: 100%;
  gap: 2px;
}

.ws-tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 100%;
  padding: 0 11px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--ink-secondary);
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  text-decoration: none;
  transition: color 120ms ease;
}

.ws-tab:hover {
  color: var(--ink-primary);
  text-decoration: none;
}

.ws-tab.is-active,
.ws-tab[aria-current="page"] {
  color: var(--accent);
  font-weight: 700;
}

.ws-tab.is-active::after,
.ws-tab[aria-current="page"]::after {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: -1px;
  height: 2.5px;
  border-radius: 2px 2px 0 0;
  background: var(--grad-primary);
}

.ws-tab-count {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 700;
  padding: 0 5px;
  height: 17px;
  line-height: 17px;
  border-radius: var(--r-pill);
  background: var(--bg-subtle);
  color: var(--ink-muted);
}

.ws-tab.is-active .ws-tab-count {
  background: var(--accent-soft);
  color: var(--accent);
}

.ws-tab-count.is-pulse {
  background: var(--ok-bg);
  color: var(--ok-fg);
}

/* Header Utility Cluster */
.cmd-utils {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-shrink: 0;
}

.cmd-search-trigger {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  min-width: 244px;
  padding: 0 11px;
  border-radius: var(--r-pill);
  border: 1px solid var(--border-default);
  background: var(--bg-surface-2);
  color: var(--ink-muted);
  font-size: var(--text-xs);
  text-align: left;
  transition: border-color 120ms ease, background 120ms ease, box-shadow 120ms ease;
}

.cmd-search-trigger:hover {
  border-color: var(--accent-border);
  background: var(--bg-surface);
  color: var(--ink-secondary);
}

.cmd-search-trigger.has-query {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.cmd-search-trigger .kbd-hint {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 1px 5px;
  border-radius: var(--r-xs);
  border: 1px solid var(--border-default);
  background: var(--bg-surface);
  color: var(--ink-muted);
}

/* ---------- 2. Live Telemetry & Centered Market Overview Strip ---------- */
.telemetry-strip {
  position: relative;
  background: var(--bg-surface-2);
  border-bottom: 1px solid var(--border-subtle);
}

.header-sync-bar {
  position: relative;
  width: 100%;
  height: 2px;
  background: color-mix(in srgb, var(--border-subtle) 65%, transparent);
  overflow: hidden;
}

.header-sync-fill {
  display: block;
  height: 100%;
  width: 100%;
  transform-origin: left center;
  transform: scaleX(var(--sync-progress, 0.12));
  background: linear-gradient(90deg, var(--accent) 0%, #06b6d4 52%, var(--ok-dot) 100%);
  opacity: 0.78;
  transition: transform 950ms linear, opacity 200ms ease;
}

.header-sync-fill.is-syncing {
  width: 38%;
  transform: translateX(-100%);
  opacity: 1;
  transition: none;
  animation: scanline-indeterminate 1.25s cubic-bezier(0.4, 0, 0.2, 1) infinite;
}

.telemetry-inner {
  max-width: var(--container-max);
  margin: 0 auto;
  min-height: 40px;
  padding: 5px var(--sp-4);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
}

.telemetry-left {
  display: flex;
  align-items: center;
  gap: 6px;
  justify-self: start;
  flex-wrap: nowrap;
  min-width: 0;
}

.telemetry-center {
  display: flex;
  align-items: center;
  justify-content: center;
  justify-self: center;
  min-width: 0;
}

.telemetry-right {
  display: flex;
  align-items: center;
  gap: 4px;
  justify-self: end;
  flex-wrap: nowrap;
  min-width: 0;
}

/* ---------- 3. Honest Alert Banner Zone ---------- */
.status-banner-wrap {
  max-width: var(--container-max);
  width: 100%;
  margin: var(--sp-2) auto 0;
  padding: 0 var(--sp-4);
}

/* ---------- 4. Main Workspace Canvas ---------- */
.app-main {
  flex: 1;
  max-width: var(--container-max);
  width: 100%;
  margin: 0 auto;
  padding: var(--sp-3) var(--sp-4) 88px;
}

[data-view-panel].is-view-entering {
  animation: view-fade-up 260ms var(--ease-spring) both;
}

/* Full-Width Terminal Layout (Zero nested left scrollbar) */
.terminal-shell {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  min-width: 0;
}

.terminal-canvas {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

/* Mobile-only quick bar & bottom-sheet filter drawer (hidden on desktop) */
.mobile-quick-bar,
.mobile-filter-sheet {
  display: none;
}

.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-drawer);
  background: var(--bg-backdrop);
  backdrop-filter: blur(2px);
}

/* ---------- 5. Slide-Over Drawers (Inspector & Watchlist) ---------- */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-drawer);
  background: var(--bg-backdrop);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: flex;
  justify-content: flex-end;
}

.drawer-backdrop.is-entering {
  animation: backdrop-fade-in 180ms ease-out both;
}

.drawer-panel {
  width: min(var(--inspector-w), 100vw);
  height: 100%;
  background: var(--bg-surface);
  border-left: 1px solid var(--border-default);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.drawer-backdrop.is-entering .drawer-panel {
  animation: drawer-slide-in 280ms var(--ease-spring) both;
}

.drawer-head {
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border-default);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--sp-3);
  background: var(--bg-surface);
  flex-shrink: 0;
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--sp-4) var(--sp-5) var(--sp-6);
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

/* ---------- 6. Compare Dock & Modal ---------- */
.compare-dock {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  z-index: var(--z-dock);
  width: min(860px, calc(100vw - 24px));
  background: color-mix(in srgb, var(--bg-surface) 92%, transparent);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
}

.compare-dock.is-entering {
  animation: dock-float-in 260ms var(--ease-spring) both;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-modal);
  background: var(--bg-backdrop);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
}

.modal-backdrop.is-entering {
  animation: backdrop-fade-in 180ms ease-out both;
}

.modal-shell {
  width: min(1160px, 100%);
  max-height: 90vh;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal-backdrop.is-entering .modal-shell {
  animation: modal-pop-in 250ms var(--ease-spring) both;
}

.modal-head {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-default);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  flex-wrap: wrap;
}

.modal-body {
  flex: 1;
  overflow: auto;
  padding: 0;
}

/* ---------- 7. Command Palette (⌘K) ---------- */
.palette-backdrop {
  position: fixed;
  inset: 0;
  z-index: var(--z-palette);
  background: var(--bg-backdrop);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: min(11vh, 96px) var(--sp-4) var(--sp-4);
}

.palette-backdrop.is-entering {
  animation: backdrop-fade-in 160ms ease-out both;
}

.palette-shell {
  width: min(640px, 100%);
  max-height: 74vh;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.palette-backdrop.is-entering .palette-shell {
  animation: modal-pop-in 220ms var(--ease-spring) both;
}

/* ---------- 8. Toast Notification Stack ---------- */
.toast-region {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast-item {
  pointer-events: auto;
  padding: 10px 14px;
  border-radius: var(--r-md);
  background: var(--ink-primary);
  color: var(--ink-inverse);
  font-size: var(--text-sm);
  font-weight: 500;
  box-shadow: var(--shadow-md);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 340px;
  animation: toast-slide-in 240ms var(--ease-spring) both;
}

/* ---------- 9. Site Footer ---------- */
.site-footer {
  border-top: 1px solid var(--border-default);
  background: var(--bg-surface);
  margin-top: auto;
}

.site-footer-inner {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 16px var(--sp-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  flex-wrap: wrap;
  font-size: var(--text-xs);
  color: var(--ink-muted);
}

.footer-links {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.footer-links a {
  color: var(--ink-secondary);
}

/* ---------- 10. Dossier Subpage Layout (reviews/*.html) ---------- */
.dossier-main {
  max-width: 1120px;
  width: 100%;
  margin: 0 auto;
  padding: var(--sp-5) var(--sp-4) 64px;
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

.dossier-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: var(--sp-4);
  align-items: start;
}

/* ==========================================================================
   Responsive Breakpoints
   ========================================================================== */

@media (max-width: 1280px) {
  .tele-fx-chip {
    display: none !important;
  }
  .cmd-search-trigger {
    min-width: 176px;
  }
}

@media (max-width: 1120px) {
  .telemetry-right {
    display: none;
  }
  .telemetry-inner {
    grid-template-columns: auto 1fr;
  }
  .telemetry-center {
    justify-self: end;
  }
}

@media (max-width: 980px) {
  :root {
    --rail-w: 240px;
  }
  .cmd-bar {
    height: auto;
    padding: 8px var(--sp-3) 0;
    flex-wrap: wrap;
    row-gap: 6px;
  }
  .cmd-bar-left {
    display: contents;
  }
  .header-vsep {
    display: none;
  }
  .brand-link {
    order: 1;
  }
  .cmd-utils {
    order: 2;
    margin-left: auto;
  }
  .ws-nav {
    order: 3;
    flex: 1 0 100%;
    width: 100%;
    height: 36px;
    border-top: 1px solid var(--border-subtle);
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0;
  }
  .ws-tab {
    justify-content: center;
    padding: 0 4px;
    font-size: var(--text-xs);
    gap: 4px;
  }
  .ws-tab-count {
    font-size: 10px;
    padding: 0 4px;
  }
  .cmd-search-trigger {
    min-width: auto;
    padding: 0 9px;
  }
  .cmd-search-trigger .search-label,
  .cmd-search-trigger .kbd-hint {
    display: none;
  }
  .telemetry-inner {
    grid-template-columns: minmax(0, 1fr);
    gap: 6px;
    padding: 6px var(--sp-3);
  }
  .telemetry-center {
    order: 1;
    width: 100%;
    justify-self: stretch;
  }
  .telemetry-left {
    order: 2;
    width: 100%;
    justify-content: space-between;
    flex-wrap: wrap;
  }
  .dossier-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .header-compare-btn {
    display: none;
  }
  .ws-tab-count {
    display: none;
  }
  .compare-dock {
    flex-wrap: nowrap;
    padding: 8px 12px;
  }
}

@media (max-width: 860px) {
  .app-main {
    padding: var(--sp-3);
    padding-bottom: 96px;
  }

  /* Hide Desktop Top Filter Dock on Mobile; use native Quick Bar + Bottom Sheet */
  .filter-dock {
    display: none !important;
  }

  .mobile-filter-sheet {
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto;
    max-height: 86vh;
    overflow-y: auto;
    z-index: calc(var(--z-drawer) + 1);
    background: var(--bg-surface);
    border-top: 1px solid var(--border-default);
    border-radius: 16px 16px 0 0;
    box-shadow: var(--shadow-lg);
    transform: translateY(105%);
    visibility: hidden;
    transition: transform 200ms cubic-bezier(0.22, 1, 0.36, 1), visibility 200ms;
  }
  .mobile-filter-sheet.is-mobile-open {
    transform: translateY(0);
    visibility: visible;
  }
  .mobile-rail-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-default);
    position: sticky;
    top: 0;
    background: var(--bg-surface);
    z-index: 2;
  }
  .mobile-rail-footer {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--border-default);
    position: sticky;
    bottom: 0;
    background: var(--bg-surface);
    z-index: 2;
  }
  .mobile-quick-bar {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  .telemetry-inner {
    padding: 6px var(--sp-3);
  }
  .compare-dock {
    bottom: 10px;
    width: calc(100vw - 16px);
    padding: 8px 10px;
    flex-wrap: wrap;
    gap: 8px;
  }
  .modal-backdrop {
    padding: 8px;
  }
  .modal-shell {
    max-height: 94vh;
  }
  .drawer-panel {
    width: 100vw;
  }
}
