* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: #f5f6f8;
  color: #1f2937;
}

/* ---------- Auth pages (login / signup) ---------- */

.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  background: #fff;
  padding: 32px 28px;
  border-radius: 12px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
}

.auth-card h1 {
  margin: 0 0 4px;
  font-size: 22px;
}

.auth-card .sub {
  margin: 0 0 24px;
  color: #6b7280;
  font-size: 14px;
}

.auth-card label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin: 14px 0 6px;
}

.auth-card input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 14px;
}

.auth-card input:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

/* Password field with show/hide toggle */
.password-field {
  position: relative;
}

.password-field input {
  padding-right: 64px; /* leave room for the toggle button */
}

.password-field .toggle-password {
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  margin: 0;
  width: auto;
  padding: 4px 10px;
  background: transparent;
  color: #2563eb;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.password-field .toggle-password:hover {
  background: rgba(37, 99, 235, 0.08);
}

.auth-card button {
  margin-top: 20px;
  width: 100%;
  padding: 11px;
  border: none;
  border-radius: 8px;
  background: #2563eb;
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.auth-card button:hover:not(:disabled) {
  background: #1d4ed8;
}

.auth-card button:disabled {
  background: #93c5fd;
  cursor: not-allowed;
}

/* Loading spinner shown inside the submit button */
.btn-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  margin-right: 8px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: btn-spin 0.7s linear infinite;
  vertical-align: -2px;
}

@keyframes btn-spin {
  to {
    transform: rotate(360deg);
  }
}

.auth-card .switch {
  margin-top: 16px;
  text-align: center;
  font-size: 13px;
  color: #6b7280;
}

.auth-card .switch a {
  color: #2563eb;
  text-decoration: none;
}

.error {
  margin-top: 12px;
  color: #b91c1c;
  font-size: 13px;
  min-height: 18px;
}

/* ---------- Chat page ---------- */

.chat-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topbar h1 {
  margin: 0;
  font-size: 16px;
}

.topbar .user {
  font-size: 13px;
  color: #6b7280;
}

.topbar button {
  margin-left: 12px;
  background: none;
  border: 1px solid #d1d5db;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 20px;
  padding: 20px;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

.chat-pane {
  background: #fff;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  min-height: 500px;
}

.thread {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.bubble.user {
  align-self: flex-end;
  background: #2563eb;
  color: #fff;
  border-bottom-right-radius: 4px;
}

.bubble.assistant {
  align-self: flex-start;
  background: #f3f4f6;
  color: #111827;
  border-bottom-left-radius: 4px;
}

.composer {
  border-top: 1px solid #e5e7eb;
  padding: 12px;
  display: flex;
  gap: 8px;
}

.composer input {
  flex: 1;
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-size: 14px;
}

.composer input:focus {
  outline: none;
  border-color: #2563eb;
}

.composer button {
  padding: 0 18px;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}

.composer button:disabled {
  background: #93c5fd;
  cursor: not-allowed;
}

/* ---------- Right panel ---------- */

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel-card {
  background: #fff;
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.panel-card h2 {
  margin: 0 0 12px;
  font-size: 14px;
  color: #374151;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.collected-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.collected-list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
  font-size: 13px;
  border-bottom: 1px solid #f3f4f6;
}

.collected-list li:last-child {
  border-bottom: none;
}

.collected-list .field-label {
  color: #6b7280;
}

.collected-list .field-value {
  color: #111827;
  font-weight: 600;
  text-align: right;
  max-width: 60%;
  overflow-wrap: anywhere;
}

.collected-list .pending .field-value {
  color: #9ca3af;
  font-weight: 400;
}

.corpus-card {
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
}

.corpus-card h2 {
  color: #047857;
}

.corpus-amount {
  font-size: 22px;
  font-weight: 700;
  color: #065f46;
  margin: 4px 0 8px;
}

.corpus-detail {
  font-size: 12px;
  color: #047857;
  margin: 2px 0;
}

/* Typing indicator (three animated dots) - unified below */

/* Typing indicator inside chat thread */
.bubble.typing {
  max-width: 64px;
  padding: 8px 10px;
  border-radius: 12px;
  display: flex;
  gap: 6px;
  align-items: center;
  justify-content: center;
}

/* The native `hidden` attribute is just `display: none`, which any rule
   that sets `display` will override. Force it back when hidden is set. */
.bubble.typing[hidden] {
  display: none;
}

.bubble.typing .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #9ca3af;
  display: inline-block;
  animation: typing-bounce 1s infinite ease-in-out;
}

.bubble.typing .dot:nth-child(2) {
  animation-delay: 0.12s;
}

.bubble.typing .dot:nth-child(3) {
  animation-delay: 0.24s;
}

@keyframes typing-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.6; }
  40% { transform: translateY(-6px); opacity: 1; }
}
