/* ==========================================================================
   Dynamic Blog — main stylesheet (responsive + dark mode)
   ========================================================================== */

:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --brand: #4f46e5;
  --brand-600: #4338ca;
  --brand-soft: #eef2ff;
  --success: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .06);
  --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #111827;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --border: #1f2937;
  --brand-soft: #1e1b4b;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4);
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0; min-height: 100vh; display: flex; flex-direction: column;
  font-family: var(--font); background: var(--bg); color: var(--text);
  line-height: 1.6; transition: background .2s, color .2s;
}
img { max-width: 100%; height: auto; display: block; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: .4em 0; }
h1 { font-size: clamp(1.6rem, 2.5vw + 1rem, 2.2rem); }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.1rem; }
.muted { color: var(--muted); }
.center { text-align: center; }
.right { text-align: right; }
.hidden { display: none !important; }
.inline-form { display: inline; margin: 0; }

.container { width: 100%; max-width: 1180px; margin: 0 auto; padding: 0 1rem; }
.main-content { flex: 1; padding-top: 1.5rem; padding-bottom: 3rem; }

/* ---------- Header / nav ---------- */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--border);
}
.nav-wrap { display: flex; align-items: center; gap: 1rem; height: 66px; }
.brand { font-weight: 800; font-size: 1.15rem; color: var(--text); white-space: nowrap; }
.brand span { color: var(--brand); }
.search-form { flex: 1; display: flex; max-width: 380px; margin-left: auto; }
.search-form input {
  flex: 1; min-width: 0; padding: .55rem .9rem; border: 1px solid var(--border);
  border-right: 0; border-radius: 10px 0 0 10px; background: var(--bg); color: var(--text);
}
.search-form button {
  padding: .55rem .9rem; border: 0; border-radius: 0 10px 10px 0;
  background: var(--brand); color: #fff; cursor: pointer;
}
.nav-links { display: flex; align-items: center; gap: 1.1rem; font-weight: 500; }
.nav-links a, .btn-link { color: var(--text); background: none; border: 0; font: inherit; cursor: pointer; padding: 0; }
.nav-links a:hover { color: var(--brand); text-decoration: none; }
.menu-toggle { display: none; }
.icon-btn {
  background: transparent; border: 1px solid var(--border); border-radius: 10px;
  padding: .4rem .6rem; cursor: pointer; font-size: 1rem; color: var(--text);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .6rem 1.1rem; border-radius: 10px; border: 1px solid transparent;
  font: inherit; font-weight: 600; cursor: pointer; transition: transform .1s, background .2s;
  text-decoration: none !important; white-space: nowrap;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-600); }
.btn-outline { border-color: var(--border); color: var(--text); background: transparent; }
.btn-outline:hover { border-color: var(--brand); color: var(--brand); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-warn { background: var(--warn); color: #fff; }
.btn-light { background: #fff; color: var(--brand-600); }
.btn-sm { padding: .35rem .75rem; font-size: .85rem; }
.btn-block { width: 100%; }
.btn-group { display: flex; gap: .5rem; flex-wrap: wrap; }
.link-btn { background: none; border: 0; color: var(--brand); cursor: pointer; font-size: .85rem; padding: 0; }

/* ---------- Cards / layout ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem;
}
.page-hero { margin-bottom: 1.5rem; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.layout-with-sidebar { display: grid; grid-template-columns: 1fr 300px; gap: 2rem; align-items: start; }
.layout-two { display: grid; grid-template-columns: 1.3fr 1fr; gap: 1.25rem; margin-top: 1.5rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.post-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1.5rem; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat { display: flex; flex-direction: column; gap: .2rem; }
.stat strong { font-size: 1.7rem; }
.sidebar { position: sticky; top: 90px; display: flex; flex-direction: column; gap: 1.25rem; }
.side-card h3 { margin-top: 0; }
.cat-list { list-style: none; padding: 0; margin: 0; }
.cat-list li { display: flex; justify-content: space-between; padding: .45rem 0; border-bottom: 1px dashed var(--border); }
.cat-list li:last-child { border-bottom: 0; }
.cat-list a.active { color: var(--brand); font-weight: 700; }
.count { color: var(--muted); font-size: .85rem; }
.cta { background: linear-gradient(135deg, var(--brand), #7c3aed); color: #fff; border: 0; }
.cta p { color: #e0e7ff; }
.cta .btn-light { margin-top: .5rem; }
.empty-state { text-align: center; padding: 3rem 1rem; }

/* ---------- Post cards ---------- */
.post-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow); display: flex; flex-direction: column;
  transition: transform .2s, box-shadow .2s;
}
.post-card:hover { transform: translateY(-3px); box-shadow: 0 14px 30px rgba(15, 23, 42, .12); }
.card-media { aspect-ratio: 16 / 9; background: var(--brand-soft); display: block; overflow: hidden; }
.card-media img { width: 100%; height: 100%; object-fit: cover; }
.media-placeholder { display: grid; place-items: center; height: 100%; font-size: 3rem; }
.card-body { padding: 1rem 1.1rem 1.2rem; display: flex; flex-direction: column; gap: .4rem; flex: 1; }
.card-body h3 { margin: .2rem 0; font-size: 1.1rem; }
.card-body h3 a { color: var(--text); }
.card-body p { margin: 0; font-size: .92rem; }
.card-meta { margin-top: auto; padding-top: .6rem; display: flex; justify-content: space-between; flex-wrap: wrap; gap: .3rem; font-size: .8rem; color: var(--muted); }
.chip {
  display: inline-block; align-self: flex-start; font-size: .75rem; font-weight: 600;
  padding: .15rem .6rem; border-radius: 999px; background: var(--brand-soft); color: var(--brand);
}
.tag { display: inline-block; font-size: .8rem; padding: .2rem .65rem; margin: .2rem; border-radius: 999px; background: var(--brand-soft); color: var(--brand); }
.tag-list { margin-top: 1.5rem; }

.page-hero h1 { margin-bottom: .2rem; }
.pagination { display: flex; gap: 1rem; align-items: center; justify-content: center; margin-top: 2rem; flex-wrap: wrap; }

/* ---------- Article ---------- */
.article { max-width: 780px; margin: 0 auto; }
.article-title { font-size: clamp(1.8rem, 3vw + 1rem, 2.6rem); font-weight: 800; margin-top: .4rem; }
.article-meta { display: flex; flex-wrap: wrap; gap: .4rem; color: var(--muted); font-size: .92rem; margin: .6rem 0 1.5rem; }
.author-name { color: var(--text); font-weight: 600; }
.article-cover { width: 100%; border-radius: var(--radius); margin-bottom: 2rem; max-height: 480px; object-fit: cover; }
.article-body { font-size: 1.08rem; line-height: 1.85; }
.article-body h2 { margin-top: 1.8em; }
.article-body h3 { margin-top: 1.4em; }
.article-body img { border-radius: var(--radius); margin: 1.2rem auto; }
.article-body blockquote { border-left: 4px solid var(--brand); margin: 1.4rem 0; padding: .4rem 1rem; color: var(--muted); font-style: italic; background: var(--brand-soft); border-radius: 0 10px 10px 0; }
.article-body pre { background: #0f172a; color: #e2e8f0; padding: 1rem; border-radius: 10px; overflow-x: auto; }
.article-body code { background: var(--brand-soft); padding: .1rem .35rem; border-radius: 4px; font-size: .92em; }
.article-body pre code { background: none; padding: 0; }
.badge-draft { background: #fef3c7; color: #92400e; padding: .5rem .8rem; border-radius: 10px; font-weight: 600; margin-bottom: 1rem; }
.share-row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin: 2rem 0; padding: 1rem 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }

/* ---------- Comments ---------- */
.comments { margin-top: 3rem; }
.comment-form textarea, .reply-form textarea { width: 100%; }
textarea, input, select {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 10px; padding: .6rem .8rem; width: 100%;
}
textarea:focus, input:focus, select:focus { outline: 2px solid var(--brand); outline-offset: 1px; border-color: transparent; }
.form-footer { display: flex; justify-content: space-between; align-items: center; gap: .6rem; margin-top: .5rem; flex-wrap: wrap; }
.comment { display: flex; gap: .75rem; margin-top: 1.25rem; }
.comment.reply { margin-left: 2.5rem; margin-top: .8rem; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0; display: grid; place-items: center;
  background: var(--brand); color: #fff; font-weight: 700;
}
.avatar.small { width: 32px; height: 32px; font-size: .85rem; }
.comment-body { flex: 1; min-width: 0; }
.comment-body p { margin: .25rem 0; word-wrap: break-word; }
.comment-head { display: flex; gap: .6rem; align-items: baseline; flex-wrap: wrap; font-size: .92rem; }
.reply-form { margin-top: .5rem; display: flex; flex-direction: column; gap: .4rem; align-items: flex-start; }
.reply-form textarea { min-height: 60px; }
.login-prompt { margin: 1rem 0; }
.related { margin-top: 3rem; }
.related h2 { margin-bottom: 1rem; }

/* ---------- Forms / auth ---------- */
.auth-card { max-width: 440px; margin: 2rem auto; }
.auth-card.wide, .wide-card { max-width: 920px; margin: 1rem auto; }
.stack { display: flex; flex-direction: column; gap: 1rem; }
label { display: flex; flex-direction: column; gap: .35rem; font-weight: 500; font-size: .95rem; }
label small { font-weight: 400; }
.error-text { color: var(--danger); }
.wide-card h1 { margin-top: 0; }
.thumb { max-width: 180px; border-radius: 8px; display: inline-block; }
.editor-toolbar { display: flex; flex-wrap: wrap; gap: .3rem; padding: .4rem; border: 1px solid var(--border); border-bottom: 0; border-radius: 10px 10px 0 0; background: var(--brand-soft); }
.editor-toolbar button { border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 6px; padding: .3rem .6rem; cursor: pointer; font: inherit; font-size: .9rem; }
.editor-toolbar button:hover { border-color: var(--brand); }
#editor { border-radius: 0 0 10px 10px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .95rem; min-height: 280px; }
input[type="file"] { padding: .4rem; }

/* ---------- Tables / badges ---------- */
.table-wrap { padding: 0; overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: .8rem 1rem; text-align: left; border-bottom: 1px solid var(--border); }
.table th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.table tr:last-child td { border-bottom: 0; }
.truncate { max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.actions a { margin-left: .6rem; font-weight: 500; }
.danger-link { color: var(--danger) !important; }
.badge { display: inline-block; padding: .18rem .6rem; border-radius: 999px; font-size: .75rem; font-weight: 700; }
.badge-published, .badge-approved { background: #dcfce7; color: #166534; }
.badge-draft, .badge-pending { background: #fef3c7; color: #92400e; }
.badge-spam { background: #fee2e2; color: #991b1b; }
[data-theme="dark"] .badge-published, [data-theme="dark"] .badge-approved { background: #052e16; color: #86efac; }
[data-theme="dark"] .badge-draft, [data-theme="dark"] .badge-pending { background: #451a03; color: #fcd34d; }
[data-theme="dark"] .badge-spam { background: #450a0a; color: #fca5a5; }
.warn { color: var(--warn); }
.list-plain { list-style: none; padding: 0; margin: 0; }
.list-plain li { padding: .6rem 0; border-bottom: 1px solid var(--border); gap: .5rem; }
.list-plain li:last-child { border-bottom: 0; }
.filter-tabs { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.filter-tabs a { padding: .4rem .9rem; border-radius: 999px; border: 1px solid var(--border); color: var(--text); font-size: .9rem; }
.filter-tabs a.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.comment-admin-list { display: flex; flex-direction: column; gap: 1rem; }
.mod-card p { margin: .6rem 0; }
.mod-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.mod-actions form { margin: 0; }

/* ---------- Flash messages ---------- */
.flash-stack { margin-top: 1rem; display: flex; flex-direction: column; gap: .5rem; }
.alert { padding: .75rem 1rem; border-radius: 10px; font-size: .95rem; animation: slidein .3s ease; border: 1px solid transparent; }
.alert-success { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.alert-error { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.alert-info, .alert-warning { background: var(--brand-soft); color: var(--brand); border-color: var(--border); }
[data-theme="dark"] .alert-success { background: #052e16; color: #86efac; border-color: #14532d; }
[data-theme="dark"] .alert-error { background: #450a0a; color: #fca5a5; border-color: #7f1d1d; }
@keyframes slidein { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--border); background: var(--surface); margin-top: 2rem; }
.footer-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 2rem; padding-top: 2rem; padding-bottom: 1.5rem; }
.copyright { text-align: center; font-size: .85rem; color: var(--muted); padding: 1rem; border-top: 1px solid var(--border); }

/* ============================ RESPONSIVE ============================ */
@media (max-width: 900px) {
  .layout-with-sidebar, .layout-two { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .footer-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .menu-toggle { display: inline-flex; margin-left: auto; }
  .search-form { display: none; }
  .nav-links {
    display: none; position: absolute; top: 66px; left: 0; right: 0;
    flex-direction: column; align-items: stretch; gap: .9rem; padding: 1rem;
    background: var(--surface); border-bottom: 1px solid var(--border); box-shadow: var(--shadow);
  }
  .nav-links.open { display: flex; }
  .nav-links .btn { text-align: center; }
  .nav-wrap { position: relative; }
  .search-form.mobile-open { display: flex; }
  .grid-2 { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .hide-sm { display: none; }
  .table td, .table th { padding: .6rem .5rem; font-size: .9rem; }
  .truncate { max-width: 160px; }
  .card { padding: 1rem; }
  .comment.reply { margin-left: 1rem; }
}

@media (max-width: 480px) {
  .post-grid { grid-template-columns: 1fr; }
  .btn-group .btn { flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* ==========================================================================
   CUSTOM ADMIN PANEL (sidebar layout)  -- replaces Django's default admin
   ========================================================================== */
.admin-body { display: block; background: var(--bg); }
.admin-layout { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.admin-sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 1.25rem 1rem; display: flex; flex-direction: column; gap: 1.5rem;
  position: sticky; top: 0; height: 100vh;
}
.admin-brand { font-weight: 800; font-size: 1.25rem; padding: .3rem .5rem; }
.admin-brand span { color: var(--brand); }
.admin-nav { display: flex; flex-direction: column; gap: .25rem; }
.admin-nav a {
  padding: .6rem .8rem; border-radius: 10px; color: var(--text); font-weight: 500;
}
.admin-nav a:hover { background: var(--brand-soft); text-decoration: none; color: var(--brand); }
.admin-nav a.active { background: var(--brand); color: #fff; }
.admin-sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: .5rem; font-size: .92rem; }
.admin-main { min-width: 0; display: flex; flex-direction: column; }
.admin-topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .8rem 1.5rem; border-bottom: 1px solid var(--border); background: var(--surface);
  position: sticky; top: 0; z-index: 20;
}
.admin-topbar-right { display: flex; align-items: center; gap: .8rem; margin-left: auto; font-size: .92rem; }
.admin-content { padding: 1.5rem; max-width: 1280px; width: 100%; }
.admin-content .flash-stack { margin: 0 0 1rem; }
.admin-topbar > .icon-btn { display: none; }

.page-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 1rem; margin-bottom: 1.5rem; }
.page-head h1 { margin: 0; }
.toolbar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 1rem; margin-bottom: 1rem; }
.inline-search { display: flex; gap: .4rem; align-items: center; }
.inline-search input { width: 240px; }
.kpi { position: relative; }
.kpi-icon { font-size: 1.4rem; }
.kpi strong { font-size: 2rem; }
.justify-end { justify-content: flex-end; }
.categories-layout { grid-template-columns: 380px 1fr; align-items: start; }
.categories-layout h3 { margin-top: 0; }
.mod-actions form { margin: 0; }

@media (max-width: 900px) {
  .admin-layout { grid-template-columns: 1fr; }
  .admin-sidebar {
    position: fixed; left: 0; top: 0; width: 260px; z-index: 60;
    transform: translateX(-100%); transition: transform .25s ease; box-shadow: var(--shadow);
  }
  .admin-sidebar.open { transform: none; }
  .admin-topbar > .icon-btn { display: inline-block; }
  .categories-layout { grid-template-columns: 1fr; }
  .inline-search input { width: 100%; }
  .admin-content { padding: 1rem; }
}
