/* lab-chat — черный фон, белый текст, моноширинный шрифт, тонкие границы. */

:root {
  --bg: #0a0a0a;
  --bg-panel: #111111;
  --bg-input: #161616;
  --bg-hover: #1a1a1a;
  --border: #232323;
  --border-strong: #333333;
  --text: #ededed;
  --text-dim: #8a8a8a;
  --text-faint: #5c5c5c;
  --accent: #fab283;
  --blue: #5c9cf5;
  --green: #7fd88f;
  --red: #e06c75;
  --yellow: #e5c07b;
  --radius: 6px;
  --mono: ui-monospace, "JetBrains Mono", "Cascadia Code", "SF Mono", Consolas, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--mono);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection {
  background: #3a2a1e;
  color: var(--text);
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

/* ─── Общие мелочи ───────────────────────────────────────────── */

.logo {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--text);
  user-select: none;
}

.logo-sm {
  font-size: 14px;
}

.eyebrow {
  margin: 0;
  font-size: 11px;
  line-height: 1.4;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
}

.kbd-hint {
  font-size: 11px;
  color: var(--text-faint);
  user-select: none;
}

.user {
  font-size: 12px;
  color: var(--accent);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.form-error {
  margin: 0;
  font-size: 12px;
  color: var(--red);
}

/* ─── Загрузка ──────────────────────────────────────────────── */

.boot {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  z-index: 20;
}

/* ─── Кнопки и поля ─────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  min-height: 38px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}

.btn:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}

.btn:focus-visible,
.input:focus-visible,
.textarea:focus-visible {
  outline: 1px solid var(--border-strong);
  outline-offset: 1px;
  border-color: var(--border-strong);
}

.btn-primary:focus-visible {
  outline-color: var(--accent);
}

.btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #0a0a0a;
  font-weight: 600;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent);
  border-color: var(--accent);
  opacity: 0.88;
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-dim);
  min-height: 30px;
  padding: 4px 8px;
}

.btn-ghost:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: var(--border);
  color: var(--text);
}

.btn-block {
  width: 100%;
}

.input,
.textarea {
  display: block;
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 12px;
  font-size: 14px;
  line-height: 1.6;
}

.input::placeholder,
.textarea::placeholder {
  color: var(--text-faint);
}

.textarea {
  resize: none;
  overflow-y: auto;
}

/* ─── Вход ──────────────────────────────────────────────────── */

.view-login {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  width: 360px;
  max-width: 100%;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 28px 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-logo {
  font-size: 17px;
  margin-bottom: 4px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
}

.login-card .btn-block {
  margin-top: 4px;
}

/* ─── Задание ───────────────────────────────────────────────── */

.view-intake {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.intake-main {
  flex: 1;
  display: flex;
  justify-content: center;
  padding: 40px 24px 64px;
}

.intake-box {
  width: 620px;
  max-width: 100%;
}

.intake-title {
  margin: 10px 0 6px;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.5;
}

.intake-hint {
  margin: 0 0 20px;
  font-size: 12px;
  color: var(--text-dim);
}

.intake-textarea {
  min-height: 200px;
}

.intake-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
}

/* Карточка задания */

.intake-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  background: var(--bg-panel);
}

.card-group + .card-group {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.card-group-title {
  margin: 0 0 6px;
}

.card-item {
  padding: 1px 0 1px 12px;
  font-size: 13px;
  color: var(--text);
  word-break: break-word;
}

.card-item-muted {
  color: var(--text-dim);
}

.card-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 3px 0 3px 12px;
}

.card-row-label {
  flex: 0 0 42%;
  font-size: 12px;
  color: var(--text-dim);
  overflow-wrap: anywhere;
}

.card-input {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 32px;
  padding: 4px 8px;
  font-size: 13px;
}

.card-input[type="number"] {
  appearance: textfield;
  -moz-appearance: textfield;
}

.card-input[type="number"]::-webkit-outer-spin-button,
.card-input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.intake-card-error {
  margin-top: 10px;
  padding-left: 2px;
}

.card-warnings {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.card-warning {
  font-size: 12px;
  color: var(--yellow);
  padding-left: 12px;
}

.card-unknown {
  font-size: 12px;
  color: var(--text-dim);
  padding-left: 12px;
}

.card-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ─── Чат ───────────────────────────────────────────────────── */

.view-chat {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  height: 52px;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.topbar-right {
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.topbar-step {
  justify-self: center;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  text-align: center;
  white-space: nowrap;
}

.progress {
  flex: 0 0 auto;
  height: 2px;
  background: var(--border);
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 120ms linear;
}

.feed-wrap {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.feed {
  max-width: 760px;
  margin: 0 auto;
  padding: 24px;
}

/* Сообщения */

.msg {
  margin: 0 0 24px;
}

.msg:last-child {
  margin-bottom: 8px;
}

.msg-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  margin-bottom: 4px;
  user-select: none;
}

.msg-user {
  border-left: 2px solid var(--border-strong);
  padding-left: 14px;
}

.msg-user .msg-text {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg-assistant {
  padding: 0;
}

.msg-step {
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.msg-step:first-child {
  padding-top: 0;
  border-top: 0;
}

.msg-error .msg-text {
  color: var(--red);
  font-size: 12px;
}

.msg-system {
  color: var(--text-dim);
  font-size: 12px;
}

/* Markdown */

.md {
  overflow-wrap: anywhere;
}

.md > :first-child {
  margin-top: 0;
}

.md > :last-child {
  margin-bottom: 0;
}

.md p {
  margin: 0 0 10px;
}

.md strong {
  font-weight: 600;
  color: var(--text);
}

.md em {
  font-style: italic;
}

.md ul,
.md ol {
  margin: 0 0 10px;
  padding-left: 22px;
}

.md li {
  margin: 2px 0;
}

.md h1,
.md h2,
.md h3,
.md h4 {
  margin: 14px 0 8px;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.5;
}

.md blockquote {
  margin: 10px 0;
  padding: 2px 0 2px 12px;
  border-left: 2px solid var(--border-strong);
  color: var(--text-dim);
}

.md hr {
  height: 0;
  margin: 16px 0;
  border: 0;
  border-top: 1px solid var(--border);
}

.md code {
  font-family: var(--mono);
  font-size: 13px;
  background: #0d0d0d;
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0 4px;
}

.md pre {
  position: relative;
  margin: 0;
  padding: 12px 14px;
  background: #0d0d0d;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.codeblock {
  position: relative;
  margin: 12px 0;
}

.md pre code {
  display: block;
  padding: 0;
  background: none;
  border: 0;
  border-radius: 0;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre;
}

/* Подсветка highlight.js в цветах темы. */
.hljs-comment,
.hljs-quote {
  color: var(--text-faint);
  font-style: italic;
}

.hljs-keyword,
.hljs-selector-tag,
.hljs-literal,
.hljs-built_in,
.hljs-type,
.hljs-name {
  color: var(--blue);
}

.hljs-string,
.hljs-attr,
.hljs-template-variable,
.hljs-selector-attr,
.hljs-selector-pseudo {
  color: var(--green);
}

.hljs-number,
.hljs-symbol,
.hljs-bullet,
.hljs-meta {
  color: var(--yellow);
}

.hljs-title,
.hljs-section,
.hljs-function .hljs-title,
.hljs-selector-id,
.hljs-selector-class {
  color: var(--blue);
}

.hljs-variable,
.hljs-params,
.hljs-property {
  color: var(--text);
}

.hljs-deletion {
  color: var(--red);
}

.hljs-addition {
  color: var(--green);
}

.hljs-emphasis {
  font-style: italic;
}

.hljs-strong {
  font-weight: 600;
}

.md table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 13px;
}

.md th,
.md td {
  border: 1px solid var(--border);
  padding: 5px 8px;
  text-align: left;
}

.md th {
  background: var(--bg-panel);
  font-weight: 600;
}

/* Кнопка копирования */

.code-copy {
  position: absolute;
  top: 6px;
  right: 6px;
  padding: 3px 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.6;
  cursor: pointer;
  opacity: 0;
  transition: opacity 80ms linear;
}

pre:hover .code-copy,
.code-copy:focus-visible {
  opacity: 1;
}

.code-copy:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
  color: var(--text);
}

@media (hover: none) {
  .code-copy {
    opacity: 1;
  }
}

/* Курсор стрима */

.msg-streaming .md::after {
  content: "▌";
  color: var(--accent);
  animation: blink 1s steps(1) infinite;
}

@keyframes blink {
  50% { opacity: 0; }
}

/* ─── Поле ввода ────────────────────────────────────────────── */

.composer {
  flex: 0 0 auto;
  border-top: 1px solid var(--border);
  background: var(--bg);
  padding-bottom: max(10px, env(safe-area-inset-bottom));
}

.composer-inner {
  max-width: 760px;
  margin: 0 auto;
  padding: 12px 24px 0;
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.composer-input {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 40px;
  max-height: 180px;
  padding: 9px 12px;
  overflow-y: auto;
}

.composer-input:disabled {
  opacity: 0.6;
}

.composer-meta {
  max-width: 760px;
  margin: 0 auto;
  padding: 6px 24px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 16px;
}

.composer-status {
  font-size: 11px;
  color: var(--text-faint);
  text-align: right;
}

/* ─── Тонкие скроллбары (WebKit) ────────────────────────────── */

::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 4px;
}

/* ─── Адаптив ───────────────────────────────────────────────── */

@media (max-width: 700px) {
  .topbar {
    padding: 0 16px;
    gap: 10px;
  }

  .feed {
    padding: 20px 16px;
  }

  .composer-inner {
    padding: 10px 16px 0;
  }

  .composer-meta {
    padding: 6px 16px 0;
  }
}

@media (max-width: 480px) {
  body {
    font-size: 13px;
  }

  .btn {
    padding: 7px 11px;
    min-height: 36px;
    font-size: 12px;
  }

  /* Вход */
  .view-login {
    padding: 16px;
    align-items: flex-start;
    padding-top: 15vh;
  }

  .login-card {
    width: 100%;
    padding: 22px 18px 18px;
  }

  /* Шапка: логотип и выход в первой строке, шаг — во второй */
  .topbar {
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "left right"
      "step step";
    height: auto;
    padding: 10px 16px 8px;
    row-gap: 4px;
  }

  .topbar-left { grid-area: left; }
  .topbar-right { grid-area: right; }
  .topbar-step {
    grid-area: step;
    justify-self: start;
    text-align: left;
  }

  .user {
    max-width: 96px;
    font-size: 11px;
  }

  /* Задание */
  .intake-main {
    padding: 24px 16px 40px;
  }

  .intake-title {
    font-size: 14px;
  }

  .intake-hint {
    margin-bottom: 16px;
  }

  .intake-textarea {
    min-height: 180px;
  }

  .intake-actions {
    flex-direction: row-reverse;
    justify-content: stretch;
  }

  .intake-actions .btn {
    flex: 1 1 auto;
  }

  .intake-actions .kbd-hint {
    display: none;
  }

  .intake-card {
    padding: 14px;
  }

  .card-actions {
    flex-wrap: wrap;
  }

  .card-actions .btn {
    flex: 1 1 100%;
  }

  .card-row {
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    padding-left: 0;
  }

  .card-row-label {
    flex: none;
  }

  /* Чат */
  .feed {
    padding: 16px;
  }

  .msg {
    margin-bottom: 18px;
  }

  .msg-user {
    padding-left: 10px;
  }

  .composer-inner {
    padding: 8px 12px 0;
    gap: 8px;
  }

  .composer-input {
    padding: 8px 10px;
  }

  .composer-meta {
    padding: 6px 12px 0;
  }

  .composer-meta .kbd-hint {
    font-size: 10px;
  }

  .md pre {
    padding: 10px 12px;
  }

  .codeblock {
    margin: 10px 0;
  }

  .md pre code {
    font-size: 12px;
  }

  .md code {
    font-size: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .progress-bar { transition: none; }
  .msg-streaming .md::after { animation: none; }
}

/* На тач-устройствах кнопка копирования видна всегда: освобождаем ей строку. */
@media (hover: none) {
  .md pre {
    padding-top: 34px;
  }
}
