:root {
  --blue-700: #0d4cd3;
  --blue-800: #073b9f;
  --ink-900: #151b28;
  --ink-700: #344054;
  --ink-500: #667085;
  --line: #d7deea;
  --line-strong: #b8c2d4;
  --surface: #ffffff;
  --page: #f3f6fb;
  --soft-blue: #edf4ff;
  --green-700: #177245;
  --green-100: #e8f7ef;
  --amber-700: #9a5b00;
  --amber-100: #fff3d7;
  --red-700: #b42318;
  --red-100: #ffe8e5;
  --shadow: 0 18px 42px rgba(31, 42, 68, 0.14);
  --radius: 8px;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--ink-900);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(243, 246, 251, 0.92)),
    repeating-linear-gradient(90deg, rgba(13, 76, 211, 0.045) 0 1px, transparent 1px 112px),
    var(--page);
  font-family:
    "Segoe UI",
    "Noto Sans",
    "Helvetica Neue",
    sans-serif;
  font-size: 16px;
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
}

.access-screen,
.chat-screen {
  min-height: 100vh;
  padding: 32px;
}

.access-screen {
  display: grid;
  place-items: center;
}

.access-panel {
  width: min(100%, 560px);
  padding: 32px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-row.compact {
  gap: 12px;
}

.brand-mark {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  color: #fff;
  background: var(--blue-700);
  border-radius: 6px;
  font-weight: 700;
}

.brand-kicker {
  margin: 0 0 4px;
  color: var(--ink-500);
  font-size: 0.85rem;
}

h1,
h2,
h3,
p {
  letter-spacing: 0;
}

h1 {
  margin: 0;
  font-size: 1.75rem;
  line-height: 1.2;
}

h2 {
  margin: 0;
  font-size: 1.1rem;
  line-height: 1.2;
}

.access-form {
  margin-top: 30px;
}

.access-form label {
  display: block;
  margin-bottom: 8px;
  color: var(--ink-700);
  font-weight: 600;
}

.access-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.access-control input,
.composer textarea {
  width: 100%;
  color: var(--ink-900);
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  outline: none;
}

.access-control input {
  min-height: 48px;
  padding: 0 14px;
}

.access-control input:focus,
.composer textarea:focus {
  border-color: var(--blue-700);
  box-shadow: 0 0 0 3px rgba(13, 76, 211, 0.14);
}

.access-control button {
  min-height: 48px;
  padding: 0 18px;
  color: #fff;
  background: var(--blue-700);
  border: 0;
  border-radius: 6px;
  font-weight: 700;
}

.access-control button:hover,
.icon-button.primary:hover {
  background: var(--blue-800);
}

.form-error {
  min-height: 22px;
  margin: 10px 0 0;
  color: var(--red-700);
  font-size: 0.92rem;
}

.is-hidden {
  display: none;
}

.chat-screen {
  display: grid;
  grid-template-rows: auto auto auto;
  gap: 22px;
  max-width: 1040px;
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 18px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.topbar .brand-mark {
  width: 40px;
  height: 40px;
  font-size: 0.9rem;
}

.template-link {
  color: var(--blue-700);
  text-decoration: none;
  font-weight: 700;
}

.template-link:hover {
  text-decoration: underline;
}

.chat-frame {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-height: 0;
  height: clamp(520px, calc(100vh - 180px), 680px);
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.algorithm-section {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(320px, 0.85fr);
  gap: 24px;
  padding: 28px 0 48px;
  border-top: 1px solid var(--line);
}

.algorithm-copy {
  display: grid;
  gap: 14px;
}

.algorithm-copy h2,
.technology-panel h3,
.algorithm-step h3 {
  margin: 0;
}

.algorithm-copy h2 {
  font-size: 1.45rem;
}

.algorithm-copy p {
  max-width: 760px;
  margin: 0;
  color: var(--ink-700);
  line-height: 1.62;
}

code {
  padding: 0.08em 0.28em;
  color: #103c91;
  background: #edf4ff;
  border: 1px solid #d8e7ff;
  border-radius: 4px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.92em;
  overflow-wrap: anywhere;
}

.algorithm-steps {
  display: grid;
  grid-column: 1 / -1;
  grid-row: 2;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.algorithm-step {
  min-width: 0;
  padding: 16px;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.algorithm-step:nth-child(2) {
  border-color: #c9ddd4;
}

.algorithm-step:nth-child(3) {
  border-color: #e7d5a9;
}

.step-number {
  display: inline-flex;
  margin-bottom: 14px;
  color: var(--ink-500);
  font-size: 0.78rem;
  font-weight: 800;
}

.algorithm-step h3 {
  font-size: 1rem;
}

.algorithm-step p {
  margin: 8px 0 0;
  color: var(--ink-700);
  line-height: 1.5;
}

.technology-panel {
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
  padding: 18px;
  align-self: start;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.technology-panel h3 {
  font-size: 1.05rem;
}

.technology-list {
  display: grid;
  gap: 12px;
  margin: 16px 0 0;
}

.technology-list div {
  min-width: 0;
}

.technology-list dt {
  color: var(--ink-500);
  font-size: 0.82rem;
  font-weight: 700;
}

.technology-list dd {
  margin: 4px 0 0;
  color: var(--ink-900);
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.page-footer {
  display: flex;
  justify-content: center;
  padding: 0 0 32px;
}

.page-footer a {
  color: var(--blue-700);
  text-decoration: none;
  font-weight: 700;
}

.page-footer a:hover {
  text-decoration: underline;
}

.messages {
  min-height: 0;
  padding: 22px;
  overflow-y: auto;
}

.message {
  display: flex;
  margin-bottom: 14px;
}

.message.user {
  justify-content: flex-end;
}

.bubble {
  width: fit-content;
  max-width: min(760px, 88%);
  padding: 12px 14px;
  border-radius: var(--radius);
  line-height: 1.45;
  white-space: pre-wrap;
}

.message.bot .bubble,
.message.system .bubble {
  background: var(--soft-blue);
  border: 1px solid #cfdef8;
}

.message.user .bubble {
  color: #fff;
  background: var(--blue-700);
}

.message.error .bubble {
  color: var(--red-700);
  background: var(--red-100);
  border-color: #ffc6bf;
}

.message.processing .bubble {
  color: var(--amber-700);
  background: var(--amber-100);
  border-color: #f3d18a;
}

.results-stack {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.result-card {
  width: min(760px, 100%);
  padding: 14px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.result-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.result-title {
  margin: 0 0 8px;
  font-weight: 700;
}

.result-code {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 4px 8px;
  color: var(--blue-700);
  background: var(--soft-blue);
  border-radius: 6px;
  font-weight: 700;
}

.result-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 10px;
  color: var(--ink-500);
  font-size: 0.88rem;
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #eef1f6;
}

.tag.ok {
  color: var(--green-700);
  background: var(--green-100);
}

.tag.warn {
  color: var(--amber-700);
  background: var(--amber-100);
}

.result-explanation {
  margin: 0;
  color: var(--ink-700);
}

details {
  margin-top: 10px;
}

summary {
  color: var(--blue-700);
  cursor: pointer;
  font-weight: 700;
}

.candidate-list {
  display: grid;
  gap: 6px;
  margin: 10px 0 0;
  padding: 0;
  list-style: none;
}

.candidate-list li {
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.csv-link {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 8px 12px;
  color: #fff;
  background: var(--green-700);
  border-radius: 6px;
  text-decoration: none;
  font-weight: 700;
}

.composer {
  display: grid;
  position: relative;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 14px;
  background: #f8fafd;
  border-top: 1px solid var(--line);
  transition:
    background-color 160ms ease,
    box-shadow 160ms ease;
}

.composer.is-drag-over {
  background: #eef5ff;
  box-shadow: inset 0 0 0 2px var(--blue-700);
}

.composer.is-drag-over::after {
  position: absolute;
  inset: 10px;
  display: grid;
  place-items: center;
  color: var(--blue-700);
  background: rgba(237, 244, 255, 0.9);
  border: 1px dashed var(--blue-700);
  border-radius: 6px;
  content: "Отпустите файл здесь";
  font-weight: 700;
  pointer-events: none;
}

.composer textarea {
  min-height: 64px;
  max-height: 180px;
  padding: 12px;
  resize: vertical;
}

.composer-actions {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

#file-input {
  display: none;
}

.icon-button {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  color: var(--blue-700);
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
}

.icon-button.primary {
  color: #fff;
  background: var(--blue-700);
  border-color: var(--blue-700);
}

.icon-button svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.file-preview {
  grid-column: 1 / -1;
  min-height: 20px;
  margin: -4px 0 0;
  color: var(--ink-500);
  font-size: 0.9rem;
}

@media (max-width: 720px) {
  .access-screen,
  .chat-screen {
    padding: 14px;
  }

  .access-panel {
    padding: 22px;
  }

  .access-control {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .chat-frame {
    height: clamp(420px, calc(100vh - 220px), 620px);
  }

  .messages {
    padding: 14px;
  }

  .composer {
    grid-template-columns: 1fr;
  }

  .composer-actions {
    justify-content: flex-end;
  }

  .bubble {
    max-width: 100%;
  }

  .algorithm-section {
    grid-template-columns: 1fr;
    padding-bottom: 28px;
  }

  .algorithm-steps {
    grid-row: auto;
    grid-template-columns: 1fr;
  }

  .technology-panel {
    grid-column: auto;
    grid-row: auto;
    padding: 16px;
  }
}
