/* ==========================================================================
   PAGE LAYOUT: HEADER, HERO, TOOLBAR, FOOTER
   ========================================================================== */

/* App Header (Glass) */
.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  width: 100%;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  /* PWA 独立窗口下内容延伸到状态栏下方，用安全区垫开时间/电量 */
  padding-top: env(safe-area-inset-top, 0px);
}

/* 统一 Header 行：桌面=品牌+搜索，移动端=搜索+分类（设计图1） */
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 64px;
}
.brand-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
}
.search-wrap {
  flex: 1;
  max-width: 28rem;
  margin: 0 8px;
}
.category-btn {
  display: none;
  align-items: center;
  gap: 6px;
  font-size: 13.5px;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 10px;
  background-color: var(--bg-surface-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  cursor: pointer;
}

/* Hide global header & footer in reading mode */
body.is-reading .app-header,
body.is-reading .app-footer,
body.is-reading #libraryMainWrapper,
body.is-reading #libraryBottomNav {
  display: none !important;
}

@supports (background: color-mix(in srgb, red 50%, transparent)) {
  .app-header {
    background: color-mix(in srgb, var(--bg-surface) 82%, transparent);
    backdrop-filter: blur(14px) saturate(1.3);
    -webkit-backdrop-filter: blur(14px) saturate(1.3);
  }
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  background: linear-gradient(135deg, #f59e0b 0%, #e11d48 100%);
  box-shadow: 0 4px 14px rgba(225, 29, 72, 0.35), inset 0 1px 1px rgba(255, 255, 255, 0.4);
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
.brand-mark:hover {
  transform: rotate(-8deg) scale(1.08);
  box-shadow: 0 6px 18px rgba(225, 29, 72, 0.55);
}

.search-input {
  width: 100%;
  padding: 8px 40px 8px 38px;
  font-size: 12px;
  border-radius: 12px;
  outline: none;
  background-color: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background-color 0.2s ease;
}
.search-input::placeholder {
  color: var(--text-muted);
}
.search-input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-gold-subtle);
  background-color: var(--bg-surface);
}

/* Hero Banner */
.hero-banner {
  position: relative;
  overflow: hidden;
  border-radius: 20px;
  padding: 28px;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
}

.hero-glow {
  position: absolute;
  top: -45%;
  right: -8%;
  width: 460px;
  height: 460px;
  border-radius: 9999px;
  background: radial-gradient(circle, var(--accent-gold-subtle) 0%, transparent 65%);
  filter: blur(24px);
  pointer-events: none;
}

.hero-grid-lines {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(var(--border-subtle) 1px, transparent 1px),
    linear-gradient(90deg, var(--border-subtle) 1px, transparent 1px);
  background-size: 44px 44px;
  opacity: 0.25;
  mask-image: radial-gradient(ellipse at top right, black 0%, transparent 62%);
  -webkit-mask-image: radial-gradient(ellipse at top right, black 0%, transparent 62%);
  pointer-events: none;
}

.stat-tile {
  padding: 14px 12px;
  border-radius: 14px;
  text-align: center;
  background-color: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  transition: transform 0.2s ease, border-color 0.2s ease;
}
.stat-tile:hover {
  transform: translateY(-2px);
  border-color: var(--accent-gold-border);
}
.stat-tile .stat-icon {
  width: 26px;
  height: 26px;
  margin: 0 auto 6px auto;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--accent-gold-subtle);
  color: var(--accent-gold);
}

/* Filter Toolbar */
.filter-toolbar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 14px 16px;
  border-radius: 16px;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
}
@media (min-width: 640px) {
  .filter-toolbar {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}

.layout-toggle-group {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 3px;
  border-radius: 10px;
  background-color: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
}
.layout-btn {
  padding: 6px;
  border-radius: 7px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
  background: transparent;
  border: none;
}
.layout-btn:hover {
  color: var(--text-primary);
}
.layout-btn.active {
  background-color: var(--bg-surface);
  color: var(--accent-gold);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

/* Books Table */
.books-table-wrapper {
  overflow: hidden;
  border-radius: 16px;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
}
.books-table-wrapper thead th {
  padding: 14px 24px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background-color: var(--bg-surface-elevated);
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}
.books-table-wrapper tbody tr {
  border-bottom: 1px solid var(--border-subtle);
  transition: background-color 0.15s ease;
}
.books-table-wrapper tbody tr:last-child {
  border-bottom: none;
}
.books-table-wrapper tbody tr:hover {
  background-color: var(--bg-surface-elevated);
}

/* Empty State */
.empty-state-icon {
  width: 64px;
  height: 64px;
  border-radius: 9999px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
  background-color: var(--bg-surface-elevated);
  border: 1px dashed var(--border-medium);
  color: var(--text-muted);
}

/* Footer */
.app-footer {
  margin-top: auto;
  padding: 22px 0;
  font-size: 12px;
  background-color: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  color: var(--text-secondary);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 9999px;
  background-color: #10b981;
  animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4); }
  50% { opacity: 0.75; box-shadow: 0 0 0 5px rgba(16, 185, 129, 0); }
}

/* Mobile Bookshelf Dedicated Refinement — 设计图1（番茄书城风格） */
@media (max-width: 640px) {
  /* ★ iOS 滚动冻结规避：sticky 头部不用 backdrop-filter，改实色底 */
  .app-header {
    background-color: var(--bg-surface) !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    transform: translateZ(0);
  }

  /* 头部：隐藏品牌，搜索优先 + 分类按钮 */
  .header-inner {
    height: auto;
    gap: 10px;
    padding-top: 12px;
    padding-bottom: 8px;
  }
  .brand-wrap { display: none; }
  .search-wrap { margin: 0; max-width: none; }
  .search-input { border-radius: 11px; padding-top: 9px; padding-bottom: 9px; }
  .category-btn { display: inline-flex; }

  /* 频道文字 Tab（推荐/小说/…）：去卡片化，激活态加大加粗+短下划线 */
  #libraryMainWrapper {
    padding-left: 14px;
    padding-right: 14px;
    padding-top: 2px;
    /* 给固定底部 Tab 栏留出空间 */
    padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px));
  }
  .filter-toolbar {
    background: transparent;
    border: none;
    border-radius: 0;
    padding: 4px 0 2px;
    gap: 4px;
  }
  .desktop-only-controls { display: none !important; }
  #tagPillsContainer {
    -webkit-overflow-scrolling: touch;
    gap: 20px;
    scrollbar-width: none;
  }
  .filter-pill {
    background: transparent !important;
    border: none !important;
    border-radius: 0;
    box-shadow: none !important;
    transform: none !important;
    padding: 6px 0 8px;
    font-size: 14px;
    color: var(--text-secondary);
    position: relative;
    flex-shrink: 0;
  }
  .filter-pill .tab-count {
    font-size: 10.5px;
    font-style: normal;
    opacity: 0.55;
    margin-left: 1px;
  }
  .filter-pill.active {
    color: var(--text-primary);
    font-size: 16.5px;
    font-weight: 800;
  }
  .filter-pill.active::after {
    content: '';
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    bottom: 1px;
    width: 22px;
    height: 3.5px;
    border-radius: 3px;
    background: var(--accent-gold);
  }

  /* 页脚在移动端隐藏（设计图无页脚） */
  .app-footer { display: none; }

  /* 固定底部 Tab 栏：书城/书架/我的（下滑隐藏、上滑呼出） */
  .lib-bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 45;
    display: flex;
    align-items: stretch;
    height: calc(56px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background-color: var(--bg-surface);
    border-top: 1px solid var(--border-subtle);
    transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.22s ease;
    /* iOS backdrop-filter 冻结规避：移动端用实色底 + 图层提升 */
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    transform: translateZ(0);
  }
  .lib-bottom-nav.nav-hidden {
    transform: translateY(105%);
    opacity: 0;
    pointer-events: none;
  }

  .lib-tab-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 10.5px;
    font-weight: 500;
    cursor: pointer;
    transition: color 0.15s ease, transform 0.15s ease;
  }
  /* 显式像素尺寸，避免 PWA 独立窗口下 Tailwind 工具类缺失导致图标塌缩 */
  .lib-tab-item svg {
    width: 23px;
    height: 23px;
    stroke-width: 2;
  }
  .lib-tab-item:active { transform: scale(0.94); }
  .lib-tab-item.active {
    color: var(--accent-gold);
    font-weight: 700;
  }
}

/* 桌面端不渲染底部 Tab 栏 */
@media (min-width: 641px) {
  .lib-bottom-nav { display: none; }
}

/* 轻提示 Toast */
.app-toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%) translateY(8px);
  z-index: 200;
  max-width: 78vw;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  color: #fff;
  background: rgba(30, 30, 34, 0.92);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
.app-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

