/* QHT Data Finder — Gemini-inspired light UI */

:root {
  --bg: #ffffff;
  --bg-tint: radial-gradient(1200px 800px at 100% 0%, #e5edff 0%, #f4f6fb 40%, #ffffff 100%);
  --sidebar: #f7f8fa;
  --sidebar-hover: #eef0f4;
  --sidebar-active: #dce4f5;
  --text: #1f1f1f;
  --text-muted: #6b7280;
  --text-faint: #9ca3af;
  --border: #e5e7eb;
  --border-strong: #d0d5dd;
  --accent: #1a73e8;
  --accent-purple: #a142f4;
  --composer-bg: #ffffff;
  --composer-shadow: 0 8px 30px rgba(60, 64, 67, 0.14);
  --card-bg: #ffffff;
  --card-hover: #f7f9fc;
  --pill-bg: #eff2f7;
  --pill-strong: #e2e8f2;
  --success: #34a853;
  --success-tint: #e6f4ea;
  --success-text: #137333;
  --warning: #fbbc04;
  --warning-tint: #fef7e0;
  --warning-text: #a56c00;
  --danger: #ea4335;
  --danger-tint: #fce8e6;
  --danger-text: #b31412;
  --code-bg: #f5f7fa;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  font-family: 'Google Sans Text', 'Google Sans', -apple-system, BlinkMacSystemFont,
               'Segoe UI', Roboto, system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* APP LAYOUT */
.app {
  display: grid;
  grid-template-columns: 260px 1fr;
  height: 100vh;
  overflow: hidden;
}

/* SIDEBAR */
.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.brand {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px 18px;
  font-size: 17px;
  font-weight: 500;
}
.brand-logo {
  font-size: 20px;
  background: linear-gradient(135deg, #4285f4, #a142f4);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.brand-name { color: var(--text); }

.side-btn {
  display: flex; align-items: center; gap: 12px;
  width: 100%;
  padding: 10px 14px;
  border: 0;
  background: transparent;
  border-radius: 999px;
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: background 0.15s;
}
.side-btn:hover { background: var(--sidebar-hover); }
.side-btn.primary {
  background: var(--pill-bg);
  font-weight: 500;
}
.side-btn.primary:hover { background: var(--pill-strong); }
.side-btn .ic {
  font-size: 15px;
  opacity: 0.85;
  min-width: 18px;
  display: inline-flex;
  justify-content: center;
}

.side-section {
  padding: 20px 14px 6px;
  font-size: 11px;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  text-transform: none;
  font-weight: 500;
}

.recent-list {
  flex: 1;
  overflow-y: auto;
  padding-bottom: 8px;
}
.recent-item {
  display: block;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  border: 0;
  background: transparent;
  width: 100%;
  text-align: left;
  font-family: inherit;
}
.recent-item:hover { background: var(--sidebar-hover); }
.recent-item.active { background: var(--sidebar-active); font-weight: 500; }
.recent-empty {
  padding: 8px 14px;
  font-size: 12px;
  color: var(--text-faint);
}

.side-footer {
  padding: 8px 4px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}
.user {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 8px;
  border-radius: 999px;
}
.user:hover { background: var(--sidebar-hover); }
.avatar-sm {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ff6a3d, #ffb84d);
  color: white;
  font-weight: 600;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.user-info {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.user-name {
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-plan {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 5px;
}
.status-dot {
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-faint);
}
.status-dot.ok { background: var(--success); }
.status-dot.err { background: var(--danger); }

/* MAIN CHAT */
.chat {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-tint);
  position: relative;
  min-width: 0;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 40px 24px 200px;
  scroll-behavior: smooth;
}

/* EMPTY STATE */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: calc(100vh - 260px);
  padding: 0 24px;
}
.empty-state h1 {
  font-size: 42px;
  font-weight: 400;
  margin: 0;
  line-height: 1.2;
  background: linear-gradient(90deg, #4285f4, #a142f4 55%, #ff6a3d);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.5px;
  max-width: 800px;
}
.empty-hint {
  color: var(--text-muted);
  font-size: 14px;
  margin: 14px 0 0;
}

/* MESSAGES */
.msg {
  max-width: 820px;
  margin: 0 auto 18px;
  display: flex;
  gap: 12px;
}
.msg .avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
  color: white;
}
.msg.user .avatar {
  background: linear-gradient(135deg, #ff6a3d, #ffb84d);
}
.msg.bot .avatar {
  background: linear-gradient(135deg, #4285f4, #a142f4);
}
.msg .body {
  flex: 1;
  min-width: 0;
}
.msg .who {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.msg .content {
  font-size: 15px;
  line-height: 1.65;
  color: var(--text);
  word-wrap: break-word;
}
.msg.bot .content {
  background: white;
  padding: 14px 18px;
  border-radius: 18px;
  border: 1px solid var(--border);
  box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}
.msg.bot.clarify .content {
  border-color: var(--warning);
  background: var(--warning-tint);
}
.msg.bot.trusted .content { border-color: #cfe6d5; }

/* Typing dots */
.typing {
  display: inline-flex;
  gap: 4px;
  margin-right: 8px;
  vertical-align: middle;
}
.typing span {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: bounce 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}
.stage-text {
  color: var(--text-muted);
  font-size: 13px;
}

/* Plan chips */
.plan-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}
.plan-chip {
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--pill-bg);
  color: var(--text);
  font-size: 12px;
}
.plan-chip.kw {
  background: #e8f0fe;
  color: #1967d2;
}

/* Banners */
.trust-banner, .critic-banner {
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 13px;
  margin-bottom: 10px;
}
.trust-banner {
  background: var(--success-tint);
  color: var(--success-text);
}
.critic-banner.revise {
  background: var(--warning-tint);
  color: var(--warning-text);
}
.critic-banner.insufficient {
  background: var(--danger-tint);
  color: var(--danger-text);
}

/* Answer text */
.answer-text {
  white-space: pre-wrap;
  word-wrap: break-word;
}
.answer-text a {
  color: var(--accent);
  text-decoration: none;
  word-break: break-all;
}
.answer-text a:hover { text-decoration: underline; }

/* Drag & drop overlay — shown when user drags a photo over the chat area */
.drop-overlay {
  position: absolute;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  pointer-events: none;
  transition: opacity 0.15s;
}
.drop-overlay.active {
  display: flex;
}
.drop-card {
  border: 2.5px dashed var(--accent);
  border-radius: 20px;
  padding: 44px 60px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 8px 40px rgba(66, 133, 244, 0.15);
  text-align: center;
  animation: pop 0.2s ease-out;
}
@keyframes pop {
  from { transform: scale(0.94); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}
.drop-icon {
  font-size: 48px;
  margin-bottom: 10px;
}
.drop-title {
  font-size: 22px;
  font-weight: 500;
  background: linear-gradient(90deg, #4285f4, #a142f4);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 6px;
}
.drop-sub {
  color: var(--text-muted);
  font-size: 14px;
}

/* Photo upload preview (face search) */
.upload-preview {
  max-width: 220px;
  max-height: 220px;
  border-radius: 12px;
  border: 1px solid var(--border);
  margin-bottom: 8px;
  display: block;
}
.upload-hint {
  font-size: 12px;
  color: var(--text-muted);
  font-style: italic;
}

/* File cards */
.files {
  display: block;
  margin-top: 14px;
}
.files-visible, .files-hidden {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 8px;
}
.files-hidden { margin-top: 8px; }
/* Fallback when the visible/hidden wrappers aren't present (small
   result sets bypass the show-more collapse and go straight to a
   single grid inside .files). */
.files > .file-card {
  display: inline-flex;
}
.files:not(:has(.files-visible)) {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 8px;
}
.show-more-btn {
  margin-top: 10px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  border-radius: 999px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s, border-color 0.15s;
}
.show-more-btn:hover {
  background: var(--card-hover);
  border-color: var(--border-strong);
}
.show-more-btn .chev { font-size: 11px; opacity: 0.7; }
.file-card {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  text-decoration: none;
  color: var(--text);
  transition: background 0.15s, border-color 0.15s;
}
.file-card:hover {
  background: var(--card-hover);
  border-color: var(--border-strong);
}
.file-icon { font-size: 20px; }
.file-main { flex: 1; min-width: 0; }
.file-name {
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 3px;
}
.file-badge {
  background: var(--pill-bg);
  padding: 1px 6px;
  border-radius: 4px;
  margin-right: 6px;
}

/* COMPOSER */
.composer {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 14px 24px 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: linear-gradient(180deg, rgba(255,255,255,0), rgba(255,255,255,0.94) 45%);
  pointer-events: none;
}
.composer > * { pointer-events: auto; }

.composer-pill {
  width: 100%;
  max-width: 820px;
  display: flex;
  align-items: flex-end;
  gap: 6px;
  padding: 8px;
  background: var(--composer-bg);
  border-radius: 28px;
  box-shadow: var(--composer-shadow);
  border: 1px solid var(--border);
}

.round-btn {
  width: 40px; height: 40px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
  font-family: inherit;
}
.round-btn:hover:not(:disabled) { background: var(--sidebar-hover); }
.round-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.add-btn {
  color: var(--text-muted);
  font-weight: 400;
}
.add-btn:hover { color: var(--accent); background: #e8f0fe; }

/* File input intentionally kept in the DOM tree (not `display:none`) so
   Chrome's file-picker fires reliably when we call input.click(). Some
   Chromium builds silently no-op programmatic .click() on display-none
   inputs — moving them out of the layout with position:absolute avoids
   that entirely. */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}
.send-btn {
  background: #1f1f1f;
  color: white;
}
.send-btn:hover:not(:disabled) { background: #000; }
.send-btn:disabled { background: #d0d5dd; color: white; opacity: 1; }

.stop-btn {
  background: var(--danger);
  color: white;
  animation: pulse 1.6s ease-in-out infinite;
}
.stop-btn:hover { background: #c5221f; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(234, 67, 53, 0.4); }
  50% { box-shadow: 0 0 0 6px rgba(234, 67, 53, 0); }
}

#input {
  flex: 1;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  padding: 10px 8px;
  font-family: inherit;
  font-size: 15px;
  color: var(--text);
  max-height: 200px;
  min-height: 24px;
  line-height: 1.4;
}
#input::placeholder { color: var(--text-faint); }

.composer-hint {
  font-size: 11px;
  color: var(--text-faint);
  text-align: center;
}

/* SCROLLBARS */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: #d6dae2;
  border-radius: 5px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover {
  background: #b8bec9;
  background-clip: padding-box;
}

/* RESPONSIVE */
@media (max-width: 768px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .empty-state h1 { font-size: 30px; }
  .messages { padding: 24px 16px 180px; }
  .composer { padding: 12px 12px 16px; }
}
