@import '/ui/tokens.css';
@import '/ui/components.css';
@import '/ui/sidebar.css';

/* KnowledgeBase app — built on the shared design system */

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

body {
  font-family: var(--font-sans);
  background: var(--background);
  color: var(--foreground);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  font-size: 0.875rem;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

#app { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.screen { display: flex; flex: 1; min-height: 0; }
.hidden { display: none !important; }

/* ── Auth ─────────────────────────────────────────────────────────────────── */

#auth-screen {
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--background);
  padding: 1rem;
}

.auth-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: 0 1px 3px oklch(0 0 0 / 8%);
  width: 100%;
  max-width: 28rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 1.5rem 0;
}

.auth-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.375rem;
  padding: 0 1.5rem;
  text-align: center;
}

.auth-icon { color: var(--foreground); margin-bottom: 0.75rem; }
.auth-title { font-size: 1.5rem; font-weight: 600; line-height: 1; }
.auth-desc  { color: var(--muted-foreground); font-size: 0.875rem; }

.auth-content { padding: 0 1.5rem; margin-top: 1.25rem; }

#auth-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

#auth-form button[type="submit"] {
  width: 100%;
  justify-content: center;
  margin-top: 0.5rem;
}

/* ── Buttons (raw HTML elements, not .btn classes) ────────────────────────── */

button {
  font-family: var(--font-sans);
  font-size: 0.875rem;
  font-weight: 500;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  padding: 0.5rem 1rem;
  cursor: pointer;
  background: var(--primary);
  color: var(--primary-foreground);
  transition: opacity 0.15s;
  height: 2.25rem;
  display: inline-flex;
  align-items: center;
}
button:hover { opacity: 0.9; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

button.secondary {
  background: transparent;
  border-color: var(--border);
  color: var(--muted-foreground);
}
button.secondary:hover { background: var(--muted); opacity: 1; }

/* ── Shared input defaults ────────────────────────────────────────────────── */

input:focus { border-color: var(--ring); }
input::placeholder { color: var(--muted-foreground); }

.error { color: var(--destructive); font-size: 0.8rem; }

/* ── FlackBack-style header ───────────────────────────────────────────────── */

header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  height: 3.5rem;
  padding: 0 1.5rem;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

/* Vertical rule between trigger and page title */
.header-sep {
  width: 1px;
  height: 1.375rem;
  background: var(--border);
  flex-shrink: 0;
}

.header-page-title {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--foreground);
}

.header-spacer { flex: 1; }
.header-actions { display: flex; gap: 0.5rem; align-items: center; }

/* ── Route views ──────────────────────────────────────────────────────────── */

.route-view {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* ── Chat route ───────────────────────────────────────────────────────────── */

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.message {
  max-width: 75%;
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius-lg);
  line-height: 1.6;
  font-size: 0.875rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.message.user      { background: var(--primary); color: var(--primary-foreground); align-self: flex-end; border-radius: var(--radius-lg) var(--radius-lg) var(--radius-sm) var(--radius-lg); }
.message.assistant { background: var(--card); border: 1px solid var(--border); align-self: flex-start; border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) var(--radius-sm); }
.message.error     { background: oklch(from var(--destructive) l c h / 8%); border: 1px solid oklch(from var(--destructive) l c h / 30%); color: var(--destructive); align-self: flex-start; }

/* Ingest log */
#ingest-log {
  margin: 0 1.5rem;
  background: oklch(0.145 0 0);
  color: oklch(0.7 0.2 155);
  border-radius: var(--radius-lg);
  padding: 0.75rem;
  font-size: 0.8rem;
  max-height: 160px;
  overflow-y: auto;
  flex-shrink: 0;
}
#ingest-output { font-family: var(--font-mono); white-space: pre-wrap; }

/* Chat input form */
#chat-form {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  background: var(--card);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  align-items: flex-end;
}

/* Override .textarea for the auto-resizing chat input */
#chat-input {
  flex: 1;
  min-height: auto;
  resize: none;
  max-height: 8rem;
  overflow-y: auto;
  line-height: 1.4;
}

/* Typing indicator */
.typing::after { content: '▋'; animation: blink 1s step-end infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* Thinking dots (before first token arrives) */
.message.assistant.thinking {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0.85rem 1rem;
}
.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted-foreground);
  animation: dot-bounce 1.2s ease-in-out infinite;
}
.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes dot-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* ── Quick Links route ────────────────────────────────────────────────────── */

.quick-links-page {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.quick-links-header { display: flex; flex-direction: column; gap: 0.25rem; }
.quick-links-header-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.quick-links-title  { font-size: 1.25rem; font-weight: 600; }
.quick-links-desc   { font-size: 0.875rem; color: var(--muted-foreground); }

.quick-links-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
  gap: 0.75rem;
}

.quick-link-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  text-decoration: none;
  color: var(--foreground);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 150ms, border-color 150ms, box-shadow 150ms;
}

.quick-link-card:hover {
  background: var(--accent);
  border-color: var(--ring);
  box-shadow: 0 0 0 2px oklch(from var(--ring) l c h / 15%);
}

.quick-link-card svg {
  flex-shrink: 0;
  color: var(--muted-foreground);
}

.quick-link-favicon { flex-shrink: 0; border-radius: 4px; }

.quick-link-card-text { display: flex; flex-direction: column; gap: 0.1rem; min-width: 0; flex: 1; }
.quick-link-card-label { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.quick-link-card-url   { font-size: 0.75rem; color: var(--muted-foreground); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.quick-link-card-desc  { font-size: 0.75rem; color: var(--muted-foreground); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.quick-link-actions {
  flex-shrink: 0;
  display: flex;
  gap: 0.125rem;
  opacity: 0;
  transition: opacity 150ms;
}
.quick-link-card:hover .quick-link-actions { opacity: 1; }

.quick-link-action-btn {
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  color: var(--muted-foreground);
  transition: background 150ms, color 150ms, border-color 150ms;
}
.quick-link-action-btn:hover {
  background: var(--muted);
  border-color: var(--border);
  color: var(--foreground);
}
.quick-link-action-btn.danger:hover {
  background: oklch(from var(--destructive) l c h / 10%);
  border-color: oklch(from var(--destructive) l c h / 30%);
  color: var(--destructive);
}

/* ── Modal ────────────────────────────────────────────────────────────────── */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: oklch(0 0 0 / 50%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}

.modal {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  box-shadow: 0 8px 32px oklch(0 0 0 / 20%);
}

.modal-title { font-size: 1.1rem; font-weight: 600; }

.modal form { display: flex; flex-direction: column; gap: 1rem; }

.form-field { display: flex; flex-direction: column; gap: 0.25rem; }
.form-field label { font-size: 0.875rem; font-weight: 500; }
.field-optional { font-weight: 400; color: var(--muted-foreground); }
.form-field input {
  width: 100%;
  border: 1px solid var(--input);
  border-radius: var(--radius-md);
  background: var(--background);
  color: var(--foreground);
  padding: 0 0.75rem;
  font-family: var(--font-sans);
  font-size: 0.875rem;
  outline: none;
  transition: border-color 0.15s;
  height: 2.25rem;
}
.form-field input:focus { border-color: var(--ring); }

.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.5rem; }

/* ── Claude MCP route ─────────────────────────────────────────────────────── */

.mcp-setup-page {
  flex: 1;
  overflow-y: auto;
  padding: 2rem;
  max-width: 680px;
}

.mcp-setup-header { margin-bottom: 2rem; }
.mcp-setup-title  { font-size: 1.25rem; font-weight: 600; margin: 0 0 0.4rem; }
.mcp-setup-desc   { font-size: 0.875rem; color: var(--muted-foreground); margin: 0; }

.mcp-setup-section { margin-bottom: 2rem; }
.mcp-setup-section h3 { font-size: 0.8125rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted-foreground); margin: 0 0 0.75rem; }

.mcp-url-box {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--sidebar-accent);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.625rem 0.875rem;
}
.mcp-url-box code { flex: 1; font-size: 0.9rem; font-family: monospace; }
.mcp-copy-btn { flex-shrink: 0; font-size: 0.8125rem; padding: 0.3rem 0.75rem; }

.mcp-steps {
  margin: 0;
  padding-left: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  font-size: 0.9rem;
  line-height: 1.6;
}

.mcp-tools {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.mcp-tools li {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.75rem 1rem;
  background: var(--sidebar-accent);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.mcp-tools code { font-size: 0.875rem; font-weight: 600; }
.mcp-tools span { font-size: 0.875rem; color: var(--muted-foreground); }

.mcp-notes {
  padding-left: 1.5rem;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  font-size: 0.875rem;
  color: var(--muted-foreground);
  line-height: 1.6;
}

/* ── Mobile ───────────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
  header { padding: 0 1rem; }
  #messages { padding: 1rem; }
  #chat-form { padding: 0.75rem 1rem; }
  .quick-links-page { padding: 1rem; }
  .mcp-setup-page { padding: 1rem; }
  .quick-links-grid { grid-template-columns: 1fr; }
}
