:root {
  --bg: #f4f1ea;
  --panel: #ffffff;
  --text: #1f2933;
  --muted: #667085;
  --border: #d8d2c7;
  --accent: #355c7d;
  --accent-soft: #e8eef3;
  --warning: #b45309;
  --warning-soft: #fff7ed;
  --success-soft: #ecfdf3;
  --sidebar-width: 260px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-width);
  background: #2f3e46;
  color: #f8fafc;
  display: flex;
  flex-direction: column;
  padding: 1rem;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand { font-size: 1.1rem; font-weight: 700; margin-bottom: 1.5rem; }
.sidebar-brand a { color: inherit; text-decoration: none; }
.sidebar-nav { display: grid; gap: .35rem; flex: 1; }
.nav-item {
  padding: .65rem .8rem;
  border-radius: .5rem;
  color: #e5e7eb;
}
.nav-item.active, .nav-item:hover { background: rgba(255,255,255,.08); color: #fff; text-decoration: none; }
.sidebar-footer { border-top: 1px solid rgba(255,255,255,.12); padding-top: 1rem; font-size: .9rem; }
.operator-name { font-weight: 600; margin-bottom: .35rem; }
.app-version, .muted { color: var(--muted); }
.main-column { flex: 1; min-width: 0; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(244,241,234,.95);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
  padding: .75rem 1rem;
  display: flex;
  gap: 1rem;
  align-items: center;
}
.subnav { display: flex; gap: .5rem; flex-wrap: wrap; }
.subnav-item {
  padding: .45rem .75rem;
  border-radius: 999px;
  color: var(--text);
  background: transparent;
}
.subnav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; text-decoration: none; }
.content { padding: 1rem 1.25rem 2rem; max-width: 1400px; }
.panel, .card, .auth-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.25rem;
}
.panel.narrow, .auth-card { max-width: 720px; }
.panel-header { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
.grid.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; }
.kv {
  display: grid;
  grid-template-columns: minmax(11rem, 14rem) minmax(0, 1fr);
  gap: .5rem 1rem;
  align-items: start;
  margin: 0;
}
.kv dt,
.kv dd { margin: 0; min-width: 0; }
.kv dt { color: var(--muted); font-weight: 500; }
.kv dd { word-break: break-word; }
.card-program-state .kv { grid-template-columns: minmax(10rem, 12rem) minmax(0, 1fr); }

/* Participant overview: full-width horizontal sections */
.overview-sections {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.overview-sections .card {
  width: 100%;
}
.overview-sections .kv {
  grid-template-columns: minmax(13rem, 18rem) minmax(0, 1fr);
  column-gap: 1.25rem;
}
.overview-sections .card-program-state .kv {
  grid-template-columns: minmax(13rem, 18rem) minmax(0, 1fr);
}
.overview-sections .kv dd {
  word-break: normal;
  overflow-wrap: break-word;
}
.overview-sections .kv-value-text {
  white-space: pre-wrap;
  line-height: 1.45;
}

.table-wrap { overflow: auto; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td { padding: .65rem .5rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.clickable-row { cursor: pointer; }
.clickable-row:hover { background: #faf8f4; }
.badge {
  display: inline-block;
  padding: .15rem .5rem;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: .85rem;
}
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.button, button.button {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: .5rem;
  padding: .55rem .9rem;
  cursor: pointer;
}
.button.primary, button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.link-button { background: none; border: none; color: #dbeafe; cursor: pointer; padding: 0; }
.filters-form { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
input, select, textarea {
  width: 100%;
  padding: .55rem .65rem;
  border: 1px solid var(--border);
  border-radius: .5rem;
  font: inherit;
}
.stack-form label { display: grid; gap: .35rem; margin-bottom: .75rem; }
.auth-page { min-height: 100vh; display: grid; place-items: center; }
.auth-wrap { width: min(420px, calc(100vw - 2rem)); }
.auth-brand { color: var(--accent); margin-bottom: .75rem; }
.alert { padding: .75rem 1rem; border-radius: .5rem; margin-bottom: 1rem; }
.alert-warning { background: var(--warning-soft); color: var(--warning); }
.alert-success { background: var(--success-soft); color: #166534; }
.pagination { display: flex; gap: .5rem; align-items: center; margin-top: 1rem; flex-wrap: wrap; }
.page-link { padding: .35rem .65rem; border: 1px solid var(--border); border-radius: .4rem; }
.page-link.active { background: var(--accent); color: #fff; border-color: var(--accent); text-decoration: none; }
.participant-header { margin-bottom: 1rem; }
.participant-header.compact { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.back-link { display: inline-block; margin-bottom: .35rem; }
.meta-row { display: flex; gap: .75rem; flex-wrap: wrap; color: var(--muted); }
.content:has(.conversation-panel) { max-width: none; padding-left: 1rem; padding-right: 1rem; }
.conversation-panel { max-width: none; padding: 1rem 1.25rem 1.5rem; }
.conversation-toolbar { margin-bottom: 1rem; }
.conversation-thread {
  display: flex;
  flex-direction: column;
  gap: .85rem;
  width: 100%;
}
.conversation-empty { text-align: center; padding: 2rem 1rem; }
.message-row {
  display: flex;
  width: 100%;
}
.message-row-user { justify-content: flex-start; }
.message-row-bot { justify-content: flex-end; }
.message-row-system { justify-content: center; }
.message-bubble {
  max-width: min(72rem, 78%);
  min-width: min(100%, 12rem);
  padding: .75rem 1rem;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: #fff;
}
.message-row-user .message-bubble {
  background: var(--accent-soft);
  border-bottom-left-radius: 4px;
}
.message-row-bot .message-bubble {
  background: #fff;
  border-bottom-right-radius: 4px;
}
.message-row-system .message-bubble {
  max-width: min(72rem, 92%);
  background: #f8fafc;
  text-align: center;
}
.message-meta {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem .75rem;
  align-items: baseline;
  font-size: .82rem;
  color: var(--muted);
  margin-bottom: .4rem;
}
.message-author { color: var(--text); font-size: .88rem; }
.message-time { font-variant-numeric: tabular-nums; }
.message-channel { opacity: .85; }
.message-body {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.45;
}
.conversation-panel .message-body:empty::after {
  content: '[Пустое сообщение]';
  color: var(--muted);
  font-style: italic;
}

@media (max-width: 900px) {
  .message-bubble { max-width: 92%; }
}
.timeline { display: grid; gap: .75rem; }
.timeline-item { border-left: 3px solid var(--accent); padding-left: .75rem; }
.note-item, .flag-item { border-top: 1px solid var(--border); padding: .75rem 0; }
.flag-item { display: flex; justify-content: space-between; gap: 1rem; align-items: start; }
.pre-wrap { white-space: pre-wrap; word-break: break-word; }
.empty { color: var(--muted); }
.mt { margin-top: 1rem; }
.toolbar { display: flex; gap: .5rem; flex-wrap: wrap; }
.sidebar-toggle { display: none; }

@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    left: 0;
    transform: translateX(-100%);
    transition: transform .2s ease;
    z-index: 20;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle { display: inline-block; }
  .kv { grid-template-columns: 1fr; }
}
