[v-cloak] {
  display: none;
}

body {
  display: flex;
  min-height: 100vh;
}

body:has([v-cloak]):after {
  content: '';
  position: fixed;
  top: calc(50% - 50px);
  left: calc(50% - 50px);
  width: 50px;
  aspect-ratio: 1;
  border-radius: 50%;
  border: 8px solid var(--spb-blue-light);
  border-top-color: var(--spb-blue);
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

button {
  min-inline-size: unset !important;
}

#app {
  flex-grow: 1;
  min-width: 0;
}

.flash-container {
  width: min(920px, 100% - 32px);
  margin: 0 auto;
  padding: 0 0 120px;
}

.load-error {
  width: min(560px, calc(100% - 32px));
  margin: 15vh auto 0;
  background: var(--spb-surface);
  border: 1px solid var(--outline-variant);
  border-radius: var(--spb-radius);
  box-shadow: 0 8px 28px rgb(0 26 77 / 0.07);
  padding: 24px;
}

.load-error h5 {
  margin: 0 0 10px;
  color: var(--spb-navy);
}

.load-error p {
  margin: 0 0 16px;
  color: var(--spb-muted);
  line-height: 1.5;
}

/* ---------- home header ---------- */

.site-header {
  padding: 18px 24px 10px;
  background: transparent;
  border-bottom: 1px solid var(--outline-variant);
  margin-bottom: 18px;
}

.top-nav {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 10px;
  min-block-size: 64px;
  white-space: normal;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
  min-width: 0;
}

.brand-logo {
  width: 58px;
  height: 58px;
  flex: none;
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  min-width: 0;
}

.brand-text strong {
  font-size: 1.02rem;
  color: var(--spb-navy);
  white-space: nowrap;
}

.brand-text small {
  font-size: 0.75rem;
  color: var(--spb-muted);
}


.top-nav > button {
  margin: 0;
  padding-inline: 10px;
  color: var(--spb-navy);
}

.top-nav > button > span {
  font-size: 0.8rem;
}

/* ---------- home content ---------- */

.page-intro {
  background: var(--surface);
  border: 1px solid var(--outline-variant);
  border-radius: var(--spb-radius);
  box-shadow: 0 6px 24px rgb(0 26 77 / 0.06);
  padding: 22px 24px;
  margin: 0 0 22px;
}

.page-intro h5 {
  margin: 0 0 8px;
  color: var(--spb-navy);
}

.page-intro p {
  margin: 0;
  color: var(--spb-muted);
  line-height: 1.55;
  max-width: 62ch;
}

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin: 0 0 12px;
}

.section-title h6 {
  margin: 0;
  color: var(--spb-navy);
}

.wiki-link {
  font-size: 0.82rem;
  text-decoration: none;
  white-space: nowrap;
}

.search-field {
  margin: 0 0 14px !important;
  background: #fff;
}

.device-list,
.role-list {
  background: var(--spb-surface);
  border-radius: var(--spb-radius);
  border: 1px solid var(--outline-variant);
  box-shadow: 0 4px 18px rgb(0 26 77 / 0.04);
}

.device-list > li:first-child,
.role-list > li:first-child {
  border-top-left-radius: var(--spb-radius);
  border-top-right-radius: var(--spb-radius);
}

.device-list > li:last-child,
.role-list > li:last-child {
  border-bottom-left-radius: var(--spb-radius);
  border-bottom-right-radius: var(--spb-radius);
}

.device-list > li,
.role-list > li {
  white-space: normal;
  padding: 0;
  min-block-size: 0;
}

.device-list > li:not(:last-child),
.role-list > li:not(:last-child) {
  border-bottom: 1px solid var(--outline-variant);
}

.device-select {
  width: 100%;
  box-sizing: border-box;
  margin: 0 !important;
  padding: 12px 16px !important;
  block-size: auto !important;
  min-block-size: 56px !important;
  justify-content: flex-start !important;
  text-align: left;
  color: var(--on-surface);
  background: transparent;
}

.device-select > .max {
  flex: 1;
}

.device-select:hover {
  background: #f4f8ff;
}

.type-icon {
  width: 24px;
  height: 24px;
  opacity: 0.7;
  flex: none;
}

.device-name {
  font-weight: 600;
  font-size: 0.95rem;
  white-space: normal;
  min-width: 0;
}

.custom-row > label {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  cursor: pointer;
  background: #fbfdff;
  width: 100%;
}

.custom-text {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.custom-text strong {
  font-size: 0.92rem;
}

.custom-text small {
  color: var(--spb-muted);
  font-size: 0.75rem;
}

.site-footer {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: flex-start;
  align-items: center;
  gap: 10px 18px;
  min-block-size: 0;
  margin-top: 28px;
  padding: 16px 0 0;
  border-top: 1px solid var(--outline-variant);
  background: transparent;
  color: var(--spb-muted);
  font-size: 0.78rem;
}

/* Обычные текстовые ссылки — подчёркивание только при наведении.
   Сюда же относятся «Настройка» и «Консоль» в футере: это кнопки,
   но выглядят и ведут себя как ссылки. */
.site-footer a,
.wiki-link,
.inline-note a,
.notes-link,
.site-footer .footer-action {
  text-decoration: none;
}

.site-footer a:hover,
.wiki-link:hover,
.inline-note a:hover,
.notes-link:hover,
.site-footer .footer-action:hover:not(:disabled) {
  text-decoration: underline;
}

/* «Настройка» и «Консоль» в футере выглядят как обычные ссылки,
   но открывают конфигуратор и последовательную консоль */
.site-footer .footer-action {
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  block-size: auto;
  min-block-size: 0;
  min-inline-size: 0;
  box-shadow: none;
  color: var(--spb-blue);
  font: inherit;
  font-size: 0.78rem;
  line-height: inherit;
  cursor: pointer;
}

/* BeerCSS добавляет кнопкам волну и тень при наведении — для ссылки не нужно */
.site-footer .footer-action::after {
  display: none;
}

.site-footer .footer-action:hover:not(:disabled) {
  box-shadow: none;
}

.site-footer .footer-action:disabled {
  color: var(--spb-muted);
  opacity: 0.6;
  cursor: not-allowed;
}

.footer-credit {
  margin-left: auto;
}

@media screen and (max-width: 720px) {
  .footer-credit {
    margin-left: 0;
  }
}

/* ---------- device / role screens ---------- */

.screen-header {
  /* BeerCSS задаёт header display:flex, justify-content:center и
     min-block-size:4rem — из-за этого строка с крошками центрировалась
     и прыгала на 8 px между экраном ролей и экраном версии */
  display: block;
  min-block-size: 0;
  padding-block: 0;
  background: transparent;
  margin: 20px 0 16px;
}

.screen-header nav {
  white-space: normal;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 48px;
}

.screen-header nav > button {
  margin: 0;
}

.node-name {
  font-size: 1.375rem;   /* имя ноды — главный заголовок экрана */
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.01em;
  color: var(--spb-navy);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-type-icon {
  width: 22px;
  height: 22px;
  opacity: 0.65;
}

.screen-title h6 {
  margin: 14px 0 4px;
  color: var(--spb-navy);
}

.screen-title p {
  margin: 0;
  color: var(--spb-muted);
  font-size: 0.88rem;
}

.role-list {
  margin-bottom: 16px;
}

.firmware-class {
  background: var(--surface-container);
  padding: 8px 16px !important;
  min-block-size: auto !important;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--spb-muted);
}

.role-select {
  width: 100%;
  box-sizing: border-box;
  margin: 0 !important;
  padding: 12px 16px !important;
  block-size: auto !important;
  min-block-size: 60px !important;
  justify-content: flex-start !important;
  text-align: left;
  color: var(--on-surface);
  background: transparent;
}

.role-select:hover {
  background: #f4f8ff;
}

.role-select > i:first-child {
  color: var(--spb-blue);
  background: var(--spb-blue-light);
  border-radius: var(--spb-radius);
  padding: 9px;
  flex: none;
}

.role-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
  min-width: 0;
  white-space: normal;
}

.role-text strong {
  font-size: 0.95rem;
}

.role-text span {
  font-size: 0.8rem;
  color: var(--spb-muted);
  line-height: 1.35;
}

.chevron {
  color: var(--spb-muted);
  flex: none;
}

/* ---------- firmware screen ---------- */

.firmware-card {
  background: var(--spb-surface);
  border-radius: var(--spb-radius);
  border: 1px solid var(--outline-variant);
  box-shadow: 0 8px 28px rgb(0 26 77 / 0.07);
  padding: 22px 24px;
}

.firmware-heading {
  display: flex;
  align-items: flex-start;
  gap: 14px;
}

.firmware-heading h5 {
  margin: 0 0 6px;
  color: var(--spb-navy);
}

.firmware-heading p {
  margin: 0;
  color: var(--spb-muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.firmware-icon {
  color: var(--spb-blue);
  background: var(--spb-blue-light);
  border-radius: var(--spb-radius);
  padding: 10px;
  flex: none;
}

.notice {
  margin: 16px 0;
}

.notice article,
.observer-notice,
.switch-notice {
  display: block;
  padding: 12px 14px;
  border-radius: var(--spb-radius);
  box-shadow: none;
  font-size: 0.86rem;
  line-height: 1.5;
}

.observer-notice {
  background: var(--spb-orange-light);
  border-left: 4px solid var(--spb-orange);
  color: #5a2100;
}

.switch-notice {
  background: var(--spb-blue-light);
  border-left: 4px solid var(--spb-blue);
  color: var(--spb-navy);
}

.switch-notice a {
  color: var(--spb-blue);
  font-weight: 600;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

.switch-notice a:hover {
  text-decoration-thickness: 2px;
}

.settings-link {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 10px 0 0;
  font-size: 0.875rem;
}

.settings-link a {
  text-decoration: none;
}

.settings-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 12px 3px 9px;
  border: 1px solid #b9d2ff;
  border-radius: var(--spb-radius);
  background: var(--spb-blue-light);
  color: var(--spb-blue);
  font-weight: 600;
  line-height: 1.4;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s;
}

.settings-chip i {
  flex: none;
  min-inline-size: 0;
  font-size: 1.05rem;
  color: var(--spb-blue);
}

.settings-chip:hover,
.settings-chip:focus {
  background: #d3e3ff;
  border-color: var(--spb-blue);
}

.settings-chip.primary {
  background: var(--spb-blue);
  border-color: var(--spb-blue);
  color: #ffffff;
}

.settings-chip.primary i {
  color: #ffffff;
}

.settings-chip.primary:hover,
.settings-chip.primary:focus {
  background: #00317f;
  border-color: #00317f;
}

/* кнопка стирания flash: красная и прижата вправо вместе с «Скачать».
   Селектор с .actions нужен, чтобы перебить «.actions button { margin: 0 }»
   и стиль .border из BeerCSS. */
/* правая группа: «Скачать» прижимается вправо всегда, а если есть
   кнопка стирания — они уезжают вправо вместе */
.actions > button[data-ui="#downloads"] {
  margin-inline-start: auto;
}

.actions:has(.erase-button) > button[data-ui="#downloads"] {
  margin-inline-start: 0;
}

.actions .erase-button {
  margin-inline-start: auto;   /* «Прошить!» остаётся слева */
  color: #b3261e;
  border-color: #b3261e;
  background: #fdeceb;
}

.actions .erase-button i {
  color: #b3261e;
}

.actions .erase-button:hover,
.actions .erase-button:focus {
  background: #f9d4d0;
  border-color: #8c1d18;
  color: #8c1d18;
}

.actions .erase-button:hover i,
.actions .erase-button:focus i {
  color: #8c1d18;
}

.settings-note {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 8px 0 0;
  color: var(--spb-muted);
  font-size: 0.82rem;
  line-height: 1.5;
}

.settings-note i {
  flex: none;
  min-inline-size: 0;
  font-size: 1.05rem;
  /* высота строки = высота строки текста (0.82rem × 1.5), поэтому
     иконка центрируется по первой строке, а не липнет к верху блока */
  block-size: 1.23rem;
  min-block-size: 1.23rem;
  line-height: 1.23rem;
  color: var(--spb-blue);
}

.settings-note code {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--spb-navy);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.95em;
}

.version-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-start;
  margin: 18px 0;
}

.version-field {
  min-width: 220px;
  margin: 0 !important;
}

.notes {
  flex: 1;
  min-width: 260px;
  background: var(--surface-container-low);
  border: 1px solid var(--outline-variant);
  border-radius: var(--spb-radius);
  padding: 12px 14px;
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--on-surface);
}

.notes b {
  color: var(--spb-navy);
}

.notes-link {
  display: inline-block;
  margin-block-start: 6px;
  font-size: 0.78rem;
  font-weight: 600;
}

.options-list {
  border-radius: var(--spb-radius);
  margin: 10px 0 14px;
}

.options-list > li {
  padding: 6px 14px;
}

.inline-note {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  background: var(--surface-container);
  border-radius: var(--spb-radius);
  padding: 12px 14px;
  color: var(--spb-muted);
  font-size: 0.85rem;
  line-height: 1.45;
  margin: 12px 0;
}

.inline-note i {
  color: var(--spb-blue);
  flex: none;
}

.observer-confirm {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--spb-orange-light);
  border: 1px solid #ffd0b5;
  border-radius: var(--spb-radius);
  padding: 14px 16px;
  margin: 18px 0 8px;
  white-space: normal;
}

.observer-confirm span {
  white-space: normal;
  color: #5a2100;
  font-size: 0.88rem;
  line-height: 1.4;
  padding-inline-start: 0.25rem;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin: 18px 0 6px;
}

.actions button {
  margin: 0;
}

.actions button span {
  white-space: normal;
}

.archive-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 0;
}

.archive-progress progress {
  flex: 1;
}

.archive-progress span {
  font-size: 0.78rem;
  color: var(--spb-muted);
  min-width: 3ch;
  text-align: right;
}

.browser-note {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  color: var(--error);
  font-size: 0.84rem;
  margin: 12px 0 0;
}

/* ---------- flashing screen ---------- */

.flash-result {
  background: var(--spb-surface);
  border-radius: var(--spb-radius);
  border: 1px solid var(--outline-variant);
  box-shadow: 0 8px 28px rgb(0 26 77 / 0.07);
  padding: 22px 24px;
}

.flash-result h6 {
  margin: 0 0 8px;
  color: var(--spb-navy);
}

.error-card {
  border-left: 4px solid var(--error);
}

.autoscroller {
  overflow: auto;
  max-height: 300px;
  display: flex;
  flex-direction: column-reverse;
  margin: 14px 0;
  background: #0f1b2d;
  border-radius: var(--spb-radius);
  padding: 12px;
}

.term {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: #d7e6ff;
  font-size: 0.75rem;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  margin: 0;
  /* BeerCSS красит любой pre в светлый фон с синей полосой — внутри
     тёмного лога прошивки это делает текст нечитаемым */
  background: transparent;
  border: 0;
  border-radius: 0;
  padding: 0;
}

.progress-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.progress-row progress {
  flex: 1;
}

.progress-row span {
  font-size: 0.78rem;
  color: var(--spb-muted);
  min-width: 4ch;
  text-align: right;
}

/* ---------- console ---------- */

.overlay {
  display: flex !important;
  flex-direction: column;
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--background);
  padding: 8px 16px 16px;
}

.overlay header {
  background: transparent;
  min-block-size: 56px;
}

/* Терминал: вывод и поле ввода живут в одном прокручиваемом блоке,
   как в официальном прошивальщике. */
.console {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 16px;
  background: #0f1b2d;
  color: #d7e6ff;
  border: 0;
  border-radius: var(--spb-radius);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.84rem;
  line-height: 1.5;
  white-space: pre-wrap;
}

.console code {
  display: block;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.console .holder {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 1.5em;
}

.console-prompt {
  color: #7fb0ff;
  font-family: inherit;
  font-size: inherit;
}

.console-input {
  flex: 1;
  display: block;
  appearance: none;
  background: transparent;
  border: 0;
  color: #f2f7ff;
  caret-color: #7fb0ff;
  font-family: inherit;
  font-size: inherit;
  line-height: inherit;
  outline: none;
  white-space: normal;
}

.console-input::placeholder {
  color: #8b99b0;
  opacity: 1;
}

.console-input:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.console-input:focus {
  outline: none;
}

.console-hint {
  color: #8b99b0;
  font-family: inherit;
  font-size: 0.78rem;
  line-height: 1.4;
  padding-top: 6px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.console-status {
  font-size: 0.72rem;
  font-weight: 600;
  color: #93a4bd;
  white-space: nowrap;
}

.console-status.online {
  color: #7fe0a0;
}

/* ---------- tooltips and device pictures ---------- */

#app .tooltip:not(:has(a)) {
  pointer-events: none;
}

#app .tooltip:is(.start, .end) {
  transform: translateY(-100%) scale(0.9);
}

#app :hover > .tooltip:is(.start, .end) {
  transform: translateY(-100%) scale(1);
}

#app .tooltip.bottom:is(.start, .end) {
  transform: translateY(100%) scale(0.9);
}

#app :hover > .tooltip.bottom:is(.start, .end) {
  transform: translateY(100%) scale(1);
}

#app .tooltip.start {
  left: 0;
  right: auto;
}

#app .tooltip.end {
  left: auto;
  right: 0;
}

#app .tooltip:has(> .device) {
  background: #ffffffdd;
  width: auto;
  padding: 8px;
}

#app img.device {
  display: block;
  width: auto;
  height: auto;
  max-width: 400px;
  max-height: 400px;
  object-fit: contain;
}

#app .tooltip.max {
  inline-size: min(20rem, 76vw);
  white-space: normal;
  text-align: start;
}

/* ---------- responsive ---------- */

@media screen and (max-width: 720px) {
  .flash-container {
    width: min(920px, 100% - 20px);
  }

  .brand-text strong {
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .brand-logo {
    width: 48px;
    height: 48px;
  }

  .top-nav {
    flex-wrap: wrap;
    gap: 4px;
    row-gap: 2px;
  }

  /* бренд занимает первую строку, кнопки — вторую:
     иначе шапка прыгает по высоте, когда появляется «Кастомная» */
  .top-nav > .brand {
    flex: 1 0 100%;
  }

  /* на узком экране кнопки шапки не влезают и занимали целую строку:
     прячем их, «Настройка» и «Консоль» доступны в футере */
  .top-nav > button {
    display: none;
  }

  /* на телефоне подсказки не открываются (нет hover), но их скрытые
     блоки вылезают за экран и растягивают страницу */
  .tooltip,
  .tooltip.max {
    display: none;
  }

  /* длинное имя платы не влезает в крошки — убираем декоративную стрелку,
     чтобы она не переносилась на отдельную строку */
  .screen-header nav > .node-name + i {
    display: none;
  }

  .firmware-card,
  .flash-result {
    padding: 16px;
  }

  .version-row {
    flex-direction: column;
    align-items: stretch;
  }

  .version-field {
    width: 100%;
    min-width: 0;
  }

  .notes {
    flex: none;
    min-width: 0;
    width: 100%;
  }

  .actions button {
    flex: 1 1 160px;
  }
}

@media screen and (max-width: 420px) {
  .brand-text small {
    display: none;
  }

  /* 320 px: с 14.4 px «MeshCore Санкт-Петербург» не влезает и обрезается */
  .brand-text strong {
    font-size: 0.8rem;
  }

  .device-name {
    font-size: 0.88rem;
  }

  .role-select {
    padding: 12px !important;
  }
}

/* ---------- скругления ----------
   BeerCSS по умолчанию делает кнопки, чипы и поля пилюлями, а карточки
   мы рисовали на 12–18 px. На вики углы почти прямые, поэтому всё
   сводим к одному маленькому радиусу. */

button,
.button,
:is(button, .button).small,
:is(button, .button).large,
:is(.button, button):is(.extra, .extend),
:is(.button, button).vertical,
:is(button, .button, .chip).circle,
.chip,
.chip.medium,
.chip.large,
.chip.round.small {
  border-radius: var(--spb-radius);
}

.field,
.field.border,
.field.round,
.field.round.small,
.field.round.large,
.field.round.extra {
  border-radius: var(--spb-radius);
}

.tooltip,
.tooltip.max {
  border-radius: var(--spb-radius);
}

nav:is(.left, .right, .top, .bottom):not(.drawer) > a:not(.button, .chip) > i {
  border-radius: var(--spb-radius);
}

/* Диапазон прошивки в заголовке: 868 (по умолчанию) или 433 */
.band-tag {
  display: inline-block;
  margin-inline-start: 8px;
  padding: 2px 8px;
  border-radius: var(--spb-radius);
  background: var(--spb-blue-light, #e3edff);
  color: var(--spb-blue, #0042aa);
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.4;
  vertical-align: middle;
  white-space: nowrap;
}
