:root {
  --graphite: #2B2B2E;
  --graphite-soft: #4A4A4F;
  --terra: #C05A34;
  --terra-tint: #F3E2DA;
  --gold: #CEA64E;
  --sand: #F7F3EC;
  --card: #FFFFFF;
  --line: #E4DCCF;
  --muted: #8A8378;
  --ok: #5B8C5A;
  --bad: #C0392B;
  --radius: 12px;
}

* { box-sizing: border-box; }

/* hidden должен побеждать любые display в классах — иначе блоки не скрываются */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;              /* прокручивается только область чата */
  background: var(--sand);
  color: var(--graphite);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

.app {
  max-width: 720px;
  margin: 0 auto;
  height: 100vh;
  height: 100dvh;                /* корректно на мобильных с адресной строкой */
  display: flex;
  flex-direction: column;
  padding: 0 16px;
}

/* header */
.head {
  padding: 20px 0 14px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--sand);
  z-index: 5;
}
.head-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}
h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.sub {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--muted);
  max-width: 46ch;
}
.rounds {
  display: flex;
  gap: 7px;
  padding-top: 6px;
  flex-shrink: 0;
}
.dot {
  width: 26px;
  height: 6px;
  border-radius: 3px;
  background: var(--line);
  transition: background .3s ease;
}
.dot.filled { background: var(--terra); }

/* chat */
.chat {
  flex: 1 1 auto;
  min-height: 0;                 /* без этого flex не даёт блоку скроллиться */
  padding: 20px 0;
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  scroll-behavior: smooth;
}
.msg {
  max-width: 82%;
  padding: 11px 15px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  word-wrap: break-word;
  animation: rise .25s ease;
}
@media (prefers-reduced-motion: reduce) {
  .msg { animation: none; }
}
@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
.msg.client {
  align-self: flex-start;
  background: var(--card);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}
.msg.psy {
  align-self: flex-end;
  background: var(--terra-tint);
  border: 1px solid #E8CFC3;
  border-bottom-right-radius: 4px;
}

/* разбор — фирменный блок */
.razbor {
  align-self: stretch;
  max-width: 100%;
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 3px solid var(--gold);
  border-radius: 8px;
  padding: 16px 18px;
  font-size: 14.5px;
  line-height: 1.55;
}
.razbor .r-title {
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--terra);
  margin-bottom: 10px;
}
.razbor .r-itog {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

/* строка-критерий: бейдж + название + описание */
.check {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}
.badge {
  flex-shrink: 0;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 20px;
  color: #fff;
  white-space: nowrap;
}
.check.ok .badge { background: var(--ok); }
.check.bad .badge { background: var(--bad); }
.check .cname { color: var(--graphite); font-weight: 500; }
.check.bad .cname { color: var(--bad); }
.check .cdesc { color: var(--muted); font-size: 13px; }

/* обычные строки разбора: рекомендации, последствия, абзацы итога */
.razbor .rline {
  margin-bottom: 6px;
  color: var(--graphite-soft);
}
.razbor .rline:first-of-type { margin-top: 4px; }

/* typing */
.typing {
  align-self: flex-start;
  color: var(--muted);
  font-size: 14px;
  padding: 6px 4px;
}

/* done banner */
.done-banner {
  margin: 4px 0 14px;
  padding: 16px 18px;
  background: #EEF4EA;
  border: 1px solid #CDE0C6;
  border-radius: var(--radius);
}
.done-title { margin: 0; font-weight: 600; color: var(--ok); }
.done-note { margin: 4px 0 0; font-size: 14px; color: var(--graphite-soft); }

/* composer */
.composer {
  display: flex;
  gap: 10px;
  padding: 12px 0 18px;
  border-top: 1px solid var(--line);
  position: sticky;
  bottom: 0;
  background: var(--sand);
}
#input {
  flex: 1;
  resize: none;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  background: var(--card);
  color: var(--graphite);
  max-height: 140px;
}
#input:focus {
  outline: 2px solid var(--terra);
  outline-offset: 1px;
  border-color: var(--terra);
}
#send {
  padding: 0 20px;
  border: none;
  border-radius: 10px;
  background: var(--terra);
  color: #fff;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: background .2s ease;
}
#send:hover:not(:disabled) { background: #A94A28; }
#send:disabled { background: var(--line); color: var(--muted); cursor: not-allowed; }
.composer.hidden { display: none; }

@media (max-width: 480px) {
  .sub { display: none; }
  .msg { max-width: 88%; }
}

/* ── экран входа ────────────────────────────────────────── */
.entry {
  max-width: 420px;
  margin: 40px auto;
  width: 100%;
  overflow-y: auto;
}
.entry-lead {
  font-size: 15px;
  color: var(--graphite-soft);
  margin: 0 0 20px;
}
.field { display: block; margin-bottom: 16px; }
.field-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--graphite-soft);
  margin-bottom: 6px;
}
.field input {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  background: var(--card);
  color: var(--graphite);
}
.field input:focus {
  outline: 2px solid var(--terra);
  outline-offset: 1px;
  border-color: var(--terra);
}
#code { letter-spacing: .04em; text-transform: uppercase; }
.field-hint {
  display: block;
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 6px;
}
.consent {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  font-size: 13px;
  color: var(--graphite-soft);
  margin-bottom: 16px;
  cursor: pointer;
  line-height: 1.45;
}
.consent input { margin-top: 2px; flex-shrink: 0; }
.entry-error {
  font-size: 13.5px;
  color: var(--bad);
  background: #FBEBEA;
  border: 1px solid #F0C9C6;
  border-radius: 8px;
  padding: 9px 12px;
  margin: 0 0 14px;
}
#entryBtn {
  width: 100%;
  padding: 12px;
  border: none;
  border-radius: 10px;
  background: var(--terra);
  color: #fff;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: background .2s ease;
}
#entryBtn:hover:not(:disabled) { background: #A94A28; }
#entryBtn:disabled { background: var(--line); color: var(--muted); cursor: not-allowed; }

/* кнопка "пройти ещё раз" */
.ghost {
  margin-top: 10px;
  padding: 9px 16px;
  border: 1px solid var(--terra);
  border-radius: 10px;
  background: transparent;
  color: var(--terra);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}
.ghost:hover:not(:disabled) { background: var(--terra-tint); }
.ghost:disabled { opacity: .5; cursor: not-allowed; }

/* обёртка чата занимает всю доступную высоту */
#chatWrap {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

/* ── баннер про cookie ─────────────────────────────────── */
.cookie-banner {
  flex: 0 0 auto;
  margin: 0 0 14px;
  background: var(--graphite);
  color: #F0EBE3;
  border-radius: 12px;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  box-shadow: 0 4px 16px rgba(0,0,0,.12);
}
.cookie-text {
  margin: 0;
  font-size: 13.5px;
  line-height: 1.5;
  flex: 1 1 240px;
}
.cookie-text a { color: var(--gold); text-decoration: underline; }
.cookie-text a:hover { color: #E2BE6C; }
.cookie-btn {
  flex-shrink: 0;
  padding: 9px 20px;
  border: none;
  border-radius: 8px;
  background: var(--terra);
  color: #fff;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}
.cookie-btn:hover { background: #A94A28; }

/* ссылки в блоке согласия */
.consent a { color: var(--terra); text-decoration: underline; }
.consent a:hover { color: #A94A28; }

/* уведомление о возврате в незавершённую сессию */
.resume-note {
  align-self: stretch;
  background: #FBF3E4;
  border: 1px solid var(--gold);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--graphite-soft);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.link-btn {
  border: none;
  background: none;
  padding: 0;
  font: inherit;
  color: var(--terra);
  text-decoration: underline;
  cursor: pointer;
}
.link-btn:hover:not(:disabled) { color: #A94A28; }
.link-btn:disabled { opacity: .5; cursor: not-allowed; }

/* длинные названия критериев не должны ломать строку с бейджем */
.check .cname { flex: 1 1 auto; min-width: 0; }
