:root {
  --primary: #6B7A52;
  --primary-dark: #556040;
  --accent: #E8C542;
  --bg: #faf8f8;
  --bg-side: #f0eee8;
  --border: #d9d4c4;
  --text: #1a1a1a;
  --text-soft: #666;
  --danger: #c0392b;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Source Sans Pro", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

/* ─── Login ─────────────────────────────────────────────── */
.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
}

.login-card {
  background: white;
  border-radius: 12px;
  padding: 2.5rem;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.2);
}

.login-brand { text-align: center; margin-bottom: 1.5rem; }
.login-logo { width: 60px; height: 60px; border-radius: 50%; margin-bottom: 0.5rem; }
.login-brand h1 { font-size: 1.4rem; font-weight: 700; }
.login-brand .sub { color: var(--text-soft); font-size: 0.9rem; }

#login-form label {
  display: block;
  margin-top: 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}
#login-form input {
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
}
#login-form input:focus { outline: none; border-color: var(--primary); }

#login-form button {
  width: 100%;
  margin-top: 1.5rem;
  padding: 0.8rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
}
#login-form button:hover { background: var(--primary-dark); }

.error { color: var(--danger); font-size: 0.85rem; margin-top: 0.8rem; min-height: 1.1em; }

/* ─── Topbar ────────────────────────────────────────────── */
.topbar {
  background: white;
  border-bottom: 1px solid var(--border);
  padding: 0.7rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 2rem;
}
.topbar .brand { display: flex; align-items: center; gap: 0.6rem; }
.topbar .logo { width: 32px; height: 32px; border-radius: 50%; }
.topbar nav { flex: 1; display: flex; gap: 1rem; }
.topbar nav a {
  color: var(--text-soft);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
}
.topbar nav a:hover { color: var(--primary); }
.user-bar { display: flex; gap: 1rem; align-items: center; font-size: 0.85rem; }
.user-bar #me { color: var(--text-soft); }

.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font: inherit;
  text-decoration: underline;
}

/* ─── Tabs ──────────────────────────────────────────────── */
.tabs {
  background: white;
  border-bottom: 1px solid var(--border);
  display: flex;
  padding: 0 1.5rem;
  gap: 0;
}
.tab {
  background: none;
  border: none;
  padding: 0.9rem 1.2rem;
  font: inherit;
  cursor: pointer;
  color: var(--text-soft);
  border-bottom: 3px solid transparent;
  font-weight: 600;
  font-size: 0.85rem;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-color: var(--primary); }

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem;
}

.panel { display: none; }
.panel.active { display: block; }

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1.2rem;
  gap: 1rem;
}
.panel-head h2 { font-size: 1.2rem; font-weight: 700; }
.panel-head .hint { color: var(--text-soft); font-size: 0.85rem; margin-top: 0.3rem; }

.primary {
  background: var(--primary);
  color: white;
  border: none;
  padding: 0.55rem 1rem;
  border-radius: 6px;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.85rem;
}
.primary:hover { background: var(--primary-dark); }
.primary.danger { background: var(--danger); }
.primary.danger:hover { background: #9c2c1f; }

/* ─── Table ─────────────────────────────────────────────── */
.data {
  width: 100%;
  background: white;
  border-radius: 8px;
  overflow: hidden;
  border-collapse: collapse;
  box-shadow: var(--shadow);
}
.data th, .data td {
  padding: 0.7rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.data th {
  background: var(--bg-side);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-soft);
}
.data tr:last-child td { border-bottom: none; }
.data tr:hover td { background: #faf8f0; }

.perm-tag {
  display: inline-block;
  background: var(--bg-side);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 0.72rem;
  margin-right: 4px;
}
.perm-tag.admin { background: #f5d76e; border-color: #c19c08; color: #5a4500; }
.perm-tag.wiki  { background: #cfe1d4; border-color: var(--primary); color: var(--primary-dark); }
.perm-tag.ai    { background: #d5d8f0; border-color: #6975a7; color: #2c3461; }

.row-actions { white-space: nowrap; }
.row-actions button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--primary);
  margin-right: 0.5rem;
}
.row-actions button:hover { text-decoration: underline; }
.row-actions button.del { color: var(--danger); }

/* ─── Settings List ─────────────────────────────────────── */
.settings-list { display: grid; gap: 0.5rem; }

.settings-cat {
  margin-top: 1.2rem;
  margin-bottom: 0.3rem;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--primary);
}
.settings-cat:first-child { margin-top: 0; }

.setting {
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.9rem 1.1rem;
  cursor: pointer;
  transition: border-color 0.1s;
}
.setting:hover { border-color: var(--primary); }
.setting-key { font-weight: 600; font-family: ui-monospace, "SF Mono", "Cascadia Code", monospace; font-size: 0.85rem; }
.setting-value {
  font-family: ui-monospace, "SF Mono", monospace;
  color: var(--text-soft);
  font-size: 0.8rem;
  margin-top: 0.25rem;
  word-break: break-all;
  white-space: pre-wrap;
}
.setting-desc { color: var(--text-soft); font-size: 0.8rem; margin-top: 0.25rem; }

/* ─── Stats ─────────────────────────────────────────────── */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.7rem;
  margin-bottom: 1rem;
}
.stat-box {
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  text-align: center;
}
.stat-num {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}
.stat-label {
  font-size: 0.75rem;
  color: var(--text-soft);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 0.3rem;
}

/* ─── Modal ─────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal[hidden] { display: none; }
.modal-card {
  background: white;
  border-radius: 12px;
  padding: 1.5rem;
  width: 100%;
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal h3 { margin-bottom: 1rem; font-size: 1.1rem; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1.2rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.modal label {
  display: block;
  margin-top: 0.9rem;
  font-size: 0.82rem;
  font-weight: 600;
}
.modal input, .modal textarea, .modal select {
  width: 100%;
  margin-top: 0.3rem;
  padding: 0.55rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: inherit;
}
.modal textarea {
  font-family: ui-monospace, "SF Mono", monospace;
  font-size: 0.82rem;
  min-height: 140px;
  resize: vertical;
}
.modal .checks {
  display: flex;
  gap: 1rem;
  margin-top: 0.5rem;
  flex-wrap: wrap;
}
.modal .checks label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
  font-weight: 400;
  cursor: pointer;
}
.modal .checks input { width: auto; margin: 0; }
.modal .hint { color: var(--text-soft); font-size: 0.78rem; margin-top: 0.4rem; }
