/**
 * Shell da aplicação — sidebar, barra superior, áreas de conteúdo.
 * Mobile / tablet: sidebar em gaveta (≤992px). Desktop: sidebar fixa (≥993px).
 */

.app {
  display: flex;
  min-height: 100vh;
  min-height: 100dvh;
}

/* ——— Sidebar ——— */
.sidebar {
  width: var(--layout-sidebar-width);
  min-width: var(--layout-sidebar-width);
  background: var(--primary);
  color: #fff;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  z-index: 1040;
  transition: transform 0.28s ease;
  box-shadow: 2px 0 12px rgba(0, 0, 0, 0.12);
}

.sidebar__brand {
  padding: 1rem 1.25rem;
  text-align: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.sidebar__brand h4 {
  margin: 0;
  color: #fff;
  font-size: 1.15rem;
  font-weight: 500;
}

.sidebar-nav {
  padding: 0.5rem 0;
  background-color: #939393;
}

.sidebar-nav ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.sidebar-nav li {
  margin: 0;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  min-height: var(--touch-target-min);
  padding: 0.65rem 1rem;
  color: #fff;
  text-decoration: none;
  transition: background 0.2s;
  gap: 0.65rem;
}

.sidebar-nav a:hover,
.sidebar-nav a:focus-visible,
.sidebar-nav a.active {
  background: rgba(255, 255, 255, 0.12);
  outline: none;
}

.sidebar-nav a i.material-icons {
  margin-right: 0;
  flex-shrink: 0;
}

/* ——— Overlay mobile ——— */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 1035;
  backdrop-filter: blur(2px);
}

.sidebar-overlay.active {
  display: block;
}

/* ——— Área principal ——— */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  width: 100%;
  margin-left: var(--layout-sidebar-width);
  padding-top: env(safe-area-inset-top, 0);
}

.top-bar {
  position: sticky;
  top: 0;
  z-index: 1030;
  background: var(--primary);
  color: #fff;
  padding: 0.5rem max(0.75rem, env(safe-area-inset-right))
    0.5rem max(0.75rem, env(safe-area-inset-left));
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem 0.75rem;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
  min-height: calc(var(--touch-target-min) + 4px);
}

.top-bar__left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex: 1 1 auto;
  min-width: 0;
}

.top-bar-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem 0.75rem;
  flex: 0 1 auto;
  min-width: 0;
}

.sidebar-toggle {
  display: none;
  background: transparent;
  border: none;
  color: #fff;
  cursor: pointer;
  padding: 0.35rem 0.6rem;
  min-width: var(--touch-target-min);
  min-height: var(--touch-target-min);
  align-items: center;
  justify-content: center;
  border-radius: 4px;
}

.sidebar-toggle:hover,
.sidebar-toggle:focus-visible {
  background: rgba(255, 255, 255, 0.12);
  outline: none;
}

.sync-status-label {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.92);
  max-width: 140px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#user-menu-btn .user-menu-caret {
  font-size: 18px;
  flex-shrink: 0;
}

@media (max-width: 400px) {
  .sync-status-label {
    display: none;
  }
}

#sync-btn {
  position: relative;
  min-height: var(--touch-target-min);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

#user-menu-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  max-width: min(100%, 220px);
  min-height: var(--touch-target-min);
}

#user-name-display {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 8rem;
}

@media (min-width: 601px) {
  #user-name-display {
    max-width: 12rem;
  }
}

.user-menu-container {
  position: relative;
}

.user-menu-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  left: auto;
  background: #fff;
  min-width: 200px;
  max-width: min(92vw, 280px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  border-radius: 6px;
  margin: 0;
  z-index: 1100;
  list-style: none;
  padding: 0.5rem 0;
}

.user-menu-dropdown li {
  margin: 0;
}

.user-menu-dropdown li a {
  display: flex;
  align-items: center;
  padding: 0.75rem 1.1rem;
  color: #333;
  text-decoration: none;
  transition: background 0.2s;
  gap: 0.65rem;
  min-height: var(--touch-target-min);
}

.user-menu-dropdown li a:hover,
.user-menu-dropdown li a:focus-visible {
  background: #f5f5f5;
  outline: none;
}

.user-menu-dropdown li a i {
  font-size: 1.25rem;
  color: var(--primary);
}

.user-menu-dropdown li.divider {
  height: 1px;
  background: var(--border-color);
  margin: 0.35rem 0;
  padding: 0;
}

.status-online {
  color: #4caf50;
}

.status-offline {
  color: #f44336;
}

/* Materialize .container dentro das páginas */
.container {
  width: 100%;
  max-width: 100%;
  margin-left: auto;
  margin-right: auto;
}

.page-content {
  width: 100%;
  max-width: 100%;
  flex: 1;
  box-sizing: border-box;
  padding: 0.5rem max(0.75rem, env(safe-area-inset-right))
    max(1rem, env(safe-area-inset-bottom)) max(0.75rem, env(safe-area-inset-left));
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.page-content-inner.container {
  max-width: var(--layout-max-content);
}

/* Blocos usados por pages.js / pessoas / relatórios */
.page-container {
  width: 100%;
  max-width: var(--layout-max-content);
  margin: 0 auto;
  padding: 0.25rem 0 1.5rem;
}

.page-header {
  margin-bottom: 1rem;
}

.page-header h2 {
  margin: 0;
  font-size: clamp(1.15rem, 2.5vw, 1.5rem);
  font-weight: 500;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.table-container {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0.5rem 0 1rem;
  border-radius: 4px;
}

.table-container table {
  min-width: 560px;
}

/**
 * Relatórios: não usar `responsive-table` do Materialize (ele oculta o thead no mobile).
 * Scroll horizontal + cabeçalho sticky = mesma apresentação do cabeçalho em qualquer largura.
 */
#relatorios-page .table-container--relatorio {
  border: 1px solid var(--border-color);
  background: #fff;
}

#relatorios-page table.relatorio-data-table {
  margin: 0;
  min-width: 100%;
}

#relatorios-page table.relatorio-data-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #e0f2f1;
  color: #004d40;
  font-weight: 600;
  font-size: 0.8125rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  padding: 0.75rem 0.65rem;
  border-bottom: 2px solid var(--primary);
  white-space: nowrap;
  vertical-align: bottom;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.08);
}

#relatorios-page table.relatorio-data-table tbody td {
  padding: 0.65rem 0.65rem;
  font-size: 0.9375rem;
  vertical-align: middle;
}

#relatorios-page table.relatorio-data-table tbody tr:last-child td {
  border-bottom: none;
}

/* ——— Dashboard (dashboard.js) ——— */
.dashboard-container {
  max-width: var(--layout-max-content);
  margin: 0 auto;
  padding-bottom: 1.5rem;
}

.dashboard-cards {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

@media (min-width: 601px) {
  .dashboard-cards {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 993px) {
  .dashboard-cards {
    grid-template-columns: repeat(4, 1fr);
  }
}

.dashboard-card {
  display: flex;
  align-items: stretch;
  gap: 1rem;
  padding: 1rem 1.1rem;
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  border-left: 4px solid var(--primary);
}

.dashboard-card.card-success {
  border-left-color: #4caf50;
}

.dashboard-card.card-danger {
  border-left-color: #ef5350;
}

.dashboard-card.card-primary {
  border-left-color: var(--primary);
}

.dashboard-card.card-info {
  border-left-color: #29b6f6;
}

.dashboard-card .card-icon {
  font-size: 1.75rem;
  opacity: 0.85;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.dashboard-card .card-content h3 {
  margin: 0 0 0.25rem;
  font-size: clamp(1.1rem, 2.5vw, 1.35rem);
  font-weight: 600;
  word-break: break-word;
}

.dashboard-card .card-content p {
  margin: 0;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.dashboard-charts {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

@media (min-width: 993px) {
  .dashboard-charts {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.chart-wrapper {
  background: #fff;
  border-radius: 8px;
  padding: 1rem;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06);
}

.chart-wrapper.full-width {
  grid-column: 1 / -1;
}

.chart-wrapper h3 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.chart-wrapper canvas {
  max-width: 100%;
  height: auto !important;
}

.filters-panel .card-title {
  padding: 1rem 1.25rem 0;
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ——— Desktop: sidebar sempre visível ——— */
@media (min-width: 993px) {
  .sidebar {
    transform: translateX(0) !important;
  }

  .sidebar.open {
    transform: translateX(0) !important;
  }

  .sidebar-toggle {
    display: none !important;
  }

  .sidebar-overlay,
  .sidebar-overlay.active {
    display: none !important;
    pointer-events: none;
  }
}

/* ——— Tablet e mobile: gaveta ——— */
@media (max-width: 992px) {
  .sidebar {
    transform: translateX(-100%);
    max-width: min(280px, 88vw);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main-content {
    margin-left: 0;
    width: 100%;
  }

  .sidebar-toggle {
    display: inline-flex;
  }
}
