:root {
  --ink: #1f2430;
  --muted: #6b7280;
  --line: #d9dde3;
  --paper: #ffffff;
  --ground: #f4f5f7;
  --accent: #2f5d8a;
  --alert: #a23b3b;
  --ok: #2f6b4f;
}

* { box-sizing: border-box; }
/* Атрибут hidden должен скрывать всегда: правило display у кнопки иначе его перебивает. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--ground);
}

a { color: var(--accent); }
h1 { font-size: 1.6rem; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; margin: 2rem 0 .75rem; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .75rem 1.5rem;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.topbar__brand { font-weight: 600; color: var(--ink); text-decoration: none; }
.topbar__nav { display: flex; align-items: center; gap: 1.25rem; }
.topbar__user { color: var(--muted); }

.page { max-width: 880px; margin: 0 auto; padding: 2rem 1.5rem 4rem; }

.heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.heading h1 { margin: 0; }

.card { background: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: 1.5rem; }
.card--narrow { max-width: 420px; margin: 0 auto; }

.form { display: grid; gap: 1rem; }
.field { display: grid; gap: .3rem; border: 0; padding: 0; margin: 0; }
.field legend { padding: 0; margin-bottom: .3rem; }
.field input[type="text"], .field input[type="email"], .field input[type="password"], .field input[type="date"] {
  font: inherit;
  padding: .5rem .6rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
}
.radio { margin-right: 1rem; }

.button {
  display: inline-block;
  font: inherit;
  padding: .5rem 1rem;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  cursor: pointer;
}
.link-button { font: inherit; border: 0; background: none; color: var(--accent); text-decoration: underline; cursor: pointer; padding: 0; }

.hint { color: var(--muted); font-size: .9rem; }
.empty { color: var(--muted); }

.flash { padding: .6rem .9rem; border-radius: 6px; margin: 0 0 1rem; }
.flash--alert { background: #f7e4e4; color: var(--alert); }
.flash--notice { background: #e2f1e9; color: var(--ok); }

.errors { padding: .6rem .9rem; border-radius: 6px; margin-bottom: 1rem; background: #f7e4e4; color: var(--alert); }
.errors p { margin: 0 0 .3rem; font-weight: 600; }
.errors ul { margin: 0; padding-left: 1.2rem; }

.table { width: 100%; border-collapse: collapse; background: var(--paper); border: 1px solid var(--line); border-radius: 8px; }
.table th, .table td { text-align: left; padding: .6rem .9rem; border-bottom: 1px solid var(--line); }
.table th { color: var(--muted); font-weight: 500; font-size: .9rem; }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: .3rem 1.5rem; margin: 1rem 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }

.list { padding-left: 1.2rem; }

h3 { font-size: 1rem; margin: 0 0 .75rem; }
.card + h2 { margin-top: 2rem; }
.table + .card, .empty + .card { margin-top: 1rem; }
.table__actions { display: flex; gap: 1rem; justify-content: flex-end; white-space: nowrap; }
.actions { display: flex; align-items: center; gap: 1rem; }

.form--member { grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); align-items: end; }
.form--member .actions, .form--member .field--checks { grid-column: 1 / -1; }
.field--checks { display: flex; flex-wrap: wrap; gap: .25rem 1rem; }
.field { min-width: 0; }
.field input, .field select { width: 100%; min-width: 0; }
.field input[type="radio"], .field input[type="checkbox"] { width: auto; }
.field select, .field input[type="number"], .search input[type="search"] {
  font: inherit;
  padding: .5rem .6rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
}

.search { display: flex; align-items: center; gap: .75rem; margin-bottom: 1rem; }
.search input[type="search"] { flex: 1; max-width: 22rem; }
.button--quiet { background: var(--paper); color: var(--accent); border: 1px solid var(--line); }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }


/* ---------- сессия: поле и фигуры ---------- */
.open-sitting { display: flex; align-items: center; gap: .5rem; }
.open-sitting select { font: inherit; padding: .5rem .6rem; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); }

.stage { display: block; width: 100%; height: 100%; user-select: none; -webkit-user-select: none; }
.stage__field { fill: #fbfaf7; stroke: #b9b3a6; stroke-width: 2; }
.stage__palette { fill: #eceae4; }
.stage--static { height: auto; border-radius: 6px; }

.figure-art * { fill: #dcd7cd; stroke: #4b4f58; stroke-width: 2.5; }
.figure-art [fill="none"] { fill: none; }
/* Невидимая широкая линия поверх тонкой (трость, хвост): чтобы по ней можно было попасть кистью. */
.figure-art [data-hit] { fill: none; stroke: transparent; stroke-width: 16; stroke-linecap: round; }
.palette-item, .figure { cursor: grab; }
.figure--dragging, .ghost { cursor: grabbing; }
.hit { fill: transparent; stroke: none; }
.figure--selected .hit { stroke: var(--accent); stroke-width: 2; stroke-dasharray: 6 5; }
.figure--leaving { opacity: .45; }
.ghost { pointer-events: none; opacity: .85; }
.figure-label { font: 600 20px system-ui, sans-serif; text-anchor: middle; fill: var(--ink); paint-order: stroke; stroke: #fbfaf7; stroke-width: 5; pointer-events: none; }

body.bare { background: #e3e1dc; }
.workspace { display: grid; grid-template-columns: 1fr; grid-template-rows: 1fr auto; height: 100vh; }
.workspace--labeling { grid-template-columns: 1fr 20rem; }
.workspace__stage { min-height: 0; padding: .75rem; }
/* Прокрутку и масштаб жестом отключаем только на поле, не на всей странице. */
.workspace__stage .stage { touch-action: none; }
.workspace__panel { overflow-y: auto; padding: 1rem; background: var(--paper); border-left: 1px solid var(--line); }
.workspace__panel h2 { margin-top: 0; }
.workspace__bar { grid-column: 1 / -1; display: flex; align-items: center; gap: 1.25rem; padding: .6rem 1rem; background: var(--paper); border-top: 1px solid var(--line); }

.tray { flex: 1; display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; min-height: 2.2rem; color: var(--muted); font-size: .9rem; }
.tray button { font: inherit; padding: .2rem .6rem; border: 1px solid var(--line); border-radius: 999px; background: var(--ground); cursor: pointer; }

.save { font-size: .9rem; color: var(--ok); white-space: nowrap; }
.save--busy { color: var(--muted); }
.save--failed { color: #fff; background: var(--alert); padding: .3rem .7rem; border-radius: 6px; font-weight: 600; }

.role-row { display: grid; gap: .3rem; padding: .6rem 0; border-bottom: 1px solid var(--line); }
.role-row--selected { background: #eef3f8; margin: 0 -1rem; padding-left: 1rem; padding-right: 1rem; }
.role-row select, .role-row input { font: inherit; padding: .4rem .5rem; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); width: 100%; }
.role-row__name { font-weight: 600; }
.role-row__off { color: var(--muted); font-weight: 400; }

.table--journal td:first-child, .table--journal td:nth-child(2) { white-space: nowrap; color: var(--muted); font-variant-numeric: tabular-nums; }
.role-row__new { display: grid; gap: .3rem; padding: .5rem; border: 1px dashed var(--line); border-radius: 6px; }
.role-row__new .button { justify-self: start; padding: .35rem .8rem; }
.role-row__error { color: var(--alert); font-size: .9rem; }

/* ---------- размер, поворот, краски ---------- */
.handle { fill: var(--paper); stroke: var(--accent); stroke-width: 2.5; }
.handle--scale { cursor: nesw-resize; }
.handle--rotate { cursor: grab; }
.handle-stalk { stroke: var(--accent); stroke-width: 2; stroke-dasharray: 4 4; pointer-events: none; }
.workspace--painting .figure, .workspace--painting .figure [data-region] { cursor: crosshair; }

.paints { display: flex; align-items: center; gap: .35rem; }
.paint { width: 1.7rem; height: 1.7rem; padding: 0; border-radius: 50%; border: 2px solid var(--paper); outline: 1px solid var(--line); background: var(--paint); cursor: pointer; }
.paint--none { background: linear-gradient(135deg, var(--paper) 44%, var(--alert) 45%, var(--alert) 55%, var(--paper) 56%); }
.paint[aria-pressed="true"] { outline: 3px solid var(--ink); }
.table--figures td:first-child { white-space: nowrap; }

/* ---------- опрос ---------- */
.workspace--labeling { grid-template-columns: 1fr 22rem; }
.survey__section { margin: 1.25rem 0 .4rem; font-weight: 700; font-size: .8rem; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.survey__figure { margin: .9rem 0 .2rem; font-weight: 600; }
.survey__empty { color: var(--muted); }
.q { display: grid; gap: .3rem; padding: .5rem 0 .7rem; border-bottom: 1px solid var(--line); }
.q__text { margin: 0; }
.q__answer, .q__reason { font: inherit; width: 100%; padding: .4rem .5rem; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); resize: vertical; }
.q__check { font-size: .9rem; color: var(--muted); }
.q__state { font-size: .8rem; color: var(--ok); min-height: 1em; }
.q__state[data-state="saving"] { color: var(--muted); }
.q__state[data-state="failed"], .q__state[data-state="rejected"] { color: var(--alert); font-weight: 600; }
.table--answers td:first-child { width: 38%; }

/* ---------- показатели ---------- */
h3 { margin-top: 1.5rem; }
.card h3 { margin-top: 0; }
.facts--metrics { grid-template-columns: 17rem 1fr; }
.table--metrics td:not(:first-child), .table--metrics th:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }
.table--metrics[data-metrics="process"] td:nth-child(2), .table--metrics[data-metrics="process"] th:nth-child(2) { text-align: left; }
.flash ul { margin: .3rem 0 0; padding-left: 1.2rem; }
.flash p { margin: 0; }

/* ---------- черновик ИИ и библиотека ---------- */
.draft-run { margin-bottom: .5rem; }
.draft { background: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: 1.25rem 1.5rem; margin-top: 1rem; }
.draft h3:first-of-type { margin-top: 1rem; }
.draft__disclaimer { margin: 0; padding: .7rem .9rem; background: #fbf3dd; border-radius: 6px; font-size: .9rem; }
.draft__list { padding-left: 1.4rem; }
.draft__list > li { margin-bottom: .8rem; }
.draft__removed { color: var(--alert); font-size: .9rem; }
.draft__basis { font-size: .85rem; color: var(--muted); }
.draft__basis ul { margin: .3rem 0; padding-left: 1.1rem; }
.draft__support { display: grid; grid-template-columns: max-content 1fr; gap: .2rem 1rem; margin: .4rem 0 0; font-size: .9rem; }
.draft__support dt { color: var(--muted); }
.draft__support dd { margin: 0; }
.draft__raw pre { white-space: pre-wrap; word-break: break-word; font-size: .8rem; background: var(--ground); padding: .8rem; border-radius: 6px; max-height: 28rem; overflow: auto; }
.statement { background: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: .8rem 1rem; margin-bottom: .6rem; }
.statement p { margin: 0 0 .3rem; }
.statement:target { outline: 3px solid var(--accent); }
.statement__id { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--accent); margin-right: .4rem; }

.heading { align-items: flex-start; }
.heading__actions { display: grid; gap: .5rem; justify-items: stretch; text-align: center; min-width: 15rem; }
.heading__actions .button { width: 100%; text-align: center; }
.heading__actions .hint { text-align: center; }

/* Подпись фигуры у нижнего края поля не обрезается. */
.stage--static { overflow: visible; margin-bottom: 1.75rem; }

/* Шапка сессии: слева заголовок и сведения, справа кнопки — сведения не съезжают вниз на высоту кнопок. */
.heading--sitting .heading__main { min-width: 0; }
.heading--sitting .heading__main h1 { margin-bottom: .75rem; }
.heading--sitting .facts { margin: 0; }

/* ---------- заключение психолога ---------- */
.editor { font: 1rem/1.6 system-ui, sans-serif; width: 100%; padding: 1rem 1.1rem; border: 1px solid var(--line); border-radius: 8px; background: var(--paper); resize: vertical; }
.editor__state { font-size: .9rem; color: var(--muted); }
.editor__state[data-state="dirty"] { color: var(--alert); font-weight: 600; }
.reference { margin-top: 2rem; }
.reference > summary { cursor: pointer; color: var(--accent); }
.sheet { max-width: 46rem; margin: 2rem auto; padding: 2.5rem 3rem; background: var(--paper); border: 1px solid var(--line); border-radius: 8px; }
.sheet__nav { display: flex; align-items: center; gap: 1rem; margin-bottom: 2rem; }
.sheet__nav a:first-child { margin-right: auto; }
.sheet__meta { color: var(--muted); font-size: .9rem; }
.sheet__body { white-space: pre-wrap; line-height: 1.6; margin: 1.5rem 0; }
.sheet__body--inline { background: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: 1rem 1.25rem; margin: .5rem 0 1rem; }
@media print {
  body.bare { background: #fff; }
  .sheet { border: 0; margin: 0; padding: 0; max-width: none; }
  .sheet__nav { display: none; }
}

/* ---------- диктовка ---------- */
.dictation { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; }
.dictation__hint { flex-basis: 100%; }
.dictation__status { font-size: .9rem; color: var(--ok); }
.dictation__status[data-kind="failed"] { color: var(--alert); font-weight: 600; }
.dictation__status[data-kind="silence"] { color: var(--alert); }
.button--recording { background: var(--alert); color: #fff; border-color: var(--alert); }
.button:disabled { opacity: .6; cursor: progress; }
.dictation__review { padding: .8rem 1rem; border: 1px solid #e3c98a; background: #fbf3dd; border-radius: 8px; }
.dictation__review p { margin: 0 0 .5rem; }
.dictation__review blockquote { margin: 0 0 .7rem; padding-left: .8rem; border-left: 3px solid #e3c98a; }

.draft__picture { font-size: 1.05rem; line-height: 1.6; margin: .5rem 0 .3rem; }

/* ---------- демонстрационный стенд ---------- */
.demo-notice { margin: 0; padding: .45rem 1.5rem; background: #fbf3dd; border-bottom: 1px solid #e3c98a; font-size: .9rem; text-align: center; }

/* ---------- сообщить о проблеме ---------- */
.topbar__report { color: var(--alert); }
dialog.report { width: min(34rem, calc(100vw - 2rem)); border: 1px solid var(--line); border-radius: 10px; padding: 1.5rem; }
dialog.report::backdrop { background: rgb(31 36 48 / .45); }
dialog.report h2 { margin: 0 0 .25rem; }
dialog.report textarea, dialog.report select { font: inherit; width: 100%; padding: .5rem .6rem; border: 1px solid var(--line); border-radius: 6px; background: var(--paper); }
.report__state { margin: 0; min-height: 1.4em; font-size: .9rem; color: var(--muted); }
.report__state[data-kind="ok"] { color: var(--ok); font-weight: 600; }
.report__state[data-kind="failed"] { color: var(--alert); font-weight: 600; }
.report__body { white-space: pre-wrap; }
.report__answer { white-space: pre-wrap; background: #e2f1e9; border-radius: 6px; padding: .5rem .7rem; }
.sheet__nav a.hint { margin-right: auto; }
.sheet__nav a:first-child { margin-right: 0; }
