/* ── Токены ───────────────────────────────────────────── */
:root {
  --bg: #E8EDF2;
  --surface: #FFFFFF;
  --surface-2: #F3F6F9;
  --ink: #101828;
  --muted: #566275;
  --line: #C9D2DE;
  --accent: #2F4BFF;
  --accent-hover: #2239D6;
  --accent-ink: #FFFFFF;
  --stub: #f79756;
  --stub-ink: #2A1D00;
  --danger: #B42318;
  --warn-bg: #FFF1CC;
  --warn-ink: #5C4200;
  --warn-line: #f79756;
  --shadow: 0 1px 0 var(--line), 0 28px 48px -28px rgba(16, 24, 40, .38);
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0C1220;
    --surface: #151D2F;
    --surface-2: #1B2540;
    --ink: #E8ECF4;
    --muted: #95A2B8;
    --line: #2A3652;
    --accent: #f79756;
    --accent-hover: #f79756;
    --accent-ink: #0C1220;
    --danger: #FF8A80;
    --warn-bg: #3A2E0E;
    --warn-ink: #FFE29A;
    --warn-line: #7A611A;
    --shadow: 0 1px 0 var(--line), 0 28px 48px -28px rgba(0, 0, 0, .7);
  }
}

/* ── База ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 var(--font); -webkit-font-smoothing: antialiased;
}
h1, p, ul { margin: 0; }
ul { padding: 0; list-style: none; }
a { color: inherit; }
button, input, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }

.brand { display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: -.01em;
  font-size: 50px;}
.brand__mark {
  --size: 50px;                       /* меняйте только это число */
  width: var(--size);
  height: var(--size);
  border-radius: calc(var(--size) * .32);
  background: var(--accent);
  position: relative;
  
}
.brand__mark::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 36%;
  height: 36%;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  border: calc(var(--size) * .11) solid var(--accent-ink);
}


/* ── Кнопки ───────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 20px; border-radius: 10px; border: 1px solid transparent;
  font-weight: 600; cursor: pointer; text-decoration: none; transition: background-color .15s, opacity .15s;
}
.btn--primary { background: var(--accent); color: var(--accent-ink); }
.btn--primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn--ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.btn--ghost:hover { background: var(--surface-2); }
.btn--block { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.icon-btn {
  width: 36px; height: 36px; display: inline-grid; place-items: center; border-radius: 8px;
  border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 15px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

.form-error { color: var(--danger); font-size: 14px; font-weight: 500; }

/* ── Лендинг ──────────────────────────────────────────── */
.landing { min-height: 100dvh; display: flex; flex-direction: column; padding: 24px clamp(20px, 5vw, 72px); }
.landing--center { justify-content: center; align-items: flex-start; gap: 16px; max-width: 640px; margin: 0 auto; }
.landing__top { padding-bottom: 8px; }
.landing__foot { color: var(--muted); font-size: 13px; padding-top: 24px; }
.hero {
  flex: 1; display: grid; align-items: center;
  grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
  gap: clamp(32px, 7vw, 112px);
}
h1 {
  font-size: clamp(2.3rem, 5vw, 4.2rem); line-height: 1.04; letter-spacing: -.035em;
  font-weight: 800; max-width: 14ch; text-wrap: balance;
}
.h-small { font-size: 2rem; max-width: none; letter-spacing: -.02em; }
.lead { margin-top: 20px; font-size: 1.15rem; color: var(--muted); max-width: 44ch; }
.facts { margin-top: 28px; display: grid; gap: 10px; color: var(--ink); max-width: 46ch; }
.facts li { padding-left: 22px; position: relative; }
.facts li::before {
  content: ""; position: absolute; left: 0; top: .6em; width: 10px; height: 2px; background: var(--accent);
}

/* Ключ-билет */
.ticket {
  position: relative; display: grid; grid-template-columns: minmax(0, 1fr) 124px;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
}
.ticket::before, .ticket::after {
  content: ""; position: absolute; right: calc(124px - 12px); width: 24px; height: 24px;
  border-radius: 50%; background: var(--bg);
}
.ticket::before { top: -12px; }
.ticket::after { bottom: -12px; }
.ticket__main { padding: clamp(24px, 4vw, 40px); display: grid; gap: 12px; align-content: center; }
.ticket__stub {
  background: var(--stub); color: var(--stub-ink); border-radius: 0 var(--radius) var(--radius) 0;
  border-left: 2px dashed rgba(42, 29, 0, .35); padding: 22px 16px;
  display: flex; flex-direction: column; justify-content: space-between; gap: 16px;
}
.ticket__stub-text { font-size: 13px; font-weight: 600; line-height: 1.3; }
.field__label { font-weight: 600; }
.field__input {
  width: 100%; min-height: 52px; padding: 0 16px; border-radius: 10px;
  border: 1.5px solid var(--line); background: var(--surface-2);
  font-family: var(--mono); font-size: 15px; letter-spacing: .01em;
}
.field__input::placeholder { color: var(--muted); }
.field__input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.field__input[aria-invalid="true"] { border-color: var(--danger); }

@media (max-width: 860px) {
  .hero { grid-template-columns: 1fr; align-items: start; padding-top: 24px; gap: 36px; }
  .ticket { grid-template-columns: 1fr; }
  .ticket::before, .ticket::after { right: auto; top: auto; bottom: 74px; }
  .ticket::before { left: -12px; }
  .ticket::after { right: -12px; }
  .ticket__stub {
    flex-direction: row; align-items: center; border-radius: 0 0 var(--radius) var(--radius);
    border-left: 0; border-top: 2px dashed rgba(42, 29, 0, .35); padding: 16px 24px; min-height: 74px;
  }
}

/* ── Чат ──────────────────────────────────────────────── */
.page-chat { height: 100dvh; overflow: hidden; }
.app { display: grid; grid-template-columns: 304px minmax(0, 1fr); height: 100dvh; }

.sidebar {
  background: var(--surface); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 16px; padding: 18px 16px; min-height: 0;
}
.sidebar__head { display: flex; align-items: center; justify-content: space-between; }
.sidebar__close { display: none; }
.chatlist { flex: 1; min-height: 0; overflow-y: auto; margin: 0 -6px; padding: 0 6px; }
.chatlist ul { display: grid; gap: 2px; }
.chatlist__empty { color: var(--muted); font-size: 14px; padding: 8px 4px; }
.chatlist__item { display: flex; align-items: center; border-radius: 10px; }
.chatlist__item:hover, .chatlist__item.is-active { background: var(--surface-2); }
.chatlist__item.is-active { box-shadow: inset 3px 0 0 var(--accent); }
.chatlist__link { flex: 1; min-width: 0; text-decoration: none; padding: 9px 10px; display: grid; gap: 1px; }
.chatlist__title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.chatlist__date { font-size: 12px; color: var(--muted); }
.chatlist__delete { opacity: 0; margin-right: 4px; }
.chatlist__item:hover .chatlist__delete, .chatlist__delete:focus-visible { opacity: 1; }
@media (hover: none) { .chatlist__delete { opacity: 1; } }

.sidebar__foot { display: grid; gap: 10px; border-top: 1px solid var(--line); padding-top: 14px; }
.keyinfo { display: flex; justify-content: space-between; align-items: baseline; font-size: 14px; gap: 8px; }
.keyinfo__id { font-family: var(--mono); color: var(--muted); }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.main__head { display: flex; align-items: center; gap: 8px; padding: 14px 24px; border-bottom: 1px solid var(--line); background: var(--surface); }
.main__title { font-size: 1.05rem; font-weight: 650; letter-spacing: 0; max-width: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu-btn { display: none; }

.notice {
  display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline;
  margin: 16px 24px 0; padding: 12px 16px; border-radius: 10px;
  background: var(--warn-bg); color: var(--warn-ink); border: 1px solid var(--warn-line); font-size: 15px;
}

.messages { flex: 1; min-height: 0; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 14px; }
.empty { margin: auto; color: var(--muted); text-align: center; max-width: 36ch; }
.msg { display: flex; }
.msg__body {
  max-width: min(72ch, 86%); padding: 11px 15px; border-radius: 14px;
  white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.55;
}
.msg--user { justify-content: flex-end; }
.msg--user .msg__body { background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 4px; }
.msg--assistant .msg__body { background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg--pending .msg__body { color: var(--muted); font-style: italic; }

.composer { padding: 14px 24px 22px; background: var(--bg); }
.composer__error { margin-bottom: 8px; }
.composer__row {
  display: flex; gap: 10px; align-items: flex-end; background: var(--surface);
  border: 1.5px solid var(--line); border-radius: 14px; padding: 8px;
}
.composer__row:focus-within { border-color: var(--accent); }
.composer textarea {
  flex: 1; resize: none; border: 0; background: transparent; outline: none;
  max-height: 200px; padding: 10px 8px; line-height: 1.45;
}
.composer textarea:disabled { cursor: not-allowed; color: var(--muted); }
.composer textarea::placeholder { color: var(--muted); }
.composer[aria-disabled="true"] .composer__row { background: var(--surface-2); border-style: dashed; }

.scrim { position: fixed; inset: 0; background: rgba(8, 12, 22, .5); z-index: 20; }

@media (max-width: 800px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: min(86vw, 320px); z-index: 30;
    transform: translateX(-102%); transition: transform .2s ease;
  }
  .sidebar.is-open { transform: none; }
  .sidebar__close, .menu-btn { display: inline-grid; }
  .main__head, .messages, .composer { padding-left: 16px; padding-right: 16px; }
  .notice { margin-left: 16px; margin-right: 16px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* Chat bubbles, Markdown and copy actions */
.msg { flex-direction: column; align-items: flex-start; min-width: 0; }
.msg--user { align-items: flex-end; }
.msg__body { min-width: 0; width: fit-content; max-width: min(80ch, 94%); }
.msg--assistant .msg__body { width: fit-content; white-space: normal; }
.msg__copy {
  margin: 5px 3px 0; padding: 5px 9px; border-radius: 7px;
  color: var(--muted); background: transparent; border: 1px solid transparent;
  font: inherit; font-size: 12px; cursor: pointer;
}
.msg__copy:hover, .msg__copy:focus-visible { border-color: var(--line); color: var(--text); background: var(--surface); }
.msg__body > :first-child { margin-top: 0; }
.msg__body > :last-child { margin-bottom: 0; }
.msg--assistant .msg__body p { margin: 0 0 .85em; }
.msg--assistant .msg__body h1, .msg--assistant .msg__body h2,
.msg--assistant .msg__body h3, .msg--assistant .msg__body h4,
.msg--assistant .msg__body h5, .msg--assistant .msg__body h6 {
  font-weight: 700; line-height: 1.3; margin: 1em 0 .5em;
}
.msg--assistant .msg__body h1 { font-size: 1.5em; }
.msg--assistant .msg__body h2 { font-size: 1.3em; }
.msg--assistant .msg__body h3 { font-size: 1.15em; }
.msg--assistant .msg__body ul, .msg--assistant .msg__body ol { padding-left: 1.5em; margin: .65em 0; }
.msg--assistant .msg__body li { margin: .3em 0; }
.msg--assistant .msg__body blockquote { border-left: 3px solid var(--line); margin: .75em 0; padding: .25em 0 .25em 1em; color: var(--muted); }
.msg--assistant .msg__body hr { border: 0; border-top: 1px solid var(--line); margin: 1em 0; }
.msg--assistant .msg__body a { color: var(--accent); text-decoration: underline; overflow-wrap: anywhere; }
.msg--assistant .msg__body :not(pre) > code {
  padding: .15em .35em; border-radius: 5px; background: var(--surface-2);
  font-family: var(--mono); font-size: .9em;
}
.md-code { margin: .8em 0; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.md-code__head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 7px 12px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.md-code__copy { background: none; color: inherit; border: 0; cursor: pointer; font: inherit; }
.md-code__copy:hover { text-decoration: underline; }
.md-code pre { overflow-x: auto; margin: 0; padding: 13px; line-height: 1.5; tab-size: 4; }
.md-code pre code { font-family: var(--mono); font-size: 13px; white-space: pre; }
.md-table-wrap { max-width: 100%; overflow-x: auto; margin: .8em 0; border: 1px solid var(--line); border-radius: 9px; }
.md-table-wrap table { width: 100%; border-collapse: collapse; font-size: .94em; }
.md-table-wrap th, .md-table-wrap td { padding: 9px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.md-table-wrap th { background: var(--surface-2); font-weight: 650; }
.md-table-wrap tr:last-child td { border-bottom: 0; }
.md-table-wrap th + th, .md-table-wrap td + td { border-left: 1px solid var(--line); }
@media (max-width: 600px) { .msg__body { max-width: 100%; } }

/* File previews in the composer */
.attachment-preview { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 10px; margin: 0 0 12px; }
.attachment-preview:empty { display: none; }
.attachment-card { position: relative; display: flex; flex-direction: column; gap: 7px; width: 138px; max-width: 100%; padding: 8px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface-2); box-sizing: border-box; }
.attachment-card--image { width: 154px; }
.attachment-card__thumbnail { display: block; width: 100%; height: 102px; object-fit: contain; border-radius: 7px; background: var(--bg); }
.attachment-card__file-icon { display: flex; align-items: center; justify-content: center; width: 52px; height: 63px; border: 2px solid var(--accent); border-radius: 8px; color: var(--accent); background: var(--bg); font-size: 12px; font-weight: 800; letter-spacing: -.3px; }
.attachment-card__name { display: block; width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; line-height: 1.4; padding-right: 14px; box-sizing: border-box; }
.attachment-card__remove { position: absolute; top: 3px; right: 3px; display: grid; place-items: center; width: 24px; height: 24px; border: 1px solid var(--line); border-radius: 50%; background: var(--bg); color: var(--muted); cursor: pointer; font-size: 19px; line-height: 1; }
.attachment-card__remove:hover { color: var(--danger); border-color: var(--danger); }
.attach-btn { background: transparent; border: 0; cursor: pointer; font-size: 21px; padding: 8px; border-radius: 9px; }
.attach-btn:hover { background: var(--surface-2); }

/* Reliable image-preview state (FileReader data URL). */
.attachment-card--image .attachment-card__thumbnail { display: none; }
.attachment-card--image.attachment-card--loaded .attachment-card__thumbnail { display: block; }
.attachment-card__image-fallback { display: grid; place-items: center; min-height: 102px; font-size: 12px; color: var(--muted); text-align: center; }
.attachment-card--loaded .attachment-card__image-fallback { display: none; }
.attachment-card--failed .attachment-card__image-fallback { display: grid; }
.attachment-card--failed .attachment-card__thumbnail { display: none; }
