/* ===== CSS Variables ===== */
:root {
  --bg: #f5f7fb;
  --card: #fff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #2454a6;
  --brand2: #163b76;
  --tag: #eef2ff;
  --green: #047857;
  --red: #b91c1c;
  --gold: #b45309;
  --touch-min: 44px;
  --radius: 12px;
  --shadow: 0 6px 20px rgba(17,24,39,.04);
}

/* ===== Reset & Base ===== */
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}
body {
  margin: 0;
  font-family: "Microsoft YaHei", "PingFang SC", -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ===== Header ===== */
header {
  background: linear-gradient(135deg, #173b73, #2563eb);
  color: #fff;
  padding: 28px 22px 24px;
}
header .wrap {
  max-width: 1200px;
  margin: 0 auto;
}
h1 {
  margin: 0 0 8px;
  font-size: 28px;
  letter-spacing: .5px;
  line-height: 1.3;
}
.subtitle {
  opacity: .92;
  font-size: 14px;
  line-height: 1.7;
}

/* ===== Main Layout ===== */
main {
  max-width: 1200px;
  margin: 18px auto;
  padding: 0 16px 34px;
}
.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}
@media(min-width:1400px) {
  main, header .wrap { max-width: 1300px; }
  .panel { padding: 24px; }
}

/* ===== Search Grid ===== */
.grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 14px;
  align-items: end;
}
.field label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}
.field input,
.field select {
  width: 100%;
  height: var(--touch-min);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 12px;
  font-size: 16px;  /* prevent iOS zoom on focus */
  background: #fff;
  color: var(--text);
  appearance: none;
  transition: border-color .15s;
}
.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(36,84,166,.1);
}

/* ===== Action Bar ===== */
.action-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 16px 24px;
  align-items: flex-end;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
.action-group {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.action-label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
  margin-right: 2px;
  white-space: nowrap;
}

/* ===== Buttons ===== */
.btn {
  height: var(--touch-min);
  border: none;
  border-radius: 10px;
  padding: 0 16px;
  background: var(--brand);
  color: #fff;
  font-size: 14px;
  cursor: pointer;
  min-width: 86px;
  touch-action: manipulation;
  transition: background .15s, transform .1s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  white-space: nowrap;
  user-select: none;
}
.btn:active { transform: scale(.97); }
.btn.secondary {
  background: #eef2ff;
  color: #1e3a8a;
  border: 1px solid transparent;
}
.btn.light {
  height: 36px;
  padding: 0 12px;
  font-size: 13px;
  background: #f3f4f6;
  color: #374151;
  border: 1px solid var(--line);
  min-width: auto;
}
.btn.fav {
  background: #fff7ed;
  color: var(--gold);
  border: 1px solid #fed7aa;
}
.btn:hover { background: var(--brand2); }
.btn.secondary:hover { background: #dbeafe; }
.btn.light:hover { background: #e5e7eb; }
.btn.fav:hover { background: #ffedd5; }

/* ===== Source Chips & Topics ===== */
.sources, .chips, .topic-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}
.source, .chip, .topic-card {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  background: #fff;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  transition: all .15s;
}
.source:active, .chip:active, .topic-card:active {
  transform: scale(.96);
}
.source.active, .chip.active, .topic-card.active {
  background: #eaf1ff;
  border-color: #93c5fd;
  color: #1d4ed8;
  font-weight: 600;
}
.section-title {
  margin-top: 16px;
  font-size: 13px;
  color: #374151;
  font-weight: 700;
}
.topic-card {
  border-radius: 10px;
  text-align: left;
  max-width: 280px;
  padding: 10px 14px;
}
.topic-card span {
  display: block;
  color: var(--muted);
  font-weight: 400;
  font-size: 12px;
  margin-top: 4px;
  line-height: 1.5;
}
.switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: var(--touch-min);
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  color: #374151;
  font-size: 13px;
  cursor: pointer;
}
.switch input { accent-color: var(--brand); width: 16px; height: 16px; }

/* ===== Data Status ===== */
.statusline {
  font-size: 12px;
  color: #6b7280;
  margin-top: 10px;
  line-height: 1.7;
}
/* ===== Collapsible Data Status Panel ===== */
.data-status {
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  box-shadow: var(--shadow);
  overflow: hidden;
}
.data-status-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  cursor: pointer;
  user-select: none;
  transition: background .15s;
  -webkit-tap-highlight-color: transparent;
}
.data-status-toggle:hover { background: #f9fafb; }
.data-status-toggle:active { background: #f3f4f6; }
.toggle-icon { font-size: 10px; color: var(--muted); transition: transform .2s; }
.toggle-label { font-size: 13px; font-weight: 700; color: #374151; }
.toggle-summary { font-size: 12px; color: var(--muted); margin-left: auto; }
.data-status-body {
  padding: 0 16px 16px;
  background: #f9fafb;
}
.status-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}
.status-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
}
.status-label {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.status-value {
  font-size: 20px;
  font-weight: 700;
  color: #111827;
}
.status-value.good { color: var(--green); }
.status-value.bad { color: var(--red); }

/* ===== Health Panel ===== */
.health-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.health-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  background: #fff;
  min-width: 800px;
}
.health-table th, .health-table td {
  border: 1px solid var(--line);
  padding: 8px 10px;
  text-align: left;
  white-space: nowrap;
}
.health-table th {
  background: #f3f4f6;
  color: #374151;
  position: sticky;
  top: 0;
}
.health-ok { color: var(--green); font-weight: 700; }
.health-partial { color: #b45309; font-weight: 700; }
.health-error { color: var(--red); font-weight: 700; }

.status-errors, .health-panel {
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}
.status-errors summary, .health-panel summary {
  cursor: pointer;
  color: #374151;
  font-size: 13px;
  font-weight: 700;
  padding: 4px 0;
}
.error-list {
  margin: 8px 0 0;
  padding-left: 18px;
  color: #4b5563;
  font-size: 12px;
  line-height: 1.7;
}

/* ===== Results ===== */
.toolbar {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  color: var(--muted);
  font-size: 14px;
}
.toolbar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.result {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin: 12px 0;
  box-shadow: var(--shadow);
}
.result-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
}
.title {
  font-size: 18px;
  line-height: 1.5;
  font-weight: 700;
  color: #102a5e;
  text-decoration: none;
  word-break: break-word;
}
.title:hover { text-decoration: underline; }
.meta {
  margin: 8px 0 10px;
  color: var(--muted);
  font-size: 13px;
  word-break: break-all;
}
.summary {
  line-height: 1.8;
  font-size: 14.5px;
  color: #374151;
  word-break: break-word;
}
.tag {
  display: inline-block;
  background: var(--tag);
  border-radius: 999px;
  padding: 4px 10px;
  margin: 6px 6px 0 0;
  color: #3730a3;
  font-size: 12px;
}
.category { background: #ecfdf5; color: #065f46; }
.score { background: #fef3c7; color: #92400e; }
.favorite-tag { background: #fff7ed; color: #b45309; }
/* Category-specific colors — applied via data attribute in JS */
[data-cat="政策规划"] { background: #eef2ff; color: #3730a3; }
[data-cat="政策文件"] { background: #e0f2fe; color: #075985; }
[data-cat="政策解读"] { background: #f0fdf4; color: #166534; }
[data-cat="理论评论"] { background: #fdf4ff; color: #86198f; }
[data-cat="产业科技"] { background: #fff7ed; color: #9a3412; }
[data-cat="经济数据"] { background: #fef3c7; color: #92400e; }
[data-cat="金融财经"] { background: #fce7f3; color: #9d174d; }
[data-cat="农业农村"] { background: #f0fdf4; color: #166534; }
[data-cat="数字经济"] { background: #e0f2fe; color: #0369a1; }
[data-cat="绿色低碳"] { background: #ecfdf5; color: #065f46; }
[data-cat="对外开放"] { background: #f0fdf4; color: #166534; }
[data-cat="社会民生"] { background: #fef2f2; color: #991b1b; }
[data-cat="改革营商"] { background: #fefce8; color: #854d0e; }

/* ===== Pagination ===== */
.pagination {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--line);
  margin-top: 16px;
  padding-top: 14px;
  color: var(--muted);
  font-size: 13px;
}
.pagination > span {
  white-space: nowrap;
}
.pagination-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.pagination .page-input {
  width: 64px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 8px;
  font-size: 14px;
  text-align: center;
}

/* ===== Misc ===== */
mark {
  background: #fde68a;
  border-radius: 3px;
  padding: 0 2px;
}
.empty {
  padding: 40px;
  text-align: center;
  color: var(--muted);
  line-height: 1.8;
}
.notice {
  font-size: 13px;
  line-height: 1.8;
  color: #4b5563;
}
.notice b { color: #111827; }
.footer {
  color: #9ca3af;
  text-align: center;
  font-size: 12px;
  margin-top: 18px;
}
.stat { font-weight: 700; color: #111827; }
.log-ok { color: var(--green); }
.log-error { color: var(--red); }

/* ===== Topic Cards, Watchwords, Health ===== */
.topic-list, .watch-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 10px; }
.topic-card, .watch-card { max-width: none; width: 100%; border-radius: 10px; }
.topic-card { display: block; }
.topic-card .btn, .watch-card .btn { width: auto; }
.topic-keywords, .topic-metrics, .watch-metrics { font-size: 12px; color: #6b7280; line-height: 1.6; margin-top: 6px; }
.topic-actions, .export-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.watch-card { border: 1px solid var(--line); background: #fff; padding: 10px 12px; text-align: left; cursor: pointer; }
.watch-card strong { display: block; font-size: 14px; }
.metric-note { font-size: 12px; color: #6b7280; line-height: 1.7; margin-top: 10px; }
.mode-select { height: 42px; border: 1px solid var(--line); border-radius: 10px; background: #fff; padding: 0 10px; }
.active-topic-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.error-banner { padding: 16px; border: 1px solid #fecaca; border-radius: 10px; background: #fef2f2; color: #991b1b; }

.health-groups { display: grid; gap: 10px; margin-top: 10px; }
.health-group { border: 1px solid var(--line); border-radius: 10px; background: #fff; padding: 10px; }
.health-group h3 { font-size: 13px; margin: 0 0 8px; }
.health-items { display: grid; gap: 6px; }
.health-item { font-size: 12px; line-height: 1.6; color: #374151; border-top: 1px solid #f3f4f6; padding-top: 6px; }
.health-item:first-child { border-top: 0; padding-top: 0; }

@media (max-width: 640px) {
  .topic-list, .watch-list { grid-template-columns: 1fr; }
  .topic-actions, .export-actions, .active-topic-bar { align-items: stretch; }
  .mode-select { width: 100%; }
}

/* ================================================
   RESPONSIVE: Tablet (<=1024px)
   ================================================ */
@media(max-width:1024px) {
  .grid {
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }
  .grid .field:first-child {
    grid-column: 1 / -1;
  }
  .status-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .result-head {
    gap: 10px;
  }
  .toolbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }
  .toolbar-actions {
    width: 100%;
  }
}

/* ================================================
   RESPONSIVE: Phone (≤768px)
   ================================================ */
@media(max-width:768px) {
  /* Header */
  header {
    padding: 20px 16px 18px;
  }
  h1 {
    font-size: 22px;
  }
  .subtitle {
    font-size: 13px;
    line-height: 1.6;
  }

  /* Panels */
  .panel {
    padding: 14px;
    border-radius: 10px;
    margin-bottom: 12px;
  }

  /* Search Grid → single column */
  .grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .grid .field:first-child {
    grid-column: auto;
  }

  /* Form elements */
  .field input, .field select {
    height: 46px;
    font-size: 16px;
  }

  /* Action bar */
  .action-bar {
    flex-direction: column;
    gap: 10px;
    margin-top: 12px;
    padding-top: 12px;
  }
  .action-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: 100%;
  }
  .action-group .action-label {
    grid-column: 1 / -1;
  }
  .btn {
    height: 44px;
    min-width: 0;
    width: 100%;
    padding: 0 12px;
    font-size: 14px;
  }
  .btn.light {
    height: 38px;
    font-size: 13px;
  }

  /* Switch */
  .switch {
    height: 44px;
    width: 100%;
    justify-content: center;
    font-size: 14px;
  }

  /* Chips & sources */
  .chips, .sources {
    gap: 6px;
  }
  .source, .chip {
    font-size: 12px;
    padding: 7px 12px;
  }
  .topic-card {
    max-width: 100%;
    width: calc(50% - 4px);
    font-size: 13px;
    padding: 10px 12px;
  }

  /* Status grid → 2 columns on phone */
  .status-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }
  .status-card {
    padding: 10px 12px;
  }
  .status-value {
    font-size: 18px;
  }

  /* Health table */
  .health-table-wrap {
    border-radius: 6px;
  }
  .health-table th, .health-table td {
    padding: 6px 8px;
    font-size: 11px;
  }

  /* Results */
  .result {
    padding: 14px;
    margin: 10px 0;
    border-radius: 10px;
  }
  .result-head {
    flex-direction: column;
    gap: 8px;
  }
  .result-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    width: 100%;
  }
  .result-actions .btn {
    height: 38px;
    min-width: 0;
  }
  .title {
    font-size: 16px;
    line-height: 1.45;
  }
  .meta {
    font-size: 12px;
    line-height: 1.6;
  }
  .summary {
    font-size: 14px;
    line-height: 1.7;
  }

  /* Pagination */
  .pagination {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding-top: 12px;
    margin-top: 14px;
  }
  .pagination > span {
    text-align: center;
    font-size: 13px;
  }
  .pagination-actions {
    justify-content: center;
    gap: 6px;
  }
  .pagination-actions .btn {
    width: auto;
    min-width: 36px;
    height: 38px;
    padding: 0 10px;
    font-size: 13px;
  }
  .pagination .page-input {
    height: 38px;
    width: 56px;
  }

  /* Toolbar */
  .toolbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    font-size: 13px;
  }
  .toolbar-actions {
    width: 100%;
  }

  /* Footer */
  .footer {
    padding: 0 4px;
  }
}

/* ================================================
   RESPONSIVE: Small Phone (≤400px)
   ================================================ */
@media(max-width:400px) {
  header {
    padding: 16px 12px 14px;
  }
  h1 {
    font-size: 19px;
  }
  .subtitle {
    font-size: 12px;
  }

  main {
    padding: 0 10px 24px;
  }

  .panel {
    padding: 12px;
    border-radius: 8px;
  }

  .action-group {
    grid-template-columns: 1fr;
  }

  .result-actions {
    grid-template-columns: 1fr;
  }

  .topic-card {
    width: 100%;
    max-width: 100%;
  }

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

  .title {
    font-size: 15px;
  }

  .pagination-actions {
    gap: 4px;
  }
  .pagination-actions .btn {
    height: 36px;
    min-width: 32px;
    padding: 0 8px;
    font-size: 12px;
  }
}
