/* Sdílený vzhled modálů a výběrových chipů (Bandmate + Backstage) — varianta „Papír“.
   Středový dialog: hairline rámeček, velký nadpis, pole jen s podtržením, patička oddělená linkou.
   Na mobilu spodní list. Formuláře (.bs-modal, .bm-drawer) i krátké dialogy (.bm-dialog) vypadají stejně.
   Chipy: A = mřížka stejných buněk pro krátké výběry, D = pole s popoverem (.bm-multi).
   Pravidla: jedna vrstva (z-index 10000, nad plovoucími widgety), zatemnění rgba(20,19,15,.5) + blur,
   hlavička pevná, vybraný stav nikdy nemění rozměr. */

.bs-modal-bg, .bm-drawer-bg, .bm-dialog-bg { --bm-pad: 24px; }

/* zámek scrollu stránky pod otevřeným modálem */
body:has(.bs-modal-bg, .bm-drawer-bg, .bm-dialog-bg) { overflow: hidden; }

/* ── Zatemnění ──────────────────────────────────────────────────── */
.bs-modal-bg, .bm-drawer-bg, .bm-dialog-bg {
  position: fixed; inset: 0; z-index: var(--z-modal, 10000); display: flex; align-items: center; justify-content: center;
  padding: 20px; overflow-y: auto; background: rgba(20, 19, 15, .5);
  -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px);
  animation: bm-fade .18s ease-out;
}

/* ── Dialog (formulář i potvrzení) ──────────────────────────────── */
.bs-modal, .bm-drawer, .bm-dialog {
  position: relative; width: 100%; max-width: 520px; margin: auto; box-sizing: border-box;
  max-height: calc(100vh - 40px); max-height: calc(100dvh - 40px); overflow-y: auto; overscroll-behavior: contain;
  padding: 0 var(--bm-pad) 0; gap: 18px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 24px 60px -20px rgba(20, 19, 15, .45);
  animation: bm-pop .18s cubic-bezier(.2, .8, .2, 1);
}
.bs-modal.bs-modal-wide, .bm-drawer.wide { max-width: min(780px, 100%); }
/* podle obsahu: editor dokumentů s náhledem je dvousloupcový, stage plot potřebuje plátno */
.bs-modal.bm2-split { max-width: min(1240px, 100%); }
.bs-modal.bs-modal-xl { max-width: min(980px, 100%); }
/* dvousloupcový editor: první sloupec není hlavička, takže bez sticky a bez záporných okrajů */
.bs-modal.bm2-split { padding-top: 22px; padding-bottom: 22px; }
.bs-modal.bm2-split > :first-child { position: static; margin: 0; padding: 0; background: none; }
.bm-dialog { max-width: 420px; padding: var(--bm-pad); }
/* formulář bez vlastní patičky: dolní okraj */
.bs-modal:not(:has(> .bs-row.bs-end:last-child)), .bm-drawer:not(:has(> .bm-foot:last-child)) { padding-bottom: 28px; }

/* hlavička zůstává při scrollu nahoře */
.bs-modal > :first-child, .bm-drawer > :first-child {
  position: sticky; top: 0; z-index: 3; margin: 0 calc(var(--bm-pad) * -1); padding: 22px var(--bm-pad) 6px; background: var(--bg);
}
.bs-modal .bs-h2, .bm-drawer .bm-h { font-size: 26px; letter-spacing: -0.05em; line-height: 1.1; }
.bs-x { flex: none; }
.bm-drawer { display: flex; flex-direction: column; gap: 0; }
.bm-drawer > :first-child { margin-bottom: 14px; }
.bm-drawer > :first-child .bm-h { margin: 0; font-weight: 700; }

/* patička s akcemi zůstává dole, scrolluje jen obsah */
.bs-modal > .bs-row.bs-end:last-child, .bm-drawer > .bm-foot:last-child {
  position: sticky; bottom: 0; z-index: 3; margin: 0 calc(var(--bm-pad) * -1); padding: 14px var(--bm-pad) calc(14px + env(safe-area-inset-bottom));
  background: var(--bg); border-top: 1px solid var(--line); flex-wrap: nowrap;
}
.bm-drawer > .bm-foot:last-child { display: flex; gap: 8px; justify-content: flex-end; align-items: center; }

/* pole jen s podtržením */
:is(.bs-modal, .bm-drawer) .field-in {
  border: 0; border-bottom: 1px solid var(--line-2); border-radius: 0; background: none; padding: 9px 2px; box-shadow: none;
}
:is(.bs-modal, .bm-drawer) .field-in:focus { border-bottom-color: var(--ink); }
:is(.bs-modal, .bm-drawer) textarea.field-in { padding-top: 9px; }

@keyframes bm-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes bm-pop { from { transform: scale(.97); opacity: .4; } to { transform: none; opacity: 1; } }
@keyframes bm-rise { from { transform: translateY(32px); opacity: .4; } to { transform: none; opacity: 1; } }

/* ── Mobil: spodní list ─────────────────────────────────────────── */
@media (max-width: 760px) {
  .bs-modal-bg, .bm-drawer-bg, .bm-dialog-bg { --bm-pad: 18px; align-items: flex-end; padding: 0; }
  .bs-modal, .bm-drawer, .bm-dialog, .bs-modal.bs-modal-wide, .bm-drawer.wide {
    max-width: 100% !important; margin: 0; max-height: 90vh; max-height: 90dvh; border: 0; border-radius: 20px 20px 0 0;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, .3); animation: bm-rise .22s cubic-bezier(.2, .8, .2, 1);
  }
  .bm-dialog { padding-bottom: calc(var(--bm-pad) + 6px + env(safe-area-inset-bottom)); }
  .bs-modal > :first-child, .bm-drawer > :first-child { padding-top: 22px; }
  .bs-modal > :first-child::before, .bm-drawer > :first-child::before {
    content: ''; position: absolute; top: 7px; left: 50%; width: 38px; height: 4px; margin-left: -19px; border-radius: 4px; background: var(--line-2);
  }
  .bs-modal > .bs-row.bs-end:last-child .btn-accent, .bs-modal > .bs-row.bs-end:last-child .btn-primary { flex: 1; }
}
@media (prefers-reduced-motion: reduce) { .bs-modal-bg, .bs-modal, .bm-drawer-bg, .bm-drawer, .bm-dialog-bg, .bm-dialog { animation: none; } }

/* ── Chipy A: mřížka stejných buněk ─────────────────────────────── */
.bs-modal .seg, .fe .seg, .bm-drawer .seg, .bm-choice {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px;
}
.bs-modal .seg:has(> :nth-child(3):last-child), .fe .seg:has(> :nth-child(3):last-child), .bm-drawer .seg:has(> :nth-child(3):last-child), .bm-choice.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (min-width: 761px) {
  .bs-modal .seg:has(> :nth-child(4):last-child):not(.long), .fe .seg:has(> :nth-child(4):last-child):not(.long), .bm-drawer .seg:has(> :nth-child(4):last-child):not(.long), .bm-choice.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .bm-choice.c5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}
.bs-modal .seg button, .fe .seg button, .bm-drawer .seg button, .bm-choice button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 44px; padding: 6px 8px;
  border-radius: 10px; border: 1px solid var(--line-2); background: none; color: var(--ink);
  font: 500 14px/1.2 inherit; font-family: inherit; text-align: center; white-space: normal; overflow-wrap: anywhere;
  transition: background .12s ease, border-color .12s ease, color .12s ease;
}
.bs-modal .seg button:hover, .fe .seg button:hover, .bm-drawer .seg button:hover, .bm-choice button:hover { border-color: var(--ink); }
.bs-modal .seg button.on, .fe .seg button.on, .bm-drawer .seg button.on, .bm-choice button.on { background: var(--ink); border-color: var(--ink); color: var(--bg); font-weight: 500; }
.bs-modal .seg button.on::before, .fe .seg button.on::before, .bm-drawer .seg button.on::before, .bm-choice button.on::before { content: '✓'; font-size: 12px; line-height: 1; }
.bs-modal .seg button:focus-visible, .fe .seg button:focus-visible, .bm-drawer .seg button:focus-visible, .bm-choice button:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* ── Chipy D: pole s popoverem (vícenásobný výběr, 6+ položek) ──── */
.bm-multi { position: relative; }
.bm-multi-field {
  width: 100%; min-height: 44px; display: flex; align-items: center; flex-wrap: wrap; gap: 6px; padding: 6px 2px;
  border: 0; border-bottom: 1px solid var(--line-2); border-radius: 0; background: none; color: var(--ink); text-align: left; font: 15px inherit; font-family: inherit;
}
.bm-multi-field.open, .bm-multi-field:focus-visible { border-bottom-color: var(--ink); outline: none; }
.bm-multi-ph { color: var(--ink-4); }
.bm-multi-chev { margin-left: auto; color: var(--ink-3); display: inline-flex; transition: transform .15s; }
.bm-multi-field.open .bm-multi-chev { transform: rotate(180deg); }
.bm-multi-tok { display: inline-flex; align-items: center; gap: 4px; padding: 3px 4px 3px 11px; border: 1px solid var(--line-2); border-radius: 999px; background: var(--bg); font-size: 13.5px; font-weight: 500; }
.bm-multi-tok i { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-style: normal; color: var(--ink-3); cursor: pointer; }
.bm-multi-tok i:hover { background: var(--bg-3); color: var(--ink); }
.bm-multi-menu {
  position: absolute; z-index: 5; left: 0; right: 0; top: calc(100% + 6px); max-height: 232px; overflow-y: auto; padding: 6px;
  border: 1px solid var(--line-2); border-radius: 12px; background: var(--bg); box-shadow: 0 16px 40px -16px rgba(20, 19, 15, .4);
}
.bm-multi-menu button { width: 100%; display: flex; align-items: center; gap: 10px; padding: 10px; border: 0; border-radius: 8px; background: none; color: var(--ink); text-align: left; font-size: 14.5px; font-family: inherit; }
.bm-multi-menu button:hover { background: var(--bg-2); }
.bm-multi-bx { width: 18px; height: 18px; flex: none; display: grid; place-items: center; border: 1.5px solid var(--line-2); border-radius: 5px; color: var(--bg); font-size: 12px; line-height: 1; }
.bm-multi-menu .on .bm-multi-bx { background: var(--ink); border-color: var(--ink); }
.bm-multi-open-pad { height: 240px; }
