:root {
  --bg: #f6f4ef;
  --bg-card: #fefdfb;
  --text: #1e1e1e;
  --text-muted: #6b6560;
  --accent: #a83232;
  --accent-soft: #f0e4e4;
  --border: #ddd8cf;
  --border-light: #ece8e0;
  --shadow: 0 1px 3px rgba(30, 30, 30, 0.06);
  --radius: 4px;
  --font-serif: "Noto Serif SC", "Songti SC", "SimSun", serif;
  --font-sans: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  --max-width: 860px;
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

a {
  color: inherit;
  text-decoration: none;
}

/* ── Header ── */
.site-header {
  background: var(--bg-card);
  border-bottom: 2px solid var(--text);
  padding: 0 24px;
}

.header-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 28px 0 20px;
}

.site-title {
  font-family: var(--font-serif);
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.site-title span {
  color: var(--accent);
}

.site-meta {
  font-size: 0.8125rem;
  color: var(--text-muted);
  text-align: right;
}

.site-meta time {
  display: block;
  font-variant-numeric: tabular-nums;
}

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

.header-link {
  font-size: 0.8125rem;
  color: var(--text-muted);
  border-bottom: 1px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}

.header-link:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ── Tabs ── */
.tabs-bar {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.tabs-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  display: flex;
  gap: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs-inner::-webkit-scrollbar {
  display: none;
}

.tab-btn {
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 500;
  padding: 14px 20px;
  border: none;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
  position: relative;
}

.tab-btn:hover {
  color: var(--text);
}

.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ── Main content ── */
.main {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 32px 24px 64px;
}

.source-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-light);
}

.source-name {
  font-family: var(--font-serif);
  font-size: 1.125rem;
  font-weight: 600;
}

.source-updated {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.refresh-btn {
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  padding: 6px 14px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-muted);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.refresh-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.refresh-btn.loading {
  opacity: 0.6;
  pointer-events: none;
}

/* ── News list ── */
.news-list {
  list-style: none;
}

.news-item {
  border-bottom: 1px solid var(--border-light);
}

.news-link {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  align-items: baseline;
  padding: 18px 4px;
  transition: background 0.12s;
}

.news-link:hover {
  background: var(--accent-soft);
}

.news-link:hover .news-title {
  color: var(--accent);
}

.news-title {
  font-family: var(--font-serif);
  font-size: 1rem;
  font-weight: 500;
  line-height: 1.55;
  transition: color 0.12s;
}

.news-date {
  font-size: 0.8125rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  padding-top: 2px;
}

/* ── States ── */
.empty-state,
.loading-state,
.error-state {
  text-align: center;
  padding: 64px 24px;
  color: var(--text-muted);
}

.empty-state p,
.loading-state p {
  font-size: 0.9375rem;
  margin-top: 8px;
}

.error-state {
  color: var(--accent);
}

.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ── Footer ── */
.site-footer {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 24px;
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border-light);
}

.hidden {
  display: none !important;
}

/* ── Login ── */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 36px 32px;
}

.login-title {
  font-family: var(--font-serif);
  font-size: 1.375rem;
  font-weight: 600;
  text-align: center;
  margin-bottom: 28px;
}

.login-form .form-group {
  margin-bottom: 16px;
}

.login-btn {
  width: 100%;
  margin-top: 8px;
  padding: 10px;
}

.admin-user {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

/* ── Admin page overrides ── */
.admin-body {
  background: var(--bg);
}

.admin-header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 20px 24px;
}

.admin-header-inner {
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.admin-title {
  font-family: var(--font-serif);
  font-size: 1.25rem;
  font-weight: 600;
}

.admin-main {
  max-width: 960px;
  margin: 0 auto;
  padding: 32px 24px 64px;
}

.section {
  margin-bottom: 40px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.section-title {
  font-family: var(--font-serif);
  font-size: 1.0625rem;
  font-weight: 600;
}

.btn {
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  padding: 8px 16px;
  border-radius: var(--radius);
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  transition: all 0.15s;
}

.btn:hover {
  border-color: var(--text-muted);
}

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

.btn-primary:hover {
  background: #8f2a2a;
  border-color: #8f2a2a;
}

.btn-danger {
  color: var(--accent);
  border-color: var(--accent-soft);
}

.btn-danger:hover {
  background: var(--accent-soft);
}

.btn-sm {
  padding: 4px 10px;
  font-size: 0.75rem;
}

/* Source cards */
.source-cards {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.source-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
}

.source-card-name {
  font-weight: 600;
  font-size: 0.9375rem;
}

.source-card-url {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
  word-break: break-all;
}

.source-card-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.source-card-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.badge {
  display: inline-block;
  font-size: 0.6875rem;
  padding: 2px 8px;
  border-radius: 2px;
  font-weight: 500;
}

.badge-on {
  background: #e8f0e8;
  color: #3a6b3a;
}

.badge-off {
  background: #f0ece8;
  color: var(--text-muted);
}

/* Form */
.form-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  display: none;
}

.form-panel.open {
  display: block;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group.full {
  grid-column: 1 / -1;
}

.form-group label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text);
}

.form-group .hint {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 400;
}

.form-group input,
.form-group select {
  font-family: var(--font-sans);
  font-size: 0.875rem;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s;
}

.form-group input:focus,
.form-group select:focus {
  border-color: var(--accent);
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border-light);
}

.rule-toggle {
  display: flex;
  gap: 0;
  margin-bottom: 16px;
}

.rule-toggle-btn {
  font-family: var(--font-sans);
  font-size: 0.8125rem;
  padding: 8px 16px;
  border: 1px solid var(--border);
  background: var(--bg);
  cursor: pointer;
  color: var(--text-muted);
}

.rule-toggle-btn:first-child {
  border-radius: var(--radius) 0 0 var(--radius);
}

.rule-toggle-btn:last-child {
  border-radius: 0 var(--radius) var(--radius) 0;
  border-left: none;
}

.rule-toggle-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.rule-fields.hidden {
  display: none;
}

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--text);
  color: #fff;
  font-size: 0.8125rem;
  padding: 12px 20px;
  border-radius: var(--radius);
  opacity: 0;
  transform: translateY(8px);
  transition: all 0.25s;
  z-index: 100;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.error {
  background: var(--accent);
}

@media (max-width: 640px) {
  .header-inner {
    flex-direction: column;
    gap: 8px;
    align-items: flex-start;
  }

  .site-meta {
    text-align: left;
  }

  .news-link {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .source-card {
    grid-template-columns: 1fr;
  }

  .source-card-actions {
    justify-content: flex-start;
  }
}
