.topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1.25rem;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 100;
  overflow: visible;
  width: 100%;
  box-sizing: border-box;
}

.topbar__left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
  min-width: 0;
}

.topbar__grow {
  flex: 1 1 auto;
  min-width: 0;
}

.topbar__end {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
  margin-left: auto;
}

.topbar__start {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-shrink: 0;
}

.topbar__brand { font-weight: 700; font-size: 1.1rem; white-space: nowrap; }
.topbar__nav {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-shrink: 0;
  min-width: 0;
  overflow: visible;
}

.topbar__search {
  flex: 0 1 24rem;
  width: 24rem;
  max-width: 24rem;
  min-width: 10rem;
  position: relative;
}

.global-search {
  position: relative;
  width: 100%;
}

.global-search__field {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--color-border);
  background: var(--color-surface-2);
  cursor: text;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.global-search__field:focus-within {
  border-color: color-mix(in srgb, var(--color-primary) 55%, var(--color-border));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-primary) 18%, transparent);
}

.global-search__icon {
  width: 1rem;
  height: 1rem;
  color: var(--color-muted);
  flex-shrink: 0;
}

.global-search__input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  color: var(--color-text);
  font-size: 0.88rem;
  outline: none;
}

.global-search__input::-webkit-search-cancel-button {
  display: none;
}

.global-search__kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.75rem;
  height: 1.35rem;
  padding: 0 0.35rem;
  border-radius: 6px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  color: var(--color-muted);
  font-size: 0.68rem;
  font-family: inherit;
  flex-shrink: 0;
}

.global-search__panel {
  position: absolute;
  top: calc(100% + 0.45rem);
  left: 0;
  right: 0;
  z-index: 200;
  max-height: min(24rem, 70vh);
  overflow: auto;
  border-radius: 12px;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.18);
  padding: 0.45rem;
}

.global-search__hint {
  margin: 0.35rem 0.55rem;
  font-size: 0.82rem;
  color: var(--color-muted);
}

.global-search__hint--error {
  color: #ef4444;
}

.global-search__group + .global-search__group {
  margin-top: 0.35rem;
  padding-top: 0.35rem;
  border-top: 1px solid var(--color-border);
}

.global-search__group-title {
  margin: 0.15rem 0.55rem 0.35rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-muted);
}

.global-search__list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.global-search__option {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  text-decoration: none;
  color: inherit;
}

.global-search__option:hover,
.global-search__option.is-active {
  background: var(--color-surface-2);
  text-decoration: none;
}

.global-search__option-title {
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.25;
}

.global-search__option-sub {
  font-size: 0.78rem;
  color: var(--color-muted);
  line-height: 1.25;
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.topbar__profile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.12rem;
}

.topbar__mqtt-status {
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
  font-size: 0.62rem;
  font-weight: 600;
  color: var(--color-muted);
  line-height: 1;
  white-space: nowrap;
  user-select: none;
}

.topbar__mqtt-dot {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  flex-shrink: 0;
}

.topbar__mqtt-status.is-online .topbar__mqtt-dot {
  background: #22c55e;
  box-shadow: 0 0 0 2px color-mix(in srgb, #22c55e 28%, transparent);
}

.topbar__mqtt-status.is-online {
  color: #16a34a;
}

.topbar__mqtt-status.is-loading .topbar__mqtt-dot {
  background: #f59e0b;
  animation: topbar-mqtt-pulse 1.2s ease-in-out infinite;
}

.topbar__mqtt-status.is-loading {
  color: #d97706;
}

.topbar__mqtt-status.is-error .topbar__mqtt-dot {
  background: #ef4444;
}

.topbar__mqtt-status.is-error {
  color: #ef4444;
}

@keyframes topbar-mqtt-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.82); }
}
.topbar__user, .topbar__tenant {
  font-size: 0.85rem;
  color: var(--color-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 14rem;
}

.topbar__tenant-select {
  width: auto;
  min-width: 0;
  max-width: 14rem;
}

.theme-switch {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  padding: 0.15rem;
  border-radius: 999px;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  flex-shrink: 0;
}

.theme-switch__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.85rem;
  height: 1.85rem;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--color-muted);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.theme-switch__btn:hover {
  color: var(--color-text);
  background: color-mix(in srgb, var(--color-border) 45%, transparent);
}

.theme-switch__btn.is-active {
  color: var(--color-text);
  background: var(--color-surface);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.theme-switch__icon {
  width: 1rem;
  height: 1rem;
}

.lang-switch {
  display: inline-flex;
  align-items: center;
  gap: 0.1rem;
  padding: 0.15rem;
  border-radius: 999px;
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  flex-shrink: 0;
}

.lang-switch__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2rem;
  height: 1.85rem;
  padding: 0 0.45rem;
  border: none;
  border-radius: 999px;
  background: transparent;
  color: var(--color-muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.lang-switch__btn:hover {
  color: var(--color-text);
  background: color-mix(in srgb, var(--color-border) 45%, transparent);
}

.lang-switch__btn.is-active {
  color: var(--color-text);
  background: var(--color-surface);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.topbar__avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: var(--color-primary);
  color: var(--color-on-primary);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-decoration: none;
  flex-shrink: 0;
  transition: background 0.15s ease, box-shadow 0.15s ease;
}

.topbar__avatar:hover {
  background: var(--color-primary-hover);
  text-decoration: none;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--color-primary) 35%, transparent);
}

.topbar__avatar.is-active {
  box-shadow: 0 0 0 2px var(--color-text);
}

.nav-link {
  color: var(--color-muted);
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  white-space: nowrap;
}
.nav-link:hover, .nav-link.is-active {
  color: var(--color-text);
  background: var(--color-surface-2);
  text-decoration: none;
}

.nav-group {
  position: relative;
  flex-shrink: 0;
}

.nav-group__trigger {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.35rem 0.5rem;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--color-muted);
  font: inherit;
  font-size: inherit;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s ease, background 0.15s ease;
}

.nav-group__trigger:hover,
.nav-group__trigger.is-active,
.nav-group.is-open .nav-group__trigger {
  color: var(--color-text);
  background: var(--color-surface-2);
}

.nav-group__chevron {
  width: 0.95rem;
  height: 0.95rem;
  transition: transform 0.15s ease;
}

.nav-group.is-open .nav-group__chevron {
  transform: rotate(180deg);
}

.nav-group__menu {
  position: fixed;
  z-index: 200;
  min-width: 10.5rem;
  padding: 0.35rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  box-shadow: var(--shadow);
}

.nav-group__link {
  display: block;
  padding: 0.45rem 0.65rem;
  border-radius: calc(var(--radius) - 2px);
  color: var(--color-muted);
  font-size: 0.9rem;
  text-decoration: none;
  white-space: nowrap;
}

.nav-group__link:hover,
.nav-group__link.is-active {
  color: var(--color-text);
  background: var(--color-surface-2);
  text-decoration: none;
}

.page {
  max-width: var(--max-width);
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

@media (min-width: 900px) {
  .page {
    min-width: 900px;
  }
}

.page--full {
  max-width: none;
  width: 100%;
  padding-left: 1.25rem;
  padding-right: 1.25rem;
}

.page__title { font-size: 1.5rem; margin-bottom: 1rem; }
.page__subtitle { color: var(--color-muted); margin-bottom: 1.5rem; }

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

body.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

body.app-shell #layout-root {
  flex-shrink: 0;
}

body.app-shell > .page {
  flex: 1;
}

body.app-shell--chat-layout {
  height: 100dvh;
  min-height: 100dvh;
  overflow: hidden;
}

body.app-shell--chat-layout > .page {
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

body.app-shell--chat-layout > .page.page--chat-shell {
  min-width: 0;
}

body.app-shell--chat-layout > .app-footer {
  flex-shrink: 0;
}

.app-footer {
  margin-top: auto;
  border-top: 1px solid var(--color-border);
  background: color-mix(in srgb, var(--color-surface) 88%, var(--color-bg));
  padding: 0.55rem 1.25rem;
}

.app-footer__inner {
  max-width: var(--max-width);
  margin: 0 auto;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 0.75rem 1.25rem;
  min-height: 2rem;
}

.app-footer__logo {
  font-weight: 700;
  font-size: 0.82rem;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.app-footer__nav {
  display: flex;
  align-items: center;
  justify-content: center;
}

.app-footer__link {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.45rem;
  border-radius: 999px;
  color: var(--color-primary);
  font-size: 0.8rem;
  font-weight: 500;
  text-decoration: none;
  transition: color 0.15s ease, background 0.15s ease;
}

.app-footer__link:hover,
.app-footer__link.is-active {
  color: var(--color-primary-hover);
  background: color-mix(in srgb, var(--color-primary) 12%, transparent);
  text-decoration: none;
}

.app-footer__icon {
  width: 0.9rem;
  height: 0.9rem;
  flex-shrink: 0;
}

.app-footer__copy {
  margin: 0;
  font-size: 0.75rem;
  text-align: right;
  white-space: nowrap;
}

.app-footer .support-badge {
  margin-left: 0.05rem;
}

.app-footer--auth {
  position: relative;
  margin-top: 0;
  background: transparent;
  border-top: 1px solid color-mix(in srgb, var(--color-border) 65%, transparent);
  padding: 0.55rem 1.5rem 0.75rem;
}

.app-footer--auth .app-footer__inner {
  max-width: none;
}

.app-footer__inner--auth {
  grid-template-columns: auto auto;
  justify-content: space-between;
}

@media (max-width: 560px) {
  .app-footer__inner--auth {
    grid-template-columns: 1fr auto;
    grid-template-areas: none;
  }

  .app-footer__inner {
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "logo copy"
      "nav nav";
    gap: 0.35rem 0.75rem;
  }

  .app-footer__logo { grid-area: logo; }
  .app-footer__nav { grid-area: nav; justify-content: center; }
  .app-footer__copy { grid-area: copy; }
}

.stat {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 1rem;
}
.stat__value { font-size: 1.75rem; font-weight: 700; }
.stat__label { color: var(--color-muted); font-size: 0.85rem; }

.storage-card__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.85rem;
}

.storage-card__head .section__title {
  margin-bottom: 0.25rem;
}

.storage-card__head .page__subtitle {
  margin: 0;
}

.storage-meter {
  height: 10px;
  border-radius: 999px;
  background: rgba(100, 116, 139, 0.2);
  overflow: hidden;
  margin-bottom: 0.65rem;
}

.storage-meter__bar {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #3b82f6, #6366f1);
  transition: width 0.25s ease;
}

.storage-meter__bar--warn {
  background: linear-gradient(90deg, #eab308, #f59e0b);
}

.storage-meter__bar--full {
  background: linear-gradient(90deg, #ef4444, #dc2626);
}

.storage-card__hint {
  margin: 0;
  font-size: 0.85rem;
}

.storage-card--full {
  border-color: rgba(239, 68, 68, 0.45);
}

.storage-breakdown {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(100, 116, 139, 0.2);
}

.storage-breakdown__title {
  margin: 0 0 0.75rem;
  font-size: 0.9rem;
  font-weight: 600;
}

.storage-breakdown__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.storage-breakdown__item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.35rem 0.75rem;
  align-items: center;
}

.storage-breakdown__label {
  font-size: 0.85rem;
  min-width: 0;
}

.storage-breakdown__meta {
  font-size: 0.8rem;
  color: var(--color-muted);
  text-align: right;
  white-space: nowrap;
}

.storage-breakdown__meter {
  grid-column: 1 / -1;
  height: 6px;
  border-radius: 999px;
  background: rgba(100, 116, 139, 0.18);
  overflow: hidden;
}

.storage-breakdown__meter-bar {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #60a5fa, #818cf8);
}

.storage-breakdown__details {
  margin-top: 0.85rem;
}

.storage-breakdown__details summary {
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-muted);
  user-select: none;
}

.storage-breakdown__details[open] summary {
  margin-bottom: 0.65rem;
  color: inherit;
}

.storage-breakdown__item--link .storage-breakdown__label a {
  color: inherit;
  text-decoration: none;
}

.storage-breakdown__item--link .storage-breakdown__label a:hover {
  text-decoration: underline;
}

.section { margin-top: 1.5rem; }
.section__title { font-size: 1rem; margin-bottom: 0.75rem; }

@media (max-width: 900px) {
  .topbar {
    flex-wrap: wrap;
    gap: 0.65rem;
  }

  .topbar__left {
    flex: 1 1 100%;
    flex-wrap: wrap;
    gap: 0.65rem;
  }

  .topbar__start {
    max-width: 100%;
  }

  .topbar__nav {
    flex: 1 1 100%;
    flex-wrap: wrap;
  }

  .topbar__grow {
    display: none;
  }

  .topbar__end {
    flex: 1 1 100%;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.65rem;
  }

  .topbar__search {
    flex: 1 1 100%;
    width: 100%;
    max-width: none;
    order: 1;
  }

  .topbar__actions {
    order: 2;
    margin-left: auto;
  }

  .topbar__mqtt-label {
    display: none;
  }

  .global-search__kbd {
    display: none;
  }
}

.nav-link .support-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.1rem;
  height: 1.1rem;
  padding: 0 0.3rem;
  margin-left: 0.2rem;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 0.62rem;
  font-weight: 700;
  vertical-align: middle;
}

.support-badge--pulse {
  animation: support-badge-pulse 1.4s ease-in-out infinite;
}

@keyframes support-badge-pulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.45); }
  50% { transform: scale(1.06); box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
}

.app-ops-banners {
  display: grid;
  gap: 0;
}

.app-ops-banners[hidden] {
  display: none;
}

.app-ops-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 0.75rem;
  padding: 0.65rem 1.25rem;
  font-size: 0.9rem;
  line-height: 1.4;
  border-bottom: 1px solid var(--color-border);
}

.app-ops-banner strong {
  font-weight: 700;
}

.app-ops-banner--maintenance {
  background: color-mix(in srgb, #f59e0b 18%, var(--color-surface));
  color: var(--color-text);
}

.app-ops-banner--maintenance.app-ops-banner--readonly {
  background: color-mix(in srgb, #ef4444 16%, var(--color-surface));
}

.app-ops-banner--announcement {
  background: color-mix(in srgb, #0ea5e9 14%, var(--color-surface));
}

