:root {
  --primary: #1565c0;
  --primary-dark: #0d47a1;
  --accent: #3f8efc;
  --background: #f7f9fc;
  --surface: #ffffff;
  --surface-soft: #eef4fc;
  --text: #1d2633;
  --muted: #667085;
  --border: #dce4ef;
  --danger: #b42318;
  --shadow: 0 18px 55px rgba(26, 64, 115, .10);
}

:root[data-theme="dark"] {
  --background: #0d1420;
  --surface: #151f2e;
  --surface-soft: #1d2a3d;
  --text: #f3f6fb;
  --muted: #aab6c8;
  --border: #2b3a50;
  --shadow: 0 18px 55px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; background: var(--background); color: var(--text); min-height: 100vh; }
a { color: var(--primary); text-decoration: none; }
button, input, select { font: inherit; }
button { cursor: pointer; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.site-header { min-height: 72px; padding: 18px clamp(20px, 5vw, 72px); display: flex; align-items: center; justify-content: space-between; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); font-size: 22px; font-weight: 800; letter-spacing: -.5px; }
.brand-mark { width: 38px; height: 38px; border-radius: 13px; display: inline-grid; place-items: center; color: #fff; background: linear-gradient(145deg, var(--accent), var(--primary-dark)); box-shadow: 0 8px 22px rgba(21,101,192,.26); }
.header-actions { display: flex; gap: 12px; align-items: center; }
.icon-button, .admin-link { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 12px; padding: 9px 13px; }
.icon-button { width: 42px; height: 42px; }

.main-shell { width: min(1180px, calc(100% - 32px)); margin: 0 auto; }
.search-hero { min-height: calc(100vh - 155px); display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 30px 0 120px; }
.search-hero.compact { min-height: auto; padding: 20px 0 34px; align-items: stretch; }
.hero-logo { width: 84px; height: 84px; border-radius: 28px; display: grid; place-items: center; color: white; background: linear-gradient(145deg, #4da0ff, #0d47a1); font-size: 48px; font-weight: 900; box-shadow: 0 22px 60px rgba(21,101,192,.30); transform: rotate(-4deg); }
.search-hero h1 { font-size: clamp(42px, 7vw, 70px); margin: 22px 0 4px; letter-spacing: -3px; }
.hero-subtitle { color: var(--muted); font-size: 18px; margin: 0 0 32px; }
.search-form { width: min(780px, 100%); min-height: 66px; display: flex; align-items: center; gap: 12px; border: 1px solid var(--border); background: var(--surface); border-radius: 22px; padding: 8px 9px 8px 20px; box-shadow: var(--shadow); transition: .2s ease; }
.search-hero.compact .search-form { width: 100%; }
.search-form:focus-within { border-color: var(--accent); box-shadow: 0 20px 65px rgba(21,101,192,.17); transform: translateY(-1px); }
.search-icon { font-size: 29px; color: var(--primary); transform: rotate(-20deg); }
.search-form input { flex: 1; min-width: 0; border: 0; outline: 0; color: var(--text); background: transparent; font-size: 18px; }
.search-form button, .stacked-form button { border: 0; color: white; background: linear-gradient(135deg, var(--accent), var(--primary-dark)); padding: 14px 25px; border-radius: 16px; font-weight: 750; box-shadow: 0 10px 25px rgba(21,101,192,.24); }
.search-form button:disabled { opacity: .6; cursor: wait; }
.search-options { width: min(780px, 100%); margin-top: 16px; display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 13px; }
.search-hero.compact .search-options { width: 100%; }
.search-options label { display: flex; align-items: center; gap: 9px; }
.search-options select { border: 1px solid var(--border); border-radius: 10px; color: var(--text); background: var(--surface); padding: 7px 10px; }
.suggestion-chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 30px; }
.suggestion-chips button { border: 1px solid var(--border); background: var(--surface); color: var(--muted); border-radius: 999px; padding: 10px 15px; }
.suggestion-chips button:hover { color: var(--primary); border-color: var(--primary); }

.status-panel, .error-panel { border-radius: 18px; margin-bottom: 24px; padding: 20px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); }
.status-panel { display: flex; gap: 16px; align-items: center; }
.status-panel[hidden], .error-panel[hidden], .results-grid[hidden] { display: none !important; }
.status-panel p { margin: 4px 0 0; color: var(--muted); }
.loader { width: 35px; height: 35px; border-radius: 50%; border: 4px solid var(--surface-soft); border-top-color: var(--primary); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.text-button { margin-left: auto; border: 0; color: var(--primary); background: transparent; }
.error-panel { color: var(--danger); border-color: rgba(180,35,24,.22); background: color-mix(in srgb, var(--surface) 92%, #ffddd8); }

.results-grid { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(310px, .75fr); gap: 24px; padding-bottom: 72px; align-items: start; }
.answer-card, .sources-panel, .admin-table-card { border: 1px solid var(--border); border-radius: 22px; background: var(--surface); box-shadow: var(--shadow); }
.answer-card { padding: clamp(22px, 4vw, 38px); }
.sources-panel { padding: 26px; position: sticky; top: 20px; max-height: calc(100vh - 40px); overflow: auto; }
.card-heading, .source-heading { display: flex; justify-content: space-between; gap: 18px; align-items: flex-start; border-bottom: 1px solid var(--border); padding-bottom: 20px; margin-bottom: 24px; }
.eyebrow { color: var(--primary); text-transform: uppercase; letter-spacing: 1.5px; font-size: 11px; font-weight: 850; }
.card-heading h2, .source-heading h2 { margin: 5px 0 0; font-size: 22px; }
.answer-actions { display: flex; gap: 8px; }
.secondary-button { color: var(--text); background: var(--surface-soft); border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; }
.answer-content { line-height: 1.75; font-size: 16px; }
.answer-content h2, .answer-content h3, .answer-content h4 { margin: 28px 0 10px; letter-spacing: -.4px; }
.answer-content p { margin: 0 0 15px; }
.answer-content li { margin: 7px 0; }
.inline-citation a { display: inline-grid; place-items: center; min-width: 22px; height: 20px; margin-left: 3px; padding: 0 4px; border-radius: 6px; background: var(--surface-soft); font-size: 11px; font-weight: 800; }
.answer-meta { border-top: 1px solid var(--border); padding-top: 18px; margin-top: 25px; display: flex; gap: 12px; color: var(--muted); font-size: 12px; }
.cache-badge { background: var(--surface-soft); color: var(--primary); border-radius: 999px; padding: 3px 8px; }
.feedback-row { margin-top: 20px; display: flex; gap: 9px; align-items: center; flex-wrap: wrap; color: var(--muted); font-size: 13px; }
.feedback-row button { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 999px; padding: 6px 11px; }
.source-card { display: grid; grid-template-columns: 32px 1fr; gap: 12px; padding: 18px 0; border-bottom: 1px solid var(--border); }
.source-card:last-child { border-bottom: 0; }
.source-number { width: 27px; height: 27px; display: grid; place-items: center; border-radius: 9px; background: var(--surface-soft); color: var(--primary); font-size: 12px; font-weight: 850; }
.source-domain, .source-url { color: var(--muted); font-size: 11px; overflow-wrap: anywhere; }
.source-card h3 { margin: 4px 0 8px; font-size: 15px; line-height: 1.35; }
.source-card p { color: var(--muted); font-size: 13px; line-height: 1.5; margin: 0 0 8px; }
.source-url { display: block; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty-state { color: var(--muted); }

.site-footer {
  padding: 22px clamp(20px, 5vw, 72px);
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  gap: 20px;
  color: var(--muted);
  font-size: 13px;
  border-top: 1px solid var(--border);
}
.footer-copyright { justify-self: start; }
.footer-center-message {
  justify-self: center;
  color: var(--text);
  font-weight: 750;
  letter-spacing: .1px;
  text-align: center;
}
.site-footer nav,
.footer-links { display: flex; gap: 18px; justify-self: end; }
.content-page { width: min(900px, calc(100% - 32px)); margin: 40px auto 100px; }
.content-page article { background: var(--surface); border: 1px solid var(--border); padding: clamp(28px, 6vw, 68px); border-radius: 24px; box-shadow: var(--shadow); }
.content-page h1 { font-size: clamp(34px, 5vw, 54px); margin-top: 0; }
.legal-content { line-height: 1.8; color: var(--muted); }

.admin-body { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth-card { width: min(440px, 100%); border: 1px solid var(--border); background: var(--surface); padding: 38px; border-radius: 24px; box-shadow: var(--shadow); }
.auth-card h1 { margin: 30px 0 8px; }
.auth-card > p { color: var(--muted); }
.stacked-form { display: grid; gap: 17px; margin-top: 25px; }
.stacked-form label { display: grid; gap: 7px; font-size: 13px; font-weight: 700; }
.stacked-form input { border: 1px solid var(--border); background: var(--background); color: var(--text); border-radius: 12px; padding: 13px; outline: none; }
.form-error { color: var(--danger); background: #fff0ee; padding: 12px; border-radius: 10px; font-size: 13px; }
.admin-header { min-height: 72px; padding: 15px 4vw; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); background: var(--surface); }
.admin-header nav { display: flex; align-items: center; gap: 18px; color: var(--muted); }
.dashboard-shell { width: min(1280px, calc(100% - 32px)); margin: 35px auto 80px; }
.dashboard-title h1 { font-size: 38px; margin: 5px 0 24px; }
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.stats-grid article { border: 1px solid var(--border); background: var(--surface); padding: 23px; border-radius: 18px; box-shadow: var(--shadow); }
.stats-grid span { display: block; color: var(--muted); font-size: 13px; }
.stats-grid strong { display: block; font-size: 31px; margin-top: 9px; }
.admin-table-card { padding: 25px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; border-bottom: 1px solid var(--border); padding: 13px 11px; }
th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .8px; }

@media (max-width: 880px) {
  .results-grid { grid-template-columns: 1fr; }
  .sources-panel { position: static; max-height: none; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
  .site-header { padding: 14px 16px; }
  .brand-small span:last-child { display: none; }
  .search-hero { padding-bottom: 60px; }
  .search-form { min-height: 58px; border-radius: 17px; padding-left: 14px; gap: 7px; }
  .search-form input { font-size: 15px; }
  .search-form button { padding: 12px 15px; border-radius: 13px; }
  .privacy-note { display: none; }
  .card-heading { flex-direction: column; }
  .answer-actions { width: 100%; }
  .answer-actions button { flex: 1; }
  .site-footer {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
  }
  .footer-copyright,
  .footer-center-message,
  .site-footer nav,
  .footer-links { justify-self: center; }
  .footer-center-message { order: -1; }
  .stats-grid { grid-template-columns: 1fr; }
  .admin-header nav span { display: none; }
}

/* Editable branding */
.brand-image {
  display: block;
  width: auto;
  height: auto;
  max-width: 230px;
  max-height: 50px;
  object-fit: contain;
}
.brand-image-login { max-width: 260px; max-height: 68px; }
.hero-brand-image {
  display: block;
  width: auto;
  height: auto;
  max-width: min(520px, 88vw);
  max-height: 190px;
  object-fit: contain;
  margin: 0 auto 18px;
}
.admin-notice { margin-bottom: 18px; padding: 14px 16px; border-radius: 12px; }
.form-success { background: #e9f8ef; color: #166534; }
.settings-card { max-width: 900px; margin: 0 0 24px; }
.branding-settings-card { max-width: 1120px; margin: 0 0 24px; }
.branding-settings-card > p { color: var(--muted); line-height: 1.65; }
.branding-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.branding-item { min-width: 0; border: 1px solid var(--border); background: var(--background); border-radius: 16px; padding: 16px; }
.branding-item small { display: block; color: var(--muted); line-height: 1.5; margin-top: -5px; }
.branding-preview { min-height: 118px; display: flex; align-items: center; justify-content: center; gap: 10px; padding: 15px; margin-bottom: 15px; overflow: hidden; border: 1px dashed var(--border); border-radius: 14px; background: var(--surface); }
.branding-preview img { display: block; max-width: 100%; max-height: 90px; width: auto; height: auto; object-fit: contain; }
.branding-preview-header img { max-height: 52px; }
.branding-preview-hero { flex-direction: column; }
.branding-preview-hero img { max-height: 100px; }
.branding-preview-favicon img { width: 64px; height: 64px; object-fit: contain; }
.mini-hero-mark { width: 52px; height: 52px; border-radius: 17px; display: grid; place-items: center; color: #fff; background: linear-gradient(145deg, #4da0ff, #0d47a1); font-size: 28px; font-weight: 900; transform: rotate(-4deg); }
.remove-branding-button { margin-top: 13px; border: 1px solid rgba(180,35,24,.28); background: #fff3f1; color: var(--danger); border-radius: 10px; padding: 9px 12px; box-shadow: none; font-weight: 700; }
.hidden-form { display: none; }

@media (max-width: 900px) {
  .branding-grid { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .brand-image { max-width: 180px; max-height: 42px; }
  .hero-brand-image { max-width: 88vw; max-height: 145px; }
}

/* Live-search API diagnostics */
.api-settings-card > p { color: var(--muted); line-height: 1.65; }
.api-status-row { display: flex; align-items: center; gap: 12px; padding: 14px 16px; margin-bottom: 14px; border: 1px solid var(--border); border-radius: 14px; background: var(--background); }
.api-status-row small { color: var(--muted); }
.api-status-dot { width: 12px; height: 12px; flex: 0 0 12px; border-radius: 50%; box-shadow: 0 0 0 4px rgba(180,35,24,.09); background: var(--danger); }
.api-status-dot.is-configured { background: #188038; box-shadow: 0 0 0 4px rgba(24,128,56,.11); }
.api-test-result { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; margin: 18px 0; padding: 14px 16px; border: 1px solid rgba(24,128,56,.25); border-radius: 14px; color: #166534; background: #e9f8ef; }
.api-test-result strong { width: 100%; }
.api-test-result span { font-size: 12px; }
.field-help { color: var(--muted); line-height: 1.5; }
.api-secondary-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--border); }
.api-secondary-actions form { margin: 0; }
.secondary-action-button { border: 1px solid var(--border); background: var(--surface-soft); color: var(--text); border-radius: 10px; padding: 10px 14px; font-weight: 700; }

/* Footer settings */
.footer-settings-card > p {
  color: var(--muted);
  line-height: 1.65;
}
.checkbox-setting {
  display: flex !important;
  align-items: center;
  gap: 10px !important;
  font-weight: 650 !important;
}
.checkbox-setting input {
  width: 18px;
  height: 18px;
  padding: 0;
  accent-color: var(--primary);
}
.footer-admin-preview {
  display: grid;
  gap: 7px;
  padding: 18px;
  border: 1px dashed var(--border);
  border-radius: 14px;
  background: var(--surface-soft);
  text-align: center;
}
.footer-admin-preview span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .09em;
  text-transform: uppercase;
}
.footer-admin-preview strong {
  color: var(--text);
  font-size: 15px;
}
