* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif; background: #f6f7fb; color: #1f2937; }
:root { --content-max-width: 800px; --font-xs: 12px; --font-sm: 14px; --font-md: 16px; --btn-font-size: var(--font-md); }
html { scrollbar-gutter: stable both-edges; }
.topbar { background: rgba(255,255,255,0.9); -webkit-backdrop-filter: saturate(180%) blur(6px); backdrop-filter: saturate(180%) blur(6px); color: #111827; padding: 8px 16px; border-bottom: 1px solid #e5e7eb; display: flex; align-items: center; gap: 8px; position: sticky; top: 0; z-index: 100; }
.topbar .spacer { flex: 1; }
.topbar h1, .topbar h2, .topbar h4 { margin: 0; font-size: var(--btn-font-size); font-weight: 600; line-height: 1.2; }
.container { max-width: 1100px; margin: 24px auto; padding: 0 16px; display: grid; grid-template-columns: 1fr; gap: 20px; }
.card { background: #fff; border-radius: 10px; padding: 16px; box-shadow: 0 1px 2px rgba(0,0,0,0.05); }
.card--wide { grid-column: 1 / -1; }
/* Hero banner */
.hero { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 24px; padding-top: 40px; padding-bottom: 30px; min-height: 60vh; }


.logo { font-size: 96px; font-weight: 700; letter-spacing: 6px; text-align: center; }

.g-blue { color: #4285F4; }
.g-red { color: #DB4437; }
.g-yellow { color: #F4B400; }
.g-green { color: #0F9D58; }
.searchbar { position: relative; display: block; width: 584px; margin: 0 auto; }
.search-input { width: 100%; height: 52px; padding: 0 52px 0 24px; font-size: 16px; border: 1px solid #dfe1e5; border-radius: 9999px; background: #fff; box-shadow: none; }
.search-input:hover { border-color: #dfe1e5; box-shadow: 0 1px 6px rgba(32,33,36,0.28); }
.search-input:focus { outline: none; border-color: #1a73e8; box-shadow: 0 0 0 2px rgba(26,115,232,0.20), 0 1px 6px rgba(32,33,36,0.20); }
body.dark .search-input:focus { outline: none; border-color: #8ab4f8; box-shadow: 0 0 0 2px rgba(138,180,248,0.20), 0 1px 6px rgba(0,0,0,0.30); }
.search-actions { display: flex; gap: 8px; align-items: center; }
button.ghost { background: #fff; border: 1px solid #d1d5db; }
/* Topbar ghost button styling for minimalist banner */
.topbar button.ghost { background: transparent; border: 1px solid #d1d5db; color: inherit; }
.topbar button.ghost:hover { filter: brightness(0.98); }
.settings { width: 100%; max-width: 584px; border: 1px solid #e5e7eb; border-radius: 10px; padding: 12px; background: #fff; }
.row { display: flex; align-items: center; gap: 12px; margin: 10px 0; flex-wrap: wrap; }
.row.wrap { flex-wrap: wrap; }
.row.no-grow { flex: 0 0 auto; }
.row.middle { justify-content: center; }
.row.cols { align-items: stretch; }
.row.push-right { margin-left: auto; }
label { font-weight: 600; }
label.block { display: block; }
textarea { width: 100%; padding: 10px 12px; border: 1px solid #e5e7eb; border-radius: 8px; background: #fafafa; }
input[type="number"], select { padding: 8px 10px; border: 1px solid #e5e7eb; border-radius: 8px; background: #fafafa; }
.leftpad { margin-left: 8px; }
button { padding: 10px 16px; border-radius: 10px; border: 1px solid #d1d5db; background: #fff; cursor: pointer; font-size: var(--btn-font-size); line-height: 1.1; }
button.primary { background: #4285F4; color: #fff; border-color: #4285F4; }
button:hover { filter: brightness(0.98); }


.panel { background: #ffffff; border: 1px solid #e5e7eb; border-radius: 10px; padding: 12px; width: 100%; min-height: 80px; overflow: auto; white-space: pre-wrap; }
.results { display: grid; grid-template-columns: 1fr; gap: 12px; width: 100%; }
.hit { border: 1px solid #e5e7eb; border-radius: 10px; padding: 12px; background: #fafbff; }
.dropzone { width: 100%; border: 2px dashed #d1d5db; border-radius: 10px; padding: 32px; text-align: center; color: #6b7280; background: #fff; min-height: 240px; display: flex; align-items: center; justify-content: center; }
.dropzone.dragover { border-color: #2f6db5; color: #1f2937; background: #f5faff; }

/* Dropzone inner layout */
.dz-inner { display: flex; flex-direction: column; gap: 6px; align-items: center; justify-content: center; width: 100%; max-width: 800px; }
.dz-header { font-weight: 700; font-size: 16px; color: #1f2937; }
.dz-desc { font-size: 13px; color: #6b7280; }
.dz-hint { font-size: 12px; color: #6b7280; }
.dz-status { font-size: 12px; color: #374151; }
.hit-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.hit-title { font-weight: 700; font-size: 14px; }
.hit-meta { font-size: 12px; color: #6b7280; margin-bottom: 6px; }
.hit-content { font-size: 14px; margin-bottom: 6px; }
.badge { display: inline-block; background: #eef2ff; color: #1e3a8a; padding: 2px 6px; border-radius: 999px; font-size: 11px; margin-left: 6px; }
.muted { color: #6b7280; font-size: 12px; }
.toast { position: fixed; bottom: 16px; right: 16px; background: #111827; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,0.15); }
.loader { display: flex; align-items: center; gap: 8px; color: #4b5563; }
.spinner { width: 18px; height: 18px; border: 2px solid #d1d5db; border-top-color: #2f6db5; border-radius: 50%; animation: spin 1s linear infinite; }
.spinner.small { width: 14px; height: 14px; }

/* Deep Research icon/button */
.dr-icon { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); border-radius: 9999px; background: #fff; color: #0b0b0b; border: 1px solid #d1d5db; height: 44px; width: 44px; display: inline-flex; align-items: center; justify-content: center; font-size: 20px; }
.dr-icon::after { content: ""; position: absolute; inset: -3px; border-radius: inherit; padding: 2px; background: conic-gradient(#f00,#ff0,#0f0,#0ff,#00f,#f0f,#f00); -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0); -webkit-mask-composite: xor; mask-composite: exclude; opacity: 0; transition: opacity .2s ease; animation: spin 3s linear infinite; }
.dr-icon:hover { background: #fff; border-color: transparent; color: #0b0b0b; box-shadow: none; }
.dr-icon:hover::after { opacity: 0.9; }

/* Make DR title more prominent */
.dr-title strong { font-size: 18px; }
.microscope-icon { filter: grayscale(100%); font-size: 20px; }

/* Deep Research modal */
.dr-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.25); backdrop-filter: blur(2px); }
.dr-modal { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(900px, calc(100% - 80px)); max-height: 80vh; background: #fff; border: 1px solid #e5e7eb; border-radius: 12px; box-shadow: 0 12px 40px rgba(0,0,0,0.18); display: flex; flex-direction: column; }
.dr-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 14px; border-bottom: 1px solid #e5e7eb; font-size: 16px; }
.dr-chat { padding: 14px; overflow: auto; flex: 1; }
.dr-input { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid #e5e7eb; }
.dr-input input { flex: 1; padding: 10px 12px; border: 1px solid #e5e7eb; border-radius: 10px; background: #fafafa; }
.dr-msg { margin: 6px 0; display: flex; }
.dr-msg.me { justify-content: flex-end; }
.dr-msg .bubble { max-width: 80%; padding: 8px 12px; border-radius: 12px; border: 1px solid #e5e7eb; background: #f5faff; }
.dr-chat pre.code { background: #0f172a0d; border: 1px solid #e5e7eb; border-radius: 8px; padding: 10px; overflow: auto; }
.dr-chat code { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; font-size: 12px; }
.dr-msg.me .bubble { background: #e0efff; border-color: #dbeafe; }

/* Brain icon next to title */
.brain-icon { margin-left: 8px; filter: grayscale(100%); }

/* Thinking animation */
.dr-thinking { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 12px; border: 1px solid #e5e7eb; background: #fafafa; color: #4b5563; font-size: 13px; }
.dr-thinking .dots { display: inline-flex; gap: 2px; }
.dr-thinking .dot { width: 4px; height: 4px; border-radius: 50%; background: currentColor; opacity: 0.3; animation: blink 1.2s infinite; }
/* Inline dots (no bubble) */
.dr-thinking-inline { display: inline-flex; align-items: center; gap: 6px; color: #4b5563; margin: 4px 0; }
.dr-thinking-inline .dots { display: inline-flex; gap: 2px; }
.dr-thinking-inline .dot { width: 4px; height: 4px; border-radius: 50%; background: currentColor; opacity: 0.3; animation: blink 1.2s infinite; }
.dr-thinking .dot:nth-child(2) { animation-delay: .2s; }
.dr-thinking .dot:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.3; } 40% { opacity: 1; } }

/* Dark mode for DR */
body.dark .dr-modal { background: #0b1220; border-color: #1f2937; }
body.dark .dr-header { border-bottom-color: #1f2937; }
body.dark .dr-input { border-top-color: #1f2937; }
body.dark .dr-input input { background: #0b1220; color: #e5e7eb; border-color: #1f2937; }
body.dark .dr-msg .bubble { background: #0e1530; border-color: #1f2937; }
body.dark .dr-msg.me .bubble { background: #122255; border-color: #1f2937; }


/* Collapsible toggles */
.collapsible-toggle { display: flex; align-items: center; gap: 6px; width: 100%; justify-content: flex-start; font-size: var(--btn-font-size); font-weight: 600; }
.collapsible-toggle .caret { display: inline-block; transition: transform .2s ease; }

/* Upload progress */
.progress-list { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.progress-item { background: #fff; border: 1px solid #e5e7eb; border-radius: 10px; padding: 8px 10px; }
.progress-row { display: flex; align-items: center; justify-content: space-between; font-size: 12px; color: #4b5563; margin-bottom: 6px; }
.progress { width: 100%; height: 8px; background: #eef2ff; border-radius: 999px; overflow: hidden; }
.refresh-icon { font-size: 18px; line-height: 1; }

/* Search actions under bar */
.search-actions-row { display: flex; gap: 10px; justify-content: center; margin-top: 8px; width: 584px; margin-left: auto; margin-right: auto; }

/* Unified controls wrapper width */
.controls-wrap { width: 100%; max-width: var(--content-max-width); margin: 0 auto; }

/* Constrain answer and results rows to shared width */
#answerRow, #resultsRow { width: 100%; max-width: var(--content-max-width); margin-left: auto; margin-right: auto; }

/* KB single-line row layout */
.hit-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.hit-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.hit-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* Hover polish */
.hit:hover { background: #f5faff; border-color: #dbeafe; }
.badge:hover { filter: brightness(0.96); }
body.dark .hit:hover { background: #0e1530; border-color: #1f2937; }
.progress-bar { height: 100%; width: 0%; background: #2f6db5; transition: width .2s ease; }

@keyframes spin { to { transform: rotate(360deg); } }
@media (min-width: 900px) { .container { grid-template-columns: 1fr 1fr; } .card--wide { grid-column: 1 / span 2; } }



/* Dark mode */
body.dark { background: #0f172a; color: #e5e7eb; }
body.dark .topbar { background: rgba(15,23,42,0.9); color: #e5e7eb; border-bottom-color: #1f2937; }
body.dark .topbar button.ghost { background: transparent; border-color: #1f2937; color: #e5e7eb; }
body.dark .card { background: #0b1220; box-shadow: none; border: 1px solid #1f2937; }
body.dark .settings, body.dark .panel { background: #0b1220; border-color: #1f2937; color: #e5e7eb; }
body.dark .search-input { background: #0b1220; color: #e5e7eb; border-color: #1f2937; }
body.dark button { background: #0b1220; color: #e5e7eb; border-color: #1f2937; }
body.dark button.primary { background: #4285F4; border-color: #4285F4; }
body.dark .dropzone { background: #0b1220; border-color: #1f2937; color: #94a3b8; }
body.dark .dz-header { color: #e5e7eb; }
body.dark .dz-desc, body.dark .dz-hint, body.dark .dz-status, body.dark .muted { color: #94a3b8; }
body.dark .dropzone.dragover { background: #0e1530; border-color: #265fa3; color: #e5e7eb; }
body.dark .hit { background: #0e1530; border-color: #1f2937; }
body.dark .badge { background: #122255; color: #c7d2fe; }

/* SpacesAI additions */
.user-controls { display: flex; align-items: center; gap: 10px; }
.user-email { font-weight: 600; font-size: var(--btn-font-size); }
.auth { width: 100%; max-width: 900px; display: flex; justify-content: flex-start; }
.auth .row.cols { display: grid; grid-template-columns: 1fr; gap: 12px; width: 100%; justify-content: center; justify-items: center; }
.auth-card { border: 1px solid #e5e7eb; border-radius: 10px; padding: 12px; background: #fff; width: 100%; max-width: 420px; }
.auth-card h3 { margin-top: 0; }
.auth-card input { width: 100%; padding: 10px 12px; border: 1px solid #e5e7eb; border-radius: 8px; background: #fafafa; margin-bottom: 8px; }
.app-panel input { padding: 8px 10px; border: 1px solid #e5e7eb; border-radius: 8px; background: #fafafa; }
@media (min-width: 800px) { .auth .row.cols { grid-template-columns: 1fr 1fr; justify-content: center; justify-items: center; } }

body.dark .auth-card { background: #0b1220; border-color: #1f2937; }
body.dark .auth-card input, body.dark .app-panel input { background: #0b1220; color: #e5e7eb; border-color: #1f2937; }

/* Responsive widths for search bar, actions, and settings */
@media (max-width: 1280px) {
  .searchbar { width: 584px; }
  .search-actions-row { width: 584px; }
  .settings { max-width: 584px; }
  .logo { font-size: 84px; }
}
@media (max-width: 1024px) {
  .searchbar { width: 600px; }
  .search-actions-row { width: 600px; }
  .settings { max-width: 600px; }
  .logo { font-size: 72px; }
}
@media (max-width: 768px) {
  .searchbar { width: calc(100% - 32px); }
  .search-actions-row { width: calc(100% - 32px); }
  .settings { max-width: calc(100% - 32px); }
  .logo { font-size: 56px; }
}

/* Dark mode tweaks */
body.dark .dr-icon { background: #0b1220; border-color: #1f2937; color: #e5e7eb; }
body.dark .dr-icon:hover { background: #0b1220; border-color: transparent; color: #e5e7eb; }