: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 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 12px 22px;
}

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

/* Settings gear (injected by settings.js next to the logo) + the MasterTravel-gated
   modal it opens. */
.settings-gear-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  border: none;
  border-radius: 8px;
  background: none;
  color: var(--ink-soft);
  cursor: pointer;
  padding: 0;
}
.settings-gear-btn:hover { background: var(--bg); color: var(--ink); }
.settings-gear-btn svg { width: 18px; height: 18px; }

.settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.settings-overlay[hidden] { display: none; }

.settings-modal {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-hover);
  padding: 28px 30px;
  max-width: 380px;
  width: 100%;
}
.settings-modal[hidden] { display: none; }
.settings-modal h2 { margin: 0 0 6px; font-size: 1.2rem; color: var(--ink); }
.settings-modal .settings-lead { margin: 0 0 18px; font-size: 0.92rem; color: var(--ink-soft); }

.settings-field { margin-bottom: 16px; }
.settings-field label {
  display: block;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 6px;
}
.settings-modal input[type="password"],
.settings-modal input[type="email"],
.settings-modal select {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.96rem;
  color: var(--ink);
  font-family: inherit;
  outline: none;
  background: #fff;
  box-sizing: border-box;
}
.settings-modal input[type="password"]:focus,
.settings-modal input[type="email"]:focus,
.settings-modal select:focus { border-color: var(--brand-red); }

.settings-error {
  margin: 6px 0 0;
  font-size: 0.86rem;
  color: var(--brand-red-dark);
  font-weight: 600;
}
.settings-error[hidden] { display: none; }

.settings-success {
  margin: 14px 0 0;
  font-size: 0.86rem;
  color: var(--brand-red-dark);
  font-weight: 600;
}
.settings-success[hidden] { display: none; }

.settings-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 4px;
}
.settings-btn-primary {
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius);
  background: var(--brand-red);
  color: #fff;
  font-size: 0.96rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.settings-btn-primary:hover { background: var(--brand-red-dark); }
.settings-btn-secondary {
  padding: 10px 20px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  font-size: 0.96rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.settings-btn-secondary:hover { border-color: var(--ink-soft); background: var(--bg); }

.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;
}

/* Travel BI Dashboard, Insurance Days Calculation, Travel Requests Report, and AirPlus
   Approval are only shown to the "full" access password (MasterTravel) */
.sidebar-link[href="/travel-bi/"],
.sidebar-link[href="/insurance-days/"],
.sidebar-link[href="/travel-requests-report/"],
.sidebar-link[href="/airplus-approval/"] {
  display: none;
}

html.bi-access .sidebar-link[href="/travel-bi/"],
html.bi-access .sidebar-link[href="/insurance-days/"],
html.bi-access .sidebar-link[href="/travel-requests-report/"],
html.bi-access .sidebar-link[href="/airplus-approval/"] {
  display: block;
}

.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;
}

.sidebar-logout {
  display: none;
  margin-top: 12px;
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: none;
  color: var(--ink-soft);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.sidebar-logout:hover {
  background: var(--brand-red-light);
  color: var(--brand-red-dark);
  border-color: var(--brand-red);
}

html.authed .sidebar-logout {
  display: block;
}

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

@media (max-width: 720px) {
  .app-shell {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    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 1 auto;
    min-width: 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .sidebar-nav::-webkit-scrollbar {
    display: none;
  }
  .sidebar-link {
    flex-shrink: 0;
    white-space: nowrap;
  }
  /* flex-basis:100% forces the footer onto its own row below brand+nav, then lays out
     its own contents (credit, version, logout) inline instead of stacked, since there's
     no room to stack them vertically in a compact mobile header. */
  .sidebar-footer {
    flex-basis: 100%;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
  }
  .sidebar-credit,
  .sidebar-version {
    margin: 0;
  }
  .sidebar-logout {
    width: auto;
    margin-top: 0;
  }
}

/* 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;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.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; }
}
