/* ── KI Knowledge Base — Stylesheet ──────────────────────── */

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

:root {
  --purple-navy: #3B4270;
  --bright-navy: #3E76B8;
  --dark-sea-green: #83BD8E;
  --marigold: #E29F28;
  --vermillion: #D84220;
  --charcoal: #363C4C;
  --cultured: #F8F8F6;
  --off-white: #F9F9FA;
  --border: #ddd;
  --border-light: #eee;
}

body {
  font-family: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: var(--charcoal);
  background: var(--off-white);
  line-height: 1.5;
}

/* ── Login screen ─────────────────────────── */
#login-screen {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 100vh; gap: 1.5rem;
}
#login-screen h1 { color: var(--purple-navy); font-size: 1.5rem; }
#login-screen p { color: #888; }
#login-btn {
  padding: 10px 24px; border: none; border-radius: 6px; cursor: pointer;
  background: var(--purple-navy); color: white; font-size: 1rem; font-weight: 500;
}
#login-btn:hover { opacity: 0.9; }
#login-error { color: var(--vermillion); display: none; }

/* ── App shell ────────────────────────────── */
#app-shell { display: none; }

header {
  background: var(--purple-navy); color: white; padding: 0 1.5rem;
  display: flex; align-items: center; justify-content: space-between; height: 52px;
}
header h1 { font-size: 1rem; font-weight: 600; white-space: nowrap; }
header nav { display: flex; gap: 1.5rem; align-items: center; }
header nav a {
  color: rgba(255,255,255,0.8); text-decoration: none; font-size: 0.9rem; font-weight: 500;
}
header nav a:hover, header nav a.active { color: white; }
#user-info {
  font-size: 0.8rem; color: rgba(255,255,255,0.7); display: flex; align-items: center; gap: 0.75rem;
}
#sign-out-btn {
  background: none; border: 1px solid rgba(255,255,255,0.3); color: rgba(255,255,255,0.8);
  padding: 3px 10px; border-radius: 4px; cursor: pointer; font-size: 0.8rem;
}
#sign-out-btn:hover { border-color: white; color: white; }

#app-content {
  max-width: 900px; margin: 1.5rem auto; padding: 0 1.5rem;
}

/* ── Section cards ────────────────────────── */
.section-card {
  background: white;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
  margin-bottom: 1.5rem;
  overflow: hidden;
}
.section-card-header {
  margin: 0; padding: 0.6rem 1rem; font-size: 0.95em;
  background: var(--cultured); border-bottom: 1px solid var(--border-light);
  display: flex; align-items: center; justify-content: space-between;
}
.section-card-body { padding: 1rem; }

/* ── Buttons ──────────────────────────────── */
.btn {
  border-radius: 4px; cursor: pointer; font-size: 0.85em;
  font-family: inherit; line-height: 1.4;
}
.btn-primary {
  padding: 6px 16px; border: none;
  background: var(--purple-navy); color: white;
}
.btn-primary:hover { opacity: 0.9; }
.btn-secondary {
  padding: 6px 16px; border: 1px solid var(--border);
  background: white; color: #666;
}
.btn-secondary:hover { border-color: #bbb; }
.btn-sm { padding: 4px 12px; }
.btn-danger { padding: 4px 10px; border: none; background: var(--vermillion); color: white; }

/* ── Form controls ────────────────────────── */
.form-input, .form-select {
  width: 100%; padding: 6px 8px; border: 1px solid var(--border);
  border-radius: 4px; font-size: 0.9em; font-family: inherit;
}
.form-textarea {
  width: 100%; padding: 6px 8px; border: 1px solid var(--border);
  border-radius: 4px; font-size: 0.9em; font-family: inherit;
  resize: vertical; min-height: 80px;
}
.form-search {
  padding: 10px 16px; border: 1px solid var(--border); border-radius: 24px;
  font-size: 1em; width: 100%; outline: none; font-family: inherit;
}
.form-search:focus { border-color: var(--bright-navy); box-shadow: 0 0 0 2px rgba(62,118,184,0.15); }

/* ── Field display ────────────────────────── */
.field { margin-bottom: 0.75rem; }
.field-label {
  font-size: 0.75em; color: #888; text-transform: uppercase; letter-spacing: 0.05em;
  margin-bottom: 0.25rem;
}

/* ── Markdown content ─────────────────────── */
.md-content p { margin: 0.25em 0; }
.md-content p:first-child { margin-top: 0; }
.md-content p:last-child { margin-bottom: 0; }
.md-content ul, .md-content ol { margin: 0.25em 0; padding-left: 1.5em; }
.md-content li { margin: 0.15em 0; }
.md-content h1, .md-content h2, .md-content h3 { margin: 0.5em 0 0.25em; font-size: 1em; }
.md-content a { color: var(--bright-navy); }
.md-content code { background: #f0f0f0; padding: 1px 4px; border-radius: 3px; font-size: 0.9em; }
.md-content pre { background: #f0f0f0; padding: 0.5em; border-radius: 4px; overflow-x: auto; font-size: 0.85em; }
.md-content blockquote { border-left: 3px solid #ddd; padding-left: 0.75em; color: #666; margin: 0.25em 0; }

/* ── Collection badges ────────────────────── */
.badge {
  display: inline-block; padding: 2px 10px; border-radius: 12px;
  font-size: 0.75em; font-weight: 500; color: white;
  text-decoration: none;
}
.badge:hover { opacity: 0.85; }

/* ── Search results ───────────────────────── */
.search-result {
  padding: 0.75rem 0; border-bottom: 1px solid var(--border-light);
}
.search-result:last-child { border-bottom: none; }
.search-result h3 { font-size: 1em; margin-bottom: 0.25rem; }
.search-result h3 a { color: var(--charcoal); text-decoration: none; }
.search-result h3 a:hover { color: var(--bright-navy); }
.search-result .meta { font-size: 0.8em; color: #888; }
.search-result mark { background: #fff3cd; padding: 0 2px; border-radius: 2px; }

/* ── Article view ─────────────────────────── */
.article-header { margin-bottom: 1.5rem; }
.article-header h1 { font-size: 1.5rem; margin-bottom: 0.5rem; }
.article-meta { font-size: 0.85em; color: #888; display: flex; gap: 1rem; flex-wrap: wrap; }

.tab-bar {
  display: flex; gap: 0; border-bottom: 2px solid var(--border-light); margin-bottom: 1rem;
}
.tab-bar button {
  padding: 8px 20px; border: none; background: none; cursor: pointer;
  font-size: 0.9em; font-family: inherit; color: #888; border-bottom: 2px solid transparent;
  margin-bottom: -2px;
}
.tab-bar button.active { color: var(--purple-navy); border-bottom-color: var(--purple-navy); font-weight: 600; }
.tab-bar button:hover { color: var(--charcoal); }

.article-section { margin-bottom: 1.25rem; }
.article-section h2 {
  font-size: 0.85em; color: #888; text-transform: uppercase; letter-spacing: 0.05em;
  margin-bottom: 0.5rem; padding-bottom: 0.25rem; border-bottom: 1px solid var(--border-light);
}

/* ── Editor ───────────────────────────────── */
.editor-section { margin-bottom: 1.25rem; }
.editor-section label {
  display: block; font-size: 0.8em; font-weight: 600; color: var(--charcoal);
  margin-bottom: 0.25rem;
}
.editor-section .hint {
  font-size: 0.75em; color: #999; margin-bottom: 0.5rem; line-height: 1.4;
}
.editor-section textarea { min-height: 100px; }
.editor-section textarea.short { min-height: 60px; }
.editor-section textarea.tall { min-height: 160px; }

.editor-actions {
  display: flex; gap: 0.75rem; align-items: center; padding: 1rem 0;
  border-top: 1px solid var(--border-light); margin-top: 1rem;
}

/* ── Collections grid ─────────────────────── */
.collections-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem;
}
.collection-card {
  background: white; border-radius: 8px; padding: 1rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08); text-decoration: none; color: inherit;
  transition: box-shadow 0.15s;
}
.collection-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.12); }
.collection-card h3 { font-size: 1em; margin-bottom: 0.25rem; }
.collection-card .count { font-size: 0.8em; color: #888; }

/* ── Recent articles list ─────────────────── */
.article-list-item {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 0.5rem 0; border-bottom: 1px solid var(--border-light);
}
.article-list-item:last-child { border-bottom: none; }
.article-list-item a { color: var(--charcoal); text-decoration: none; font-weight: 500; }
.article-list-item a:hover { color: var(--bright-navy); }
.article-list-item .meta { font-size: 0.8em; color: #888; white-space: nowrap; }

/* ── Star toggle ─────────────────────────── */
.star-toggle {
  background: none; border: none; cursor: pointer; font-size: 1.1em;
  color: #ccc; padding: 0; line-height: 1; transition: color 0.15s;
}
.star-toggle:hover { color: var(--marigold); }
.star-toggle.active { color: var(--marigold); }
