:root {
  --bg: #f5f6f4;
  --surface: #ffffff;
  --surface-2: #eef1ee;
  --fg: #1d2a24;
  --muted: #5a6a62;
  --line: #d9dfdb;
  --accent: #1f6f50;
  --accent-fg: #ffffff;
  --accent-soft: #e2f0e9;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --warn: #8a5a00;
  --warn-soft: #fff3d6;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121614;
    --surface: #1b211e;
    --surface-2: #232a26;
    --fg: #e6ece8;
    --muted: #9fb0a7;
    --line: #2f3833;
    --accent: #4fb487;
    --accent-fg: #0d1a14;
    --accent-soft: #1d3329;
    --danger: #f2948d;
    --danger-soft: #3a1f1d;
    --warn: #f0c165;
    --warn-soft: #3a3020;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 18px; margin: 24px 0 8px; }
h3 { font-size: 16px; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 14px; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; color: var(--fg); text-decoration: none; font-size: 18px; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.nav a {
  padding: 6px 10px; border-radius: 8px; text-decoration: none; color: var(--muted);
}
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.who { font-size: 14px; color: var(--muted); display: flex; gap: 8px; align-items: center; }

.view { max-width: 920px; margin: 0 auto; padding: 16px 16px 120px; }
.head { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; justify-content: space-between; margin-bottom: 16px; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 14px;
}
.list { display: grid; gap: 8px; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.tag {
  display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.tag.accent { background: var(--accent-soft); color: var(--accent); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }

button, .button {
  font: inherit; font-size: 15px; padding: 9px 14px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line); background: var(--surface); color: var(--fg);
  text-decoration: none; display: inline-block;
}
button.primary, .button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
button.danger { color: var(--danger); }
button.icon { padding: 6px 10px; min-width: 36px; }
button:disabled { opacity: .5; cursor: default; }

label.field { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
input[type=text], select, textarea {
  font: inherit; color: var(--fg); background: var(--surface); width: 100%;
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
}
textarea { resize: vertical; min-height: 44px; }
input:focus, select:focus, textarea:focus, button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
.check { display: inline-flex; gap: 6px; align-items: center; font-size: 14px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; }
.kpi .value { font-size: 26px; font-weight: 700; }
.kpi .label { font-size: 13px; color: var(--muted); }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; }

/* Редактор */
.section { display: grid; gap: 8px; }
.section-head { display: flex; gap: 6px; align-items: center; }
.item { border-left: 3px solid var(--line); }
.item.critical { border-left-color: var(--danger); }
.item-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin-top: 8px; }
.item-actions { display: flex; gap: 4px; justify-content: flex-end; margin-top: 8px; }
.savebar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 9;
  background: var(--surface); border-top: 1px solid var(--line);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
}
.savebar .inner { max-width: 920px; margin: 0 auto; display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: center; }
.savebar .inner > .muted { flex-basis: 100%; }
.savebar input { flex: 1; min-width: 140px; }
.errors { background: var(--danger-soft); color: var(--danger); border-radius: var(--radius); padding: 10px 14px; }
.errors ul { margin: 4px 0 0; padding-left: 18px; }
.notice { background: var(--warn-soft); color: var(--warn); border-radius: var(--radius); padding: 10px 14px; }
.link-box { word-break: break-all; font-family: ui-monospace, monospace; font-size: 13px; background: var(--surface-2); padding: 10px; border-radius: 8px; }

.toast {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); z-index: 20;
  background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 8px; max-width: 90vw;
}

@media (max-width: 560px) {
  .who .name { display: none; }
  .brand { flex: 1; }
  .nav { order: 3; flex-basis: 100%; flex-wrap: nowrap; overflow-x: auto; }
  .nav a { white-space: nowrap; }
  .view { padding-bottom: 150px; }
  .kpi .value { font-size: 22px; }
}

/* Тестовый чат */
.sim-tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 8px; }
.sim-tab { display: grid; text-align: left; gap: 2px; min-width: 110px; max-width: 170px; }
.sim-tab > span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sim-intro { margin: 0 0 8px; }
.sim-tab.active { border-color: var(--accent); background: var(--accent-soft); }
.sim-tab.add { min-width: auto; color: var(--accent); }
.sim-chat { display: flex; flex-direction: column; padding: 0; height: 70vh; }
.sim-log { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; background: var(--surface-2); }
.sim-bar { display: flex; gap: 6px; padding: 8px; border-top: 1px solid var(--line); }
.msg { max-width: 92%; padding: 8px 10px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); }
.msg.me { align-self: flex-end; background: var(--accent-soft); border-color: transparent; }
.msg-text { white-space: pre-wrap; word-break: break-word; font-size: 15px; }
.msg-images { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 6px; }
.msg-images img { max-width: 100%; max-height: 220px; border-radius: 8px; }
.msg-buttons { display: grid; gap: 4px; margin-top: 8px; }
.msg-row { display: flex; gap: 4px; }
.msg-row > * { flex: 1; text-align: center; font-size: 14px; padding: 8px 6px; }
@media (max-width: 560px) { .sim-intro { display: none; } }

/* журнал по людям (кабинет платформы) */
.log { display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.log-line { line-height: 1.4; padding-bottom: 6px; border-bottom: 1px solid var(--line, #e5e5e5); overflow-wrap: anywhere; }
.log-line:last-child { border-bottom: 0; padding-bottom: 0; }
