/* Box model guard: evita que padding/border aumentem largura e gera overflow */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100vh;
  overflow-x: hidden;
  margin: 0;
  padding: 0;
}

body.nav-open {
  overflow: hidden;
}

.container {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding-inline: clamp(12px, 3vw, 24px);
}

.app-shell {
  --rail-width: 96px;
  display: grid;
  width: 100%;
  grid-template-columns: var(--rail-width) minmax(0, 1fr);
  transition: grid-template-columns 200ms ease;
  max-width: 100%;
  overflow-x: hidden;
}

.nav-rail {
  background: linear-gradient(180deg, #0f1523, #111827);
  color: #e5ecf6;
  padding: var(--space-4) var(--space-3);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-4);
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  /* fixo em desktop para cobrir toda a altura visível e evitar cortes */
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 12;
  width: var(--rail-width, 96px);
  max-width: var(--rail-width, 96px);
  box-sizing: border-box;
  transition: width 200ms ease;
  overflow-y: auto; /* garante visibilidade integral ao rolar */
}

.rail-logo {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  border-radius: var(--radius-md);
  padding: var(--space-2);
  background: linear-gradient(135deg, rgba(127, 192, 176, 0.15), rgba(141, 182, 255, 0.12));
  border: 1px solid rgba(255, 255, 255, 0.06);
}

.logo-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, #7fc0b0, #8db6ff);
  color: #0f1724;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.rail-menu {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  align-items: stretch;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0;
  text-decoration: none;
  color: inherit;
  padding: 10px 8px;
  border-radius: 16px;
  position: relative;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast), background var(--transition-fast), color var(--transition-fast), padding var(--transition-fast);
  min-height: 78px;
  border: 1px solid transparent;
  width: 100%;
  overflow: hidden;
}

.nav-item::before {
  content: "";
  position: absolute;
  left: 6px;
  top: 12px;
  bottom: 12px;
  width: 8px;
  border-radius: 999px;
  background: linear-gradient(180deg, rgba(127, 192, 176, 0.6), rgba(141, 182, 255, 0.5));
  transition: transform 220ms ease, opacity 220ms ease;
  opacity: 0;
  transform: scaleY(0);
  transform-origin: center;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.06);
  transform: translateY(-2px);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.25);
  border-color: rgba(255, 255, 255, 0.04);
}

.nav-item:hover::before {
  opacity: 1;
  transform: scaleY(1);
}

.nav-item:focus-visible {
  outline: 2px solid rgba(127, 192, 176, 0.7);
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(127, 192, 176, 0.18);
}

.nav-item.is-active {
  background: rgba(127, 192, 176, 0.18);
  color: #fff;
  box-shadow: 0 12px 26px rgba(0, 0, 0, 0.28);
}

.nav-item.is-active::before {
  background: linear-gradient(180deg, #7fc0b0, #8db6ff);
  opacity: 1;
  transform: scaleY(1);
}

.nav-item:hover.is-active {
  transform: translateY(-2px);
}

.nav-item__icon {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
}

.nav-item__icon svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.nav-item__label {
  font-size: 12px;
  color: rgba(229, 236, 246, 0.9);
  text-align: center;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  display: none;
}

.app-shell.rail-expanded {
  --rail-width: 180px;
}

.app-shell.rail-expanded .nav-item__label {
  display: block;
}

.app-shell.rail-expanded .nav-item {
  justify-content: flex-start;
  gap: 6px;
  padding-top: 14px;
}

.rail-label {
  display: inline-flex;
  font-size: 12px;
  color: rgba(229, 236, 246, 0.9);
}

.rail-footer {
  margin-top: auto;
  padding: var(--space-2);
  background: rgba(255, 255, 255, 0.04);
  border-radius: var(--radius-md);
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 12px;
  color: rgba(229, 236, 246, 0.85);
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--color-neutral);
  box-shadow: 0 0 0 6px rgba(127, 192, 176, 0.12);
}

.status-ok {
  background: var(--color-positive);
}

.page {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  min-height: 100vh;
  overflow-x: hidden;
  grid-column: 2 / -1;
  width: 100%;
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  padding: var(--space-4) var(--space-5);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  background: rgba(246, 247, 251, 0.8);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--color-border);
  z-index: 10;
  width: 100%;
  max-width: var(--max-content-width);
  margin: 0 auto;
  min-width: 0;
}

.topbar.stuck {
  box-shadow: var(--shadow-card);
}

.page-heading {
  display: grid;
  gap: 4px;
}

.page-content {
  width: 100%;
  max-width: var(--max-content-width);
  margin: 0 auto;
  padding: clamp(16px, 3vw, 28px);
  display: grid;
  gap: var(--space-6);
  padding-bottom: clamp(32px, 6vw, 64px);
  align-content: start;
  min-width: 0;
}

.panel-grid {
  display: grid;
  gap: var(--space-4);
  align-items: start;
}

.panel-grid.two-columns {
  grid-template-columns: minmax(360px, 1.1fr) minmax(320px, 1fr);
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.section-head .eyebrow {
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-muted);
}

/* ===========================
   Responsive layout
   Breakpoints: 1024 / 900 / 768 / 520
   =========================== */

/* Tablet general (<=1024px) */
@media (max-width: 1024px) {
   .app-shell {
    --rail-width: 72px;
    grid-template-columns: var(--rail-width) minmax(0, 1fr);
  }
}

/* Small desktop / tablet (<=900px) */
@media (max-width: 900px) {
  .topbar {
    padding: var(--space-4);
  }

  .page-content {
    padding: var(--space-4);
    gap: var(--space-5);
  }

  .panel-grid.two-columns {
    grid-template-columns: 1fr;
  }
}

/* Mobile + small tablet (<=768px) */
@media (max-width: 768px) {
  /* App vira uma coluna; sidebar sai do grid e vira drawer */
   .app-shell {
    --rail-width: 0px;
    grid-template-columns: 1fr;
  }

  .page {
    grid-column: 1 / -1;
    width: 100%;
    min-width: 0;
    max-width: none;
    margin: 0;
  }

  /* Drawer lateral */
  .nav-rail {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;

    width: min(320px, 86vw);
    max-width: 86vw;
    height: 100dvh;

    flex-direction: column;
    justify-content: flex-start;

    padding: var(--space-4) var(--space-3);
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    border-top: none;

    backdrop-filter: blur(10px);

    transform: translateX(-100%);
    transition: transform 200ms ease, box-shadow 200ms ease;
    overflow-y: auto;
    z-index: 32;
  }

  body.nav-open .nav-rail {
    transform: translateX(0);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.3);
  }

  .nav-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    opacity: 0;
    pointer-events: none;
    transition: opacity 200ms ease;
    z-index: 31;
  }

  body.nav-open .nav-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  /* Logo volta para dentro do drawer (sem conflito de display) */
  .rail-logo {
    display: flex;
    position: static;
    width: 100%;
    height: auto;
    padding: var(--space-2);
    margin-bottom: var(--space-2);
  }

  .rail-footer {
    display: flex;
  }

  /* Menu do drawer: vertical */
  .rail-menu {
    flex-direction: column;
    gap: 8px;
    width: 100%;
  }

  .nav-item {
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;

    width: 100%;
    min-height: 52px;
    padding: 10px 12px;
  }

  .nav-item::before {
    display: none;
  }

  .nav-item__label {
    display: block;
    font-size: 13px;
    text-align: left;
  }

  .rail-label {
    font-size: 12px;
  }

  /* Topbar e conteúdo */
  .topbar {
    position: sticky;
    top: 0;
    padding: var(--space-3);
  }

  .topbar.stuck {
    box-shadow: var(--shadow-card);
  }

  .topbar-actions {
    width: 100%;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: var(--space-2);
  }

  .page-content {
    padding: var(--space-4) var(--space-3) 96px;
  }

  .panel-grid.two-columns,
  .panel-grid {
    grid-template-columns: 1fr;
  }
}

/* Mobile compact (<=520px) */
@media (max-width: 520px) {
  .topbar {
    gap: var(--space-3);
  }

  .topbar-actions {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-2);
  }

  .page-content {
    padding: var(--space-3) var(--space-2) 96px;
  }
}
