:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --text: #1a2332;
  --muted: #6b7a90;
  --border: #e4e9f0;
  --primary: #1a6fb5;
  --primary-hover: #155a94;
  --secondary: #0f8a6a;
  --secondary-hover: #0c7056;
  --danger: #c0392b;
  --ok: #1e8e3e;
  --cached: #e8f5e9;
  --cached-text: #1b5e20;
  --shadow: 0 8px 24px rgba(26, 35, 50, 0.06);
  --radius: 14px;
  --font: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: linear-gradient(180deg, #eaf1f8 0%, var(--bg) 220px);
  color: var(--text);
  min-height: 100vh;
}

.sidebar {
  position: fixed; inset: 0 auto 0 0; width: 220px; padding: 24px 14px;
  background: #17283d; color: #fff; z-index: 20;
  box-shadow: 8px 0 24px rgba(15, 35, 58, 0.12);
}
.sidebar-brand { display: flex; align-items: center; gap: 11px; padding: 0 8px 22px; }
.sidebar-brand .logo { width: 42px; height: 42px; box-shadow: none; }
.sidebar-brand strong { display: block; font-size: 1rem; }
.sidebar-brand span { display: block; margin-top: 2px; color: #9fb2c8; font-size: 0.75rem; }
.side-nav { display: flex; flex-direction: column; gap: 7px; }
.side-nav-item {
  width: 100%; border: 0; border-radius: 10px; padding: 12px 13px;
  background: transparent; color: #c6d3e1; text-align: left; font-size: 0.94rem;
  cursor: pointer; display: flex; align-items: center; gap: 10px;
}
.side-nav-item:hover { background: rgba(255,255,255,0.08); color: #fff; }
.side-nav-item.active { background: #287dbf; color: #fff; font-weight: 700; }
.side-nav-item span { width: 20px; text-align: center; font-size: 1.1rem; }
body[data-active-view="search"] [data-view-panel="monitor"],
body[data-active-view="monitor"] [data-view-panel="search"] { display: none !important; }

.app {
  max-width: 1180px;
  margin: 0 auto 0 max(220px, calc((100vw - 1180px + 220px) / 2));
  padding: 28px 20px 48px;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 20px;
}
.brand { display: flex; gap: 14px; align-items: center; }
.logo {
  width: 48px; height: 48px; border-radius: 12px;
  background: linear-gradient(135deg, #1a6fb5, #0f8a6a);
  color: #fff; font-weight: 800; display: grid; place-items: center;
  letter-spacing: -0.5px; box-shadow: var(--shadow);
}
.header h1 { margin: 0; font-size: 1.45rem; letter-spacing: 0.02em; }
.sub { margin: 4px 0 0; color: var(--muted); font-size: 0.92rem; }
.header-right {
  display: flex; flex-direction: column; align-items: flex-end; gap: 6px;
  max-width: min(48vw, 420px);
}
.header-meta {
  font-size: 0.82rem; color: var(--muted);
  background: rgba(255,255,255,0.8);
  border: 1px solid var(--border);
  padding: 7px 12px; border-radius: 999px;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header-meta.path {
  border-radius: 10px;
  white-space: normal;
  line-height: 1.35;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 0.75rem;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 14px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr 1fr;
  gap: 14px 16px;
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field-wide { grid-column: 1 / -1; }
.field-company { grid-column: span 2; }
.field span { font-size: 0.88rem; font-weight: 600; color: #334155; }
.field em { font-style: normal; font-weight: 400; color: var(--muted); margin-left: 6px; }
.field input {
  height: 42px; border: 1px solid var(--border); border-radius: 10px;
  padding: 0 12px; font-size: 1rem; outline: none; background: #fbfcfe;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus {
  border-color: #8bb8df;
  box-shadow: 0 0 0 3px rgba(26,111,181,0.12);
  background: #fff;
}
.source-field { border: 0; padding: 0; margin: 0; }
.source-field legend { font-size: 0.88rem; font-weight: 600; color: #334155; margin-bottom: 8px; }
.source-options { display: flex; flex-wrap: wrap; gap: 18px; }

.advanced-search {
  margin-top: 16px; border: 1px solid var(--border); border-radius: 12px;
  background: #fbfcfe; overflow: hidden;
}
.advanced-search summary {
  cursor: pointer; padding: 12px 14px; font-weight: 700; color: #334155;
  user-select: none;
}
.advanced-search summary em {
  font-style: normal; font-weight: 400; color: var(--muted); margin-left: 8px;
}
.search-groups {
  display: grid; grid-template-columns: 1fr 1fr; gap: 18px;
  padding: 2px 14px 14px;
}
.search-group h3 { margin: 4px 0 9px; font-size: 0.9rem; color: #334155; }
.search-row {
  display: grid; grid-template-columns: 68px 1fr; min-height: 42px;
  margin-bottom: 9px;
}
.search-row span {
  display: grid; place-items: center; border: 1px solid #d8dee7; border-right: 0;
  border-radius: 8px 0 0 8px; background: #f4f6f8; color: #334155; font-weight: 600;
}
.search-row input {
  width: 100%; min-width: 0; border: 1px solid #d8dee7; border-radius: 0 8px 8px 0;
  padding: 0 12px; font-size: 0.96rem; outline: none; background: #fff;
}
.search-row input:focus { border-color: #8bb8df; box-shadow: 0 0 0 3px rgba(26,111,181,0.1); }
.search-help { margin: -2px 14px 14px; color: var(--muted); font-size: 0.82rem; }

.actions {
  display: flex; flex-wrap: wrap; gap: 10px;
  margin-top: 16px; align-items: center;
}

.btn {
  border: none; border-radius: 10px; height: 42px; padding: 0 16px;
  font-size: 0.95rem; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  transition: transform .05s, background .15s, opacity .15s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--secondary); color: #fff; }
.btn-secondary:hover:not(:disabled) { background: var(--secondary-hover); }
.btn-ghost {
  background: #f0f4f8; color: #334155; border: 1px solid var(--border);
}
.btn-ghost:hover { background: #e7edf4; }
.btn-ghost.active { background: #dcecff; color: #155a94; border-color: #8bb8df; }
.btn-icon { font-size: 1rem; }

.status-line {
  margin-top: 14px; padding: 10px 12px; border-radius: 10px;
  background: #f0f7ff; color: #1e4b7a; font-size: 0.92rem;
}
.status-line.error { background: #fdecea; color: #8a1f14; }
.status-line.ok { background: #eaf7ee; color: #14532d; }

.monitor-head { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; }
.monitor-head h2 { margin: 0; font-size: 1.05rem; }
.monitor-head p { margin: 5px 0 0; color: var(--muted); font-size: 0.86rem; }
.monitor-state {
  flex: 0 0 auto; border-radius: 999px; padding: 5px 10px; font-size: 0.78rem;
  font-weight: 700; color: #64748b; background: #eef2f6;
}
.monitor-state.running { color: #146c43; background: #e6f6ed; }
.monitor-grid { display: grid; grid-template-columns: 1.5fr 1fr; gap: 18px; margin-top: 16px; }
.monitor-codes textarea {
  min-height: 94px; resize: vertical; border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; font: inherit; line-height: 1.5; outline: none; background: #fbfcfe;
}
.monitor-codes textarea:focus, .monitor-options select:focus {
  border-color: #8bb8df; box-shadow: 0 0 0 3px rgba(26,111,181,0.12); background: #fff;
}
.monitor-options { display: flex; flex-direction: column; gap: 16px; }
.monitor-options select {
  height: 42px; border: 1px solid var(--border); border-radius: 10px; padding: 0 10px;
  background: #fbfcfe; font-size: 0.95rem; outline: none;
}
.monitor-actions { margin-top: 14px; }
.btn-ghost.danger { color: #a12b24; }
.btn-ghost.danger:hover { background: #fdecea; }
.monitor-company-section { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 15px; }
.monitor-company-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.monitor-company-title h3 { margin: 0; font-size: 0.94rem; color: #334155; }
.monitor-company-title span { color: var(--muted); font-size: 0.82rem; }
.monitor-company-list { display: grid; gap: 9px; margin-top: 11px; }
.monitor-company-item {
  display: grid; grid-template-columns: 100px minmax(140px, 1fr) 90px auto;
  align-items: center; gap: 12px; padding: 11px 12px;
  border: 1px solid var(--border); border-radius: 10px; background: #fbfcfe;
}
.monitor-company-code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 700; }
.monitor-company-name { color: #334155; font-weight: 600; }
.monitor-company-status { color: #14734b; font-size: 0.82rem; font-weight: 700; }
.btn-stop-company {
  border: 1px solid #efc6c2; background: #fff; color: #a12b24; border-radius: 8px;
  padding: 7px 10px; font-weight: 600; cursor: pointer;
}
.btn-stop-company:hover { background: #fdecea; }
.monitor-company-empty { margin: 3px 0; color: var(--muted); font-size: 0.86rem; }

.toolbar-card {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; flex-wrap: wrap;
}
.toolbar-left, .toolbar-right {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.check {
  display: inline-flex; align-items: center; gap: 6px;
  font-weight: 600; user-select: none; cursor: pointer;
}
.check.small { font-weight: 500; color: var(--muted); font-size: 0.88rem; }
.check input { width: 16px; height: 16px; }
.muted { color: var(--muted); font-size: 0.9rem; }
.sep { color: #cbd5e1; }

.progress-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 8px;
}
.progress-bar {
  height: 10px; background: #edf2f7; border-radius: 999px; overflow: hidden;
}
.progress-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, #1a6fb5, #0f8a6a);
  transition: width .25s ease;
}
.progress-log {
  margin: 12px 0 0; padding: 0; list-style: none;
  max-height: 160px; overflow: auto; font-size: 0.88rem;
}
.progress-log li {
  padding: 4px 0; border-bottom: 1px dashed #eef2f6;
  display: flex; gap: 8px;
}
.progress-log .tag {
  flex: 0 0 auto; min-width: 42px; font-weight: 700; font-size: 0.78rem;
}
.tag.ok { color: var(--ok); }
.tag.err { color: var(--danger); }
.tag.cache { color: #1565c0; }

.table-wrap { overflow: auto; max-height: min(62vh, 680px); }
table {
  width: 100%; border-collapse: collapse; font-size: 0.92rem;
}
thead th {
  position: sticky; top: 0; background: #f8fafc;
  text-align: left; padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  color: #475569; font-size: 0.82rem; z-index: 1;
}
tbody td {
  padding: 11px 8px; border-bottom: 1px solid #f0f3f7;
  vertical-align: top;
}
tbody tr:hover { background: #f8fbff; }
tbody tr.selected { background: #eef6ff; }

.col-check { width: 36px; }
.col-date { width: 108px; white-space: nowrap; }
.col-source { width: 92px; white-space: nowrap; }
.col-code { width: 72px; }
.col-name { width: 88px; }
.col-size { width: 70px; white-space: nowrap; color: var(--muted); }
.col-status { width: 88px; }
.col-title { min-width: 280px; line-height: 1.45; }
.title-line { display: flex; align-items: flex-start; gap: 8px; flex-wrap: wrap; }
.title-text { flex: 1 1 280px; }
.announcement-link { color: #173b67; text-decoration: none; font-weight: 600; }
.announcement-link:hover { color: var(--primary); text-decoration: underline; }
.announcement-link:focus-visible { outline: 2px solid #8bb8df; outline-offset: 3px; border-radius: 3px; }
.search-hit {
  border: 1px solid #f3b8a9; background: #fff4ef; color: #b33a1e;
  border-radius: 999px; padding: 3px 9px; font-size: 0.76rem; font-weight: 700;
  cursor: pointer; white-space: nowrap;
}
mark.keyword-hit { background: #fff0a8; color: #d9363e; padding: 0 1px; border-radius: 2px; }
.snippet-row td { padding: 0 8px 13px 44px; background: #fbfcff; }
.snippet-panel {
  border-left: 3px solid #8bb8df; padding: 10px 12px; color: #24324a;
}
.snippet-keywords { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 8px; }
.keyword-chip {
  border: 1px solid #f1b3b7; background: #fff; color: #d9363e; border-radius: 999px;
  padding: 3px 9px; cursor: pointer; font-size: 0.8rem;
}
.search-snippet {
  padding: 8px 0; line-height: 1.75; border-bottom: 1px dashed #e4e9f0;
}
.search-snippet:last-child { border-bottom: 0; }
.search-snippet.flash { animation: snippet-flash 1.2s ease; }
@keyframes snippet-flash { 0%, 100% { background: transparent; } 35% { background: #fff7cf; } }

.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 0.75rem; font-weight: 700;
}
.badge.cached { background: var(--cached); color: var(--cached-text); }
.badge.fresh { background: #fff3e0; color: #e65100; }
.badge.done { background: #e3f2fd; color: #0d47a1; }

.empty {
  text-align: center; color: var(--muted); padding: 28px 8px; margin: 0;
}

.footer {
  margin-top: 18px; display: flex; justify-content: space-between;
  color: var(--muted); font-size: 0.82rem; gap: 12px; flex-wrap: wrap;
}

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%);
  background: #1a2332; color: #fff; padding: 12px 18px; border-radius: 12px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.18); z-index: 50;
  max-width: min(90vw, 480px); text-align: center;
}

.choice-modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; }
.choice-modal[hidden] { display: none; }
.choice-backdrop { position: absolute; inset: 0; background: rgba(15, 30, 48, 0.48); }
.choice-dialog {
  position: relative; width: min(92vw, 620px); max-height: 82vh; overflow: auto;
  background: #fff; border-radius: 15px; padding: 20px; box-shadow: 0 24px 70px rgba(0,0,0,0.25);
}
.choice-dialog h2 { margin: 0; font-size: 1.12rem; }
.choice-dialog > p { margin: 7px 0 16px; color: var(--muted); font-size: 0.88rem; }
.choice-groups { display: grid; gap: 13px; }
.choice-group { display: grid; gap: 6px; }
.choice-group label { font-size: 0.85rem; font-weight: 700; color: #334155; }
.choice-group select {
  width: 100%; min-height: 42px; border: 1px solid var(--border); border-radius: 9px;
  padding: 0 10px; background: #fff; font-size: 0.92rem;
}
.choice-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 18px; }

@media (max-width: 820px) {
  .sidebar {
    position: sticky; top: 0; width: 100%; height: auto; padding: 9px 12px;
    display: flex; align-items: center; gap: 12px;
  }
  .sidebar-brand { padding: 0; }
  .sidebar-brand span { display: none; }
  .side-nav { flex-direction: row; flex: 1; justify-content: flex-end; }
  .side-nav-item { width: auto; padding: 9px 11px; }
  .app { margin: 0 auto; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  .search-groups { grid-template-columns: 1fr; }
  .monitor-grid { grid-template-columns: 1fr; }
  .monitor-company-item { grid-template-columns: 84px 1fr auto; }
  .monitor-company-status { display: none; }
  .header { flex-direction: column; }
  .col-name, .col-size { display: none; }
}
@media (max-width: 560px) {
  .sidebar-brand div:last-child { display: none; }
  .side-nav { justify-content: stretch; }
  .side-nav-item { flex: 1; justify-content: center; }
  .form-grid { grid-template-columns: 1fr; }
  .field-wide { grid-column: auto; }
  .field-company { grid-column: auto; }
}
