/* Sdílená hlavička Boatry v1 (docs/SHARED_HEADER.md, PLAN 4b.13). Jeden soubor pro dokument
   i shadow DOM: pravidla pro elementy boatry-header a boatry-bottom-nav platí jen v dokumentu
   (rezervovaná výška), zbytek jen uvnitř shadow DOM. Logické vlastnosti kvůli RTL. */

/* ---- Dokument: rezervovaná výška (kap. 5 kontraktu) ---- */
boatry-header {
  display: block;
  min-height: 84px;
}

boatry-bottom-nav {
  display: block;
  position: fixed;
  inset-inline: 0;
  inset-block-end: 0;
  z-index: 1030;
  height: calc(64px + env(safe-area-inset-bottom));
}

/* Položky hostitele ve slotu spodní lišty: barvy z proměnných komponenty (dědí je z :host). */
boatry-bottom-nav > a {
  color: var(--bh-muted, #4d5d6b);
  font-weight: 600;
  text-decoration: none;
}

boatry-bottom-nav > a > span {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

boatry-bottom-nav > a[aria-current="page"] {
  color: var(--bh-current, #0b5c99);
}

@media (min-width: 768px) {
  boatry-header {
    min-height: 92px;
  }

  boatry-bottom-nav {
    display: none;
  }
}

/* ---- Shadow DOM ---- */
:host {
  --bh-bg: #ffffff;
  --bh-fg: #14212b;
  --bh-muted: #4d5d6b;
  --bh-border: #d8e0e7;
  --bh-hover: #eef3f7;
  --bh-accent: #0b5c99;
  --bh-accent-fg: #ffffff;
  --bh-strip-bg: #0b3d64;
  --bh-strip-fg: #ffffff;
  --bh-strip-label: rgba(255, 255, 255, 0.2);
  --bh-pop-bg: #ffffff;
  --bh-shadow: 0 8px 24px rgba(10, 30, 50, 0.18);
  --bh-badge: #c62828;
  --bh-badge-fg: #ffffff;
  --bh-focus: #1a73c8;
  --bh-current: #0b5c99;
  display: block;
  color: var(--bh-fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
}

:host([theme="dark"]) {
  --bh-bg: #12202c;
  --bh-fg: #e6edf3;
  --bh-muted: #a9b8c6;
  --bh-border: #2a3b4a;
  --bh-hover: #1d2f3e;
  --bh-accent: #4ea3e6;
  --bh-accent-fg: #0b1620;
  --bh-strip-bg: #08263f;
  --bh-strip-fg: #e6edf3;
  --bh-strip-label: rgba(255, 255, 255, 0.16);
  --bh-pop-bg: #172836;
  --bh-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  --bh-badge: #ef5350;
  --bh-focus: #7cc0f5;
  --bh-current: #7cc0f5;
}

:host([theme="night"]) {
  /* Noční vzhled pro noční vidění na lodi: jen červená na černé (barvy nočního vzhledu Edu,
     packages/app/src/styles.css). */
  --bh-bg: #000000;
  --bh-fg: #ff4d4d;
  --bh-muted: #e64545;
  --bh-border: #4d0000;
  --bh-hover: #1f0000;
  --bh-accent: #ff6666;
  --bh-accent-fg: #000000;
  --bh-strip-bg: #120000;
  --bh-strip-fg: #ff6666;
  --bh-strip-label: rgba(255, 77, 77, 0.18);
  --bh-pop-bg: #120000;
  --bh-shadow: none;
  --bh-badge: #ff6666;
  --bh-badge-fg: #000000;
  --bh-focus: #ff9999;
  --bh-current: #ff9999;
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :host([theme="auto"]),
  :host(:not([theme])) {
    --bh-bg: #12202c;
    --bh-fg: #e6edf3;
    --bh-muted: #a9b8c6;
    --bh-border: #2a3b4a;
    --bh-hover: #1d2f3e;
    --bh-accent: #4ea3e6;
    --bh-accent-fg: #0b1620;
    --bh-strip-bg: #08263f;
    --bh-strip-fg: #e6edf3;
    --bh-strip-label: rgba(255, 255, 255, 0.16);
    --bh-pop-bg: #172836;
    --bh-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    --bh-badge: #ef5350;
    --bh-focus: #7cc0f5;
    --bh-current: #7cc0f5;
  }
}

:host(boatry-bottom-nav) {
  /* Spodní lišta je fixní i u hostitele, který nenačítá pravidla pro dokument (kap. 5). */
  position: fixed;
  inset-inline: 0;
  inset-block-end: 0;
  z-index: 1030;
}

@media (min-width: 768px) {
  :host(boatry-bottom-nav) {
    display: none;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

a {
  color: inherit;
  text-decoration: none;
}

a:focus-visible,
summary:focus-visible,
button:focus-visible {
  outline: 2px solid var(--bh-focus);
  outline-offset: 2px;
  border-radius: 6px;
}

summary {
  list-style: none;
  cursor: pointer;
}

summary::-webkit-details-marker {
  display: none;
}

.bh-icon {
  flex: 0 0 auto;
  display: block;
}

:host([dir="rtl"]) .bh-icon-flip {
  transform: scaleX(-1);
}

/* Horní řádek */
.bh-bar {
  height: 48px;
  background: var(--bh-bg);
  border-block-end: 1px solid var(--bh-border);
}

.bh-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  width: min(100%, 1320px);
  height: 100%;
  margin-inline: auto;
  padding-inline: 16px;
}

.bh-logo {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-weight: 700;
  font-size: 18px;
}

.bh-brand {
  white-space: nowrap;
}

.bh-mark {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--bh-accent);
  color: var(--bh-accent-fg);
  font-size: 16px;
}

.bh-nav,
.bh-tools {
  display: none;
}

.bh-nav {
  align-items: center;
  gap: 2px;
  min-width: 0;
  margin-inline-start: 12px;
}

.bh-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 8px;
  color: var(--bh-muted);
  font-weight: 500;
  white-space: nowrap;
}

.bh-link:hover {
  background: var(--bh-hover);
  color: var(--bh-fg);
}

.bh-link[aria-current="page"] {
  color: var(--bh-current);
  box-shadow: inset 0 -2px 0 var(--bh-current);
  border-radius: 8px 8px 0 0;
}

.bh-tools {
  align-items: center;
  gap: 8px;
  margin-inline-start: auto;
}

.bh-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding-inline: 12px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: none;
  color: var(--bh-fg);
  font: inherit;
  font-weight: 500;
  white-space: nowrap;
}

summary.bh-button:hover,
.bh-button:hover {
  background: var(--bh-hover);
}

.bh-button-outline {
  border-color: var(--bh-accent);
  color: var(--bh-accent);
}

.bh-button-primary {
  background: var(--bh-accent);
  color: var(--bh-accent-fg);
}

.bh-button-primary:hover {
  background: var(--bh-accent);
  filter: brightness(1.1);
}

.bh-account-name {
  max-width: 14em;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Rozbalovací nabídky (details) */
.bh-menu {
  position: relative;
}

.bh-pop {
  position: absolute;
  inset-block-start: calc(100% + 6px);
  inset-inline-end: 0;
  z-index: 10;
  min-width: 220px;
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  padding: 6px;
  border: 1px solid var(--bh-border);
  border-radius: 10px;
  background: var(--bh-pop-bg);
  box-shadow: var(--bh-shadow);
}

.bh-pop-title {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px 6px;
  color: var(--bh-muted);
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bh-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--bh-fg);
  font: inherit;
  text-align: start;
  cursor: pointer;
}

.bh-item:hover {
  background: var(--bh-hover);
}

.bh-item[aria-current] {
  color: var(--bh-current);
  font-weight: 600;
}

.bh-item > span:not(.bh-badge) {
  flex: 1 1 auto;
}

.bh-language-form {
  margin: 0;
}

.bh-sep {
  margin: 6px 4px;
  border: 0;
  border-block-start: 1px solid var(--bh-border);
}

.bh-badge {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding-inline: 5px;
  border-radius: 10px;
  background: var(--bh-badge);
  color: var(--bh-badge-fg);
  font-size: 12px;
  font-weight: 700;
}

/* Pruh s posledním článkem magazínu */
.bh-strip {
  height: 36px;
  background: var(--bh-strip-bg);
  color: var(--bh-strip-fg);
  font-size: 14px;
}

.bh-strip-link {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  height: 100%;
}

a.bh-strip-link:hover .bh-strip-title {
  text-decoration: underline;
}

.bh-strip-label {
  flex: 0 0 auto;
  padding: 1px 8px;
  border-radius: 4px;
  background: var(--bh-strip-label);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.bh-strip-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (min-width: 768px) {
  .bh-bar {
    height: 56px;
  }

  .bh-nav,
  .bh-tools {
    display: flex;
  }
}

@media (min-width: 768px) and (max-width: 1359.98px) {
  /* Jen ikony; popisek zůstává pro čtečky obrazovky. */
  .bh-link > span,
  .bh-account-name,
  .bh-admin-label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
}

/* Jazyk a vzhled hostitele (režim hostitele a náhradní hlavička) */
.bh-prefs {
  display: flex;
  align-items: center;
  gap: 8px;
}

.bh-prefs-sheet {
  display: block;
}

.bh-prefs-sheet .bh-languages + .bh-pop-title,
.bh-prefs-sheet .bh-themes + .bh-pop-title {
  margin-block-start: 6px;
}

.bh-themes {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 2px;
}

.bh-lang-code {
  font-weight: 600;
  text-transform: uppercase;
}

/* Spodní lišta (rám: Účet, slot, menu) */
.bbn {
  display: flex;
  align-items: stretch;
  height: calc(64px + env(safe-area-inset-bottom));
  padding-block-end: env(safe-area-inset-bottom);
  background: var(--bh-bg);
  border-block-start: 1px solid var(--bh-border);
  box-shadow: 0 -4px 16px rgba(10, 30, 50, 0.08);
}

.bbn-side {
  flex: 0 0 64px;
}

.bbn-slot {
  display: flex;
  flex: 1 1 auto;
  min-width: 0;
}

.bbn-item,
::slotted(a) {
  display: flex;
  flex: 1 1 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-width: 0;
  height: 64px;
  padding: 6px 2px;
  color: var(--bh-muted);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  overflow: hidden;
}

.bbn-item {
  position: relative;
}

.bbn-item > span:not(.bh-badge) {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

::slotted(a[aria-current="page"]),
.bbn-item[aria-current="page"],
details[open] > .bbn-item {
  color: var(--bh-current);
}

.bbn-badge {
  position: absolute;
  inset-block-start: 4px;
  inset-inline-start: calc(50% + 4px);
}

.bbn-panel {
  position: fixed;
  inset-inline: 0;
  inset-block-end: calc(64px + env(safe-area-inset-bottom));
  max-height: min(70vh, 560px);
  overflow-y: auto;
  padding: 8px 8px 12px;
  border-block-start: 1px solid var(--bh-border);
  border-radius: 14px 14px 0 0;
  background: var(--bh-pop-bg);
  box-shadow: var(--bh-shadow);
}

.bbn-panel .bh-item {
  min-height: 44px;
}

.bh-languages {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 2px;
}

.bh-languages .bh-language-form {
  display: contents;
}

@media (min-width: 768px) {
  .bbn {
    display: none;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .bh-pop,
  .bbn-panel {
    animation: bh-in 0.12s ease-out;
  }
}

@keyframes bh-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
}
