:root {
  --rt-vw: 100vw;
  --rt-vh: 100dvh;
  --rt-safe-bottom: env(safe-area-inset-bottom);
  --rt-safe-top: env(safe-area-inset-top);
  --rt-page-max: 760px;
  --rt-page-x: clamp(12px, 3.8vw, 18px);
  --rt-nav-width: min(calc(100vw - 18px), 720px);
  --rt-nav-height: 72px;
  --rt-nav-bottom: max(8px, env(safe-area-inset-bottom));
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: hidden;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100dvh;
  min-height: var(--rt-vh);
  position: relative;
}

.app-shell {
  width: min(100%, var(--rt-page-max));
  max-width: var(--rt-page-max);
  min-width: 0;
  min-height: 100dvh;
  min-height: var(--rt-vh);
  margin-inline: auto;
  padding-left: var(--rt-page-x);
  padding-right: var(--rt-page-x);
  padding-bottom: calc(var(--rt-nav-height) + var(--rt-nav-bottom) + 26px);
  overflow-x: hidden;
}

#view-root {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: hidden;
}

.screen,
.card,
.metric-card,
.list,
.list-item,
.form-grid,
.grid-2,
.action-row,
.template-grid,
.device-grid {
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.screen {
  overflow-x: hidden;
}

.grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-field,
.form-field input,
.form-field select,
.form-field textarea {
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

input,
select,
textarea,
button {
  max-width: 100%;
}

.bottom-nav {
  position: fixed !important;
  left: 50% !important;
  right: auto !important;
  bottom: var(--rt-nav-bottom) !important;
  transform: translateX(-50%) !important;
  width: var(--rt-nav-width) !important;
  max-width: calc(100vw - 18px) !important;
  min-width: 0 !important;
  height: auto;
  min-height: var(--rt-nav-height);
  display: grid !important;
  grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
  align-items: stretch;
  gap: 2px;
  padding: 7px;
  margin: 0 !important;
  border-radius: 26px;
  overflow: hidden;
  z-index: 90;
  box-sizing: border-box;
}

.bottom-nav button {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  min-height: 56px;
  padding: 7px 2px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  overflow: hidden;
  white-space: nowrap;
  border-radius: 18px;
}

.bottom-nav button span {
  display: block;
  flex: 0 0 auto;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  text-align: center;
  font-size: clamp(1rem, 4.3vw, 1.22rem);
  line-height: 1;
}

.bottom-nav button small {
  display: block;
  width: 100%;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
  white-space: nowrap;
  font-size: clamp(0.61rem, 2.45vw, 0.76rem);
  line-height: 1.05;
}

.pwa-update-banner {
  left: 50% !important;
  right: auto !important;
  bottom: calc(var(--rt-nav-height) + var(--rt-nav-bottom) + 10px) !important;
  transform: translateX(-50%) !important;
  width: var(--rt-nav-width) !important;
  max-width: calc(100vw - 18px) !important;
}

.pwa-install-button {
  right: max(12px, calc((100vw - min(100vw, var(--rt-page-max))) / 2 + 12px));
  bottom: calc(var(--rt-nav-height) + var(--rt-nav-bottom) + 12px) !important;
}

@media (max-width: 620px) {
  :root {
    --rt-page-x: 13px;
    --rt-nav-width: calc(100vw - 16px);
    --rt-nav-height: 70px;
  }

  .app-shell {
    padding-left: var(--rt-page-x) !important;
    padding-right: var(--rt-page-x) !important;
  }

  .grid-2 {
    grid-template-columns: 1fr !important;
  }

  .action-row {
    display: grid;
    grid-template-columns: 1fr;
  }

  .action-row button,
  .action-row .primary-btn,
  .action-row .secondary-btn,
  .action-row .danger-btn {
    width: 100%;
  }

  .bottom-nav {
    padding: 6px;
    border-radius: 24px;
  }

  .bottom-nav button {
    min-height: 55px;
    border-radius: 17px;
  }
}

@media (max-width: 390px) {
  :root {
    --rt-nav-width: calc(100vw - 12px);
    --rt-page-x: 11px;
  }

  .bottom-nav {
    padding: 5px;
    gap: 1px;
  }

  .bottom-nav button {
    min-height: 52px;
    padding: 6px 1px;
  }

  .bottom-nav button span {
    font-size: 1.02rem;
  }

  .bottom-nav button small {
    font-size: 0.58rem;
    letter-spacing: -0.02em;
  }
}

@media (max-width: 340px) {
  .bottom-nav button small {
    display: none;
  }

  .bottom-nav button {
    min-height: 48px;
  }

  :root {
    --rt-nav-height: 62px;
  }
}

@media (orientation: landscape) and (max-height: 520px) {
  :root {
    --rt-nav-height: 58px;
    --rt-nav-bottom: 6px;
  }

  .app-shell {
    padding-bottom: calc(var(--rt-nav-height) + 18px);
  }

  .bottom-nav {
    min-height: var(--rt-nav-height);
    padding: 5px;
    border-radius: 22px;
  }

  .bottom-nav button {
    min-height: 46px;
    flex-direction: row;
    gap: 5px;
  }

  .bottom-nav button span {
    width: auto;
    font-size: 1rem;
  }

  .bottom-nav button small {
    width: auto;
    font-size: 0.68rem;
  }
}

@supports (height: 100svh) {
  body,
  .app-shell {
    min-height: 100svh;
  }
}

@supports (height: 100dvh) {
  body,
  .app-shell {
    min-height: 100dvh;
  }
}

html[data-orientation="landscape"] .screen-header h2 {
  max-width: 100%;
}

html[data-device-class="compact"] .metric-value {
  font-size: clamp(1.65rem, 9vw, 2.2rem);
}

html[data-device-class="compact"] .card {
  border-radius: 22px;
}

html[data-device-class="compact"] .screen-header h2 {
  letter-spacing: -0.065em;
}