/*
 * Obsah článku (SVAT-295, převzato z Discussion `article-content.css`, přebarveno na tokeny design systemu) – tytéž styly
 * pro zobrazení (.sw-article-content) i pro editor (.ck-content), aby článek v editoru vypadal stejně jako po uložení.
 * Formát obsahu generuje CKEditor 5 (wwwroot/js/ckeditor-interop.js), pevný bod sanitizeru Application/Common/ArticleHtml:
 *   - blokový obrázek  <figure class="image [image_resized] [image-style-align-left|right]" style="width:N%"><img>[<figcaption>]</figure>
 *   - obrázek v řádku  <img [class="image_resized|image-style-align-left|right"] style="width:N%"> uvnitř odstavce
 *   - galerie          po sobě jdoucí <figure class="image image-style-gallery"><img>[<figcaption>]</figure>
 *   - YouTube          <figure class="media"><div data-oembed-url><div class="embed-responsive …"><iframe class="embed-responsive-item"></div></div></figure>
 *   - tabulka          <figure class="table"><table>[<thead><tr><th>…]<tbody><tr><td [colspan] [rowspan]>…</table></figure>
 *   - Tip / Pozor      <div class="callout">…</div> / <div class="callout callout-warning">…</div>
 * Styly CKEditoru (lib/ckeditor5/…/ckeditor5.css) vkládá interop PŘED stylopisy webu, takže tady stačí stejná specifičnost.
 * Žádné pravidlo nesmí platit mimo .sw-article-content / .ck-content – výjimkou jsou pravidla .ck.ck-editor…, která platí
 * jen pro UI editoru. Barvy jen z tokens.css (design system kap. 2), písma Fraunces (nadpisy) + Manrope (text).
 */

/* Písmo a velikost textu editoru jako u zobrazeného článku (proměnné CKEditoru přepsané na jeho ploše). */
.ck-content {
    --ck-content-font-family: var(--sw-font-text);
    --ck-content-font-size: var(--sw-article-fs);
    --ck-content-line-height: var(--sw-article-lh);
    --ck-content-font-color: var(--sw-text);
    --ck-content-color-image-caption-background: var(--sw-surface-tint);
    --ck-content-color-image-caption-text: var(--sw-text-muted);
}

/* UI editoru v barvách webu: lišta a rámeček (CKEditor skládá barvy z proměnných --ck-color-*). */
.sw-ck-host {
    --ck-color-base-border: var(--sw-divider-strong);
    --ck-color-focus-border: var(--sw-primary);
    --ck-color-base-active: var(--sw-primary);
    --ck-color-base-active-focus: var(--sw-primary-strong);
    --ck-color-button-on-background: var(--sw-primary-soft);
    --ck-color-button-on-hover-background: var(--sw-primary-soft);
    --ck-color-button-on-color: var(--sw-primary-strong);
    --ck-color-link-default: var(--sw-primary-strong);
    --ck-border-radius: var(--sw-radius-input);
    --ck-font-face: var(--sw-font-text);
}

.ck.ck-editor {
    text-align: start;
}

.ck.ck-editor__main > .ck-editor__editable {
    min-height: 320px;
    background: var(--sw-surface);
}

/* Čtecí sloupec: text článku má nejvýš --article-max-width a stojí na středu; v editoru stejně široká plocha
   (content-box, aby vnitřní odsazení editoru šířku textu nezmenšilo). Procenta zmenšených obrázků se tak na monitoru
   vztahují vždy k téže šířce (ArticleImageMarkup počítá sizes z 800 px). Strop výšky obrázku drží fotku na výšku celou v okně. */
.sw-article-content,
.ck-content {
    --article-max-width: 800px;
    --article-image-max-height: min(70vh, 720px);
    --sw-article-fs: 16px;
    --sw-article-lh: 1.65;
}

.sw-article-content {
    max-width: var(--article-max-width);
    margin-inline: auto;
    color: var(--sw-text);
    font-family: var(--sw-font-text);
    font-size: var(--sw-article-fs);
    line-height: var(--sw-article-lh);
    overflow-wrap: break-word;
}

.ck.ck-editor__main > .ck-editor__editable.ck-content {
    box-sizing: content-box;
    max-width: var(--article-max-width);
    margin-inline: auto;
}

/* Nadpisy obsahu (h2–h4 z editoru) – Fraunces jako nadpisy webu. */
.sw-article-content :is(h2, h3, h4),
.ck-content :is(h2, h3, h4) {
    margin: 1.6em 0 .5em;
    color: var(--sw-text);
    font-family: var(--sw-font-display);
    font-weight: 500;
    line-height: 1.2;
    text-wrap: balance;
}
/* Kotvy kapitol (id doplňuje ArticleHeadings při zobrazení): po skoku na nadpis zůstane nad ním odstup jako u .sw-anchor. */
.sw-article-content :is(h2, h3, h4)[id] { scroll-margin-top: var(--sw-space-5); }
/* Odkaz „#“ na kapitolu na konci nadpisu (jen článek se zobrazeným obsahem, ArticleHeadings.HeadingLinkClass): nenápadný,
   barva akce při najetí a fokusu. V okně článku appky skrytý – odkaz tam nejde zkopírovat. */
.sw-article-content .sw-heading-anchor {
    margin-inline-start: .35em;
    color: var(--sw-text-muted);
    font-family: var(--sw-font-text);
    font-weight: 400;
    text-decoration: none;
}
.sw-article-content .sw-heading-anchor:hover,
.sw-article-content .sw-heading-anchor:focus-visible { color: var(--sw-primary-strong); }
body.app-mode .sw-article-content .sw-heading-anchor { display: none; }
.sw-article-content h2, .ck-content h2 { font-size: 1.75em; }
.sw-article-content h3, .ck-content h3 { font-size: 1.4em; }
.sw-article-content h4, .ck-content h4 { font-size: 1.15em; }
.sw-article-content > :first-child { margin-top: 0; }

.sw-article-content p,
.ck-content p {
    margin: 0 0 1em;
}

/* Odkazy v textu: šalvěj s podtržením (barva nikdy jediný nositel významu). */
.sw-article-content a,
.ck-content a {
    color: var(--sw-primary-strong);
    text-decoration: underline;
    text-underline-offset: 2px;
    overflow-wrap: anywhere;
}
.sw-article-content a:hover { color: var(--sw-primary); }

/* Plovoucí obrázky nesmí přetéct pod konec článku. */
.sw-article-content::after,
.ck-content::after {
    content: "";
    display: table;
    clear: both;
}

/* Obrázky nikdy nepřetečou šířku článku a drží poměr stran. */
.sw-article-content img,
.ck-content img {
    max-width: 100%;
    height: auto;
}

.sw-article-content img {
    cursor: zoom-in;
}

/* Jemný okraj obrázků (snímky obrazovky s bílým pozadím jinak splývají se stránkou). Prstenec stínem, ne border: nemění
   rozměry ani rozvržení, kopíruje zaoblení a lightbox (vlastní img mimo obsah) ho nemá. Dlaždice galerie bez okraje
   (ořezané čtverce v mřížce by rámečky rušily) – pravidlo níže. */
.sw-article-content img,
.ck-content img {
    box-shadow: 0 0 0 1px var(--sw-divider-strong);
}

/* Obrázek otevíraný z klávesnice (article-lightbox.js mu doplní tabindex): zřetelný fokus (kap. 6.1). */
.sw-article-content img.article-lightbox-focusable:focus-visible {
    outline: 3px solid var(--sw-primary);
    outline-offset: 2px;
}

/* Blokový obrázek: na střed, šířka podle obrázku (nejvýš šířka článku). */
.sw-article-content .image,
.ck-content .image {
    display: table;
    clear: both;
    text-align: center;
    margin: 1em auto;
    min-width: 50px;
}

.sw-article-content .image img,
.ck-content .image img {
    display: block;
    margin: 0 auto;
    max-width: 100%;
    min-width: 100%;
    height: auto;
    max-height: var(--article-image-max-height);
    object-fit: contain;
    border-radius: var(--sw-radius-input);
}

/* Zmenšený obrázek: šířku v % nese atribut style figure / img. */
.sw-article-content .image.image_resized,
.ck-content .image.image_resized {
    display: block;
    box-sizing: border-box;
    max-width: 100%;
    min-width: min(100%, 200px);
}

.sw-article-content .image.image_resized img,
.ck-content .image.image_resized img {
    width: 100%;
}

.sw-article-content .image.image_resized > figcaption,
.ck-content .image.image_resized > figcaption {
    display: block;
}

.sw-article-content img.image_resized,
.ck-content img.image_resized {
    height: auto;
}

/* Obrázky v řádku textu stojí vedle sebe a zarovnávají se na řádek. */
.sw-article-content p img,
.sw-article-content li img {
    vertical-align: bottom;
}

/* Obtékání vlevo / vpravo (blokový obrázek i obrázek v řádku). */
.sw-article-content .image-style-align-left,
.ck-content .image-style-align-left {
    float: left;
    margin-right: 1.5em;
}

.sw-article-content .image-style-align-right,
.ck-content .image-style-align-right {
    float: right;
    margin-left: 1.5em;
}

.sw-article-content .image.image-style-align-left,
.sw-article-content .image.image-style-align-right,
.ck-content .image.image-style-align-left,
.ck-content .image.image-style-align-right {
    clear: none;
    margin-top: .25em;
    margin-bottom: 1em;
}

.sw-article-content img.image-style-align-left,
.sw-article-content img.image-style-align-right,
.ck-content .image-inline.image-style-align-left,
.ck-content .image-inline.image-style-align-right {
    margin-top: .25em;
    margin-bottom: .75em;
}

/* Popisek obrázku. */
.sw-article-content .image > figcaption,
.ck-content .image > figcaption {
    display: table-caption;
    caption-side: bottom;
    padding: .5em .75em;
    font-size: var(--sw-fs-secondary);
    font-weight: 600;
    line-height: 1.4;
    color: var(--sw-text-muted);
    background-color: transparent;
    word-break: normal;
    overflow-wrap: anywhere;
}

/* Galerie fotek: po sobě jdoucí blokové obrázky se stylem galerie tvoří mřížku čtvercových náhledů (dlaždice 1:1 jako
   galerie svatby) – na monitoru 4 vedle sebe, pod 768 px 2. Šířka dlaždice přebíjí i zmenšení z editoru; celou fotku a
   popisek ukáže prohlížeč fotek (article-lightbox.js), v článku se popisek neukazuje. */
.sw-article-content figure.image.image-style-gallery,
.ck-content figure.image.image-style-gallery {
    display: block;
    float: left;
    box-sizing: border-box;
    width: 25% !important;
    min-width: 0;
    max-width: none;
    margin: 0;
    padding: 3px;
    clear: none;
}

/* Galerie začíná pod obtékanými obrázky (jinak by se dlaždice vtěsnaly vedle plovoucího obrázku): dlaždice jsou plovoucí
   bloky (clear na inline-block nepůsobí), první dlaždice řady má clear: both a první prvek za galerií taky, ať text pod
   galerií nezačne vedle poslední řady. Dlaždice mají stejnou výšku (čtverec), takže řady se neskládají „schodovitě“. */
.sw-article-content figure.image.image-style-gallery:not(figure.image-style-gallery + figure.image-style-gallery),
.ck-content figure.image.image-style-gallery:not(figure.image-style-gallery + figure.image-style-gallery),
.sw-article-content figure.image-style-gallery + :not(figure.image-style-gallery),
.ck-content figure.image-style-gallery + :not(figure.image-style-gallery) {
    clear: both;
}

.sw-article-content figure.image.image-style-gallery img,
.ck-content figure.image.image-style-gallery img {
    width: 100%;
    min-width: 100%;
    height: auto;
    max-height: none;
    /* Přebíjí poměr stran originálu, který editor zapisuje do style obrázku. */
    aspect-ratio: 1 !important;
    object-fit: cover;
    border-radius: var(--sw-radius-button-sm);
    box-shadow: none;
}

.sw-article-content figure.image.image-style-gallery > figcaption {
    display: none;
}

.ck-content figure.image.image-style-gallery > figcaption {
    display: block;
    padding: .25em .4em;
    font-size: .75em;
}

/* Citace a vodorovná čára. */
.sw-article-content blockquote,
.ck-content blockquote {
    margin: 1.25em 0;
    padding: .25em 1.25em;
    border-left: 4px solid var(--sw-primary-soft);
    color: var(--sw-text-muted);
    font-family: var(--sw-font-display);
    font-size: 1.1em;
    font-style: italic;
    overflow: hidden;
}

.sw-article-content hr,
.ck-content hr {
    display: block;
    width: 100%;
    height: 0;
    margin: 1.75em 0;
    border: 0;
    border-top: 2px solid var(--sw-divider-strong);
    background: none;
    opacity: 1;
}

/* Seznamy. */
.sw-article-content :is(ul, ol),
.ck-content :is(ul, ol) {
    margin: 0 0 1em;
    padding-inline-start: 1.5em;
}
.sw-article-content li + li { margin-top: .25em; }

/* Tabulka: obálka figure.table drží šířku článku, širší tabulka se posouvá do strany uvnitř obálky (stránka nepřeteče).
   Buňky mají spodní mez šířky, aby se úzké sloupce na telefonu nelámaly po písmenech. */
.sw-article-content figure.table {
    display: block;
    clear: both;
    box-sizing: border-box;
    max-width: 100%;
    margin: 1.25em 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.sw-article-content figure.table > table,
.ck-content figure.table > table {
    width: 100%;
    height: auto;
    border-collapse: collapse;
    border: 1px solid var(--sw-divider-strong);
    background: var(--sw-surface);
    font-size: .95em;
}

.sw-article-content figure.table td,
.sw-article-content figure.table th,
.ck-content figure.table td,
.ck-content figure.table th {
    min-width: 5em;
    padding: .45em .7em;
    border: 1px solid var(--sw-divider-strong);
    vertical-align: top;
    text-align: start;
    overflow-wrap: normal;
}

.sw-article-content figure.table th,
.ck-content figure.table th {
    font-weight: 700;
    background-color: var(--sw-surface-tint);
}

/* Odstavce v buňce bez mezer navíc (editor obaluje víceřádkový text buňky do <p>). */
.sw-article-content figure.table td > p,
.sw-article-content figure.table th > p {
    margin: 0;
}

.sw-article-content figure.table td > p + p,
.sw-article-content figure.table th > p + p {
    margin-top: .5em;
}

/* Široká tabulka v editoru se posouvá uvnitř své obálky; úchyt výběru tabulky a tlačítka „odstavec před / za“ leží uvnitř
   obálky (rozložení třídy ck-table-overflowing CKEditoru 49), posouvaná obálka by je jinak ořízla. Třída .ck-content
   v selektoru přebíjí display:table ze stylů CKEditoru. */
.ck.ck-editor__editable.ck-content figure.table {
    display: flex;
    flex-direction: column;
    box-sizing: border-box;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
}

.ck.ck-editor__editable figure.table.ck-widget.ck-widget_with-selection-handle > .ck-widget__selection-handle {
    --ck-widget-handler-icon-size: 10px;
    transform: translateY(calc(0px - var(--ck-widget-outline-thickness)));
    z-index: 3;
}

.ck.ck-editor__editable figure.table.ck-widget > .ck-widget__type-around {
    --ck-widget-type-around-button-size: 16px;
    pointer-events: none;
    position: absolute;
    inset: 0;
}

.ck.ck-editor__editable figure.table.ck-widget > .ck-widget__type-around > .ck-widget__type-around__button_before,
.ck.ck-editor__editable figure.table.ck-widget > .ck-widget__type-around > .ck-widget__type-around__button_after {
    transform: none;
    z-index: 2;
}

.ck.ck-editor__editable figure.table.ck-widget > .ck-widget__type-around > .ck-widget__type-around__button_before {
    margin-left: var(--ck-widget-type-around-button-size);
    border-radius: 0 0 100px 100px;
    left: min(10%, 30px);
}

.ck.ck-editor__editable figure.table.ck-widget > .ck-widget__type-around > .ck-widget__type-around__button_before::after {
    border-radius: 0 0 100px 100px;
}

.ck.ck-editor__editable figure.table.ck-widget > .ck-widget__type-around > .ck-widget__type-around__button_after {
    bottom: calc(-.5 * var(--ck-widget-outline-thickness));
    border-radius: 100px 100px 0 0;
    right: min(10%, 30px);
}

.ck.ck-editor__editable figure.table.ck-widget > .ck-widget__type-around > .ck-widget__type-around__button_after::after {
    border-radius: 100px 100px 0 0;
}

.ck.ck-editor__editable figure.table.ck-widget > .ck-widget__type-around svg {
    width: 10px;
    height: 8px;
}

/* Obrázek v buňce nesmí roztáhnout tabulku ani dostat strop výšky blokového obrázku. */
.sw-article-content figure.table img,
.ck-content figure.table img {
    max-width: 100%;
}

/* Blok Tip (rada, šalvěj) a Pozor (upozornění, terakota – kap. 2: varování = accent): pruh vlevo na tónovém podkladu. */
.sw-article-content .callout,
.ck-content .callout {
    clear: both;
    margin: 1.25em 0;
    padding: .85em 1.1em;
    border-inline-start: 4px solid var(--sw-primary);
    border-radius: var(--sw-radius-input);
    background-color: var(--sw-primary-soft);
    color: var(--sw-text);
    overflow-wrap: break-word;
}

.sw-article-content .callout.callout-warning,
.ck-content .callout.callout-warning {
    border-inline-start-color: var(--sw-accent);
    background-color: var(--sw-accent-soft);
}

.sw-article-content .callout > :first-child,
.ck-content .callout > :first-child {
    margin-top: 0;
}

.sw-article-content .callout > :last-child,
.ck-content .callout > :last-child {
    margin-bottom: 0;
}

/* Vložené video YouTube přes celou šířku textu v poměru 16:9. */
.sw-article-content .media,
.ck-content .media {
    display: block;
    clear: both;
    min-width: 15em;
    margin: 1.25em 0;
}

.sw-article-content .embed-responsive,
.ck-content .embed-responsive {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    overflow: hidden;
    border-radius: var(--sw-radius-input);
    background: var(--sw-media-bg);
}

.sw-article-content .embed-responsive .embed-responsive-item,
.ck-content .embed-responsive .embed-responsive-item {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
}

/* Na úzkém displeji obrázky přestanou obtékat a blokové obrázky zaberou celou šířku článku – zmenšení v % je určené
   pro šířku počítače. Obrázky v řádku zůstávají vedle sebe. Editor kreslí totéž co uložený článek. */
@media (max-width: 767.98px) {
    .sw-article-content .image.image_resized,
    .ck-content .image.image_resized {
        width: 100% !important;
    }

    .sw-article-content .image-style-align-left,
    .sw-article-content .image-style-align-right,
    .ck-content .image-style-align-left,
    .ck-content .image-style-align-right {
        float: none;
        display: block;
        width: 100% !important;
        margin-left: 0;
        margin-right: 0;
    }

    .sw-article-content figure.image.image-style-gallery,
    .ck-content figure.image.image-style-gallery {
        width: 50% !important;
    }
}

@media print {
    .sw-article-content .image,
    .sw-article-content .media {
        break-inside: avoid;
    }
}
