:root {
  --ink: #1a1f26;
  --muted: #4f5d70;
  --panel: #222730;
  --panel-ink: #f7f9fc;
  --accent: #f3b24b;
  --accent-ink: #181818;
  --surface: #f2f4f8;
  --paper: #ffffff;
  --line: #d5dae2;
}

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

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

body {
  color: var(--ink);
  background: linear-gradient(150deg, #e9edf2, #f4f1ea 45%, #edf2fa);
  font-family: "Segoe UI", Tahoma, sans-serif;
  line-height: 1.45;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--panel);
  color: var(--panel-ink);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
  backdrop-filter: blur(4px);
}

.topbar__inner {
  max-width: 1320px;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.logo {
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  display: inline-block;
  background: url("icon.png") center/contain no-repeat;
  border-radius: 10px;
  transition: transform 0.2s ease, filter 0.2s ease;
}

.logo:hover {
  transform: translateY(-1px);
  filter: brightness(1.06);
}

.topbar__controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-link {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  transition: transform 0.2s ease, background 0.2s ease;
}

.nav-link--chat-toggle {
  cursor: pointer;
  padding: 0;
  appearance: none;
  -webkit-appearance: none;
}

.theme-doc-page .nav-link--chat-toggle {
  position: fixed;
  width: 1px;
  height: 1px;
  margin: -1px;
  border: 0;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  pointer-events: none;
}

.nav-link:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.15);
}

.nav-link.is-active {
  background: rgba(243, 178, 75, 0.2);
  border-color: rgba(243, 178, 75, 0.8);
  box-shadow: 0 0 0 2px rgba(243, 178, 75, 0.3);
}

.nav-link--chat-toggle[aria-expanded="true"] {
  background: rgba(243, 178, 75, 0.2);
  border-color: rgba(243, 178, 75, 0.8);
  box-shadow: 0 0 0 2px rgba(243, 178, 75, 0.3);
}

.nav-icon {
  width: 20px;
  height: 20px;
  display: block;
  background: var(--panel-ink);
  -webkit-mask: var(--nav-icon) center / contain no-repeat;
  mask: var(--nav-icon) center / contain no-repeat;
}

.nav-icon--doc {
  --nav-icon: url("icondoc.png");
}

.nav-icon--chat {
  --nav-icon: url("iconchat.png");
}

.doc-switch-label {
  font-size: 12px;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: rgba(247, 249, 252, 0.75);
}

.doc-switch {
  height: 38px;
  min-width: 220px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.08);
  color: var(--panel-ink);
  padding: 0 10px;
  font-size: 14px;
}

.doc-switch option {
  color: #111720;
}

.catalog-shell {
  max-width: 1240px;
  margin: 24px auto 60px;
  padding: 0 18px;
}

.catalog-hero {
  margin-bottom: 24px;
  padding: 24px;
  border-radius: 18px;
  border: 1px solid rgba(0, 0, 0, 0.08);
  background: linear-gradient(120deg, #f8fbff, #f3efe7);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.08);
}

.catalog-hero__eyebrow {
  margin: 0 0 8px;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  font-size: 12px;
  color: #5f6e82;
}

.catalog-hero h1 {
  margin: 0 0 10px;
  font-size: 32px;
}

.catalog-hero p {
  margin: 0;
  color: #445163;
  max-width: 620px;
}

.catalog-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.catalog-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.08);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.catalog-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.11);
}

.catalog-card__title {
  margin: 0 0 6px;
  font-size: 18px;
}

.catalog-card__file {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
  word-break: break-word;
}

.catalog-card__link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 34px;
  padding: 0 12px;
  border-radius: 10px;
  text-decoration: none;
  font-weight: 600;
  color: var(--accent-ink);
  background: var(--accent);
  transition: filter 0.2s ease;
}

.catalog-card__link:hover {
  filter: brightness(0.97);
}

.doc-layout {
  max-width: 1120px;
  margin: 22px auto 56px;
  padding: 0 18px;
}

.doc-shell {
  background: rgba(255, 255, 255, 0.84);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.08);
  overflow: hidden;
}

.doc-shell__head {
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(241, 245, 251, 0.75);
}

.doc-shell__head h1 {
  margin: 0 0 6px;
  font-size: 24px;
}

.doc-shell__file {
  margin: 0 0 6px;
  font-size: 13px;
  color: var(--muted);
}

.doc-shell__status {
  margin: 0;
  font-size: 13px;
  color: #38485f;
}

.doc-viewer {
  padding: 0;
  min-height: 320px;
  overflow: auto;
  background: #d7dbe2;
}

.doc-viewer--mobile-fit {
  overflow-x: hidden;
}

.doc-viewer .docx-wrapper {
  min-width: 100%;
  width: max-content;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  background: transparent !important;
  padding: 20px !important;
}

.doc-viewer .docx {
  margin: 0 !important;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.05), 0 16px 34px rgba(0, 0, 0, 0.18) !important;
  border: 1px solid #d0d0d0 !important;
}

.doc-viewer .docx,
.doc-viewer .docx * {
  text-rendering: geometricPrecision;
  font-kerning: normal;
}

.chat-backdrop {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(9, 15, 25, 0.5);
  backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.chat-shell {
  width: min(450px, calc(100vw - 32px));
  background: #111722;
  color: #eef3ff;
  border-radius: 16px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.18);
  padding: 16px;
  position: fixed;
  right: 16px;
  top: 74px;
  z-index: 90;
  max-height: calc(100vh - 92px);
  display: flex;
  flex-direction: column;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translate3d(0, -6px, 0) scale(0.99);
  transition: transform 0.2s ease, opacity 0.2s ease, visibility 0.2s step-end;
}

body.chat-open .chat-backdrop {
  opacity: 1;
  pointer-events: auto;
}

body.chat-open .chat-shell {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translate3d(0, 0, 0) scale(1);
  transition: transform 0.2s ease, opacity 0.2s ease, visibility 0s;
}

.chat-shell__head {
  position: relative;
  padding-right: 40px;
}

.chat-shell__head h2 {
  margin: 0;
  font-size: 20px;
}

.chat-shell__status {
  margin: 6px 0 0;
  font-size: 13px;
  color: rgba(237, 242, 255, 0.72);
}

.chat-close {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  background: rgba(255, 255, 255, 0.1);
  color: #edf3ff;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.chat-close:hover {
  background: rgba(255, 255, 255, 0.16);
}

.chat-close:focus-visible {
  outline: 2px solid rgba(243, 178, 75, 0.8);
  outline-offset: 2px;
}

.chat-window {
  margin-top: 14px;
  min-height: 240px;
  max-height: none;
  flex: 1 1 auto;
  overflow-y: auto;
  border-radius: 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.06);
  padding: 12px;
}

.chat-empty {
  text-align: center;
  padding: 32px 12px;
  color: rgba(237, 242, 255, 0.7);
}

.chat-empty__title {
  font-size: 20px;
  margin-bottom: 6px;
}

.chat-empty__text {
  font-size: 14px;
}

.chat-message {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  margin-bottom: 12px;
  align-items: start;
}

.chat-message--user {
  grid-template-columns: minmax(0, 1fr) auto;
}

.chat-message--user .chat-avatar {
  grid-column: 2;
  background: #f0b24a;
  color: #171717;
}

.chat-message--user .chat-bubble {
  grid-column: 1;
  background: rgba(240, 178, 74, 0.2);
  border-color: rgba(240, 178, 74, 0.28);
}

.chat-avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  background: rgba(255, 255, 255, 0.2);
}

.chat-bubble {
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.1);
  padding: 10px 12px;
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.chat-files {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chat-file-chip {
  font-size: 11px;
  border-radius: 999px;
  padding: 4px 8px;
  color: #f8f9ff;
  background: rgba(255, 255, 255, 0.15);
}

.chat-citations {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chat-citation {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 11px;
  text-decoration: none;
  color: #d8e6ff;
  background: rgba(81, 128, 208, 0.35);
}

.chat-citation:hover {
  background: rgba(81, 128, 208, 0.52);
}

.chat-typing {
  display: inline-flex;
  gap: 5px;
  margin-bottom: 8px;
  padding: 10px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
}

.chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #d9e4ff;
  animation: chat-pulse 1.1s infinite ease-in-out;
}

.chat-typing span:nth-child(2) {
  animation-delay: 0.15s;
}

.chat-typing span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes chat-pulse {
  0%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  50% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

.chat-tools {
  margin-top: 12px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.panel-button {
  border: none;
  border-radius: 10px;
  height: 38px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: var(--accent-ink);
  background: var(--accent);
  transition: transform 0.15s ease, filter 0.2s ease;
}

.panel-button:hover {
  filter: brightness(0.97);
}

.panel-button:active {
  transform: translateY(1px);
}

.panel-button.ghost {
  color: #edf1ff;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.chat-input {
  margin-top: 12px;
}

.chat-label {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: rgba(237, 242, 255, 0.76);
}

.chat-input__row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 78px 98px;
  gap: 8px;
}

#chat-input {
  width: 100%;
  min-height: 42px;
  max-height: 180px;
  resize: none;
  overflow-x: hidden;
  overflow-y: hidden;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(13, 17, 26, 0.75);
  color: #eef2ff;
  padding: 9px 10px;
  line-height: 1.35;
  font: inherit;
}

#chat-input::placeholder {
  color: rgba(238, 242, 255, 0.55);
}

.chat-send,
.chat-stop {
  border: none;
  border-radius: 10px;
  min-width: 0;
  min-height: 42px;
  padding: 0 14px;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.2s ease;
}

.chat-send {
  color: #151515;
  background: var(--accent);
}

.chat-stop {
  color: #f0f3ff;
  background: rgba(255, 255, 255, 0.14);
}

.chat-send:hover,
.chat-stop:hover {
  filter: brightness(0.96);
}

.chat-send:disabled,
.chat-stop:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}

.image-upload-row {
  margin-top: 10px;
}

.image-upload {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 10px;
  padding: 7px 10px;
  border: 1px dashed rgba(255, 255, 255, 0.3);
  font-size: 13px;
  cursor: pointer;
  color: rgba(237, 242, 255, 0.92);
  transition: background 0.2s ease, border-color 0.2s ease;
}

.image-upload:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.4);
}

.image-upload input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.image-list {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.image-chip {
  display: inline-grid;
  grid-template-columns: auto minmax(0, 140px) auto;
  align-items: center;
  gap: 8px;
  padding: 4px 6px 4px 4px;
  border-radius: 12px;
  font-size: 11px;
  background: rgba(255, 255, 255, 0.16);
  border: 1px solid rgba(255, 255, 255, 0.15);
}

.image-chip__thumb {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.image-chip__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-chip__remove {
  border: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  cursor: pointer;
  color: #0f1320;
  background: #f1f3f9;
}

.chat-hint {
  margin-top: 8px;
  color: rgba(237, 242, 255, 0.68);
  font-size: 12px;
}

.nav-link:focus-visible,
.doc-switch:focus-visible,
.panel-button:focus-visible,
.chat-send:focus-visible,
.chat-stop:focus-visible,
#chat-input:focus-visible,
.image-upload:focus-within {
  outline: 2px solid rgba(243, 178, 75, 0.7);
  outline-offset: 2px;
}

.chat-window::-webkit-scrollbar,
#chat-input::-webkit-scrollbar,
.doc-viewer::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

.chat-window::-webkit-scrollbar-track,
#chat-input::-webkit-scrollbar-track,
.doc-viewer::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.06);
  border-radius: 10px;
}

.chat-window::-webkit-scrollbar-thumb,
#chat-input::-webkit-scrollbar-thumb,
.doc-viewer::-webkit-scrollbar-thumb {
  background: rgba(243, 178, 75, 0.45);
  border-radius: 10px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

@media (max-width: 1024px) {
  .doc-layout {
    max-width: 100%;
    padding: 0 14px;
  }

  .doc-viewer .docx-wrapper {
    padding: 16px !important;
  }

  .chat-shell {
    width: min(430px, calc(100vw - 24px));
    right: 12px;
    top: 68px;
    max-height: calc(100vh - 80px);
  }
}

@media (max-width: 700px) {
  .topbar__inner {
    flex-wrap: wrap;
    justify-content: space-between;
    padding: 10px 14px;
  }

  .topbar__controls {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .doc-switch-label {
    width: 100%;
    margin-top: 2px;
  }

  .doc-switch {
    min-width: 100%;
  }

  .theme-doc-page .topbar__controls {
    width: 100%;
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr);
    gap: 8px;
    align-items: center;
  }

  .theme-doc-page .doc-switch {
    min-width: 0;
    width: 100%;
  }

  .doc-layout {
    margin: 14px auto 34px;
    padding: 0 10px;
  }

  .doc-shell {
    border-radius: 14px;
  }

  .doc-shell__head {
    padding: 14px 14px 10px;
  }

  .doc-shell__head h1 {
    font-size: 20px;
  }

  .doc-viewer {
    min-height: 260px;
    overflow-x: hidden;
  }

  .doc-viewer .docx-wrapper {
    min-width: 0;
    width: 100%;
    align-items: center;
    gap: 12px;
    padding: 10px !important;
  }

  .doc-viewer .docx {
    transform-origin: top center;
  }

  .chat-shell {
    left: 0;
    right: 0;
    top: 61px;
    width: 100vw;
    max-height: calc(100vh - 61px);
    height: calc(100vh - 61px);
    border-radius: 14px 14px 0 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
    padding: 14px;
  }

  .chat-window {
    min-height: 180px;
  }

  .chat-input__row {
    grid-template-columns: 1fr;
  }

  .chat-send,
  .chat-stop {
    width: 100%;
    min-height: 40px;
  }

  .chat-tools {
    grid-template-columns: 1fr;
  }
}
