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

:root {
  --bg: #f5f6f8;
  --bg-card: #ffffff;
  --text: #1a1a2e;
  --text-muted: #6b7280;
  --text-faint: #9ca3af;
  --border: #e5e7eb;
  --border-light: #f0f1f3;
  --accent: #4a6cf7;
  --accent-hover: #3a5ce5;
  --accent-soft: rgba(74, 108, 247, 0.08);
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --nav-bg: #0f0f1a;
  --radius: 10px;
  --radius-lg: 14px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
  --shadow-lg: 0 10px 25px -5px rgba(0,0,0,0.08), 0 8px 10px -6px rgba(0,0,0,0.04);
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.container {
  max-width: 880px;
  margin: 0 auto;
  padding: 0 1.5rem;
  width: 100%;
}

/* ============================================
   NAVBAR
   ============================================ */
.navbar {
  background: var(--nav-bg);
  padding: 0;
  margin-bottom: 2.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.nav-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  height: 56px;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  text-decoration: none;
  transition: opacity 0.15s;
}

.nav-brand:hover {
  opacity: 0.85;
}

.nav-logo {
  display: block;
}

.nav-brand-text {
  color: rgba(255,255,255,0.4);
  font-size: 0.85rem;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding-left: 0.6rem;
  border-left: 1px solid rgba(255,255,255,0.15);
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nav-links a {
  color: rgba(255,255,255,0.55);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  padding: 0.4rem 0.65rem;
  border-radius: 6px;
  transition: all 0.15s;
}

.nav-links a:hover {
  color: #fff;
  background: rgba(255,255,255,0.08);
}

.nav-btn {
  background: var(--accent) !important;
  color: #fff !important;
  padding: 0.4rem 0.85rem !important;
  border-radius: 6px;
  font-weight: 500 !important;
}

.nav-btn:hover {
  background: var(--accent-hover) !important;
}

.nav-divider {
  width: 1px;
  height: 20px;
  background: rgba(255,255,255,0.12);
  margin: 0 0.25rem;
}

.nav-user {
  color: rgba(255,255,255,0.35);
  font-size: 0.8rem;
  font-weight: 500;
}

.nav-logout {
  color: rgba(255,255,255,0.35) !important;
  font-size: 0.8rem !important;
}

.nav-search {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 0.6rem;
  color: rgba(255,255,255,0.3);
  pointer-events: none;
}

.nav-search input {
  background: rgba(255,255,255,0.07);
  border: 1px solid rgba(255,255,255,0.1);
  color: #fff;
  padding: 0.4rem 0.65rem 0.4rem 2rem;
  border-radius: 8px;
  font-size: 0.83rem;
  font-family: inherit;
  width: 180px;
  transition: all 0.2s;
}

.nav-search input:focus {
  width: 240px;
  background: rgba(255,255,255,0.12);
  border-color: rgba(255,255,255,0.2);
  outline: none;
  box-shadow: 0 0 0 3px rgba(74, 108, 247, 0.2);
}

.nav-search input::placeholder {
  color: rgba(255,255,255,0.3);
}

/* ============================================
   MAIN CONTENT
   ============================================ */
main {
  flex: 1;
  padding-bottom: 3rem;
}

/* ============================================
   AUTH PAGES (login, setup)
   ============================================ */
.auth-card {
  max-width: 400px;
  margin: 3rem auto;
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 2.5rem 2rem 2rem;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}

.auth-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-bottom: 2rem;
}

.auth-wiki-badge {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding-left: 0.75rem;
  border-left: 2px solid var(--border);
}

.auth-subtitle {
  text-align: center;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
}

.auth-card form {
  display: flex;
  flex-direction: column;
}

.auth-form {
  max-width: 100%;
  margin: 0;
}

/* ============================================
   FORMS
   ============================================ */
label {
  display: block;
  font-weight: 600;
  font-size: 0.83rem;
  margin-bottom: 0.35rem;
  margin-top: 1rem;
  color: var(--text);
}

label:first-of-type {
  margin-top: 0;
}

.label-hint {
  font-weight: 400;
  color: var(--text-faint);
  font-size: 0.78rem;
}

input[type="text"],
input[type="password"],
textarea {
  width: 100%;
  padding: 0.6rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.92rem;
  font-family: inherit;
  background: var(--bg-card);
  color: var(--text);
  transition: all 0.15s;
}

input[type="text"]:focus,
input[type="password"]:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

textarea {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.87rem;
  line-height: 1.55;
  resize: vertical;
  min-height: 400px;
}

/* ============================================
   BUTTONS
   ============================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1.15rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 0.88rem;
  cursor: pointer;
  text-decoration: none;
  font-weight: 500;
  font-family: inherit;
  transition: all 0.15s;
  gap: 0.4rem;
}

.btn:hover {
  background: var(--accent-hover);
  box-shadow: var(--shadow-sm);
}

.btn-full {
  width: 100%;
  margin-top: 1.5rem;
  padding: 0.7rem;
  font-size: 0.92rem;
}

.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--border-light);
  box-shadow: none;
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--border);
}

.btn-danger:hover {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.form-actions {
  margin-top: 1.5rem;
  display: flex;
  gap: 0.65rem;
}

.inline-form {
  display: inline;
}

.inline-fields {
  display: flex;
  gap: 1rem;
  align-items: flex-end;
  flex-wrap: wrap;
}

.inline-fields > div {
  flex: 1;
  min-width: 150px;
}

/* ============================================
   ALERTS
   ============================================ */
.alert {
  padding: 0.7rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.88rem;
  font-weight: 500;
}

.alert.error {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
}

.alert.success {
  background: #f0fdf4;
  color: #15803d;
  border: 1px solid #bbf7d0;
}

/* ============================================
   PAGE HEADERS
   ============================================ */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

h1 {
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

h2 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-top: 2rem;
  margin-bottom: 0.75rem;
}

/* ============================================
   ARTICLE LIST
   ============================================ */
.article-list {
  margin-top: 0.5rem;
}

.article-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.85rem 1rem;
  border-radius: var(--radius);
  transition: background 0.12s;
  margin: 0 -1rem;
}

.article-item:hover {
  background: var(--accent-soft);
}

.article-item + .article-item {
  border-top: 1px solid var(--border-light);
}

.article-title {
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  font-size: 1rem;
}

a.article-title:hover {
  color: var(--accent);
}

.article-meta {
  color: var(--text-faint);
  font-size: 0.78rem;
  white-space: nowrap;
  margin-left: 1rem;
}

.empty {
  color: var(--text-muted);
  padding: 3rem 0;
  text-align: center;
}

.empty a {
  color: var(--accent);
}

/* ============================================
   ARTICLE VIEW
   ============================================ */
.wiki-article {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.article-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 0.25rem;
  flex-wrap: wrap;
}

.article-header h1 {
  font-size: 1.85rem;
}

.article-actions {
  display: flex;
  gap: 0.45rem;
  flex-shrink: 0;
}

.article-actions .btn {
  font-size: 0.82rem;
  padding: 0.4rem 0.85rem;
}

.wiki-article > .article-meta {
  color: var(--text-faint);
  font-size: 0.8rem;
  margin-bottom: 2rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border-light);
}

/* ============================================
   MARKDOWN BODY
   ============================================ */
.markdown-body {
  line-height: 1.75;
  color: #374151;
}

.markdown-body h1,
.markdown-body h2,
.markdown-body h3,
.markdown-body h4 {
  margin-top: 1.75em;
  margin-bottom: 0.5em;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

.markdown-body h1 { font-size: 1.5rem; }
.markdown-body h2 {
  font-size: 1.3rem;
  padding-bottom: 0.35em;
  border-bottom: 1px solid var(--border-light);
}
.markdown-body h3 { font-size: 1.1rem; }

.markdown-body p {
  margin-bottom: 1em;
}

.markdown-body ul,
.markdown-body ol {
  margin-bottom: 1em;
  padding-left: 1.75rem;
}

.markdown-body li {
  margin-bottom: 0.3em;
}

.markdown-body li::marker {
  color: var(--text-faint);
}

.markdown-body code {
  background: #f3f4f6;
  padding: 0.15em 0.45em;
  border-radius: 5px;
  font-size: 0.86em;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  color: #e11d48;
}

.markdown-body pre {
  background: var(--nav-bg);
  color: #e2e8f0;
  padding: 1.15rem 1.35rem;
  border-radius: var(--radius);
  overflow-x: auto;
  margin-bottom: 1.25em;
  border: 1px solid rgba(255,255,255,0.06);
}

.markdown-body pre code {
  background: none;
  padding: 0;
  color: inherit;
  font-size: 0.85rem;
}

.markdown-body blockquote {
  border-left: 3px solid var(--accent);
  padding: 0.65rem 1.15rem;
  margin: 0 0 1.25em 0;
  background: var(--accent-soft);
  color: var(--text-muted);
  border-radius: 0 var(--radius) var(--radius) 0;
}

.markdown-body table {
  border-collapse: collapse;
  width: 100%;
  margin-bottom: 1.25em;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.markdown-body th,
.markdown-body td {
  border: 1px solid var(--border);
  padding: 0.55rem 0.85rem;
  text-align: left;
  font-size: 0.9rem;
}

.markdown-body th {
  background: #f9fafb;
  font-weight: 600;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
}

.markdown-body img {
  max-width: 100%;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.markdown-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 2.5em 0;
}

.markdown-body a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: rgba(74, 108, 247, 0.3);
  text-underline-offset: 2px;
  transition: text-decoration-color 0.15s;
}

.markdown-body a:hover {
  text-decoration-color: var(--accent);
}

.markdown-body strong {
  font-weight: 600;
  color: var(--text);
}

/* ============================================
   EDIT FORM
   ============================================ */
.edit-form {
  background: var(--bg-card);
  padding: 2rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  margin-top: 1rem;
}

/* ============================================
   REVISION BANNER
   ============================================ */
.revision-banner {
  background: #fffbeb;
  border: 1px solid #fde68a;
  padding: 0.75rem 1.15rem;
  border-radius: var(--radius);
  margin-bottom: 1.5rem;
  font-size: 0.88rem;
  color: #92400e;
}

.revision-banner a {
  color: var(--accent);
  font-weight: 500;
}

/* ============================================
   SEARCH
   ============================================ */
.search-form {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.search-form input {
  flex: 1;
}

/* ============================================
   USERS PAGE
   ============================================ */
.users-add-form {
  background: var(--bg-card);
  padding: 1.5rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  margin-top: 0.5rem;
}

/* ============================================
   PASSWORD GENERATE
   ============================================ */
.password-field {
  display: flex;
  gap: 0.4rem;
}

.password-field input {
  flex: 1;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.9rem;
  letter-spacing: 0.02em;
}

.btn-generate {
  white-space: nowrap;
  flex-shrink: 0;
  font-size: 0.82rem !important;
  padding: 0.5rem 0.75rem !important;
}

.generated-hint {
  margin-top: 0.75rem;
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 500;
}

/* ============================================
   FOOTER
   ============================================ */
.footer {
  padding: 2rem 0 1.5rem;
  border-top: 1px solid var(--border-light);
}

.footer-inner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  color: var(--text-faint);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.footer-logo {
  opacity: 0.35;
}

.footer-inner span {
  opacity: 0.5;
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 640px) {
  .nav-inner {
    height: auto;
    padding: 0.75rem 0;
    flex-direction: column;
    align-items: flex-start;
  }
  .nav-links {
    flex-wrap: wrap;
    gap: 0.25rem;
  }
  .nav-search input {
    width: 140px;
  }
  .nav-search input:focus {
    width: 180px;
  }
  .article-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.2rem;
  }
  .article-meta { margin-left: 0; }
  .article-header { flex-direction: column; }
  .inline-fields { flex-direction: column; }
  .wiki-article {
    padding: 1.5rem;
    border-radius: var(--radius);
  }
  .auth-card {
    margin: 1.5rem auto;
    padding: 1.75rem 1.25rem;
  }
}
