/* ── Variables ─────────────────────────────── */
:root {
  --bg: #ffffff;
  --bg2: #f8f9fa;
  --border: #e5e7eb;
  --text: #1f2937;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --green: #16a34a;
  --red: #dc2626;
  --sidebar-w: 220px;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
}

/* ── Reset ─────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }
body { font-family: var(--font); color: var(--text); background: var(--bg); line-height: 1.6; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }

/* ── Public Navbar ──────────────────────────── */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
  height: 60px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 100;
}
.nav-brand { font-weight: 700; font-size: 1.1rem; color: var(--text); }
.nav-brand:hover { text-decoration: none; }
.nav-links a { margin-left: 1.5rem; color: var(--muted); font-size: 0.95rem; }
.nav-links a:hover { color: var(--text); text-decoration: none; }
.nav-login { background: var(--accent); color: #fff !important; padding: 0.35rem 0.9rem; border-radius: 6px; font-size: 0.85rem !important; }
.nav-login:hover { background: var(--accent-hover); color: #fff !important; }

/* ── Container ─────────────────────────────── */
.container { max-width: 820px; margin: 0 auto; padding: 2.5rem 1.5rem; }

/* ── Footer ─────────────────────────────────── */
.footer { text-align: center; padding: 2rem 1rem; color: var(--muted); font-size: 0.875rem; border-top: 1px solid var(--border); margin-top: 4rem; }

/* ── Hero ───────────────────────────────────── */
.hero { padding: 3rem 0 2rem; }
.hero h1 { font-size: 2.5rem; font-weight: 800; letter-spacing: -0.02em; }
.hero-sub { color: var(--muted); font-size: 1.1rem; margin-top: 0.5rem; }

/* ── Section ────────────────────────────────── */
.section { margin: 3rem 0; }
.section-header { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 1.25rem; }
.section-header h2 { font-size: 1.25rem; font-weight: 700; }
.see-all { font-size: 0.875rem; color: var(--muted); }
.see-all:hover { color: var(--accent); }

/* ── Post cards ─────────────────────────────── */
.post-list { display: flex; flex-direction: column; gap: 1.5rem; }
.post-card { padding: 1.5rem; border: 1px solid var(--border); border-radius: var(--radius); }
.post-card:hover { border-color: var(--accent); }
.post-meta { font-size: 0.8rem; color: var(--muted); margin-bottom: 0.4rem; }
.post-card h2, .post-card h3 { font-size: 1.2rem; margin-bottom: 0.4rem; }
.post-card h2 a, .post-card h3 a { color: var(--text); }
.post-card h2 a:hover, .post-card h3 a:hover { color: var(--accent); text-decoration: none; }
.post-excerpt { color: var(--muted); font-size: 0.95rem; margin-bottom: 0.75rem; }
.read-more { font-size: 0.875rem; }

/* ── Page titles ────────────────────────────── */
.page-title { font-size: 2rem; font-weight: 800; margin-bottom: 0.5rem; letter-spacing: -0.02em; }
.page-sub { color: var(--muted); margin-bottom: 2rem; }

/* ── Full post ──────────────────────────────── */
.post-full { margin: 0; }
.post-header { margin-bottom: 2.5rem; padding-bottom: 1.5rem; border-bottom: 1px solid var(--border); }
.post-header h1 { font-size: 2rem; font-weight: 800; letter-spacing: -0.02em; margin-top: 0.5rem; }
.post-body { font-size: 1.05rem; line-height: 1.8; }
.post-body h1, .post-body h2, .post-body h3 { margin: 2rem 0 0.75rem; font-weight: 700; }
.post-body h1 { font-size: 1.6rem; }
.post-body h2 { font-size: 1.3rem; }
.post-body h3 { font-size: 1.1rem; }
.post-body p { margin: 1rem 0; }
.post-body ul, .post-body ol { margin: 1rem 0 1rem 1.5rem; }
.post-body li { margin: 0.25rem 0; }
.post-body blockquote { border-left: 4px solid var(--accent); padding-left: 1rem; color: var(--muted); margin: 1.5rem 0; }
.post-body code { background: var(--bg2); padding: 0.15em 0.4em; border-radius: 4px; font-size: 0.9em; }
.post-body pre { background: var(--bg2); padding: 1rem; border-radius: var(--radius); overflow-x: auto; margin: 1.5rem 0; }
.post-body pre code { background: none; padding: 0; }
.post-body hr { border: none; border-top: 1px solid var(--border); margin: 2rem 0; }
.post-nav { margin-top: 3rem; padding-top: 1.5rem; border-top: 1px solid var(--border); }

/* ── File grid (home) ───────────────────────── */
.file-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 1rem; }
.file-card { border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; display: flex; gap: 0.75rem; align-items: flex-start; color: var(--text); }
.file-card:hover { border-color: var(--accent); text-decoration: none; }
.file-icon { background: var(--bg2); color: var(--accent); font-size: 0.65rem; font-weight: 700; padding: 0.4rem 0.5rem; border-radius: 4px; white-space: nowrap; flex-shrink: 0; }
.file-info { min-width: 0; }
.file-title { font-size: 0.9rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-size { font-size: 0.75rem; color: var(--muted); }

/* ── Archives ───────────────────────────────── */
.category-title { font-size: 1rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 0.75rem; }
.archive-list { display: flex; flex-direction: column; gap: 0; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-bottom: 2.5rem; }
.archive-row { display: flex; align-items: center; gap: 1rem; padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); }
.archive-row:last-child { border-bottom: none; }
.archive-icon { background: var(--bg2); color: var(--accent); font-size: 0.6rem; font-weight: 700; padding: 0.35rem 0.45rem; border-radius: 4px; flex-shrink: 0; }
.archive-details { flex: 1; min-width: 0; }
.archive-title { font-weight: 500; }
.archive-desc { font-size: 0.875rem; color: var(--muted); }
.archive-meta { font-size: 0.78rem; color: var(--muted); }

/* ── Buttons ────────────────────────────────── */
.btn { display: inline-block; padding: 0.55rem 1.1rem; border-radius: var(--radius); font-size: 0.9rem; font-weight: 500; cursor: pointer; border: none; background: var(--accent); color: #fff; text-decoration: none; }
.btn:hover { background: var(--accent-hover); text-decoration: none; color: #fff; }
.btn-sm { padding: 0.3rem 0.75rem; font-size: 0.82rem; }
.btn-full { width: 100%; text-align: center; padding: 0.7rem; }
.btn-outline { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.btn-outline:hover { background: var(--accent); color: #fff; }
.btn-danger { background: var(--red); }
.btn-danger:hover { background: #b91c1c; }

/* ── Forms ──────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 1.25rem; }
.form-group label { font-size: 0.875rem; font-weight: 500; }
.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="file"],
.form-group textarea,
.form-group select { padding: 0.55rem 0.75rem; border: 1px solid var(--border); border-radius: var(--radius); font-family: var(--font); font-size: 0.95rem; background: var(--bg); width: 100%; }
.form-group textarea { resize: vertical; font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace; font-size: 0.9rem; line-height: 1.5; }
.form-group input:focus, .form-group textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,0.15); }
.form-check { flex-direction: row; align-items: center; gap: 0.5rem; }
.form-check input { width: auto; }
.form-actions { display: flex; gap: 0.75rem; margin-top: 1.5rem; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.hint { font-weight: 400; color: var(--muted); font-size: 0.82rem; }
.required { color: var(--red); }

/* ── Alerts ─────────────────────────────────── */
.alert { padding: 0.75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: 0.9rem; }
.alert-error { background: #fef2f2; color: var(--red); border: 1px solid #fecaca; }

/* ── Empty state ────────────────────────────── */
.empty { color: var(--muted); padding: 1.5rem 0; }
.center-page { text-align: center; padding: 6rem 1rem; }
.center-page h1 { font-size: 5rem; font-weight: 800; color: var(--border); }
.center-page p { color: var(--muted); margin: 0.5rem 0 1.5rem; }

/* ── Login page ─────────────────────────────── */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg2); }
.login-box { background: var(--bg); padding: 2.5rem; border-radius: 12px; border: 1px solid var(--border); width: 100%; max-width: 380px; }
.login-box h1 { font-size: 1.5rem; font-weight: 800; margin-bottom: 0.25rem; }
.login-sub { color: var(--muted); font-size: 0.9rem; margin-bottom: 1.75rem; }

/* ── Admin layout ───────────────────────────── */
.admin-body { background: var(--bg2); }
.admin-layout { display: flex; min-height: 100vh; }
.sidebar { width: var(--sidebar-w); background: var(--bg); border-right: 1px solid var(--border); display: flex; flex-direction: column; position: fixed; top: 0; bottom: 0; left: 0; overflow-y: auto; }
.sidebar-brand { padding: 1.25rem 1.5rem; font-weight: 800; font-size: 1rem; border-bottom: 1px solid var(--border); }
.sidebar-brand a { color: var(--text); }
.sidebar-brand a:hover { text-decoration: none; }
.sidebar-nav { padding: 1rem 0.75rem; display: flex; flex-direction: column; gap: 0.15rem; flex: 1; }
.sidebar-nav a { padding: 0.5rem 0.75rem; border-radius: 6px; color: var(--muted); font-size: 0.9rem; }
.sidebar-nav a:hover { background: var(--bg2); color: var(--text); text-decoration: none; }
.sidebar-nav a.active { background: var(--accent); color: #fff; }
.sidebar-nav hr { border: none; border-top: 1px solid var(--border); margin: 0.5rem 0; }
.admin-content { margin-left: var(--sidebar-w); padding: 2rem 2.5rem; flex: 1; max-width: 1100px; }
.admin-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 2rem; }
.admin-header h1 { font-size: 1.75rem; font-weight: 800; }

/* ── Stats ──────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 2.5rem; }
.stat-card { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem 1.5rem; }
.stat-num { font-size: 2rem; font-weight: 800; color: var(--accent); }
.stat-label { font-size: 0.82rem; color: var(--muted); margin-top: 0.2rem; }

/* ── Dashboard grid ─────────────────────────── */
.dashboard-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 2rem; }
.dashboard-grid section { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; }
.section-title { font-size: 1.1rem; font-weight: 700; margin-bottom: 1rem; }

/* ── Data table ─────────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; background: var(--bg); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); }
.data-table thead { background: var(--bg2); }
.data-table th { text-align: left; padding: 0.75rem 1rem; font-size: 0.8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; border-bottom: 1px solid var(--border); }
.data-table td { padding: 0.85rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--bg2); }
.actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.text-muted { color: var(--muted); }

/* ── Badges ─────────────────────────────────── */
.badge { display: inline-block; padding: 0.2rem 0.6rem; border-radius: 999px; font-size: 0.75rem; font-weight: 500; }
.badge-green { background: #dcfce7; color: #15803d; }
.badge-gray { background: var(--bg2); color: var(--muted); }

/* ── Upload box ─────────────────────────────── */
.upload-box { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.75rem; margin-bottom: 2.5rem; }
.upload-box h2 { font-size: 1.1rem; font-weight: 700; margin-bottom: 1.25rem; }
.upload-form .form-row { margin-bottom: 0; }

/* ── Edit post form ─────────────────────────── */
.edit-form { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 2rem; max-width: 820px; }

/* ── Responsive ─────────────────────────────── */
@media (max-width: 768px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .admin-content { margin-left: 0; padding: 1.5rem 1rem; }
  .data-table { font-size: 0.82rem; }
  .actions { flex-direction: column; }
  .container { padding: 1.5rem 1rem; }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .hero h1 { font-size: 1.8rem; }
  .file-grid { grid-template-columns: 1fr 1fr; }
}
