/* ============================================================
   Reset & base
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f0f0f;
  --surface: #1a1a1a;
  --surface2: #242424;
  --border: #2e2e2e;
  --text: #e8e8e8;
  --text-muted: #888;
  --accent: #7c5cbf;
  --accent-hover: #9470d4;
  --green: #4caf7d;
  --red: #e05050;
  --font: system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, monospace;
  --radius: 10px;
  --shadow: 0 2px 12px rgba(0,0,0,0.4);
}

html { font-size: 16px; }
body { background: var(--bg); color: var(--text); font-family: var(--font); line-height: 1.6; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
img { max-width: 100%; display: block; }
h1,h2,h3,h4 { line-height: 1.2; font-weight: 700; }

/* ============================================================
   Layout
   ============================================================ */
.container { max-width: 1100px; margin: 0 auto; padding: 0 1.5rem; }

/* ============================================================
   Store header
   ============================================================ */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1rem 0;
  position: sticky; top: 0; z-index: 100;
}
.site-header .container { display: flex; align-items: center; justify-content: space-between; }
.site-logo { font-size: 1.3rem; font-weight: 800; color: var(--text); letter-spacing: -0.02em; }
.site-nav a { color: var(--text-muted); margin-left: 1.5rem; font-size: 0.95rem; }
.site-nav a:hover { color: var(--text); }

/* ============================================================
   Store footer
   ============================================================ */
.site-footer {
  margin-top: 4rem;
  border-top: 1px solid var(--border);
  padding: 1.5rem 0;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ============================================================
   Grid / cards
   ============================================================ */
.section { margin-top: 3rem; }
.section-title { font-size: 1.4rem; margin-bottom: 1.5rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; font-size: 0.85rem; font-weight: 600; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.9rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.2s, transform 0.15s;
  display: flex; flex-direction: column;
  color: var(--text);
}
.card:hover { border-color: var(--accent); transform: translateY(-2px); }
.card-img { aspect-ratio: 16/10; overflow: hidden; }
.card-img img { width: 100%; height: 100%; object-fit: cover; }
.card-body { padding: 0.75rem; flex: 1; display: flex; flex-direction: column; gap: 0.35rem; }
.card-title { font-size: 0.92rem; font-weight: 600; }
.card-desc { color: var(--text-muted); font-size: 0.82rem; flex: 1; line-height: 1.4; }
.price { font-size: 0.95rem; font-weight: 700; color: var(--accent); }
.date { font-size: 0.8rem; color: var(--text-muted); }

/* Blog-style post list */
.blog-list { display: flex; flex-direction: column; }

.blog-item {
  display: flex;
  gap: 1.25rem;
  padding: 1.25rem 0;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  transition: background 0.15s;
}
.blog-item:first-child { padding-top: 0; }
.blog-item:last-child { border-bottom: none; padding-bottom: 0; }
.blog-item:hover { color: var(--text); }
.blog-item:hover .blog-item-title { color: var(--accent); }

.blog-item-thumb {
  flex-shrink: 0;
  width: 120px;
  height: 80px;
  border-radius: 6px;
  overflow: hidden;
  background: var(--surface2);
}
.blog-item-thumb img { width: 100%; height: 100%; object-fit: cover; }

.blog-item-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.35rem; }
.blog-item-title { font-size: 1.1rem; font-weight: 600; line-height: 1.3; transition: color 0.15s; }
.blog-item-date { font-size: 0.8rem; color: var(--text-muted); }
.blog-item-excerpt { font-size: 0.88rem; color: var(--text-muted); line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

@media (max-width: 500px) {
  .blog-item { flex-direction: column; gap: 0.75rem; }
  .blog-item-thumb { width: 100%; height: 140px; }
}

/* ============================================================
   Product page
   ============================================================ */
.product-page {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3rem;
  margin-top: 3rem;
  align-items: start;
}
@media (max-width: 700px) { .product-page { grid-template-columns: 1fr; } }

.product-cover img { width: 100%; border-radius: var(--radius); border: 1px solid var(--border); }
.product-info h1 { font-size: 2rem; margin-bottom: 0.5rem; }
.price-large { font-size: 1.8rem; font-weight: 800; color: var(--accent); margin-bottom: 1.5rem; }
.price-min { font-size: 1rem; font-weight: 400; color: var(--text-muted); margin-left: 0.4rem; }
.product-desc { color: var(--text-muted); margin-bottom: 2rem; line-height: 1.8; }
.buy-form { display: flex; flex-direction: column; gap: 0.75rem; }
.pwyw-input { display: flex; flex-direction: column; gap: 0.25rem; }
.pwyw-input label { font-size: 0.85rem; color: var(--text-muted); }
.crypto-note { font-size: 0.82rem; color: var(--text-muted); margin-top: 0.75rem; }

/* ============================================================
   Post page
   ============================================================ */
/* Post layout: article + TOC sidebar */
.post-layout { display: grid; grid-template-columns: minmax(0, 780px) 220px; gap: 3rem; align-items: start; margin: 3rem auto; max-width: 1060px; }
.post-page { min-width: 0; }
.post-toc-sidebar { position: sticky; top: 5rem; max-height: calc(100vh - 6rem); overflow-y: auto; }

.post-cover { margin-bottom: 2rem; }
.post-cover img { width: 100%; border-radius: var(--radius); }
.post-header h1 { font-size: 2.2rem; }
.post-header time { color: var(--text-muted); font-size: 0.9rem; }
.post-content { margin-top: 2rem; line-height: 1.85; }
.post-content p { margin-bottom: 1.2rem; }
.post-content h2, .post-content h3 { margin: 2rem 0 0.75rem; scroll-margin-top: 5rem; }

/* TOC nav */
#post-toc { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.25rem; }
.toc-toggle { display: none; }
.toc-list { margin: 0; padding: 0 0 0 1rem; display: flex; flex-direction: column; gap: 0.4rem; list-style: decimal; }
.toc-item { font-size: 0.875rem; }
.toc-item a { color: var(--text-muted); text-decoration: none; line-height: 1.4; display: block; }
.toc-item a:hover, .toc-item a.toc-active { color: var(--accent); }
.toc-sub { margin-left: 0.75rem; }
.toc-sub a { font-size: 0.825rem; }

/* Mobile: single column, TOC collapses */
@media (max-width: 900px) {
  .post-layout { grid-template-columns: 1fr; margin: 1.5rem auto; gap: 0; }
  .post-toc-sidebar { position: static; order: -1; margin-bottom: 1.5rem; }
  #post-toc { padding: 0; }
  .toc-toggle { display: flex; align-items: center; justify-content: space-between; width: 100%; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.75rem 1rem; cursor: pointer; color: var(--text); font-size: 0.85rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }
  .toc-toggle-icon { font-size: 0.7rem; transition: transform 0.2s; }
  #post-toc.toc-open .toc-toggle-icon { transform: rotate(180deg); }
  .toc-list { display: none; border: 1px solid var(--border); border-top: none; border-radius: 0 0 var(--radius) var(--radius); padding: 0.75rem 1rem 0.75rem 1.75rem; background: var(--surface); }
  #post-toc.toc-open .toc-list { display: flex; }
}

.post-linked-products { margin-top: 3rem; border-top: 1px solid var(--border); padding-top: 2rem; }
.product-checklist { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.5rem; }
.check-item { display: flex; align-items: center; gap: 0.6rem; cursor: pointer; font-size: 0.95rem; }
.check-item input[type="checkbox"] { width: 1rem; height: 1rem; flex-shrink: 0; }

/* ============================================================
   Result pages (success/failed)
   ============================================================ */
.result-page { text-align: center; max-width: 480px; margin: 5rem auto; }
.result-icon { font-size: 4rem; margin-bottom: 1rem; }
.result-page h1 { font-size: 2rem; margin-bottom: 0.5rem; }
.result-page p { color: var(--text-muted); margin-bottom: 1.5rem; }
.note { font-size: 0.85rem; margin-top: 0.75rem; }
.success-icon { color: var(--green); }
.failed-icon { color: var(--red); }

.spinner {
  width: 48px; height: 48px;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 1.5rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   Form inputs / buttons
   ============================================================ */
.input {
  width: 100%;
  padding: 0.65rem 0.9rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-family: var(--font);
  font-size: 1rem;
  transition: border-color 0.2s;
}
.input:focus { outline: none; border-color: var(--accent); }
.textarea { resize: vertical; min-height: 120px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0.65rem 1.4rem;
  border-radius: 6px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s, transform 0.1s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); color: #fff; }
.btn-secondary { background: var(--surface2); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--border); color: var(--text); }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.85rem; }
.btn-danger { background: transparent; color: var(--red); border-color: var(--red); }
.btn-danger:hover { background: var(--red); color: #fff; }

/* ============================================================
   Misc
   ============================================================ */
.back-link { display: inline-block; margin-top: 2rem; color: var(--text-muted); font-size: 0.9rem; }
.back-link:hover { color: var(--text); }
.empty-state { padding: 3rem 0; text-align: center; color: var(--text-muted); }
.alert { padding: 0.75rem 1rem; border-radius: 6px; margin-bottom: 1rem; font-size: 0.9rem; }
.alert-error { background: rgba(224,80,80,0.15); border: 1px solid var(--red); color: var(--red); }

/* ============================================================
   Org media embeds
   ============================================================ */
.post-content figure,
.product-desc figure {
    margin: 1.5rem 0;
}
.post-content figure img,
.product-desc figure img {
    max-width: 100%;
    border-radius: var(--radius);
}
.post-content figure video,
.product-desc figure video {
    max-width: 100%;
    border-radius: var(--radius);
}
figure.org-youtube {
    position: relative;
    width: 100%;
    padding-bottom: 56.25%;
    height: 0;
    margin: 1.5rem 0;
}
figure.org-youtube iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}

/* Org badge for admin */
.badge-org {
    display: inline-block;
    padding: 0.15rem 0.45rem;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: rgba(124,92,191,0.2);
    color: var(--accent);
    border-radius: 3px;
    border: 1px solid rgba(124,92,191,0.4);
}

/* ============================================================
   Admin layout
   ============================================================ */
.admin-body { background: var(--bg); }

.admin-layout {
  display: flex;
  min-height: 100vh;
}

.admin-sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1.5rem 0;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}

.admin-logo {
  padding: 0 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.admin-logo a { color: var(--text); font-weight: 800; font-size: 1.1rem; }
.admin-badge { font-size: 0.72rem; color: var(--accent); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }

.admin-nav { display: flex; flex-direction: column; flex: 1; }
.admin-nav a {
  padding: 0.65rem 1.25rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  transition: background 0.15s, color 0.15s;
  border-left: 3px solid transparent;
}
.admin-nav a:hover, .admin-nav a.active {
  background: var(--surface2);
  color: var(--text);
  border-left-color: var(--accent);
}

.logout-form { padding: 1rem 1.25rem 0; margin-top: auto; }
.btn-logout {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 0.5rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  width: 100%;
  transition: background 0.15s;
}
.btn-logout:hover { background: var(--surface2); color: var(--text); }

.admin-main { flex: 1; padding: 2rem; max-width: 1400px; }

.admin-page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2rem;
}
.admin-page-header h1 { font-size: 1.6rem; }

/* ============================================================
   Stats grid
   ============================================================ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.stat-value { font-size: 1.8rem; font-weight: 800; }
.stat-label { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.25rem; text-transform: uppercase; letter-spacing: 0.05em; }

.quick-actions { display: flex; gap: 0.75rem; flex-wrap: wrap; }

/* ============================================================
   Admin table
   ============================================================ */
.admin-table { width: 100%; border-collapse: collapse; }
.admin-table th, .admin-table td {
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.admin-table th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); font-weight: 600; }
.admin-table tr:hover td { background: var(--surface); }
.admin-table .actions { display: flex; gap: 0.5rem; align-items: center; }
.thumb { width: 48px; height: 36px; object-fit: cover; border-radius: 4px; }

/* ============================================================
   Admin form
   ============================================================ */
.admin-form { max-width: 1100px; }
.form-group { margin-bottom: 1.5rem; }
.form-group label { display: block; margin-bottom: 0.4rem; font-size: 0.9rem; font-weight: 600; }
.form-group small { display: block; margin-top: 0.35rem; color: var(--text-muted); font-size: 0.8rem; }
.form-check { display: flex; align-items: center; gap: 0.6rem; }
.form-check input { width: auto; accent-color: var(--accent); }
.form-check label { margin: 0; font-weight: normal; }
.form-actions { display: flex; gap: 0.75rem; flex-wrap: wrap; margin-top: 2rem; }
.current-file { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 0.5rem; }
.current-image { margin-bottom: 0.75rem; }
.current-image img { border-radius: 6px; border: 1px solid var(--border); }

/* ============================================================
   Login page
   ============================================================ */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 2.5rem; width: 100%; max-width: 380px; }
.login-box h1 { font-size: 1.4rem; margin-bottom: 0.25rem; }
.login-box h2 { font-size: 1rem; color: var(--text-muted); margin-bottom: 1.5rem; font-weight: 400; }
.login-form { display: flex; flex-direction: column; gap: 1rem; }
.login-form label { font-size: 0.9rem; font-weight: 600; }

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 600px) {
  .admin-layout { flex-direction: column; }
  .admin-sidebar { width: 100%; height: auto; position: static; flex-direction: row; flex-wrap: wrap; padding: 0.75rem; }
  .admin-nav { flex-direction: row; flex: none; }
  .admin-nav a { padding: 0.5rem 0.75rem; border-left: none; border-bottom: 3px solid transparent; }
  .admin-nav a.active { border-left: none; border-bottom-color: var(--accent); }
  .admin-logo { padding: 0.5rem 0.75rem; }
  .logout-form { padding: 0.5rem 0.75rem; margin-top: 0; }
  .admin-main { padding: 1rem; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
