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

:root {
  --bg: #f8f9fa;
  --surface: #fff;
  --border: #dee2e6;
  --text: #212529;
  --muted: #6c757d;
  --primary: #0d6efd;
  --primary-hover: #0b5ed7;
  --viss-color: #198754;
  --1177-color: #d63384;
  --kunskapsstod-color: #0dcaf0;
  --gic-color: #e65100;
  --radius: 8px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ── Header ─────────────────────────────────────────────── */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.logo {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--primary);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.tagline {
  color: var(--muted);
  font-size: 0.85rem;
}

/* ── Tab bar ─────────────────────────────────────────────── */
.tab-bar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  flex: 1;
  padding: 12px 16px;
  font-size: 0.95rem;
  font-weight: 500;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  cursor: pointer;
  color: var(--muted);
  transition: color 0.15s, border-color 0.15s;
  min-height: 44px;
}

.tab-btn:hover {
  color: var(--text);
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* ── Main content ────────────────────────────────────────── */
main {
  max-width: 900px;
  margin: 0 auto;
  padding: 16px;
}

/* ── Search bar ──────────────────────────────────────────── */
.search-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

#search-input {
  width: 100%;
  padding: 12px 16px;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  min-height: 44px;
}

#search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15);
}

#site-filter,
#qa-site-filter,
#qa-model,
#qa-mode {
  padding: 10px 12px;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  min-height: 44px;
  width: 100%;
}

.results-meta {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 12px;
  min-height: 20px;
}

/* ── Result cards ────────────────────────────────────────── */
.results {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.card:hover {
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.card-top {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}

.site-badge {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 2px 8px;
  border-radius: 20px;
  color: #fff;
  white-space: nowrap;
}

.badge-viss { background: var(--viss-color); }
.badge-1177 { background: var(--1177-color); }
.badge-kunskapsstodforvardgivare { background: var(--kunskapsstod-color); color: #000; }
.badge-gic { background: var(--gic-color); }

.card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.relevance-pct {
  font-size: 0.75rem;
  font-weight: 600;
  margin-left: auto;
  white-space: nowrap;
}

.relevance-bar {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  margin-bottom: 6px;
  overflow: hidden;
}

.relevance-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.3s;
}

.card-excerpt {
  font-size: 0.875rem;
  color: var(--muted);
  margin-bottom: 8px;
  line-height: 1.5;
}

.keywords {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.keyword-chip {
  font-size: 0.72rem;
  padding: 2px 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--muted);
}

/* ── Detail view ─────────────────────────────────────────── */
.hidden { display: none !important; }

.back-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 8px 0;
  margin-bottom: 20px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

.back-btn:hover { text-decoration: underline; }

#detail-header {
  margin-bottom: 24px;
}

.detail-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.detail-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.source-link {
  font-size: 0.875rem;
  color: var(--primary);
  text-decoration: none;
}

.source-link:hover { text-decoration: underline; }

/* ── Markdown body ───────────────────────────────────────── */
.markdown-body {
  line-height: 1.7;
  color: var(--text);
}

.markdown-body h1 { font-size: 1.6rem; margin: 1.2em 0 0.5em; }
.markdown-body h2 { font-size: 1.25rem; margin: 1.2em 0 0.4em; border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.markdown-body h3 { font-size: 1.05rem; margin: 1em 0 0.3em; }
.markdown-body h4, .markdown-body h5, .markdown-body h6 { font-size: 1rem; margin: 0.8em 0 0.3em; }
.markdown-body p { margin: 0.6em 0; }
.markdown-body ul, .markdown-body ol { padding-left: 1.5em; margin: 0.6em 0; }
.markdown-body li { margin: 0.2em 0; }
.markdown-body strong { font-weight: 600; }
.markdown-body em { font-style: italic; }
.markdown-body table { border-collapse: collapse; width: 100%; margin: 1em 0; font-size: 0.875rem; overflow-x: auto; display: block; }
.markdown-body th, .markdown-body td { border: 1px solid var(--border); padding: 8px 12px; text-align: left; }
.markdown-body th { background: var(--bg); font-weight: 600; }
.markdown-body blockquote { border-left: 4px solid var(--border); padding-left: 16px; color: var(--muted); margin: 0.8em 0; }
.markdown-body code { background: var(--bg); padding: 1px 4px; border-radius: 4px; font-family: monospace; font-size: 0.875em; }
.markdown-body pre { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; overflow-x: auto; margin: 0.8em 0; }
.markdown-body pre code { background: none; padding: 0; }
.markdown-body a { color: var(--primary); }

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 48px 0;
  font-size: 1rem;
}

/* ── Q&A section ─────────────────────────────────────────── */
.qa-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

#qa-input {
  width: 100%;
  padding: 12px 16px;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  resize: none;
  overflow: hidden;
  font-family: inherit;
  line-height: 1.5;
}

#qa-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15);
}

.qa-controls {
  display: flex;
  gap: 8px;
}

.qa-controls #qa-site-filter {
  flex: 1;
}

#qa-submit {
  padding: 10px 20px;
  font-size: 1rem;
  font-weight: 600;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  min-height: 44px;
  white-space: nowrap;
  transition: background 0.15s;
}

#qa-submit:hover:not(:disabled) {
  background: var(--primary-hover);
}

#qa-submit:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* Loading spinner */
#qa-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.9rem;
  padding: 16px 0;
}

.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Answer block */
.answer-block {
  background: #f0f4ff;
  border-left: 4px solid var(--primary);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 16px 20px;
  line-height: 1.7;
  font-size: 0.95rem;
  white-space: pre-wrap;
  margin-bottom: 20px;
}

/* Sources */
.qa-sources-heading {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.qa-sources {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.source-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: border-color 0.15s, box-shadow 0.15s;
  min-height: 44px;
}

.source-card:hover {
  border-color: var(--primary);
  box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}

.source-card-title {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text);
}

/* Disclaimer */
.disclaimer {
  font-size: 0.78rem;
  color: var(--muted);
  text-align: center;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  margin-top: 8px;
}

/* ── Auth modal ──────────────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 32px 28px;
  width: min(400px, calc(100vw - 32px));
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
}

.modal-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
}

.modal-desc {
  font-size: 0.9rem;
  color: var(--muted);
}

.modal input[type="password"] {
  width: 100%;
  padding: 11px 14px;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  min-height: 44px;
}

.modal input[type="password"]:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15);
}

.modal button {
  padding: 11px 20px;
  font-size: 1rem;
  font-weight: 600;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  min-height: 44px;
  transition: background 0.15s;
}

.modal button:hover {
  background: var(--primary-hover);
}

.modal-error {
  font-size: 0.85rem;
  color: #dc3545;
}

/* ── Source group toggle ─────────────────────────────────── */
.source-group-bar {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}

.source-group-btn {
  padding: 6px 14px;
  font-size: 0.85rem;
  font-weight: 500;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s;
}

.source-group-btn:hover {
  border-color: var(--primary);
  color: var(--text);
}

.source-group-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* ── Close answer button ─────────────────────────────────── */
.close-answer-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.85rem;
  cursor: pointer;
  padding: 4px 8px;
  float: right;
  margin-bottom: 4px;
}

.close-answer-btn:hover {
  color: var(--text);
}

/* ── Show more / hidden cards ────────────────────────────── */
.card-hidden {
  display: none;
}

.show-more-btn {
  display: block;
  width: 100%;
  padding: 12px;
  font-size: 0.9rem;
  font-weight: 500;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--primary);
  cursor: pointer;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
}

.show-more-btn:hover {
  border-color: var(--primary);
  background: #f0f4ff;
}

/* ── Feedback section ────────────────────────────────────── */
.feedback-heading {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 4px;
}

.feedback-desc {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 12px;
}

.feedback-input,
.feedback-textarea {
  width: 100%;
  padding: 10px 14px;
  font-size: 0.95rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  font-family: inherit;
  margin-bottom: 8px;
}

.feedback-input:focus,
.feedback-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.15);
}

.feedback-textarea {
  resize: vertical;
  line-height: 1.5;
}

.feedback-status {
  font-size: 0.85rem;
  margin-bottom: 8px;
}

.feedback-submit {
  padding: 10px 20px;
  font-size: 0.95rem;
  font-weight: 600;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  min-height: 44px;
  transition: background 0.15s;
}

.feedback-submit:hover {
  background: var(--primary-hover);
}

/* ── Footer ──────────────────────────────────────────────── */
.site-footer {
  max-width: 900px;
  margin: 32px auto 16px;
  padding: 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  font-size: 0.8rem;
  color: var(--muted);
}

.site-footer a {
  color: var(--primary);
  text-decoration: none;
}

.site-footer a:hover {
  text-decoration: underline;
}

/* ── Desktop overrides (641px+) ──────────────────────────── */
@media (min-width: 641px) {
  .site-header {
    padding: 16px 24px;
  }

  .logo {
    font-size: 1.5rem;
  }

  main {
    padding: 24px 16px;
  }

  .search-bar {
    flex-direction: row;
  }

  #search-input {
    flex: 1;
    width: auto;
  }

  #site-filter {
    width: auto;
  }

  .qa-bar {
    gap: 10px;
  }

  .detail-title {
    font-size: 1.75rem;
  }

  .tagline {
    font-size: 0.9rem;
  }
}
