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

:root {
  --bg: #0f1117;
  --surface: #1a1c25;
  --surface2: #242733;
  --border: #2e3144;
  --text: #e4e6ed;
  --text2: #9ca0b0;
  --primary: #6c72cb;
  --primary-hover: #7f85d8;
  --accent: #4ecdc4;
  --accent-hover: #6ad8d1;
  --danger: #e74c5e;
  --tag-up-fast: #ff6b6b;
  --tag-up: #ffa94d;
  --tag-hot: #ff922b;
  --tag-stable: #69db7c;
  --tag-recover: #74c0fc;
  --tag-default: #868e96;
  --tag-pending: #da77f2;
  --radius: 8px;
  --shadow: 0 2px 12px rgba(0,0,0,.3);
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

.hidden { display: none !important; }

header {
  text-align: center;
  padding: 2.5rem 1rem 1.5rem;
  background: linear-gradient(135deg, #1a1c2580, #242733);
  border-bottom: 1px solid var(--border);
}
header h1 { font-size: 1.8rem; letter-spacing: .5px; }
header .subtitle { color: var(--text2); font-size: .95rem; margin-top: .3rem; }

main { max-width: 1200px; margin: 0 auto; padding: 1.5rem 1rem 4rem; }

/* ── Toolbar ── */
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.toolbar-left { display: flex; gap: .6rem; flex-wrap: wrap; flex: 1; }
.toolbar-left input,
.toolbar-left select {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: .55rem .8rem;
  border-radius: var(--radius);
  font-size: .9rem;
  outline: none;
  transition: border-color .2s;
}
.toolbar-left input:focus,
.toolbar-left select:focus { border-color: var(--primary); }
.toolbar-left input { min-width: 200px; flex: 1; max-width: 320px; }

/* ── Stats ── */
.stats { display: flex; gap: .8rem; flex-wrap: wrap; margin-bottom: 1.2rem; }
.stat-badge {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: .3rem .85rem;
  font-size: .82rem;
  color: var(--text2);
}
.stat-badge strong { color: var(--text); margin-right: .2rem; }

/* ── Buttons ── */
.btn {
  padding: .55rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: .88rem;
  transition: all .2s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface2); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #111; font-weight: 600; }
.btn-accent:hover { background: var(--accent-hover); }
.btn-small { padding: .3rem .7rem; font-size: .8rem; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: rgba(231,76,94,.12); }

/* ── Table ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
thead th {
  background: var(--surface);
  padding: .7rem .6rem;
  text-align: left;
  color: var(--text2);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  white-space: nowrap;
}
tbody td {
  padding: .6rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
tbody tr:hover { background: var(--surface); }

.keyword-cell { font-weight: 600; color: var(--accent); }
.keyword-cell a { color: var(--accent); text-decoration: none; }
.keyword-cell a:hover { text-decoration: underline; }

/* ── Trend Tags ── */
.trend-tag {
  display: inline-block;
  padding: .15rem .55rem;
  border-radius: 12px;
  font-size: .78rem;
  font-weight: 600;
  white-space: nowrap;
}
.trend-fast { background: rgba(255,107,107,.15); color: var(--tag-up-fast); }
.trend-up { background: rgba(255,169,77,.15); color: var(--tag-up); }
.trend-hot { background: rgba(255,146,43,.15); color: var(--tag-hot); }
.trend-stable { background: rgba(105,219,124,.12); color: var(--tag-stable); }
.trend-recover { background: rgba(116,192,252,.12); color: var(--tag-recover); }
.trend-pending { background: rgba(218,119,242,.12); color: var(--tag-pending); }
.trend-default { background: rgba(134,142,150,.12); color: var(--tag-default); }

.category-tag {
  display: inline-block;
  padding: .15rem .5rem;
  border-radius: 12px;
  font-size: .78rem;
  background: rgba(108,114,203,.12);
  color: var(--primary);
  white-space: nowrap;
}

.action-btns { display: flex; gap: .3rem; white-space: nowrap; }

/* ── Expand Section ── */
.expand-section {
  margin-top: 2.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}
.expand-section h2 { font-size: 1.15rem; margin-bottom: .3rem; }
.expand-section .hint { color: var(--text2); font-size: .85rem; margin-bottom: 1rem; }
.expand-bar { display: flex; gap: .6rem; }
.expand-bar input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: .6rem .9rem;
  border-radius: var(--radius);
  font-size: .95rem;
  outline: none;
}
.expand-bar input:focus { border-color: var(--accent); }

.expand-results { margin-top: 1.2rem; }
.expand-header { display: flex; align-items: center; gap: .8rem; margin-bottom: .8rem; flex-wrap: wrap; }
.expand-header span { font-weight: 600; font-size: .95rem; }

.expand-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: .5rem; }
.expand-item {
  display: flex; align-items: center; gap: .5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .45rem .7rem;
  font-size: .85rem;
  transition: border-color .2s;
}
.expand-item:hover { border-color: var(--primary); }
.expand-item input[type="checkbox"] { accent-color: var(--accent); flex-shrink: 0; }
.expand-item .kw { flex: 1; }
.expand-item .type-badge {
  font-size: .72rem;
  padding: .1rem .4rem;
  border-radius: 8px;
  background: var(--surface2);
  color: var(--text2);
}
.expand-item a {
  color: var(--primary);
  font-size: .78rem;
  text-decoration: none;
  flex-shrink: 0;
}
.expand-item a:hover { text-decoration: underline; }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 480px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 1rem 1.2rem;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1.05rem; }
.modal-close {
  background: none; border: none; color: var(--text2);
  font-size: 1.4rem; cursor: pointer; line-height: 1;
}
.modal-close:hover { color: var(--text); }

#keywordForm {
  padding: 1.2rem;
  display: flex; flex-direction: column; gap: .9rem;
}
#keywordForm label {
  display: flex; flex-direction: column; gap: .25rem;
  font-size: .85rem; color: var(--text2);
}
#keywordForm input,
#keywordForm select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: .5rem .7rem;
  border-radius: var(--radius);
  font-size: .9rem;
  outline: none;
}
#keywordForm input:focus,
#keywordForm select:focus { border-color: var(--primary); }
.form-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: .5rem; }

/* ── Responsive ── */
@media (max-width: 640px) {
  .expand-list { grid-template-columns: 1fr; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar-left { flex-direction: column; }
  .toolbar-left input { max-width: 100%; }
}
