/*
 * Cards, grids, chips, tabs, rows.
 * Grid metrics: 推荐/分类/书架 3x0.58 spacing 12/10 padding 16;
 * 更新/排行/热门 3x0.54 spacing 12/8 padding LTRB(12,8,12,16)
 * (lib/app.dart, lib/ui/update_feed_card.dart).
 */

.cover {
  position: relative;
  overflow: hidden;
  background: var(--cover-empty);
  border-radius: inherit;
}

.cover__img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cover--empty {
  display: grid;
  place-items: center;
}

.cover__broken {
  width: 36px;
  height: 30px;
  border: 2px solid rgba(0, 0, 0, 0.26);
  border-radius: 3px;
  position: relative;
}

.cover__broken::after {
  content: '';
  position: absolute;
  left: 2px;
  right: 2px;
  bottom: 3px;
  height: 10px;
  background: rgba(0, 0, 0, 0.26);
  clip-path: polygon(0 100%, 32% 24%, 56% 100%, 74% 52%, 100% 100%);
}

/* minmax(0,1fr): long titles must not push the three columns past the viewport. */
.grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid--comic {
  padding: 0 16px 16px;
  row-gap: 12px;
  column-gap: 10px;
}

.grid--feed {
  padding: 8px 12px 16px;
  row-gap: 12px;
  column-gap: 8px;
}

.comic-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  aspect-ratio: 0.58;
  text-align: left;
}

.comic-card__cover {
  flex: 1 1 auto;
  min-height: 0;
  border-radius: 8px;
  margin-bottom: 6px;
}

.comic-card__title {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.2;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.comic-card__subtitle {
  font-size: 11px;
  color: var(--fg-secondary);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.comic-card__caption {
  font-size: 11px;
  color: var(--accent);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.feed-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  aspect-ratio: 0.54;
  text-align: left;
}

.feed-card__cover {
  flex: 1 1 auto;
  min-height: 0;
  border-radius: 6px;
  margin-bottom: 5px;
}

.feed-card__time {
  position: absolute;
  left: 5px;
  top: 5px;
  max-width: 80px;
  padding: 2px 4px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  font-size: 9px;
  font-weight: 600;
  line-height: 1.15;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.feed-card__title {
  font-size: 12px;
  font-weight: 600;
  line-height: 1.15;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.feed-card__chapter {
  margin-top: 2px;
  font-size: 10px;
  line-height: 1.15;
  color: #757575;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.feed-card__source {
  margin-top: 2px;
  font-size: 9px;
  font-weight: 600;
  line-height: 1.15;
  color: var(--accent);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.source-badge {
  display: inline-block;
  padding: 2px 6px;
  border-radius: 4px;
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  line-height: 1.2;
}

.source-badge--pill {
  border-radius: 999px;
  padding: 2px 8px;
}

/* ---------- chips ---------- */

.chip-row {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  overflow-x: auto;
  scrollbar-width: none;
}

.chip-row::-webkit-scrollbar {
  display: none;
}

.chip {
  flex: 0 0 auto;
  height: 32px;
  padding: 0 12px;
  border-radius: 16px;
  background: var(--chip-bg);
  color: var(--fg);
  font-size: 13px;
  white-space: nowrap;
}

.chip--active {
  background: var(--accent);
  color: #fff;
}

/* ---------- tabs ---------- */

.tab-bar {
  display: flex;
  align-items: stretch;
  height: 46px;
  border-bottom: 1px solid var(--divider);
}

.tab-bar__tab {
  flex: 1 1 0;
  position: relative;
  font-size: 14px;
  color: var(--fg-secondary);
}

.tab-bar__tab--active {
  color: var(--accent);
  font-weight: 600;
}

.tab-bar__tab--active::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 32px;
  height: 3px;
  border-radius: 2px 2px 0 0;
  background: var(--accent);
}

.tab-body {
  min-height: 320px;
}

/* ---------- fake search bar (首页) ---------- */

.search-fake-wrap {
  padding: 8px 12px;
  background: var(--bg);
}

.search-fake {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  height: 36px;
  padding: 0 12px;
  border-radius: 18px;
  background: var(--chip-bg);
  color: var(--fg-tertiary);
}

.search-fake__icon,
.search-field__icon {
  flex: 0 0 auto;
  width: 15px;
  height: 15px;
  border: 2px solid currentColor;
  border-radius: 50%;
  position: relative;
}

.search-fake__icon::after,
.search-field__icon::after {
  content: '';
  position: absolute;
  right: -5px;
  bottom: -3px;
  width: 7px;
  height: 2px;
  background: currentColor;
  transform: rotate(45deg);
}

.search-fake__hint {
  font-size: 13px;
}

.search-field {
  width: 100%;
  height: 40px;
  border: 0;
  background: transparent;
  color: var(--fg);
  font-size: 16px;
  outline: none;
}

/* ---------- section header ---------- */

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 8px 4px 16px;
}

.section-header__title {
  font-size: 18px;
  font-weight: 700;
}

/* ---------- empty / error ---------- */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 280px;
  padding: 40px 24px;
  color: var(--fg-tertiary);
  text-align: center;
}

.empty-state__icon {
  width: 56px;
  height: 56px;
  border: 3px solid currentColor;
  border-radius: 6px;
  opacity: 0.35;
}

.empty-state__icon--history {
  border-radius: 50%;
  position: relative;
}

.empty-state__icon--history::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 20%;
  width: 3px;
  height: 34%;
  background: currentColor;
  transform-origin: bottom center;
  transform: rotate(35deg);
}

.empty-state__icon--search {
  border-radius: 50%;
}

.empty-state__title {
  font-size: 15px;
  color: var(--fg-tertiary);
}

.empty-state__hint {
  font-size: 13px;
  color: var(--fg-tertiary);
  opacity: 0.85;
}

.error-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 280px;
  padding: 40px 24px;
  text-align: center;
}

.error-panel__icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 3px solid var(--danger);
  position: relative;
  opacity: 0.8;
}

.error-panel__icon::after {
  content: '!';
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--danger);
  font-size: 24px;
  font-weight: 700;
}

.error-panel__message {
  font-size: 14px;
  color: var(--fg-secondary);
}

/* ---------- list rows (我的 / 设置) ---------- */

.group-title {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 18px 16px 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--fg-secondary);
}

.group-title__bar {
  width: 3px;
  height: 14px;
  border-radius: 2px;
  background: var(--accent);
}

.list-row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 8px 16px;
  text-align: left;
  background: var(--bg);
  border-bottom: 1px solid var(--divider);
}

.list-row__avatar {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
}

.list-row__body {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.list-row__title {
  font-size: 15px;
}

.list-row__subtitle {
  font-size: 12px;
  color: var(--fg-tertiary);
}

.list-row__trailing {
  font-size: 13px;
  color: var(--fg-tertiary);
}

.list-row__chevron {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-top: 2px solid rgba(0, 0, 0, 0.26);
  border-right: 2px solid rgba(0, 0, 0, 0.26);
  transform: rotate(45deg);
}

/* ---------- ad slots (FAIL_OPEN: empty slots collapse) ---------- */

.ad-slot {
  display: block;
  overflow: hidden;
  background: transparent;
}

.ad-slot--empty {
  display: none;
}

.ad-slot--inset {
  margin: 8px 12px;
  border-radius: 8px;
}

.ad-slot__image {
  display: block;
  width: 100%;
  height: auto;
  object-fit: contain;
}
