@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;1,9..40,300&family=DM+Mono:wght@400;500&display=swap');

/* ── CSS Variables ─────────────────────────────────────────────────────── */
:root {
  --bg:          #f0f2f5;
  --surface:     #ffffff;
  --surface-2:   #f7f8fa;
  --border:      #e2e6eb;
  --border-2:    #cdd3da;
  --navy:        #0c2d4e;
  --navy-mid:    #164a73;
  --blue:        #1a6fa8;
  --blue-light:  #e8f2fb;
  --accent:      #0e85c8;
  --user-bg:     #0e4d80;
  --user-fg:     #ffffff;
  --ai-bg:       #ffffff;
  --ai-fg:       #1a2535;
  --muted:       #6b7a8d;
  --success:     #1a7a4a;
  --radius:      14px;
  --radius-sm:   8px;
  --shadow:      0 1px 3px rgba(0,0,0,0.06), 0 4px 16px rgba(0,0,0,0.07);
  --shadow-lg:   0 8px 32px rgba(0,0,0,0.12);
  --font:        'DM Sans', sans-serif;
  --font-mono:   'DM Mono', monospace;
}

/* ── Reset ─────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  background-image:
    radial-gradient(ellipse at 20% 0%, rgba(14,133,200,0.08) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 100%, rgba(12,45,78,0.06) 0%, transparent 60%);
  background-attachment: fixed;
  color: var(--ai-fg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── App Shell ─────────────────────────────────────────────────────────── */
.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px 40px;
}

.qa-container {
  width: 100%;
  max-width: 860px;
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* ── Header ────────────────────────────────────────────────────────────── */
.qa-header {
  text-align: center;
  padding: 36px 24px 28px;
}

.qa-header h1 {
  font-size: clamp(1.8rem, 3.5vw, 2.6rem);
  font-weight: 600;
  color: var(--navy);
  letter-spacing: -0.03em;
  line-height: 1.15;
}

.who {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 400;
  letter-spacing: 0.01em;
}

/* ── Chat Section ──────────────────────────────────────────────────────── */
.chat-section {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  border: 1px solid var(--border);
}

.chat-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}

.chat-topbar h2 {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--navy);
  letter-spacing: 0.01em;
  text-transform: uppercase;
}

.chat-topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-status {
  color: var(--muted);
  font-size: 0.82rem;
  font-style: italic;
}

/* ── Chat Thread ───────────────────────────────────────────────────────── */
.chat-thread {
  height: 520px;
  overflow-y: auto;
  padding: 20px;
  scroll-behavior: smooth;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.chat-thread::-webkit-scrollbar { width: 6px; }
.chat-thread::-webkit-scrollbar-track { background: transparent; }
.chat-thread::-webkit-scrollbar-thumb { background: var(--border-2); border-radius: 10px; }
.chat-thread::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ── Empty State ───────────────────────────────────────────────────────── */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding: 48px 24px;
  color: var(--muted);
  gap: 12px;
}

.empty-state-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--navy-mid);
}

.empty-state-text {
  font-size: 0.92rem;
  max-width: 480px;
  line-height: 1.6;
  color: var(--muted);
}

/* ── Messages ──────────────────────────────────────────────────────────── */
.msg-row {
  display: flex;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg-row.user { justify-content: flex-end; }
.msg-row.assistant { justify-content: flex-start; }

.msg-bubble {
  max-width: min(720px, 85%);
  padding: 13px 16px;
  border-radius: var(--radius);
  line-height: 1.6;
  word-break: break-word;
}

.msg-bubble.user {
  background: var(--user-bg);
  color: var(--user-fg);
  border-bottom-right-radius: 4px;
}

.msg-bubble.assistant {
  background: var(--ai-bg);
  color: var(--ai-fg);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}

.msg-label {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 6px;
  opacity: 0.65;
}

.msg-content {
  font-size: 0.96rem;
  line-height: 1.65;
}

/* ── Sources Toggle ────────────────────────────────────────────────────── */
.sources-toggle {
  margin-top: 10px;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  background: transparent;
  border: 1px solid var(--border-2);
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.15s;
  box-shadow: none;
  margin-bottom: 0;
}

.sources-toggle:hover {
  background: var(--blue-light);
  border-color: var(--accent);
  color: var(--accent);
  transform: none;
  box-shadow: none;
}

.sources-block {
  margin-top: 8px;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-family: var(--font-mono);
  color: var(--muted);
  line-height: 1.7;
  border: 1px solid var(--border);
}

.sources-block.hidden { display: none; }

/* ── Follow-up Buttons ─────────────────────────────────────────────────── */
.follow-up-options {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.follow-up-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 14px;
  background: var(--blue-light);
  border: 1px solid rgba(14,133,200,0.25);
  border-radius: var(--radius-sm);
  color: var(--navy-mid);
  font-size: 0.88rem;
  font-family: var(--font);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  line-height: 1.4;
  box-shadow: none;
  margin: 0;
  white-space: normal;
  word-break: break-word;
  overflow: hidden;
}

.follow-up-btn:hover {
  background: #d0e8f7;
  border-color: var(--accent);
  color: var(--navy);
  transform: translateX(3px);
  box-shadow: none;
}

.follow-up-btn::before {
  content: "→ ";
  color: var(--accent);
  font-weight: 600;
}

/* ── Composer ──────────────────────────────────────────────────────────── */
.composer {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.composer textarea {
  flex: 1;
  min-height: 48px;
  max-height: 160px;
  resize: none;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-2);
  background: var(--surface);
  color: var(--ai-fg);
  font-family: var(--font);
  font-size: 0.95rem;
  line-height: 1.5;
  transition: border-color 0.15s;
  margin: 0;
  width: auto;
}

.composer textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(14,133,200,0.12);
}

.composer textarea::placeholder { color: var(--muted); }

.composer-actions {
  display: flex;
  align-items: flex-end;
}

/* ── Buttons ───────────────────────────────────────────────────────────── */
button, .btn {
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

#askBtn {
  padding: 12px 22px;
  background: var(--navy);
  color: white;
  border-color: var(--navy);
  box-shadow: 0 2px 8px rgba(12,45,78,0.25);
}

#askBtn:hover:not(:disabled) {
  background: var(--navy-mid);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(12,45,78,0.3);
}

#askBtn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.secondary-btn {
  padding: 7px 14px;
  background: var(--surface);
  color: var(--navy-mid);
  border-color: var(--border-2);
  font-size: 0.82rem;
  box-shadow: none;
}

.secondary-btn:hover {
  background: var(--blue-light);
  border-color: var(--accent);
  color: var(--accent);
  transform: none;
  box-shadow: none;
}

/* ── Upload Section ────────────────────────────────────────────────────── */
.upload-section {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  padding: 20px;
  margin-top: 12px;
}

.upload-section h2 {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--navy);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 14px;
  text-align: left;
}

.upload-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.upload-row input[type="file"] {
  flex: 1 1 260px;
  padding: 9px 12px;
  border: 1px solid var(--border-2);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ai-fg);
  font-family: var(--font);
  font-size: 0.88rem;
  margin: 0;
  width: auto;
}

#uploadBtn {
  padding: 9px 18px;
  background: var(--surface-2);
  color: var(--navy-mid);
  border-color: var(--border-2);
  box-shadow: none;
}

#uploadBtn:hover {
  background: var(--blue-light);
  border-color: var(--accent);
  color: var(--accent);
  transform: none;
  box-shadow: none;
}

.upload-status {
  margin-top: 10px;
  font-size: 0.84rem;
  color: var(--muted);
  min-height: 18px;
  text-align: left;
}

/* ── Login / Home pages ────────────────────────────────────────────────── */
.container, .home-screen {
  max-width: 860px;
  width: min(860px, calc(100vw - 32px));
  margin: 40px auto;
  background: var(--surface);
  padding: 40px 32px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  text-align: center;
  color: var(--ai-fg);
}

h1, h2 { color: var(--navy); }

.login-input {
  width: 320px;
  max-width: 90%;
  margin: 8px auto 16px;
  display: block;
  padding: 12px 14px;
  font-size: 0.95rem;
  font-family: var(--font);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-2);
  background: var(--surface);
  color: var(--ai-fg);
}

.login-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(14,133,200,0.12);
}

.btn.primary {
  background: var(--navy);
  color: white;
  border-color: var(--navy);
  padding: 11px 24px;
}

.btn.primary:hover {
  background: var(--navy-mid);
  transform: translateY(-1px);
}

.home-buttons {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  margin-top: 32px;
}

@media (min-width: 500px) {
  .home-buttons { flex-direction: row; justify-content: center; }
}

label { font-weight: 600; color: var(--navy); }
hr { border: none; border-top: 1px solid var(--border); margin: 24px 0; }

#response, #uploadStatus {
  background: var(--surface-2);
  padding: 14px;
  margin-top: 14px;
  border-radius: var(--radius-sm);
  font-size: 0.92rem;
  border: 1px solid var(--border);
  text-align: left;
}

/* ── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .app-shell { padding: 12px 10px 32px; }
  .qa-header { padding: 24px 16px 20px; }
  .chat-thread { height: 60vh; padding: 14px; }
  .msg-bubble { max-width: 92%; }
  .chat-topbar { padding: 12px 14px; }
  .composer { padding: 10px 12px; }
  .upload-section { padding: 16px; }
}

/* ── Login submit button ────────────────────────────────────────────────── */
#loginForm button[type="submit"] {
  padding: 12px 36px;
  background: var(--navy);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  margin-top: 8px;
  transition: background 0.15s, transform 0.1s;
  box-shadow: 0 2px 8px rgba(12,45,78,0.2);
  display: inline-block;
  width: auto;
}

#loginForm button[type="submit"]:hover {
  background: var(--navy-mid);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(12,45,78,0.3);
}

/* ── Portal / Home buttons ──────────────────────────────────────────────── */
.portal-btn {
  padding: 16px 36px;
  font-size: 1rem;
  font-weight: 600;
  font-family: var(--font);
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 2px solid var(--navy);
  background: var(--surface);
  color: var(--navy);
  transition: all 0.15s;
  min-width: 220px;
  text-align: center;
  box-shadow: 0 2px 8px rgba(12,45,78,0.08);
  display: inline-block;
  white-space: nowrap;
}

.portal-btn:hover {
  background: var(--navy);
  color: white;
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(12,45,78,0.2);
}

.portal-btn.accent {
  background: var(--navy);
  color: white;
}

.portal-btn.accent:hover {
  background: var(--navy-mid);
}

.btn.primary {
  background: var(--navy);
  color: white;
  border-color: var(--navy);
  padding: 13px 28px;
  font-size: 0.95rem;
  font-weight: 600;
}

.btn.primary:hover {
  background: var(--navy-mid);
  transform: translateY(-1px);
}
