@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  --bg: #0f172a;
  --panel: #161f36;
  --panel-border: #243049;
  --slate: #1e293b;
  --text: #f8fafc;
  --text-dim: #94a3b8;
  --accent: #22c55e;
  --accent-dim: #16a34a;
  --danger: #f87171;
  --radius: 14px;
  --mono: 'JetBrains Mono', monospace;
  --sans: 'IBM Plex Sans', sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  line-height: 1.5;
  min-height: 100vh;
}

.bg-grid {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(148, 163, 184, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(148, 163, 184, 0.06) 1px, transparent 1px);
  background-size: 40px 40px;
  mask-image: radial-gradient(ellipse 80% 50% at 50% 0%, #000 40%, transparent 100%);
  z-index: 0;
  pointer-events: none;
}

.site-header, .layout, .site-footer { position: relative; z-index: 1; }

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 32px;
  border-bottom: 1px solid var(--panel-border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-weight: 600;
  font-size: 16px;
  color: var(--text);
}
.brand-mark { color: var(--accent); }
.accent { color: var(--accent); }

.header-link {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--text-dim);
  text-decoration: none;
  font-size: 14px;
  cursor: pointer;
  transition: color 200ms ease;
}
.header-link:hover { color: var(--text); }
.header-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 4px; }

.layout {
  max-width: 720px;
  margin: 0 auto;
  padding: 56px 24px 80px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.intro h1 {
  font-size: clamp(28px, 4vw, 38px);
  margin: 0 0 12px;
  letter-spacing: -0.02em;
}
.intro p {
  margin: 0;
  color: var(--text-dim);
  font-size: 16px;
  max-width: 560px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 24px;
}

.panel-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}
.panel-head h2 {
  font-size: 16px;
  margin: 0;
  font-weight: 600;
}
.step-index {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--accent);
  background: rgba(34, 197, 94, 0.12);
  border: 1px solid rgba(34, 197, 94, 0.25);
  border-radius: 6px;
  padding: 2px 7px;
}

.key-row {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.key-input-wrap {
  position: relative;
  flex: 1;
  min-width: 220px;
}
#api-key {
  width: 100%;
  background: var(--slate);
  border: 1px solid var(--panel-border);
  color: var(--text);
  font-family: var(--mono);
  font-size: 14px;
  padding: 11px 42px 11px 14px;
  border-radius: 10px;
  outline: none;
  transition: border-color 200ms ease;
}
#api-key:focus { border-color: var(--accent); }
#api-key::placeholder { color: var(--text-dim); }

.icon-btn {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: flex;
  transition: color 200ms ease;
}
.icon-btn:hover { color: var(--text); }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.remember-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-dim);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.remember-row input { accent-color: var(--accent); cursor: pointer; }

.hint {
  margin: 14px 0 0;
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.6;
}
.hint code {
  font-family: var(--mono);
  background: var(--slate);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
}

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  border: 1.5px dashed var(--panel-border);
  border-radius: 10px;
  padding: 32px 20px;
  cursor: pointer;
  color: var(--text-dim);
  transition: border-color 200ms ease, background 200ms ease, color 200ms ease;
  text-align: center;
}
.dropzone:hover, .dropzone.is-dragover {
  border-color: var(--accent);
  background: rgba(34, 197, 94, 0.06);
  color: var(--text);
}
.dropzone:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.dropzone-label { font-size: 15px; font-weight: 500; }
.dropzone-sub { font-size: 12px; color: var(--text-dim); }

.file-list {
  list-style: none;
  margin: 16px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.file-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--slate);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
}
.file-item .file-name {
  font-family: var(--mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-item .file-status {
  flex-shrink: 0;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  font-family: var(--mono);
}
.file-status.is-uploading { color: #fbbf24; background: rgba(251, 191, 36, 0.12); }
.file-status.is-indexing { color: #60a5fa; background: rgba(96, 165, 250, 0.12); }
.file-status.is-ready { color: var(--accent); background: rgba(34, 197, 94, 0.12); }
.file-status.is-error { color: var(--danger); background: rgba(248, 113, 113, 0.12); }

.status-pill {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  color: var(--text-dim);
}
.status-pill.is-idle { color: var(--text-dim); }
.status-pill.is-ready { color: var(--accent); border-color: rgba(34, 197, 94, 0.3); background: rgba(34, 197, 94, 0.08); }
.status-pill.is-busy { border-color: rgba(96, 165, 250, 0.3); background: rgba(96, 165, 250, 0.08); }

.shimmer {
  background-image: linear-gradient(90deg, var(--shimmer-base, var(--text-dim)) 0%, var(--shimmer-base, var(--text-dim)) 35%, #ffffff 50%, var(--shimmer-base, var(--text-dim)) 65%, var(--shimmer-base, var(--text-dim)) 100%);
  background-size: 220% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: shimmer-sweep 1.8s ease-in-out infinite;
}
@keyframes shimmer-sweep {
  0% { background-position: 160% 0; }
  100% { background-position: -60% 0; }
}
.file-status.is-uploading .shimmer { --shimmer-base: #fbbf24; }
.file-status.is-indexing .shimmer { --shimmer-base: #60a5fa; }
.status-pill.is-busy .shimmer { --shimmer-base: #60a5fa; }

.chat-log {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 160px;
  max-height: 420px;
  overflow-y: auto;
  padding-right: 4px;
  margin-bottom: 16px;
}
.chat-empty {
  color: var(--text-dim);
  font-size: 14px;
  padding: 24px 4px;
  text-align: center;
}

.msg {
  max-width: 88%;
  padding: 11px 14px;
  border-radius: 10px;
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
}
.msg.user {
  align-self: flex-end;
  background: var(--accent-dim);
  color: #052e12;
}
.msg.bot {
  align-self: flex-start;
  background: var(--slate);
  border: 1px solid var(--panel-border);
  white-space: normal;
}
.msg.bot :where(p, ul, ol) { margin: 0 0 8px; }
.msg.bot :where(p, ul, ol):last-child { margin-bottom: 0; }
.msg.bot ul, .msg.bot ol { padding-left: 20px; }
.msg.bot li { margin: 2px 0; }
.msg.bot strong { color: var(--text); font-weight: 600; }
.msg.bot a { color: var(--accent); }
.msg.bot code {
  font-family: var(--mono);
  background: var(--bg);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.9em;
}
.msg.bot pre {
  background: var(--bg);
  padding: 10px;
  border-radius: 8px;
  overflow-x: auto;
}
.msg.bot pre code { background: none; padding: 0; }
.msg.error {
  align-self: flex-start;
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid rgba(248, 113, 113, 0.3);
  color: var(--danger);
}
.msg.pending {
  font-style: italic;
  background-image: linear-gradient(90deg, var(--text-dim) 0%, var(--text-dim) 35%, #ffffff 50%, var(--text-dim) 65%, var(--text-dim) 100%);
  background-size: 220% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: shimmer-sweep 1.8s ease-in-out infinite;
}

.sources {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--panel-border);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.source-chip {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-dim);
  background: var(--bg);
  border: 1px solid var(--panel-border);
  border-radius: 6px;
  padding: 3px 8px;
}

.chat-form {
  display: flex;
  gap: 10px;
}
#chat-input {
  flex: 1;
  background: var(--slate);
  border: 1px solid var(--panel-border);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  padding: 12px 14px;
  border-radius: 10px;
  outline: none;
  transition: border-color 200ms ease;
}
#chat-input:focus { border-color: var(--accent); }
#chat-input:disabled { opacity: 0.5; cursor: not-allowed; }

.primary-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--accent);
  color: #052e12;
  border: none;
  font-family: var(--sans);
  font-weight: 600;
  font-size: 14px;
  padding: 12px 18px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 200ms ease, transform 150ms ease;
}
.primary-btn:hover:not(:disabled) { background: #4ade80; }
.primary-btn:active:not(:disabled) { transform: scale(0.97); }
.primary-btn:disabled { background: var(--slate); color: var(--text-dim); cursor: not-allowed; }
.primary-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

.site-footer {
  text-align: center;
  padding: 24px;
  color: var(--text-dim);
  font-size: 12px;
  font-family: var(--mono);
  border-top: 1px solid var(--panel-border);
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

@media (max-width: 480px) {
  .site-header { padding: 18px 16px; }
  .layout { padding: 32px 16px 56px; }
  .key-row { flex-direction: column; align-items: stretch; }
  .msg { max-width: 100%; }
}
