/* ── Reset & base ─────────────────────────────────────────────────────────── */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: #292a2d;
  color: #f8f8ff;
  display: flex;
  min-height: 100vh;
}

a { color: inherit; text-decoration: none; }

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
  width: 220px;
  min-height: 100vh;
  background: #252627;
  border-right: 1px solid #3a3a3a;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
}

.sidebar-logo {
  padding: 24px 20px 16px;
  font-size: 1.1rem;
  font-weight: 700;
  color: #f8f8ff;
  border-bottom: 1px solid #3a3a3a;
}

.sidebar-logo span { color: #868686; }

.sidebar-nav {
  list-style: none;
  padding: 12px 0;
  flex: 1;
  overflow-y: auto;
}

.sidebar-nav li a {
  display: block;
  padding: 9px 20px;
  color: #bbb;
  font-size: 0.9rem;
  transition: background 0.15s, color 0.15s;
}

.sidebar-nav li a:hover { background: #2d2d2d; color: #f8f8ff; }
.sidebar-nav li a.active { color: #f8f8ff; background: #323232; font-weight: 600; }

.nav-section {
  padding: 14px 20px 4px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: #868686;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid #3a3a3a;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.85rem;
}

.sidebar-footer a { color: #868686; }
.sidebar-footer a:hover { color: #f8f8ff; }

/* ── Main content ─────────────────────────────────────────────────────────── */
.main-content {
  margin-left: 220px;
  flex: 1;
  padding: 32px 36px;
  max-width: 1100px;
}

/* ── Login page ───────────────────────────────────────────────────────────── */
body.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-container {
  width: 100%;
  max-width: 360px;
  padding: 36px;
  background: #2d2d2d;
  border: 1px solid #444;
  border-radius: 12px;
}

.login-container h1 {
  font-size: 1.4rem;
  font-weight: 700;
  color: #f8f8ff;
  margin-bottom: 4px;
}

.login-container h1 span { color: #868686; }
.login-subtitle { color: #868686; font-size: 0.9rem; margin-bottom: 24px; }

/* ── Page header ──────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
  padding-bottom: 16px;
  border-bottom: 1px solid;
  border-image: linear-gradient(to right, transparent, #555, transparent) 1;
}

.page-header h1 { font-size: 1.5rem; font-weight: 700; color: #f8f8ff; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-block;
  padding: 9px 16px;
  background: #323232;
  color: #e8e8e8;
  border: 1px solid #444;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.88rem;
  font-family: inherit;
  transition: background 0.2s, border-color 0.2s, transform 0.15s;
  white-space: nowrap;
}

.btn:hover { background: #3a3a3a; border-color: #555; }

.btn-sm { padding: 5px 11px; font-size: 0.82rem; }

.btn-primary {
  background: linear-gradient(135deg, #868686 0%, #555 100%);
  border-color: #505050;
  color: #fff;
}
.btn-primary:hover {
  background: linear-gradient(135deg, #9a9a9a 0%, #686868 100%);
  transform: translateY(-1px);
}

.btn-publish {
  background: linear-gradient(135deg, #3a7a4a 0%, #265534 100%);
  border-color: #2d6040;
  color: #fff;
}
.btn-publish:hover { background: linear-gradient(135deg, #459658 0%, #2f6b3f 100%); }

.btn-danger { color: #ffb3b3; border-color: #3a1f1f; }
.btn-danger:hover { background: #321818; border-color: #5a2b2b; }

.btn-block { width: 100%; text-align: center; }

/* ── Flash messages ───────────────────────────────────────────────────────── */
.flash {
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 20px;
  font-size: 0.9rem;
}
.flash-error { background: #2a1414; border: 1px solid #5a2b2b; color: #ff9494; }
.flash-success { background: #12281a; border: 1px solid #2d6040; color: #7dcf9a; }

/* ── Forms ────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.85rem;
  color: #bbb;
}

.form-group input[type="text"],
.form-group input[type="datetime-local"],
.form-group input[type="date"],
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 9px 11px;
  background: #252627;
  border: 1px solid #3a3a3a;
  border-radius: 6px;
  color: #f0f0f8;
  font-size: 0.9rem;
  font-family: inherit;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: #868686;
}

.form-check label { display: flex; align-items: center; gap: 8px; cursor: pointer; color: #bbb; }
.form-check input[type="checkbox"] { width: auto; accent-color: #868686; }

.upload-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.upload-status {
  font-size: 0.82rem;
  color: #868686;
}

/* ── Dashboard stats ──────────────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}

.stat-card {
  display: block;
  background: #2d2d2d;
  border: 1px solid #444;
  border-radius: 10px;
  padding: 20px;
  text-align: center;
  transition: border-color 0.2s, transform 0.15s;
}

.stat-card:hover { border-color: #868686; transform: translateY(-2px); }

.stat-number { font-size: 2.2rem; font-weight: 700; color: #f8f8ff; }
.stat-label { font-size: 0.85rem; color: #868686; margin-top: 4px; }
.stat-sub { font-size: 0.75rem; color: #868686; margin-top: 4px; }

/* ── Git status ───────────────────────────────────────────────────────────── */
.git-status-box {
  background: #2d2d2d;
  border: 1px solid #444;
  border-radius: 10px;
  padding: 20px;
}

.git-status-box h2 { font-size: 1rem; margin-bottom: 12px; color: #bbb; }

.git-output {
  font-family: 'SFMono-Regular', 'Consolas', monospace;
  font-size: 0.82rem;
  color: #868686;
  white-space: pre-wrap;
  word-break: break-all;
  background: #252627;
  padding: 12px;
  border-radius: 6px;
  border: 1px solid #3a3a3a;
}

/* ── Content list table ───────────────────────────────────────────────────── */
.post-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.post-table th {
  text-align: left;
  padding: 10px 12px;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: #868686;
  border-bottom: 1px solid #3a3a3a;
}

.post-table td {
  padding: 11px 12px;
  border-bottom: 1px solid #323232;
  vertical-align: middle;
}

.post-table tr:hover td { background: #2d2d2d; }
.post-table a { color: #bbb; }
.post-table a:hover { color: #f8f8ff; }

.date-cell { color: #868686; font-size: 0.82rem; white-space: nowrap; }

.actions-cell { white-space: nowrap; display: flex; gap: 6px; align-items: center; }

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.4px;
}
.badge-draft { background: #2a2218; color: #c9a84c; border: 1px solid #433214; }
.badge-published { background: #12281a; color: #7dcf9a; border: 1px solid #2d6040; }

.empty-state { color: #868686; padding: 20px 0; }
.empty-state a { color: #bbb; text-decoration: underline; }

/* ── Content editor layout ────────────────────────────────────────────────── */
.editor-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 24px;
  align-items: start;
}

.editor-sidebar {
  background: #2d2d2d;
  border: 1px solid #444;
  border-radius: 10px;
  padding: 20px;
  position: sticky;
  top: 24px;
}

.editor-main {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.editor-main-section {
  background: #2d2d2d;
  border: 1px solid #444;
  border-radius: 10px;
  padding: 16px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.editor-main label,
.editor-main-section label {
  font-size: 0.85rem;
  color: #bbb;
}

.editor-main-section label small {
  color: #868686;
  font-weight: normal;
}

.editor-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid #3a3a3a;
}

/* EasyMDE overrides */
.CodeMirror, .CodeMirror-scroll {
  background: #252627 !important;
  color: #f0f0f8 !important;
  border: none !important;
  min-height: 420px;
}

.editor-toolbar {
  background: #2d2d2d !important;
  border-color: #3a3a3a !important;
}

.editor-toolbar button {
  color: #bbb !important;
}

.editor-toolbar button:hover, .editor-toolbar button.active {
  background: #323232 !important;
  border-color: #555 !important;
  color: #f8f8ff !important;
}

.EasyMDEContainer {
  border: 1px solid #3a3a3a !important;
  border-radius: 6px !important;
  overflow: hidden;
}

.EasyMDEContainer .CodeMirror {
  border-top: 1px solid #3a3a3a !important;
}

.CodeMirror-cursor { border-left-color: #e0e0e0 !important; }

.editor-preview {
  background: #252627 !important;
  color: #f0f0f8 !important;
  border: none !important;
  padding: 16px !important;
}

.editor-preview p, .editor-preview li { line-height: 1.7; }

/* ── Image picker ─────────────────────────────────────────────────────────── */
.image-input-row { display: flex; gap: 8px; }
.image-input-row input { flex: 1; }

.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
  max-height: 380px;
  overflow-y: auto;
  padding: 4px;
}

.image-grid img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 6px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.15s;
}

.image-grid img:hover { border-color: #868686; }
.image-grid .loading { color: #868686; font-size: 0.85rem; grid-column: 1/-1; }

/* ── Modals (shared) ──────────────────────────────────────────────────────── */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal.active { display: flex; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
}

.modal-box {
  position: relative;
  z-index: 1;
  background: #2d2d2d;
  border: 1px solid #444;
  border-radius: 10px;
  padding: 24px;
  max-width: 540px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.modal-header h2, .modal-header h3 { color: #f8f8ff; font-size: 1.1rem; }

.modal-close {
  background: none;
  border: none;
  color: #868686;
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
}
.modal-close:hover { color: #f8f8ff; }

.modal-box label {
  display: block;
  margin-bottom: 5px;
  font-size: 0.85rem;
  color: #bbb;
}

.modal-box input,
.modal-box select {
  width: 100%;
  margin-bottom: 14px;
  padding: 9px 11px;
  background: #252627;
  border: 1px solid #3a3a3a;
  color: #f0f0f8;
  border-radius: 6px;
  font-family: inherit;
  font-size: 0.9rem;
}

.modal-buttons {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

.modal-buttons .btn { flex: 1; text-align: center; }

/* ── Books grid ───────────────────────────────────────────────────────────── */
.books-grid {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  padding: 0;
}

.book-card {
  background: #2d2d2d;
  border: 1px solid #444;
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.book-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 6px 18px rgba(0,0,0,0.35);
}

.book-image-wrapper {
  position: relative;
  width: 100%;
  padding-top: 150%;
  background: #252627;
}

.book-image-wrapper img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-bottom: 1px solid #444;
}

.book-review-badge {
  position: absolute;
  top: -8px; right: -8px;
  width: 40px; height: 50px;
  background: linear-gradient(135deg, #868686 50%, #464646 50%);
  clip-path: polygon(0 0, 100% 0, 100% 70%, 50% 100%, 0 70%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  color: #fff;
  text-decoration: none;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  border: none;
}
.book-review-badge:hover {
  background: linear-gradient(135deg, #9a9a9a 50%, #686868 50%);
  transform: translateY(-3px);
}

.book-body { padding: 12px 12px 14px; display: flex; flex-direction: column; gap: 6px; }
.book-title { font-weight: 700; font-size: 0.95rem; color: #f8f8ff; line-height: 1.2; word-break: break-word; }
.book-author { color: #868686; font-size: 0.85rem; }
.book-meta { display: flex; flex-direction: column; gap: 4px; font-size: 0.8rem; color: #bbb; }

.status-badge {
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 12px;
}
.status-reading { background: #ff9800; color: #000; }
.status-finished { background: #4caf50; color: #fff; }

.book-actions { display: flex; gap: 8px; padding: 0 12px 12px; }
.book-actions button {
  flex: 1;
  padding: 8px 10px;
  border-radius: 6px;
  border: 1px solid #444;
  background: #323232;
  color: #e8e8e8;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s ease;
}
.book-actions button:hover { background: #3a3a3a; border-color: #555; }
.book-actions .delete-btn { color: #ffb3b3; border-color: #3a1f1f; }
.book-actions .delete-btn:hover { background: #321818; border-color: #5a2b2b; }

/* ── Git actions ──────────────────────────────────────────────────────────── */
.git-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.git-commit-form {
  display: flex;
  gap: 8px;
  flex: 1;
  min-width: 220px;
}

.git-commit-input {
  flex: 1;
  background: #1e1e1e;
  border: 1px solid #444;
  border-radius: 6px;
  color: #e0e0e0;
  padding: 8px 12px;
  font-size: 0.9rem;
}

.git-commit-input:focus {
  outline: none;
  border-color: #666;
}

.btn-secondary {
  background: #2d2d2d;
  border: 1px solid #555;
  color: #ccc;
  border-radius: 6px;
  padding: 9px 16px;
  cursor: pointer;
  font-size: 0.9rem;
  font-family: 'SFMono-Regular', 'Consolas', monospace;
}

.btn-secondary:hover { background: #3a3a3a; border-color: #777; color: #fff; }

.git-actions-box { margin-top: 1.5rem; }

.git-op-output { margin-top: 14px; }
.git-op-ok { border-color: #2d6040; }
.git-op-fail { border-color: #5a2b2b; }

/* ── Push result ──────────────────────────────────────────────────────────── */
.push-result { margin-bottom: 20px; border-radius: 8px; overflow: hidden; }
.push-ok .git-output { border-color: #2d6040; }
.push-fail .git-output { border-color: #5a2b2b; }

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .sidebar { display: none; }
  .main-content { margin-left: 0; padding: 20px; }
  .editor-layout { grid-template-columns: 1fr; }
  .editor-sidebar { position: static; }
}

@media (max-width: 600px) {
  .books-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
