:root {
  --bg: #fafaf7;
  --fg: #1a1a1a;
  --muted: #666;
  --accent: #b8341c;
  --border: #e5e5e0;
  --code-bg: #f0efe9;
  --max-width: 42rem;
  --font-sans:  -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-serif: Georgia, "Times New Roman", serif;
  --font-mono:  ui-monospace, "SF Mono", Consolas, monospace;
}

body.private {
  --bg: #f4f1ea;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-serif);
  font-size: 18px;
  line-height: 1.6;
}

main {
  max-width: var(--max-width);
  margin: 2rem auto 4rem;
  padding: 0 1.25rem;
}

.site-header,
.site-footer {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 1.25rem;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-family: var(--font-sans);
  font-size: 0.95rem;
}

.site-header { border-bottom: 1px solid var(--border); }
.site-footer { border-top: 1px solid var(--border); color: var(--muted); margin-top: 4rem; }

.site-title { font-weight: 600; text-decoration: none; color: var(--fg); }

nav a {
  margin-left: 1rem;
  color: var(--muted);
  text-decoration: none;
}
nav a:hover { color: var(--accent); }

h1, h2, h3 { font-family: var(--font-sans); line-height: 1.25; }
h1 { font-size: 2rem; margin-top: 0; }
h2 { font-size: 1.4rem; margin-top: 2.5rem; }

a { color: var(--accent); }
a:hover { text-decoration: underline; }

.tagline { color: var(--muted); font-style: italic; }
.hero { padding: 1rem 0 2rem; }

/* Post list */
.post-list { list-style: none; padding: 0; }
.post-list li { padding: 1rem 0; border-bottom: 1px solid var(--border); }
.post-list a { font-size: 1.15rem; font-weight: 500; text-decoration: none; }
.post-list time { display: block; color: var(--muted); font-family: var(--font-sans); font-size: 0.85rem; }
.post-list .excerpt { margin: 0.4rem 0 0; color: var(--muted); font-size: 0.95rem; }

/* Post body */
.post header, .page header { margin-bottom: 2rem; }
.post-date { color: var(--muted); font-family: var(--font-sans); font-size: 0.9rem; }
.tags { list-style: none; padding: 0; margin: 0.5rem 0 0; display: flex; gap: 0.5rem; }
.tags li {
  font-size: 0.75rem;
  font-family: var(--font-sans);
  background: var(--border);
  padding: 0.15rem 0.5rem;
  border-radius: 3px;
}

.post-body img, .page-body img { max-width: 100%; height: auto; border-radius: 4px; }
.post-body pre, .page-body pre {
  background: var(--code-bg);
  padding: 1rem;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  border-radius: 4px;
}
.post-body code, .page-body code { font-family: var(--font-mono); font-size: 0.9em; }
.post-body blockquote, .page-body blockquote {
  margin-left: 0;
  padding-left: 1rem;
  border-left: 3px solid var(--border);
  color: var(--muted);
}

/* Auth */
.auth { max-width: 22rem; margin: 4rem auto; }
.auth-form label { display: block; margin-bottom: 1rem; }
.auth-form span { display: block; font-family: var(--font-sans); font-size: 0.9rem; margin-bottom: 0.25rem; }
.auth-form input {
  width: 100%;
  padding: 0.6rem;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 4px;
}
.auth-form button {
  width: 100%;
  padding: 0.7rem;
  font-size: 1rem;
  background: var(--accent);
  color: white;
  border: 0;
  border-radius: 4px;
  cursor: pointer;
}
.error { color: #a02020; font-size: 0.9rem; }

.inline-form { display: inline; margin: 0; }
.link-button {
  background: none;
  border: 0;
  padding: 0;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  margin-left: 1rem;
}
.link-button:hover { color: var(--accent); }

.private-nav { list-style: none; padding: 0; font-family: var(--font-sans); }
.private-nav li { padding: 0.4rem 0; }

/* ============================ Admin ============================ */
.admin-layout {
  display: grid;
  grid-template-columns: 14rem 1fr;
  gap: 2.5rem;
  max-width: 72rem;
  margin: 0 auto;
}
.admin-sidebar h2 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin: 0 0 0.5rem;
}
.admin-sidebar nav { display: flex; flex-direction: column; }
.admin-sidebar nav a {
  margin: 0;
  padding: 0.55rem 0;
  font-family: var(--font-sans);
  font-size: 0.95rem;
  border-bottom: 1px solid var(--border);
  color: var(--fg);
  text-decoration: none;
}
.admin-sidebar nav a:hover { color: var(--accent); }
.admin-sidebar nav a.active { color: var(--accent); font-weight: 600; }

.admin-main { min-width: 0; }
.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

/* override max-width for admin */
body.private main:has(.admin-layout) { max-width: 76rem; }

/* Dashboard */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}
.stat {
  display: flex;
  flex-direction: column;
  padding: 1.25rem;
  background: white;
  border: 1px solid var(--border);
  border-radius: 6px;
  text-decoration: none;
  color: var(--fg);
}
.stat:hover { border-color: var(--accent); }
.stat-num { font-size: 2rem; font-weight: 600; line-height: 1; }
.stat-label { font-family: var(--font-sans); font-size: 0.85rem; color: var(--muted); margin-top: 0.4rem; }
.quick-actions { list-style: none; padding: 0; font-family: var(--font-sans); }
.quick-actions li { padding: 0.4rem 0; }

/* Tables */
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-sans);
  font-size: 0.9rem;
}
.admin-table th {
  text-align: left;
  font-weight: 500;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
}
.admin-table td { padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--border); }
.admin-table tr:hover td { background: rgba(0,0,0,0.02); }
.mono { font-family: var(--font-mono); font-size: 0.85em; color: var(--muted); }

.badge {
  display: inline-block;
  font-size: 0.7rem;
  padding: 0.1rem 0.5rem;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 500;
}
.badge-public  { background: #e0eee0; color: #2d5e2d; }
.badge-private { background: #f0e0d0; color: #7a4a1a; }
.badge-draft   { background: #eee; color: #555; margin-left: 0.25rem; }

/* Buttons */
.btn-primary {
  display: inline-block;
  padding: 0.5rem 1rem;
  background: var(--accent);
  color: white;
  border-radius: 4px;
  text-decoration: none;
  font-family: var(--font-sans);
  font-size: 0.9rem;
}
.btn-link-danger {
  background: none; border: 0; padding: 0;
  color: #a02020; cursor: pointer; font: inherit;
  font-size: 0.85rem; text-decoration: underline;
}

/* Tabs */
.tab-nav { display: flex; gap: 0.25rem; }
.tab-nav a {
  padding: 0.4rem 0.9rem;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  text-decoration: none;
  color: var(--muted);
}
.tab-nav a.active { background: var(--accent); color: white; border-color: var(--accent); }

/* Image grid */
.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
  gap: 1rem;
}
.image-card {
  display: flex;
  flex-direction: column;
  background: white;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}
.image-card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  display: block;
}
.image-meta {
  padding: 0.6rem 0.75rem;
  font-size: 0.8rem;
  font-family: var(--font-sans);
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.empty { color: var(--muted); font-style: italic; }
.hint  { color: var(--muted); font-size: 0.9rem; }

/* ============================ Editor ============================ */
.editor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}
.editor-actions { display: flex; gap: 0.5rem; align-items: center; }
.editor-actions button {
  padding: 0.5rem 1rem;
  font-family: var(--font-sans);
  font-size: 0.9rem;
  background: var(--accent);
  color: white;
  border: 0;
  border-radius: 4px;
  cursor: pointer;
}
.editor-actions .btn-secondary {
  background: white;
  color: var(--fg);
  border: 1px solid var(--border);
}
.editor-actions .btn-danger { background: #a02020; }

.editor-status {
  font-family: var(--font-sans);
  font-size: 0.85rem;
  color: var(--muted);
  margin-right: 0.75rem;
  min-width: 12rem;
  text-align: right;
}
.editor-status.ok    { color: #2d8a4f; }
.editor-status.error { color: #a02020; }

.meta-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem 1rem;
  margin-bottom: 1.5rem;
  padding: 1rem;
  background: white;
  border: 1px solid var(--border);
  border-radius: 4px;
}
.meta-fields label { display: flex; flex-direction: column; }
.meta-fields label.full       { grid-column: 1 / -1; }
.meta-fields label.nav-toggle { align-self: end; }
.meta-fields label span { font-family: var(--font-sans); font-size: 0.8rem; color: var(--muted); margin-bottom: 0.2rem; }
.meta-fields input[type="text"],
.meta-fields input[type="date"],
.meta-fields input[type="number"] {
  padding: 0.4rem 0.5rem;
  font-size: 0.95rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  font-family: var(--font-sans);
}
.meta-fields .checkboxes { grid-column: 1 / -1; display: flex; gap: 1.5rem; }
.meta-fields label.inline { flex-direction: row; align-items: center; gap: 0.4rem; }
.meta-fields label.inline span { margin: 0; font-size: 0.9rem; color: var(--fg); }

.editor-pane {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  height: calc(100vh - 24rem);
  min-height: 28rem;
}
.editor-col, .preview-col { display: flex; flex-direction: column; min-width: 0; }
.editor-col h3, .preview-col h3 {
  font-family: var(--font-sans);
  font-size: 0.8rem;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 0.4rem;
}
.cm-wrapper {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  min-height: 0;
}
.cm-editor { height: 100%; }
.preview {
  flex: 1;
  padding: 1rem 1.25rem;
  overflow-y: auto;
  background: white;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-family: var(--font-serif);
  font-size: 0.95rem;
}
.preview h1 { font-size: 1.5rem; }
.preview h2 { font-size: 1.2rem; margin-top: 1.2rem; }
.preview pre { background: var(--code-bg); padding: 0.75rem; border-radius: 3px; overflow-x: auto; }
.preview img { max-width: 100%; height: auto; }

@media (max-width: 900px) {
  .editor-pane { grid-template-columns: 1fr; height: auto; }
  .editor-col, .preview-col { height: 22rem; }
  .meta-fields { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .admin-layout { grid-template-columns: 1fr; gap: 1rem; }
  .admin-sidebar nav { flex-direction: row; flex-wrap: wrap; gap: 0.5rem; }
  .admin-sidebar nav a { border: 1px solid var(--border); border-radius: 4px; padding: 0.4rem 0.7rem; }
  .site-header { flex-direction: column; align-items: flex-start; gap: 0.5rem; }
}
