/* UI refresh · bookshelf
   书架 / 离线书库 / 官方书架 / 账号卡片：.bookshelf-panel、.bookshelf-*、.official-*、.account-*。
   只使用 refresh/foundation.css 中的 --ds-* 设计令牌；不得修改其他文件负责的选择器。

   这一页只用 foundation 的三档字号（caption 12 / meta 13 / body 14，标题 15）、
   --ds-radius-* 圆角和 --ds-control-* 控件高度：旧样式里 10–11px 的小字、29px 高的
   「详情」按钮和 12px / 999px 等零散圆角都在这里收拢。 */

/* ---------------------------------------------------------------------------
   Toolbar: source tabs, filters and actions share one control height.
   ------------------------------------------------------------------------ */
.bookshelf-controls-summary {
  border-radius: var(--ds-radius-md);
  font-size: var(--ds-text-meta);
  font-weight: var(--ds-weight-medium);
}

.bookshelf-controls-disclosure:not([open]) > .bookshelf-toolbar,
.bookshelf-toolbar {
  gap: var(--ds-space-2);
}

/* 书架标题旁的 WebDAV 快捷按钮（#458）：默认隐藏；显示时和「导入」按钮靠右排在一起。 */
.bookshelf-webdav-quick {
  margin-left: auto;
}

.section-head > .bookshelf-webdav-quick[hidden],
.section-head > .bookshelf-webdav-quick > [hidden] {
  display: none;
}

.bookshelf-toolbar > .ghost-button {
  min-height: var(--ds-control);
  border-radius: var(--ds-radius-full);
  font-size: var(--ds-text-meta);
}

.bookshelf-panel > .settings-hint,
#officialBookshelfMeta {
  font-size: var(--ds-text-caption);
  line-height: var(--ds-leading-body);
}

/* ---------------------------------------------------------------------------
   Batch bar
   ------------------------------------------------------------------------ */
.bookshelf-batch-bar {
  gap: var(--ds-space-3);
  padding: var(--ds-space-2) var(--ds-space-3);
  border-radius: var(--ds-radius-md);
}

.bookshelf-batch-count {
  color: var(--ds-text-muted);
  font-size: var(--ds-text-meta);
  font-weight: var(--ds-weight-medium);
}

.bookshelf-batch-actions {
  gap: var(--ds-space-2);
}

.bookshelf-batch-actions > button {
  min-height: var(--ds-control-sm);
  padding: 0 var(--ds-space-3);
  border-radius: var(--ds-radius-full);
  font-size: var(--ds-text-meta);
}

/* ---------------------------------------------------------------------------
   Grid and cards
   ------------------------------------------------------------------------ */
.bookshelf-grid {
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: var(--ds-space-3);
}

.bookshelf-card {
  gap: var(--ds-space-2);
  padding: var(--ds-pad-card);
  border-color: var(--ds-border);
  border-radius: var(--ds-radius-lg);
  background: var(--ds-surface-card);
  transition: background var(--ds-motion-fast) var(--ds-ease), border-color var(--ds-motion-fast) var(--ds-ease);
}

.bookshelf-card:hover {
  background: var(--ds-surface-card-hover);
}

.bookshelf-open-area {
  gap: var(--ds-space-2);
  border-radius: var(--ds-radius-sm);
}

.bookshelf-card-cover {
  border-radius: var(--ds-radius-sm);
  background: var(--ds-surface-raised);
}

.bookshelf-card-title {
  color: var(--ds-text);
  font-size: var(--ds-text-body);
  font-weight: var(--ds-weight-strong);
  line-height: var(--ds-leading-tight);
}

.bookshelf-card-meta,
.bookshelf-card-progress,
.bookshelf-card-flags,
.bookshelf-card-status-line {
  font-size: var(--ds-text-caption);
  line-height: var(--ds-leading-body);
}

.bookshelf-card-meta,
.bookshelf-card-flags {
  color: var(--ds-text-muted);
}

.bookshelf-card-flags,
.bookshelf-card-status-line {
  gap: var(--ds-space-1) var(--ds-space-2);
}

.bookshelf-status-chip {
  padding: 0 var(--ds-space-2);
  border-radius: var(--ds-radius-xs);
  font-size: var(--ds-text-caption);
  font-weight: var(--ds-weight-medium);
  line-height: 1.6;
}

/* The label is the checkbox's hit area: the 13px box keeps its look, the
   transparent label around it is at least 32×32 (44×44 on phones). */
.bookshelf-card-select {
  gap: var(--ds-space-2);
  min-width: var(--ds-control-sm);
  min-height: var(--ds-control-sm);
  font-size: var(--ds-text-meta);
}

/* The card's own actions: the old rule made 「详情」 29px tall with 11px text. */
.bookshelf-card-actions {
  gap: var(--ds-space-2);
  margin-top: auto;
}

.bookshelf-card-actions button {
  min-height: var(--ds-control-sm);
  padding: 0 var(--ds-space-2);
  border-radius: var(--ds-radius-full);
  font-size: var(--ds-text-meta);
  font-weight: var(--ds-weight-medium);
  line-height: var(--ds-leading-tight);
}

/* ---------------------------------------------------------------------------
   Compact bookshelf: smaller cards, never smaller type than the caption step.
   (Same selectors as the legacy rules so these win on order.)
   ------------------------------------------------------------------------ */
body.bookshelf-compact .bookshelf-grid {
  grid-template-columns: repeat(auto-fill, minmax(118px, 1fr));
  gap: var(--ds-space-2);
}

body.bookshelf-compact .bookshelf-card {
  gap: var(--ds-space-1);
  padding: var(--ds-space-2);
  border-radius: var(--ds-radius-md);
}

body.bookshelf-compact .bookshelf-card-title {
  font-size: var(--ds-text-meta);
}

body.bookshelf-compact .bookshelf-card-progress.local-progress-line,
body.bookshelf-compact .bookshelf-card-progress.official-progress-line,
body.bookshelf-compact .bookshelf-card-status-line,
body.bookshelf-compact .bookshelf-status-chip {
  font-size: var(--ds-text-caption);
  line-height: var(--ds-leading-tight);
}

body.bookshelf-compact .bookshelf-status-chip {
  padding: 0 var(--ds-space-1);
}

/* ---------------------------------------------------------------------------
   Official bookshelf: group wall, pager, flags
   ------------------------------------------------------------------------ */
.official-bookshelf-filters {
  width: min(360px, 100%);
}

.official-shelf-flags,
.official-sync-pending {
  font-size: var(--ds-text-caption);
}

.official-bookshelf-more {
  min-height: var(--ds-control);
  border-radius: var(--ds-radius-full);
  font-size: var(--ds-text-meta);
}

.bookshelf-group-wall {
  gap: var(--ds-space-3);
}

.bookshelf-group-card {
  gap: var(--ds-space-1);
  padding: var(--ds-pad-panel);
  border-color: var(--ds-border);
  border-radius: var(--ds-radius-lg);
  background: var(--ds-surface-card);
  color: var(--ds-text);
  transition: background var(--ds-motion-fast) var(--ds-ease), border-color var(--ds-motion-fast) var(--ds-ease);
}

.bookshelf-group-card:hover {
  border-color: var(--ds-accent);
  background: var(--ds-surface-card-hover);
}

.bookshelf-group-name {
  font-size: var(--ds-text-title-sm);
  font-weight: var(--ds-weight-strong);
  line-height: var(--ds-leading-tight);
}

.bookshelf-group-count,
.bookshelf-group-hint {
  font-size: var(--ds-text-caption);
  line-height: var(--ds-leading-body);
}

.bookshelf-group-count {
  color: var(--ds-text-muted);
}

.bookshelf-group-hint {
  color: var(--ds-text-subtle);
}

/* ---------------------------------------------------------------------------
   Account card (rendered inside settings, owned here)
   ------------------------------------------------------------------------ */
.account-avatar-fallback {
  font-size: var(--ds-text-headline);
}

.account-login-form {
  border-radius: var(--ds-radius-md);
}

.account-form-row > .text-input,
.account-form-row > button {
  min-height: var(--ds-control);
}

/* ---------------------------------------------------------------------------
   Touch: every bookshelf control reaches 44px on phones and narrow windows.
   ------------------------------------------------------------------------ */
@media (max-width: 600px) {
  /* 批量操作：“已选 N 本”单独一行，按钮等宽两列占满宽度，
     不再按文字长短参差换行、右边缘对不齐。 */
  .bookshelf-batch-bar {
    flex-direction: column;
    align-items: stretch;
  }

  .bookshelf-batch-actions {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .bookshelf-batch-actions > button {
    width: 100%;
    min-width: 0;
    padding: 0 var(--ds-space-2);
  }

  .bookshelf-grid {
    grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  }

  .bookshelf-card-actions button {
    min-height: var(--ds-control-touch);
  }
}

body.mobile-shell .bookshelf-card-actions button,
body.mobile-shell .bookshelf-batch-actions > button,
body.mobile-shell .bookshelf-toolbar > .ghost-button,
body.mobile-shell .official-bookshelf-more,
body.mobile-shell .account-form-row > .text-input,
body.mobile-shell .account-form-row > button {
  min-height: var(--ds-control-touch);
}

body.mobile-shell .bookshelf-card-select {
  min-width: var(--ds-control-touch);
  min-height: var(--ds-control-touch);
}

body.mobile-shell.bookshelf-compact .bookshelf-grid {
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
}

/* ---- 书架细节：今日已读 / 检查更新一行、新章节角标、已读完、离线书库（参考 fqapp / Legado） */
.bookshelf-today-row {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: var(--ds-control-sm);
  color: var(--ds-text-muted);
  font-size: var(--ds-text-meta);
}

.bookshelf-today-row .ghost-button {
  min-height: var(--ds-control-sm);
}

.bookshelf-card-cover {
  position: relative;
}

.bookshelf-new-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  z-index: 1;
  min-width: 22px;
  padding: 1px 6px;
  border-radius: var(--ds-radius-full);
  background: var(--ds-accent);
  color: var(--ds-on-accent);
  font-size: var(--ds-text-caption);
  font-weight: var(--ds-weight-strong);
  line-height: 1.5;
  text-align: center;
  pointer-events: none;
}

.bookshelf-finished {
  color: var(--ds-accent);
  font-weight: var(--ds-weight-medium);
}

.bookshelf-empty-state .empty-state-actions {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 12px;
}

.offline-library-list {
  display: grid;
  gap: 6px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
  text-align: left;
}

.offline-library-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--ds-border);
  border-radius: var(--ds-radius-md);
  background: var(--ds-surface-card);
}

.offline-library-name {
  overflow: hidden;
  color: var(--ds-text);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.offline-library-count {
  color: var(--ds-text-muted);
  font-size: var(--ds-text-meta);
}

.bookshelf-card {
  -webkit-touch-callout: none;
}

/* ---------------------------------------------------------------------------
   Header disclosure, import note and today row (bookshelf layout pass)
   ------------------------------------------------------------------------ */
/* The collapsed header used to repeat “本地书架”, the same words as the
   segmented control right under it. It now names what it opens and shows the
   current source and filter as a muted readout. */
.bookshelf-controls-summary {
  gap: var(--ds-space-2);
}

.bookshelf-controls-label {
  flex: 1 1 auto;
  min-width: 0;
}

.bookshelf-controls-state {
  flex: 0 0 auto;
  color: var(--ds-text-muted);
  font-weight: 400;
}

/* One short line; encodings and size limits sit behind “了解更多”. */
.bookshelf-import-hint > summary {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px var(--ds-space-2);
  list-style: none;
  cursor: pointer;
}

.bookshelf-import-hint > summary::-webkit-details-marker {
  display: none;
}

.bookshelf-import-more {
  color: var(--ds-accent);
  white-space: nowrap;
}

.bookshelf-import-hint[open] .bookshelf-import-more {
  display: none;
}

.bookshelf-import-hint > p {
  margin: 4px 0 0;
}

/* Reading time and the group count read as one stats line, left aligned,
   with “检查更新” on the right of the same row. */
.bookshelf-today-stats {
  min-width: 0;
}

.bookshelf-today-stats > span + span::before {
  content: " · ";
}
