/* ==========================================================================
   Samsung One UI Layout & Navigation Architecture
   Otimizado para Mobile (360px - 430px) com Ergonomia One-Handed
   ========================================================================== */

/* Reset & Base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  scroll-behavior: smooth;
  background-color: var(--bg-app);
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  user-select: none;
}

/* ==========================================================================
   Topbar (Compacto e Responsivo no Mobile)
   ========================================================================== */

.topbar {
  height: var(--topbar-height);
  background-color: rgba(14, 15, 20, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  position: sticky;
  top: 0;
  z-index: 100;
  width: 100%;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.brand-icon-box {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: rgba(45, 116, 255, 0.15);
  border: 1px solid rgba(45, 116, 255, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
}

.brand-title-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.brand-status {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-pill);
  background-color: var(--color-success);
  box-shadow: 0 0 8px rgba(28, 209, 102, 0.6);
  flex-shrink: 0;
  animation: pulse-status 2.5s infinite ease-in-out;
}

.brand-status.offline {
  background-color: var(--color-danger);
  box-shadow: 0 0 8px rgba(255, 71, 87, 0.6);
  animation: none;
}

@keyframes pulse-status {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.6; transform: scale(1.15); }
}

.brand-text h1 {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.2px;
  color: var(--text-main);
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-sub {
  font-size: 10.5px;
  color: var(--text-muted);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* Polling selector compacto no mobile */
.select-poll-top {
  background-color: var(--bg-surface-elevated);
  color: var(--text-muted);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  padding: 4px 8px;
  font-family: var(--font-sans);
  font-size: 11px;
  font-weight: 600;
  outline: none;
  cursor: pointer;
  height: 32px;
}

/* Error Banner One UI */
.error-banner {
  background-color: rgba(255, 71, 87, 0.18);
  border-bottom: 1px solid rgba(255, 71, 87, 0.35);
  color: #ffccd0;
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: space-between;
  backdrop-filter: blur(12px);
  animation: slide-down 0.25s ease-out;
}

@keyframes slide-down {
  from { transform: translateY(-100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ==========================================================================
   App Layout
   ========================================================================== */

.app-layout {
  display: flex;
  flex: 1;
  min-height: calc(100vh - var(--topbar-height));
  background-color: var(--bg-app);
  width: 100%;
}

/* Desktop Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background-color: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
  display: none;
  flex-direction: column;
  justify-content: space-between;
  padding: 16px 12px;
  flex-shrink: 0;
}

.nav-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: transparent;
  border: none;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: var(--transition-fast);
}

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

.nav-item:active {
  transform: scale(0.97);
}

.nav-item.active {
  background-color: var(--color-primary-subtle);
  color: var(--color-primary);
  font-weight: 700;
}

.sidebar-footer {
  padding-top: 14px;
  border-top: 1px solid var(--border-subtle);
  font-size: 11px;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sidebar-footer strong {
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* ==========================================================================
   Content Area & Mobile Viewport Constraints
   ========================================================================== */

.content-area {
  flex: 1;
  padding: 12px 12px;
  max-width: 960px;
  margin: 0 auto;
  width: 100%;
  box-sizing: border-box;
  /* Espaço reservado exato para a bottom nav sem sobreposição */
  padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 8px) + 20px);
}

.tab-pane {
  display: none;
  animation: fadeInPane 0.2s cubic-bezier(0.2, 0.8, 0.4, 1);
}

.tab-pane.active {
  display: block;
}

@keyframes fadeInPane {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  padding: 0 2px;
}

.section-header h2 {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.3px;
  color: var(--text-main);
}

/* Grid System */
.grid-cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

/* ==========================================================================
   Samsung One UI Mobile Bottom Navigation (Docked Full Width)
   Fixa no fundo com suporte nativo a safe-area
   ========================================================================== */

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  height: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background-color: rgba(14, 15, 19, 0.95);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 1000;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.6);
}

.b-nav-item {
  flex: 1;
  height: var(--bottom-nav-height);
  background: transparent;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition-fast);
  padding: 4px 0;
}

.b-nav-item:active {
  transform: scale(0.92);
}

.b-nav-icon-wrapper {
  width: 44px;
  height: 26px;
  border-radius: var(--radius-pill);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);
}

.b-nav-icon {
  font-size: 19px;
  line-height: 1;
}

.b-nav-label {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: -0.2px;
  transition: var(--transition-fast);
}

/* Active State Samsung One UI */
.b-nav-item.active {
  color: var(--color-primary);
}

.b-nav-item.active .b-nav-icon-wrapper {
  background-color: var(--color-primary-subtle);
}

.b-nav-item.active .b-nav-label {
  color: var(--color-primary);
  font-weight: 700;
}

/* ==========================================================================
   Responsive Breakpoints
   ========================================================================== */

@media (max-width: 600px) {
  :root {
    --topbar-height: 48px;
    --bottom-nav-height: 56px;
  }

  .topbar {
    padding: 0 10px;
    height: 48px;
  }

  .brand {
    gap: 6px;
  }

  .brand-icon-box {
    display: none !important;
  }

  .topbar-actions .select-poll-top,
  .topbar-actions #btn-toggle-screen {
    display: none !important;
  }

  .brand-text h1 {
    font-size: 13.5px;
  }

  .brand-sub {
    font-size: 10px;
  }

  .content-area {
    padding: 8px 8px;
    padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px) + 24px);
  }

  .section-header {
    margin-bottom: 8px;
  }

  .section-header h2 {
    font-size: 16px;
  }

  .grid-cards {
    gap: 8px;
  }

  .b-nav-icon-wrapper {
    width: 38px;
    height: 24px;
  }

  .b-nav-icon {
    width: 17px;
    height: 17px;
  }

  .b-nav-label {
    font-size: 9.5px;
  }
}

@media (min-width: 768px) {
  .sidebar {
    display: flex;
  }

  .bottom-nav {
    display: none;
  }

  .content-area {
    padding: 20px;
    padding-bottom: 28px;
  }

  .grid-cards {
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
  }
}
