/* Blog (/mag/) - loaded only by the blog templates. Every class is mg-* so
   nothing here can leak into the rest of the site, and the old .mag-* rules in
   main.css stay untouched. */
.mg {
    --mg-brand: #1562df;
    --mg-navy: #102d5c;
    --mg-ink: #273c5c;
    --mg-muted: #6b7a93;
    --mg-soft: #eef3ff;
    --mg-line: #e3e9f3;
    --mg-card: #fff;
    --mg-radius: 16px;
    padding-top: 12px;
    padding-bottom: 40px;
    color: var(--mg-ink);
}

/* ---------- breadcrumb ---------- */
.mg-crumbs {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    font-size: 13px;
    color: var(--mg-muted);
    margin: 4px 0 14px;
}
.mg-crumbs a { color: var(--mg-muted); }
.mg-crumbs a:hover { color: var(--mg-brand); }
.mg-crumbs [aria-current] {
    color: var(--mg-ink);
    font-weight: 700;
    max-width: 60ch;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.mg-crumbs__sep { opacity: .6; }

/* ---------- listing header ---------- */
.mg-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 18px 28px;
    flex-wrap: wrap;
    padding: 26px 28px;
    margin-bottom: 16px;
    border-radius: 22px;
    background:
        radial-gradient(circle at 12% 20%, rgb(21 98 223 / 10%), transparent 45%),
        linear-gradient(180deg, #fff, #f6f9ff);
    border: 1px solid var(--mg-line);
}
.mg-head__eyebrow {
    display: inline-block;
    font-size: 13px;
    font-weight: 700;
    color: var(--mg-brand);
    margin-bottom: 4px;
}
.mg-head__title {
    margin: 0;
    font-size: clamp(24px, 3vw, 32px);
    font-weight: 900;
    line-height: 1.5;
    color: var(--mg-navy);
}
.mg-head__sub {
    margin: 6px 0 0;
    color: var(--mg-muted);
    font-size: 14.5px;
}
.mg-search {
    position: relative;
    flex: 1 1 280px;
    max-width: 420px;
}
.mg-search input {
    width: 100%;
    border: 0;
    border-radius: 999px;
    padding: 12px 20px 12px 52px;
    font-size: 14px;
    color: var(--mg-ink);
    background: #fff;
    border: 1px solid var(--mg-line);
    box-shadow: 0 4px 14px rgb(16 45 92 / 6%);
}
.mg-search button {
    position: absolute;
    left: 6px;
    top: 50%;
    transform: translateY(-50%);
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 50%;
    background: var(--mg-brand);
    color: #fff;
    display: grid;
    place-items: center;
    cursor: pointer;
}
[dir=ltr] .mg-search input { padding: 12px 52px 12px 20px; }
[dir=ltr] .mg-search button { left: auto; right: 6px; }
.mg-search-result {
    background: var(--mg-soft);
    border-radius: 12px;
    padding: 10px 16px;
    font-size: 14px;
}
.mg-search-result a { margin-inline-start: 10px; color: var(--mg-brand); font-weight: 700; }

/* ---------- category chips ---------- */
.mg-cats {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    scrollbar-width: none;
    padding: 2px 0 6px;
    margin-bottom: 18px;
}
.mg-cats::-webkit-scrollbar { display: none; }
.mg-cats__item {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: 999px;
    background: var(--mg-card);
    border: 1px solid var(--mg-line);
    color: var(--mg-ink);
    font-size: 14px;
    font-weight: 700;
    transition: background .15s, color .15s, border-color .15s;
}
.mg-cats__item:hover { border-color: var(--mg-brand); color: var(--mg-brand); }
.mg-cats__item.is-active { background: var(--mg-brand); border-color: var(--mg-brand); color: #fff; }
.mg-cats__count {
    font-size: 12px;
    background: var(--mg-soft);
    color: var(--mg-brand);
    border-radius: 999px;
    padding: 0 8px;
    line-height: 20px;
}
.mg-cats__item.is-active .mg-cats__count { background: rgb(255 255 255 / 22%); color: #fff; }

/* ---------- cards ---------- */
.mg-section-title {
    font-size: 21px;
    font-weight: 900;
    color: var(--mg-navy);
    margin: 28px 0 14px;
    display: flex;
    align-items: center;
    gap: 10px;
}
.mg-section-title::before {
    content: "";
    width: 6px;
    height: 22px;
    border-radius: 3px;
    background: var(--mg-brand);
}
.mg-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 22px;
}
/* page 1: one wide card, then a row of three */
.mg-featured {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 22px;
}
.mg-card {
    background: var(--mg-card);
    border: 1px solid var(--mg-line);
    border-radius: var(--mg-radius);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: box-shadow .2s, border-color .2s;
}
.mg-card:hover { border-color: #cfdcf3; box-shadow: 0 12px 28px rgb(16 45 92 / 10%); }
.mg-card__media {
    display: block;
    aspect-ratio: 16 / 9;
    background: var(--mg-soft);
    overflow: hidden;
}
.mg-card__media picture { display: block; width: 100%; height: 100%; }
.mg-card__media img,
.mg-card__placeholder {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform .35s ease;
}
.mg-card:hover .mg-card__media img { transform: scale(1.04); }
.mg-card__placeholder { background: linear-gradient(135deg, var(--mg-soft), #dfe8fb); }
.mg-card__body {
    padding: 16px 18px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex: 1;
    align-items: flex-start;
}
.mg-card__title {
    margin: 0;
    font-size: 17px;
    font-weight: 800;
    line-height: 1.8;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.mg-card__title a { color: var(--mg-navy); }
.mg-card__title a:hover { color: var(--mg-brand); }
.mg-card__excerpt {
    margin: 0;
    font-size: 14px;
    line-height: 1.95;
    color: var(--mg-muted);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.mg-card__meta {
    margin-top: auto;
    padding-top: 10px;
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12.5px;
    color: var(--mg-muted);
    border-top: 1px dashed var(--mg-line);
}
.mg-card__more { color: var(--mg-brand); font-weight: 700; }
/* the wide card: image beside the text */
.mg-card--big { grid-column: 1 / -1; flex-direction: row; }
.mg-card--big .mg-card__media { flex: 0 0 58%; aspect-ratio: 16 / 9; }
.mg-card--big .mg-card__body { padding: 26px 28px; justify-content: center; gap: 12px; }
.mg-card--big .mg-card__title { font-size: clamp(20px, 2.2vw, 26px); line-height: 1.7; -webkit-line-clamp: 3; }
.mg-card--big .mg-card__excerpt { font-size: 15px; -webkit-line-clamp: 4; }
.mg-card--big .mg-card__meta { margin-top: 6px; }

.mg-pill {
    display: inline-block;
    font-size: 12px;
    font-weight: 700;
    padding: 2px 12px;
    border-radius: 999px;
    background: var(--pill-bg, var(--mg-soft));
    color: var(--pill-fg, var(--mg-brand));
}

.mg-empty {
    background: var(--mg-card);
    border-radius: var(--mg-radius);
    padding: 40px;
    text-align: center;
    color: var(--mg-muted);
}

/* ---------- pagination ---------- */
.mg-pages {
    display: flex !important; /* main.css hides bare navs; this is a div, but be explicit */
    justify-content: center;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 30px;
}
.mg-pages__num,
.mg-pages__step,
.mg-pages__gap {
    min-width: 40px;
    height: 40px;
    padding: 0 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    font-weight: 700;
    font-size: 14px;
    background: var(--mg-card);
    color: var(--mg-ink);
    border: 1px solid var(--mg-line);
}
a.mg-pages__num:hover, a.mg-pages__step:hover { border-color: var(--mg-brand); color: var(--mg-brand); }
.mg-pages__num.is-current { background: var(--mg-brand); border-color: var(--mg-brand); color: #fff; }
.mg-pages__step.is-disabled { opacity: .45; }
.mg-pages__gap { border: 0; background: none; min-width: 20px; padding: 0; }

/* ---------- single post ---------- */
.mg-post {
    background: var(--mg-card);
    border-radius: 20px;
    padding: 30px clamp(16px, 4vw, 48px) 26px;
    box-shadow: 0 1px 2px rgb(16 45 92 / 5%), 0 10px 30px rgb(16 45 92 / 5%);
}
.mg-post__head { max-width: 820px; margin: 0 auto 18px; }
.mg-post__title {
    font-size: clamp(24px, 3.4vw, 34px);
    font-weight: 900;
    line-height: 1.6;
    color: var(--mg-navy);
    margin: 10px 0 12px;
}
.mg-post__meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 18px;
    font-size: 13px;
    color: var(--mg-muted);
}
.mg-meta__item a, .mg-meta__item strong { color: var(--mg-ink); font-weight: 700; }
.mg-meta__item--updated { color: #0b7a4b; }
.mg-post__cover {
    margin: 0 auto 22px;
    max-width: 1000px;
    border-radius: 18px;
    overflow: hidden;
    background: var(--mg-soft);
    text-align: center;
}
/* the whole image, never cropped: a wide one scales down, a tall one is capped */
.mg-post__cover picture { display: block; }
.mg-post__cover img {
    display: block;
    margin: 0 auto;
    max-width: 100%;
    width: auto;
    height: auto;
    max-height: min(75vh, 640px);
    object-fit: contain;
}
.mg-post__lead {
    max-width: 820px;
    margin: 0 auto 22px;
    background: var(--mg-soft);
    border-inline-start: 5px solid var(--mg-brand);
    border-radius: 14px;
    padding: 16px 20px;
    font-size: 16px;
    line-height: 2.1;
    text-align: justify;
}
.mg-post__lead p:last-child { margin-bottom: 0; }

/* table of contents: numbered, two columns on desktop, the rest behind «more» */
.mg-toc {
    max-width: 820px;
    margin: 0 auto 24px;
    border: 1px solid var(--mg-line);
    border-radius: 14px;
    padding: 12px 18px;
    background: #fbfcff;
}
.mg-toc > summary { cursor: pointer; font-weight: 900; color: var(--mg-navy); }
.mg-toc__list {
    margin: 10px 0 0;
    padding-inline-start: 22px;
    columns: 2 260px;
    column-gap: 28px;
}
.mg-toc__list li { margin: 3px 0; line-height: 1.85; break-inside: avoid; font-size: 14.5px; }
.mg-toc__list li::marker { color: var(--mg-brand); font-weight: 700; }
.mg-toc a { color: var(--mg-ink); }
.mg-toc a:hover { color: var(--mg-brand); }
.mg-toc__l3 { list-style: circle; font-size: 13.5px !important; }
.mg-toc__more { margin-top: 6px; }
.mg-toc__more > summary { cursor: pointer; color: var(--mg-brand); font-weight: 700; font-size: 14px; }

/* article body typography */
.mg-content {
    max-width: 820px;
    margin: 0 auto;
    font-size: 16.5px;
    line-height: 2.15;
    text-align: justify;
    overflow-wrap: anywhere;
}
.mg-content > *:first-child { margin-top: 0; }
.mg-content p { margin: 0 0 1.1em; }
.mg-content a { color: var(--mg-brand); text-decoration: underline; text-underline-offset: 4px; text-decoration-thickness: 1px; }
.mg-content a:hover { text-decoration-thickness: 2px; }
.mg-content h2,
.mg-content h3,
.mg-content h4,
.mg-content h5,
.mg-content h6 {
    color: var(--mg-navy);
    font-weight: 900;
    line-height: 1.7;
    scroll-margin-top: 90px;
    text-align: start;
}
.mg-content h2 {
    font-size: 24px;
    margin: 1.8em 0 .7em;
    padding-bottom: 8px;
    border-bottom: 2px solid var(--mg-soft);
    position: relative;
}
.mg-content h2::after {
    content: "";
    position: absolute;
    bottom: -2px;
    inset-inline-start: 0;
    width: 70px;
    height: 2px;
    background: var(--mg-brand);
}
.mg-content h3 { font-size: 20px; margin: 1.5em 0 .6em; color: #1d4fa8; }
.mg-content h4 { font-size: 18px; margin: 1.3em 0 .5em; }
.mg-content h5, .mg-content h6 { font-size: 16.5px; margin: 1.2em 0 .5em; }
.mg-content ul,
.mg-content ol { margin: 0 0 1.2em; padding-inline-start: 0; list-style: none; }
.mg-content li { position: relative; padding-inline-start: 30px; margin: .45em 0; }
.mg-content ul > li::before {
    content: "";
    position: absolute;
    inset-inline-start: 8px;
    top: .85em;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--mg-brand);
    box-shadow: 0 0 0 4px var(--mg-soft);
}
.mg-content ol { counter-reset: mg-ol; }
.mg-content ol > li { counter-increment: mg-ol; }
.mg-content ol > li::before {
    content: counter(mg-ol);
    position: absolute;
    inset-inline-start: 0;
    top: .3em;
    width: 22px;
    height: 22px;
    border-radius: 7px;
    background: var(--mg-brand);
    color: #fff;
    font-size: 12px;
    font-weight: 800;
    line-height: 22px;
    text-align: center;
}
.mg-content li > ul, .mg-content li > ol { margin: .4em 0 0; }
.mg-content blockquote {
    margin: 1.4em 0;
    padding: 16px 20px;
    background: #f7f9fd;
    border-inline-start: 4px solid var(--mg-brand);
    border-radius: 12px;
    color: var(--mg-ink);
    font-style: normal;
}
.mg-content img {
    max-width: 100%;
    height: auto;
    border-radius: 14px;
    display: block;
    margin: 1.2em auto;
}
.mg-content figure { margin: 1.4em 0; text-align: center; }
.mg-content figcaption { font-size: 13px; color: var(--mg-muted); margin-top: 6px; }
.mg-content iframe, .mg-content video { max-width: 100%; border-radius: 14px; border: 0; }
.mg-content hr { border: 0; height: 1px; background: var(--mg-line); margin: 2em 0; }
.mg-content code {
    background: var(--mg-soft);
    padding: 1px 6px;
    border-radius: 6px;
    font-size: .92em;
    direction: ltr;
    unicode-bidi: isolate;
}
.mg-content pre {
    background: #0f1b33;
    color: #e6edf9;
    padding: 14px 18px;
    border-radius: 12px;
    overflow-x: auto;
    direction: ltr;
    text-align: left;
}
.mg-content pre code { background: none; padding: 0; color: inherit; }
/* tables: scroll inside their own box on a narrow screen, never the page */
.mg-content table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin: 1.4em 0;
    border: 1px solid var(--mg-line);
    border-radius: 14px;
    font-size: 15px;
    line-height: 1.9;
    text-align: start;
}
.mg-content thead th,
.mg-content tr:first-child th {
    background: var(--mg-navy);
    color: #fff;
    font-weight: 800;
}
.mg-content th, .mg-content td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--mg-line);
    vertical-align: top;
    min-width: 110px;
}
.mg-content tbody tr:nth-child(even) td { background: #f8faff; }
.mg-content tr:last-child td { border-bottom: 0; }

/* the author box under the article */
.mg-author {
    max-width: 820px;
    margin: 28px auto 0;
    display: flex;
    gap: 16px;
    align-items: flex-start;
    padding: 18px 20px;
    border-radius: 16px;
    background: var(--mg-soft);
}
.mg-author__logo { width: 56px; height: 56px; object-fit: contain; border-radius: 14px; background: #fff; padding: 6px; flex: 0 0 auto; }
.mg-author__label { display: block; font-size: 12px; color: var(--mg-muted); }
.mg-author__name { display: block; font-size: 16px; color: var(--mg-navy); margin-bottom: 4px; }
.mg-author__bio { margin: 0; font-size: 14px; line-height: 2; color: var(--mg-ink); }

/* post footer */
.mg-post__foot { max-width: 820px; margin: 26px auto 0; }
.mg-more-cat {
    display: inline-block;
    background: var(--mg-soft);
    color: var(--mg-brand);
    font-weight: 800;
    padding: 8px 18px;
    border-radius: 999px;
}
.mg-adjacent {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-top: 18px;
}
.mg-adjacent__item {
    border: 1px solid var(--mg-line);
    border-radius: 14px;
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    color: var(--mg-ink);
}
.mg-adjacent__item:hover { border-color: var(--mg-brand); }
.mg-adjacent__item span { font-size: 12px; color: var(--mg-muted); }
.mg-adjacent__item strong { font-size: 14.5px; line-height: 1.8; }
.mg-adjacent__item--next { grid-column: 2; text-align: end; }
.mg-related { margin-top: 10px; }

/* ---------- responsive ---------- */
@media (max-width: 991px) {
    .mg-grid, .mg-featured { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
    .mg-card--big { flex-direction: column; }
    .mg-card--big .mg-card__media { flex: none; }
    .mg-card--big .mg-card__body { padding: 18px 20px; }
}
@media (max-width: 600px) {
    .mg-head { padding: 18px 16px; border-radius: 18px; }
    .mg-search { max-width: none; }
    /* one full-width card per row: a big, sharp image (the srcset picks 1200px) */
    .mg-grid, .mg-featured { grid-template-columns: minmax(0, 1fr); gap: 16px; }
    .mg-card--big .mg-card__title { font-size: 19px; }
    .mg-card__excerpt { -webkit-line-clamp: 2; }
    /* a wide table scrolls inside its own box, never the page */
    .mg-content table { display: block; overflow-x: auto; }
    .mg-post { padding: 20px 14px; border-radius: 16px; }
    .mg-post__cover { border-radius: 12px; }
    .mg-content { font-size: 16px; line-height: 2.05; text-align: start; }
    .mg-content h2 { font-size: 21px; }
    .mg-content h3 { font-size: 18.5px; }
    .mg-toc__list { columns: 1; }
    .mg-author { flex-direction: column; }
    .mg-adjacent { grid-template-columns: 1fr; }
    .mg-adjacent__item--next { grid-column: auto; }
}
@media (prefers-reduced-motion: reduce) {
    .mg-card, .mg-card__media img { transition: none; }
    .mg-card:hover .mg-card__media img { transform: none; }
}

/* ---------- draft banner ---------- */
.mg-draft-banner { background: #fff3df; color: #7a4a00; border-radius: 12px; padding: 10px 14px; margin-bottom: 12px; font-size: 14px; }

/* ---------- comments ---------- */
.mg-comments {
    margin-top: 18px;
    background: var(--mg-card);
    border-radius: 20px;
    padding: 22px clamp(16px, 4vw, 40px) 26px;
    box-shadow: 0 1px 2px rgb(16 45 92 / 5%), 0 10px 30px rgb(16 45 92 / 5%);
}
.mg-comments .mg-section-title { margin-top: 0; }
.mg-comments > * { max-width: 820px; margin-inline: auto; }
.mg-comments__count { font-size: 13px; background: var(--mg-soft); color: var(--mg-brand); border-radius: 999px; padding: 0 10px; }
.mg-cform { display: grid; gap: 10px; margin-bottom: 22px; }
.mg-cform__label { font-weight: 700; font-size: 14px; }
.mg-cform textarea,
.mg-cform input[type=text] {
    width: 100%;
    border: 1px solid var(--mg-line);
    border-radius: 12px;
    padding: 12px 14px;
    font: inherit;
    font-size: 15px;
    background: #fbfcfe;
    resize: vertical;
}
.mg-cform textarea:focus, .mg-cform input[type=text]:focus { outline: 2px solid var(--mg-soft); border-color: var(--mg-brand); }
.mg-cform__row { display: flex; gap: 8px; flex-wrap: wrap; }
.mg-cform__row input { flex: 1 1 180px; }
.mg-cform__admin { border: 1px dashed var(--mg-brand); background: var(--mg-soft); border-radius: 12px; padding: 10px 12px; display: grid; gap: 8px; font-size: 13.5px; }
.mg-cform__foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 13.5px; }
.mg-cform__note { color: var(--mg-muted); }
.mg-cform__submit { border: 0; border-radius: 12px; padding: 10px 22px; background: var(--mg-brand); color: #fff; font-weight: 800; cursor: pointer; }
.mg-cform__submit[disabled] { opacity: .6; }
.mg-cform__reply { background: var(--mg-soft); border-radius: 10px; padding: 6px 12px; font-size: 13.5px; }
.mg-cform__reply button { border: 0; background: none; color: var(--mg-brand); cursor: pointer; margin-inline-start: 8px; }
.mg-cform__msg { font-size: 13.5px; min-height: 1em; }
.mg-cform__msg.is-ok { color: #0b7a4b; }
.mg-cform__msg.is-err { color: #b42318; }
.mg-clist { list-style: none; margin: 0 auto; padding: 0; display: grid; gap: 14px; }
.mg-clist--replies { margin: 12px 0 0; padding-inline-start: 14px; border-inline-start: 2px solid var(--mg-soft); }
.mg-c { display: flex; gap: 12px; align-items: flex-start; }
.mg-c__avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; flex: 0 0 auto; background: var(--mg-soft); }
.mg-clist--replies .mg-c__avatar { width: 32px; height: 32px; }
.mg-c__body { min-width: 0; flex: 1; }
.mg-c__head { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; font-size: 13px; color: var(--mg-muted); }
.mg-c__head strong { color: var(--mg-ink); font-size: 14.5px; }
.mg-c__pending { color: #9a5b00; font-size: 12px; }
.mg-c__text { margin: 4px 0 0; line-height: 2; overflow-wrap: anywhere; }
.mg-c__reply { border: 0; background: none; color: var(--mg-brand); font-size: 13px; font-weight: 700; cursor: pointer; padding: 4px 0; }
.mg-comments__empty { color: var(--mg-muted); margin: 0 auto; }
