@import url('https://fonts.googleapis.com/css2?family=Crimson+Pro:ital,wght@0,400;0,600;0,700;1,400&family=Karla:wght@400;500;600;700&family=Fira+Code:wght@400;500&display=swap');

:root {
  --ink: #1c1917;
  --parchment: #faf6f1;
  --cream: #f5efe7;
  --linen: #ece4d9;
  --terracotta: #c2410c;
  --terracotta-dark: #9a3412;
  --terracotta-light: #fed7aa;
  --espresso: #292524;
  --stone: #78716c;
  --stone-light: #a8a29e;
  --warm-white: #fefdfb;
  --border: #d6cec4;
  --border-light: #e7e0d6;
  --shadow: rgba(28, 25, 23, 0.06);
  --shadow-md: rgba(28, 25, 23, 0.1);
  --danger: #b91c1c;
  --danger-hover: #991b1b;
  --success: #15803d;
  --success-bg: #dcfce7;
  --caution-bg: #fef9c3;
  --caution: #a16207;
  --danger-bg: #fee2e2;

  --font-serif: 'Crimson Pro', Georgia, serif;
  --font-sans: 'Karla', system-ui, sans-serif;
  --font-mono: 'Fira Code', 'SF Mono', monospace;
}

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

body {
  font-family: var(--font-sans);
  background: var(--parchment);
  color: var(--ink);
  line-height: 1.65;
  min-height: 100vh;
  background-image:
    radial-gradient(ellipse at 20% 0%, rgba(194, 65, 12, 0.03) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 100%, rgba(41, 37, 36, 0.03) 0%, transparent 60%);
}

.container { max-width: 1100px; margin: 0 auto; padding: 0 24px; }

/* ---- Animations ---- */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.animate-in { animation: fadeUp 0.4s ease-out both; }
.animate-in-delayed { animation: fadeUp 0.4s ease-out 0.1s both; }

/* ---- Nav ---- */
nav {
  background: var(--espresso);
  padding: 0;
  margin-bottom: 32px;
  border-bottom: 3px solid var(--terracotta);
}
nav .container {
  display: flex;
  justify-content: space-between;
  align-items: stretch;
}
nav a {
  color: var(--stone-light);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  padding: 16px 16px;
  display: inline-block;
  letter-spacing: 0.02em;
  transition: color 0.2s, background 0.2s;
  position: relative;
}
nav a:hover { color: #fff; background: rgba(255,255,255,0.05); }
nav a.active {
  color: #fff;
}
nav a.active::after {
  content: '';
  position: absolute;
  bottom: 0; left: 16px; right: 16px;
  height: 2px;
  background: var(--terracotta);
}
nav .brand {
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 20px;
  color: #fff;
  padding: 14px 0;
  letter-spacing: -0.01em;
}
nav .brand::before {
  content: '\25C8';
  margin-right: 8px;
  color: var(--terracotta);
  font-size: 16px;
}
nav .nav-links { display: flex; align-items: stretch; }

/* ---- Login ---- */
body.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--espresso);
  background-image:
    repeating-linear-gradient(0deg, transparent, transparent 40px, rgba(255,255,255,0.015) 40px, rgba(255,255,255,0.015) 41px),
    repeating-linear-gradient(90deg, transparent, transparent 40px, rgba(255,255,255,0.015) 40px, rgba(255,255,255,0.015) 41px);
}
.login-box {
  max-width: 380px;
  width: 100%;
  background: var(--warm-white);
  padding: 48px 40px;
  border-radius: 2px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3), 0 0 0 1px rgba(255,255,255,0.05);
  animation: fadeUp 0.5s ease-out;
  position: relative;
}
.login-box::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: var(--terracotta);
}
.login-box h1 {
  font-family: var(--font-serif);
  font-size: 28px;
  margin-bottom: 8px;
  color: var(--ink);
  font-weight: 700;
  letter-spacing: -0.02em;
}
.login-box .subtitle {
  color: var(--stone);
  font-size: 14px;
  margin-bottom: 32px;
}
.login-box input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 2px;
  font-size: 15px;
  font-family: var(--font-sans);
  background: var(--parchment);
  color: var(--ink);
  margin-bottom: 16px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.login-box input:focus {
  outline: none;
  border-color: var(--terracotta);
  box-shadow: 0 0 0 3px rgba(194, 65, 12, 0.1);
}
.login-box button {
  width: 100%;
  padding: 12px;
  background: var(--terracotta);
  color: white;
  border: none;
  border-radius: 2px;
  font-size: 15px;
  font-family: var(--font-sans);
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.03em;
  transition: background 0.2s, transform 0.1s;
}
.login-box button:hover { background: var(--terracotta-dark); }
.login-box button:active { transform: scale(0.98); }
.error {
  color: var(--danger);
  font-size: 14px;
  margin-bottom: 12px;
  display: none;
  padding: 8px 12px;
  background: var(--danger-bg);
  border-radius: 2px;
  border-left: 3px solid var(--danger);
}

/* ---- Search ---- */
.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 24px;
  animation: fadeUp 0.4s ease-out 0.15s both;
}
.search-bar input {
  flex: 1;
  padding: 11px 16px;
  border: 1px solid var(--border);
  border-radius: 2px;
  font-size: 15px;
  font-family: var(--font-sans);
  background: var(--warm-white);
  color: var(--ink);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.search-bar input:focus {
  outline: none;
  border-color: var(--terracotta);
  box-shadow: 0 0 0 3px rgba(194, 65, 12, 0.08);
}
.search-bar input::placeholder { color: var(--stone-light); }
.search-bar button {
  padding: 11px 20px;
  background: var(--espresso);
  color: #fff;
  border: none;
  border-radius: 2px;
  font-family: var(--font-sans);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
}
.search-bar button:hover { background: #1c1917; }

/* ---- Table ---- */
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--warm-white);
  border: 1px solid var(--border-light);
  animation: fadeUp 0.4s ease-out 0.2s both;
}
thead { border-bottom: 2px solid var(--border); }
th {
  padding: 10px 16px;
  text-align: left;
  font-size: 11px;
  font-weight: 700;
  color: var(--stone);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: var(--cream);
}
td {
  padding: 12px 16px;
  font-size: 14px;
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}
tr { transition: background 0.15s; }
tbody tr:hover { background: var(--cream); }
tbody tr:last-child td { border-bottom: none; }
a.doc-link {
  color: var(--terracotta);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.15s;
}
a.doc-link:hover {
  color: var(--terracotta-dark);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ---- Tags ---- */
.tag {
  display: inline-block;
  background: var(--linen);
  color: var(--espresso);
  padding: 2px 10px;
  border-radius: 2px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  margin: 2px 4px 2px 0;
  text-transform: uppercase;
}

/* ---- Document View ---- */
.doc-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 20px;
  animation: fadeUp 0.4s ease-out both;
}
.doc-header h1 {
  font-family: var(--font-serif);
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  color: var(--ink);
}
.doc-content {
  background: var(--warm-white);
  padding: 32px;
  border: 1px solid var(--border-light);
  animation: fadeUp 0.4s ease-out 0.15s both;
  line-height: 1.75;
}
.doc-content h1, .doc-content h2, .doc-content h3 {
  font-family: var(--font-serif);
  letter-spacing: -0.01em;
  margin-top: 1.5em;
  margin-bottom: 0.5em;
  color: var(--ink);
}
.doc-content h1 { font-size: 28px; border-bottom: 1px solid var(--border-light); padding-bottom: 8px; }
.doc-content h2 { font-size: 22px; }
.doc-content h3 { font-size: 18px; }
.doc-content p { margin-bottom: 1em; }
.doc-content code {
  font-family: var(--font-mono);
  font-size: 13px;
  background: var(--cream);
  padding: 2px 6px;
  border-radius: 2px;
  color: var(--terracotta-dark);
}
.doc-content pre {
  background: var(--espresso);
  color: #e7e5e4;
  padding: 16px 20px;
  border-radius: 2px;
  overflow-x: auto;
  margin: 1em 0;
  font-size: 13px;
  line-height: 1.6;
}
.doc-content pre code { background: none; color: inherit; padding: 0; }
.doc-content ul, .doc-content ol { margin-left: 1.5em; margin-bottom: 1em; }
.doc-content li { margin-bottom: 0.3em; }
.doc-content blockquote {
  border-left: 3px solid var(--terracotta);
  padding: 8px 16px;
  margin: 1em 0;
  color: var(--stone);
  background: var(--cream);
}
.doc-content table { margin: 1em 0; font-size: 14px; }
.doc-content a { color: var(--terracotta); }
.doc-meta {
  background: var(--warm-white);
  padding: 16px 20px;
  border: 1px solid var(--border-light);
  margin-bottom: 16px;
  display: flex;
  gap: 32px;
  animation: fadeUp 0.4s ease-out 0.1s both;
}
.doc-meta label {
  font-size: 11px;
  font-weight: 700;
  color: var(--stone);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  display: block;
  margin-bottom: 4px;
}
.doc-meta .value { font-size: 14px; }

/* ---- Editor ---- */
.editor-area {
  width: 100%;
  min-height: 450px;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 2px;
  font-family: var(--font-mono);
  font-size: 14px;
  line-height: 1.7;
  resize: vertical;
  background: var(--warm-white);
  color: var(--ink);
  transition: border-color 0.2s;
}
.editor-area:focus {
  outline: none;
  border-color: var(--terracotta);
  box-shadow: 0 0 0 3px rgba(194, 65, 12, 0.08);
}

/* ---- Buttons ---- */
.btn {
  padding: 8px 18px;
  border: none;
  border-radius: 2px;
  cursor: pointer;
  font-size: 13px;
  font-family: var(--font-sans);
  font-weight: 600;
  letter-spacing: 0.02em;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn-primary {
  background: var(--terracotta);
  color: white;
}
.btn-primary:hover { background: var(--terracotta-dark); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-secondary {
  background: transparent;
  color: var(--stone);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--cream); color: var(--ink); border-color: var(--stone-light); }
.btn + .btn { margin-left: 8px; }
.btn:active { transform: scale(0.97); }

/* ---- Audit Log ---- */
.audit-filters {
  display: flex;
  gap: 12px;
  margin-bottom: 20px;
  animation: fadeUp 0.4s ease-out 0.1s both;
}
.audit-filters select {
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 2px;
  font-family: var(--font-sans);
  font-size: 14px;
  background: var(--warm-white);
  color: var(--ink);
  cursor: pointer;
  transition: border-color 0.2s;
}
.audit-filters select:focus {
  outline: none;
  border-color: var(--terracotta);
}

/* Action-specific tag colors */
.tag-created { background: var(--success-bg); color: var(--success); }
.tag-updated { background: #dbeafe; color: #1d4ed8; }
.tag-deleted { background: var(--danger-bg); color: var(--danger); }
.tag-changelog { background: #f3e8ff; color: #7c3aed; }
.tag-question { background: var(--caution-bg); color: var(--caution); }
.tag-search { background: var(--linen); color: var(--espresso); }

/* ---- Modal ---- */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(28, 25, 23, 0.6);
  backdrop-filter: blur(4px);
  z-index: 100;
  justify-content: center;
  align-items: center;
}
.modal-overlay.active { display: flex; }
.modal {
  background: var(--warm-white);
  padding: 32px;
  border-radius: 2px;
  max-width: 620px;
  width: 90%;
  box-shadow: 0 24px 80px rgba(0,0,0,0.25);
  animation: slideDown 0.3s ease-out;
  position: relative;
}
.modal::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--terracotta);
}
.modal h2 {
  font-family: var(--font-serif);
  font-size: 24px;
  margin-bottom: 24px;
  letter-spacing: -0.01em;
}
.modal .form-group { margin-bottom: 16px; }
.modal label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--stone);
  margin-bottom: 6px;
}
.modal input, .modal textarea, .modal select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 2px;
  font-size: 14px;
  font-family: var(--font-sans);
  background: var(--parchment);
  color: var(--ink);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.modal input:focus, .modal textarea:focus {
  outline: none;
  border-color: var(--terracotta);
  box-shadow: 0 0 0 3px rgba(194, 65, 12, 0.08);
}
.modal textarea {
  min-height: 180px;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 24px;
  padding-top: 16px;
  border-top: 1px solid var(--border-light);
}

/* ---- Score badge ---- */
.score {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 2px;
  font-size: 11px;
  font-weight: 700;
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
  margin-left: 8px;
}
.score-high { background: var(--success-bg); color: var(--success); }
.score-medium { background: var(--caution-bg); color: var(--caution); }
.score-low { background: var(--danger-bg); color: var(--danger); }

/* ---- Page Layout ---- */
.page-title {
  font-family: var(--font-serif);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  animation: fadeUp 0.4s ease-out both;
}
.actions-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

/* ---- Empty State ---- */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--stone);
  font-size: 15px;
}
.empty-state .icon { font-size: 32px; margin-bottom: 12px; opacity: 0.4; }

/* ---- Timestamp ---- */
td.timestamp {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--stone);
  white-space: nowrap;
}

/* ---- Footer spacer ---- */
body > .container { padding-bottom: 48px; }
