:root {
  color-scheme: light;
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef3f2;
  --text: #1d2526;
  --muted: #637172;
  --line: #d8e0df;
  --accent: #137a73;
  --accent-2: #3454d1;
  --ok: #1f8a55;
  --warn: #9a6400;
  --error: #b3261e;
  --idle: #657277;
  --shadow: 0 10px 30px rgba(27, 42, 44, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", Arial, sans-serif;
  font-size: 14px;
}

a {
  color: inherit;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(244, 246, 245, 0.94);
  backdrop-filter: blur(12px);
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 24px;
  font-weight: 750;
}

h2 {
  margin-bottom: 0;
  font-size: 16px;
  font-weight: 720;
}

h3 {
  margin-bottom: 4px;
  font-size: 14px;
}

.topbar-actions,
.status-row,
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.button,
.row-button {
  border: 1px solid var(--accent);
  border-radius: 7px;
  background: var(--accent);
  color: white;
  font: inherit;
  font-weight: 650;
  text-decoration: none;
  cursor: pointer;
}

.button {
  min-height: 36px;
  padding: 7px 12px;
}

.button.secondary {
  border-color: var(--line);
  background: var(--surface);
  color: var(--text);
}

.button:disabled {
  cursor: wait;
  opacity: 0.6;
}

.shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 24px 28px 40px;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.status-card,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.status-card {
  min-height: 130px;
  padding: 16px;
}

.metric {
  margin: 20px 0 6px;
  font-size: 24px;
  font-weight: 780;
}

.muted,
.subtle,
.empty {
  color: var(--muted);
}

.muted {
  margin-bottom: 0;
}

.subtle {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  line-height: 1.25;
  word-break: break-word;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  background: #edf0f1;
  color: var(--idle);
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
}

.badge.ok {
  background: #e5f4ec;
  color: var(--ok);
}

.badge.active {
  background: #e8edff;
  color: var(--accent-2);
}

.badge.warn {
  background: #fff1d6;
  color: var(--warn);
}

.badge.error {
  background: #fde8e7;
  color: var(--error);
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
}

.main-column,
.side-column {
  display: grid;
  align-content: start;
  gap: 18px;
}

.panel {
  overflow: hidden;
}

.panel-header {
  min-height: 58px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 780;
  text-transform: uppercase;
}

td {
  word-break: break-word;
}

tbody tr {
  transition: background 0.15s ease;
}

tbody tr:hover,
tbody tr.selected {
  background: #f4faf9;
}

.row-button {
  width: 100%;
  max-width: 230px;
  padding: 6px 8px;
  overflow-wrap: anywhere;
  border-color: transparent;
  background: transparent;
  color: var(--accent);
  text-align: left;
}

.progress {
  width: 100%;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e4e9ea;
}

.progress span {
  display: block;
  height: 100%;
  min-width: 0;
  background: var(--accent);
}

.details {
  padding: 18px;
}

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

.detail-grid > div {
  min-height: 74px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}

.label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
  text-transform: uppercase;
}

.artifact-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 16px 0;
}

.artifact-summary span {
  padding: 5px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 650;
}

.artifact-list,
.tool-list,
.role-list {
  display: grid;
  gap: 8px;
  padding: 14px;
}

.artifact-list a,
.tool-link {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
  text-decoration: none;
}

.artifact-list a:hover,
.tool-link:hover {
  border-color: var(--accent);
}

.artifact-list span,
.artifact-list small {
  color: var(--muted);
  font-size: 12px;
}

.role-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}

.role-item p {
  margin-bottom: 0;
  color: var(--muted);
}

.role-score {
  min-width: 62px;
  text-align: right;
}

.role-score strong {
  display: block;
  font-size: 20px;
}

.role-score span {
  color: var(--muted);
  font-size: 12px;
}

.empty {
  padding: 18px;
}

/* === Группировка артефактов по чатам (детали прогона) === */

.chat-group {
  margin-bottom: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfc;
}

.chat-group summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  cursor: pointer;
  font-weight: 650;
  overflow-wrap: anywhere;
}

.chat-group summary .subtle {
  margin-top: 0;
}

.chat-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 12px 12px;
}

.chat-links a {
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--accent);
  font-weight: 650;
  text-decoration: none;
}

.chat-links a:hover {
  border-color: var(--accent);
}

.chat-links a.secondary {
  color: var(--muted);
}

/* === Читалка (viewer.html) === */

.viewer-panel {
  max-width: 880px;
  margin: 0 auto;
}

.viewer-meta {
  padding: 14px 26px 0;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.md-body {
  padding: 10px 26px 30px;
  font-size: 15px;
  line-height: 1.6;
}

.md-body h1 {
  margin: 20px 0 10px;
  font-size: 26px;
}

.md-body h2 {
  margin: 20px 0 8px;
  font-size: 20px;
}

.md-body h3 {
  margin: 16px 0 6px;
  font-size: 16px;
}

.md-body p,
.md-body ul,
.md-body ol {
  margin: 0 0 10px;
}

.md-body li {
  margin-bottom: 4px;
}

.md-body blockquote {
  margin: 0 0 10px;
  padding: 8px 14px;
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
  background: var(--surface-2);
  color: var(--text);
}

.md-body code {
  padding: 1px 5px;
  border-radius: 5px;
  background: var(--surface-2);
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
}

.md-body pre {
  margin: 0 0 10px;
  padding: 12px 14px;
  overflow-x: auto;
  border-radius: 8px;
  background: #1d2526;
  color: #e8eeed;
}

.md-body pre code {
  padding: 0;
  background: transparent;
  color: inherit;
}

.md-body hr {
  margin: 18px 0;
  border: 0;
  border-top: 1px solid var(--line);
}

.md-table-wrap {
  margin: 0 0 10px;
  overflow-x: auto;
}

.md-body table {
  table-layout: auto;
}

.md-body th,
.md-body td {
  padding: 8px 10px;
}

@media (max-width: 1120px) {
  .status-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .layout {
    grid-template-columns: 1fr;
  }

  .side-column {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .topbar,
  .topbar-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .shell {
    padding: 16px;
  }

  .status-grid,
  .side-column,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  table {
    min-width: 760px;
  }
}
