@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=Source+Serif+4:ital,opsz,wght@0,8..60,600&display=swap');

/* ── Reader design system tokens ── */
:root {
  --surface-primary:   #ffffff;
  --surface-secondary: #f1f3f4;
  --surface-tertiary:  #e8eaed;
  --text-primary:      #29313a;
  --text-secondary:    #606c79;
  --text-tertiary:     #909aa6;
  --interactive:       #2675de;
  --interactive-bg:    rgba(38, 117, 222, 0.08);
  --border-subtle:     #e0e3e6;
  --border-default:    #c1c7cf;
  --border-focus:      #4592ee;
  --success:           #22a06b;
  --success-bg:        rgba(34, 160, 107, 0.1);
  --error:             #ef4444;
  --error-bg:          rgba(239, 68, 68, 0.08);
  /* Status colors */
  --published-color:   #22a06b;
  --published-bg:      rgba(34, 160, 107, 0.1);
  --alternate-color:   #8b5cf6;
  --alternate-bg:      rgba(139, 92, 246, 0.1);
  --flagged-color:     #d97706;
  --flagged-bg:        rgba(217, 119, 6, 0.1);
  --skipped-color:     #ef4444;
  --skipped-bg:        rgba(239, 68, 68, 0.08);
  --suggested-color:   #2675de;
  --suggested-bg:      rgba(38, 117, 222, 0.08);
}

[data-theme="dark"] {
  --surface-primary:   #161c22;
  --surface-secondary: #1e252d;
  --surface-tertiary:  #252d37;
  --text-primary:      #e0e3e6;
  --text-secondary:    #939fad;
  --text-tertiary:     #606c79;
  --interactive:       #7caeec;
  --interactive-bg:    rgba(124, 174, 236, 0.1);
  --border-subtle:     #29313a;
  --border-default:    #8592a0;
  --border-focus:      #7caeec;
  --success:           #2ea876;
  --success-bg:        rgba(46, 168, 118, 0.12);
  --error:             #f87171;
  --error-bg:          rgba(248, 113, 113, 0.08);
  --published-color:   #2ea876;
  --published-bg:      rgba(46, 168, 118, 0.12);
  --alternate-color:   #a78bfa;
  --alternate-bg:      rgba(167, 139, 250, 0.1);
  --flagged-color:     #fbbf24;
  --flagged-bg:        rgba(251, 191, 36, 0.1);
  --skipped-color:     #f87171;
  --skipped-bg:        rgba(248, 113, 113, 0.08);
  --suggested-color:   #7caeec;
  --suggested-bg:      rgba(124, 174, 236, 0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--surface-primary);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Shell nav (same as volumes) ── */
.shell-nav {
  height: 56px;
  display: flex;
  align-items: center;
  padding: 0 24px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--surface-primary);
  flex-shrink: 0;
  z-index: 10;
}

.shell-brand {
  font-family: 'Source Serif 4', Georgia, serif;
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  text-decoration: none;
  margin-right: 28px;
  flex-shrink: 0;
}
.shell-brand:hover { color: var(--interactive); }

.shell-nav-links { display: flex; align-items: center; gap: 2px; flex: 1; }

.shell-nav-link {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  text-decoration: none;
  padding: 5px 10px;
  border-radius: 5px;
}
.shell-nav-link:hover { color: var(--text-primary); background: var(--surface-secondary); }
.shell-nav-link.active { color: var(--text-primary); background: var(--surface-secondary); }

.shell-nav-right { display: flex; align-items: center; }

.theme-toggle {
  display: flex;
  align-items: center;
  background: var(--surface-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 20px;
  padding: 3px;
  gap: 2px;
}

.theme-toggle-btn {
  width: 28px;
  height: 22px;
  border-radius: 16px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.theme-toggle-btn.active {
  background: var(--surface-primary);
  color: var(--text-primary);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

/* ── Shell body: sidebar + main ── */
.shell-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
  width: 232px;
  flex-shrink: 0;
  border-right: 1px solid var(--border-subtle);
  background: var(--surface-secondary);
  overflow-y: auto;
  padding: 16px 0;
}

.sidebar-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0 16px 8px;
}

.run-row {
  padding: 8px 16px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 1px;
  transition: background 0.1s;
}
.run-row:hover { background: var(--surface-tertiary); }
.run-row.active { background: var(--interactive-bg); }

.run-vol { font-size: 12px; font-weight: 600; color: var(--interactive); }
.run-title {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.run-date { font-size: 11px; color: var(--text-tertiary); }

/* ── Main content ── */
.main-content {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding: 24px;
}

.page-heading {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
  margin-bottom: 4px;
}

.page-sub {
  font-size: 13px;
  color: var(--text-tertiary);
  margin-bottom: 20px;
}

/* ── Action bar ── */
.action-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

input[type="number"]#volume-input {
  width: 88px;
  height: 32px;
  background: var(--surface-primary);
  border: 1px solid var(--border-default);
  border-radius: 4px;
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  padding: 0 10px;
}
input[type="number"]#volume-input:focus {
  outline: none;
  border-color: var(--border-focus);
}

button {
  height: 32px;
  padding: 0 14px;
  border-radius: 48px;
  border: none;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  background: var(--interactive);
  color: #fff;
}
button:hover { opacity: 0.9; }
button:disabled {
  background: var(--surface-tertiary);
  color: var(--text-tertiary);
  cursor: not-allowed;
  opacity: 1;
}

button.secondary {
  background: var(--surface-secondary);
  color: var(--text-secondary);
  border: 1px solid var(--border-default);
}
button.secondary:hover { background: var(--surface-tertiary); opacity: 1; }

/* ── Status bar ── */
.status-bar {
  font-size: 12px;
  color: var(--text-tertiary);
  margin-bottom: 16px;
  min-height: 16px;
}
.status-bar.running { color: var(--flagged-color); }
.status-bar.done    { color: var(--success); }
.status-bar.error   { color: var(--error); }
#suggest-status { margin-bottom: 16px; }
#generate-status { margin-top: 8px; margin-bottom: 0; }

/* ── Volume header (title + editor) ── */
.vol-header-row {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 20px;
}
.vol-title-row { flex: 1; }
.vol-editor-row select {
  height: 28px;
  padding: 0 8px;
  border-radius: 4px;
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  background: var(--surface-secondary);
  border: 1px solid var(--border-default);
  color: var(--text-primary);
}
.vol-editor-row select:focus { outline: none; border-color: var(--border-focus); }

.field-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 4px;
}

input[type="text"]#volume-title {
  width: 100%;
  height: 32px;
  background: var(--surface-primary);
  border: 1px solid var(--border-default);
  border-radius: 4px;
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  padding: 0 10px;
}
input[type="text"]#volume-title:focus {
  outline: none;
  border-color: var(--border-focus);
}

/* ── Category sections ── */
.section {
  background: var(--surface-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 14px;
  margin-bottom: 12px;
}

.category-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.category-title { font-size: 13px; font-weight: 600; color: var(--text-primary); }

.count-badge {
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 10px;
  font-weight: 500;
}
.count-ok  { background: var(--published-bg);  color: var(--published-color); }
.count-bad { background: var(--skipped-bg);    color: var(--skipped-color); }

/* ── Item cards ── */
.item-card {
  background: var(--surface-primary);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  padding: 12px;
  margin-bottom: 8px;
}

.card-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
  align-items: start;
}

.card-fields {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.card-field { display: flex; flex-direction: column; }

.field-value input {
  width: 100%;
  height: 28px;
  background: var(--surface-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  padding: 0 8px;
}
.field-value input:focus {
  outline: none;
  border-color: var(--border-focus);
}

/* ── Stat box ── */
.stat-box {
  background: var(--surface-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 5px;
  padding: 7px 12px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

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

.stat-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.stat-value {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.stat-value.stat-nil { color: var(--text-tertiary); font-weight: 400; }
.stat-value.stat-date { font-size: 11px; font-weight: 500; color: var(--text-secondary); }

.stat-divider {
  height: 1px;
  background: var(--border-subtle);
}

/* ── URL row ── */
.url-row { margin-bottom: 0; }
.url-row + .url-row { margin-top: 8px; }
.url-row + .item-footer { margin-top: 14px; }

.rss-book-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

a.item-url {
  font-size: 12px;
  color: var(--interactive);
  text-decoration: none;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-top: 4px;
}
a.item-url:hover { text-decoration: underline; }

/* ── Item footer (status + prompt dropdowns) ── */
.item-footer {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-top: 14px;
}

.status-with-note {
  display: flex;
  align-items: center;
  gap: 10px;
}

select.status-select {
  height: 28px;
  padding: 0 8px;
  border-radius: 4px;
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  background: var(--surface-secondary);
  border: 1px solid var(--border-default);
  color: var(--text-primary);
}
select.status-select.published { border-color: var(--published-color); color: var(--published-color); }
select.status-select.alternate { border-color: var(--alternate-color); color: var(--alternate-color); }
select.status-select.flagged   { border-color: var(--flagged-color);   color: var(--flagged-color); }
select.status-select.skipped   { border-color: var(--skipped-color);   color: var(--skipped-color); }
select.status-select.suggested { border-color: var(--suggested-color); color: var(--suggested-color); }

select.prompt-select {
  height: 28px;
  padding: 0 8px;
  border-radius: 4px;
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  background: var(--surface-secondary);
  border: 1px solid var(--border-default);
  color: var(--text-primary);
}
select.prompt-select:focus { outline: none; border-color: var(--border-focus); }

.note {
  font-size: 12px;
  color: var(--flagged-color);
}

/* ── Summary / bio ── */
.item-details {
  margin-top: 8px;
}
.item-details summary {
  font-size: 11px;
  color: var(--text-tertiary);
  cursor: pointer;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  user-select: none;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 4px;
}
.item-details summary::-webkit-details-marker { display: none; }
.item-details summary::before { content: '▸'; font-size: 9px; }
details[open].item-details summary::before { content: '▾'; }
.item-details p {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 6px;
  line-height: 1.5;
}
.item-details summary:hover { color: var(--text-secondary); }

.item-bio { margin-top: 8px; }
.item-bio p { font-size: 13px; color: var(--text-secondary); line-height: 1.5; }

/* ── Bottom bar ── */
.bottom-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-top: 16px;
  margin-top: 8px;
  border-top: 1px solid var(--border-subtle);
  flex-wrap: wrap;
}

#save-status {
  font-size: 13px;
  flex: none;
}
#save-status.saved-ok { color: var(--success); }

.validation-error {
  font-size: 12px;
  color: var(--error);
  flex: 1;
}

button#generate-btn {
  background: var(--success);
  color: #fff;
  margin-left: auto;
}
button#generate-btn:hover { opacity: 0.9; }
button#generate-btn:disabled {
  background: var(--surface-tertiary);
  color: var(--text-tertiary);
  cursor: not-allowed;
  opacity: 1;
}

/* "Suggest feeds from pool" button (RSS section header, right side) */
.suggest-feeds-btn {
  margin-left: auto;
  height: 28px;
  padding: 0 12px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 6px;
  border: 1px solid var(--border-default);
  background: var(--surface-secondary);
  color: var(--text-secondary);
  cursor: pointer;
}
.suggest-feeds-btn:hover:not(:disabled) {
  background: var(--surface-tertiary);
}
.suggest-feeds-btn:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

/* "Add to Reader" button (per-card, right side of item-footer) */
.reader-btn {
  margin-left: auto;
  align-self: flex-end;
  height: 28px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 500;
  border-radius: 6px;
  border: 1px solid var(--border-default);
  background: var(--surface-secondary);
  color: var(--text-primary);
  cursor: pointer;
}
.reader-btn:hover:not(:disabled) {
  background: var(--surface-tertiary);
  border-color: var(--border-default);
}
.reader-btn:disabled {
  cursor: default;
  opacity: 0.7;
}
.reader-btn.saved {
  background: var(--surface-secondary);
  color: var(--text-secondary);
  border-color: var(--border-default);
}
.reader-btn-error {
  margin-left: auto;
  margin-right: 8px;
  align-self: flex-end;
  color: #c0392b;
  font-size: 12px;
  line-height: 28px;
}
.reader-btn-error + .reader-btn {
  margin-left: 0;
}

/* ── Mobile ── */
@media (max-width: 600px) {
  .shell-nav { padding: 0 16px; }
  .shell-body { flex-direction: column; overflow: visible; }
  body { height: auto; }

  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border-subtle);
    overflow-y: visible;
    padding: 12px 0;
  }

  .main-content {
    overflow-y: visible;
    padding: 16px;
  }

  .card-grid { grid-template-columns: 1fr; }
  .rss-book-fields { grid-template-columns: 1fr; }

  .action-bar { gap: 6px; }

  input[type="number"]#volume-input { width: 80px; }

  button, input[type="number"]#volume-input,
  input[type="text"]#volume-title,
  .field-value input, select.status-select {
    min-height: 44px;
    font-size: 16px; /* Prevents iOS zoom on focus */
  }

  button { height: auto; padding: 10px 14px; }

  .bottom-bar { gap: 8px; }
  button#generate-btn { width: 100%; justify-content: center; margin-left: 0; }
}
