:root {
  color-scheme: light;
  font-family: "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  background: #f4f6f8;
  color: #18202f;
  --panel: #ffffff;
  --line: #d9e0ea;
  --line-soft: #edf1f6;
  --muted: #657287;
  --text: #18202f;
  --primary: #1769d1;
  --primary-strong: #0c56b4;
  --success: #14723d;
  --warning: #8a520e;
  --danger: #a12b2b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
}

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

button,
select,
input {
  min-height: 38px;
}

button {
  border: 1px solid #b9c4d4;
  background: #fff;
  border-radius: 6px;
  padding: 8px 12px;
  cursor: pointer;
  color: var(--text);
}

button:hover {
  border-color: #8fa2bd;
  background: #f8fafc;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

button.primary,
#askButton {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 700;
}

#askButton:hover {
  background: var(--primary-strong);
  border-color: var(--primary-strong);
}

a {
  color: var(--primary);
}

.login-gate {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 18px;
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(255, 231, 235, 0.94), rgba(225, 250, 244, 0.94) 48%, rgba(232, 242, 255, 0.96)),
    #f8fbff;
}

.login-gate[hidden],
.app-locked {
  display: none;
}

.login-card {
  position: relative;
  width: min(100%, 430px);
  padding: 30px;
  border: 1px solid rgba(244, 158, 174, 0.46);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 22px 60px rgba(65, 83, 118, 0.18);
  text-align: center;
  transform-origin: center;
}

.login-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  margin-bottom: 14px;
  padding: 5px 12px;
  border: 1px solid #bae6da;
  border-radius: 999px;
  background: #ecfff9;
  color: #1e7569;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
}

.login-card h1 {
  margin: 0 0 10px;
  color: #26324a;
  font-size: 28px;
}

.login-question {
  margin: 0 0 18px;
  color: #5b6579;
  font-weight: 700;
  line-height: 1.55;
}

.login-label {
  margin-bottom: 8px;
  text-align: left;
  color: #46526a;
}

#loginAnswer {
  width: 100%;
  border: 1px solid #e7aeb9;
  border-radius: 8px;
  padding: 12px 13px;
  background: #fff;
  color: var(--text);
  line-height: 1.35;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

#loginAnswer:focus {
  outline: 3px solid rgba(244, 158, 174, 0.26);
  border-color: #e77891;
}

.login-button {
  width: 100%;
  margin-top: 14px;
  border-color: #ff879e;
  background: #ff8fa4;
  color: #fff;
  font-weight: 800;
  box-shadow: 0 9px 18px rgba(255, 143, 164, 0.28);
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.login-button:hover {
  border-color: #ff7994;
  background: #ff7994;
  box-shadow: 0 12px 22px rgba(255, 121, 148, 0.32);
  transform: translateY(-1px);
}

.login-button:active {
  transform: translateY(1px) scale(0.99);
}

.login-feedback {
  min-height: 24px;
  margin: 14px 0 0;
  color: #6a7488;
  font-weight: 800;
  line-height: 1.45;
}

.login-success-text,
.login-error-text {
  display: none;
}

.login-feedback.is-success {
  color: #19805a;
}

.login-feedback.is-error {
  color: #b33350;
}

.login-sparkle {
  position: absolute;
  width: 18px;
  height: 18px;
  border: 3px solid rgba(255, 180, 76, 0.72);
  transform: rotate(45deg);
  animation: sparkle-drift 4.8s ease-in-out infinite;
}

.sparkle-one {
  top: 18%;
  left: 18%;
}

.sparkle-two {
  right: 17%;
  bottom: 24%;
  border-color: rgba(92, 190, 178, 0.72);
  animation-delay: 0.9s;
}

.sparkle-three {
  right: 24%;
  top: 21%;
  border-color: rgba(127, 159, 237, 0.7);
  animation-delay: 1.8s;
}

.login-denied .login-card {
  animation: login-shake 320ms ease;
}

.login-approved .login-card {
  animation: login-glow 760ms ease forwards;
}

@keyframes sparkle-drift {
  0%,
  100% {
    transform: translateY(0) rotate(45deg) scale(1);
  }
  50% {
    transform: translateY(-12px) rotate(45deg) scale(1.12);
  }
}

@keyframes login-shake {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(-8px);
  }
  50% {
    transform: translateX(7px);
  }
  75% {
    transform: translateX(-4px);
  }
}

@keyframes login-glow {
  0% {
    transform: translateY(0) scale(1);
    box-shadow: 0 22px 60px rgba(65, 83, 118, 0.18);
  }
  100% {
    transform: translateY(-4px) scale(1.02);
    box-shadow: 0 28px 70px rgba(51, 162, 125, 0.28);
  }
}

.shell {
  max-width: 1320px;
  margin: 0 auto;
  padding: 20px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 18px 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
}

h1 {
  margin: 0 0 6px;
  font-size: 23px;
  line-height: 1.25;
}

h2 {
  margin: 0 0 10px;
  font-size: 16px;
  line-height: 1.35;
}

#statusLine {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.actions,
.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

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

.workspace {
  display: grid;
  grid-template-columns: minmax(320px, 0.82fr) minmax(420px, 1.18fr);
  grid-template-areas:
    "question answer"
    "sources answer";
  gap: 16px;
  margin-top: 16px;
  align-items: start;
}

.panel,
.docs-shell {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
}

.panel {
  padding: 16px;
}

.question-panel {
  grid-area: question;
}

.answer-panel {
  grid-area: answer;
}

.sources-panel {
  grid-area: sources;
}

label {
  display: block;
  color: #303b4f;
  font-weight: 700;
}

textarea {
  width: 100%;
  min-height: 178px;
  margin: 8px 0 12px;
  resize: vertical;
  border: 1px solid #c6d0df;
  border-radius: 7px;
  padding: 12px;
  background: #fff;
  color: var(--text);
  line-height: 1.55;
}

textarea:focus,
select:focus,
button:focus-visible {
  outline: 2px solid rgba(23, 105, 209, 0.24);
  outline-offset: 2px;
}

select {
  border: 1px solid #c6d0df;
  border-radius: 6px;
  background: #fff;
  padding: 7px 9px;
}

.toggle {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  font-weight: 600;
  color: #354258;
}

.answer,
.sources,
.docs {
  min-width: 0;
}

.answer {
  min-height: 560px;
  white-space: pre-wrap;
  line-height: 1.72;
  font-size: 15px;
  color: #172033;
}

.answer.empty,
.sources.empty {
  display: flex;
  align-items: center;
}

.sources {
  line-height: 1.55;
}

.source-item,
.doc-item {
  padding: 11px 0;
  border-bottom: 1px solid var(--line-soft);
}

.source-item:last-child,
.doc-item:last-child {
  border-bottom: 0;
}

.source-item strong,
.doc-item strong {
  display: inline-block;
  margin-bottom: 4px;
  line-height: 1.4;
}

.meta {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.confidence {
  margin-bottom: 8px;
  border-radius: 6px;
  padding: 8px 10px;
  background: #eef5ff;
  color: #17457e;
  font-weight: 700;
}

.confidence.low {
  background: #fff4e6;
  color: var(--warning);
}

.confidence.medium {
  background: #f3f6fb;
  color: #4f5f77;
}

.confidence.high {
  background: #eaf8ef;
  color: var(--success);
}

.empty {
  color: #768297;
}

.ok {
  color: var(--success);
  font-weight: 700;
}

.bad {
  color: var(--danger);
  font-weight: 700;
}

.docs-panel {
  margin-top: 16px;
}

.docs-shell {
  overflow: hidden;
}

.docs-shell summary {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 14px 16px;
  cursor: pointer;
  font-weight: 700;
}

.docs-shell summary::-webkit-details-marker {
  display: none;
}

.docs-shell summary::before {
  content: "+";
  display: inline-grid;
  place-items: center;
  width: 20px;
  height: 20px;
  flex: 0 0 auto;
  border: 1px solid #b9c4d4;
  border-radius: 50%;
  color: var(--primary);
  font-weight: 700;
}

.docs-shell[open] summary::before {
  content: "-";
}

#docsSummary {
  margin-left: auto;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  text-align: right;
}

.docs {
  max-height: 440px;
  overflow: auto;
  border-top: 1px solid var(--line-soft);
  padding: 4px 16px 10px;
}

@media (max-width: 920px) {
  .shell {
    padding: 12px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
    padding: 14px;
  }

  .actions,
  .controls {
    align-items: stretch;
  }

  .actions button,
  .controls button,
  .controls select {
    flex: 1 1 132px;
  }

  .workspace {
    grid-template-columns: 1fr;
    grid-template-areas:
      "question"
      "answer"
      "sources";
    gap: 12px;
  }

  .panel {
    padding: 14px;
  }

  h1 {
    font-size: 21px;
  }

  .answer {
    min-height: 320px;
  }

  .docs-shell summary {
    align-items: flex-start;
  }
}

@media (max-width: 560px) {
  .shell {
    padding: 10px;
  }

  .topbar,
  .panel,
  .docs-shell {
    border-radius: 7px;
  }

  .actions,
  .controls {
    gap: 8px;
  }

  .toggle {
    width: 100%;
  }

  textarea {
    min-height: 150px;
  }

  .answer {
    min-height: 280px;
    font-size: 14px;
  }

  .docs-shell summary {
    flex-wrap: wrap;
  }

  #docsSummary {
    width: 100%;
    margin-left: 32px;
    text-align: left;
  }
}
