/* Estrutura: barra lateral + conteúdo; no celular, a barra vira gaveta. */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}

/* ---------- Barra lateral ---------- */
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: var(--sp-4) var(--sp-3);
  background: var(--bg);
  border-right: 1px solid var(--line);
}

.sidebar__brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 40px;
  padding: 0 var(--sp-2) 0 var(--sp-3);
  margin-bottom: var(--sp-6);
}

.brand {
  display: inline-flex;
  align-items: center;
  font-size: 1.0625rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1;
}

.brand__logo {
  flex: none;
  width: 1.75em;
  height: 1.75em;
  margin-right: 0.5em;
}

.brand__mark {
  /* Fonte da interface: na Cascadia Mono o "4" tem o topo aberto e lê como "Ч". */
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

.brand__name {
  color: var(--text);
}

.nav {
  display: flex;
  flex-direction: column;
  gap: var(--sp-5);
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.nav__label {
  padding: 0 var(--sp-3) var(--sp-2);
  font-size: var(--fs-xs);
  font-weight: 500;
  color: var(--text-3);
}

.nav__list {
  display: grid;
  gap: 2px;
}

.nav__item {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  height: 34px;
  padding: 0 var(--sp-3);
  border-radius: var(--radius);
  color: var(--text-2);
  transition: background-color var(--dur-1), color var(--dur-1);
}

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

.nav__item[aria-current="page"] {
  background: var(--surface);
  color: var(--text);
}

.nav__item[aria-current="page"]::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 2px;
  border-radius: 2px;
  background: var(--accent);
}

.nav__item[aria-current="page"] .icon {
  color: var(--accent);
}

.sidebar__user {
  display: grid;
  gap: var(--sp-2);
  margin-top: var(--sp-4);
  padding: var(--sp-3) var(--sp-2) 0;
  border-top: 1px solid var(--line);
}

.sidebar__who {
  display: grid;
  padding: 0 var(--sp-1);
  min-width: 0;
}

.sidebar__name {
  font-weight: 500;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar__role {
  font-size: var(--fs-xs);
  color: var(--text-3);
}

.sidebar__actions {
  display: flex;
  gap: var(--sp-1);
}

.sidebar__actions .btn {
  flex: 1;
}

.sidebar__actions .btn[aria-current="page"] {
  background: var(--surface);
  color: var(--text);
}

.sidebar__close {
  display: none;
}

/* ---------- Conteúdo ---------- */
.app__main {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: none;
}

.page {
  width: 100%;
  max-width: 1440px;
  padding: var(--sp-7) var(--sp-8) var(--sp-9);
  outline: none;
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--sp-4);
  margin-bottom: var(--sp-6);
}

.page-header__title {
  font-size: var(--fs-2xl);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.015em;
}

.page-header__lead {
  max-width: 72ch;
  margin-top: var(--sp-1);
  color: var(--text-2);
}

.page-header__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}

.stack {
  display: grid;
  gap: var(--sp-5);
}

/* Uma coluna só, para tarefas de foco (ex.: troca obrigatória de senha). */
.narrow {
  display: grid;
  gap: var(--sp-5);
  max-width: 560px;
}

.columns {
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
  gap: var(--sp-5);
  align-items: start;
}

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

/* Item de grade não encolhe abaixo do conteúdo por padrão: sem isto, uma tabela larga empurra a coluna
   por cima da vizinha. Com min-width 0, a tabela rola dentro do próprio bloco. */
.columns > *,
.stack > * {
  min-width: 0;
}

/* Pedido: coluna lateral de largura própria no computador; abaixo disso, uma coluna só, na ordem
   venda, itens, compras, envios, financeiro, problemas, tarefas, destino, anexos e linha do tempo. Aviso de falha ocupa as duas colunas. */
.order-layout__full {
  grid-column: 1 / -1;
}

@media (min-width: 1200px) {
  .columns.order-layout {
    grid-template-columns: minmax(0, 1fr) minmax(300px, 360px);
  }
}

@media (max-width: 1199px) {
  .columns.order-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .order-layout__column {
    display: contents;
  }

  .order-layout__sale {
    order: 1;
  }

  .order-layout__items {
    order: 2;
  }

  .order-layout__purchases {
    order: 3;
  }

  .order-layout__shipments {
    order: 4;
  }

  .order-layout__finance {
    order: 4;
  }

  .order-layout__issues {
    order: 5;
  }

  .order-layout__tasks {
    order: 6;
  }

  .order-layout__destination {
    order: 7;
  }

  .order-layout__attachments {
    order: 8;
  }

  .order-layout__timeline {
    order: 9;
  }
}

/* ---------- Gaveta no celular e tablet ---------- */
@media (max-width: 1023px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    width: min(84vw, 300px);
    background: var(--surface);
    border-right: 1px solid var(--line-strong);
    transform: translateX(-102%);
    transition: transform var(--dur-3) var(--ease);
    visibility: hidden;
  }

  .app.is-nav-open .sidebar {
    transform: none;
    visibility: visible;
  }

  .sidebar__close {
    display: inline-grid;
  }

  .drawer-backdrop {
    position: fixed;
    inset: 0;
    z-index: 35;
    background: rgba(4, 4, 6, 0.6);
  }

  .topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    height: 52px;
    padding: 0 var(--sp-3);
    background: var(--bg);
    border-bottom: 1px solid var(--line);
  }

  .page {
    padding: var(--sp-5) var(--sp-4) var(--sp-8);
  }

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

/* ---------- Telas de entrada e de erro ---------- */
.auth-body,
.status-body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: var(--sp-6) var(--sp-4);
}

.auth {
  width: 100%;
  max-width: 384px;
}

.auth__brand {
  display: flex;
  justify-content: center;
  margin-bottom: var(--sp-6);
}

.auth__logo {
  display: block;
  width: 72px;
  height: 72px;
}

.auth-card {
  padding: var(--sp-7) var(--sp-6) var(--sp-6);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
}

.auth-card__title {
  font-size: var(--fs-xl);
  font-weight: 600;
}

.auth-card__lead {
  margin: var(--sp-1) 0 var(--sp-6);
  color: var(--text-2);
}

.status-page {
  width: 100%;
  max-width: 460px;
}

.status-page__code {
  margin: var(--sp-7) 0 var(--sp-2);
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  color: var(--accent);
}

.status-page__title {
  font-size: var(--fs-2xl);
  font-weight: 600;
  letter-spacing: -0.015em;
}

.status-page__message {
  margin: var(--sp-2) 0 var(--sp-4);
  color: var(--text-2);
}

.status-page__ref {
  margin-bottom: var(--sp-6);
  font-size: var(--fs-sm);
  color: var(--text-3);
}

.status-page__debug {
  margin: 0 0 var(--sp-6);
  padding: var(--sp-3);
  overflow-x: auto;
  white-space: pre-wrap;
  font-size: var(--fs-xs);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
