:root {
  --primary-color: #9e1f1f;
  --primary-hover: #7e1919;
  --secondary-color: #1a1a1a;
  --bg: #121212;
  --surface: #1e1e1e;
  --border: rgba(158, 31, 31, 0.3);
  --text: #f0f0f0;
  --muted: #b0b0b0;
  --accent: #9e1f1f;
  --accent-hover: #7e1919;
  --brand: #9e1f1f;
  --brand-hover: #7e1919;
  --user-bg: #2a2222;
  --assistant-bg: #1a1a1a;
  --success: #3ecf8e;
  --error: #f07178;
  --bg-input: #2a2a2a;
  --shadow-color: rgba(0, 0, 0, 0.3);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Roboto", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  flex-shrink: 0;
  background: var(--bg);
}

.app-navbar {
  background: var(--secondary-color);
  box-shadow: 0 2px 8px var(--shadow-color);
}

.app-navbar-inner {
  max-width: 80%;
  margin: 0 auto;
  padding: 0.8rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.navbar-brand {
  color: #fff;
  text-decoration: none;
  font-weight: 600;
  font-size: 1.3rem;
  line-height: 1.3;
  font-family: "Roboto", sans-serif;
}

.brand-name-highlight {
  font-family: "Cormorant Garamond", serif;
  font-size: 1.5em;
  font-weight: 700;
  color: var(--primary-color);
  margin-left: 0.15rem;
}

.navbar-toggle {
  display: none;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 0.4rem 0.65rem;
  cursor: pointer;
}

.navbar-nav {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.navbar-nav .nav-link {
  display: inline-block;
  margin: 0;
  padding: 0.5rem 1rem;
  color: rgba(255, 255, 255, 0.8);
  text-decoration: none;
  border-radius: 4px;
  font-size: 0.95rem;
  font-weight: 400;
  font-family: "Roboto", sans-serif;
  transition: all 0.2s;
}

.navbar-nav .nav-link:hover {
  color: #fff;
  background: rgba(158, 31, 31, 0.2);
}

.navbar-nav .nav-link.active {
  color: #fff;
  background: var(--primary-color);
}

.info-shell {
  max-width: 80%;
  margin: 0 auto;
  padding: 1rem 1rem 1.25rem;
}

.info-card {
  background: var(--surface);
  border: none;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 4px 12px var(--shadow-color);
}

.info-card.inner {
  background: var(--secondary-color);
  box-shadow: none;
  border: 1px solid var(--border);
}

.info-card-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  background: var(--secondary-color);
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  font: inherit;
  white-space: normal;
  height: auto;
}

.info-card > .info-card-header {
  border-bottom: 2px solid var(--border);
}

.info-card.inner > .info-card-header {
  background: transparent;
  border-bottom: 1px solid transparent;
}

.info-card-header:hover {
  background: rgba(158, 31, 31, 0.12);
}

.info-card-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--primary-color);
  font-family: "Roboto", sans-serif;
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.info-card-title i {
  color: #e7b416;
}

.info-chevron {
  color: #fff;
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.info-card-header[aria-expanded="true"] .info-chevron {
  transform: rotate(180deg);
}

.info-card-body {
  overflow: hidden;
}

.info-card-body.collapsed {
  display: none;
}

.info-card-content {
  padding: 1.25rem 1.35rem 1.4rem;
  color: var(--text);
  font-size: 0.95rem;
  line-height: 1.55;
  background: var(--surface);
}

.info-card.inner .info-card-content {
  background: var(--secondary-color);
}

.info-card-content p {
  margin: 0 0 0.85rem;
}

.info-card-content h4 {
  margin: 1rem 0 0.55rem;
  color: var(--primary-color);
  font-size: 0.98rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.info-card-content h4 i {
  color: #e7b416;
}

.info-card-content ul,
.info-card-content ol {
  margin: 0 0 0.75rem;
  padding-left: 1.25rem;
}

.info-card-content li {
  margin-bottom: 0.45rem;
}

.info-card-content hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1rem 0;
}

.info-inner-stack {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1rem 1.1rem 1.15rem;
  background: var(--bg);
}

.info-columns {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}

.info-alert {
  margin-top: 0.85rem;
  padding: 0.75rem 0.9rem;
  border-radius: 8px;
  background: rgba(158, 31, 31, 0.12);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 0.9rem;
}

.info-alert i {
  color: #e7b416;
  margin-right: 0.35rem;
}

.layout {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  padding-top: 0.25rem;
}

.chat {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  height: auto;
}

.docs-offcanvas {
  position: fixed;
  top: 0;
  right: 0;
  width: min(420px, 100vw);
  height: 100vh;
  z-index: 1100;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -8px 0 24px var(--shadow-color);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.28s ease;
}

.docs-offcanvas.open {
  transform: translateX(0);
}

.offcanvas-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1090;
  background: rgba(0, 0, 0, 0.55);
}

.offcanvas-backdrop.hidden {
  display: none;
}

.offcanvas-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1.15rem;
  border-bottom: 2px solid var(--border);
  background: var(--secondary-color);
  flex-shrink: 0;
}

.offcanvas-title {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 500;
  color: var(--primary-color);
  font-family: "Roboto", sans-serif;
}

.offcanvas-close {
  font-size: 1.4rem;
  line-height: 1;
  padding: 0.15rem 0.45rem;
}

.offcanvas-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.15rem;
  min-height: 0;
}

.offcanvas-body .subtitle {
  margin: 0 0 1.15rem;
}

.chat-shell {
  width: 100%;
  max-width: 80%;
  margin: 0 auto;
  padding: 0 1rem 1.25rem;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.chat-card {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-radius: 8px;
  box-shadow: 0 4px 12px var(--shadow-color);
  overflow: hidden;
}

.chat-card-header {
  padding: 1rem 1.25rem;
  background: var(--secondary-color);
  border-bottom: 2px solid var(--border);
  flex-shrink: 0;
}

.chat-card-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--primary-color);
  font-family: "Roboto", sans-serif;
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.chat-card-title i {
  color: #e7b416;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.55rem 1rem;
  border: none;
  border-radius: 6px;
  background: var(--primary-color);
  color: #fff;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  height: auto;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.subtitle {
  margin: 0 0 1.5rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.panel {
  margin-bottom: 1.25rem;
}

.panel h2 {
  margin: 0 0 0.75rem;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

label {
  display: block;
  margin-bottom: 0.6rem;
  font-size: 0.85rem;
  color: var(--muted);
}

input[type="number"],
input[type="text"],
textarea {
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-input);
  color: var(--text);
  font: inherit;
}

textarea { resize: vertical; }

.file-label input { display: none; }

.file-label span {
  display: block;
  padding: 0.65rem;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.15s;
}

.file-label span:hover { border-color: var(--accent); }

.file-label.disabled {
  pointer-events: none;
  opacity: 0.55;
}

.file-label.disabled span {
  cursor: not-allowed;
}

.status {
  margin-top: 0.75rem;
  font-size: 0.85rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 1.25rem;
}

#uploadHint.status {
  display: block;
  min-height: 0;
}

.status.error { color: var(--error); }
.status.ok { color: var(--success); }
.status.busy { color: var(--text); }

.spinner {
  width: 0.85rem;
  height: 0.85rem;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  flex-shrink: 0;
  animation: spin 0.7s linear infinite;
}

.spinner.hidden { display: none; }

@keyframes spin {
  to { transform: rotate(360deg); }
}

.progress { margin-top: 0.75rem; }
.progress.hidden { display: none; }

.progress-bar {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 0.4rem;
}

#progressFill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: 4px;
  transition: width 0.3s ease;
}

.progress-bar.indeterminate #progressFill {
  width: 35%;
  transition: none;
  animation: progress-indeterminate 1.1s ease-in-out infinite;
}

@keyframes progress-indeterminate {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(320%); }
}

#progressText { font-size: 0.8rem; color: var(--muted); }

details {
  margin-top: 0.75rem;
  font-size: 0.85rem;
}

details summary {
  cursor: pointer;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

#ocrResultBlock.hidden { display: none; }

#ocrResult {
  max-height: 200px;
  overflow: auto;
  font-size: 0.75rem;
  white-space: pre-wrap;
  background: var(--bg);
  padding: 0.5rem;
  border-radius: 6px;
}

.page-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.75rem;
}

.page-preview.hidden { display: none; }

.page-preview img {
  width: 56px;
  height: 72px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.page-preview img.viewing {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
}

.page-preview img.attached {
  border-color: var(--success);
  box-shadow: 0 0 0 2px rgba(62, 207, 142, 0.35);
}

.api-status {
  margin-top: 1rem;
  padding: 0.5rem;
  border-radius: 6px;
  font-size: 0.8rem;
  background: var(--bg);
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.msg {
  max-width: 80%;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  line-height: 1.5;
}

.msg.user .msg-body {
  white-space: pre-wrap;
}

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

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

.msg-body h1,
.msg-body h2,
.msg-body h3,
.msg-body h4 {
  color: var(--accent);
  margin: 1rem 0 0.75rem;
  font-weight: 600;
}

.msg-body p,
.msg-body ul,
.msg-body ol {
  margin-bottom: 0.45rem;
}

.msg-body table {
  width: 100%;
  margin: 1rem 0;
  border-collapse: collapse;
  background-color: rgba(255, 255, 255, 0.03);
}

.msg-body th,
.msg-body td {
  border: 1px solid var(--border);
  padding: 0.55rem 0.7rem;
  vertical-align: top;
  text-align: left;
}

.msg-body th {
  color: var(--accent);
  background-color: rgba(158, 31, 31, 0.14);
  font-weight: 600;
}

.msg-body strong {
  color: #ffffff;
}

.msg-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1rem 0;
}

.msg.user {
  align-self: flex-end;
  background: var(--user-bg);
}

.msg.assistant {
  align-self: flex-start;
  background: var(--assistant-bg);
  border: 1px solid var(--border);
}

.answer-loading {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--muted);
  font-size: 0.9rem;
}

.answer-loading .spinner {
  width: 0.9rem;
  height: 0.9rem;
}

.msg .role {
  font-size: 0.7rem;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.msg-attach {
  font-size: 0.75rem;
  color: var(--success);
  margin-bottom: 0.35rem;
}

.chat-form {
  display: block;
  padding: 1rem 1.25rem 1.15rem;
  border-top: 1px solid var(--border);
  background: var(--secondary-color);
}

.chat-form-main {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-width: 0;
}

.chat-actions {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 0.75rem;
}

.chat-actions > #sendBtn {
  justify-self: start;
}

.chat-actions > .llm-mode-group {
  justify-self: center;
}

.chat-actions > #docsPanelOpen {
  justify-self: end;
}

/* Как Bootstrap input-group в norms_api */
.input-group {
  display: inline-flex;
  flex-wrap: nowrap;
  align-items: stretch;
  width: auto;
  vertical-align: middle;
}

.input-group > .input-group-text,
.input-group > .form-select {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  height: 2.75rem;
  padding: 0.5rem 0.85rem;
  font-size: 0.95rem;
  line-height: 1.25;
  text-align: center;
  border: 1px solid var(--border);
  background-color: var(--bg-input);
}

.input-group > .input-group-text {
  white-space: nowrap;
  color: var(--muted);
  border-right-width: 0;
  border-radius: 6px 0 0 6px;
  min-width: 5.5rem;
}

.input-group > .form-select {
  appearance: none;
  -webkit-appearance: none;
  color: var(--text);
  cursor: pointer;
  min-width: 9.5rem;
  border-radius: 0 6px 6px 0;
  border-left-width: 1px;
  padding-left: 2rem;
  padding-right: 2rem;
  text-align: center;
  text-align-last: center;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23ffffff' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 0.65rem center;
  background-size: 12px 10px;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.input-group > .form-select:focus {
  outline: none;
  z-index: 1;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 0.2rem rgba(158, 31, 31, 0.25);
}

.input-group > .form-select.context-options-label {
  color: #fff;
  font-weight: 500;
}

.context-options-label {
  color: var(--primary-color);
  font-weight: 500;
}

.llm-mode-group {
  grid-column: 2;
}

.attach-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
}

.attach-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.attach-toggle input {
  width: auto;
  margin: 0;
}

.attach-page-input {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.attach-page-input input {
  width: 4.5rem;
  margin: 0;
}

.attach-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  font-size: 0.78rem;
  color: var(--success);
  background: rgba(62, 207, 142, 0.1);
  border: 1px solid rgba(62, 207, 142, 0.25);
}

.attach-chip button {
  padding: 0;
  width: 1.1rem;
  height: 1.1rem;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1;
}

.attach-chip button:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.attach-limit-hint {
  font-size: 0.75rem;
  color: var(--muted);
}

.attach-badge {
  font-size: 0.8rem;
  color: var(--success);
  padding: 0.35rem 0.5rem;
  background: rgba(62, 207, 142, 0.1);
  border-radius: 6px;
  border: 1px solid rgba(62, 207, 142, 0.25);
}

.attach-badge.hidden,
.attach-page-input.hidden,
.hidden {
  display: none !important;
}

.btn-ghost {
  padding: 0.2rem 0.55rem;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  font-size: 1rem;
  line-height: 1;
}

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

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.lightbox.hidden {
  display: none;
}

.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
}

.lightbox-panel {
  position: relative;
  z-index: 1;
  width: min(900px, 100%);
  max-height: calc(100vh - 2rem);
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.lightbox-header,
.lightbox-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}

.lightbox-footer {
  border-bottom: none;
  border-top: 1px solid var(--border);
  justify-content: flex-end;
}

.lightbox-body {
  overflow: auto;
  padding: 1rem;
  text-align: center;
  background: var(--bg);
}

.lightbox-body img {
  max-width: 100%;
  max-height: calc(100vh - 12rem);
  border-radius: 6px;
  border: 1px solid var(--border);
}

.chat-form textarea {
  flex: 1;
  margin: 0;
  width: 100%;
}

button {
  padding: 0 1.25rem;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
}

button:hover { background: var(--accent-hover); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

#sendBtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  min-width: 7.5rem;
  height: 2.75rem;
  padding-top: 0;
  padding-bottom: 0;
  box-sizing: border-box;
}

#sendBtn .spinner {
  width: 0.85rem;
  height: 0.85rem;
  border-color: rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
}

@media (max-width: 900px) {
  .info-columns {
    grid-template-columns: 1fr;
  }

  .app-navbar-inner,
  .info-shell,
  .chat-shell {
    max-width: 100%;
  }
}

@media (max-width: 800px) {
  .chat { min-height: 50vh; }
  .docs-offcanvas { width: 100vw; }

  .navbar-toggle { display: inline-flex; }
  .navbar-nav {
    display: none;
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }
  .navbar-nav.open { display: flex; }
  .navbar-nav .nav-link { width: 100%; }
}
