/* ==========================================================================
   Tworks — shared components (header, search, cards, buttons, chips,
   drawer/modal, pagination, toast). Used by every page in the mock.
   ========================================================================== */

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  padding: 10px 18px;
  font-weight: 600;
  font-size: var(--fs-sm);
  line-height: 1.2;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.08s ease, box-shadow .15s ease;
}
.btn:active { transform: translateY(1px); }

.btn-primary { background: var(--brand); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--brand-dark); }

.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-alt); }

.btn-ghost { background: transparent; color: var(--text-soft); }
.btn-ghost:hover { background: var(--surface-alt); color: var(--text); }

.btn-outline-brand { background: transparent; color: var(--brand); border-color: var(--brand); }
.btn-outline-brand:hover { background: var(--brand-soft); }

.btn-sm { padding: 6px 12px; font-size: var(--fs-xs); border-radius: var(--radius-sm); }
.btn-lg { padding: 13px 26px; font-size: var(--fs-md); border-radius: var(--radius-md); }
.btn-block { width: 100%; }
.btn-icon { padding: 8px; width: 36px; height: 36px; border-radius: var(--radius-pill); }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; pointer-events: none; }

/* ---------- Site header ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 60;
  height: var(--header-h);
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.site-header .container { display: flex; align-items: center; gap: var(--space-5); }

.brand-mark {
  display: flex;
  flex-direction: column;
  gap: 1px;
  line-height: 1.1;
  color: var(--text);
  flex-shrink: 0;
  text-decoration: none;
}
.brand-mark .word { font-weight: 800; font-size: 19px; letter-spacing: -0.02em; }
.brand-mark .dot { color: var(--brand); }
.brand-mark small {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
}

/* [Desktop UI] Centers the main nav + search bar as one unit within the
   header, independent of the brand-mark (left) and Account/header-actions
   (right) — margin:0 auto absorbs the remaining flex space evenly on both
   sides, since neither sibling group has its own flex-grow to compete for
   it. At <=1000px .main-nav hides (see the media query further down), so
   this wrapper switches to flex:1 there instead — the search bar alone
   should still stretch to fill the row like it did before this wrapper
   existed, not just sit centered at its own intrinsic width. */
.site-header-center { display: flex; align-items: center; gap: var(--space-5); margin: 0 auto; }
@media (max-width: 1000px) {
  .site-header-center { flex: 1; margin: 0; min-width: 0; }
}

/* UI overhaul v2 — nav items are <button data-view> (SPA routing, no real
   hrefs), not <a>: style both so neither the primary row nor the drawer
   silently falls back to unstyled browser buttons depending on markup. */
.main-nav { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.main-nav a, .main-nav button {
  font-family: var(--font-ui);
  appearance: none;
  border: none;
  background: none;
  cursor: pointer;
  padding: 9px 14px;
  border-radius: var(--radius-md);
  font-size: var(--fs-sm);
  font-weight: 600;
  line-height: 1.5;
  color: var(--text-soft);
  transition: background 0.15s ease, color 0.15s ease;
}
.main-nav a:hover, .main-nav button:hover { color: var(--text); background: var(--surface-alt); }
.main-nav a.active, .main-nav button.active { color: var(--brand); background: var(--brand-soft); }

.nav-dropdown { position: relative; }
.nav-dropdown-trigger {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 9px 12px 9px 14px;
  border: none;
  background: none;
  border-radius: var(--radius-md);
  font-family: var(--font-ui);
  font-size: var(--fs-sm);
  font-weight: 600;
  line-height: 1.5;
  color: var(--text-soft);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.nav-dropdown-trigger:hover,
.nav-dropdown-trigger[aria-expanded='true'] { color: var(--text); background: var(--surface-alt); }
.nav-dropdown-trigger.active { color: var(--brand); background: var(--brand-soft); }
.nav-dropdown-trigger .icon-caret { transition: transform 0.15s ease; }
.nav-dropdown-trigger[aria-expanded='true'] .icon-caret { transform: rotate(180deg); }

.nav-dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 190px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: opacity 0.15s ease, transform 0.15s ease, visibility 0.15s ease;
}
.nav-dropdown-menu a, .nav-dropdown-menu button {
  font-family: var(--font-ui);
  appearance: none;
  border: none;
  background: none;
  text-align: left;
  cursor: pointer;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--text-soft);
  transition: background 0.15s ease, color 0.15s ease;
}
.nav-dropdown-menu a:hover, .nav-dropdown-menu button:hover { color: var(--text); background: var(--surface-alt); }
.nav-dropdown-menu a.active, .nav-dropdown-menu button.active { color: var(--brand); background: var(--brand-soft); }
.nav-dropdown[data-open='true'] .nav-dropdown-menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.header-search {
  flex: 1;
  max-width: 280px;
  min-width: 180px;
  position: relative;
}
.header-search input {
  width: 100%;
  height: 40px;
  padding: 0 40px 0 38px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--surface-alt);
  font-size: var(--fs-sm);
  transition: border-color .15s ease, background .15s ease;
}
.header-search input:focus {
  outline: none;
  border-color: var(--brand);
  background: var(--surface);
}
.header-search svg.icon-search {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px; height: 16px;
  color: var(--text-faint);
  pointer-events: none;
}

/* margin-left:auto moved into the <=1000px media query below — at desktop
   width it's empty (.nav-toggle is display:none there), and an unconditional
   auto margin here would compete with .site-header-center's own left/right
   auto margins for the same free space, throwing off the "centered nav +
   search" layout above. Below 1000px .site-header-center switches to
   flex:1 and eats all the free space itself, so this margin is the only
   thing pushing the now-visible hamburger to the row's far right. */
.header-actions { display: flex; align-items: center; gap: var(--space-3); flex-shrink: 0; }

.nav-toggle { display: none; }

@media (max-width: 1000px) {
  .main-nav { display: none; }
  .nav-dropdown { display: none; }
  .header-search { max-width: none; }
  .header-actions { margin-left: auto; }
  .nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px; height: 38px;
    border-radius: var(--radius-md);
    background: var(--surface-alt);
    border: 1px solid var(--border);
  }
}

@media (max-width: 640px) {
  .site-header .container { padding: 0 var(--space-4); gap: var(--space-3); }
  .brand-mark .word { font-size: 16px; }
  .brand-mark small { font-size: 7.5px; }
  .header-search { min-width: 70px; }
  .header-search input { height: 34px; padding: 0 12px 0 32px; font-size: 13px; }
  .header-search svg.icon-search { left: 11px; width: 14px; height: 14px; }
  .nav-toggle { width: 34px; height: 34px; }
}

/* mobile drawer nav */
.mobile-nav-drawer {
  position: fixed;
  inset: 0;
  z-index: 90;
  visibility: hidden;
  overflow: hidden;
}
.mobile-nav-drawer[data-open='true'] { visibility: visible; }
.mobile-nav-drawer .scrim {
  position: absolute; inset: 0;
  background: rgba(20,22,31,0.4);
  opacity: 0;
  transition: opacity .2s ease;
}
.mobile-nav-drawer[data-open='true'] .scrim { opacity: 1; }
.mobile-nav-drawer .panel {
  position: absolute; top: 0; right: 0; bottom: 0;
  width: min(300px, 84vw);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  padding: var(--space-5);
  transform: translateX(100%);
  transition: transform .25s ease;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  overflow-y: auto;
}
.mobile-nav-drawer[data-open='true'] .panel { transform: translateX(0); }
.mobile-nav-drawer .panel a, .mobile-nav-drawer .panel button {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-ui);
  appearance: none;
  border: none;
  background: none;
  text-align: left;
  cursor: pointer;
  padding: 12px 10px;
  border-radius: var(--radius-md);
  font-size: var(--fs-base);
  font-weight: 600;
  color: var(--text);
}
/* Minimalist line-icon style (24x24 viewBox, stroke=currentColor) matching
   the mock's .nd-bottombar icons, replacing the earlier emoji set — stroke
   inherits the button's own `color`, so the active/red state colors the
   icon for free with no extra rule. */
.mobile-nav-drawer .panel .drawer-icon { display: flex; align-items: center; justify-content: center; width: 20px; flex-shrink: 0; }
.mobile-nav-drawer .panel .drawer-icon svg { width: 19px; height: 19px; }

/* Explicit close affordance at the top of the panel — closing via the
   scrim/Escape/nav-click still works, this just makes it discoverable. */
.mobile-nav-drawer .panel .drawer-close {
  align-self: flex-end;
  width: 36px; height: 36px;
  padding: 0;
  margin-bottom: var(--space-2);
  border-radius: 50%;
  background: var(--surface-alt);
  color: var(--text-soft);
  justify-content: center;
}
.mobile-nav-drawer .panel .drawer-close svg { width: 18px; height: 18px; }
.mobile-nav-drawer .panel .drawer-close:hover { background: var(--surface-sunken); color: var(--text); }
.mobile-nav-drawer .panel a.active, .mobile-nav-drawer .panel button.active { color: var(--brand); background: var(--brand-soft); }
.mobile-nav-drawer .panel .drawer-group-label {
  margin-top: var(--space-2);
  padding: 10px 10px 0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.mobile-nav-drawer .panel a.drawer-sublink, .mobile-nav-drawer .panel button.drawer-sublink { padding-left: 20px; font-weight: 500; }

/* ---------- Chips / badges / tags ---------- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 13px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-xs);
  font-weight: 600;
  background: var(--surface-alt);
  color: var(--text-soft);
  border: 1px solid transparent;
  transition: background .15s ease, color .15s ease;
}
.chip:hover { background: var(--surface-sunken); }
.chip.active { background: var(--text); color: #fff; }
.chip-genre.active { background: var(--brand-soft); color: var(--brand-darker); border-color: var(--brand-soft-border); }

/* Auto-convert status feedback (UI overhaul v2, Phase 4) — replaces the
   retired dispatch-counter stamp animation with a status chip. */
.chip--processing { background: var(--warning-soft); color: var(--warning); animation: chip-pulse 1.2s ease-in-out infinite; }
.chip--failed { background: var(--danger-soft); color: var(--danger); }
@keyframes chip-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .55; } }
@media (prefers-reduced-motion: reduce) { .chip--processing { animation: none; } }

/* Plain modern auto-convert card (Phase 4) — replaces the dispatch counter. */
.auto-convert-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  margin-bottom: var(--space-5);
}
.auto-convert-card .card-tag-row { margin-bottom: var(--space-3); }

/* Shown inline in the auto-convert card when a conversion attempt fails —
   explains why, then walks the user through the manual dichngay.com path. */
.convert-interrupted-notice {
  margin-top: var(--space-4);
  padding: var(--space-4);
  background: var(--warning-soft);
  border: 1px solid var(--warning);
  border-radius: var(--radius-md);
}
.convert-interrupted-notice .notice-title {
  font-weight: 700;
  color: var(--warning);
  margin: 0 0 var(--space-2);
}
.convert-interrupted-notice .notice-detail {
  color: var(--text-soft);
  margin: 0 0 var(--space-3);
}
.convert-interrupted-notice .notice-steps-label {
  font-weight: 600;
  margin: 0 0 var(--space-2);
}
.convert-interrupted-notice .notice-steps {
  margin: 0;
  padding-left: var(--space-5);
  color: var(--text);
}
.convert-interrupted-notice .notice-steps li { margin-bottom: var(--space-1); }

.tag {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent-dark);
}
.tag-status-ongoing { background: var(--success-soft); color: var(--success); }
.tag-status-completed { background: var(--surface-sunken); color: var(--text-soft); }
.tag-status-hiatus { background: var(--warning-soft); color: var(--warning); }

/* .badge-count {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  background: rgba(20, 22, 31, 0.72);
  backdrop-filter: blur(3px);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
} */

.rating {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--gold);
}
.rating svg { width: 13px; height: 13px; }

/* ---------- Book cover placeholder ---------- */

.cover {
  position: relative;
  aspect-ratio: 3 / 4;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--surface-sunken);
  flex-shrink: 0;
}
.cover img { width: 100%; height: 100%; object-fit: cover; }

/*.cover .badge-count { position: absolute; right: 6px; bottom: 6px; } */

/* Tworks additions: cover size modifiers for list/table density (the mock
   only sized .cover via .book-card/.book-card-wide/.rank-row context), and
   select/remove overlay controls the mock's read-only sample cards never
   needed (Library's real batch-select + soft-delete). */
.cover--md { width: 56px; flex: 0 0 56px; }
.cover--sm { width: 36px; flex: 0 0 36px; }

.book-card { position: relative; }
.book-card .card-select,
.book-card .card-remove {
  position: absolute;
  z-index: 2;
  top: 8px;
  width: 18px; height: 18px;
}
.book-card .card-select { left: 8px; cursor: pointer; }
.book-card .card-remove {
  right: 8px;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: rgba(255,255,255,0.9);
  border: none;
  font-size: 13px;
  line-height: 1;
  box-shadow: var(--shadow-sm);
}
.card-select-inline, .card-remove-inline { cursor: pointer; flex-shrink: 0; }
.card-remove-inline { background: none; border: none; font-size: 14px; color: var(--text-faint); }

/* ---------- BookCard ---------- */

.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: var(--space-5) var(--space-4);
}

.book-card { display: flex; flex-direction: column; gap: 8px; }
.book-card .cover { transition: transform .18s ease; }
.book-card:hover .cover { transform: translateY(-3px); }

.book-card .card-tag-row { display: flex; align-items: center; gap: 6px; }
.book-card h3 {
  font-size: var(--fs-sm);
  font-weight: 700;
  line-height: 1.3;
  margin-top: 2px;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.book-card .author { font-size: 12px; color: var(--text-faint); }
.book-card .synopsis {
  font-size: 12px;
  color: var(--text-soft);
  line-height: 1.45;
  margin-top: 2px;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.book-card.book-card-wide {
  flex-direction: row;
  gap: var(--space-4);
  align-items: flex-start;
}
.book-card.book-card-wide .cover { width: 92px; flex: 0 0 92px; }
.book-card.book-card-wide h3 { font-size: var(--fs-md); -webkit-line-clamp: 2; }
.book-card.book-card-wide .synopsis { -webkit-line-clamp: 2; }

/* List view (Tworks addition) — .book-card-wide rows stacked as a plain
   list instead of the mock's grid, each in its own bordered row. */
.book-list { display: flex; flex-direction: column; gap: var(--space-3); }
.book-list .book-card-wide {
  padding: var(--space-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

/* ---------- Ranking rail ---------- */

.rank-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border);
}
.rank-row:last-child { border-bottom: none; }
.rank-row .rank-num {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 15px;
  width: 22px;
  text-align: center;
  color: var(--text-faint);
  flex-shrink: 0;
}
.rank-row:nth-child(1) .rank-num { color: #fff; background: #ffb020; border-radius: 6px; }
.rank-row:nth-child(2) .rank-num { color: #fff; background: #a8b0c0; border-radius: 6px; }
.rank-row:nth-child(3) .rank-num { color: #fff; background: #d38a52; border-radius: 6px; }
.rank-row .cover { width: 40px; flex: 0 0 40px; }
.rank-row .rank-meta { min-width: 0; flex: 1; }
.rank-row .rank-meta .title {
  font-size: 13px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.rank-row .rank-meta .sub { font-size: 11px; color: var(--text-faint); }

/* ---------- Filter bar ---------- */

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.filter-group { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.filter-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-faint);
  margin-right: 4px;
}
.select-control {
  height: 34px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-alt);
  font-size: 13px;
  font-weight: 600;
}
.filter-spacer { flex: 1; }
/* Library's Select-novels/+Add-content buttons, relocated here from the
   now-deprecated .view-header (styles.css) — same row as the rest of the
   library controls, pushed right by .filter-spacer above like the view
   switch already was. */
.library-controls-actions { display: flex; align-items: center; gap: 8px; }

/* ---------- Tabs ---------- */

/* ---------- Pagination ---------- */

.pagination { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: var(--space-6); }
.page-btn {
  min-width: 34px; height: 34px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-soft);
  padding: 0 8px;
}
.page-btn:hover { background: var(--surface-alt); }
.page-btn.active { background: var(--text); color: #fff; border-color: var(--text); }
.page-btn[disabled] { opacity: .4; pointer-events: none; }
.page-dots { color: var(--text-faint); padding: 0 2px; }

/* ---------- Section heading ---------- */

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}
.section-head h2 { font-size: var(--fs-xl); }
.section-head .see-all { font-size: 13px; font-weight: 700; color: var(--accent); flex-shrink: 0; }
.section-head .see-all:hover { text-decoration: underline; }
.eyebrow {
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--brand);
  display: block;
  margin-bottom: 4px;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 20px);
  background: var(--text);
  color: #fff;
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 200;
  display: flex;
  align-items: center;
  gap: 8px;
}
.toast[data-show='true'] { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Empty state ---------- */

.empty-state {
  text-align: center;
  padding: var(--space-7) var(--space-4);
  color: var(--text-faint);
}
.empty-state .icon { font-size: 32px; margin-bottom: var(--space-2); }
.empty-state p { margin: 4px 0; }
.empty-state .btn { margin-top: var(--space-3); }

/* ---------- Footer ---------- */

.site-footer {
  border-top: 1px solid var(--border);
  margin-top: var(--space-7);
  padding: var(--space-6) 0 var(--space-7);
  color: var(--text-faint);
  font-size: 12px;
  text-align: center;
}

/* ---------- Progress ---------- */

.progress-track {
  height: 6px;
  border-radius: var(--radius-pill);
  background: var(--surface-sunken);
  overflow: hidden;
}
.progress-fill { height: 100%; background: var(--brand); border-radius: var(--radius-pill); }
