/* ============================================================
   Nori · чат
   ============================================================ */

html, body { overflow: hidden; }
body { background: var(--bg-tint); }

.app { display: flex; height: 100dvh; overflow: hidden; }

/* Боковая панель ----------------------------------------------- */
.sidebar {
  flex: none; width: 278px;
  display: flex; flex-direction: column; gap: 12px;
  padding: 14px 12px;
  background: var(--bg);
  border-right: 1px solid var(--line-soft);
  z-index: 30;
}
.side-top { display: flex; align-items: center; padding: 4px 6px 2px; }
.side-top .brand { display: flex; align-items: center; gap: 9px; color: var(--text); }
.side-top .brand:hover { text-decoration: none; }
.brand-name { font-size: 19px; font-weight: 650; letter-spacing: -.03em; }
.side-close { display: none; margin-left: auto; }

.new-chat {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-radius: var(--r-full);
  background: var(--grad); color: #fff;
  font-size: 14.5px; font-weight: 550;
  box-shadow: 0 5px 18px rgba(80, 100, 220, .3);
  transition: transform .18s var(--ease), box-shadow .25s var(--ease);
}
.new-chat:hover { box-shadow: 0 8px 26px rgba(80, 100, 220, .44); }
.new-chat:active { transform: scale(.98); }

.side-search {
  display: flex; align-items: center; gap: 8px;
  padding: 0 12px; height: 40px;
  border-radius: var(--r-full); background: var(--surface-2);
  color: var(--text-3);
}
.side-search input {
  flex: 1; min-width: 0; height: 100%;
  border: 0; background: none; outline: none; font-size: 14px;
}
.side-search input::-webkit-search-cancel-button { filter: grayscale(1) opacity(.6); }

.side-list { flex: 1; overflow-y: auto; overflow-x: hidden; margin: 0 -4px; padding: 2px 4px; display: flex; flex-direction: column; gap: 2px; }
.side-group { padding: 14px 12px 6px; font-size: 11.5px; font-weight: 650; letter-spacing: .1em; text-transform: uppercase; color: var(--text-3); }

.side-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 10px 10px 10px 12px;
  border-radius: var(--r-sm);
  color: var(--text-2); font-size: 14px; text-align: left;
  transition: background .16s var(--ease), color .16s var(--ease);
}
.side-item:hover { background: var(--surface-2); color: var(--text); }
.side-item.active { background: color-mix(in srgb, var(--blue) 14%, transparent); color: var(--text); font-weight: 550; }
.side-item .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-item .x { flex: none; opacity: 0; width: 26px; height: 26px; display: grid; place-items: center; border-radius: 8px; color: var(--text-3); }
.side-item:hover .x, .side-item.active .x { opacity: 1; }
.side-item .x:hover { background: var(--surface-3); color: var(--red); }
.side-empty { padding: 22px 14px; color: var(--text-3); font-size: 13.5px; text-align: center; line-height: 1.5; white-space: pre-line; }

.side-bottom { display: grid; gap: 2px; padding-top: 8px; border-top: 1px solid var(--line-soft); }
.side-act {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: var(--r-sm);
  color: var(--text-2); font-size: 14px;
  transition: background .16s var(--ease), color .16s var(--ease);
}
.side-act:hover { background: var(--surface-2); color: var(--text); }
.side-act.danger:hover { color: var(--red); }

.scrim { position: fixed; inset: 0; background: rgba(6, 8, 12, .55); backdrop-filter: blur(2px); z-index: 25; }

/* Основная область --------------------------------------------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; background: var(--bg-tint); }

.topbar {
  display: flex; align-items: center; gap: 10px;
  height: 60px; padding: 0 14px;
  border-bottom: 1px solid transparent;
  background: color-mix(in srgb, var(--bg-tint) 84%, transparent);
  backdrop-filter: blur(12px);
  z-index: 10;
}
.topbar.scrolled { border-bottom-color: var(--line-soft); }
.topbar-title {
  flex: 1; min-width: 0;
  font-size: 15.5px; font-weight: 600; letter-spacing: -.015em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.topbar-actions { display: flex; gap: 2px; }
.only-mobile { display: none; }

/* Лента сообщений ---------------------------------------------- */
.stream { flex: 1; overflow-y: auto; overscroll-behavior: contain; scroll-behavior: smooth; }
.stream-inner { max-width: 820px; margin: 0 auto; padding: 24px clamp(14px, 3vw, 24px) 8px; }

.welcome { padding: clamp(28px, 8vh, 74px) 4px 34px; text-align: center; }
.wel-orb {
  width: 74px; height: 74px; margin: 0 auto 22px;
  border-radius: 50%; background: var(--grad);
  box-shadow: 0 12px 40px rgba(100, 110, 220, .38);
  animation: orb 5.5s var(--ease) infinite alternate;
}
@keyframes orb { to { transform: translateY(-9px) scale(1.05); border-radius: 44% 56% 52% 48%; } }
.wel-title { font-size: clamp(27px, 5vw, 40px); letter-spacing: -.04em; margin-bottom: 12px; }
.wel-sub { max-width: 470px; margin: 0 auto 30px; color: var(--text-2); font-size: 16px; }

.chips { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); text-align: left; }
.sug {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; border-radius: var(--r-md);
  border: 1px solid var(--line); background: var(--surface);
  font-size: 14.2px; color: var(--text-2); line-height: 1.4;
  transition: transform .2s var(--ease-out), border-color .2s var(--ease), box-shadow .25s var(--ease), color .2s;
}
.sug:hover { transform: translateY(-2px); color: var(--text); border-color: color-mix(in srgb, var(--blue) 40%, var(--line)); box-shadow: var(--glow); }
.sug-ic { flex: none; font-size: 17px; }

.messages { display: flex; flex-direction: column; gap: 26px; padding-bottom: 20px; }

.msg { display: flex; gap: 14px; animation: rise .38s var(--ease-out) both; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
.msg-ava {
  flex: none; width: 32px; height: 32px; border-radius: 50%;
  background: var(--grad);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--blue) 10%, transparent);
}
.msg-main { min-width: 0; flex: 1; }

.msg.user { justify-content: flex-end; }
.msg.user .msg-ava { display: none; }
.msg.user .msg-main { flex: 0 1 auto; max-width: 78%; }
.msg.user .md {
  padding: 12px 18px; border-radius: 22px 22px 6px 22px;
  background: var(--grad); color: #fff;
  box-shadow: 0 4px 16px rgba(90, 105, 220, .26);
}
.msg.user .md a { color: #fff; text-decoration: underline; }
.msg.user .msg-tools { justify-content: flex-end; }

/* Панель размышлений ------------------------------------------- */
.think {
  margin-bottom: 14px;
  border: 1px solid var(--line); border-radius: var(--r-md);
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  overflow: hidden;
}
.think[open] { background: var(--surface); }
.think summary {
  display: flex; align-items: center; gap: 9px;
  padding: 11px 14px; cursor: pointer; list-style: none;
  font-size: 13.2px; font-weight: 550; color: var(--text-3);
}
.think summary::-webkit-details-marker { display: none; }
.think summary:hover { color: var(--text-2); }
.think-spark {
  flex: none; width: 10px; height: 10px; border-radius: 2px;
  background: var(--grad);
}
.think.live .think-spark { animation: spin 2.4s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.think.live .think-label {
  background: linear-gradient(90deg, var(--text-3) 20%, var(--text) 45%, var(--text-3) 70%);
  background-size: 220% 100%;
  -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: shimmer 1.9s linear infinite;
}
@keyframes shimmer { to { background-position: -220% 0; } }
.think-chev { margin-left: auto; transition: transform .26s var(--ease); }
.think[open] .think-chev { transform: rotate(180deg); }
.think-text {
  max-height: 300px; overflow-y: auto;
  padding: 2px 15px 14px;
  border-top: 1px solid var(--line-soft);
  font-family: var(--mono); font-size: 12.6px; line-height: 1.75;
  color: var(--text-3); white-space: pre-wrap; word-break: break-word;
}
.think-text::before { content: ''; display: block; height: 12px; }

/* Инструменты под сообщением ----------------------------------- */
.msg-tools { display: flex; gap: 4px; margin-top: 8px; opacity: 0; transition: opacity .2s var(--ease); }
.msg:hover .msg-tools, .msg:focus-within .msg-tools { opacity: 1; }
.tool {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 11px; border-radius: var(--r-full);
  font-size: 12.5px; color: var(--text-3);
  transition: background .16s var(--ease), color .16s var(--ease);
}
.tool:hover { background: var(--surface-2); color: var(--text); }
.tool.done { color: var(--green); }

/* Markdown ------------------------------------------------------ */
.md { font-size: 15.6px; line-height: 1.72; }
.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }
.md p { margin: 0 0 14px; }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 { margin: 26px 0 12px; letter-spacing: -.02em; }
.md h1 { font-size: 25px; }
.md h2 { font-size: 21.5px; }
.md h3 { font-size: 18.5px; }
.md h4 { font-size: 16.5px; }
.md h5, .md h6 { font-size: 15.5px; color: var(--text-2); }
.md ul, .md ol { margin: 0 0 14px; padding-left: 24px; }
.md li { margin: 5px 0; }
.md li > ul, .md li > ol { margin: 6px 0 2px; }
.md li > p { margin: 0 0 8px; }
.md li > p:last-child { margin-bottom: 0; }
.md li.task { list-style: none; margin-left: -20px; display: flex; gap: 9px; align-items: flex-start; }
.task-box {
  flex: none; width: 16px; height: 16px; margin-top: 4px;
  border: 1.6px solid var(--text-3); border-radius: 4px;
}
.task-box.on {
  border-color: transparent; background: var(--grad);
  mask-composite: exclude;
  position: relative;
}
.task-box.on::after {
  content: ''; position: absolute; inset: 0;
  background: #fff;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='%23000' stroke-width='3.4' stroke-linecap='round' stroke-linejoin='round' d='m5 12.5 4.5 4.5L19 7'/%3E%3C/svg%3E") center/12px no-repeat;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='none' stroke='%23000' stroke-width='3.4' stroke-linecap='round' stroke-linejoin='round' d='m5 12.5 4.5 4.5L19 7'/%3E%3C/svg%3E") center/12px no-repeat;
}
.md blockquote {
  margin: 0 0 14px; padding: 4px 0 4px 16px;
  border-left: 3px solid color-mix(in srgb, var(--blue) 55%, var(--line));
  color: var(--text-2);
}
.md hr { margin: 22px 0; border: 0; border-top: 1px solid var(--line); }
.md img { margin: 8px 0; border-radius: var(--r-sm); border: 1px solid var(--line-soft); }
.md strong { font-weight: 650; }
.md a { text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--accent) 45%, transparent); text-underline-offset: 2px; }

.md :not(pre) > code {
  padding: .16em .42em;
  border-radius: 6px;
  background: var(--surface-3);
  font-family: var(--mono); font-size: .875em;
  overflow-wrap: anywhere;
}

/* Код ----------------------------------------------------------- */
.code-wrap {
  margin: 0 0 16px;
  border: 1px solid var(--line); border-radius: var(--r-md);
  background: var(--code-bg); overflow: hidden;
}
.code-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 8px 8px 14px;
  border-bottom: 1px solid var(--line-soft);
  background: color-mix(in srgb, var(--surface-2) 70%, transparent);
}
.code-lang { font-family: var(--mono); font-size: 11.5px; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); }
.code-copy {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: var(--r-full);
  font-size: 12px; color: var(--text-3);
  transition: background .16s var(--ease), color .16s var(--ease);
}
.code-copy:hover { background: var(--surface-3); color: var(--text); }
.code-copy.done { color: var(--green); }
.code-wrap pre { margin: 0; padding: 14px 16px; overflow-x: auto; }
.code-wrap code {
  font-family: var(--mono); font-size: 13.1px; line-height: 1.66;
  white-space: pre; tab-size: 2;
}

.hl-com { color: #7b8494; font-style: italic; }
.hl-str { color: #2e9e5b; }
.hl-num { color: #b5722c; }
.hl-kw { color: #2f6fdb; font-weight: 550; }
.hl-fn { color: #7a51c7; }
.hl-tag { color: #cf4f57; }
.hl-attr { color: #b5722c; }
.hl-var { color: #cf4f57; }
.hl-lit { color: #2f6fdb; }
.hl-punct { color: var(--text-3); }

html[data-theme='dark'] .hl-com { color: #6b7484; }
html[data-theme='dark'] .hl-str { color: #7ee0a0; }
html[data-theme='dark'] .hl-num { color: #f0b878; }
html[data-theme='dark'] .hl-kw { color: #8ab4f8; }
html[data-theme='dark'] .hl-fn { color: #c9a8ff; }
html[data-theme='dark'] .hl-tag { color: #ff9a8d; }
html[data-theme='dark'] .hl-attr { color: #f5c451; }
html[data-theme='dark'] .hl-var { color: #ff9a8d; }
html[data-theme='dark'] .hl-lit { color: #8ab4f8; }

/* Таблицы -------------------------------------------------------- */
.table-wrap { margin: 0 0 16px; overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-md); }
.md table { width: 100%; border-collapse: collapse; font-size: 14.4px; }
.md th, .md td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--line-soft); }
.md th { background: var(--surface-2); font-weight: 600; white-space: nowrap; }
.md tbody tr:last-child td { border-bottom: 0; }
.md tbody tr:hover { background: color-mix(in srgb, var(--blue) 5%, transparent); }

/* Курсор набора + ошибки ---------------------------------------- */
.msg.streaming .md > *:last-child::after {
  content: '';
  display: inline-block; width: 8px; height: 1.05em;
  margin-left: 3px; vertical-align: -2px;
  background: var(--grad); border-radius: 2px;
  animation: caret 1.05s steps(2) infinite;
}
@keyframes caret { 50% { opacity: .15; } }

.msg-error {
  display: flex; align-items: flex-start; gap: 10px;
  margin-top: 10px; padding: 12px 15px;
  border: 1px solid color-mix(in srgb, var(--red) 40%, var(--line));
  border-radius: var(--r-md);
  background: color-mix(in srgb, var(--red) 8%, transparent);
  color: var(--text); font-size: 14px;
}
.msg-error b { color: var(--red); font-weight: 600; }

.dots { display: inline-flex; gap: 5px; padding: 6px 0 2px; }
.dots i {
  width: 7px; height: 7px; border-radius: 50%; background: var(--text-3);
  animation: bounce 1.25s var(--ease) infinite;
}
.dots i:nth-child(2) { animation-delay: .16s; }
.dots i:nth-child(3) { animation-delay: .32s; }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0); opacity: .45; } 30% { transform: translateY(-5px); opacity: 1; } }

/* Композер ------------------------------------------------------- */
.composer-zone {
  position: relative;
  padding: 6px clamp(14px, 3vw, 24px) 12px;
  background: linear-gradient(to top, var(--bg-tint) 62%, transparent);
}
.composer {
  max-width: 820px; margin: 0 auto;
  border: 1px solid var(--line); border-radius: 26px;
  background: var(--surface);
  box-shadow: var(--shadow-1);
  transition: border-color .2s var(--ease), box-shadow .25s var(--ease);
}
.composer:focus-within { border-color: color-mix(in srgb, var(--blue) 45%, var(--line)); box-shadow: var(--glow); }

.composer textarea {
  display: block; width: 100%;
  max-height: 260px; padding: 15px 20px 4px;
  border: 0; background: none; outline: none; resize: none;
  font-size: 15.6px; line-height: 1.6;
}
.composer textarea::placeholder { color: var(--text-3); }

.composer-bar { display: flex; align-items: center; gap: 10px; padding: 6px 10px 10px 12px; }
.chip {
  display: inline-flex; align-items: center; gap: 7px;
  height: 34px; padding: 0 14px;
  border: 1px solid var(--line); border-radius: var(--r-full);
  font-size: 13.2px; font-weight: 500; color: var(--text-2);
  transition: background .18s var(--ease), color .18s var(--ease), border-color .18s var(--ease);
}
.chip:hover { background: var(--surface-2); color: var(--text); }
.chip.on {
  border-color: transparent; color: #fff;
  background: var(--grad);
  box-shadow: 0 3px 12px rgba(90, 105, 220, .3);
}
.hint { flex: 1; font-size: 12.2px; color: var(--text-3); text-align: right; }

.send {
  flex: none; display: grid; place-items: center;
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--grad); color: #fff;
  box-shadow: 0 4px 14px rgba(90, 105, 220, .34);
  transition: transform .18s var(--ease), opacity .2s var(--ease), filter .2s;
}
.send:hover { filter: brightness(1.07); }
.send:active { transform: scale(.92); }
.send[disabled] { opacity: .4; box-shadow: none; pointer-events: none; }
.send.stop { background: var(--surface-3); color: var(--text); box-shadow: none; }

.disclaimer { max-width: 820px; margin: 9px auto 0; text-align: center; font-size: 11.8px; color: var(--text-3); }

.scroll-down {
  position: absolute; top: -46px; left: 50%; translate: -50% 0;
  display: grid; place-items: center;
  width: 38px; height: 38px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface); color: var(--text-2);
  box-shadow: var(--shadow-1);
  animation: rise .3s var(--ease-out);
  z-index: 5;
}
.scroll-down:hover { color: var(--text); background: var(--surface-2); }

/* Тост + окно доступа -------------------------------------------- */
.toast {
  position: fixed; left: 50%; bottom: 108px; translate: -50% 0;
  max-width: min(90vw, 420px);
  padding: 11px 18px; border-radius: var(--r-full);
  background: var(--text); color: var(--bg);
  font-size: 13.6px; font-weight: 500;
  box-shadow: var(--shadow-2);
  opacity: 0; pointer-events: none;
  transition: opacity .24s var(--ease), translate .3s var(--ease-out);
  z-index: 60;
}
.toast.show { opacity: 1; translate: -50% -8px; }

.gate {
  border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: 28px 26px; max-width: 380px; width: calc(100vw - 32px);
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-2);
}
.gate::backdrop { background: rgba(6, 8, 12, .6); backdrop-filter: blur(3px); }
.gate h2 { font-size: 21px; margin-bottom: 8px; letter-spacing: -.025em; }
.gate p { color: var(--text-2); font-size: 14.5px; margin-bottom: 18px; }
.gate input {
  width: 100%; height: 46px; padding: 0 16px; margin-bottom: 16px;
  border: 1px solid var(--line); border-radius: var(--r-full);
  background: var(--surface-2); outline: none; font-size: 15px;
}
.gate input:focus { border-color: var(--blue); }
.gate-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* Адаптив -------------------------------------------------------- */
@media (max-width: 860px) {
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: 84vw; max-width: 310px;
    transform: translateX(-102%);
    transition: transform .3s var(--ease-out);
    box-shadow: var(--shadow-2);
  }
  .sidebar.open { transform: none; }
  .side-close { display: grid; }
  .only-mobile { display: grid; }
  .hint { display: none; }
  .msg.user .msg-main { max-width: 88%; }
  .toast { bottom: 130px; }
}
@media (max-width: 520px) {
  .stream-inner { padding-top: 12px; }
  .chips { grid-template-columns: 1fr; }
  .composer textarea { font-size: 16px; }
}
