/**
 * Boyig shell — Apple Settings / Finder sidebar language.
 * Requires boyig-tokens.css (+ optional boyig-components.css) first.
 */
:root {
  --by-sidebar-w: var(--sidebar-w, 232px);
  --by-sidebar-bg: var(--glass);
  --by-sidebar-solid: var(--bg-elevated);
  --by-surface: var(--fill);
  --by-surface-hover: var(--fill-hover);
  --by-surface-active: var(--accent-soft);
  --by-ink: var(--text);
  --by-ink-2: var(--text-secondary);
  --by-ink-3: var(--text-tertiary);
  --by-line: var(--separator);
  --by-tint: var(--tint);
  --by-accent: var(--accent);
  --by-radius: var(--radius-sm, 8px);
  --by-spring: var(--spring);
}

.by-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 100vh;
  max-height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--by-ink);
  font: 100%/1.47 var(--font);
  -webkit-font-smoothing: antialiased;
  font-optical-sizing: auto;
}

/* Full-bleed topbar + body row (sidebar under topbar) */
.by-shell > .by-topbar {
  flex-shrink: 0;
  width: 100%;
  position: relative;
  top: auto;
  z-index: 50;
}

.by-shell-body {
  display: flex;
  flex: 1;
  min-height: 0;
  min-width: 0;
}

/* Desktop icon rail: 56px slot, labels overlay on hover/pin (AIGC + BoDict).
   Below 1024px the slot is display:contents so BoDict’s 820px bottom tabs still work. */
.by-rail-slot,
.by-aigc-rail-slot {
  display: contents;
}

.by-rail-pin {
  display: none;
  flex-shrink: 0;
  width: 2.25rem;
  height: 2.25rem;
  align-items: center;
  justify-content: center;
  padding: 0;
  border-radius: 999px;
  border: 0.5px solid var(--by-line);
  background: transparent;
  color: var(--by-ink-3);
  cursor: pointer;
  transition: color 120ms var(--ease-out), background 120ms var(--ease-out), transform 100ms var(--ease-out);
}
.by-rail-pin:hover {
  color: var(--by-ink);
  background: var(--by-surface);
}
.by-rail-pin:active { transform: scale(0.97); }

@media (min-width: 1024px) {
  .by-rail-pin {
    display: inline-flex;
  }

  .by-shell-body > .by-rail-slot,
  .by-shell-body > .by-aigc-rail-slot {
    display: block;
    position: relative;
    width: 56px;
    flex-shrink: 0;
    align-self: stretch;
    z-index: 45;
  }

  .by-rail-slot .by-sidebar,
  .by-aigc-rail-slot .by-sidebar {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 56px;
    height: auto;
    display: flex;
    overflow: hidden;
    transition: width 180ms cubic-bezier(0.25, 0.1, 0.25, 1), box-shadow 180ms ease;
  }

  .by-rail-slot.is-expanded .by-sidebar,
  .by-aigc-rail-slot.is-expanded .by-sidebar {
    width: 200px;
    box-shadow: 8px 0 28px rgba(0, 0, 0, 0.22);
  }

  .by-rail-slot:not(.is-expanded) .by-nav-section,
  .by-rail-slot:not(.is-expanded) .by-nav-label,
  .by-rail-slot:not(.is-expanded) .by-nav-extra,
  .by-aigc-rail-slot:not(.is-expanded) .by-nav-section,
  .by-aigc-rail-slot:not(.is-expanded) .by-nav-label,
  .by-aigc-rail-slot:not(.is-expanded) .by-nav-extra {
    display: none !important;
  }

  .by-rail-slot:not(.is-expanded) .by-nav,
  .by-aigc-rail-slot:not(.is-expanded) .by-nav {
    padding-left: 0.35rem;
    padding-right: 0.35rem;
    align-items: stretch;
  }

  .by-rail-slot:not(.is-expanded) .by-nav-item,
  .by-aigc-rail-slot:not(.is-expanded) .by-nav-item {
    justify-content: center;
    gap: 0;
    padding-left: 0;
    padding-right: 0;
  }

  .by-rail-slot:not(.is-expanded) .by-sidebar-footer,
  .by-aigc-rail-slot:not(.is-expanded) .by-sidebar-footer {
    align-items: center;
    padding-left: 0.35rem;
    padding-right: 0.35rem;
  }
}

.by-sidebar {
  width: var(--by-sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  top: auto;
  height: auto;
  align-self: stretch;
  z-index: 40;
  background: var(--by-sidebar-bg);
  backdrop-filter: blur(40px) saturate(180%);
  -webkit-backdrop-filter: blur(40px) saturate(180%);
  border-right: 0.5px solid var(--by-line);
}

/* AIGC: desktop rail vs mobile drawer (avoids Tailwind hidden/lg:flex clash) */
.by-sidebar--desktop {
  display: none;
}
@media (min-width: 1024px) {
  .by-sidebar--desktop {
    display: flex;
  }
}
.by-sidebar--drawer {
  display: flex;
  height: 100%;
  position: relative;
}

.by-sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.95rem 0.9rem 0.7rem;
  text-decoration: none;
  color: inherit;
  transition: opacity 120ms var(--ease-out), transform 100ms var(--ease-out);
}
.by-sidebar-brand:hover { opacity: 0.88; }
.by-sidebar-brand:active { transform: scale(0.98); }

.by-mark {
  font-family: var(--font-bo);
  font-size: 1.4rem;
  font-weight: 400;
  line-height: 1.15;
  color: var(--by-ink);
  letter-spacing: 0;
}

.by-logo {
  display: block;
  width: 2rem;
  height: 2rem;
  object-fit: contain;
  flex-shrink: 0;
}

.by-logo-wordmark {
  display: block;
  height: 2rem;
  width: auto;
  max-width: 9.5rem;
  min-width: 4.5rem;
  object-fit: contain;
  object-position: left center;
  flex-shrink: 0;
}

.by-brand-text { min-width: 0; flex: 1; }
.by-brand-name {
  display: block;
  font-size: var(--text-callout);
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.2;
  color: var(--by-ink);
}
.by-brand-sub {
  display: block;
  margin-top: 0.1rem;
  font-size: var(--text-caption);
  color: var(--by-ink-3);
  letter-spacing: 0.01em;
  line-height: 1.3;
}

.by-apps {
  display: flex;
  gap: 0.15rem;
  padding: 0 0.7rem 0.35rem;
}
.by-theme-rail {
  margin: 0 0.7rem 0.65rem;
  width: auto;
}
.by-app {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 1.8rem;
  padding: 0.2rem;
  border-radius: 7px;
  font-size: var(--text-caption);
  font-weight: 500;
  letter-spacing: 0.01em;
  text-decoration: none;
  color: var(--by-ink-3);
  background: transparent;
  border: 0;
  cursor: pointer;
  transition: color 120ms var(--ease-out), background 120ms var(--ease-out), transform 100ms var(--ease-out);
}
.by-app:hover { color: var(--by-ink-2); background: var(--by-surface); }
.by-app:active { transform: scale(0.97); }
.by-app.is-active {
  color: var(--by-ink);
  background: var(--by-surface);
  font-weight: 600;
}

.by-nav {
  flex: 1;
  overflow-y: auto;
  padding: 0.2rem 0.55rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.08rem;
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar) transparent;
}

.by-nav-section {
  margin: 0.9rem 0.55rem 0.28rem;
  font-size: var(--text-caption);
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--by-ink-3);
}
.by-nav-section:first-child { margin-top: 0.3rem; }

.by-nav-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  min-height: 2.05rem;
  padding: 0.42rem 0.55rem;
  border: 0;
  border-radius: var(--by-radius);
  background: transparent;
  color: var(--by-ink-2);
  font: inherit;
  font-size: var(--text-body);
  font-weight: 400;
  letter-spacing: -0.01em;
  line-height: 1.25;
  text-decoration: none;
  text-align: left;
  cursor: pointer;
  transition: background 120ms var(--ease-out), color 120ms var(--ease-out), transform 100ms var(--ease-out);
}
.by-nav-item:hover {
  background: var(--by-surface-hover);
  color: var(--by-ink);
}
.by-nav-item:active { transform: scale(0.985); }
.by-nav-item.is-active {
  background: var(--by-surface-active);
  color: var(--by-ink);
  font-weight: 600;
}
.by-nav-item.is-active .by-nav-icon { color: var(--by-tint); opacity: 1; }
.by-nav-item--sub {
  padding-left: 0.85rem;
}

.by-nav-icon {
  width: 1.25rem;
  height: 1.25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  opacity: 0.9;
  color: inherit;
}
.by-nav-icon svg { width: 1.05rem; height: 1.05rem; stroke-width: 1.75; }

.by-nav-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.by-nav-label--stack {
  white-space: normal !important;
  display: flex;
  flex-direction: column;
  gap: 0.05rem;
  line-height: 1.25;
}

.by-nav-meta {
  font-size: var(--text-caption);
  color: var(--by-ink-3);
  flex-shrink: 0;
  opacity: 0.7;
}

.by-sidebar-footer {
  padding: 0.55rem 0.65rem 0.7rem;
  border-top: 0.5px solid var(--by-line);
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  flex-shrink: 0;
}

.by-footer-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.4rem 0.5rem;
  border-radius: var(--by-radius);
  background: transparent;
  font-size: var(--text-footnote);
  color: var(--by-ink-2);
}

.by-main {
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  background:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px),
    var(--bg);
  background-size: 28px 28px, 28px 28px, auto;
  background-position: center top;
}

/* BoDict-only mobile bottom tab bar (.app.by-shell). AIGC uses its own drawer. */
@media (max-width: 820px) {
  .app.by-shell {
    width: 100%;
    max-width: 100%;
    min-height: 100dvh;
  }
  .app.by-shell > .by-shell-body {
    flex-direction: column;
  }
  .app.by-shell .by-sidebar {
    position: fixed !important;
    left: 0;
    right: 0;
    bottom: 0;
    top: auto !important;
    width: 100% !important;
    height: auto !important;
    max-height: none !important;
    flex-direction: column;
    border-right: 0;
    border-top: 0.5px solid var(--by-line);
    padding-bottom: env(safe-area-inset-bottom);
    background: var(--glass-strong);
    backdrop-filter: blur(24px) saturate(160%);
    z-index: 50;
  }
  .app.by-shell .by-sidebar .by-sidebar-brand,
  .app.by-shell .by-sidebar .by-apps,
  .app.by-shell .by-sidebar .by-sidebar-footer,
  .app.by-shell .by-sidebar .by-nav-section,
  .app.by-shell .by-sidebar .by-nav-meta { display: none !important; }
  .app.by-shell .by-sidebar .by-theme-rail {
    display: flex !important;
    margin: 0;
    padding: 0.35rem 0.55rem 0.1rem;
    border-radius: 0;
    background: transparent;
  }
  .app.by-shell .by-sidebar .by-nav {
    flex-direction: row;
    width: 100%;
    padding: 0.2rem 0.3rem 0.3rem;
    gap: 0;
    overflow: visible;
  }
  .app.by-shell .by-sidebar .by-nav-item {
    flex: 1;
    flex-direction: column;
    justify-content: center;
    gap: 0.12rem;
    min-height: 3.1rem;
    max-height: 3.6rem;
    padding: 0.35rem 0.15rem;
    font-size: 0.625rem;
    border-radius: 10px;
  }
  .app.by-shell .by-sidebar .by-nav-item .by-nav-label {
    display: block;
    font-size: 0.625rem;
    max-width: 100%;
  }
  .app.by-shell .by-main {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    padding-bottom: calc(4.5rem + env(safe-area-inset-bottom));
    background: var(--bg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .by-nav-item, .by-app, .by-sidebar-brand, .theme-btn, .suggestion-chip, .by-rail-pin {
    transition: background 160ms ease, color 160ms ease !important;
  }
  .by-rail-slot .by-sidebar,
  .by-aigc-rail-slot .by-sidebar {
    transition: none !important;
  }
  .by-nav-item:active, .by-app:active, .by-sidebar-brand:active,
  .theme-btn:active, .suggestion-chip:hover { transform: none !important; }
}

@media (prefers-reduced-transparency: reduce) {
  .by-sidebar {
    background: var(--by-sidebar-solid);
    backdrop-filter: none;
  }
}

@media (prefers-contrast: more) {
  .by-sidebar { border-right: 1px solid var(--text); }
  .by-nav-item.is-active { outline: 1px solid var(--by-tint); }
}
