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

:root {
  --primary: #382110;
  --primary-hover: #2A1A0D;
  --accent: #409A6A;
  --accent-hover: #357F57;
  --error: #C0392B;
  --success: #409A6A;
  --bg: #FFFFFF;
  --bg-page: #F4F1EA;
  --surface: #F4F1EA;
  --border: #D8D8D8;
  --border-light: #E8E8E8;
  --text: #333333;
  --text-secondary: #999999;
  --text-dark: #382110;
  --topbar-bg: #382110;
  --topbar-text: #FFFFFF;
  --radius: 4px;
  --shadow: 0 1px 2px rgba(0,0,0,0.1);
  --shadow-hover: 0 2px 8px rgba(0,0,0,0.15);
  --max-content: 720px;
  --max-grid: 960px;
  --font: "Lato", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-serif: "Merriweather", Georgia, "Times New Roman", serif;
}

body { font-family: var(--font); color: var(--text); background: var(--bg-page); line-height: 1.6; font-size: 14px; }

.hidden { display: none !important; }

/* Top Bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 20px; background: var(--topbar-bg); position: sticky; top: 0; z-index: 10;
}
.topbar-brand {
  font-size: 1.125rem; font-weight: 700; color: var(--topbar-text);
  font-family: var(--font-serif); letter-spacing: 0.5px; text-decoration: none;
}
.topbar-right { display: flex; align-items: center; gap: 16px; }
.topbar-right a, .topbar-right span {
  color: rgba(255,255,255,0.8); font-size: 0.8125rem; text-decoration: none;
}
.topbar-right a:hover { color: #FFFFFF; }
.topbar-user { display: none; }
@media (min-width: 768px) { .topbar-user { display: inline; } }

/* Auth pages */
.auth-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 16px; background: var(--bg-page);
}
.auth-card {
  width: 100%; max-width: 400px; padding: 32px 28px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg); box-shadow: var(--shadow);
}
.auth-card h1 {
  font-size: 1.5rem; font-weight: 700; margin-bottom: 8px;
  text-align: center; color: var(--text-dark); font-family: var(--font-serif);
}
.auth-card .subtitle {
  color: var(--text-secondary); text-align: center;
  margin-bottom: 24px; font-size: 0.8125rem;
}

/* Forms */
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block; font-size: 0.8125rem; font-weight: 600;
  margin-bottom: 4px; color: var(--text); text-transform: uppercase; letter-spacing: 0.3px;
}
.form-group input, .form-group select {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 0.9375rem; font-family: var(--font); background: var(--bg);
}
.form-group input:focus, .form-group select:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(64,154,106,0.2);
}
.form-error { color: var(--error); font-size: 0.75rem; margin-top: 4px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 8px 16px; border-radius: 3px; font-size: 0.875rem; font-weight: 600;
  cursor: pointer; border: none; font-family: var(--font); text-decoration: none; letter-spacing: 0.3px;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:focus { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-full { width: 100%; }
.btn-outline { background: var(--bg); border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: var(--surface); border-color: #bbb; }
.btn-sm { padding: 5px 12px; font-size: 0.8125rem; }
.btn-danger { color: var(--error); }

.auth-link { text-align: center; margin-top: 16px; font-size: 0.8125rem; color: var(--text-secondary); }
.auth-link a { color: var(--accent); text-decoration: none; font-weight: 600; }
.auth-link a:hover { text-decoration: underline; }

/* Alert messages */
.alert {
  padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; font-size: 0.8125rem;
}
.alert-success { background: #E8F5E9; color: #2E7D32; border: 1px solid #C8E6C9; }
.alert-error { background: #FFEBEE; color: #C62828; border: 1px solid #FFCDD2; }

/* Main content area */
.main { padding: 20px; max-width: var(--max-grid); margin: 0 auto; }

/* Page titles */
.page-title {
  font-size: 1.25rem; font-weight: 700; margin-bottom: 16px;
  color: var(--text-dark); font-family: var(--font-serif);
}

/* Category grid */
.category-grid { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 768px) { .category-grid { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1024px) { .category-grid { grid-template-columns: 1fr 1fr 1fr; } }

.category-card {
  display: block; padding: 16px 18px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg); cursor: pointer; transition: box-shadow 0.15s;
  box-shadow: var(--shadow); text-decoration: none; color: inherit;
}
.category-card:hover { box-shadow: var(--shadow-hover); border-color: #bbb; }
.category-card:focus { outline: 2px solid var(--accent); outline-offset: 2px; }
.category-card h3 { font-size: 1rem; font-weight: 700; margin-bottom: 2px; color: var(--text-dark); }
.category-card .count {
  font-size: 0.75rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px;
}

/* Back row */
.back-row { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.back-row a { color: var(--accent); text-decoration: none; font-size: 0.8125rem; font-weight: 600; }
.back-row a:hover { text-decoration: underline; }

/* File list */
.file-list {
  list-style: none; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.file-item {
  display: block; padding: 12px 16px; border-bottom: 1px solid var(--border-light);
  text-decoration: none; color: var(--text); font-size: 0.9375rem;
  transition: background 0.1s;
}
.file-item:last-child { border-bottom: none; }
.file-item:hover { background: var(--surface); }
.file-item:focus { outline: 2px solid var(--accent); outline-offset: -2px; }

/* File view */
.file-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; flex-wrap: wrap; gap: 8px;
}
.file-header a { color: var(--accent); text-decoration: none; font-size: 0.8125rem; font-weight: 600; }
.file-header a:hover { text-decoration: underline; }

.file-content {
  max-width: var(--max-content); margin: 0 auto; font-size: 1rem; line-height: 1.8;
  background: var(--bg); padding: 24px; border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.file-content h1 { font-size: 1.625rem; font-weight: 700; margin: 20px 0 10px; color: var(--text-dark); font-family: var(--font-serif); }
.file-content h2 { font-size: 1.25rem; font-weight: 700; margin: 18px 0 8px; color: var(--text-dark); font-family: var(--font-serif); }
.file-content h3 { font-size: 1.1rem; font-weight: 700; margin: 16px 0 6px; color: var(--text-dark); }
.file-content p { margin-bottom: 14px; color: #444; }
.file-content ul, .file-content ol { margin: 0 0 14px 20px; color: #444; }
.file-content code { background: var(--surface); padding: 2px 5px; border-radius: 3px; font-size: 0.85em; border: 1px solid var(--border-light); }
.file-content pre { background: var(--surface); padding: 14px; border-radius: var(--radius); overflow-x: auto; margin-bottom: 14px; border: 1px solid var(--border); }
.file-content pre code { background: none; padding: 0; border: none; }
.file-content img { max-width: 100%; height: auto; }
.file-content blockquote { border-left: 3px solid var(--accent); padding-left: 16px; margin: 0 0 14px; color: #666; }
.file-content table { border-collapse: collapse; width: 100%; margin-bottom: 14px; }
.file-content th, .file-content td { border: 1px solid var(--border); padding: 8px 10px; text-align: left; font-size: 0.875rem; }
.file-content th { background: var(--surface); font-weight: 700; }

/* Admin layout */
.admin-layout { display: flex; min-height: calc(100vh - 45px); }
.admin-sidebar {
  width: 200px; border-right: 1px solid var(--border); padding: 12px;
  background: var(--bg); flex-shrink: 0;
}
.admin-sidebar a {
  display: block; padding: 7px 12px; border-radius: 3px; text-decoration: none;
  color: var(--text); font-size: 0.8125rem; margin-bottom: 2px; font-weight: 500;
}
.admin-sidebar a:hover { background: var(--surface); }
.admin-sidebar a.active { background: var(--accent); color: #fff; }
.admin-main { flex: 1; padding: 20px; background: var(--bg-page); }

@media (max-width: 767px) {
  .admin-layout { flex-direction: column; }
  .admin-sidebar {
    width: 100%; display: flex; gap: 4px; padding: 8px;
    border-right: none; border-bottom: 1px solid var(--border);
  }
  .admin-sidebar a { margin-bottom: 0; }
}

.admin-main h2 {
  font-size: 1.125rem; font-weight: 700; margin-bottom: 16px;
  color: var(--text-dark); font-family: var(--font-serif);
}

/* Admin table */
.admin-table {
  width: 100%; border-collapse: collapse; background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.admin-table th, .admin-table td {
  text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border-light); font-size: 0.8125rem;
}
.admin-table th {
  font-weight: 700; color: var(--text-secondary); text-transform: uppercase;
  letter-spacing: 0.5px; font-size: 0.6875rem; background: var(--surface);
}
.admin-table .actions { display: flex; gap: 6px; }

/* Upload form */
.upload-form {
  max-width: 480px; background: var(--bg); padding: 20px;
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}

/* Admin header row */
.admin-header-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; flex-wrap: wrap; gap: 8px;
}
.admin-header-row h2 { margin: 0; }

/* Stats grid */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; max-width: 400px; }
.stat-card {
  background: var(--bg); padding: 16px; border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); text-align: center;
}
.stat-card .stat-value { font-size: 1.5rem; font-weight: 700; color: var(--text-dark); }
.stat-card .stat-label {
  font-size: 0.75rem; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.5px;
}

/* Inline form */
.inline-form { display: inline; }

/* Empty state */
.empty-state { text-align: center; padding: 48px 16px; color: var(--text-secondary); }

/* Links in main */
.main a { color: var(--accent); }
.main a:hover { text-decoration: underline; }
