/* =====================================================================
 * Editor chrome.
 *
 * Two rules govern this file:
 *   1. Nothing here may live inside .page — all chrome is in #ed-bar and
 *      #ed-layer, which are fixed-position children of <body>.
 *   2. Selection affordances use `outline`, never `border` or `padding`:
 *      outline is painted outside the box model and cannot shift the
 *      layout by even a fraction of a point.
 * ===================================================================== */

:root {
  --ed-gold: #BB9653;
  --ed-bg:   #1c1d21;
  --ed-fg:   #e9e9ec;
  --ed-mut:  #9a9aa3;
  --ed-warn: #d9822b;
  --ed-err:  #d64545;
  --ed-ok:   #3d9a5c;
}

body { padding-bottom: calc(var(--ed-barh, 44px) + 16px); }

/* ---------- the scaled stage ----------
 * #ed-fit / #ed-stage are created at RUNTIME by editor.js, never by
 * bake.php, so app/template.html stays byte-identical.
 *
 * overflow:hidden on #ed-fit is required: a transform leaves the layout
 * box at its full 720px and that phantom keeps contributing to the
 * document's scrollable overflow, bringing the horizontal scrollbar
 * straight back. It clips nothing real — #ed-fit is sized to exactly the
 * scaled visual width.
 *
 * display:flow-root on #ed-stage is required: .page has margin:14pt auto,
 * and without a BFC those margins collapse through the wrappers into
 * <body>, so offsetHeight under-reports by 28pt.
 *
 * Never add will-change/filter/contain here — they create a containing
 * block even when transform is none, so they can outlive the print reset.
 */
#ed-fit   { margin: 0 auto; overflow: hidden; }
#ed-stage { width: 540pt; display: flow-root; transform-origin: top left; }

/* ---------- bottom toolbar ---------- */

#ed-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 2147483000;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  background: var(--ed-bg); color: var(--ed-fg);
  font: 13px/1.3 "Segoe UI", system-ui, sans-serif;
  box-shadow: 0 -2px 12px rgba(0,0,0,.35);
  flex-wrap: wrap; row-gap: 6px;
}
.ed-brand { font-weight: 700; color: var(--ed-gold); letter-spacing: .3px; margin-right: 2px; }
.ed-sep   { flex: 1; }

.ed-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: transparent; border: 1px solid #55565e; flex: none;
}
.ed-dot.on { background: var(--ed-warn); border-color: var(--ed-warn); }

.ed-btn {
  font: inherit; color: var(--ed-fg);
  background: #2a2b31; border: 1px solid #3a3b43; border-radius: 5px;
  padding: 5px 11px; cursor: pointer; white-space: nowrap;
}
.ed-btn:hover  { background: #35363e; }
.ed-btn:active { transform: translateY(1px); }
.ed-primary    { background: var(--ed-gold); border-color: var(--ed-gold); color: #1b1b1b; font-weight: 600; }
.ed-primary:hover { background: #c9a463; }
.ed-picker-btn { max-width: min(320px, 42vw); overflow: hidden; text-overflow: ellipsis; }

/* ---------- zoom ---------- */
.ed-zoomgrp { display: flex; align-items: center; gap: 4px; flex: none; }
.ed-zoom    { max-width: 170px; }
/* a native <select> popup is drawn by the OS outside the page box, so
   unlike .ed-pop it can never overflow the viewport */
select.ed-btn { appearance: none; padding-right: 22px;
  background-image: linear-gradient(45deg, transparent 50%, #9a9aa3 50%),
                    linear-gradient(135deg, #9a9aa3 50%, transparent 50%);
  background-position: calc(100% - 13px) 50%, calc(100% - 8px) 50%;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; }
select.ed-btn option { background: #2a2b31; color: var(--ed-fg); }
.ed-chip       { background: #4a3212; border-color: var(--ed-warn); color: #ffd9a8; }

/* ---------- document picker ---------- */

.ed-pop {
  position: absolute; bottom: 100%; margin-bottom: 8px; left: 12px;
  width: min(420px, calc(100vw - 24px)); max-height: 60vh;
  display: flex; flex-direction: column;
  background: #232429; border: 1px solid #3a3b43; border-radius: 8px;
  box-shadow: 0 12px 40px rgba(0,0,0,.5); overflow: hidden;
}
/* display:flex beats the UA's [hidden]{display:none}, so closePicker() set
   the attribute and nothing happened -- the picker stayed open and kept
   swallowing clicks over that corner of the page */
.ed-pop[hidden] { display: none; }

.ed-search {
  font: inherit; color: var(--ed-fg); background: #1a1b1f;
  border: 0; border-bottom: 1px solid #3a3b43; padding: 10px 12px; outline: none;
}
.ed-list { list-style: none; margin: 0; padding: 4px; overflow-y: auto; }

.ed-opt {
  position: relative; padding: 7px 30px 7px 10px; border-radius: 5px; cursor: pointer;
}
.ed-opt:hover, .ed-opt.on { background: #32333b; }
.ed-opt.bad  { opacity: .55; }
.ed-new      { color: var(--ed-gold); border-bottom: 1px solid #3a3b43; border-radius: 0; margin-bottom: 4px; }
.ed-opt-t    { display: flex; align-items: center; gap: 8px; }
.ed-opt-t span:first-child { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ed-opt-s    { color: var(--ed-mut); font-size: 11px; margin-top: 2px; }
.ed-pill     { background: #3a3b43; color: #cfd0d8; border-radius: 10px; padding: 1px 8px; font-size: 11px; }
.ed-empty    { color: var(--ed-mut); padding: 14px 10px; text-align: center; }
.ed-del {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  background: none; border: 0; color: var(--ed-mut); cursor: pointer;
  font-size: 12px; padding: 4px 6px; border-radius: 4px; opacity: 0;
}
.ed-opt:hover .ed-del { opacity: 1; }
.ed-del:hover { color: #fff; background: var(--ed-err); }

/* ---------- floating overlays ---------- */

#ed-layer { position: fixed; inset: 0; z-index: 2147482000; pointer-events: none; }

.ed-rowbar, .ed-imgbar {
  position: fixed; display: flex; gap: 2px; align-items: center;
  background: var(--ed-bg); border: 1px solid #3a3b43; border-radius: 6px;
  padding: 3px; pointer-events: auto;
  box-shadow: 0 4px 14px rgba(0,0,0,.4);
  font: 12px/1 "Segoe UI", system-ui, sans-serif;
}
/* The same trap as .ed-pop above: an author display:flex beats the UA's
   [hidden]{display:none}, so .hidden = true hid nothing and all three bars
   sat painted in the top-left corner from page load onwards -- never placed,
   so position:fixed put them at their static position inside #ed-layer.
   Anything here that sets display must guard [hidden] too. */
.ed-rowbar[hidden], .ed-imgbar[hidden] { display: none; }

.ed-rb {
  font: inherit; color: var(--ed-fg); background: #2a2b31;
  border: 1px solid #3a3b43; border-radius: 4px;
  min-width: 24px; height: 22px; padding: 0 6px; cursor: pointer;
}
.ed-rb:hover { background: var(--ed-gold); color: #1b1b1b; border-color: var(--ed-gold); }
.ed-imglabel { color: var(--ed-mut); padding: 0 6px; max-width: 160px;
               overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- toasts ---------- */

#ed-toasts {
  position: fixed; right: 14px; bottom: calc(var(--ed-barh, 44px) + 26px); z-index: 2147483100;
  display: flex; flex-direction: column; gap: 8px;
  max-width: min(460px, calc(100vw - 28px));
}
.ed-toast {
  display: flex; gap: 10px; align-items: flex-start;
  background: #232429; color: var(--ed-fg);
  border-left: 3px solid var(--ed-mut); border-radius: 6px;
  padding: 10px 12px; font: 12.5px/1.45 "Segoe UI", system-ui, sans-serif;
  box-shadow: 0 8px 26px rgba(0,0,0,.45);
}
.ed-toast.ed-warn  { border-left-color: var(--ed-warn); }
.ed-toast.ed-error { border-left-color: var(--ed-err); }
.ed-toast.ed-ok    { border-left-color: var(--ed-ok); }
.ed-x     { background: none; border: 0; color: var(--ed-mut); cursor: pointer; font-size: 12px; }
.ed-x:hover { color: #fff; }
.ed-warnlist  { display: flex; flex-direction: column; gap: 3px; }
.ed-warnrow   { font: inherit; text-align: left; background: none; color: #ffd9a8;
                border: 0; padding: 3px 0; cursor: pointer; text-decoration: underline; }

/* ---------- úvodný prehľad ----------
 * Celoobrazovková vrstva so zoznamom uloženého. Je to fixed dieťa <body>,
 * nie súčasť .page — pravidlo 1 hore platí aj tu.
 *
 * z-index leží medzi lištou (2147483000) a toastmi (2147483100): prehľad
 * lištu prekryje (tlačidlá Uložiť/Tlač bez otvoreného dokumentu nedávajú
 * zmysel), ale ponuka na obnovenie konceptu a chybové hlásenia zostanú
 * viditeľné nad ním.
 */
#ed-home {
  position: fixed; inset: 0; z-index: 2147483050;
  overflow: auto; overscroll-behavior: contain;
  background: #16171a; color: var(--ed-fg);
  font: 14px/1.45 "Segoe UI", system-ui, sans-serif;
  display: flex; justify-content: center;
}
/* Tá istá pasca ako pri .ed-pop a .ed-rowbar: autorský display:flex porazí
   [hidden]{display:none} od prehliadača, takže vrstva by ostala navždy
   roztiahnutá cez celý editor. */
#ed-home[hidden] { display: none; }

.ed-home-in {
  width: 100%; max-width: 760px; padding: 40px 20px 64px;
  display: flex; flex-direction: column; gap: 18px;
}

.ed-home-hd { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.ed-home-brand { font-size: 26px; font-weight: 700; color: var(--ed-gold); letter-spacing: .3px; }
.ed-home-sub   { color: var(--ed-mut); font-size: 14px; }

.ed-home-bar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.ed-home-bar .ed-btn { flex: none; padding: 8px 14px; }
.ed-home-q {
  flex: 1 1 220px; min-width: 0;
  background: #22232a; color: var(--ed-fg); border: 1px solid #3a3b43;
  border-radius: 6px; padding: 8px 10px; font: inherit;
}
.ed-home-q:focus { outline: none; border-color: var(--ed-gold); }

.ed-home-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }

.ed-home-row {
  background: #22232a; border: 1px solid #2f3038; border-radius: 8px;
  padding: 12px 14px; cursor: pointer;
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px;
  align-items: center;
}
.ed-home-row:hover  { border-color: var(--ed-gold); background: #282932; }
.ed-home-row:focus-visible { outline: 2px solid var(--ed-gold); outline-offset: 2px; }
.ed-home-row.bad    { opacity: .55; cursor: default; }
.ed-home-row.bad:hover { border-color: #2f3038; background: #22232a; }

.ed-home-rt   { display: flex; align-items: center; gap: 8px; min-width: 0; }
.ed-home-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.ed-home-row .ed-opt-s { grid-column: 1; }
.ed-home-act  { grid-column: 2; grid-row: 1 / span 2; display: flex; gap: 6px; align-items: center; }
.ed-home-act .ed-rb { height: 26px; }
.ed-del2:hover { background: var(--ed-err); border-color: var(--ed-err); color: #fff; }

/* prázdny stav má vyzerať ako miesto pre riadok, nie ako stratený text */
.ed-home-list .ed-empty {
  border: 1px dashed #33343b; border-radius: 8px; padding: 30px 16px;
}

.ed-home-foot { color: var(--ed-mut); font-size: 12px; margin: 0; }

@media (max-width: 559px) {
  .ed-home-in  { padding: 24px 14px 48px; }
  .ed-home-row { grid-template-columns: 1fr; }
  .ed-home-act { grid-column: 1; grid-row: auto; margin-top: 8px; }
}

#ed-fileproto {
  position: fixed; inset: 0 0 auto 0; z-index: 2147483200;
  background: var(--ed-err); color: #fff; padding: 14px 18px;
  font: 14px/1.4 "Segoe UI", system-ui, sans-serif;
}

/* =====================================================================
 * Affordances on the document itself — outline only, never border.
 * ===================================================================== */

body.ed-editing [data-ed]:hover,
body.ed-editing [data-ed-slot]:hover {
  outline: 1px dashed rgba(187,150,83,.75); outline-offset: 1px;
}
body.ed-editing [data-ed]:focus,
body.ed-editing [data-ed-slot]:focus {
  outline: 1.5px solid var(--ed-gold); outline-offset: 1px;
}
body.ed-editing [data-ed-img] {
  cursor: pointer; outline: 1px dashed transparent; outline-offset: 2px;
}
body.ed-editing [data-ed-img]:hover { outline-color: rgba(187,150,83,.9); }

body.ed-editing .ed-overflow { outline: 1.5px solid var(--ed-err) !important; outline-offset: 1px; }
body.ed-editing .ed-flash { animation: ed-flash 1.2s ease-out; }
@keyframes ed-flash {
  0%, 100% { outline-color: var(--ed-err); }
  50%      { outline: 3px solid var(--ed-gold); }
}

/* the wrapper the baker adds around each fake info table is 540x0pt and
   must never intercept clicks meant for the header behind it */
[data-ed-table][data-ed-geom] { pointer-events: none; }
[data-ed-table][data-ed-geom] > * { pointer-events: auto; }

/* =====================================================================
 * Breakpoints. The page itself is scaled by JS; this is only the chrome.
 * ===================================================================== */

/* two clean rows instead of flex-wrapping at arbitrary points */
@media (max-width: 999px) {
  .ed-sep { flex-basis: 100%; height: 0; margin: 0; }
}

@media (max-width: 759px) {
  .ed-brand { display: none; }
  .ed-lg { display: none; }
}
@media (min-width: 760px) { .ed-sm { display: none; } }

@media (max-width: 559px) {
  #ed-bar        { gap: 6px; padding: 7px 8px; }
  .ed-btn        { padding: 5px 8px; }
  .ed-picker-btn { max-width: none; flex: 1 1 110px; min-width: 0; }
  .ed-imglabel   { display: none; }
  .ed-pop        { left: 8px; }
}

@media (max-width: 419px) {
  #ed-bar   { font-size: 12px; }
  .ed-btn   { padding: 4px 7px; }
  .ed-zoom  { max-width: 92px; }
  .ed-chip  { padding: 5px 8px; }
}

/* =====================================================================
 * Print: every trace of the editor disappears.
 * ===================================================================== */

@media print {
  body { padding-bottom: 0 !important; }
  #ed-bar, #ed-layer, #ed-toasts, #ed-fileproto, #ed-home { display: none !important; }

  /* display:contents deletes the wrappers' own boxes, so the printed box
     tree is provably identical to the pre-wrapper one — same margin
     collapsing, same fragmentation, same pagination. */
  #ed-fit, #ed-stage { display: contents !important; }
  /* belt-and-braces: if display:contents were ever unsupported, none of
     the properties that make a box monolithic in paged media may survive. */
  #ed-fit, #ed-stage {
    transform: none !important; transform-origin: initial !important;
    width: auto !important; height: auto !important;
    min-width: 0 !important; max-width: none !important;
    margin: 0 !important; padding: 0 !important;
    overflow: visible !important; position: static !important;
    contain: none !important; filter: none !important;
    will-change: auto !important; zoom: 1 !important;
  }
  [data-ed], [data-ed-slot], [data-ed-img] { outline: none !important; }
  /* belt-and-braces: no editor state may tint anything on paper */
  .ed-overflow, .ed-flash { outline: none !important; animation: none !important; }
}

/* ---------- charts ----------
 * The canvas replaces an <img>, so it gets the same selection affordance.
 * Its backing store is the original export's pixel size and CSS scales it
 * to the print box -- never set width/height here or the chart resamples.
 */
body.ed-editing [data-ed-chart] {
  outline: 1px dashed rgba(187,150,83,.55); outline-offset: 1px; cursor: pointer;
}
body.ed-editing [data-ed-chart]:hover { outline-color: rgba(187,150,83,.9); }

.ed-chartpop {
  /* #ed-layer is pointer-events:none so clicks reach the document; anything
     that wants clicks has to opt back in, exactly like .ed-rowbar */
  pointer-events: auto;
  position: fixed; right: 14px; z-index: 2147483100;
  bottom: calc(var(--ed-barh, 44px) + 14px);
  width: min(560px, calc(100vw - 28px));
  max-height: min(70vh, 620px);
  display: flex; flex-direction: column;
  background: var(--ed-bg); color: var(--ed-fg);
  border-radius: 8px; box-shadow: 0 8px 30px rgba(0,0,0,.45);
  font: 13px/1.35 "Segoe UI", system-ui, sans-serif;
}
.ed-chartpop-head,
.ed-chartpop-foot {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; flex: none;
}
.ed-chartpop-head { border-bottom: 1px solid #33343b; }
.ed-chartpop-foot { border-top: 1px solid #33343b; flex-wrap: wrap; }
.ed-chartpop-body { overflow: auto; padding: 6px 10px; }
.ed-chartpop table { border-collapse: collapse; width: 100%; }
.ed-chartpop th {
  text-align: left; font-weight: 600; color: var(--ed-mut);
  padding: 2px 4px; position: sticky; top: 0; background: var(--ed-bg);
}
.ed-chartpop td { padding: 1px 2px; }
.ed-chartpop input {
  width: 100%; box-sizing: border-box;
  background: #26272d; color: var(--ed-fg);
  border: 1px solid #3a3b43; border-radius: 4px;
  padding: 3px 5px; font: inherit;
}
.ed-chartpop input:focus { outline: none; border-color: var(--ed-gold); }
.ed-cnum { text-align: right; font-variant-numeric: tabular-nums; }
.ed-ctext { min-width: 120px; }
.ed-cdel { padding: 2px 6px; }
.ed-chartpop-note { color: var(--ed-mut); font-size: 12px; }

@media print {
  .ed-chartpop { display: none !important; }
  [data-ed-chart] { outline: none !important; }
}

/* running total of a percentage split, in the chart panel's footer */
.ed-sum      { color: var(--ed-mut); font-size: 12px; }
.ed-sum.bad  { color: var(--ed-err); font-weight: 600; }
/* box-shadow, not border: a border would resize the cell mid-typing */
.ed-badrow input { box-shadow: inset 2px 0 0 var(--ed-err); }

/* the card bar: same idiom as .ed-rowbar, including opting back into clicks */
.ed-cardbar {
  position: fixed; display: flex; gap: 2px; align-items: center;
  background: var(--ed-bg); border: 1px solid #3a3b43; border-radius: 6px;
  padding: 3px; pointer-events: auto; z-index: 2147482500;
  box-shadow: 0 4px 14px rgba(0,0,0,.4);
}
.ed-cardbar[hidden] { display: none; }        /* see .ed-rowbar[hidden] above */
.ed-cardbar .ed-btn { padding: 2px 7px; }
body.ed-editing [data-ed-card]:focus-within { outline: 1px dashed rgba(187,150,83,.5); outline-offset: 2px; }
@media print { .ed-cardbar { display: none !important; } [data-ed-card] { outline: none !important; } }
