/* The Daily Reader - web edition. Carries over the desktop app's newspaper
   look: Times masthead, Georgia body, hairline section rules. */

:root {
  --masthead-bg: #1a1a1a;
  --masthead-fg: #ffffff;
  --page-bg: #f5f5f5;
  --section-bg: #f8f8f8;
  --section-border: #333333;
  --article-bg: #ffffff;
  --link: #1a1a1a;
  --link-visited: #551A8B;
  --source: #666666;
  --hairline: #ddd;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page-bg);
  font-family: Georgia, 'Times New Roman', serif;
  color: #1a1a1a;
}

.hidden { display: none !important; }

/* ---------- Masthead ---------- */

.masthead {
  background: var(--masthead-bg);
  color: var(--masthead-fg);
  padding: 14px 16px 0;
}

.masthead-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  max-width: 1200px;
  margin: 0 auto;
}

.masthead-title {
  font-family: 'Times New Roman', Times, serif;
  font-size: clamp(26px, 5vw, 40px);
  font-weight: bold;
  margin: 0;
  letter-spacing: 1px;
}

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

.date-label {
  background: none;
  border: none;
  color: #cccccc;
  font-family: Arial, sans-serif;
  font-size: 13px;
  cursor: pointer;
  border-bottom: 1px dashed #777;
  padding: 2px 0;
}
.date-label:hover { color: #fff; }

.date-picker-hidden {
  width: 0; height: 0; opacity: 0; border: none; padding: 0; position: absolute;
}

/* ---------- Toolbar ---------- */

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 1200px;
  margin: 10px auto 0;
  padding-bottom: 10px;
  flex-wrap: wrap;
}

.search-wrap { flex: 1; min-width: 180px; }

#search-input {
  width: 100%;
  padding: 7px 12px;
  border: 1px solid #555;
  border-radius: 3px;
  font-family: Georgia, serif;
  font-size: 14px;
  background: #2a2a2a;
  color: #fff;
}
#search-input::placeholder { color: #999; }

.toolbar-actions { display: flex; gap: 8px; }

.ghost-btn {
  background: none;
  border: 1px solid #888;
  color: inherit;
  font-family: Arial, sans-serif;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 3px;
  cursor: pointer;
}
.masthead .ghost-btn { color: #ddd; border-color: #666; }
.masthead .ghost-btn:hover { color: #fff; border-color: #aaa; }
.content .ghost-btn:hover, .pagination .ghost-btn:hover, .modal .ghost-btn:hover { background: #eee; }

.solid-btn {
  background: #1a1a1a;
  color: #fff;
  border: 1px solid #1a1a1a;
  font-family: Arial, sans-serif;
  font-size: 13px;
  padding: 7px 14px;
  border-radius: 3px;
  cursor: pointer;
}
.solid-btn:hover { background: #333; }

/* ---------- Section nav ---------- */

.section-nav {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  max-width: 1200px;
  margin: 0 auto;
  border-top: 1px solid #444;
  -webkit-overflow-scrolling: touch;
}

.section-nav button {
  background: none;
  border: none;
  color: #bbb;
  font-family: 'Times New Roman', serif;
  font-size: 15px;
  font-weight: bold;
  padding: 10px 14px;
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 3px solid transparent;
}
.section-nav button:hover { color: #fff; }
.section-nav button.active { color: #fff; border-bottom-color: #fff; }

/* ---------- Status bar ---------- */

.status-bar {
  max-width: 1200px;
  margin: 0 auto;
  padding: 6px 16px;
  font-family: Arial, sans-serif;
  font-size: 12px;
  color: var(--source);
  min-height: 24px;
}

/* ---------- Content ---------- */

.content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px 24px;
}

.section-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  border-bottom: 2px solid var(--section-border);
  margin: 22px 0 12px;
  padding-bottom: 4px;
}
.section-header h2 {
  font-family: 'Times New Roman', serif;
  font-size: 20px;
  margin: 0;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 14px;
}

.article-card {
  background: var(--article-bg);
  border: 1px solid var(--hairline);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.article-card .source-line {
  font-family: Arial, sans-serif;
  font-size: 11px;
  font-style: italic;
  color: var(--source);
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.article-card h3 {
  font-family: Georgia, serif;
  font-size: 16px;
  margin: 0;
  line-height: 1.3;
}
.article-card h3 a {
  color: var(--link);
  text-decoration: none;
}
.article-card h3 a:hover { text-decoration: underline; }
.article-card h3 a:visited { color: var(--link-visited); }

.article-card .thumb {
  width: 100%;
  max-height: 180px;
  object-fit: cover;
  border: 1px solid var(--hairline);
}

.article-card .summary {
  font-size: 13px;
  color: #333;
  line-height: 1.45;
  margin: 0;
}

.card-actions {
  margin-top: auto;
  display: flex;
  gap: 12px;
  font-family: Arial, sans-serif;
  font-size: 12px;
}
.card-actions button {
  background: none;
  border: none;
  color: var(--source);
  cursor: pointer;
  padding: 0;
  font-size: 12px;
  text-decoration: underline;
}
.card-actions button:hover { color: #1a1a1a; }

/* Historical source grid */

.hist-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.hist-card {
  background: var(--article-bg);
  border: 1px solid var(--hairline);
  padding: 14px;
  cursor: pointer;
}
.hist-card:hover { border-color: #999; background: #fcfcfc; }
.hist-card h3 { font-family: 'Times New Roman', serif; margin: 0 0 6px; font-size: 17px; }
.hist-card .count { font-family: Arial, sans-serif; font-size: 12px; color: var(--source); }
.hist-card ul { margin: 8px 0 0; padding-left: 18px; font-size: 13px; }
.hist-card li { margin-bottom: 4px; }

/* Sources page */
.source-chip-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}
.source-chip {
  background: var(--article-bg);
  border: 1px solid var(--hairline);
  padding: 12px 14px;
  cursor: pointer;
  font-family: 'Times New Roman', serif;
  font-size: 16px;
  font-weight: bold;
}
.source-chip:hover { border-color: #999; }
.source-chip .meta { display: block; font-family: Arial, sans-serif; font-size: 11px; font-weight: normal; color: var(--source); margin-top: 4px; }
.source-chip.failed { border-color: #c0392b; }
.source-chip.failed .meta { color: #c0392b; }

/* ---------- Pagination ---------- */

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 10px 0 30px;
  font-family: Arial, sans-serif;
  font-size: 13px;
}

/* ---------- Modal ---------- */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 50;
}

.modal-box {
  background: #fff;
  width: 100%;
  max-width: 760px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  border: 1px solid #333;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 2px solid var(--section-border);
}
.modal-header h2 { font-family: 'Times New Roman', serif; margin: 0; font-size: 20px; }

.tab-bar {
  display: flex;
  overflow-x: auto;
  border-bottom: 1px solid var(--hairline);
}
.tab-btn {
  background: none;
  border: none;
  font-family: Arial, sans-serif;
  font-size: 13px;
  padding: 10px 14px;
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 3px solid transparent;
  color: #555;
}
.tab-btn.active { color: #1a1a1a; border-bottom-color: #1a1a1a; font-weight: bold; }

.tab-panel { padding: 14px 16px; overflow-y: auto; flex: 1; }

.hint { font-family: Arial, sans-serif; font-size: 12px; color: var(--source); margin-top: 0; }

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

.settings-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: Arial, sans-serif;
  font-size: 13px;
  flex-wrap: wrap;
}
.settings-row .grow { flex: 1; min-width: 120px; }
.settings-row input[type="text"], .settings-add input[type="text"] {
  padding: 6px 8px;
  border: 1px solid #bbb;
  border-radius: 3px;
  font-size: 13px;
}
.settings-row select { padding: 6px; font-size: 13px; }
.settings-row .small-btn {
  background: none; border: 1px solid #bbb; border-radius: 3px;
  font-size: 12px; padding: 4px 8px; cursor: pointer;
}
.settings-row .small-btn:hover { background: #eee; }
.settings-row .url { color: var(--source); font-size: 11px; word-break: break-all; }

.settings-add {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  flex-wrap: wrap;
}
.settings-add input { flex: 1; min-width: 140px; }

.modal-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--hairline);
  display: flex;
  justify-content: flex-end;
}

/* ---------- Empty / loading ---------- */

.empty-note {
  font-family: Arial, sans-serif;
  color: var(--source);
  font-size: 14px;
  padding: 40px 0;
  text-align: center;
}

@media (max-width: 600px) {
  .article-card .thumb { max-height: 150px; }
  .masthead { padding: 10px 12px 0; }
  .content { padding: 0 10px 20px; }
}

/* ---------- v2: Top Stories ---------- */

.top-stories {
  border: 2px solid var(--section-border);
  background: var(--article-bg);
  margin-top: 18px;
  padding: 14px;
}
.top-stories .ts-label {
  font-family: Arial, sans-serif;
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--source);
  margin: 0 0 10px;
}
.ts-item { padding: 8px 0; border-top: 1px solid var(--hairline); }
.ts-item:first-of-type { border-top: none; }
.ts-item h3 { font-family: Georgia, serif; font-size: 17px; margin: 0 0 4px; line-height: 1.3; }
.ts-item h3 a { color: var(--link); text-decoration: none; }
.ts-item h3 a:hover { text-decoration: underline; }
.ts-item .ts-meta { font-family: Arial, sans-serif; font-size: 11px; color: var(--source); }
.ts-item .ts-meta strong { color: #1a1a1a; }
.ts-coverage { display: none; margin: 6px 0 0; padding-left: 16px; font-size: 12px; }
.ts-item.open .ts-coverage { display: block; }
.ts-coverage a { color: var(--source); }
.ts-toggle { background: none; border: none; font-size: 11px; color: var(--source); cursor: pointer; text-decoration: underline; padding: 0; margin-left: 6px; }

/* ---------- v2: add-source discovery ---------- */

.add-source-box { margin-top: 6px; }
.discover-result { border: 1px solid var(--hairline); background: #fafafa; padding: 10px 12px; margin-top: 10px; }
.suggestion {
  font-family: Arial, sans-serif;
  font-size: 13px;
  background: #fdf6e3;
  border: 1px solid #e6d9a8;
  padding: 8px 10px;
  margin: 8px 0;
}
.suggestion.hidden { display: none; }
#new-source-category { padding: 7px; font-size: 13px; }
