:root {
  color-scheme: light;
  --background: #fafafa;
  --foreground: #171717;
  --card: #ffffff;
  --card-foreground: #171717;
  --muted: #737373;
  --muted-foreground: #525252;
  --border: #e5e5e5;
  --input: #d4d4d4;
  --primary: #171717;
  --primary-foreground: #fafafa;
  --secondary: #f5f5f5;
  --secondary-foreground: #262626;
  --accent: #f4f4f5;
  --accent-foreground: #18181b;
  --blue: #2563eb;
  --green: #059669;
  --green-bg: #ecfdf5;
  --red: #dc2626;
  --red-bg: #fef2f2;
  --amber: #b45309;
  --amber-bg: #fffbeb;
  --cyan: #0891b2;
  --violet: #7c3aed;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-hover: 0 12px 28px rgba(0, 0, 0, 0.08);
  --font-sans: "SF Pro Text", "Segoe UI Variable", "Segoe UI", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --font-display: "SF Pro Display", "Segoe UI Variable Display", "Segoe UI", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(37, 99, 235, 0.05), transparent 34rem),
    linear-gradient(180deg, #fff 0%, var(--background) 22rem);
  color: var(--foreground);
  font-family: var(--font-sans);
  font-size: 15px;
}
a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; }
button:disabled { cursor: not-allowed; opacity: .55; }

.shell { display: grid; grid-template-columns: 260px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  background: rgba(255, 255, 255, 0.86);
  padding: 20px 16px;
  border-right: 1px solid var(--border);
  backdrop-filter: blur(14px);
}
.brand {
  display: flex; align-items: center; gap: 12px;
  min-height: 44px; margin-bottom: 18px; padding: 0 8px;
  font-weight: 760; font-size: 15px; font-family: var(--font-display);
}
.brand-mark {
  width: 34px; height: 34px; border-radius: var(--radius);
  display: grid; place-items: center;
  background: var(--primary); color: var(--primary-foreground);
  font-weight: 800; box-shadow: var(--shadow);
}
.nav { display: grid; gap: 4px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  min-height: 38px; padding: 9px 10px;
  color: var(--muted-foreground); border-radius: var(--radius);
  font-size: 14px; font-weight: 650;
  border: 1px solid transparent; cursor: pointer;
}
.nav a.active, .nav a:hover {
  background: var(--accent); color: var(--accent-foreground);
  border-color: var(--border);
}
.sidebar-footer {
  position: absolute; bottom: 16px; left: 16px; right: 16px;
  font-size: 12px; color: var(--muted);
}
.sidebar-footer button {
  margin-top: 8px; width: 100%;
  background: #fff; color: var(--secondary-foreground);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 8px 10px; font-size: 12px; font-weight: 600; cursor: pointer;
}

.main { min-width: 0; width: min(1320px, 100%); padding: 32px 40px 56px; }

.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 20px; margin-bottom: 20px;
}
.eyebrow {
  color: var(--muted); font-size: 12px; font-weight: 750;
  letter-spacing: .04em; text-transform: uppercase; margin-bottom: 7px;
}
h1 {
  font-size: clamp(28px, 3vw, 38px); line-height: 1.08;
  font-weight: 760; font-family: var(--font-display);
}
.subhead {
  color: var(--muted-foreground); margin-top: 9px;
  font-size: 15px; line-height: 1.5; max-width: 760px;
}

.panel { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel-pad { padding: 18px; }
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.form-row { display: flex; gap: 10px; width: 100%; }

.input, textarea.input, select.input {
  width: 100%; min-height: 42px; padding: 10px 12px;
  border: 1px solid var(--input); border-radius: var(--radius);
  color: var(--foreground); background: #fff; outline: none;
  transition: border-color .16s ease, box-shadow .16s ease;
}
.input:focus, textarea.input:focus, select.input:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(23, 23, 23, .09);
}
textarea.input { min-height: 84px; resize: vertical; }

.btn {
  min-height: 40px; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 0 14px; border: 1px solid transparent; border-radius: var(--radius);
  cursor: pointer; font-weight: 700; font-size: 14px; white-space: nowrap;
  transition: background .16s, border-color .16s, color .16s, box-shadow .16s;
}
.btn-primary { background: var(--primary); color: var(--primary-foreground); }
.btn-primary:hover { background: #262626; }
.btn-quiet { background: #fff; color: var(--secondary-foreground); border-color: var(--border); }
.btn-quiet:hover { background: var(--secondary); }
.btn-danger { background: var(--red-bg); color: var(--red); border-color: #fecaca; }

.flash-wrap { display: grid; gap: 8px; margin-bottom: 18px; }
.flash {
  padding: 12px 14px; border-radius: var(--radius);
  font-size: 14px; font-weight: 650; border: 1px solid var(--border); background: #fff;
}
.flash.success { color: var(--green); background: var(--green-bg); border-color: #bcefd8; }
.flash.error { color: var(--red); background: var(--red-bg); border-color: #fecdd3; }
.flash.info { color: var(--blue); background: #eff6ff; border-color: #bfdbfe; }

.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.signal-card, .company-card {
  display: block; min-height: 164px; background: #fff;
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); cursor: pointer;
  transition: transform .14s, border-color .14s, box-shadow .14s;
}
.signal-card:hover, .company-card:hover {
  transform: translateY(-1px); border-color: #c7c7c7; box-shadow: var(--shadow-hover);
}
.signal-top, .company-top { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 16px; }

.icon-box {
  width: 42px; height: 42px; flex: 0 0 42px; border-radius: var(--radius);
  display: grid; place-items: center; font-size: 18px;
  background: var(--green-bg); color: var(--green); border: 1px solid #c8f4dd; font-weight: 760;
}
.icon-blue { background: #eff6ff; color: var(--blue); border-color: #bfdbfe; }
.icon-cyan { background: #ecfeff; color: var(--cyan); border-color: #a5f3fc; }
.icon-violet { background: #f5f3ff; color: var(--violet); border-color: #ddd6fe; }
.icon-amber { background: var(--amber-bg); color: var(--amber); border-color: #fde5aa; }

.card-title { font-size: 17px; font-weight: 760; line-height: 1.2; font-family: var(--font-display); }
.card-meta { color: var(--muted); font-size: 13px; margin-top: 4px; line-height: 1.4; }
.card-copy { color: var(--muted-foreground); font-size: 14px; line-height: 1.48; }

.status-pill, .signal-pill {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 24px; padding: 0 9px; border-radius: 999px;
  font-size: 12px; font-weight: 760;
  border: 1px solid var(--border); background: var(--secondary); color: var(--muted-foreground);
}
.status-success { background: var(--green-bg); color: var(--green); border-color: #bcefd8; }
.status-running { background: #eff6ff; color: var(--blue); border-color: #bfdbfe; }
.status-failed { background: var(--red-bg); color: var(--red); border-color: #fecdd3; }
.status-never  { background: var(--secondary); color: var(--muted); }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
  text-align: left; padding: 14px 16px;
  border-bottom: 1px solid var(--border); font-size: 14px; vertical-align: top;
}
.table th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; font-weight: 760; }
.table tr:last-child td { border-bottom: 0; }

.metric-strip { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin: 18px 0; }
.metric { padding: 16px; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.metric-label { color: var(--muted); font-size: 12px; font-weight: 760; text-transform: uppercase; letter-spacing: .04em; }
.metric-value { margin-top: 5px; font-size: 18px; font-weight: 760; overflow-wrap: anywhere; font-family: var(--font-display); }

.signals-list { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: #fff; box-shadow: var(--shadow); }
.signals-list-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 18px; background: #fff; border-bottom: 1px solid var(--border);
}
.signal-row { display: flex; align-items: flex-start; gap: 14px; padding: 18px; border-bottom: 1px solid var(--border); }
.signal-row:last-child { border-bottom: 0; }
.signal-body { min-width: 0; flex: 1; }
.signal-titleline { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.signal-name { font-size: 16px; font-weight: 760; }
.signal-summary { color: var(--muted-foreground); line-height: 1.55; overflow-wrap: anywhere; }

.detail-chips { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 12px; }
.detail-chip {
  display: inline-flex; gap: 6px; max-width: 100%;
  padding: 6px 9px; border-radius: var(--radius);
  background: var(--secondary); border: 1px solid var(--border); color: var(--muted-foreground);
  font-size: 12px; line-height: 1.35;
}
.detail-chip strong { color: var(--foreground); }

.empty { padding: 34px 24px; text-align: center; color: var(--muted-foreground); background: #fff; border: 1px solid var(--border); border-radius: var(--radius); }

.job-box { margin: 18px 0; padding: 18px; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.progress { height: 8px; background: var(--secondary); border-radius: 999px; overflow: hidden; margin-top: 12px; }
.progress span { display: block; height: 100%; width: 0%; background: var(--primary); transition: width .25s ease; }

.error-box { margin-top: 18px; padding: 14px 16px; background: var(--red-bg); border: 1px solid #fecdd3; border-radius: var(--radius); color: #991b1b; font-size: 14px; line-height: 1.55; }
.post { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 12px; box-shadow: var(--shadow); }
.post-text { color: var(--muted-foreground); font-size: 14px; line-height: 1.6; white-space: pre-line; }

.spinner {
  display: inline-block; width: 16px; height: 16px;
  border: 2px solid var(--border); border-top-color: var(--primary);
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Detail chips — grid layout ─────────────────────── */
.detail-chips-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}
.detail-chip-block {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 8px 10px;
  min-width: 0;
}
.detail-chip-key {
  font-size: 11px;
  font-weight: 760;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .03em;
}
.detail-chip-val {
  color: var(--foreground);
  font-size: 13px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}
.detail-chip-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 2px; }
.detail-tag-pill {
  display: inline-flex;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--accent);
  border: 1px solid var(--border);
  font-size: 11px;
  font-weight: 650;
}

/* ── Crawl History section ───────────────────────────── */
.history-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}
.history-table-wrap { overflow-x: auto; }
.history-show-all-btn {
  display: block;
  width: 100%;
  border-radius: 0;
  border-top: 1px solid var(--border);
  border-left: 0; border-right: 0; border-bottom: 0;
  font-size: 13px;
  min-height: 38px;
  color: var(--muted-foreground);
}
.history-show-all-btn:hover { background: var(--secondary); color: var(--foreground); }

/* ── Uncategorized posts (collapsible) ──────────────── */
.uncat-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
  box-shadow: var(--shadow);
  margin: 18px 0;
}
.uncat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  gap: 12px;
  padding: 16px 18px;
  background: transparent;
  border: 0;
  cursor: pointer;
  text-align: left;
  font: inherit;
}
.uncat-head:hover { background: var(--secondary); }
.uncat-toggle { font-size: 14px; color: var(--muted); flex-shrink: 0; }
.uncat-body { border-top: 1px solid var(--border); padding: 14px 18px; }
.uncat-body .post { box-shadow: none; }
.uncat-body .post:last-child { margin-bottom: 0; }
.uncat-note {
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted-foreground);
  background: var(--secondary);
  border-radius: 8px;
  padding: 6px 10px;
}

/* ── Signal type count chips ─────────────────────────── */
.signal-type-counts {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
}
.type-count-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--secondary);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted-foreground);
}
.type-count-chip .tcc-num {
  color: var(--foreground);
  font-weight: 740;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 999px;
  min-width: 18px;
  text-align: center;
  padding: 0 5px;
}

@media (max-width: 980px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; padding: 16px; }
  .brand { margin-bottom: 14px; }
  .nav { grid-template-columns: repeat(3, 1fr); }
  .sidebar-footer { position: static; margin-top: 16px; }
  .main { padding: 26px 18px 44px; }
  .grid-2, .grid-3, .metric-strip { grid-template-columns: 1fr; }
  .page-head { flex-direction: column; }
  .form-row { flex-direction: column; }
  .btn { width: 100%; }
  .signal-row { flex-direction: column; }
  .detail-chips-grid { grid-template-columns: 1fr; }
}
