:root {
  --brand-red: #E02927;
  --brand-red-dark: #B81E1C;
  --brand-red-light: #FDECEC;
  --ink: #1C1C1E;
  --ink-soft: #55575C;
  --border: #E5E3E1;
  --bg: #FAFAF9;
  --card-bg: #FFFFFF;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-hover: 0 4px 14px rgba(0,0,0,0.08);
}

* { box-sizing: border-box; }

/* App shell */
.app-shell {
  display: flex;
  align-items: stretch;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--card-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
  z-index: 20;
}

.sidebar-brand {
  padding: 4px 12px 22px;
}

.sidebar-logo {
  height: 34px;
  width: auto;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar-link {
  display: block;
  padding: 10px 12px;
  border-radius: var(--radius);
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 500;
  transition: background 0.15s ease, color 0.15s ease;
}

.sidebar-link:hover {
  background: var(--bg);
  color: var(--ink);
}

.sidebar-link.active {
  background: var(--brand-red-light);
  color: var(--brand-red-dark);
  font-weight: 600;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.sidebar-credit {
  margin: 0;
  font-size: 0.72rem;
  color: var(--ink-soft);
}

.sidebar-version {
  margin: 2px 0 0;
  font-size: 0.72rem;
  color: var(--ink-soft);
  opacity: 0.7;
}

.app-content {
  flex: 1;
  min-width: 0;
}

@media (max-width: 720px) {
  .app-shell {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    height: auto;
    flex-direction: row;
    align-items: center;
    padding: 12px 16px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .sidebar-brand {
    padding: 0 16px 0 0;
  }
  .sidebar-nav {
    flex-direction: row;
    flex: 1;
  }
  .sidebar-footer {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
    text-align: right;
  }
}

/* Passphrase gate */
.passphrase-gate {
  min-height: calc(100vh - 40px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

#app-body {
  display: none;
}

html.authed #app-body {
  display: block;
}

html.authed .passphrase-gate {
  display: none;
}

.passphrase-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-hover);
  padding: 36px 32px;
  max-width: 360px;
  width: 100%;
  text-align: center;
}

.passphrase-card .logo {
  height: 36px;
  margin-bottom: 18px;
}

.passphrase-card h2 {
  margin: 0 0 6px;
  font-size: 1.15rem;
  color: var(--ink);
}

.passphrase-card p {
  margin: 0 0 18px;
  font-size: 0.88rem;
  color: var(--ink-soft);
}

#passphrase-input {
  width: 100%;
  padding: 12px 14px;
  font-size: 1rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  margin-bottom: 14px;
  text-align: center;
}

#passphrase-input:focus {
  border-color: var(--brand-red);
  box-shadow: 0 0 0 3px var(--brand-red-light);
}

.primary-button {
  width: 100%;
  padding: 12px;
  background: var(--brand-red);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
}

.primary-button:hover { background: var(--brand-red-dark); }
.primary-button:disabled { opacity: 0.6; cursor: not-allowed; }

.passphrase-error {
  color: var(--brand-red-dark) !important;
  font-size: 0.82rem !important;
  margin-top: 10px !important;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
}

/* Header */
.site-header {
  background: #FFFFFF;
  border-bottom: 3px solid var(--brand-red);
  padding: 24px 20px;
}

.header-inner {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 20px;
}

.logo {
  height: 42px;
  width: auto;
  flex-shrink: 0;
}

.header-text h1 {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--ink);
}

.header-text p {
  margin: 4px 0 0;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

/* Main layout */
main {
  max-width: 900px;
  margin: 0 auto;
  padding: 32px 20px 60px;
}

/* Search */
.search-section {
  margin-bottom: 36px;
}

.search-box {
  display: flex;
  align-items: stretch;
  gap: 10px;
}

#search-input {
  flex: 1;
  min-width: 0;
  padding: 16px 20px;
  font-size: 1.05rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  background: var(--card-bg);
  color: var(--ink);
}

#search-input:focus {
  border-color: var(--brand-red);
  box-shadow: 0 0 0 3px var(--brand-red-light);
}

.ask-button {
  padding: 0 24px;
  background: var(--brand-red);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease;
  flex-shrink: 0;
}

.ask-button:hover { background: var(--brand-red-dark); }
.ask-button:disabled { opacity: 0.6; cursor: not-allowed; }

.search-hint {
  margin: 10px 2px 0;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.search-hint.status-searching { color: var(--brand-red-dark); }
.search-hint.status-ready { color: #2E7D32; }

/* Categories */
.categories-section h2,
.results-header h2 {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0 0 14px;
  color: var(--ink);
}

.category-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.category-chip {
  background: var(--card-bg);
  border: 1.5px solid var(--border);
  color: var(--ink);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.category-chip:hover {
  border-color: var(--brand-red);
  color: var(--brand-red-dark);
  box-shadow: var(--shadow-hover);
}

.category-chip.active {
  background: var(--brand-red);
  border-color: var(--brand-red);
  color: #fff;
}

/* Results */
.results-section {
  margin-top: 28px;
}

.results-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 4px;
}

.link-button {
  background: none;
  border: none;
  color: var(--brand-red-dark);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 0;
}

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

.results-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 14px;
}

/* Direct answer */
.answer-section {
  margin-top: 28px;
}

.direct-answer {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-left: 4px solid var(--brand-red);
  border-radius: var(--radius);
  padding: 22px 24px;
  box-shadow: var(--shadow);
  margin-top: 14px;
}

.direct-answer-text {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--ink);
  line-height: 1.6;
  white-space: pre-wrap;
}

.ai-disclaimer {
  margin: 14px 0 0;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--ink-soft);
}

/* Answer cards */
.answer-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-left: 4px solid var(--brand-red);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}

.answer-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.answer-category {
  display: inline-block;
  background: var(--brand-red-light);
  color: var(--brand-red-dark);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 3px 10px;
  border-radius: 999px;
}

.answer-citation {
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.answer-question {
  margin: 0 0 8px;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--ink);
}

.answer-short {
  margin: 0 0 10px;
  color: var(--ink);
  font-size: 0.96rem;
}

.answer-details summary {
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--brand-red-dark);
  font-weight: 600;
  outline: none;
}

.answer-full {
  margin: 10px 0 0;
  padding: 12px 14px;
  background: var(--bg);
  border-radius: 6px;
  font-size: 0.88rem;
  color: var(--ink-soft);
  font-style: italic;
  white-space: pre-wrap;
}

.match-score {
  font-size: 0.72rem;
  color: var(--ink-soft);
  font-weight: 400;
  text-transform: none;
  margin-left: 8px;
}

/* Fallback */
.fallback-section {
  margin-top: 28px;
}

.fallback-card {
  background: var(--brand-red-light);
  border: 1px solid #F5C6C5;
  border-radius: var(--radius);
  padding: 22px 24px;
  text-align: center;
}

.fallback-card h3 {
  margin: 0 0 8px;
  color: var(--brand-red-dark);
  font-size: 1.05rem;
}

.fallback-card p {
  margin: 4px 0;
  color: var(--ink);
}

.contact-line a {
  color: var(--brand-red-dark);
  font-weight: 600;
}

/* Footer */
.site-footer {
  max-width: 900px;
  margin: 0 auto;
  padding: 24px 20px 40px;
  font-size: 0.78rem;
  color: var(--ink-soft);
  text-align: center;
  border-top: 1px solid var(--border);
}

.site-footer a { color: var(--brand-red-dark); }

.model-status {
  margin-top: 8px;
  font-size: 0.72rem;
  opacity: 0.8;
}

@media (max-width: 600px) {
  .header-inner { gap: 14px; }
  .logo { height: 32px; }
  .header-text h1 { font-size: 1.15rem; }
}
