/*
 * Obsah článku (diskuze) – tytéž styly pro zobrazení (.discussion-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):
 *   - 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) se vkládají PŘED stylopisy webu, takže tady stačí stejná
 * specifičnost. Žádné pravidlo nesmí platit mimo .discussion-content / .ck-content – výjimkou jsou pravidla
 * .ck.ck-editor…, která platí jen pro UI editoru (plocha a obal editoru), ne pro obsah článku ani zbytek webu, a obsah
 * článku z nadpisů .article-contents (stojí nad textem článku ve stejném čtecím sloupci).
 */

/* 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(--font-sans);
    --ck-content-font-size: 1rem;
    --ck-content-line-height: var(--bs-body-line-height);
    --ck-content-font-color: var(--bs-body-color);
}

/* Plocha editoru roste s obsahem; formulář stránky zarovnává na střed, text článku ale začíná vlevo. */
.ck.ck-editor {
    text-align: start;
}

.ck.ck-editor__main > .ck-editor__editable {
    min-height: 300px;
}

/* Čtecí sloupec: text článku má nejvýš --article-max-width a stojí na středu karty; 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. Strop výšky obrázku drží fotku na výšku a snímek telefonu celé v okně. */
.discussion-content,
.ck-content {
    --article-max-width: 800px;
    --article-image-max-height: min(70vh, 720px);
}

/* Barvy tabulek a bloků Tip / Pozor (tmavý vzhled v bloku html[data-bs-theme="dark"] níže). */
:root {
    --article-table-border: #c9ced4;
    --article-table-header-bg: #f1f3f5;
    --article-callout-tip-bar: #198754;
    --article-callout-tip-bg: #edf7f1;
    --article-callout-warning-bar: #e0a800;
    --article-callout-warning-bg: #fff8e1;
}

.discussion-content {
    max-width: var(--article-max-width);
    margin-inline: auto;
}

.ck.ck-editor__main > .ck-editor__editable.ck-content {
    box-sizing: content-box;
    max-width: var(--article-max-width);
    margin-inline: auto;
}

/* Plovoucí obrázky nesmí přetéct pod konec článku. */
.discussion-content::after,
.ck-content::after {
    content: "";
    display: table;
    clear: both;
}

/* Dlouhá adresa v textu odkazu se zalomí, jinak by na telefonu roztáhla článek do šířky. */
.discussion-content a,
.ck-content a {
    overflow-wrap: anywhere;
}

/* Obrázky nikdy nepřetečou šířku článku a drží poměr stran. */
.discussion-content img,
.ck-content img {
    max-width: 100%;
    height: auto;
}

.discussion-content img {
    cursor: zoom-in;
}

/* Obrázek otevíraný z klávesnice (lightbox.js mu doplní tabindex): zřetelný fokus v barvě odkazů obou vzhledů. */
.discussion-content img.lightbox-focusable:focus-visible {
    outline: 3px solid var(--primary-text);
    outline-offset: 2px;
}

/* Blokový obrázek: na střed, šířka podle obrázku (nejvýš šířka článku). */
.discussion-content .image,
.ck-content .image {
    display: table;
    clear: both;
    text-align: center;
    margin: 1em auto;
    min-width: 50px;
}

.discussion-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);
    /* Obrázek zúžený stropem výšky drží poměr stran a stojí na středu svého místa. */
    object-fit: contain;
}

/* Zmenšený obrázek: šířku v % nese atribut style figure / img. Spodní mez šířky drží dřívější zmenšení na 30 až 50 %
   (dělaná pro širší sloupec) čitelná i ve čtecím sloupci. */
.discussion-content .image.image_resized,
.ck-content .image.image_resized {
    display: block;
    box-sizing: border-box;
    max-width: 100%;
    min-width: min(100%, 480px);
}

.discussion-content .image.image_resized img,
.ck-content .image.image_resized img {
    width: 100%;
}

.discussion-content .image.image_resized > figcaption,
.ck-content .image.image_resized > figcaption {
    display: block;
}

.discussion-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. */
.discussion-content p img,
.discussion-content li img {
    vertical-align: bottom;
}

/* Obtékání vlevo / vpravo (blokový obrázek i obrázek v řádku). */
.discussion-content .image-style-align-left,
.ck-content .image-style-align-left {
    float: left;
    margin-right: 1.5em;
}

.discussion-content .image-style-align-right,
.ck-content .image-style-align-right {
    float: right;
    margin-left: 1.5em;
}

.discussion-content .image.image-style-align-left,
.discussion-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;
}

.discussion-content img.image-style-align-left,
.discussion-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. */
.discussion-content .image > figcaption,
.ck-content .image > figcaption {
    display: table-caption;
    caption-side: bottom;
    padding: .5em .75em;
    font-size: .875em;
    line-height: 1.4;
    color: var(--bs-secondary-color);
    background-color: var(--bs-tertiary-bg);
    word-break: normal;
    overflow-wrap: anywhere;
}

/* Galerie fotek: po sobě jdoucí blokové obrázky se stylem galerie tvoří mřížku čtvercových náhledů – na monitoru
   4 vedle sebe, pod 768 px 2. Šířka dlaždice přebíjí i zmenšení z editoru (style na figure); celou fotku a popisek
   ukáže prohlížeč fotek (lightbox.js), v článku se popisek neukazuje. */
.discussion-content figure.image.image-style-gallery,
.ck-content figure.image.image-style-gallery {
    display: inline-block;
    vertical-align: top;
    box-sizing: border-box;
    width: 25% !important;
    min-width: 0;
    max-width: none;
    margin: 0;
    padding: 2px;
    clear: none;
}

.discussion-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;
}

.discussion-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. */
.discussion-content blockquote,
.ck-content blockquote {
    margin: 1em 0;
    padding: .25em 1.25em;
    border-left: 4px solid var(--bs-border-color);
    color: var(--bs-secondary-color);
    font-style: italic;
    overflow: hidden;
}

.discussion-content hr,
.ck-content hr {
    display: block;
    width: 100%;
    height: 0;
    margin: 1.5em 0;
    border: 0;
    border-top: 2px solid var(--bs-border-color);
    background: none;
    opacity: 1;
}

/* 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. V editoru se posouvá stejně
   (pravidlo .ck.ck-editor__editable figure.table níže), plocha editoru tak do strany nejede. */
.discussion-content figure.table {
    display: block;
    clear: both;
    box-sizing: border-box;
    max-width: 100%;
    margin: 1em 0;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.discussion-content figure.table > table,
.ck-content figure.table > table {
    width: 100%;
    height: auto;
    border-collapse: collapse;
    border: 1px solid var(--article-table-border);
}

.discussion-content figure.table td,
.discussion-content figure.table th,
.ck-content figure.table td,
.ck-content figure.table th {
    min-width: 5em;
    padding: .4em .6em;
    border: 1px solid var(--article-table-border);
    vertical-align: top;
    text-align: start;
    overflow-wrap: normal;
}

.discussion-content figure.table th,
.ck-content figure.table th {
    font-weight: 600;
    background-color: var(--article-table-header-bg);
}

/* Odstavce v buňce bez mezer navíc (editor obaluje víceřádkový text buňky do <p>). */
.discussion-content figure.table td > p,
.discussion-content figure.table th > p {
    margin: 0;
}

.discussion-content figure.table td > p + p,
.discussion-content figure.table th > p + p {
    margin-top: .5em;
}

/* Široká tabulka v editoru se posouvá uvnitř své obálky. Obálka posouvaná do strany ořízne vše, co z ní vyčnívá, proto
   úchyt pro výběr tabulky a tlačítka „vložit odstavec před / za“ leží uvnitř obálky – stejné rozložení, jaké CKEditor 49
   používá pro tabulky širší než editor (třída ck-table-overflowing pluginu TableScroll, ten se ale řídí jen šířkou
   tabulky z TableColumnResize, kterou editor článků nemá). Výběr buněk a kontextová lišta tabulky na tom nezávisí
   (lišta je plovoucí panel mimo plochu editoru). Třída .ck-content v selektoru přebíjí display:table ze stylů CKEditoru,
   které se načítají až po tomto souboru. */
.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 přes celé okno ani dostat strop výšky blokového obrázku. */
.discussion-content figure.table img,
.ck-content figure.table img {
    max-width: 100%;
}

/* Blok Tip (rada) a Pozor (upozornění): zvýrazněný blok s barevným pruhem vlevo; obsah jsou odstavce, seznamy i další bloky. */
.discussion-content .callout,
.ck-content .callout {
    clear: both;
    margin: 1em 0;
    padding: .75em 1em;
    border-inline-start: 4px solid var(--article-callout-tip-bar);
    border-radius: .375rem;
    background-color: var(--article-callout-tip-bg);
    color: var(--bs-body-color);
    overflow-wrap: break-word;
}

.discussion-content .callout.callout-warning,
.ck-content .callout.callout-warning {
    border-inline-start-color: var(--article-callout-warning-bar);
    background-color: var(--article-callout-warning-bg);
}

.discussion-content .callout > :first-child,
.ck-content .callout > :first-child {
    margin-top: 0;
}

.discussion-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. */
.discussion-content .media,
.ck-content .media {
    display: block;
    clear: both;
    min-width: 15em;
    margin: 1em 0;
}

.discussion-content .embed-responsive,
.ck-content .embed-responsive {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    overflow: hidden;
}

.discussion-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, na telefonu by byl obrázek nečitelně malý. Obrázky v řádku zůstávají vedle sebe
   (řady náhledů po 32 %). Editor kreslí totéž co uložený článek. */
@media (max-width: 767.98px) {
    .discussion-content .image.image_resized,
    .ck-content .image.image_resized {
        width: 100% !important;
    }

    .discussion-content .image-style-align-left,
    .discussion-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;
    }

    .discussion-content figure.image.image-style-gallery,
    .ck-content figure.image.image-style-gallery {
        width: 50% !important;
    }
}

/* Tmavý vzhled editoru (lišta, nabídky, dialogy, plocha): CKEditor 5 skládá všechny barvy UI ze základních
   proměnných --ck-color-base-* na :root; selektor html[…] je silnější, takže jejich přepsáním se přebarví celé UI
   (odvozené proměnné se dosazují na témže prvku). Text obsahu bere --bs-body-color (pravidlo .ck-content výše). */
html[data-bs-theme="dark"] {
    --ck-color-base-background: #212529;
    --ck-color-base-foreground: #2b3035;
    --ck-color-base-border: #495057;
    --ck-color-base-border-light: #3d4650;
    --ck-color-base-text: #dee2e6;
    --ck-color-base-text-light: #adb5bd;
    --ck-color-base-hover: #343a40;
    --ck-color-base-hover-strong: #3d444b;
    --ck-color-base-selected: #1f3250;
    --ck-color-base-selected-hover: #26406a;
    --ck-color-base-active: #6ea8fe;
    --ck-color-base-active-focus: #6ea8fe;
    --ck-color-base-action: #3a7cd5;
    --ck-color-base-action-hover: #1e5aaa;
    --ck-color-base-action-muted: #1b2738;
    --ck-color-base-action-disabled: #2f4a73;
    /* Text tlačítka akce (Uložit, Vložit) je v CKEditoru barva podkladu editoru – v tmavém by byl tmavý na modré. */
    --ck-color-interactive-primary-text: #fff;
    --ck-color-base-focus: #6ea8fe;
    --ck-color-base-error-shadow: #2c0b0e;
    --ck-color-shadow-drop: rgba(0, 0, 0, 0.5);
    --ck-color-shadow-drop-active: rgba(0, 0, 0, 0.6);
    --ck-color-shadow-inner: rgba(0, 0, 0, 0.4);
    --ck-color-engine-placeholder-text: #8794a5;
    --ck-color-link-default: #6ea8fe;
    --ck-color-media-embed-placeholder-url-text: #adb5bd;
    --ck-color-upload-placeholder-loader: #6c757d;
    --ck-content-color-image-caption-background: #2b3035;
    --ck-content-color-image-caption-text: #dee2e6;
    --article-table-border: #495057;
    --article-table-header-bg: #2b3035;
    --article-callout-tip-bar: #3fb37f;
    --article-callout-tip-bg: #17291f;
    --article-callout-warning-bar: #ffc107;
    --article-callout-warning-bg: #2f2810;
}

@media print {
    .discussion-content .image,
    .discussion-content .media {
        break-inside: avoid;
    }
}

/* Kotvy kapitol (ArticleContents doplňuje id="kap-…" nadpisům h2/h3 při vykreslení): po skoku na kapitolu zůstane nad
   nadpisem kousek místa (hlavička webu není pevná, stačí malý odstup). */
.discussion-content [id^="kap-"] {
    scroll-margin-top: 1rem;
}

/* Odkaz na kapitolu u nadpisu (jen článek se zapnutým obsahem): nenápadná značka # v barvě vedlejšího textu, modrá při
   najetí a fokusu. */
.discussion-content .heading-anchor {
    margin-inline-start: .4em;
    color: var(--muted-text);
    font-weight: 400;
    text-decoration: none;
}

.discussion-content .heading-anchor:hover,
.discussion-content .heading-anchor:focus-visible {
    color: var(--primary-text);
}

/* Obsah článku z nadpisů – nav.article-contents stojí těsně nad .discussion-content ve stejném čtecím sloupci. */
.article-contents {
    max-width: 800px;
    margin: 0 auto 1.5rem;
    padding: .75rem 1rem;
    border: 1px solid var(--bs-border-color);
    border-radius: .5rem;
    background: var(--bs-tertiary-bg);
}

.article-contents summary {
    font-weight: 600;
    cursor: pointer;
}

.article-contents ol {
    margin: .5rem 0 0;
    padding-inline-start: 1.5rem;
}

.article-contents ol ol {
    margin-top: .25rem;
    list-style-type: disc;
}

/* Nadpisy s vlastním číslem (ArticleContents.HasOwnNumbers): bez čísel seznamu, text u okraje rámečku, vnořené víc odsazené. */
.article-contents .article-contents__own-numbers {
    list-style: none;
    padding-inline-start: 0;
}

.article-contents .article-contents__own-numbers ol {
    padding-inline-start: 2rem;
}

.article-contents li {
    margin: .2rem 0;
    overflow-wrap: anywhere;
}

.article-contents a {
    color: var(--primary-text);
    text-decoration: none;
}

.article-contents a:hover,
.article-contents a:focus-visible {
    text-decoration: underline;
}
