*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  color-scheme: dark;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  font-family: var(--font-family-base);
  background-color: var(--bg-main);
  color: var(--text-main);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 100%;
  overflow-x: hidden;
  position: relative;
  line-height: 1.5;
}

/* Scrollbars */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--bg-main);
}
::-webkit-scrollbar-thumb {
  background: var(--bg-surface-elevated);
  border-radius: var(--radius-full);
  border: 2px solid var(--bg-main);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--border-focus);
}

/* Layout Architecture */
.app-layout {
  display: flex;
  min-height: 100dvh;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

/* Sidebar Navigation */
.app-sidebar {
  width: 260px;
  background-color: var(--bg-surface);
  border-inline-end: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100dvh;
  z-index: 40;
  transition: transform var(--transition-normal);
}

.brand-header {
  padding: 1.5rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  border-block-end: 1px solid var(--border-subtle);
}

.brand-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--primary), var(--accent-teal));
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
  color: white;
}

.brand-title {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(to right, #ffffff, #94a3b8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-badge {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 0.15rem 0.4rem;
  background: var(--primary-light);
  color: var(--primary);
  border-radius: var(--radius-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-inline-start: auto;
}

/* Navigation Links */
.nav-menu {
  list-style: none;
  padding: 1rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  flex: 1;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.925rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  border: 1px solid transparent;
}

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

.nav-item.active {
  background-color: var(--primary-light);
  color: var(--primary);
  border-color: var(--border-accent);
  font-weight: 600;
}

.nav-item svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  stroke-width: 2;
}

.nav-badge {
  margin-inline-start: auto;
  font-size: 0.75rem;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-full);
  background-color: var(--bg-surface-elevated);
  color: var(--text-muted);
  font-weight: 600;
}

.nav-badge.alert {
  background-color: var(--accent-rose-light);
  color: var(--accent-rose);
}

/* Main Content Area */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: 100%;
  overflow-x: hidden;
  background-color: var(--bg-main);
}

/* App Header & Profile Bar */
.app-header {
  height: 66px;
  padding: 0 1.5rem;
  background-color: var(--bg-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-block-end: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 30;
}

.header-left {
  display: flex;
  align-items: center;
}

/* Brand icon with Perfil Saúde title and version */
.header-brand-box {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  cursor: pointer;
  user-select: none;
  transition: transform var(--transition-fast);
}

.header-brand-box:hover {
  transform: scale(1.02);
}

.header-brand-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--primary), var(--accent-teal));
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
  flex-shrink: 0;
}

.header-brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.header-brand-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.header-version-label {
  font-family: var(--font-family-mono);
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--accent-teal);
  letter-spacing: 0.03em;
  line-height: 1;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* 1. Profile Avatar Button (Marlon / Rony / Wagner) com Seta */
.profile-avatar-btn {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  padding: 2px 7px 2px 2px;
  cursor: pointer;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all var(--transition-fast);
}

.profile-avatar-btn:hover {
  border-color: var(--border-focus);
  background-color: var(--bg-surface-hover);
  transform: scale(1.05);
}

.profile-avatar-btn .profile-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.95rem;
  color: white;
  border: 1px solid rgba(255, 255, 255, 0.25);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

.profile-chevron {
  color: var(--text-muted);
  transition: transform var(--transition-fast), color var(--transition-fast);
}

.profile-avatar-btn:hover .profile-chevron {
  color: #ffffff;
  transform: translateY(1px);
}

/* 2. Logged User Avatar Circle */
.logged-user-avatar-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border-radius: var(--radius-full);
  transition: transform var(--transition-fast);
}

.logged-user-avatar-btn:hover {
  transform: scale(1.08);
}

.user-avatar-circle {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, #1e293b, #334155);
  border: 2px solid rgba(56, 189, 248, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #38bdf8;
  font-weight: 700;
  font-size: 0.95rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

/* 3. Header Action Buttons (Logout & Admin) */
.btn-header-circle,
.btn-header-logout {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-full);
  background-color: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  transition: all var(--transition-fast);
}

.btn-header-circle:hover {
  border-color: var(--primary);
  color: var(--primary);
  transform: scale(1.08);
}

.btn-header-logout:hover {
  background-color: var(--accent-rose-light);
  color: var(--accent-rose);
  border-color: var(--accent-rose);
  transform: scale(1.08);
}

/* Viewport / Content View */
.view-container {
  padding: 1.75rem;
  max-width: 1440px;
  width: 100%;
  box-sizing: border-box;
  margin: 0 auto;
  display: none;
  animation: fadeIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.view-container.active {
  display: block;
}

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

/* Mobile Bottom Navigation (Responsive) */
.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 64px;
  background-color: var(--bg-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-block-start: 1px solid var(--border-subtle);
  z-index: 50;
  justify-content: space-around;
  align-items: center;
  padding: 0 0.5rem;
}

.mobile-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.7rem;
  font-weight: 500;
  padding: 0.4rem;
  border-radius: var(--radius-sm);
  flex: 1;
  transition: color var(--transition-fast);
}

.mobile-nav-item.active {
  color: var(--primary);
  font-weight: 600;
}

.mobile-nav-item svg {
  width: 22px;
  height: 22px;
}

/* Responsive Breakpoints */
@media (max-width: 900px) {
  .app-sidebar {
    display: none;
  }
  .mobile-nav {
    display: flex;
  }
  .view-container {
    padding: 1rem 0.85rem;
    padding-bottom: 80px; /* Space for mobile nav */
    max-width: 100%;
    box-sizing: border-box;
    overflow-x: hidden;
  }
  .app-header {
    padding: 0 1rem;
    height: 64px;
  }
}

@media (max-width: 768px) {
  .app-header {
    padding: 0 0.85rem;
    height: 60px;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

  .header-actions {
    gap: 0.5rem;
  }

  .profile-avatar-btn .profile-avatar,
  .user-avatar-circle,
  .btn-header-logout,
  .btn-header-circle {
    width: 35px;
    height: 35px;
    font-size: 0.9rem;
  }

  .header-brand-icon {
    width: 32px;
    height: 32px;
  }

  .card {
    padding: 1.15rem 0.85rem;
  }
}

@media (max-width: 480px) {
  .app-header {
    padding: 0 0.65rem;
  }

  .header-actions {
    gap: 0.4rem;
  }

  .view-container {
    padding: 0.75rem 0.4rem 80px 0.4rem;
  }

  .btn-sm {
    padding: 0.3rem 0.5rem;
    font-size: 0.75rem;
  }
}
