/* ==========================================================================
   Layout & Grid System - Fixed Header, Compact & Comfortable
   ========================================================================== */

/* Sleek Minimal Custom Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  background-color: var(--bg-body);
}

/* Header Mount Placeholder to Prevent Content Jump */
#app-header-mount {
  height: var(--header-height);
  width: 100%;
  flex-shrink: 0;
}

/* Header - Strictly Fixed to Top, Never Scrolls Away */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  width: 100%;
  height: var(--header-height);
  background: var(--bg-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-color);
  z-index: var(--z-header);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  overflow: visible;
  gap: 8px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.header-logo svg {
  width: 22px;
  height: 22px;
  color: var(--color-root);
}

.header-home {
  display: inline-flex;
  align-items: center;
  font-size: 0.82rem;
  font-weight: 800;
  color: #fff;
  background: var(--primary);
  padding: 6px 12px;
  border-radius: var(--radius-full);
  white-space: nowrap;
  line-height: 1.2;
  box-shadow: 0 1px 2px rgba(37, 99, 235, 0.35);
}

.header-home:hover {
  color: #fff;
  filter: brightness(1.08);
}

.header-center {
  flex: 1;
  min-width: 0;
  max-width: 480px;
  margin: 0 16px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.theme-picker {
  position: relative;
  flex-shrink: 0;
}

.theme-toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 12px 0 6px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-size: 0.82rem;
  font-weight: 650;
  box-shadow: var(--shadow-xs);
  cursor: pointer;
  white-space: nowrap;
}

.theme-toggle-btn:hover {
  border-color: var(--primary);
  color: var(--primary-text);
}

.theme-toggle-label {
  line-height: 1;
}

.theme-panel {
  display: block;
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  width: 220px;
  padding: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  z-index: var(--z-modal);
}

.theme-panel[hidden] {
  display: none !important;
}

.theme-panel-title {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 2px 8px 8px;
}

.theme-option {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 7px 8px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: none;
  color: var(--text-primary);
  font-size: 0.86rem;
  cursor: pointer;
  text-align: left;
}

.theme-option:hover {
  background: var(--bg-subtle);
}

.theme-option.active {
  border-color: var(--primary);
  background: var(--primary-light);
}

.theme-swatch {
  display: flex;
  width: 42px;
  height: 16px;
  border-radius: 99px;
  overflow: hidden;
  border: 1px solid var(--border-color);
  flex-shrink: 0;
}

.theme-swatch i {
  flex: 1;
  display: block;
}

.theme-nav-option {
  width: 100%;
}

/* App Main Body */
.app-body {
  display: flex;
  flex: 1;
  position: relative;
  min-height: calc(100vh - var(--header-height));
}

/* Sidebar Mount Placeholder */
#app-sidebar-mount {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  flex-shrink: 0;
}

/* Sidebar - Fixed to Left, Independent Smooth Scroll */
.app-sidebar {
  width: var(--sidebar-width);
  position: fixed;
  top: var(--header-height);
  left: 0;
  bottom: 0;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 16px;
  padding: 12px 8px;
  overflow-y: auto;
  z-index: var(--z-sticky);
}

.nav-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-label {
  padding: 6px 10px 2px;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  transition: var(--transition-fast);
}

.nav-link svg {
  width: 16px;
  height: 16px;
  opacity: 0.75;
}

.nav-link:hover {
  background: var(--bg-subtle);
  color: var(--text-primary);
}

.nav-link.active {
  background: var(--color-root-bg);
  color: var(--color-root);
  font-weight: 600;
}

.nav-link.active svg {
  opacity: 1;
  color: var(--color-root);
}

.nav-badge {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  padding: 1px 5px;
  border-radius: var(--radius-full);
  background: var(--bg-subtle);
  color: var(--text-muted);
}

.nav-link.active .nav-badge {
  background: rgba(13, 148, 136, 0.2);
  color: var(--color-root);
}

/* Main Content Area - Fluid, Comfortable, Non-Overflowing */
.app-content {
  flex: 1;
  min-width: 0;
  padding: 16px 20px 48px;
  width: 100%;
  box-sizing: border-box;
}

#app-main-content {
  width: 100%;
  max-width: var(--container-max);
  margin: 0 auto;
}

/* Grid Layouts - Compact & Responsive */
.main-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}

.dense-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

/* Mobile Bottom Navigation (Hidden on desktop) */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bottom-nav-height);
  background: var(--bg-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border-color);
  z-index: var(--z-header);
  justify-content: space-around;
  align-items: center;
  padding: 0 6px;
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  flex: 1;
  height: 100%;
  color: var(--text-muted);
  font-size: 0.7rem;
  font-weight: 500;
  transition: var(--transition-fast);
}

.bottom-nav-item svg {
  width: 18px;
  height: 18px;
}

.bottom-nav-item.active {
  color: var(--color-root);
  font-weight: 600;
}

.bottom-nav-toolbox {
  flex: 1.2;
  margin: 6px 2px 8px;
  height: calc(100% - 14px);
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font-weight: 800;
}

.bottom-nav-toolbox svg {
  color: #fff;
}

.bottom-nav-toolbox span {
  font-size: 0.62rem;
  letter-spacing: -0.02em;
}

/* Mobile Breakpoints */
@media (max-width: 840px) {
  #app-sidebar-mount,
  .app-sidebar {
    display: none;
  }

  .bottom-nav {
    display: flex;
  }

  .app-content {
    padding: 12px 12px calc(var(--bottom-nav-height) + 16px);
  }

  .app-header {
    padding: 0 10px;
    gap: 6px;
  }

  .header-left {
    gap: 6px;
  }

  .header-home {
    display: none;
  }

  .header-center {
    margin: 0 4px;
    max-width: none;
  }

  .header-logo {
    font-size: 0.96rem;
    gap: 6px;
  }

  .header-logo svg {
    width: 20px;
    height: 20px;
  }

  .header-logo span {
    max-width: 7.5em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .theme-toggle-btn {
    padding: 0 6px;
    height: 32px;
    gap: 0;
  }

  .theme-toggle-label {
    display: none;
  }

  .theme-swatch {
    width: 28px;
    height: 14px;
  }

  .main-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .dense-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
}

@media (max-width: 480px) {
  .app-header {
    padding: 0 8px;
  }

  .header-logo span {
    display: none; /* 超窄屏只保留精美的语素图标，为搜索框留出充裕空间 */
  }

  .stats-grid {
    gap: 6px;
  }
}
