:root {
  color-scheme: light;
  font-family: "Avenir Next", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  --ink: #152442;
  --muted: #526280;
  --border: #dce4f2;
  --surface: #fff;
  --sidebar: #f5f7fc;
  --accent: #244cdd;
  --accent-hover: #1d3db1;
  --tint: #edf2ff;
  --focus: #2358b9;
  background: var(--surface);
  color: var(--ink);
}

:root[data-specialist="sad"] {
  --ink: #1e2b24;
  --muted: #4d6055;
  --border: #dce6df;
  --sidebar: #f3f7f4;
  --accent: #226044;
  --accent-hover: #194e36;
  --tint: #e6f2e9;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
body, h1, h2, h3, p { margin: 0; }
button, input, textarea { font: inherit; }
a { color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .64; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 3px; }

.sr-only, .skip-link:not(:focus) {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip-link:focus {
  position: fixed;
  z-index: 2;
  inset: 8px auto auto 8px;
  background: var(--surface);
  padding: 10px 12px;
  border-radius: 6px;
}

.app {
  display: grid;
  grid-template: auto minmax(0, 1fr) / 263px minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}

.topbar {
  grid-column: 1 / -1;
  min-width: 0;
  padding: 12px 25px;
  min-height: 66px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--border);
}

.brand, .account {
  display: flex;
  align-items: center;
  gap: 11px;
}

.brand {
  flex: none;
  white-space: nowrap;
  font-weight: 750;
  font-size: .96rem;
  letter-spacing: -.02em;
  line-height: 1.2;
}

.brand small {
  display: block;
  color: var(--muted);
  font-size: .74rem;
  font-weight: 500;
  margin-top: 4px;
  letter-spacing: 0;
}

.brand-mark {
  display: grid;
  grid-template-columns: repeat(2, 6px);
  grid-auto-rows: 6px;
  justify-content: center;
  align-content: center;
  gap: 3px;
  width: 35px;
  height: 35px;
  border-radius: 11px;
  background: var(--ink);
  flex: none;
}

.brand-mark i {
  background: #fff;
  border-radius: 1.5px;
}

.brand-mark i:first-child { border-radius: 6px 1.5px 1.5px; }
.brand-mark i:last-child { opacity: .48; }
.account { min-width: 0; font-size: .82rem; color: var(--muted); }
#account-email { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; max-width: min(38vw, 410px); }
.cabinet-link { display: inline-flex; align-items: center; flex: none; text-decoration: none; }

.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-columns: minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
}

.catalog-nav {
  margin: 18px 15px 0;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  display: grid;
}

.catalog-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  min-height: 44px;
  border-radius: 9px;
  text-decoration: none;
  font-size: .88rem;
  font-weight: 650;
}

.catalog-nav a:hover { background: var(--tint); color: var(--accent); }

.profile-mark {
  display: inline-grid;
  width: 28px;
  height: 28px;
  align-items: center;
  justify-items: center;
  border-radius: 8px;
  flex: none;
  font-weight: 700;
}

.legal-mark { background: #e5ecff; color: #244cdd; }
.garden-mark { background: #e0efe5; color: #226044; }
.garden-mark::before {
  content: "";
  width: .68em;
  height: .84em;
  border: .085em solid;
  border-radius: 70% 5% 70% 12%;
  transform: rotate(27deg);
}

.quiet, .secondary, .primary, .new-chat {
  min-height: 41px;
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 6px 13px;
  font-size: .84rem;
  font-weight: 680;
  line-height: 1.2;
}

.quiet { background: transparent; color: var(--accent); }
.quiet:hover:not(:disabled) { background: var(--tint); }
.primary { border-color: var(--accent); background: var(--accent); color: #fff; }
.primary:hover:not(:disabled) { background: var(--accent-hover); }
.secondary, .new-chat { border-color: var(--border); background: var(--surface); color: var(--ink); }
.secondary:hover:not(:disabled), .new-chat:hover:not(:disabled) { background: var(--tint); border-color: var(--accent); }

.history-pane {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 17px;
  padding: 15px;
}

.history-actions { display: flex; gap: 7px; }
.new-chat { flex: 1; text-align: left; }
.new-chat > span { font-size: 1.13rem; padding-right: 4px; }
.history-toggle { display: none; }
.history-content { min-height: 0; overflow: auto; padding: 2px 3px; scrollbar-width: thin; }
.history-content h2 { margin: 0 3px 7px; font-size: .8rem; color: var(--muted); font-weight: 650; }
.sidebar-note { margin: 6px 3px; color: var(--muted); font-size: .81rem; line-height: 1.4; }
#chat-list { display: grid; grid-template-columns: minmax(0, 1fr); gap: 2px; list-style: none; margin: 0; padding: 0; }
#chat-list a { display: block; padding: 11px 7px; border-radius: 7px; font-size: .84rem; text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#chat-list a:hover, #chat-list a[aria-current] { background: var(--tint); color: var(--accent); }
#chat-list a[aria-disabled="true"] { cursor: default; opacity: .64; }
#chat-list a:focus-visible { outline-offset: -2px; }

.workspace { min-width: 0; min-height: 0; background: var(--surface); }
.center-panel {
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  padding: 24px;
  height: 100%;
  overflow: auto;
  color: var(--muted);
  text-align: center;
}

.auth-panel { background: linear-gradient(152deg, var(--tint), var(--surface) 64%); }
.auth-card {
  width: min(430px, 100%);
  padding: clamp(19px, 4vw, 32px);
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: 0 12px 45px #1616250b;
  text-align: left;
}

.profile-caption {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .82rem;
  color: var(--accent);
  font-weight: 700;
}

.auth-card h1 { margin-top: 13px; font-size: clamp(1.65rem, 4vw, 2.1rem); color: var(--ink); letter-spacing: -.045em; }
#sign-in-intro { margin-top: 7px; line-height: 1.5; overflow-wrap: anywhere; }
.auth-card form { display: grid; gap: 8px; margin-top: 22px; }
.yandex-sign-in { display: grid; margin-top: 18px; }
.yandex-sign-in button { display: flex; align-items: center; justify-content: center; gap: 8px; }
.yandex-mark { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; background: #fff; color: #b92b1d; font-weight: 800; font-size: .73rem; }
.auth-alternative { margin-top: 16px; font-size: .82rem; color: var(--muted); }
.auth-alternative:not([hidden]) + form { margin-top: 9px; }
.auth-card label { font-weight: 680; font-size: .87rem; color: var(--ink); }
.auth-card input {
  width: 100%;
  min-height: 46px;
  padding: 9px 11px;
  color: var(--ink);
  border: 1px solid #a9a2b5;
  border-radius: 8px;
  background: #fff;
}

.email-consent-choice:not([hidden]) {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  margin-top: 4px;
  font-size: .86rem;
}
.auth-card .email-consent-choice input {
  flex: none;
  width: 1.1rem;
  height: 1.1rem;
  min-height: 0;
  padding: 0;
  margin: .19rem 0 0;
}
.email-consent-choice a { display: block; }
.auth-submit { min-height: 45px; margin-top: 5px; }
.change-email { justify-self: center; }
.notice { color: var(--muted); font-size: .87rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.notice[data-tone="error"] { color: #a32a32; }
.auth-card .notice { margin-top: 13px; }

.chat {
  display: grid;
  height: 100%;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.chat-header {
  padding: 13px clamp(18px, 4vw, 45px) 15px;
  min-width: 0;
  border-bottom: 1px solid var(--border);
}

.chat-header .profile-mark { width: 23px; height: 23px; border-radius: 6px; }
.chat-header h1 {
  margin-top: 5px;
  font-size: clamp(1.12rem, 2vw, 1.35rem);
  font-weight: 750;
  letter-spacing: -.026em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-scroll { min-height: 0; overflow: auto; padding: 22px 0 28px; overscroll-behavior-y: contain; }
.chat-scroll:focus-visible { outline-offset: -2px; }
.chat-inner { width: min(calc(100% - 44px), 760px); margin-inline: auto; min-width: 0; }
.chat-scroll > .chat-inner { min-height: 100%; display: grid; align-content: start; }
.chat-scroll > .chat-inner:has(.welcome:not([hidden])) { align-content: center; }
.welcome { display: grid; justify-items: center; gap: 9px; margin: 0 auto; text-align: center; }
.welcome-mark { width: 57px; height: 57px; border-radius: 16px; font-size: 1.7rem; }
.welcome h2 { margin-top: 4px; font-size: clamp(1.4rem, 3vw, 2rem); letter-spacing: -.04em; }
.welcome p { color: var(--muted); max-width: 27rem; line-height: 1.5; }
#retry-chat { justify-self: start; margin-top: 10px; }

#messages { display: grid; gap: 28px; }
.turn { display: grid; gap: 17px; min-width: 0; }
.question-message { justify-self: end; width: fit-content; max-width: min(90%, 630px); border-radius: 15px 15px 3px 15px; background: var(--tint); padding: 11px 15px; }
.answer-message { padding: 2px 3px; min-width: 0; }
.message-label { margin-bottom: 5px; color: var(--muted); font-size: .78rem; font-weight: 720; }
.answer-label { color: var(--accent); }
.message-text { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.62; }
.attachments { display: grid; gap: 5px; list-style: none; margin: 0; padding: 0; min-width: 0; }
.draft-attachments { max-height: min(24dvh, 180px); overflow: auto; padding: 4px; }
.turn-files { width: min(100%, 380px); margin-top: 7px; }
.attachment-item {
  display: flex;
  align-items: center;
  gap: 5px 9px;
  min-width: 0;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}
.attachment-meta { min-width: 0; flex: 1; }
.attachment-name { display: block; font-size: .82rem; line-height: 1.32; overflow-wrap: anywhere; }
.attachment-type { display: block; color: var(--muted); font-size: .73rem; margin-top: 2px; }
.attachment-download { display: inline-flex; flex: none; align-items: center; min-height: 38px; padding-inline: 3px; color: var(--accent); font-size: .8rem; font-weight: 650; text-underline-offset: 2px; }
.attachment-item .remove-file { flex: none; min-width: 40px; min-height: 40px; padding: 0; font-size: 1.15rem; }
.turn-state { font-size: .82rem; color: var(--muted); }
.turn-timing { margin-bottom: 8px; font-size: .79rem; color: var(--muted); }
.message-text:not(:empty) + .turn-state { margin-top: 8px; }
.turn-retry { margin-top: 8px; min-height: 44px; }
.word-actions { width: min(100%, 430px); margin-top: 12px; }
.word-card {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px 12px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}
.word-page {
  width: 23px;
  height: 27px;
  background: #e9effd;
  border: 1px solid #9bb3e7;
  clip-path: polygon(0 0, 70% 0, 100% 26%, 100% 100%, 0 100%);
  border-radius: 4px;
  position: relative;
}
.word-page::before {
  content: "";
  position: absolute;
  inset: 44% 19% auto;
  height: 1px;
  background: #3961ac;
  box-shadow: 0 4px #3961ac, 0 8px #3961ac;
}
.word-filename { display: block; font-size: .84rem; font-weight: 650; overflow-wrap: anywhere; }
.word-metadata { display: block; margin-top: 3px; color: var(--muted); font-size: .76rem; }
.word-open {
  min-height: 44px;
  padding: 0 3px;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: .83rem;
  font-weight: 690;
}
.word-open:hover { text-decoration: underline; text-underline-offset: 3px; }
.word-status { margin-top: 8px; }
.word-dialog {
  width: min(680px, calc(100% - 26px));
  max-width: none;
  max-height: min(90dvh, 760px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 16px 60px #211d2c30;
}
.word-dialog::backdrop { background: #211d2c66; }
.word-preview-frame { display: flex; flex-direction: column; max-height: min(88dvh, 755px); }
.word-preview-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  border-bottom: 1px solid var(--border);
  padding: 13px clamp(12px, 3vw, 24px);
}
.word-preview-header > div { min-width: 0; overflow-wrap: anywhere; }
.word-preview-header h2 { font-size: clamp(1.15rem, 3vw, 1.4rem); }
#word-preview-meta { margin-top: 6px; font-size: .81rem; color: var(--muted); }
.word-preview-body {
  overflow: auto;
  min-height: 0;
  padding: 16px clamp(12px, 3vw, 24px);
  overscroll-behavior-y: contain;
}
#word-preview-text { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.55; }
#word-preview-retry { margin-top: 10px; }
.word-preview-footer { border-top: 1px solid var(--border); padding: 11px clamp(12px, 3vw, 24px); }
.word-preview-footer a { display: inline-flex; align-items: center; text-decoration: none; }
.progress { width: fit-content; margin-bottom: 9px; padding: 5px 8px; border: 1px solid var(--border); border-radius: 7px; color: var(--muted); font-size: .79rem; }
.progress summary { cursor: pointer; padding: 3px 1px; }
.answer-sources { margin-top: 12px; font-size: .82rem; color: var(--muted); }
.answer-sources summary { cursor: pointer; width: fit-content; }
.answer-sources ul { display: grid; gap: 6px; margin: 6px 0 0; padding-left: 21px; }
.answer-sources a { color: var(--accent); overflow-wrap: anywhere; }
.answer-sources time { display: block; font-size: .74rem; }
.progress ul { display: grid; gap: 6px; list-style: none; margin: 5px 0 4px; padding: 0 3px; }
.progress li { display: flex; align-items: center; gap: 7px; }
.progress-indicator { display: inline-grid; place-items: center; flex: none; width: 14px; height: 14px; }
.progress li[data-state="working"] .progress-indicator { border: 2px solid #c7dcf5; border-block-start-color: #225eb4; border-radius: 50%; animation: rotate .9s linear infinite; }
.progress li[data-state="done"] .progress-indicator { color: #217849; font-weight: 750; }
.progress li[data-state="interrupted"] .progress-indicator { color: var(--muted); font-weight: 750; }
@keyframes rotate { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .progress li[data-state="working"] .progress-indicator { animation: none; }
}

.composer-frame {
  border-top: 1px solid var(--border);
  padding: 13px 0 max(16px, env(safe-area-inset-bottom));
  background: var(--surface);
}

#chat-notice, #chat-availability { margin-bottom: 8px; }
.chat-billing { margin-bottom: 8px; }
.composer { padding: 9px 10px 8px; border: 1px solid #acb8ce; border-radius: 14px; }
.composer:focus-within { border-color: var(--accent); }
.composer textarea {
  display: block;
  width: 100%;
  min-height: 52px;
  max-height: min(30vh, 180px);
  resize: vertical;
  border: 0;
  border-radius: 5px;
  padding: 6px 7px;
  color: var(--ink);
  background: var(--surface);
  line-height: 1.45;
}

.composer textarea::placeholder { color: var(--muted); }
.composer textarea:focus-visible { outline-offset: -1px; }
.composer[data-pending="true"] :is(textarea, .draft-attachments, .attach-button, #composer-hint) { display: none; }
.composer-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 6px; }
.composer-actions p { margin-right: auto; padding-left: 7px; font-size: .74rem; color: var(--muted); }
.composer-pilot-note { padding: 0 7px; color: var(--muted); font-size: .74rem; }
.attach-button { flex: none; min-width: 41px; padding: 0; font-size: 1.35rem; line-height: 1; }
#attachment-notice { padding: 6px 6px 3px; max-height: 14dvh; overflow: auto; }

@media (max-width: 680px) {
  .app { grid-template: auto auto minmax(0, 1fr) / minmax(0, 1fr); min-height: 360px; }
  .app[data-reduced-viewport] {
    position: fixed;
    inset: var(--chat-visible-top) 0 auto;
    height: var(--chat-visible-height);
    min-height: 0;
    grid-template-rows: auto minmax(0, 1fr);
  }
  .app[data-reduced-viewport] :is(.sidebar, .chat-header) { display: none; }
  .app[data-reduced-viewport] .chat { grid-template-rows: minmax(0, 1fr) auto; }
  .app[data-reduced-viewport] .draft-attachments { max-height: calc(var(--chat-visible-height) * .22); }
  .app[data-reduced-viewport] #attachment-notice { max-height: calc(var(--chat-visible-height) * .12); }
  .topbar { min-height: 56px; padding: 7px 12px; gap: 9px; }
  .brand, .account { gap: 7px; }
  .brand-mark { width: 30px; height: 30px; border-radius: 8px; }
  .brand small { font-size: .68rem; }
  .account .quiet { padding-inline: 7px; }
  .sidebar { border: 0; border-bottom: 1px solid var(--border); }
  .catalog-nav { margin: 0; padding: 4px 10px; border-bottom: 0; }
  .catalog-nav a { padding-inline: 7px; font-size: .82rem; }
  .history-pane { padding: 0 10px 6px; gap: 6px; }
  .history-toggle { display: inline-block; }
  .history-actions { justify-content: space-between; }
  .new-chat { flex: none; }
  .history-content { display: none; max-height: min(30dvh, 230px); }
  .history-pane[data-expanded="true"] .history-content { display: block; }
  .history-content h2 { display: none; }
  .center-panel { place-content: safe center; padding: 17px 12px; }
  .chat-header { padding: 7px 12px 9px; }
  .chat-inner { width: calc(100% - 24px); }
  .chat-scroll { padding: 14px 0 17px; }
  .composer-frame { padding: 8px 0 max(8px, env(safe-area-inset-bottom)); }
  .composer { padding: 5px 5px 4px; }
  .composer textarea { min-height: 48px; resize: none; }
  .composer-actions { margin-top: 3px; }
  .composer-actions p { display: none; }
  .composer-actions .attach-button { margin-right: auto; min-width: 44px; min-height: 44px; }
  .attachment-item .remove-file { min-width: 44px; min-height: 44px; }
  .attachment-download { min-height: 44px; }
}

@media (max-width: 440px) {
  #account-email { display: none; }
}

@media (max-height: 460px) and (max-width: 680px) {
  .chat-header .profile-caption { display: none; }
}
