/* Blog: public listing, single post + table of contents, and the admin editor. */

html { scroll-behavior: smooth; }

/* ============================ Public: decoration + motion ============================ */

/* Blog pages: flexible width + a full-bleed gradient backdrop that fills the
   whole main area (from below the header to above the footer). */
.blog-page,
html.blog-anim-ready {
    overflow-x: clip; /* contain the 100vw backdrop so it never adds a scrollbar */
}

.blog-page .site-main {
    position: relative;
    width: min(1560px, 92vw);
}

.blog-deco {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 100vw;
    transform: translateX(-50%);
    overflow: hidden;
    pointer-events: none;
    z-index: 0;
    background:
        radial-gradient(120% 70% at 50% -10%, rgba(37, 150, 190, 0.13), transparent 60%),
        linear-gradient(170deg, rgba(70, 134, 180, 0.07) 0%, rgba(124, 58, 237, 0.08) 55%, rgba(245, 166, 35, 0.05) 100%);
}

.b-blob {
    position: absolute;
    border-radius: 50%;
    filter: blur(48px);
    opacity: 0.4;
    animation: blob-float 16s ease-in-out infinite;
}

.b-blob.b1 { width: 340px; height: 340px; top: -110px; inset-inline-end: -70px; background: radial-gradient(circle at 30% 30%, #2596be, transparent 70%); }
.b-blob.b2 { width: 300px; height: 300px; top: 140px; inset-inline-start: -90px; background: radial-gradient(circle at 30% 30%, #7c3aed, transparent 70%); animation-delay: -5s; }
.b-blob.b3 { width: 260px; height: 260px; bottom: -90px; inset-inline-end: 22%; background: radial-gradient(circle at 30% 30%, #f5a623, transparent 70%); animation-delay: -9s; opacity: 0.3; }

@keyframes blob-float {
    0%, 100% { transform: translate(0, 0) scale(1); }
    50% { transform: translate(0, -26px) scale(1.07); }
}

/* Scroll reveal — only armed once JS adds .blog-anim-ready (no-JS stays visible). */
.blog-anim-ready .b-reveal {
    opacity: 0;
    transform: translateY(18px);
    transition: opacity 0.6s var(--ease), transform 0.6s var(--ease);
}

.blog-anim-ready .b-reveal.in {
    opacity: 1;
    transform: none;
}

@media (prefers-reduced-motion: reduce) {
    .b-blob { animation: none; }
    html { scroll-behavior: auto; }
    .blog-anim-ready .b-reveal { opacity: 1; transform: none; transition: none; }
}

/* ============================ Public listing ============================ */
.blog-list { position: relative; z-index: 1; }

.blog-hero {
    position: relative;
    z-index: 1;
    text-align: center;
    max-width: 62ch;
    margin: 0 auto clamp(28px, 5vw, 48px);
    padding-top: 6px;
}

.blog-hero-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 18px;
    border-radius: var(--radius-full);
    background: var(--grad-brand-soft);
    color: var(--teal-600);
    font-weight: 800;
    font-size: 14px;
    margin-bottom: 18px;
}

.blog-hero-badge .ty-icon { width: 16px; height: 16px; }

.blog-hero h1 {
    font-size: clamp(30px, 5.2vw, 52px);
    line-height: 1.2;
    letter-spacing: -0.02em;
    margin: 0 0 14px;
}

.blog-hero h1 .grad {
    background: linear-gradient(110deg, #2596be, #7c3aed);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.blog-hero p {
    color: var(--ink-soft);
    font-size: clamp(15px, 2vw, 18px);
    margin: 0;
}

.blog-grid {
    position: relative;
    z-index: 1;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 24px;
}

.blog-card {
    --c1: #2596be;
    --c2: #4686b4;
    padding: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
    border: 1px solid var(--line);
    transition: transform 0.28s var(--ease), box-shadow 0.28s var(--ease);
}

.blog-card::before {
    content: "";
    position: absolute;
    top: 0;
    inset-inline: 0;
    height: 5px;
    background: linear-gradient(90deg, var(--c1), var(--c2));
    z-index: 2;
}

.blog-card:nth-child(3n+1) { --c1: #2596be; --c2: #18996b; }
.blog-card:nth-child(3n+2) { --c1: #4686b4; --c2: #7c3aed; }
.blog-card:nth-child(3n+3) { --c1: #f5a623; --c2: #ec6a4b; }

.blog-card:hover {
    transform: translateY(-6px);
    box-shadow: var(--shadow-lg);
}

.blog-card-media {
    display: block;
    aspect-ratio: 16 / 9;
    background: linear-gradient(130deg, var(--c1), var(--c2));
    overflow: hidden;
    position: relative;
}

.blog-card-media img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.45s var(--ease);
}

.blog-card:hover .blog-card-media img { transform: scale(1.06); }

.blog-card-placeholder {
    width: 100%;
    height: 100%;
    display: grid;
    place-items: center;
    color: #fff;
}

.blog-card-placeholder .ty-icon { width: 52px; height: 52px; opacity: 0.9; }

.blog-card-body {
    padding: 20px 22px 22px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1;
}

.blog-card-title { font-size: 19px; line-height: 1.55; margin: 0; }

.blog-card-title a {
    color: var(--ink);
    text-decoration: none;
    transition: color 0.2s var(--ease);
}

.blog-card:hover .blog-card-title a { color: var(--teal-600); }

.blog-card-excerpt {
    color: var(--ink-soft);
    font-size: 14px;
    line-height: 1.85;
    margin: 0;
    flex: 1;
}

.blog-card-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
    padding-top: 12px;
    border-top: 1px solid var(--line);
}

.blog-card-link {
    color: var(--teal-600);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.blog-card-link .ty-icon {
    width: 16px;
    height: 16px;
    transition: transform 0.25s var(--ease);
}

.blog-card:hover .blog-card-link .ty-icon { transform: translateX(-4px); }

.blog-pager {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-top: 36px;
}

.blog-pager-info { color: var(--muted); font-weight: 700; font-size: 14px; }

/* ============================ Single post ============================ */
.blog-post { width: min(960px, 100%); margin: 0 auto; position: relative; z-index: 1; }

.blog-post-band {
    position: relative;
    overflow: hidden;
    border-radius: var(--radius-lg);
    padding: clamp(22px, 4vw, 42px);
    background: linear-gradient(125deg, #2596be 0%, #4686b4 45%, #7c3aed 100%);
    color: #fff;
    box-shadow: 0 30px 60px -30px rgba(37, 130, 168, 0.7);
}

.blog-post-band-inner { position: relative; z-index: 1; }

.blog-breadcrumb {
    color: rgba(255, 255, 255, 0.85);
    font-size: 13px;
    font-weight: 700;
    margin-bottom: 16px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.blog-breadcrumb a { color: rgba(255, 255, 255, 0.95); text-decoration: none; }
.blog-breadcrumb a:hover { text-decoration: underline; }
.blog-breadcrumb span[aria-hidden] { opacity: 0.55; }

.blog-post-head h1 {
    font-size: clamp(28px, 5vw, 46px);
    line-height: 1.25;
    letter-spacing: -0.01em;
    margin: 0 0 16px;
    color: #fff;
}

.blog-post-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    font-size: 13.5px;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.9);
}

.blog-post-meta .ty-icon { width: 16px; height: 16px; }

.blog-post-figure {
    position: relative;
    z-index: 1;
    margin: 20px auto 0;
    width: 100%;
    aspect-ratio: 16 / 9;
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow);
}

.blog-post-figure img { width: 100%; height: 100%; object-fit: cover; object-position: center; display: block; }

.blog-post-layout {
    display: grid;
    grid-template-columns: 250px minmax(0, 1fr);
    gap: 36px;
    align-items: start;
    margin-top: 32px;
}

/* Table of contents */
.blog-toc { position: sticky; top: 86px; }

.blog-toc-inner {
    position: relative;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px;
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.blog-toc-inner::before {
    content: "";
    position: absolute;
    top: 0;
    inset-inline: 0;
    height: 4px;
    background: var(--grad-brand);
}

.blog-toc-title {
    font-size: 15px;
    margin: 4px 0 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--ink);
}

.blog-toc-title .ty-icon { width: 18px; height: 18px; color: var(--teal); }

.blog-toc ol {
    list-style: none;
    margin: 0;
    padding: 0;
    counter-reset: toc;
    display: grid;
    gap: 4px;
}

.blog-toc > nav > ol > li { counter-increment: toc; }

.blog-toc ol ol {
    margin: 4px 0;
    padding-inline-start: 14px;
    border-inline-start: 2px solid var(--line);
}

.blog-toc a {
    color: var(--ink-soft);
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.6;
    display: block;
    padding: 4px 8px;
    border-radius: 8px;
    transition: color 0.15s var(--ease), background 0.15s var(--ease);
}

.blog-toc > nav > ol > li > a::before { content: counter(toc) ". "; color: var(--teal); font-weight: 800; }
.blog-toc a:hover { color: var(--teal-600); background: rgba(37, 150, 190, 0.08); }
.blog-toc ol ol a { font-size: 13px; font-weight: 500; color: var(--muted); }
.blog-toc a.is-current { color: #fff; background: var(--grad-brand); }
.blog-toc a.is-current::before { color: #fff; }

/* Content typography */
.blog-content { font-size: 17px; line-height: 2.1; color: var(--ink-soft); overflow-wrap: anywhere; }
.blog-content > *:first-child { margin-top: 0; }

.blog-content h2 {
    position: relative;
    font-size: 26px;
    line-height: 1.5;
    color: var(--ink);
    margin: 42px 0 14px;
    padding-inline-start: 16px;
    scroll-margin-top: 90px;
}

.blog-content h2::before {
    content: "";
    position: absolute;
    inset-inline-start: 0;
    top: 0.18em;
    bottom: 0.18em;
    width: 5px;
    border-radius: 3px;
    background: linear-gradient(var(--teal), #7c3aed);
}

.blog-content h3 {
    font-size: 21px;
    line-height: 1.55;
    color: var(--ink);
    margin: 28px 0 10px;
    scroll-margin-top: 90px;
}

.blog-content h3::before { content: "◗ "; color: var(--accent); }

.blog-content h4 { font-size: 18px; color: var(--ink); margin: 22px 0 8px; }
.blog-content p { margin: 0 0 18px; text-align: justify; }
.blog-content li { text-align: justify; }
.blog-content a { color: var(--teal-600); text-decoration: underline; text-underline-offset: 3px; }

.blog-content ul,
.blog-content ol { margin: 0 0 18px; padding-inline-start: 24px; display: grid; gap: 8px; }

.blog-content li { line-height: 2; }
.blog-content li::marker { color: var(--teal); }

.blog-content img {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius);
    margin: 16px 0;
    display: block;
    box-shadow: var(--shadow);
}

.blog-content blockquote {
    margin: 22px 0;
    padding: 14px 20px;
    border-inline-start: 4px solid var(--teal);
    background: var(--grad-brand-soft);
    border-radius: var(--radius-sm);
    color: var(--ink);
    font-weight: 600;
}

.blog-content blockquote p:last-child { margin-bottom: 0; }

.blog-content code {
    background: rgba(70, 134, 180, 0.12);
    padding: 2px 7px;
    border-radius: 6px;
    font-size: 0.9em;
    direction: ltr;
    unicode-bidi: embed;
}

.blog-content pre {
    background: var(--ink);
    color: #e7f1f6;
    padding: 18px 20px;
    border-radius: var(--radius);
    overflow-x: auto;
    direction: ltr;
    margin: 0 0 20px;
}

.blog-content pre code { background: none; padding: 0; color: inherit; }
.blog-content hr { border: none; border-top: 1px solid var(--line); margin: 32px 0; }

.blog-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 0 0 20px;
    font-size: 15px;
}

.blog-content thead { background: var(--grad-brand-soft); }
.blog-content th,
.blog-content td { border: 1px solid var(--line); padding: 10px 12px; text-align: right; }
.blog-content th { color: var(--ink); font-weight: 800; }

.blog-preview-banner {
    background: rgba(245, 166, 35, 0.14);
    color: #9a6a12;
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    font-weight: 700;
    font-size: 14px;
    margin-bottom: 18px;
}

/* Public responsive (complements the shared block lower in the file) */
@media (max-width: 1000px) {
    .blog-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 600px) {
    .blog-grid { grid-template-columns: 1fr; }
    .blog-post-figure { width: 100%; aspect-ratio: 4 / 3; margin-top: 14px; }
    .blog-content h2 { font-size: 23px; }
}

/* ============================ Admin: blog list bits ============================ */
.ax-blog-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.ax-blog-toolbar-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.ax-blog-count {
    color: var(--muted);
    font-weight: 700;
    font-size: 13px;
}

/* Keep the three actions on a single line (inner flex row avoids <td>/<form>
   display quirks); the results area scrolls horizontally if needed. */
.ax-blog-actions {
    white-space: nowrap;
}

.ax-actions-row {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.ax-actions-row .btn {
    min-height: 34px;
    padding: 0 12px;
    font-size: 13px;
}

.ax-actions-row .ty-icon {
    width: 15px;
    height: 15px;
}

.ax-inline-form {
    margin: 0;
}

.btn-danger {
    color: var(--danger);
}

.btn-danger:hover {
    background: var(--danger-soft);
}

/* ============================ Admin: editor ============================ */
.ax-editor {
    width: min(1200px, 100%);
}

.ax-flash {
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    font-weight: 700;
    font-size: 14px;
}

.ax-flash.ok {
    background: var(--success-soft);
    color: var(--success);
}

.ax-flash.ok a {
    color: var(--success);
}

.ax-flash.err {
    background: var(--danger-soft);
    color: var(--danger);
}

.ax-editor-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: 20px;
    align-items: start;
}

.ax-editor-main {
    display: grid;
    gap: 16px;
}

.ax-editor-side {
    display: grid;
    gap: 16px;
}

.ax-editor-box {
    padding: 18px 18px 20px;
    display: grid;
    gap: 12px;
}

.ax-editor-box h3 {
    font-size: 16px;
    margin: 0;
}

.ax-editor .field {
    display: grid;
    gap: 6px;
}

.ax-editor label {
    font-size: 13px;
    font-weight: 700;
    color: var(--ink-soft);
}

.ax-editor input[type="text"],
.ax-editor input[type="datetime-local"],
.ax-editor textarea,
.ax-editor select {
    width: 100%;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    background: #fff;
    padding: 10px 12px;
    font: inherit;
    min-height: 44px;
}

.ax-editor input:focus-visible,
.ax-editor textarea:focus-visible,
.ax-editor select:focus-visible {
    outline: none;
    border-color: var(--teal);
    box-shadow: var(--shadow-glow);
}

.field-hint {
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
}

.field-hint.ltr,
.ax-editor input[dir="ltr"] {
    direction: ltr;
    text-align: left;
}

.md-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.md-toolbar .ty-icon {
    width: 16px;
    height: 16px;
}

.md-hint {
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
}

.md-input {
    font-family: "Vazirmatn", "Kalameh", monospace;
    line-height: 1.9;
    resize: vertical;
    min-height: 380px;
    transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

.md-input.is-dragover {
    border-color: var(--teal);
    box-shadow: var(--shadow-glow);
    background: var(--grad-brand-soft);
}

.md-uploading {
    color: var(--teal-600);
    font-size: 13px;
    font-weight: 700;
}

.ax-check {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 600;
    color: var(--ink-soft);
    cursor: pointer;
}

.ax-check input {
    width: 18px;
    height: 18px;
    accent-color: var(--teal);
}

.featured-preview {
    aspect-ratio: 16 / 9;
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--grad-brand-soft);
    display: grid;
    place-items: center;
}

.featured-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.featured-preview.is-empty {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
    gap: 6px;
}

.featured-preview .ty-icon {
    width: 22px;
    height: 22px;
}

.featured-actions {
    display: flex;
    gap: 8px;
}

/* ============================ AI generation panel ============================ */
.ai-gen {
    padding: 18px;
    display: grid;
    gap: 12px;
    border: 1px solid rgba(124, 58, 237, 0.28);
    background: linear-gradient(135deg, rgba(124, 58, 237, 0.07), rgba(37, 150, 190, 0.07));
}

.ai-gen-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.ai-gen-head h3 {
    font-size: 16px;
    margin: 0;
    gap: 8px;
}

.ai-gen-head h3 .ty-icon {
    width: 18px;
    height: 18px;
    color: #7c3aed;
}

.ai-gen-settings {
    font-size: 13px;
    font-weight: 700;
    color: var(--teal-600);
    text-decoration: none;
    white-space: nowrap;
}

.ai-gen-settings:hover {
    text-decoration: underline;
}

/* Keyword boxes */
.ai-kw {
    display: grid;
    gap: 8px;
}

.ai-kw > label {
    font-size: 13px;
    font-weight: 700;
    color: var(--ink-soft);
}

.ai-kw > label small {
    color: var(--muted);
    font-weight: 600;
}

.ai-kw-list {
    display: grid;
    gap: 8px;
}

.ai-kw-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-kw-input {
    flex: 1;
    min-width: 0;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    background: #fff;
    padding: 10px 12px;
    font: inherit;
}

.ai-kw-input:focus-visible {
    outline: none;
    border-color: #7c3aed;
    box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.14);
}

.ai-kw-del {
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line);
    background: #fff;
    color: var(--muted);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    transition: color 0.15s var(--ease), border-color 0.15s var(--ease), background 0.15s var(--ease);
}

.ai-kw-del:hover {
    color: var(--danger);
    border-color: var(--danger-soft);
    background: var(--danger-soft);
}

.ai-kw-add {
    justify-self: start;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 1px dashed rgba(124, 58, 237, 0.4);
    background: transparent;
    color: #7c3aed;
    font-weight: 700;
    font-size: 13px;
    padding: 7px 14px;
    border-radius: var(--radius-full);
    cursor: pointer;
}

.ai-kw-add:hover {
    background: rgba(124, 58, 237, 0.08);
}

.ai-kw-add .ty-icon {
    width: 15px;
    height: 15px;
}

.ai-gen-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.ai-gen-actions .ty-icon {
    width: 16px;
    height: 16px;
}

.ai-gen-status {
    font-size: 13px;
    font-weight: 700;
    color: var(--muted);
}

.ai-gen-status.is-ok {
    color: var(--success);
}

.ai-gen-status.is-error {
    color: var(--danger);
}

.ai-gen-error {
    border: 1px solid var(--danger-soft);
    border-radius: var(--radius-sm);
    background: var(--danger-soft);
    padding: 12px 14px;
    display: grid;
    gap: 6px;
}

.ai-gen-error-title {
    font-size: 12px;
    font-weight: 800;
    color: var(--danger);
}

.ai-gen-error pre {
    margin: 0;
    max-height: 280px;
    overflow: auto;
    background: #fff;
    border-radius: 8px;
    padding: 12px;
    font-size: 12px;
    line-height: 1.7;
    direction: ltr;
    text-align: left;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

/* ============================ Responsive ============================ */
@media (max-width: 1000px) {
    .blog-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .blog-post-layout {
        grid-template-columns: 1fr;
        gap: 20px;
    }

    .blog-toc {
        position: static;
    }

    .ax-editor-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 600px) {
    .blog-grid {
        grid-template-columns: 1fr;
    }
}
