/* QuantWing adaptive navigation.
   One five-button DOM changes geometry only: desktop rail, mobile bottom dock.
   Viewer nodes and bot lifecycle stay untouched. */
:root {
  --qw-desktop-rail-w: 236px;
  --qw-titlebar-h: 44px;
  --qw-mobile-dock-h: 70px;
  --qw-dock-press-duration: 176ms;
  --qw-dock-release-duration: 600ms;
  --qw-dock-spring: cubic-bezier(.2, 1.35, .3, 1);
}

.window-drag-strip { display: none; }

/* Caption controls are fixed to the viewport. Only the mobile nav may scale;
   its header must never establish a transformed/filter containing block. */
body:not(.auth-locked) .app-header {
  transform: none;
  filter: none;
  perspective: none;
  contain: none;
  will-change: auto;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

/* 登入／阻擋畫面也保留同一條無框拖曳面；三顆按鈕仍是 no-drag。 */
html[data-host="tauri"] body.auth-locked .window-drag-region {
  display: block;
  position: fixed;
  inset: 0 138px auto 0;
  z-index: 11990;
  height: var(--qw-titlebar-h);
  border-bottom: 0;
  background: transparent;
  -webkit-app-region: drag;
  user-select: none;
}

@media (min-width: 761px) {
  body:not(.auth-locked) #appShell {
    box-sizing: border-box;
    min-height: 100dvh;
    padding-left: var(--qw-desktop-rail-w);
    padding-top: var(--qw-titlebar-h);
  }

  body:not(.auth-locked) .app-header {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 9000;
    box-sizing: border-box;
    width: var(--qw-desktop-rail-w);
    min-height: 100dvh;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: 0 16px 20px;
    border-right: 1px solid color-mix(in srgb, var(--muted) 18%, transparent);
    border-bottom: 0;
    background: linear-gradient(90deg, rgba(8, 16, 29, .82), rgba(8, 16, 29, .5));
    box-shadow: none;
    /* A backdrop-filter on the header would become the containing block for
       the fixed native window controls and pull them into the rail. */
    backdrop-filter: none;
  }

  body:not(.auth-locked) .app-header .brand {
    width: 100%;
    height: 104px;
    min-width: 0;
    flex: 0 0 104px;
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    padding: 10px 2px 0;
    pointer-events: none;
  }
  body:not(.auth-locked) .app-header .brand-logo {
    width: 46px;
    height: 46px;
    flex: 0 0 46px;
    object-fit: contain;
    filter: none;
  }
  body:not(.auth-locked) .app-header .brand-text {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 0;
  }
  body:not(.auth-locked) .app-header .brand strong {
    display: block;
    color: var(--text);
    font: 700 24px/1 "Segoe UI Variable", "Segoe UI", sans-serif;
    letter-spacing: -.03em;
  }

  body:not(.auth-locked) .app-header .tabs {
    display: flex;
    width: 100%;
    height: auto;
    flex: 0 0 auto;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 12px 0 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }
  body:not(.auth-locked) .app-header .tab {
    width: 100%;
    min-width: 0;
    height: 56px;
    min-height: 56px;
    grid-template-columns: 28px minmax(0, 1fr);
    grid-template-rows: 1fr;
    justify-items: start;
    gap: 14px;
    padding: 0 16px;
    border-color: transparent;
    border-radius: 14px;
    color: var(--muted);
    background: transparent;
    box-shadow: none;
    font-size: 18px;
    font-weight: 600;
    letter-spacing: 0;
  }
  body:not(.auth-locked) .app-header .tab svg { width: 24px; height: 24px; }
  body:not(.auth-locked) .app-header .tab:hover {
    color: var(--text);
    background: color-mix(in srgb, var(--text) 6%, transparent);
    transform: translateX(2px);
  }
  body:not(.auth-locked) .app-header .tab.active {
    color: var(--text);
    border-color: color-mix(in srgb, var(--accent) 20%, transparent);
    background: color-mix(in srgb, var(--accent) 12%, transparent);
    box-shadow: inset 3px 0 var(--accent), inset 0 1px rgb(255 255 255 / 6%);
  }

  body:not(.auth-locked) .app-header .header-status {
    width: 100%;
    margin-top: auto;
    flex-direction: column;
    gap: 10px;
  }
  body:not(.auth-locked) .app-header .header-update-badge,
  body:not(.auth-locked) .app-header .system-status {
    box-sizing: border-box;
    width: 100%;
    min-width: 0;
    min-height: 56px;
    justify-content: flex-start;
    padding: 10px 16px;
    white-space: normal;
  }
  body:not(.auth-locked) .app-header .header-update-badge { font-size: 15px; line-height: 1.4; }
  body:not(.auth-locked) .app-header .header-update-badge::before { margin-right: 6px; font-size: 15px; }
  body:not(.auth-locked) .app-header .system-status { gap: 10px; font-size: 16px; line-height: 1.4; }
  body:not(.auth-locked) .app-header .system-status-text {
    min-width: 0;
    max-width: none;
    overflow-wrap: anywhere;
    white-space: normal;
  }
  body:not(.auth-locked) .app-header .system-status-panel {
    top: auto;
    right: auto;
    bottom: 0;
    left: calc(100% + 12px);
  }

  /* Windows keeps a discoverable drag region beside its caption buttons.
     This strip is the same app surface as the rail, separated only by hairlines. */
  html[data-host="tauri"] body:not(.auth-locked) .window-drag-strip {
    display: block;
    position: fixed;
    inset: 0 138px auto 0;
    z-index: 11990;
    height: var(--qw-titlebar-h);
    border-bottom: 0;
    background: transparent;
    -webkit-app-region: drag;
    user-select: none;
  }
  /* 頂列空間由 appShell 統一保留；2x2 的 main 全高規則不再能把它覆寫掉。 */
}

@media (min-width: 761px) and (max-width: 1100px) {
  :root { --qw-desktop-rail-w: 204px; }
  body:not(.auth-locked) .app-header { padding-inline: 12px; }
  body:not(.auth-locked) .app-header .brand { gap: 8px; padding-inline: 0; }
  body:not(.auth-locked) .app-header .brand-logo { width: 40px; height: 40px; flex-basis: 40px; }
  body:not(.auth-locked) .app-header .tab { padding-inline: 12px; gap: 10px; }
}

@media (max-width: 760px) {
  body:not(.auth-locked) #appShell { padding-left: 0; }
  body:not(.auth-locked) .app-header {
    /* Keep fixed descendants anchored to the viewport, not this header. */
    backdrop-filter: none;
  }
  html[data-host="tauri"] body:not(.auth-locked) .app-header .header-status {
    margin-right: 126px;
  }
  body:not(.auth-locked) .app-header .tabs {
    position: fixed;
    isolation: isolate;
    left: max(12px, env(safe-area-inset-left));
    right: max(12px, env(safe-area-inset-right));
    grid-template-columns: repeat(5, minmax(0, 1fr));
    height: var(--qw-mobile-dock-h);
    bottom: max(10px, env(safe-area-inset-bottom));
    gap: 2px;
    padding: 6px;
    overflow: visible;
    border: 0;
    border-radius: 28px;
    background: transparent;
    box-shadow: none;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    transform-origin: center;
    transition: transform var(--qw-dock-release-duration) var(--qw-dock-spring);
  }
  /* One glass layer, borrowed from the verified TranslationAI mobile dock.
     The nav/text stays opaque and the stars remain visible beneath the tint. */
  body:not(.auth-locked) .app-header .tabs::before {
    content: "";
    position: absolute;
    z-index: -1;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    background: color-mix(in srgb, var(--qw-glass-surface, #152337) 92%, transparent);
    border: 1px solid color-mix(in srgb, var(--muted) 45%, transparent);
    box-shadow: 0 6px 24px rgb(0 0 0 / 5%), inset 0 1px 0 rgb(255 255 255 / 45%);
  }
  @supports ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
    body:not(.auth-locked) .app-header .tabs::before {
      background: color-mix(in srgb, var(--qw-glass-surface, #152337) 62%, transparent);
      -webkit-backdrop-filter: blur(4px) saturate(180%);
      backdrop-filter: blur(4px) saturate(180%);
    }
  }
  body:not(.auth-locked) .app-header .tabs:has(.tab:active) {
    transform: scale(1.043);
    transition-duration: var(--qw-dock-press-duration);
  }
  body:not(.auth-locked) .app-header .tab {
    height: 58px;
    min-height: 52px;
    grid-template-rows: 28px auto;
    align-content: center;
    gap: 3px;
    padding: 3px 1px;
    border: 1px solid transparent;
    border-radius: 23px;
    color: var(--text);
    background: transparent;
    box-shadow: none;
    font-size: clamp(13px, 3.2vw, 14.5px);
    font-weight: 600;
    line-height: 1.1;
    letter-spacing: 0;
    -webkit-tap-highlight-color: transparent;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    transition: color 160ms ease, background 160ms ease, border-color 160ms ease;
  }
  body:not(.auth-locked) .app-header .tab svg { width: 26px; height: 26px; }
  /* Scaling both the dock and each key compounds the movement. */
  body:not(.auth-locked) .app-header .tab:hover,
  body:not(.auth-locked) .app-header .tab:active { transform: none; }
  body:not(.auth-locked) .app-header .tab:hover {
    background: color-mix(in srgb, var(--text) 6%, transparent);
  }
  body:not(.auth-locked) .app-header .tab.active {
    color: var(--text);
    border-color: color-mix(in srgb, var(--text) 10%, transparent);
    background: color-mix(in srgb, var(--text) 14%, transparent);
    box-shadow: inset 0 1px 0 rgb(255 255 255 / 45%);
  }
  body:not(.auth-locked) main {
    padding-bottom: calc(var(--qw-mobile-dock-h) + 34px + env(safe-area-inset-bottom));
  }
  body:not(.auth-locked):has(#internal-browse.panel.active) main {
    padding-bottom: calc(var(--qw-mobile-dock-h) + 22px + env(safe-area-inset-bottom));
  }
}

@media (prefers-reduced-motion: reduce) {
  body:not(.auth-locked) .app-header .tabs,
  body:not(.auth-locked) .app-header .tabs:has(.tab:active) {
    transform: none;
    transition: none;
  }
  body:not(.auth-locked) .app-header .tab { transition: none; }
  body:not(.auth-locked) .app-header .tab:hover,
  body:not(.auth-locked) .app-header .tab:active { transform: none; }
}
