:root {
  --bg: #f1f5f9;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #4f46e5;
  --accent-ink: #eef2ff;
  --danger: #dc2626;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Ubuntu, sans-serif;
  background: var(--bg);
  color: var(--ink);
  padding-bottom: 84px;
}

header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--ink);
  color: #fff;
}
header h1 { font-size: 18px; margin: 0; }

main { max-width: 720px; margin: 0 auto; padding: 16px; }

#tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 5;
}
#tabbar button {
  flex: 1;
  padding: 14px 4px;
  border: 0;
  background: none;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
}
#tabbar button.active { color: var(--accent); font-weight: 600; }

.tab { display: none; }
.tab.active { display: block; }

button, .ghost {
  font: inherit;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  padding: 8px 14px;
  cursor: pointer;
  text-decoration: none;
  display: inline-block;
}
form.askbar button, #edit-form button {
  background: var(--accent);
  color: #fff;
  border: 0;
}
.danger { color: var(--danger); border-color: #fecaca; }

#dropzone {
  border: 2px dashed #c7d2fe;
  border-radius: 14px;
  padding: 24px 16px;
  text-align: center;
  background: var(--accent-ink);
  margin-bottom: 14px;
  cursor: pointer;
}
#dropzone.drag { background: #e0e7ff; border-color: var(--accent); }
#dropzone p { margin: 6px 0; }
#dropzone input { display: none; }
.hint { color: var(--muted); font-size: 13px; }

.filters { display: flex; gap: 8px; margin-bottom: 14px; }
.filters select, .filters input, .askbar input, #edit-form input {
  flex: 1;
  min-width: 0;
  font: inherit;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
}

.askbar { display: flex; gap: 8px; margin-bottom: 14px; }

.cards { display: flex; flex-direction: column; gap: 10px; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  cursor: pointer;
}
.card h3 { margin: 0 0 4px; font-size: 15px; }
.card .snippet { color: var(--muted); font-size: 13px; margin: 8px 0 0; }
.card .meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

.chip {
  font-size: 12px;
  background: var(--accent-ink);
  color: var(--accent);
  border-radius: 999px;
  padding: 3px 10px;
}
.chip.cat { background: #ecfdf5; color: #047857; }
.chip.status { background: #fef9c3; color: #a16207; }
.chip.status.ready { background: #ecfdf5; color: #047857; }
.chip.status.failed { background: #fee2e2; color: #b91c1c; }

.score { margin-left: auto; color: var(--muted); font-size: 12px; }

.answer {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 16px;
  white-space: pre-wrap;
  line-height: 1.55;
  font-size: 15px;
}
.answer .cursor { animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0; } }

.sources { margin-top: 12px; }
.source {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 8px;
  font-size: 13px;
  cursor: pointer;
}
.source b { font-size: 14px; }

#doc-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  z-index: 10;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
#doc-card {
  background: var(--card);
  border-radius: 20px 20px 0 0;
  padding: 20px;
  width: 100%;
  max-width: 720px;
  max-height: 88vh;
  overflow-y: auto;
  position: relative;
}
#doc-card .close {
  position: absolute;
  top: 12px;
  right: 12px;
  border: 0;
  background: none;
  font-size: 18px;
  color: var(--muted);
}
#doc-card h2 { margin: 0 40px 4px 0; font-size: 18px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.row { display: flex; gap: 8px; margin: 12px 0; flex-wrap: wrap; }

#edit-form { display: flex; flex-direction: column; gap: 10px; }
#edit-form label { font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }

#doc-text-wrap summary { cursor: pointer; color: var(--muted); margin-top: 8px; }
#doc-text {
  white-space: pre-wrap;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  max-height: 40vh;
  overflow-y: auto;
  background: var(--bg);
  border-radius: 10px;
  padding: 12px;
}

#install-btn { background: none; color: #fff; border-color: #475569; }

.empty { text-align: center; color: var(--muted); padding: 40px 0; }
