:root {
  --bg: #0a0a0a;
  --bg-elevated: #141414;
  --bg-hover: #1a1a1a;
  --border: #262626;
  --border-strong: #333;
  --text: #f5f5f5;
  --text-muted: #a3a3a3;
  --text-dim: #737373;
  --accent: #fafafa;
  --accent-fg: #0a0a0a;
  --da: #22c55e;
  --ne: #ef4444;
  --delno: #f59e0b;
  --mogoce: #38bdf8;
  --info: #a78bfa;
  --no: #a3a3a3;
  --radius: 16px;
  --font: "Inter", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
}

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

.app {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100%;
}

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

.login-gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  position: relative;
  z-index: 50;
  background:
    radial-gradient(ellipse 80% 50% at 50% -20%, #262626 0%, transparent 55%),
    var(--bg);
}

.login-card {
  width: min(400px, 100%);
  border: 1px solid var(--border-strong);
  background: #111;
  border-radius: 20px;
  padding: 1.5rem 1.35rem 1.35rem;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.login-brand strong {
  display: block;
  font-size: 1.05rem;
}

.login-brand p {
  margin: 0.15rem 0 0;
  color: var(--text-dim);
  font-size: 0.82rem;
}

.login-label {
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-top: 0.35rem;
}

.login-input {
  border: 1px solid var(--border-strong);
  background: #1a1a1a;
  border-radius: 12px;
  padding: 0.75rem 0.9rem;
  outline: none;
  color: #f5f5f5;
  caret-color: #f5f5f5;
  font: inherit;
  width: 100%;
  box-sizing: border-box;
  -webkit-text-fill-color: #f5f5f5;
}

.login-input::placeholder {
  color: #737373;
  -webkit-text-fill-color: #737373;
  opacity: 1;
}

.login-input:focus {
  border-color: #a3a3a3;
  background: #222;
}

/* Chrome/Safari autofill paints a yellow box and can hide typed text */
.login-input:-webkit-autofill,
.login-input:-webkit-autofill:hover,
.login-input:-webkit-autofill:focus {
  -webkit-text-fill-color: #f5f5f5;
  caret-color: #f5f5f5;
  box-shadow: 0 0 0 1000px #1a1a1a inset;
  transition: background-color 99999s ease-out;
}

.login-error {
  margin: 0.35rem 0 0;
  color: #fca5a5;
  font-size: 0.85rem;
}

.login-submit {
  margin-top: 0.75rem;
  border: 0;
  border-radius: 999px;
  padding: 0.75rem 1rem;
  background: #fafafa;
  color: #0a0a0a;
  font-weight: 600;
  cursor: pointer;
}

.login-submit:hover {
  background: #e5e5e5;
}

.login-submit:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 1.25rem 1rem;
  border-right: 1px solid var(--border);
  background: #080808;
}

.brand {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  padding: 0.25rem 0.35rem 0.75rem;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-weight: 700;
  background: linear-gradient(145deg, #fff 0%, #c4c4c4 100%);
  color: #111;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.brand-text strong {
  font-size: 0.95rem;
}

.brand-text span {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.btn {
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  border-radius: 999px;
  padding: 0.65rem 1rem;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

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

.btn.ghost {
  width: 100%;
  text-align: left;
  font-weight: 500;
}

.btn.subtle {
  width: 100%;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.sidebar-meta {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-elevated);
}

.meta-row {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.78rem;
  color: var(--text-dim);
}

.meta-row span:last-child {
  color: var(--text-muted);
  text-align: right;
  max-width: 55%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.hint {
  margin: 0;
  font-size: 0.72rem;
  line-height: 1.4;
  color: var(--text-dim);
  padding: 0 0.25rem;
}

.sidebar-footer {
  margin-top: auto;
  font-size: 0.72rem;
  color: var(--text-dim);
  line-height: 1.45;
  padding: 0.5rem 0.25rem;
}

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100vh;
}

.topbar {
  display: flex;
  justify-content: flex-end;
  padding: 0.85rem 1.25rem;
}

.lang-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  background: var(--bg-elevated);
}

.lang-btn {
  border: 0;
  background: transparent;
  padding: 0.4rem 0.85rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-dim);
  cursor: pointer;
}

.lang-btn.active {
  background: #fff;
  color: #0a0a0a;
}

.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: min(1040px, 100%);
  margin: 0 auto;
  padding: 0 1.25rem 1rem;
}

.hero {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 2rem 0 4rem;
  gap: 0.85rem;
}

.hero h1 {
  margin: 0;
  font-size: clamp(1.75rem, 4vw, 2.4rem);
  font-weight: 600;
  letter-spacing: -0.03em;
}

.hero-sub {
  margin: 0;
  max-width: 34rem;
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1.5;
}

.examples {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  margin-top: 1rem;
  max-width: 40rem;
}

.chip {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  border-radius: 999px;
  padding: 0.55rem 0.9rem;
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
  text-align: left;
  line-height: 1.35;
}

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

.thread {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  padding: 1rem 0 2rem;
  width: 100%;
}

.msg {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.msg.user .bubble {
  align-self: flex-end;
  background: #1f1f1f;
  border: 1px solid var(--border);
  border-radius: 18px 18px 6px 18px;
  padding: 0.85rem 1rem;
  max-width: 90%;
  white-space: pre-wrap;
  line-height: 1.5;
}

.msg.assistant .card {
  align-self: stretch;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, #121212 0%, #0d0d0d 100%);
  border-radius: var(--radius);
  padding: 1.1rem 1.15rem 1.15rem;
}

.verdict-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.85rem;
}

.verdict-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 4.5rem;
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  border: 1px solid transparent;
}

.verdict-badge.da {
  color: #052e16;
  background: var(--da);
}

.verdict-badge.ne {
  color: #450a0a;
  background: var(--ne);
}

.verdict-badge.delno {
  color: #451a03;
  background: var(--delno);
}

.verdict-badge.mogoce {
  color: #0c4a6e;
  background: var(--mogoce);
}

.verdict-badge.info {
  color: #2e1065;
  background: var(--info);
}

.verdict-badge.no_answer {
  color: #171717;
  background: var(--no);
}

.verdict-label {
  color: var(--text-dim);
  font-size: 0.8rem;
}

.explanation {
  margin: 0;
  line-height: 1.6;
  font-size: 0.98rem;
  white-space: pre-wrap;
}

.section-title {
  margin: 1rem 0 0.4rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.conditions,
.missing {
  margin: 0;
  padding-left: 1.15rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.conditions li,
.missing li {
  margin: 0.25rem 0;
}

.sources {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.source-btn {
  display: block;
  width: 100%;
  text-align: left;
  color: #e5e5e5;
  font-size: 0.88rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.55rem 0.75rem;
  background: #101010;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.source-btn:hover {
  border-color: #525252;
  background: #161616;
}

.source-btn small {
  display: block;
  color: var(--text-dim);
  font-size: 0.72rem;
  margin-top: 0.15rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Source excerpt modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  animation: fadeIn 0.15s ease;
}

.modal-backdrop[hidden] {
  display: none;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  width: min(720px, 100%);
  max-height: min(85vh, 900px);
  display: flex;
  flex-direction: column;
  background: #121212;
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.15rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

.modal-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.35;
}

.modal-heading {
  margin: 0.35rem 0 0;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.modal-close {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.15rem 0.4rem;
  border-radius: 8px;
}

.modal-close:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.modal-body {
  padding: 1rem 1.15rem;
  overflow-y: auto;
  flex: 1;
}

.modal-excerpt {
  margin: 0;
  padding: 0.9rem 1rem;
  border-left: 3px solid #525252;
  background: #0c0c0c;
  border-radius: 0 12px 12px 0;
  color: var(--text-muted);
  font-size: 0.92rem;
  line-height: 1.6;
  white-space: pre-wrap;
}

.modal-link-wrap {
  margin-top: 1rem;
}

.modal-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: #e5e5e5;
  font-size: 0.88rem;
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.5rem 0.9rem;
  background: #1a1a1a;
}

.modal-link:hover {
  border-color: #737373;
  background: #222;
}

.modal-footer {
  padding: 0.85rem 1.15rem 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.72rem;
  line-height: 1.45;
  color: var(--text-dim);
}

.meta-foot {
  margin-top: 0.9rem;
  font-size: 0.72rem;
  color: var(--text-dim);
}

.loading {
  color: var(--text-muted);
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.dots::after {
  content: "";
  animation: dots 1.2s steps(4, end) infinite;
}

@keyframes dots {
  0% { content: ""; }
  25% { content: "."; }
  50% { content: ".."; }
  75% { content: "..."; }
  100% { content: ""; }
}

.composer-wrap {
  width: min(1040px, 100%);
  margin: 0 auto;
  padding: 0 1.25rem 1.25rem;
  position: sticky;
  bottom: 0;
  background: linear-gradient(180deg, transparent 0%, var(--bg) 28%);
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  border: 1px solid var(--border-strong);
  background: #111;
  border-radius: 28px;
  padding: 0.55rem 0.55rem 0.55rem 1.1rem;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.02), 0 12px 40px rgba(0, 0, 0, 0.45);
}

.composer:focus-within {
  border-color: #525252;
}

.composer textarea {
  flex: 1;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  max-height: 160px;
  min-height: 24px;
  line-height: 1.45;
  padding: 0.55rem 0;
}

.composer textarea::placeholder {
  color: var(--text-dim);
}

.send {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 999px;
  background: #fafafa;
  color: #0a0a0a;
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.15s ease, transform 0.1s ease;
}

.send:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.send:not(:disabled):hover {
  transform: scale(1.04);
}

.composer-note {
  text-align: center;
  margin: 0.55rem 0 0;
  font-size: 0.72rem;
  color: var(--text-dim);
}

.error-banner {
  border: 1px solid #7f1d1d;
  background: #1c0b0b;
  color: #fecaca;
  border-radius: 12px;
  padding: 0.75rem 0.9rem;
  font-size: 0.9rem;
}

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

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .sidebar-footer,
  .sidebar-actions .hint {
    display: none;
  }
}
