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

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: #f5f5f5;
  color: #1a1a1a;
  line-height: 1.6;
}

header {
  background: #fff;
  border-bottom: 1px solid #e0e0e0;
  padding: 0.75rem 1.5rem;
  position: sticky;
  top: 0;
  z-index: 10;
}

nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 800px;
  margin: 0 auto;
}

.nav-links a {
  color: #1a1a1a;
  text-decoration: none;
  font-weight: 500;
  margin-right: 1.25rem;
}

.nav-links a:hover { text-decoration: underline; }

.btn-crawl {
  background: #2563eb;
  color: #fff;
  border: none;
  padding: 0.4rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
}

.btn-crawl:hover { background: #1d4ed8; }

.flash {
  background: #d1fae5;
  border-left: 4px solid #10b981;
  padding: 0.6rem 1.5rem;
  font-size: 0.9rem;
  color: #065f46;
}

main {
  max-width: 800px;
  margin: 2rem auto;
  padding: 0 1.5rem;
}

h1 { font-size: 1.5rem; margin-bottom: 1.25rem; }
h2 { font-size: 1.1rem; margin-bottom: 0.75rem; }

.news-card {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.category {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  background: #e0e7ff;
  color: #3730a3;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
}

.news-card h2 {
  font-size: 1.15rem;
  margin-bottom: 0.5rem;
  color: #111;
}

.news-card h2 a { color: inherit; text-decoration: none; }
.news-card h2 a:hover { text-decoration: underline; }

.summary { color: #444; margin-bottom: 0.75rem; }

.news-card footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.8rem;
  color: #888;
  gap: 1rem;
}

.news-card footer a { color: #2563eb; word-break: break-all; }
.source-label { font-weight: 500; }
.timestamp { white-space: nowrap; flex-shrink: 0; }

.empty { color: #888; font-style: italic; }

/* Filter bar */
.filter-bar {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}

.category-filters { display: flex; gap: 0.4rem; flex-wrap: wrap; }

.filter-btn {
  background: #f0f0f0;
  border: 1px solid #ddd;
  border-radius: 999px;
  padding: 0.3rem 0.85rem;
  font-size: 0.82rem;
  cursor: pointer;
  color: #444;
}

.filter-btn:hover { background: #e0e0e0; }
.filter-btn.active { background: #2563eb; color: #fff; border-color: #2563eb; }

#search-input {
  flex: 1;
  min-width: 180px;
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 0.35rem 0.75rem;
  font-size: 0.88rem;
}

/* Entity filter bar */
.entity-filter-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: 6px;
  padding: 0.5rem 0.75rem;
  margin-bottom: 1rem;
  font-size: 0.85rem;
}

.entity-filter-label { color: #92400e; font-weight: 600; }

.active-entity-chip {
  background: #fef3c7;
  border: 1px solid #fcd34d;
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
  color: #78350f;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.active-entity-chip button {
  background: none;
  border: none;
  cursor: pointer;
  color: #78350f;
  font-size: 0.8rem;
  padding: 0;
  line-height: 1;
}

#clear-entity-filter {
  margin-left: auto;
  background: none;
  border: 1px solid #d97706;
  border-radius: 4px;
  color: #b45309;
  padding: 0.15rem 0.5rem;
  cursor: pointer;
  font-size: 0.8rem;
}

/* Entity tags on cards */
.entity-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.6rem;
}

.entity-tag {
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  cursor: pointer;
  user-select: none;
  transition: opacity 0.15s;
}

.entity-tag:hover { opacity: 0.75; }
.entity-tag.company { background: #dbeafe; color: #1e40af; }
.entity-tag.person  { background: #dcfce7; color: #166534; }
.entity-tag.product { background: #fae8ff; color: #7e22ce; }

.add-source { margin-bottom: 2rem; }

.form-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.form-row input[type="url"] { flex: 2; min-width: 200px; }
.form-row input[type="text"] { flex: 1; min-width: 120px; }

input[type="url"], input[type="text"] {
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 0.4rem 0.75rem;
  font-size: 0.9rem;
}

.form-row button, .btn-delete {
  background: #2563eb;
  color: #fff;
  border: none;
  padding: 0.4rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
}

.btn-delete { background: #ef4444; }
.btn-delete:hover { background: #dc2626; }

table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #e0e0e0;
  font-size: 0.9rem;
}

th, td {
  padding: 0.65rem 1rem;
  text-align: left;
  border-bottom: 1px solid #e0e0e0;
}

th { background: #f9f9f9; font-weight: 600; color: #555; }
tr:last-child td { border-bottom: none; }
td a { color: #2563eb; word-break: break-all; }
td.article-count { text-align: center; font-weight: 600; color: #2563eb; }

.category-mgmt { margin-top: 2.5rem; }

.category-note {
  font-size: 0.85rem;
  color: #666;
  margin-bottom: 0.85rem;
}

.add-category-form { margin-bottom: 1rem; }

.category-table { margin-top: 0.5rem; }

.cat-locked { color: #bbb; font-size: 0.85rem; }

/* Admin page — crawl zone (mirrors danger-zone, green) */
.crawl-zone {
  border: 1px solid #bbf7d0;
  border-radius: 8px;
  padding: 1.25rem;
  background: #f0fdf4;
  margin-bottom: 2rem;
}

.crawl-zone h2 { color: #14532d; margin-bottom: 1rem; }

.crawl-actions {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.crawl-card {
  flex: 1;
  min-width: 200px;
  background: #fff;
  border: 1px solid #bbf7d0;
  border-radius: 8px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.crawl-card-body p {
  font-size: 0.85rem;
  color: #666;
  margin-top: 0.25rem;
}

.interval-form {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.interval-form input[type="number"] {
  width: 80px;
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 0.35rem 0.6rem;
  font-size: 0.9rem;
}

.interval-unit { font-size: 0.88rem; color: #555; }
.hint { font-size: 0.8rem; color: #888; font-style: italic; }

.lang-form {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.lang-option {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
  cursor: pointer;
}

.btn-success {
  background: #16a34a;
  color: #fff;
  border: none;
  padding: 0.45rem 1.1rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  align-self: flex-start;
}

.btn-success:hover { background: #15803d; }

.btn-primary {
  background: #2563eb;
  color: #fff;
  border: none;
  padding: 0.45rem 1.1rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  align-self: flex-start;
  margin-top: 0.25rem;
}

.btn-primary:hover { background: #1d4ed8; }

/* Settings zone */
.settings-zone {
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 1.25rem;
  background: #fff;
  margin-bottom: 2rem;
}

.settings-zone h2 { color: #1a1a1a; margin-bottom: 1rem; }

.settings-cards {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.settings-card {
  flex: 1;
  min-width: 200px;
  background: #f9f9f9;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.settings-card-body p {
  font-size: 0.85rem;
  color: #666;
  margin-top: 0.25rem;
}

/* Admin page */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: #fff;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 1.25rem;
  text-align: center;
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: #2563eb;
  line-height: 1;
  margin-bottom: 0.35rem;
}

.stat-label {
  font-size: 0.82rem;
  color: #666;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stats-columns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2.5rem;
}

.stats-section { }

.danger-zone {
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 1.25rem;
  background: #fff5f5;
}

.danger-zone h2 { color: #991b1b; margin-bottom: 1rem; }

.reset-actions {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.reset-card {
  flex: 1;
  min-width: 200px;
  background: #fff;
  border: 1px solid #fecaca;
  border-radius: 8px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.reset-card-body p {
  font-size: 0.85rem;
  color: #666;
  margin-top: 0.25rem;
}

.btn-danger {
  background: #ef4444;
  color: #fff;
  border: none;
  padding: 0.45rem 1.1rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  align-self: flex-start;
}

.btn-danger:hover { background: #dc2626; }

/* Nav badge */
.nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: #f59e0b;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  min-width: 1.1rem;
  height: 1.1rem;
  border-radius: 999px;
  padding: 0 0.3rem;
  margin-left: 0.3rem;
  vertical-align: middle;
  line-height: 1;
}

/* Staging page */
.staging-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.staging-count {
  font-size: 1rem;
  font-weight: 400;
  color: #666;
  margin-left: 0.4rem;
}

.staging-bulk-actions {
  display: flex;
  gap: 0.5rem;
}

.staging-card .card-header {
  justify-content: space-between;
}

.staging-actions {
  display: flex;
  gap: 0.4rem;
}

.btn-publish {
  background: #16a34a;
  color: #fff;
  border: none;
  padding: 0.25rem 0.75rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 500;
}

.btn-publish:hover { background: #15803d; }

.btn-discard {
  background: #f3f4f6;
  color: #374151;
  border: 1px solid #d1d5db;
  padding: 0.25rem 0.75rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 500;
}

.btn-discard:hover { background: #e5e7eb; }
