/* ── App shell ──────────────────────────────────────────────── */
.app {
  display: grid;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-columns: 1fr;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
}
@media (min-width: 769px) {
  .app {
    grid-template-columns: var(--sidebar-w) 1fr;
  }
}

/* ── Topbar (compacta) ─────────────────────────────────────── */
.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  z-index: 50;
  padding: 0 14px;
  gap: 12px;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.hamburger {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  color: var(--text-2);
  border-radius: var(--radius-sm);
  transition: background var(--t-fast);
}
.hamburger:hover { background: var(--surface-2); color: var(--text); }
.hamburger svg { width: 18px; height: 18px; }
@media (min-width: 769px) {
  .hamburger { display: none; }
}

.logo-icon {
  width: 20px;
  height: 20px;
  border: 1px solid var(--green);
  display: grid;
  place-items: center;
  position: relative;
  border-radius: 3px;
  flex-shrink: 0;
}
.logo-icon::before {
  content: '';
  position: absolute;
  inset: -3px;
  border: 1px solid rgba(0, 232, 122, 0.15);
  border-radius: 3px;
}
.logo-icon svg { width: 11px; height: 11px; color: var(--green); }

.logo-name {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.1em;
}
.logo-name span { color: var(--green); }

/* nav horizontal no desktop; no mobile usa-se bottom-nav + drawer */
.topbar-nav {
  display: none;
}
@media (min-width: 769px) {
  .topbar-nav {
    display: flex;
    align-items: center;
    gap: 2px;
    height: 100%;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .topbar-nav::-webkit-scrollbar { display: none; }
}

.nav-tab {
  display: flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 13px;
  font-family: var(--font-sans);
  font-size: 12.5px;
  font-weight: 500;
  letter-spacing: 0;
  color: var(--text-3);
  cursor: pointer;
  border-radius: 999px;
  transition: background var(--t-fast), color var(--t-fast);
}
.nav-tab:hover { color: var(--text); background: var(--surface-2); }
.nav-tab.active { color: var(--text); background: var(--surface-3); }
.nav-tab svg { width: 14px; height: 14px; }
.nav-tab.active svg { color: var(--green); }
.nav-tab .badge {
  font-family: var(--font-mono);
  font-size: 9px;
  padding: 1px 6px;
  background: var(--surface-3);
  color: var(--text-3);
  border-radius: 999px;
  letter-spacing: 0.02em;
}
.nav-tab.active .badge { background: var(--green-dim); color: var(--green); }
.nav-tab.danger .badge { background: var(--red-dim); color: var(--red); }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-4);
  transition: background var(--t-base);
  flex-shrink: 0;
}
.live-dot.connected {
  background: var(--green);
  animation: pulse-live 1.6s infinite;
}
@keyframes pulse-live {
  0%, 100% { box-shadow: 0 0 0 0 var(--green-glow); }
  50% { box-shadow: 0 0 0 5px transparent; }
}

.clock {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-2);
  letter-spacing: 0.04em;
}

.health-chip {
  display: none;
  align-items: center;
  gap: 4px;
  font-family: var(--font-mono);
  font-size: 10px;
  padding: 3px 7px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 3px;
}
@media (min-width: 769px) {
  .health-chip { display: inline-flex; }
}
.health-chip.ok { border-color: rgba(0, 232, 122, 0.25); color: var(--green); }
.health-chip.warn { border-color: rgba(245, 158, 11, 0.3); color: var(--amber); }
.health-chip.critical { border-color: rgba(255, 71, 87, 0.3); color: var(--red); }

/* ── Sidebar / Drawer ──────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(280px, 86vw);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 110;
  transform: translateX(-100%);
  transition: transform var(--t-slow);
}
.sidebar.open { transform: translateX(0); }
@media (min-width: 769px) {
  .sidebar {
    position: static;
    width: var(--sidebar-w);
    transform: none;
    grid-row: 2;
    grid-column: 1;
  }
  /* views sem painel de contexto: esconde a sidebar e expande o conteúdo */
  .app.no-sidebar { grid-template-columns: 1fr; }
  .app.no-sidebar .sidebar { display: none; }
  .app.no-sidebar .main { grid-column: 1; }
}

.sidebar-head {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
@media (max-width: 768px) {
  .sidebar-head { display: flex; }
}
.sidebar-close {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  color: var(--text-3); border-radius: var(--radius-sm);
}
.sidebar-close:hover { background: var(--surface-2); color: var(--text); }
.sidebar-title {
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  color: var(--text-3);
  text-transform: uppercase;
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 105;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-base);
}
.sidebar-backdrop.open {
  opacity: 1;
  pointer-events: all;
}
@media (min-width: 769px) {
  .sidebar-backdrop { display: none; }
}

.sidebar-section {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sidebar-section.flex { flex: 1; overflow: hidden; }
.sidebar-nav-footer { flex-shrink: 0; }
.sidebar-nav-footer .sidebar-list { max-height: 38vh; }

.sidebar-label {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.16em;
  color: var(--text-4);
  text-transform: uppercase;
  padding: 0 8px 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-search {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  transition: border-color var(--t-base);
}
.sidebar-search:focus { border-color: var(--green); outline: none; }
.sidebar-search::placeholder { color: var(--text-4); }

.sidebar-list {
  margin-top: 6px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-height: 0;
}

.route-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  cursor: pointer;
  transition: background var(--t-fast);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-2);
  border-left: 2px solid transparent;
  border-radius: var(--radius-sm);
  min-height: 36px;
}
.route-item:hover { background: var(--surface-2); color: var(--text); }
.route-item.active {
  background: var(--green-dim);
  color: var(--green);
  border-left-color: var(--green);
}
.route-item .label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.route-item .indicator {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-4);
  flex-shrink: 0;
}
.route-item .indicator.ok { background: var(--green); }
.route-item .indicator.warn { background: var(--amber); }
.route-item .indicator.critical { background: var(--red); }
.route-item .count {
  font-size: 9px;
  padding: 1px 5px;
  background: var(--surface-3);
  color: var(--text-3);
  border-radius: 3px;
}

/* ── Main ──────────────────────────────────────────────────── */
.main {
  overflow: hidden;
  display: flex;
  flex-direction: column;
  grid-row: 2;
  grid-column: 1;
  padding-bottom: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom, 0));
}
@media (min-width: 769px) {
  .main {
    padding-bottom: 0;
    grid-column: 2;
  }
}

.view {
  display: none;
  height: 100%;
  flex-direction: column;
  overflow: hidden;
}
.view.active { display: flex; }

/* ── Bottom nav (mobile) ──────────────────────────────────── */
.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 50;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
@media (min-width: 769px) {
  .bottom-nav { display: none; }
}

.bottom-nav button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 6px 2px;
  min-height: 56px;
  font-family: var(--font-mono);
  font-size: 8px;
  letter-spacing: 0.04em;
  color: var(--text-4);
  transition: color var(--t-fast);
  position: relative;
}
.bottom-nav button:hover { color: var(--text-2); }
.bottom-nav button.active { color: var(--green); }
.bottom-nav button.active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 22px;
  height: 2px;
  background: var(--green);
  border-radius: 0 0 2px 2px;
}
.bottom-nav button svg { width: 19px; height: 19px; }
.bottom-nav .badge {
  position: absolute;
  top: 4px;
  right: calc(50% - 16px);
  font-size: 8px;
  padding: 1px 4px;
  min-width: 14px;
  text-align: center;
  background: var(--surface-3);
  color: var(--text-3);
  border-radius: 6px;
  letter-spacing: 0.04em;
}
.bottom-nav button.active .badge { background: var(--green-dim); color: var(--green); }
.bottom-nav button.danger .badge { background: var(--red-dim); color: var(--red); }