/* ==========================================================================
   Answers — premium UI
   Design tokens, layout, components. Supports light + dark themes.
   ========================================================================== */

:root {
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif;
  --font-mono: "SFMono-Regular", ui-monospace, Menlo, Consolas, monospace;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 24px;
  --radius-full: 999px;

  --maxw: 760px;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

/* ---- Light theme ---- */
[data-theme="light"] {
  --bg: #fbfbf8;
  --surface: #ffffff;
  --surface-2: #f3f3ee;
  --text: #14171a;
  --text-soft: #3d4550;
  --muted: #767d87;
  --border: #e6e6e0;
  --border-strong: #d6d6cd;
  --accent: #20808d;
  --accent-hover: #1a6d78;
  --accent-soft: rgba(32, 128, 141, 0.1);
  --accent-contrast: #ffffff;
  --skeleton: #ececE6;
  --skeleton-shine: rgba(255, 255, 255, 0.75);
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-md: 0 6px 24px -10px rgba(16, 24, 40, 0.18);
  --shadow-lg: 0 24px 60px -24px rgba(16, 24, 40, 0.3);
  --code-bg: #0f1b22;
  --ambient: radial-gradient(70% 45% at 50% -12%, rgba(32, 128, 141, 0.1), transparent 70%);
}

/* ---- Dark theme ---- */
[data-theme="dark"] {
  --bg: #16181a;
  --surface: #1d2022;
  --surface-2: #24282b;
  --text: #ececea;
  --text-soft: #c6c9ca;
  --muted: #8d949a;
  --border: #2c3134;
  --border-strong: #3b4145;
  --accent: #23b0c4;
  --accent-hover: #3cc3d6;
  --accent-soft: rgba(35, 176, 196, 0.14);
  --accent-contrast: #06222a;
  --skeleton: #262b2e;
  --skeleton-shine: rgba(255, 255, 255, 0.06);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 8px 30px -12px rgba(0, 0, 0, 0.6);
  --shadow-lg: 0 26px 64px -26px rgba(0, 0, 0, 0.75);
  --code-bg: #0e1417;
  --ambient: radial-gradient(70% 45% at 50% -12%, rgba(35, 176, 196, 0.12), transparent 70%);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  background-color: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  transition: background-color 0.3s var(--ease), color 0.3s var(--ease);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: var(--ambient);
  transition: background 0.3s var(--ease);
}

.hide {
  display: none !important;
}

.disable-form {
  opacity: 0.5;
  pointer-events: none;
}

/* ==========================================================================
   Layout
   ========================================================================== */

.app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 0 20px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 2px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
  font-size: 16px;
  letter-spacing: -0.02em;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  color: var(--accent);
}

.brand-mark svg {
  width: 100%;
  height: 100%;
}

.brand-name {
  transform: translateY(0.5px);
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: color 0.2s var(--ease), background 0.2s var(--ease),
    border-color 0.2s var(--ease);
}

.icon-btn:hover {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--border);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

[data-theme="dark"] .icon-sun,
[data-theme="light"] .icon-moon {
  display: none;
}

.content {
  display: flex;
  flex: 1;
  flex-direction: column;
  width: 100%;
  padding-bottom: 40px;
}

.content.centered {
  justify-content: center;
}

/* ==========================================================================
   Hero + search
   ========================================================================== */

.search-wrap {
  width: 100%;
}

.hero {
  margin-bottom: 20px;
  text-align: center;
}

.content:not(.centered) .hero {
  display: none;
}

.hero-title {
  margin: 0;
  font-size: clamp(28px, 5.2vw, 40px);
  font-weight: 500;
  letter-spacing: -0.035em;
  line-height: 1.15;
  color: var(--text);
}

.hero-sub {
  margin: 12px 0 0;
  font-size: 15px;
  color: var(--muted);
}

.search-form {
  width: 100%;
}

.search-field {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 8px 8px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease),
    background-color 0.3s var(--ease);
}

.search-field:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft), var(--shadow-md);
}

.search-input {
  flex: 1;
  min-width: 0;
  padding: 11px 0;
  font-family: inherit;
  font-size: 17px;
  color: var(--text);
  background: transparent;
  border: 0;
  outline: 0;
}

.search-input::placeholder {
  color: var(--muted);
}

.search-input::-webkit-search-cancel-button,
.search-input::-webkit-search-decoration {
  -webkit-appearance: none;
  appearance: none;
}

.search-submit {
  display: grid;
  flex: none;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  color: var(--accent-contrast);
  background: var(--accent);
  border: 0;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: background 0.2s var(--ease), transform 0.15s var(--ease);
}

.search-submit:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.search-submit:active {
  transform: translateY(0) scale(0.96);
}

.search-submit svg {
  width: 18px;
  height: 18px;
}

.search-meta {
  display: flex;
  align-items: center;
  margin-top: 12px;
  padding: 0 6px;
}

.model-select {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  padding: 6px 12px 6px 11px;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  transition: color 0.2s var(--ease), border-color 0.2s var(--ease);
}

.model-select:hover {
  color: var(--text);
  border-color: var(--border-strong);
}

.model-select svg {
  width: 15px;
  height: 15px;
  opacity: 0.85;
}

.model-select select {
  padding-right: 2px;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  color: inherit;
  background: transparent;
  border: 0;
  outline: 0;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

.model-select option {
  color: var(--text);
  background: var(--surface);
}

/* ==========================================================================
   Chips (suggestions)
   ========================================================================== */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 26px;
}

.chips.center {
  justify-content: center;
}

.chip {
  display: inline-flex;
  align-items: center;
  padding: 9px 15px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-soft);
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: color 0.18s var(--ease), background 0.18s var(--ease),
    border-color 0.18s var(--ease), transform 0.18s var(--ease),
    box-shadow 0.18s var(--ease);
}

.chip:hover {
  color: var(--text);
  background: var(--accent-soft);
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

/* ==========================================================================
   Results
   ========================================================================== */

.results {
  width: 100%;
  animation: fade-up 0.35s var(--ease) both;
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.answer-title {
  margin: 4px 0 18px;
  font-size: clamp(22px, 3.4vw, 30px);
  font-weight: 600;
  line-height: 1.28;
  letter-spacing: -0.03em;
  color: var(--text);
}

/* Answer prose */
.prose {
  font-size: 16px;
  line-height: 1.75;
  color: var(--text-soft);
}

.prose > *:first-child {
  margin-top: 0;
}

.prose p {
  margin: 0 0 1.1em;
}

.prose h1,
.prose h2,
.prose h3,
.prose h4 {
  margin: 1.5em 0 0.6em;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
}

.prose h1 {
  font-size: 1.5em;
}
.prose h2 {
  font-size: 1.3em;
}
.prose h3 {
  font-size: 1.12em;
}

.prose ul,
.prose ol {
  margin: 0 0 1.1em;
  padding-left: 1.35em;
}

.prose li {
  margin: 0.35em 0;
}

.prose strong {
  font-weight: 600;
  color: var(--text);
}

.prose a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
  transition: border-color 0.15s var(--ease);
}

.prose a:hover {
  border-bottom-color: currentColor;
}

.prose code {
  padding: 0.15em 0.4em;
  font-family: var(--font-mono);
  font-size: 0.86em;
  background: var(--surface-2);
  border-radius: 6px;
}

.prose pre {
  margin: 0 0 1.2em;
  padding: 16px;
  overflow-x: auto;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.prose pre code {
  padding: 0;
  font-size: 13px;
  background: transparent;
}

.prose blockquote {
  margin: 1.1em 0;
  padding: 0.25em 0 0.25em 1em;
  color: var(--muted);
  border-left: 3px solid var(--accent);
}

.prose hr {
  margin: 1.6em 0;
  border: 0;
  border-top: 1px solid var(--border);
}

.prose table {
  width: 100%;
  margin: 0 0 1.2em;
  border-collapse: collapse;
  font-size: 14px;
}

.prose th,
.prose td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

/* Citation pills */
.cite {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  margin: 0 1px;
  font-size: 10.5px;
  font-weight: 700;
  line-height: 1;
  color: var(--accent);
  text-decoration: none !important;
  vertical-align: 1px;
  background: var(--accent-soft);
  border: 1px solid transparent;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: color 0.15s var(--ease), background 0.15s var(--ease);
}

.cite:hover {
  color: var(--accent-contrast);
  background: var(--accent);
}

/* Section titles */
.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 34px 0 14px;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.section-title svg {
  width: 16px;
  height: 16px;
  color: var(--accent);
}

/* Follow-up question rows */
.q-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  margin-bottom: 10px;
  padding: 15px 18px;
  font-size: 14.5px;
  font-weight: 500;
  color: var(--text-soft);
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: color 0.18s var(--ease), background 0.18s var(--ease),
    border-color 0.18s var(--ease), transform 0.18s var(--ease),
    box-shadow 0.18s var(--ease);
}

.q-row:hover {
  color: var(--text);
  background: var(--accent-soft);
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.q-row .q-plus {
  flex: none;
  font-size: 18px;
  font-weight: 300;
  color: var(--muted);
  transition: color 0.18s var(--ease);
}

.q-row:hover .q-plus {
  color: var(--accent);
}

/* Source cards */
.sources-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 12px;
}

.source-card {
  display: block;
  height: 100%;
  padding: 14px;
  color: inherit;
  text-decoration: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  transition: border-color 0.18s var(--ease), transform 0.18s var(--ease),
    box-shadow 0.18s var(--ease);
}

.source-card:hover {
  border-color: var(--border-strong);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.source-domain {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 8px;
  overflow: hidden;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  text-overflow: ellipsis;
}

.source-favicon {
  flex: none;
  width: 16px;
  height: 16px;
  border-radius: 4px;
}

.source-title {
  display: -webkit-box;
  margin: 0 0 6px;
  overflow: hidden;
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--text);
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.source-snippet {
  display: -webkit-box;
  margin: 0;
  overflow: hidden;
  font-size: 12.5px;
  line-height: 1.5;
  color: var(--muted);
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

/* Disclaimer */
.disclaimer {
  margin-top: 30px;
  padding-top: 20px;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--muted);
  border-top: 1px solid var(--border);
}

.disclaimer strong {
  font-weight: 600;
  color: var(--text-soft);
}

/* Loading skeleton */
#answerContent:empty {
  height: 152px;
  background-image:
    linear-gradient(90deg, transparent, var(--skeleton-shine), transparent),
    linear-gradient(var(--skeleton), var(--skeleton)),
    linear-gradient(var(--skeleton), var(--skeleton)),
    linear-gradient(var(--skeleton), var(--skeleton)),
    linear-gradient(var(--skeleton), var(--skeleton));
  background-repeat: no-repeat;
  background-size: 320px 100%, 100% 14px, 86% 14px, 92% 14px, 58% 14px;
  background-position: -320px 0, 0 0, 0 30px, 0 60px, 0 90px;
  border-radius: var(--radius-sm);
  animation: shimmer 1.5s infinite linear;
}

@keyframes shimmer {
  to {
    background-position: 760px 0, 0 0, 0 30px, 0 60px, 0 90px;
  }
}

/* ==========================================================================
   Modals (Bootstrap overrides)
   ========================================================================== */

.modal-content {
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.modal-header {
  padding: 18px 20px 8px;
  border-bottom: 0;
}

.modal-title,
.modal-body h6 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--text);
}

.modal-body {
  padding: 8px 20px 22px;
  font-size: 14px;
  line-height: 1.65;
  color: var(--text-soft);
}

.modal-body p {
  margin: 0 0 12px;
}

.modal-source-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--accent);
  text-decoration: none;
}

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

.modal-source-link img {
  width: 16px;
  height: 16px;
  border-radius: 4px;
}

.modal-source-link svg {
  width: 14px;
  height: 14px;
}

.btn-close {
  filter: var(--btn-close-filter, none);
}

[data-theme="dark"] .btn-close {
  filter: invert(1) grayscale(1) brightness(1.6);
}

/* ==========================================================================
   Footer
   ========================================================================== */

.footer {
  padding: 22px 0 26px;
  font-size: 12.5px;
  color: var(--muted);
  text-align: center;
}

.footer a {
  color: var(--muted);
  text-decoration: none;
  transition: color 0.15s var(--ease);
}

.footer a:hover {
  color: var(--accent);
}

/* ==========================================================================
   Code highlighting theme
   ========================================================================== */

.hljs {
  display: block;
  padding: 0;
  overflow-x: auto;
  color: #e6edf3;
  background: transparent;
}

.hljs-comment,
.hljs-quote {
  font-style: italic;
  color: #7d8b96;
}

.hljs-keyword,
.hljs-selector-tag,
.hljs-literal,
.hljs-section,
.hljs-doctag,
.hljs-type,
.hljs-name,
.hljs-strong {
  font-weight: 600;
  color: #7ee2b8;
}

.hljs-string,
.hljs-meta,
.hljs-symbol,
.hljs-bullet,
.hljs-addition,
.hljs-template-tag,
.hljs-template-variable,
.hljs-attr,
.hljs-attribute {
  color: #f0d78c;
}

.hljs-title,
.hljs-title.function_,
.hljs-built_in,
.hljs-selector-id,
.hljs-selector-class {
  color: #8fd3ff;
}

.hljs-number,
.hljs-variable,
.hljs-link,
.hljs-regexp {
  color: #e59cff;
}

.hljs-deletion {
  color: #ff8f8f;
}

.hljs-emphasis {
  font-style: italic;
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 560px) {
  .app {
    padding: 0 16px;
  }

  .hero-title {
    font-size: 26px;
  }

  .search-field {
    padding-left: 16px;
  }

  .search-input {
    font-size: 16px;
  }

  .sources-grid {
    grid-template-columns: 1fr;
  }

  .chip {
    font-size: 13px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ==========================================================================
   Navigation sidebar
   ========================================================================== */

.app {
  width: 100%;
  max-width: none;
  min-height: 100vh;
  margin: 0;
  padding: 0;
  flex-direction: row;
}

.sidebar {
  position: fixed;
  z-index: 30;
  inset: 0 auto 0 0;
  display: flex;
  flex-direction: column;
  width: 248px;
  padding: 14px 12px 12px;
  overflow: hidden;
  color: var(--text-soft);
  background: var(--surface-2);
  border-right: 1px solid var(--border);
  transition: width 0.22s var(--ease), transform 0.22s var(--ease),
    background-color 0.25s var(--ease);
}

.sidebar-brand-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 42px;
  margin-bottom: 18px;
  padding: 0 2px 0 5px;
}

.sidebar .brand {
  min-width: 0;
  gap: 8px;
  font-size: 15px;
}

.sidebar .brand-mark {
  flex: none;
  width: 23px;
  height: 23px;
}

.sidebar .brand-name {
  white-space: nowrap;
}

.sidebar-collapse {
  flex: none;
  width: 32px;
  height: 32px;
}

.sidebar-collapse svg {
  width: 17px;
  height: 17px;
}

.sidebar-action,
.sidebar-link {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 40px;
  padding: 0 11px;
  overflow: hidden;
  font: inherit;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-soft);
  text-align: left;
  white-space: nowrap;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  transition: color 0.16s var(--ease), background 0.16s var(--ease),
    border-color 0.16s var(--ease);
}

.sidebar-action svg,
.sidebar-link > svg {
  flex: none;
  width: 18px;
  height: 18px;
  color: var(--muted);
}

.sidebar-action {
  min-height: 42px;
  margin-bottom: 9px;
  color: var(--text);
  background: var(--surface);
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
}

.sidebar-action svg {
  color: var(--accent);
}

.sidebar-action:hover,
.sidebar-link:hover {
  color: var(--text);
  background: var(--accent-soft);
  border-color: var(--border);
}

.sidebar-link:hover > svg {
  color: var(--accent);
}

.sidebar-nav {
  display: grid;
  gap: 3px;
}

.sidebar-database-link {
  text-decoration: none;
}

.sidebar-section {
  min-height: 0;
  margin-top: 25px;
}

.sidebar-section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 7px 8px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

.sidebar-clear {
  padding: 2px 0 2px 6px;
  font: inherit;
  font-size: 10px;
  color: var(--muted);
  background: none;
  border: 0;
  cursor: pointer;
  opacity: 0.7;
  transition: color 0.15s var(--ease), opacity 0.15s var(--ease);
}

.sidebar-section:hover .sidebar-clear,
.sidebar-clear:focus-visible {
  opacity: 1;
}

.sidebar-clear:hover {
  color: var(--accent);
}

.recent-searches {
  display: grid;
  gap: 2px;
  max-height: min(48vh, 440px);
  overflow: auto;
}

.recent-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 37px;
  padding: 0 9px;
  overflow: hidden;
  color: var(--text-soft);
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  transition: color 0.16s var(--ease), background 0.16s var(--ease);
}

.recent-item:hover {
  color: var(--text);
  background: var(--surface);
}

.recent-icon {
  display: grid;
  flex: none;
  place-items: center;
  color: var(--muted);
}

.recent-icon svg {
  width: 15px;
  height: 15px;
}

.recent-label {
  overflow: hidden;
  font-size: 12.5px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-empty {
  margin: 4px 8px;
  font-size: 12px;
  color: var(--muted);
}

.sidebar-bottom {
  display: grid;
  gap: 10px;
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.theme-link {
  min-height: 38px;
}

.sidebar-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 8px 7px 2px;
}

.profile-avatar {
  display: grid;
  flex: none;
  place-items: center;
  width: 30px;
  height: 30px;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent-contrast);
  background: var(--accent);
  border-radius: 50%;
}

.profile-copy {
  display: grid;
  min-width: 0;
  line-height: 1.35;
}

.profile-copy strong {
  overflow: hidden;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-soft);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.profile-copy small {
  overflow: hidden;
  margin-top: 2px;
  font-size: 10px;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workspace {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-width: 0;
  min-height: 100vh;
  margin-left: 248px;
  transition: margin-left 0.22s var(--ease);
}

.topbar {
  justify-content: flex-start;
  min-height: 56px;
  padding: 8px 24px;
}

.sidebar-open,
.mobile-page-title {
  display: none;
}

.content {
  width: 100%;
  max-width: 1000px;
  margin: 0 auto;
  padding: 36px 32px 42px;
}

.content.centered {
  min-height: calc(100vh - 118px);
}

.search-wrap {
  max-width: 780px;
  margin: 0 auto;
}

.results {
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
}

.footer {
  width: 100%;
  margin-top: auto;
  padding: 18px 24px 24px;
}

.sidebar-overlay {
  display: none;
}

.topbar {
  position: relative;
  z-index: 40;
}

.topbar-actions {
  position: relative;
  margin-left: auto;
}

.features-menu-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  padding: 0 13px;
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-soft);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: color 0.16s var(--ease), background 0.16s var(--ease),
    border-color 0.16s var(--ease);
}

.features-menu-button:hover,
.features-menu-button[aria-expanded="true"] {
  color: var(--text);
  background: var(--accent-soft);
  border-color: var(--border-strong);
}

.features-menu-button svg {
  width: 17px;
  height: 17px;
  color: var(--accent);
}

.features-menu {
  position: absolute;
  top: calc(100% + 9px);
  right: 0;
  z-index: 45;
  display: grid;
  width: 280px;
  padding: 8px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 15px;
  box-shadow: var(--shadow-lg);
  animation: menu-in 0.16s var(--ease) both;
}

@keyframes menu-in {
  from {
    opacity: 0;
    transform: translateY(-5px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.features-menu-heading {
  padding: 8px 10px 9px;
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
}

.topic-option {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 48px;
  padding: 6px 10px;
  color: var(--text-soft);
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 9px;
  cursor: pointer;
  transition: color 0.15s var(--ease), background 0.15s var(--ease);
}

.topic-option:hover,
.topic-option.active {
  color: var(--text);
  background: var(--surface-2);
}

.topic-icon {
  display: grid;
  flex: none;
  place-items: center;
  width: 30px;
  height: 30px;
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 8px;
}

.topic-copy {
  display: grid;
  min-width: 0;
  gap: 1px;
}

.topic-copy strong {
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.35;
}

.topic-copy small {
  font-size: 10.5px;
  line-height: 1.35;
  color: var(--muted);
}

.topic-check {
  margin-left: auto;
  font-size: 13px;
  color: var(--accent);
  opacity: 0;
}

.topic-option.active .topic-check {
  opacity: 1;
}

.search-topic-tag {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 11px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
}

.category-search {
  max-width: 820px;
  margin: 0 auto 34px;
}

.category-search .hero,
.category-search #suggestions {
  display: none;
}

.category-search .search-field {
  padding-top: 5px;
  padding-bottom: 5px;
  border-radius: 18px;
  box-shadow: var(--shadow-sm);
}

.category-search .search-input {
  font-size: 15px;
}

.category-landing {
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  animation: fade-up 0.28s var(--ease) both;
}

.category-page-header {
  margin: 8px 0 24px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.category-kicker {
  display: inline-block;
  margin-bottom: 8px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--accent);
}

.category-title {
  margin: 0;
  font-size: clamp(28px, 4vw, 36px);
  font-weight: 600;
  letter-spacing: -0.035em;
  line-height: 1.15;
  color: var(--text);
}

.category-description {
  max-width: 620px;
  margin: 10px 0 0;
  font-size: 14px;
  line-height: 1.65;
  color: var(--muted);
}

.category-topics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.topic-card {
  display: flex;
  align-items: center;
  gap: 13px;
  min-width: 0;
  min-height: 88px;
  padding: 15px;
  color: var(--text-soft);
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: color 0.17s var(--ease), background 0.17s var(--ease),
    border-color 0.17s var(--ease), transform 0.17s var(--ease),
    box-shadow 0.17s var(--ease);
}

.topic-card:hover {
  color: var(--text);
  background: var(--accent-soft);
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.topic-card-icon {
  display: grid;
  flex: none;
  place-items: center;
  width: 40px;
  height: 40px;
  font-size: 17px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.topic-card-copy {
  display: grid;
  min-width: 0;
  gap: 4px;
}

.topic-card-copy strong {
  overflow: hidden;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topic-card-copy small {
  display: -webkit-box;
  overflow: hidden;
  font-size: 11px;
  line-height: 1.45;
  color: var(--muted);
  line-clamp: 2;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
}

.topic-card-arrow {
  display: grid;
  flex: none;
  place-items: center;
  width: 25px;
  height: 25px;
  margin-left: auto;
  color: var(--muted);
  border-radius: 50%;
  transition: color 0.17s var(--ease), background 0.17s var(--ease),
    transform 0.17s var(--ease);
}

.topic-card-arrow svg {
  width: 16px;
  height: 16px;
}

.topic-card:hover .topic-card-arrow {
  color: var(--accent);
  background: var(--surface);
  transform: translateX(2px);
}

.sidebar-collapsed .sidebar {
  width: 72px;
  padding-right: 9px;
  padding-left: 9px;
}

.sidebar-collapsed .workspace {
  margin-left: 72px;
}

.sidebar-collapsed .sidebar-brand-row {
  justify-content: space-between;
  padding: 0 1px 0 5px;
}

.sidebar-collapsed .sidebar .brand-name,
.sidebar-collapsed .sidebar-action span,
.sidebar-collapsed .sidebar-link span,
.sidebar-collapsed .sidebar-section,
.sidebar-collapsed .profile-copy {
  display: none;
}

.sidebar-collapsed .sidebar-collapse {
  position: static;
  width: 28px;
  height: 28px;
  opacity: 1;
}

.sidebar-collapsed .sidebar-action,
.sidebar-collapsed .sidebar-link {
  justify-content: center;
  gap: 0;
  padding: 0;
}

.sidebar-collapsed .sidebar-action {
  margin-top: 2px;
}

.sidebar-collapsed .sidebar-action svg,
.sidebar-collapsed .sidebar-link > svg {
  width: 19px;
  height: 19px;
}

.sidebar-collapsed .sidebar-profile {
  justify-content: center;
  padding-right: 0;
  padding-left: 0;
}

@media (max-width: 760px) {
  .sidebar {
    z-index: 60;
    width: min(288px, 86vw);
    box-shadow: var(--shadow-lg);
    transform: translateX(-105%);
  }

  body.sidebar-open {
    overflow: hidden;
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-overlay {
    position: fixed;
    z-index: 50;
    inset: 0;
    display: block;
    padding: 0;
    visibility: hidden;
    background: rgba(0, 0, 0, 0.42);
    border: 0;
    opacity: 0;
    transition: opacity 0.22s var(--ease), visibility 0.22s;
  }

  body.sidebar-open .sidebar-overlay {
    visibility: visible;
    opacity: 1;
  }

  .sidebar-collapse {
    display: none;
  }

  .sidebar-collapsed .sidebar {
    width: min(288px, 86vw);
    padding-right: 12px;
    padding-left: 12px;
  }

  .sidebar-collapsed .workspace {
    margin-left: 0;
  }

  .sidebar-collapsed .sidebar .brand-name,
  .sidebar-collapsed .sidebar-action span,
  .sidebar-collapsed .sidebar-link span,
  .sidebar-collapsed .sidebar-section,
  .sidebar-collapsed .profile-copy {
    display: initial;
  }

  .sidebar-collapsed .sidebar-section {
    display: block;
  }

  .sidebar-collapsed .sidebar-action,
  .sidebar-collapsed .sidebar-link {
    justify-content: flex-start;
    gap: 12px;
    padding: 0 11px;
  }

  .sidebar-collapsed .sidebar-profile {
    justify-content: flex-start;
    padding-right: 7px;
    padding-left: 7px;
  }

  .workspace,
  .sidebar-collapsed .workspace {
    margin-left: 0;
  }

  .topbar {
    min-height: 56px;
    gap: 10px;
    padding: 8px 16px;
  }

  .sidebar-open,
  .mobile-page-title {
    display: inline-flex;
  }

  .mobile-page-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-soft);
  }

  .content {
    padding: 28px 20px 34px;
  }

  .content.centered {
    min-height: calc(100vh - 110px);
  }
}

@media (max-width: 560px) {
  .content {
    padding-right: 16px;
    padding-left: 16px;
  }

  .category-topics {
    grid-template-columns: 1fr;
  }

  .footer {
    padding-right: 16px;
    padding-left: 16px;
  }
}

/* ==========================================================================
   Local supplier and knowledge database
   ========================================================================== */

.knowledge-page {
  width: min(100% - 40px, 960px);
  min-height: 100vh;
  margin: 0 auto;
  padding: 26px 0 64px;
}

.knowledge-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 42px;
}

.knowledge-back,
.knowledge-brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--text-soft);
  font-size: 12.5px;
  font-weight: 500;
  text-decoration: none;
}

.knowledge-back:hover {
  color: var(--accent);
}

.knowledge-back svg {
  width: 17px;
  height: 17px;
}

.knowledge-brand {
  color: var(--text);
  font-size: 14px;
  font-weight: 650;
}

.knowledge-brand-mark {
  font-size: 19px;
  color: var(--accent);
}

.knowledge-intro {
  max-width: 720px;
  margin: 48px 0 30px;
}

.knowledge-eyebrow {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--accent);
  text-transform: uppercase;
}

.knowledge-intro h1 {
  margin: 8px 0 10px;
  font-size: clamp(28px, 5vw, 38px);
  font-weight: 600;
  letter-spacing: -0.04em;
  color: var(--text);
}

.knowledge-intro p {
  max-width: 700px;
  margin: 0;
  font-size: 13px;
  line-height: 1.7;
  color: var(--muted);
}

.database-filename {
  display: inline-flex;
  margin-top: 13px;
  padding: 5px 9px;
  font-size: 11px;
  color: var(--text-soft);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 7px;
}

.knowledge-workspace {
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.knowledge-toolbar,
.knowledge-tabs {
  display: flex;
  align-items: center;
}

.knowledge-toolbar {
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.knowledge-tabs {
  gap: 5px;
  min-width: 0;
}

.knowledge-tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 36px;
  padding: 0 11px;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 9px;
  cursor: pointer;
}

.knowledge-tab:hover,
.knowledge-tab.active {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--border);
}

.knowledge-tab.active {
  color: var(--accent);
}

.knowledge-count {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  font-size: 10px;
  color: var(--text-soft);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
}

.knowledge-add,
.knowledge-save {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  padding: 0 13px;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-contrast);
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 9px;
  cursor: pointer;
  transition: filter 0.16s var(--ease), transform 0.16s var(--ease);
}

.knowledge-add:hover,
.knowledge-save:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.knowledge-add svg {
  width: 16px;
  height: 16px;
}

.database-status {
  min-height: 19px;
  margin: 11px 2px 13px;
  font-size: 11px;
  color: var(--muted);
}

.database-status.error {
  color: var(--danger, #e36b6b);
}

.knowledge-panel[hidden],
.knowledge-form[hidden] {
  display: none;
}

.knowledge-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.knowledge-card {
  min-width: 0;
  padding: 15px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}

.knowledge-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.knowledge-card-title {
  display: grid;
  min-width: 0;
  gap: 7px;
}

.knowledge-card-title h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
  overflow-wrap: anywhere;
  color: var(--text);
}

.knowledge-category {
  justify-self: start;
  padding: 3px 8px;
  font-size: 10px;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: var(--radius-full);
}

.knowledge-detail {
  display: flex;
  gap: 8px;
  margin: 5px 0;
  font-size: 11.5px;
  line-height: 1.5;
  overflow-wrap: anywhere;
  color: var(--text-soft);
}

.knowledge-detail-label {
  flex: 0 0 58px;
  color: var(--muted);
}

.knowledge-detail a {
  color: var(--accent);
  text-decoration: none;
}

.knowledge-detail a:hover {
  text-decoration: underline;
}

.knowledge-tags {
  margin: 0 0 8px;
  font-size: 10.5px;
  color: var(--accent);
}

.knowledge-description {
  margin: 8px 0 0;
  font-size: 11.5px;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: var(--text-soft);
}

.knowledge-record-actions {
  display: flex;
  justify-content: flex-end;
  gap: 7px;
  margin-top: 13px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

.knowledge-edit,
.knowledge-delete,
.knowledge-cancel {
  min-height: 30px;
  padding: 0 9px;
  font: inherit;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text-soft);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 7px;
  cursor: pointer;
}

.knowledge-edit:hover,
.knowledge-cancel:hover {
  color: var(--text);
  background: var(--surface);
}

.knowledge-delete {
  color: #dc7777;
}

.knowledge-delete:hover {
  color: #f08a8a;
  background: rgba(220, 90, 90, 0.08);
  border-color: rgba(220, 90, 90, 0.35);
}

.knowledge-empty {
  grid-column: 1 / -1;
  padding: 35px 18px;
  font-size: 12px;
  color: var(--muted);
  text-align: center;
  background: var(--surface-2);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-md);
}

.knowledge-dialog {
  width: min(620px, calc(100% - 28px));
  max-height: min(88vh, 820px);
  padding: 0;
  overflow: auto;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.knowledge-dialog::backdrop {
  background: rgba(5, 8, 10, 0.68);
  backdrop-filter: blur(3px);
}

.knowledge-dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 19px 21px 15px;
  border-bottom: 1px solid var(--border);
}

.knowledge-dialog-header h2 {
  margin: 5px 0 0;
  font-size: 19px;
  font-weight: 600;
  letter-spacing: -0.025em;
}

.knowledge-close {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  font-size: 22px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

.knowledge-close:hover {
  color: var(--text);
  background: var(--surface-2);
}

.knowledge-form {
  display: grid;
  gap: 13px;
  padding: 18px 21px 21px;
}

.knowledge-form label {
  display: grid;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-soft);
}

.knowledge-form input,
.knowledge-form select,
.knowledge-form textarea {
  width: 100%;
  min-height: 38px;
  padding: 9px 11px;
  font: inherit;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
}

.knowledge-form textarea {
  min-height: 92px;
  resize: vertical;
}

.knowledge-form input:focus,
.knowledge-form select:focus,
.knowledge-form textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.knowledge-form input::placeholder,
.knowledge-form textarea::placeholder {
  color: var(--muted);
}

.knowledge-form-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 11px;
}

.knowledge-form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
  padding-top: 13px;
  border-top: 1px solid var(--border);
}

.knowledge-save:disabled {
  cursor: wait;
  opacity: 0.65;
}

@media (max-width: 640px) {
  .knowledge-page {
    width: min(100% - 28px, 960px);
    padding-top: 17px;
  }

  .knowledge-intro {
    margin: 35px 0 22px;
  }

  .knowledge-workspace {
    padding: 12px;
  }

  .knowledge-toolbar {
    align-items: flex-start;
  }

  .knowledge-tabs {
    flex-wrap: wrap;
  }

  .knowledge-tab {
    padding: 0 8px;
    font-size: 10.5px;
  }

  .knowledge-add {
    flex: none;
    min-height: 36px;
    padding: 0 9px;
    font-size: 10.5px;
  }

  .knowledge-list {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 420px) {
  .knowledge-form-row {
    grid-template-columns: 1fr;
  }
}
