/* Estrutura do app: trilho de navegação, área principal, páginas e aviso de conexão. */

.app {
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}

.app.is-booting,
.app.no-shell {
  display: block;
}

.app.no-shell > .main {
  height: 100vh;
  height: 100dvh;
}

/* trilho lateral */
.rail {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 14px 8px 12px;
  background: var(--bg-raised);
  border-right: 1px solid var(--line);
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  scrollbar-width: none;
}

.rail-brand {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  margin: 0 auto 12px;
  border-radius: 14px;
  background: var(--surface-2);
  border: 1px solid var(--line-2);
  overflow: hidden;
  font-family: var(--font-display);
  font-stretch: 75%;
  font-weight: 800;
  font-size: 17px;
  letter-spacing: -0.02em;
  color: var(--text);
}

.rail-brand img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.nav-label {
  margin: 12px 0 3px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  text-align: center;
  color: var(--text-3);
}

.nav-item {
  position: relative;
  display: grid;
  justify-items: center;
  gap: 5px;
  padding: 10px 2px 9px;
  border-radius: 12px;
  color: var(--text-3);
  font-size: 10.5px;
  font-weight: 600;
  line-height: 1.1;
  text-align: center;
  transition: color 0.15s, background 0.15s;
}

.nav-item .i {
  width: 21px;
  height: 21px;
  stroke-width: 1.8;
}

.nav-item:hover {
  color: var(--text);
  background: var(--surface);
}

.nav-item[aria-current='page'] {
  color: var(--text);
  background: var(--surface-2);
}

.nav-item[aria-current='page']::before {
  content: '';
  position: absolute;
  left: -8px;
  top: 12px;
  bottom: 12px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--text);
}

.nav-item .badge {
  position: absolute;
  top: 5px;
  right: 14px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  border: 2px solid var(--bg-raised);
  background: var(--text);
  color: var(--bg);
  font-size: 10px;
  font-weight: 800;
}

.rail-spacer {
  flex: 1;
  min-height: 12px;
}

.avatar {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--surface-3);
  border: 1px solid var(--line-3);
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
}

.conn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.conn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-3);
  flex: none;
}

.conn-dot.is-online {
  background: var(--ok);
  box-shadow: 0 0 0 3px var(--ok-soft);
}

.conn-dot.is-connecting {
  background: var(--warn);
}

.conn-dot.is-offline {
  background: var(--late);
  box-shadow: 0 0 0 3px var(--late-soft);
}

.conn-dot.is-info {
  background: var(--info);
  box-shadow: 0 0 0 3px var(--info-soft);
}

/* área principal (é ela que rola, não o body) */
.main {
  position: relative;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  overflow-x: hidden;
}

.page {
  max-width: 1480px;
  margin: 0 auto;
  padding: 28px clamp(16px, 3vw, 36px) 56px;
  animation: fade-in 0.2s ease;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 20px;
}

.page-title {
  font-family: var(--font-display);
  font-stretch: 78%;
  font-weight: 800;
  font-size: clamp(28px, 3vw, 36px);
  letter-spacing: -0.02em;
  line-height: 1;
}

.page-sub {
  margin-top: 7px;
  color: var(--text-3);
}

.page-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

/* aviso persistente de conexão: cartão no canto, nunca faixa cobrindo o topo */
.conn-card {
  position: fixed;
  left: calc(var(--rail-w) + 16px);
  bottom: 16px;
  z-index: 70;
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: min(420px, calc(100vw - var(--rail-w) - 32px));
  padding: 12px 14px;
  border-radius: 12px;
  background: #1b2128;
  border: 1px solid rgba(255, 79, 79, 0.45);
  box-shadow: var(--shadow-2);
  font-size: 13px;
  animation: toast-in 0.2s var(--ease);
}

.conn-card strong {
  display: block;
}

.conn-card span {
  color: var(--text-2);
}

/* modo TV / cozinha: sem trilho, tudo para os pedidos */
body.tv .app {
  grid-template-columns: minmax(0, 1fr);
}

body.tv .rail {
  display: none;
}

body.tv .conn-card {
  left: 16px;
}

/* celular: trilho vira barra inferior */
@media (max-width: 760px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) auto;
  }

  .main {
    grid-row: 1;
    height: 100%;
  }

  .rail {
    grid-row: 2;
    flex-direction: row;
    height: auto;
    padding: 5px 6px calc(5px + env(safe-area-inset-bottom));
    border-right: 0;
    border-top: 1px solid var(--line);
    overflow-x: auto;
    overflow-y: hidden;
    gap: 2px;
  }

  .rail-brand,
  .nav-label,
  .rail-spacer,
  .rail-extra {
    display: none;
  }

  .nav-item {
    flex: 1 0 66px;
    padding: 8px 2px 7px;
  }

  .nav-item[aria-current='page']::before {
    left: 18px;
    right: 18px;
    top: -5px;
    bottom: auto;
    width: auto;
    height: 3px;
    border-radius: 0 0 3px 3px;
  }

  .conn-card {
    left: 12px;
    bottom: 76px;
  }

  .page {
    padding: 18px 14px 36px;
  }
}
