:root {
  --bg: #f4f6f9;
  --card: #fff;
  --text: #1f2933;
  --muted: #6b7785;
  --border: #e1e5eb;
  --primary: #1f6feb;
  --queued: #8a94a3;
  --analyzing: #d99a00;
  --diagnosed: #1a8f4c;
  --needs: #c2600f;
  --failed: #c62828;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 18px; margin: 0; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

main { padding: 16px 20px; }

.muted { color: var(--muted); font-weight: normal; }
.center { text-align: center; }
.error { color: var(--failed); }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
}

button {
  font: inherit;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #fff;
  cursor: pointer;
}
button.secondary { background: #fff; color: var(--text); border-color: var(--border); }
button.danger { background: #fff; color: #b42318; border-color: #f0b4ae; }
button.danger:hover:not(:disabled) { background: #fef3f2; }
button:disabled { opacity: .5; cursor: default; }

input, select, textarea {
  font: inherit;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

.login { max-width: 380px; margin: 60px auto; }
.login form { display: flex; flex-direction: column; gap: 8px; }

.user { font-weight: 600; }

.summary { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.summary .stat {
  flex: 1 1 130px;
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--queued);
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
}
.summary .stat.active { outline: 2px solid var(--primary); }
.summary .stat .num { font-size: 22px; font-weight: 600; }

.layout { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 14px; align-items: start; }
@media (max-width: 1000px) { .layout { grid-template-columns: 1fr; } }

.list-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.pager { display: flex; align-items: center; gap: 6px; }

table.incidents { width: 100%; border-collapse: collapse; }
table.incidents th, table.incidents td {
  text-align: left;
  padding: 7px 6px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
table.incidents th { font-size: 12px; color: var(--muted); font-weight: 600; }
table.incidents tbody tr { cursor: pointer; }
table.incidents tbody tr:hover { background: #f0f4fa; }
table.incidents tbody tr.selected { background: #e3edfd; }
td.report { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
td.time { white-space: nowrap; }

.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
  background: var(--queued);
}
.s-queued { --c: var(--queued); }
.s-analyzing { --c: var(--analyzing); }
.s-diagnosed { --c: var(--diagnosed); }
.s-needs_more_data { --c: var(--needs); }
.s-failed { --c: var(--failed); }
.badge[class*="s-"] { background: var(--c); }
.stat[class*="s-"] { border-left-color: var(--c); }

.detail-card h2 { font-size: 16px; margin: 0 0 6px; }
.detail-card h3 { font-size: 13px; margin: 16px 0 6px; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 3px 10px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.report-text { white-space: pre-wrap; background: #f7f9fb; border: 1px solid var(--border); border-radius: 6px; padding: 8px; }
pre.diagnosis {
  white-space: pre-wrap;
  font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  background: #f7f9fb;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  margin: 0;
}
.warn { background: #fff4e5; border: 1px solid #f3c98b; border-radius: 6px; padding: 8px; margin: 8px 0; }

details.exec { border: 1px solid var(--border); border-radius: 6px; margin-bottom: 6px; }
details.exec summary { padding: 6px 8px; cursor: pointer; }
details.exec pre { margin: 0; padding: 8px; background: #f7f9fb; overflow: auto; max-height: 300px; font-size: 12px; }
.ok { color: var(--diagnosed); }
.fail { color: var(--failed); }

.reanalyze textarea { width: 100%; min-height: 60px; margin-bottom: 6px; }
.delete-zone { margin-top: 20px; padding-top: 12px; border-top: 1px dashed var(--border); }
