/* ---------- Шрифты (размещены на сервере, без внешних запросов) ---------- */
@font-face { font-family: "Marcellus"; src: url(/fonts/marcellus-latin-400-normal.woff2) format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Golos Text"; src: url(/fonts/golos-text-cyrillic-400-normal.woff2) format("woff2"); font-weight: 400; font-display: swap; unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: "Golos Text"; src: url(/fonts/golos-text-latin-400-normal.woff2) format("woff2"); font-weight: 400; font-display: swap; unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Golos Text"; src: url(/fonts/golos-text-cyrillic-500-normal.woff2) format("woff2"); font-weight: 500; font-display: swap; unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: "Golos Text"; src: url(/fonts/golos-text-latin-500-normal.woff2) format("woff2"); font-weight: 500; font-display: swap; unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122, U+2212; }
@font-face { font-family: "Golos Text"; src: url(/fonts/golos-text-cyrillic-600-normal.woff2) format("woff2"); font-weight: 600; font-display: swap; unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: "Golos Text"; src: url(/fonts/golos-text-latin-600-normal.woff2) format("woff2"); font-weight: 600; font-display: swap; unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122, U+2212; }
@font-face { font-family: "Literata"; src: url(/fonts/literata-cyrillic-400-normal.woff2) format("woff2"); font-weight: 400; font-display: swap; unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: "Literata"; src: url(/fonts/literata-latin-400-normal.woff2) format("woff2"); font-weight: 400; font-display: swap; unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122, U+2212; }
@font-face { font-family: "Literata"; src: url(/fonts/literata-cyrillic-400-italic.woff2) format("woff2"); font-weight: 400; font-style: italic; font-display: swap; unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: "Literata"; src: url(/fonts/literata-latin-400-italic.woff2) format("woff2"); font-weight: 400; font-style: italic; font-display: swap; unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122, U+2212; }
@font-face { font-family: "Literata"; src: url(/fonts/literata-cyrillic-600-normal.woff2) format("woff2"); font-weight: 600; font-display: swap; unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: "Literata"; src: url(/fonts/literata-latin-600-normal.woff2) format("woff2"); font-weight: 600; font-display: swap; unicode-range: U+0000-00FF, U+2000-206F, U+20AC, U+2122, U+2212; }

/* ---------- Цвета ---------- */
:root {
  --paper: #EDEFEA;      /* холодный серо-зелёный, как бухгалтерская бумага */
  --surface: #F7F8F5;
  --ink: #1B2420;
  --muted: #5B6862;
  --line: #CCD3CE;
  --bronze: #2E6B5E;     /* патина бронзы */
  --bronze-ink: #F4F6F2;
  --seal-bg: #DCE6E0;
  --restored: #2E6B5E;
  --danger: #9E3726;
  --focus: #2E6B5E;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #121715;
    --surface: #1A201E;
    --ink: #E1E7E3;
    --muted: #96A29C;
    --line: #2D3632;
    --bronze: #7FBFAE;
    --bronze-ink: #0F1513;
    --seal-bg: #1F2E2A;
    --restored: #8FCAB9;
    --danger: #E08A78;
    --focus: #7FBFAE;
    color-scheme: dark;
  }
}

/* ---------- Основа ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 16px/1.5 "Golos Text", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Логотип ---------- */
.wordmark {
  font-family: "Marcellus", "Trajan Pro", Georgia, serif;
  font-weight: 400;
  letter-spacing: 0.14em;
  color: var(--ink);
  margin: 0;
  white-space: nowrap;
}
.wordmark .interpunct { color: var(--bronze); margin: 0 0.04em 0 0.08em; }
.wordmark-lg { font-size: clamp(2.75rem, 9vw, 4.75rem); line-height: 1; letter-spacing: 0.12em; }
.wordmark-sm { font-size: 1.15rem; }

/* ---------- Кнопки ---------- */
.btn {
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0.55rem 1rem;
  font-weight: 500;
  font-size: 0.95rem;
  cursor: pointer;
  background: none;
  line-height: 1.2;
  white-space: nowrap;
}
.btn-primary { background: var(--bronze); color: var(--bronze-ink); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { border-color: var(--line); background: var(--surface); }
.btn-ghost:hover { border-color: var(--bronze); }
.btn-quiet { color: var(--muted); padding: 0.4rem 0.6rem; }
.btn-quiet:hover { color: var(--ink); }
.btn-small { font-size: 0.85rem; padding: 0.2rem 0.5rem; }
.btn:disabled { opacity: 0.5; cursor: default; }

/* ---------- Вход ---------- */
.login {
  min-height: 100%;
  display: flex;
  align-items: center;
  padding: 48px clamp(16px, 8vw, 120px);
}
.login-col { max-width: 36rem; width: 100%; }
.login-lead { font-size: 1.125rem; line-height: 1.55; margin: 1.75rem 0 2.25rem; max-width: 32rem; }

.demo { margin: 0 0 2.5rem; padding: 1.1rem 0 0; border-top: 1px solid var(--line); }
.demo-line { font-family: "Literata", Georgia, serif; font-size: 1.05rem; line-height: 2; margin: 0; }
.demo figcaption { color: var(--muted); font-size: 0.875rem; margin-top: 0.5rem; }
.demo-swap { display: inline-block; position: relative; vertical-align: baseline; }

.seal, .demo-swap.is-sealed {
  font-family: "Golos Text", system-ui, sans-serif;
  font-size: 0.8em;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--bronze);
  background: var(--seal-bg);
  border: 1px dashed var(--bronze);
  border-radius: 3px;
  padding: 0.05em 0.4em;
  white-space: nowrap;
  line-height: 1.5;
}
.demo-swap.is-sealing { animation: seal-in 520ms cubic-bezier(.2,.7,.2,1) both; }
@keyframes seal-in {
  0% { opacity: 0; transform: translateY(0.25em) scale(0.92); }
  100% { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) { .demo-swap.is-sealing { animation: none; } }

.login-form label { display: block; font-weight: 500; margin-bottom: 0.4rem; }
.login-row { display: flex; gap: 0.5rem; }
.login-row input {
  flex: 1;
  min-width: 0;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.login-row input::placeholder { color: var(--muted); opacity: 0.6; }
.form-error { color: var(--danger); min-height: 1.5em; margin: 0.5rem 0 0; font-size: 0.925rem; }

/* ---------- Окно диалога ---------- */
.app { display: flex; flex-direction: column; height: 100%; height: 100dvh; }
.bar {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.6rem clamp(16px, 3vw, 28px);
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}
.bar-client { color: var(--muted); font-size: 0.925rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-left: 0.75rem; border-left: 1px solid var(--line); }
.bar-spacer { flex: 1; }
.bar-left { color: var(--muted); font-size: 0.85rem; font-variant-numeric: tabular-nums; }

.thread { flex: 1; overflow-y: auto; padding: 2rem clamp(16px, 4vw, 40px) 1rem; scroll-behavior: smooth; }
.thread > * { max-width: 46rem; margin-left: auto; margin-right: auto; }

.empty h2 { font-family: "Literata", Georgia, serif; font-weight: 400; font-size: 1.75rem; margin: 1rem 0 0.75rem; }
.empty p { color: var(--muted); max-width: 38rem; margin: 0 0 1.5rem; }
.examples { display: grid; gap: 0.5rem; }
.example {
  text-align: left; cursor: pointer;
  background: none; border: none; border-left: 2px solid var(--line);
  padding: 0.35rem 0 0.35rem 0.9rem; color: var(--ink); line-height: 1.45;
}
.example:hover { border-left-color: var(--bronze); }

/* Сообщение клиента */
.msg-user { margin: 2rem auto 0.75rem; padding-left: 1rem; border-left: 3px solid var(--bronze); }
.msg-user .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.masked { margin-top: 0.5rem; font-size: 0.875rem; color: var(--muted); }
.masked button { background: none; border: none; padding: 0; color: var(--bronze); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
.sent {
  margin-top: 0.6rem; padding: 0.75rem 0.9rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: 6px;
  font-size: 0.925rem; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--ink);
}
.sent .seal { font-size: 0.85em; }

/* Ответ */
.msg-ai { margin: 1rem auto 1.5rem; font-family: "Literata", Georgia, serif; font-size: 1.0625rem; line-height: 1.65; overflow-wrap: anywhere; }
.msg-ai p { margin: 0 0 0.9em; }
.msg-ai h3, .msg-ai h4 { font-family: "Golos Text", system-ui, sans-serif; font-weight: 600; font-size: 1rem; margin: 1.4em 0 0.5em; }
.msg-ai ul, .msg-ai ol { margin: 0 0 0.9em; padding-left: 1.4em; }
.msg-ai li { margin: 0.25em 0; }
.msg-ai strong { font-weight: 600; }
.msg-ai code { font-size: 0.9em; background: var(--surface); border: 1px solid var(--line); border-radius: 3px; padding: 0 0.25em; }
.msg-ai .restored { text-decoration: underline dotted var(--restored); text-underline-offset: 4px; text-decoration-thickness: 1.5px; }
.msg-ai.is-streaming > :last-child::after { content: ""; display: inline-block; width: 0.5em; height: 1em; margin-left: 2px; vertical-align: -0.15em; background: var(--bronze); animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .msg-ai.is-streaming > :last-child::after { animation: none; } }
.msg-tools { display: flex; gap: 0.25rem; margin-top: -0.5rem; font-family: "Golos Text", system-ui, sans-serif; }
.msg-error { color: var(--danger); font-family: "Golos Text", system-ui, sans-serif; font-size: 0.95rem; }
.thinking { color: var(--muted); font-family: "Golos Text", system-ui, sans-serif; font-size: 0.95rem; }

/* ---------- Поле ввода ---------- */
.composer { padding: 0.75rem clamp(16px, 4vw, 40px) calc(0.75rem + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--paper); }
.composer > * { max-width: 46rem; margin-left: auto; margin-right: auto; }
.composer-form { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 0.6rem 0.75rem; }
.composer-form:focus-within { border-color: var(--bronze); }
#message {
  width: 100%; border: none; background: none; resize: none; outline: none;
  max-height: 40vh; min-height: 1.5em; line-height: 1.5; padding: 0.15rem 0;
}
.composer-row { display: flex; align-items: center; gap: 0.75rem; margin-top: 0.5rem; flex-wrap: wrap; }
.terms { flex: 1; display: flex; align-items: center; flex-wrap: wrap; gap: 0.35rem; min-width: 12rem; font-size: 0.875rem; }
.terms-label { color: var(--muted); }
.terms-chips { display: contents; }
.term-chip { display: inline-flex; align-items: center; gap: 0.25rem; }
.term-chip button { border: none; background: none; padding: 0 0.1rem; color: var(--bronze); cursor: pointer; font-size: 1em; line-height: 1; }
#term-input { flex: 1; min-width: 8rem; border: none; border-bottom: 1px dashed var(--line); background: none; outline: none; padding: 0.15rem 0; }
#term-input:focus { border-bottom-color: var(--bronze); }
.composer-actions { display: flex; gap: 0.5rem; margin-left: auto; }

.preview { margin-bottom: 0.6rem; background: var(--surface); border: 1px dashed var(--bronze); border-radius: 8px; padding: 0.6rem 0.75rem; }
.preview-head { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: 0.875rem; margin-bottom: 0.35rem; }
.preview-body { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 30vh; overflow-y: auto; font-size: 0.95rem; }
.preview-summary { color: var(--muted); font-size: 0.85rem; margin-top: 0.5rem; }

.disclaimer { color: var(--muted); font-size: 0.78rem; margin-top: 0.5rem; text-align: center; }

/* ---------- Телефон ---------- */
@media (max-width: 640px) {
  .login { align-items: flex-start; padding-top: 12vh; }
  .login-row { flex-direction: column; }
  .bar { gap: 0.4rem; }
  .bar-client, .bar-left { display: none; }
  .btn-quiet { padding: 0.4rem 0.4rem; font-size: 0.875rem; }
  .composer-actions { width: 100%; }
  .composer-actions .btn { flex: 1; }
  .msg-ai { font-size: 1rem; }
}
