:root {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-elevated: #1c222b;
  --border: #30363d;
  --border-subtle: #24292f;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --green: #22c55e;
  --green-bg: rgba(34, 197, 94, 0.14);
  --green-border: rgba(34, 197, 94, 0.35);
  --red: #ef4444;
  --red-bg: rgba(239, 68, 68, 0.14);
  --red-border: rgba(239, 68, 68, 0.35);
  --gray: #9ca3af;
  --gray-bg: rgba(156, 163, 175, 0.12);
  --gray-border: rgba(156, 163, 175, 0.25);
  --amber: #f59e0b;
  --amber-bg: rgba(245, 158, 11, 0.14);
  --amber-border: rgba(245, 158, 11, 0.35);
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  background-color: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a {
  color: #60a5fa;
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.app-shell {
  min-height: 100vh;
  max-width: 1020px;
  margin: 0 auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Header */
.app-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-icon {
  font-size: 1.75rem;
  line-height: 1;
}

.brand h1 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-subtitle {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.header-sleep-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 500;
  color: #c4b5fd;
  background: rgba(139, 92, 246, 0.14);
  border: 1px solid rgba(139, 92, 246, 0.35);
  white-space: nowrap;
}

/* Cards & Typography */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

h2 {
  margin: 0 0 12px;
  font-size: 1.05rem;
  font-weight: 600;
}

h3 {
  margin: 0 0 8px;
  font-size: 1.05rem;
  font-weight: 600;
}

.muted {
  color: var(--text-muted);
  font-size: 0.88rem;
}

.stack-md {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Forms */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-muted);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.field input,
.field select {
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.form-error {
  margin: 8px 0 0;
  font-size: 0.85rem;
  color: #fca5a5;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 40px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-sm {
  min-height: 34px;
  padding: 6px 11px;
  font-size: 0.82rem;
}

.btn-full {
  width: 100%;
}

.btn-primary {
  background: var(--accent);
  color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface-elevated);
  border-color: var(--border);
  color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
  background: #252c37;
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-muted);
}

.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  background: var(--surface-elevated);
}

.btn-danger {
  background: var(--red-bg);
  border-color: var(--red-border);
  color: #fca5a5;
}

.btn-danger:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.25);
  color: #fecaca;
}

/* Auth View */
.auth-view {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 0;
}

.auth-card {
  width: 100%;
  max-width: 380px;
}

.auth-card p {
  margin: 0 0 16px;
}

/* Dashboard */
.dashboard {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Add Book Form */
.add-book-form {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.field-submit {
  justify-content: flex-end;
}

@media (min-width: 768px) {
  .add-book-form {
    grid-template-columns: repeat(12, 1fr);
    align-items: end;
  }

  .field-url {
    grid-column: span 5;
  }

  .field-mode {
    grid-column: span 4;
  }

  .field-title {
    grid-column: span 3;
  }

  .field-price {
    grid-column: span 2;
  }

  .field-priority {
    grid-column: span 2;
  }

  .field-group {
    grid-column: span 3;
  }

  .field-genre {
    grid-column: span 3;
  }

  .field-submit {
    grid-column: span 2;
  }

  .field-submit .btn-full {
    width: 100%;
  }
}

/* Main Tabs */
.main-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.main-tab {
  flex: 1 1 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
  white-space: nowrap;
}

.main-tab:hover {
  color: var(--text);
  background: var(--surface-elevated);
}

.main-tab.is-active {
  background: var(--surface-elevated);
  border-color: var(--accent);
  color: var(--text);
  font-weight: 600;
}

.main-tab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.tab-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 19px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 600;
}

.main-tab.is-active .tab-count {
  background: rgba(59, 130, 246, 0.18);
  border-color: rgba(59, 130, 246, 0.4);
  color: #93c5fd;
}

.tab-unread-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 19px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--green-bg);
  border: 1px solid var(--green-border);
  color: #4ade80;
  font-size: 0.72rem;
  font-weight: 700;
}

/* Books Toolbar (Two-Zone) */
.books-toolbar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px 14px;
  margin-bottom: 14px;
}

.toolbar-zone {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.toolbar-zone-view {
  padding-top: 10px;
  border-top: 1px solid var(--border-subtle);
}

.toolbar-zone-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  line-height: 1;
}

.toolbar-zone-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.toolbar-search {
  flex: 1 1 100%;
  min-width: 0;
}

.toolbar-search input {
  width: 100%;
  min-height: 36px;
  padding: 6px 12px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: inherit;
}

.toolbar-search input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

.toolbar-field {
  flex: 1 1 135px;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.toolbar-field label {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.toolbar-field select {
  flex: 1;
  min-width: 0;
  min-height: 34px;
  padding: 4px 8px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-family: inherit;
}

.toolbar-field select:focus {
  outline: none;
  border-color: var(--accent);
}

.toolbar-chips-field {
  flex: 1 1 auto;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
}

.filter-group-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.filter-chips-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.filter-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  line-height: 1.2;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.filter-chip:hover {
  color: var(--text);
  background: var(--surface-elevated);
  border-color: var(--text-muted);
}

.filter-chip:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.filter-chip.is-active {
  font-weight: 600;
}

.filter-chip[data-value="available"].is-active {
  background: var(--green-bg);
  border-color: var(--green-border);
  color: #4ade80;
}

.filter-chip[data-value="unavailable"].is-active {
  background: rgba(148, 163, 184, 0.18);
  border-color: rgba(148, 163, 184, 0.45);
  color: var(--text);
}

.filter-chip[data-value="high"].is-active {
  background: rgba(239, 68, 68, 0.16);
  border-color: rgba(239, 68, 68, 0.45);
  color: #fca5a5;
}

.filter-chip[data-value="normal"].is-active {
  background: rgba(59, 130, 246, 0.16);
  border-color: rgba(59, 130, 246, 0.45);
  color: #93c5fd;
}

.filter-chip[data-value="low"].is-active {
  background: rgba(245, 158, 11, 0.16);
  border-color: rgba(245, 158, 11, 0.45);
  color: #fcd34d;
}

.filter-chip[data-value="weekly"].is-active {
  background: rgba(129, 140, 248, 0.16);
  border-color: rgba(129, 140, 248, 0.45);
  color: #c4b5fd;
}

.btn-clear-filters {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s ease, border-color 0.15s ease, background-color 0.15s ease;
}

.btn-clear-filters:hover {
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.45);
  background: rgba(239, 68, 68, 0.08);
}

.view-mode-toggle {
  display: inline-flex;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 2px;
  flex-shrink: 0;
}

.view-mode-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.95rem;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.view-mode-btn:hover {
  color: var(--text);
  background: var(--surface-elevated);
}

.view-mode-btn.is-active {
  background: var(--accent);
  color: #ffffff;
}

@media (min-width: 768px) {
  .books-toolbar {
    flex-direction: row;
    align-items: stretch;
    gap: 16px;
  }

  .toolbar-zone-filters {
    flex: 1.2 1 0;
  }

  .toolbar-zone-view {
    flex: 1 1 0;
    padding-top: 0;
    padding-left: 16px;
    border-top: none;
    border-left: 1px solid var(--border);
  }

  .toolbar-search {
    flex: 1 1 180px;
  }

  .toolbar-field {
    flex: 0 1 auto;
  }
}

/* Books Section */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.section-header h2 {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.count-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 22px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 600;
}

.books-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.empty-state {
  text-align: center;
  padding: 36px 16px;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

/* Book Card */
.book-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: border-color 0.15s ease;
}

.book-card.is-paused {
  opacity: 0.72;
}

.book-card.is-available {
  border-color: var(--green-border);
}

.book-body {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-width: 0;
  flex: 1;
}

.book-cover-wrap {
  flex-shrink: 0;
  width: 52px;
  height: 76px;
  border-radius: 6px;
  overflow: hidden;
  background: var(--bg);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
}

.book-cover-img {
  width: 52px;
  height: 76px;
  object-fit: cover;
  display: block;
}

.book-cover-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 1.35rem;
  background: linear-gradient(145deg, var(--surface-elevated), var(--bg));
}

.book-main {
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 0;
  flex: 1;
}

.book-title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.book-title-link {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  word-break: break-word;
}

.book-title-link:hover {
  color: #60a5fa;
}

.book-status-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  border: 1px solid transparent;
}

.badge-available {
  background: var(--green-bg);
  border-color: var(--green-border);
  color: #4ade80;
}

.badge-unavailable {
  background: var(--gray-bg);
  border-color: var(--gray-border);
  color: var(--gray);
}

.badge-error {
  background: var(--red-bg);
  border-color: var(--red-border);
  color: #f87171;
}

.badge-unknown {
  background: var(--amber-bg);
  border-color: var(--amber-border);
  color: #fbbf24;
}

/* Priority Badges */
.badge-priority-high {
  background: rgba(249, 115, 22, 0.14);
  border-color: rgba(249, 115, 22, 0.4);
  color: #fb923c;
}

.badge-priority-normal {
  background: var(--gray-bg);
  border-color: var(--gray-border);
  color: var(--text-muted);
}

.badge-priority-low {
  background: rgba(107, 114, 128, 0.08);
  border-color: rgba(107, 114, 128, 0.2);
  color: #6e7681;
}

.badge-priority-weekly {
  background: rgba(129, 140, 248, 0.12);
  border-color: rgba(129, 140, 248, 0.3);
  color: #a5b4fc;
}

.badge-mode-price {
  background: rgba(59, 130, 246, 0.12);
  border-color: rgba(59, 130, 246, 0.3);
  color: #93c5fd;
  font-weight: 500;
}

.badge-mode-list {
  background: rgba(167, 139, 250, 0.14);
  border-color: rgba(167, 139, 250, 0.35);
  color: #c4b5fd;
  font-weight: 500;
}

.badge-list-unread {
  background: var(--green-bg);
  border-color: var(--green-border);
  color: #4ade80;
}

.badge-list-neutral {
  background: var(--gray-bg);
  border-color: var(--gray-border);
  color: var(--text-muted);
  font-weight: 500;
}

.btn-ack {
  background: rgba(34, 197, 94, 0.16);
  border: 1px solid rgba(34, 197, 94, 0.45);
  color: #4ade80;
  font-weight: 600;
}

.btn-ack:hover:not(:disabled) {
  background: rgba(34, 197, 94, 0.25);
  border-color: rgba(34, 197, 94, 0.65);
}

.btn-ack-compact {
  white-space: nowrap;
  padding: 4px 8px;
  font-size: 0.78rem;
}

/* List Items Preview (<details> inside list card) */
.list-items-preview {
  margin-top: 4px;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  background: var(--bg);
  overflow: hidden;
}

.list-items-preview-summary {
  padding: 6px 10px;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.list-items-preview-summary:hover {
  color: var(--text);
  background: var(--surface-elevated);
}

.list-items-ul {
  list-style: none;
  margin: 0;
  padding: 4px 10px 8px;
  border-top: 1px solid var(--border-subtle);
  max-height: 220px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.list-items-li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.82rem;
  line-height: 1.35;
}

.list-items-li.is-unread {
  background: rgba(34, 197, 94, 0.08);
  border-radius: 4px;
  padding: 2px 6px;
  margin: 0 -6px;
}

.list-item-title-wrap {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex: 1;
}

.badge-new {
  display: inline-flex;
  align-items: center;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--green-bg);
  border: 1px solid var(--green-border);
  color: #4ade80;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  flex-shrink: 0;
}

.list-item-link {
  color: var(--text);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-item-link:hover {
  color: #60a5fa;
}

.list-item-price {
  flex-shrink: 0;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.78rem;
}

.list-items-empty {
  margin: 0;
  padding: 8px 10px;
  border-top: 1px solid var(--border-subtle);
  font-size: 0.8rem;
}

/* Compact Mode */
.books-list--compact,
.books-list--compact .book-group-items {
  gap: 6px;
}

.book-row {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  transition: border-color 0.15s ease;
}

.book-row.is-paused {
  opacity: 0.68;
}

.book-row.is-available {
  border-color: var(--green-border);
}

.book-row-main {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  min-width: 0;
  flex: 1;
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--amber);
}

.status-dot--available {
  background: var(--green);
  box-shadow: 0 0 6px rgba(34, 197, 94, 0.55);
}

.status-dot--unavailable {
  background: var(--gray);
}

.status-dot--error {
  background: var(--red);
}

.status-dot--unknown {
  background: var(--amber);
}

.book-row-title {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  min-width: 0;
  flex: 1 1 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.book-row-title:hover {
  color: #60a5fa;
}

.book-row-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.book-row-price {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.book-row-price.is-available {
  color: #4ade80;
  font-weight: 600;
}

.badge-compact {
  padding: 1px 6px;
  font-size: 0.72rem;
}

.tag-compact {
  padding: 1px 7px;
  font-size: 0.72rem;
  max-width: 130px;
}

.book-row-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.btn-icon {
  min-height: 30px;
  width: 30px;
  padding: 0;
  font-size: 0.85rem;
  line-height: 1;
}

.btn-icon.is-paused-btn {
  color: #4ade80;
  border-color: var(--green-border);
}

@media (max-width: 640px) {
  .book-row {
    align-items: flex-start;
    padding: 8px 9px;
  }

  .book-row-title {
    flex-basis: calc(100% - 20px);
  }

  .book-row-meta {
    padding-left: 17px;
  }
}

/* Tag Pills (Group & Genre) */
.book-tags-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.tag-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 500;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  color: var(--text-muted);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tag-group {
  color: var(--text);
  border-color: var(--group-color, var(--border));
  background: color-mix(in srgb, var(--group-color, #60a5fa) 14%, transparent);
}

.tag-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--group-color, var(--accent));
}

/* Grouped Books (<details>) */
.book-group {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(22, 27, 34, 0.55);
  overflow: hidden;
}

.book-group-summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 14px;
  background: var(--surface);
  border-left: 4px solid var(--group-color, var(--border));
  cursor: pointer;
  user-select: none;
  font-weight: 600;
  font-size: 0.94rem;
}

.book-group-summary::-webkit-details-marker {
  display: none;
}

.book-group-summary:hover {
  background: var(--surface-elevated);
}

.book-group-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.book-group-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.book-group-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.book-group-chevron {
  color: var(--text-muted);
  transition: transform 0.2s ease;
}

.book-group[open] > .book-group-summary .book-group-chevron {
  transform: rotate(180deg);
}

.book-group-items {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid var(--border-subtle);
}

.bazaar-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.82rem;
  font-weight: 600;
  color: #4ade80;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  background: rgba(34, 197, 94, 0.08);
}

.bazaar-link:hover {
  background: rgba(34, 197, 94, 0.18);
  text-decoration: none;
}

.book-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.book-error-detail {
  font-size: 0.8rem;
  color: #fca5a5;
  word-break: break-word;
}

/* Book Actions */
.book-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--border-subtle);
}

.toggle-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
}

.toggle-btn:hover:not(:disabled) {
  background: var(--surface-elevated);
}

.toggle-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gray);
}

.toggle-btn.is-active .toggle-dot {
  background: var(--green);
  box-shadow: 0 0 6px rgba(34, 197, 94, 0.7);
}

@media (min-width: 768px) {
  .book-card {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
  }

  .book-main {
    flex: 1;
  }

  .book-actions {
    border-top: none;
    padding-top: 0;
    flex-shrink: 0;
    justify-content: flex-end;
  }
}

/* Collapsible Logs */
.logs-section {
  padding: 0;
  overflow: hidden;
}

.logs-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
}

.logs-toggle-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  padding: 4px 0;
  cursor: pointer;
  text-align: left;
}

.chevron {
  transition: transform 0.2s ease;
  color: var(--text-muted);
}

.logs-toggle-btn[aria-expanded="true"] .chevron {
  transform: rotate(180deg);
}

.logs-panel {
  border-top: 1px solid var(--border);
  padding: 12px 14px;
}

.logs-table-wrap {
  width: 100%;
  overflow-x: auto;
}

.logs-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.83rem;
}

.logs-table th,
.logs-table td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: top;
}

.logs-table th {
  color: var(--text-muted);
  font-weight: 600;
  white-space: nowrap;
}

.logs-table tr:last-child td {
  border-bottom: none;
}

@media (max-width: 640px) {
  .logs-table thead {
    display: none;
  }

  .logs-table,
  .logs-table tbody,
  .logs-table tr,
  .logs-table td {
    display: block;
    width: 100%;
  }

  .logs-table tr {
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
  }

  .logs-table tr:last-child {
    border-bottom: none;
  }

  .logs-table td {
    padding: 2px 0;
    border-bottom: none;
  }
}

/* Modals */
dialog.modal {
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  width: calc(100% - 32px);
  max-width: 440px;
  max-height: 90vh;
  overflow-y: auto;
}

dialog.modal.modal-lg {
  max-width: 560px;
}

dialog.modal::backdrop {
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(2px);
}

.modal-box {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.modal-header-row h3 {
  margin: 0;
}

.modal-grid-2 {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

@media (min-width: 500px) {
  .modal-grid-2 {
    grid-template-columns: 1fr 1fr;
  }
}

.modal-divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 4px 0;
}

.settings-sections {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.settings-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.settings-section h4 {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text);
}

.settings-hint {
  margin: -4px 0 0;
  font-size: 0.8rem;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.88rem;
  cursor: pointer;
}

.checkbox-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  flex-shrink: 0;
}

.group-colors-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.group-color-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 6px 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.group-color-label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-size: 0.88rem;
}

.group-color-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.group-color-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.group-color-controls input[type="color"] {
  width: 34px;
  height: 28px;
  padding: 1px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
}

.modal-subtitle {
  margin: 0;
  word-break: break-word;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  right: 16px;
  bottom: 16px;
  left: 16px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: none;
  z-index: 1000;
}

.toast {
  pointer-events: auto;
  max-width: 380px;
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.88rem;
  box-shadow: var(--shadow);
  animation: toast-in 0.18s ease-out;
}

.toast-success {
  border-color: var(--green-border);
  color: #86efac;
}

.toast-error {
  border-color: var(--red-border);
  color: #fca5a5;
}

@media (min-width: 640px) {
  .toast {
    width: auto;
    min-width: 240px;
  }
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Footer */
.app-footer {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text-muted);
}
