/* ==========================================================================
   NEXO SAÚDE — LAYOUT & SHELL STRUCTURE
   Sidebar, Header, Connectivity Bar, Demo Bar & Containers
   ========================================================================== */

/* Main Layout Grid */
.app-container {
  display: flex;
  min-height: 100vh;
  width: 100vw;
  background-color: var(--bg-app);
  position: relative;
}

/* --------------------------------------------------------------------------
   SIDEBAR
   -------------------------------------------------------------------------- */
.app-sidebar {
  width: var(--sidebar-width);
  background-color: var(--bg-sidebar);
  color: var(--slate-300);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  height: 100vh;
  position: sticky;
  top: 0;
  z-index: 40;
  transition: width var(--transition-normal), transform var(--transition-normal);
  border-right: 1px solid rgba(255, 255, 255, 0.06);
}

.sidebar-header {
  height: var(--header-height);
  padding: 0 1.15rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

.brand-logo {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  text-decoration: none;
  color: #FFFFFF;
  min-width: 0;
  flex: 1;
}

.brand-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, var(--primary-500) 0%, var(--primary-700) 100%);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #FFFFFF;
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.35);
  flex-shrink: 0;
}

.brand-icon svg {
  width: 22px;
  height: 22px;
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
  gap: 0.15rem;
}

.brand-title {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 800;
  color: #FFFFFF;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
  line-height: 1.2;
}

.brand-title > span:first-child {
  white-space: nowrap;
}

.brand-badge {
  font-size: 0.62rem;
  padding: 0.12rem 0.45rem;
  background: rgba(16, 185, 129, 0.2);
  color: var(--primary-300);
  border: 1px solid rgba(16, 185, 129, 0.35);
  border-radius: var(--radius-full);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  line-height: 1;
  flex-shrink: 0;
}

.brand-subtitle {
  font-size: 0.72rem;
  color: var(--slate-400);
  white-space: nowrap;
  font-weight: 500;
  letter-spacing: 0.01em;
}

.sidebar-toggle-btn {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--slate-400);
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}
.sidebar-toggle-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #FFFFFF;
  border-color: rgba(255, 255, 255, 0.2);
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 1.4rem 0.95rem;
  display: flex;
  flex-direction: column;
  gap: 1.4rem;
}

.nav-section {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.nav-section-title {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--slate-500);
  padding: 0 0.85rem 0.45rem 0.85rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.72rem 0.95rem;
  border-radius: 10px;
  color: var(--slate-300);
  font-size: 0.92rem;
  font-weight: 500;
  text-decoration: none;
  transition: all var(--transition-fast);
  position: relative;
}

.nav-item svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  transition: color var(--transition-fast);
}

.nav-item:hover {
  background: var(--bg-sidebar-hover);
  color: #FFFFFF;
}

.nav-item.active {
  background: linear-gradient(90deg, rgba(16, 185, 129, 0.2) 0%, rgba(16, 185, 129, 0.06) 100%);
  color: #FFFFFF;
  font-weight: 600;
  border-left: 3.5px solid var(--primary-500);
}

.nav-item.active svg {
  color: var(--primary-400);
}

.nav-item .nav-badge {
  margin-left: auto;
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-full);
  background: var(--primary-900);
  color: var(--primary-300);
  font-weight: 700;
}

.sidebar-footer {
  padding: 1.15rem 1rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.2);
}

.operation-device-card {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.75rem 0.85rem;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 10px;
  transition: all var(--transition-fast);
}

.device-dot {
  width: 8px;
  height: 8px;
  background: var(--primary-500);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--primary-500);
  flex-shrink: 0;
}

.device-info {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  gap: 0.1rem;
}

.device-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--slate-200);
  white-space: nowrap;
}

.device-sub {
  font-size: 0.7rem;
  color: var(--slate-400);
  white-space: nowrap;
}

/* --------------------------------------------------------------------------
   COLLAPSED SIDEBAR (ICON-ONLY MODE)
   -------------------------------------------------------------------------- */
.app-sidebar.collapsed {
  width: var(--sidebar-collapsed-width);
}

.app-sidebar.collapsed .sidebar-header {
  padding: 0 0.5rem;
  justify-content: center;
  position: relative;
}

.app-sidebar.collapsed .brand-logo {
  gap: 0;
  justify-content: center;
}

.app-sidebar.collapsed .brand-text {
  display: none !important;
}

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

.app-sidebar.collapsed .sidebar-nav {
  padding: 1rem 0.5rem;
  gap: 0.6rem;
  align-items: center;
  overflow-x: hidden;
}

.app-sidebar.collapsed .nav-section {
  width: 100%;
  align-items: center;
  gap: 0.35rem;
}

.app-sidebar.collapsed .nav-section-title {
  display: none !important;
}

.app-sidebar.collapsed .nav-item {
  width: 44px;
  height: 44px;
  padding: 0;
  justify-content: center;
  border-radius: var(--radius-md);
  border-left: none !important;
  position: relative;
  margin: 0 auto;
}

.app-sidebar.collapsed .nav-item span:not(.nav-badge) {
  display: none !important;
}

.app-sidebar.collapsed .nav-item .nav-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 8px;
  height: 8px;
  padding: 0;
  border-radius: 50%;
  font-size: 0;
  background: var(--primary-400);
  border: 1px solid var(--bg-sidebar);
}

.app-sidebar.collapsed .nav-item.active {
  background: var(--primary-600);
  color: #FFFFFF;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
}

.app-sidebar.collapsed .nav-item.active svg {
  color: #FFFFFF;
}

/* Tooltip on Hover in Collapsed Mode */
.app-sidebar.collapsed .nav-item[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  left: calc(100% + 14px);
  top: 50%;
  transform: translateY(-50%);
  background: var(--slate-900);
  color: #FFFFFF;
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.15);
  z-index: 150;
  pointer-events: none;
  animation: tooltipFadeIn 0.15s cubic-bezier(0.16, 1, 0.3, 1);
}

.app-sidebar.collapsed .nav-item[data-tooltip]:hover::before {
  content: '';
  position: absolute;
  left: calc(100% + 8px);
  top: 50%;
  transform: translateY(-50%);
  border-width: 5px 6px 5px 0;
  border-style: solid;
  border-color: transparent var(--slate-900) transparent transparent;
  z-index: 150;
  pointer-events: none;
  animation: tooltipFadeIn 0.15s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes tooltipFadeIn {
  from { opacity: 0; transform: translateY(-50%) translateX(-4px); }
  to { opacity: 1; transform: translateY(-50%) translateX(0); }
}

.app-sidebar.collapsed .sidebar-footer {
  padding: 0.75rem 0.5rem;
  display: flex;
  justify-content: center;
}

.app-sidebar.collapsed .operation-device-card {
  width: 40px;
  height: 40px;
  padding: 0;
  justify-content: center;
  border-radius: var(--radius-md);
}

.app-sidebar.collapsed .device-info {
  display: none !important;
}

/* --------------------------------------------------------------------------
   APP MAIN & HEADER
   -------------------------------------------------------------------------- */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  overflow-y: auto;
}

.app-header {
  height: var(--header-height);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0 1.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 30;
  box-shadow: var(--shadow-xs);
}

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

.mobile-menu-btn {
  display: none;
  background: transparent;
  border: 1px solid var(--border-subtle);
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  align-items: center;
  justify-content: center;
  color: var(--slate-700);
  cursor: pointer;
}

.operation-tag {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0.85rem;
  background: var(--slate-50);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
}

.operation-badge-icon {
  color: var(--primary-600);
  display: flex;
}

.operation-name {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--slate-800);
}

.operation-loc {
  font-size: 0.78rem;
  color: var(--slate-500);
}

.header-center {
  flex: 1;
  max-width: 480px;
  margin: 0 1.5rem;
}

.global-search-box {
  position: relative;
  width: 100%;
}

.global-search-input {
  width: 100%;
  height: 40px;
  padding: 0 2.75rem 0 2.5rem;
  background: var(--slate-100);
  border: 1px solid transparent;
  border-radius: var(--radius-full);
  font-size: 0.88rem;
  color: var(--text-primary);
  transition: all var(--transition-fast);
}

.global-search-input:focus {
  outline: none;
  background: #FFFFFF;
  border-color: var(--primary-500);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.search-icon-btn {
  position: absolute;
  left: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--slate-400);
  pointer-events: none;
  display: flex;
}

.search-kbd-shortcut {
  position: absolute;
  right: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.7rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  padding: 0.15rem 0.45rem;
  border-radius: var(--radius-xs);
  color: var(--slate-500);
  font-family: var(--font-mono);
  font-weight: 600;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

/* Connectivity Status Pill */
.connectivity-pill {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.85rem;
  border-radius: var(--radius-full);
  background: var(--success-bg);
  border: 1px solid var(--success-border);
  color: var(--success-text);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.connectivity-pill:hover {
  filter: brightness(0.97);
  box-shadow: var(--shadow-xs);
}

.connectivity-pill.offline {
  background: var(--warning-bg);
  border-color: var(--warning-border);
  color: var(--warning-text);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: currentColor;
  position: relative;
}

.status-dot.pulsing::after {
  content: '';
  position: absolute;
  top: -3px;
  left: -3px;
  right: -3px;
  bottom: -3px;
  border-radius: 50%;
  border: 2px solid currentColor;
  opacity: 0.6;
  animation: pulse-ring 2s cubic-bezier(0.215, 0.61, 0.355, 1) infinite;
}

@keyframes pulse-ring {
  0% { transform: scale(0.6); opacity: 0.8; }
  100% { transform: scale(1.6); opacity: 0; }
}

.header-icon-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background: var(--slate-50);
  border: 1px solid var(--border-subtle);
  color: var(--slate-600);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
  transition: all var(--transition-fast);
}

.header-icon-btn:hover {
  background: var(--slate-100);
  color: var(--slate-900);
}

.notification-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 17px;
  height: 17px;
  background: var(--danger-solid);
  color: #FFFFFF;
  font-size: 0.65rem;
  font-weight: 700;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg-surface);
}

.user-profile-btn {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.35rem 0.65rem 0.35rem 0.35rem;
  border-radius: var(--radius-full);
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.user-profile-btn:hover {
  background: var(--slate-50);
  border-color: var(--border-subtle);
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--blue-600) 0%, var(--primary-600) 100%);
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
}

.user-info {
  display: flex;
  flex-direction: column;
  text-align: left;
}

.user-name {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--slate-800);
  line-height: 1.2;
}

.user-role {
  font-size: 0.72rem;
  color: var(--slate-500);
}

/* --------------------------------------------------------------------------
   PAGE CONTENT WRAPPER
   -------------------------------------------------------------------------- */
.page-content {
  flex: 1;
  padding: 2rem 2.25rem;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
}

/* Page Header Structure */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.75rem;
  gap: 1rem;
  flex-wrap: wrap;
}

.page-title-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.page-title {
  font-size: 1.65rem;
  font-weight: 800;
  color: var(--slate-900);
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.page-subtitle {
  font-size: 0.9rem;
  color: var(--slate-500);
}

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

/* --------------------------------------------------------------------------
   FLOATING DEMO LAUNCHER BAR ("Modo Demo")
   -------------------------------------------------------------------------- */
.demo-floating-menu {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 100;
}

.demo-menu-trigger {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.65rem 1.15rem;
  background: var(--slate-900);
  color: #FFFFFF;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  font-weight: 700;
  box-shadow: var(--shadow-xl), 0 0 20px rgba(0, 0, 0, 0.35);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.demo-menu-trigger:hover {
  transform: translateY(-2px);
  background: var(--slate-800);
  border-color: var(--primary-400);
}

.demo-badge-dot {
  width: 8px;
  height: 8px;
  background: var(--primary-400);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--primary-400);
}

.demo-popover-card {
  position: absolute;
  bottom: calc(100% + 0.75rem);
  right: 0;
  width: 320px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  padding: 1rem;
  display: none;
  flex-direction: column;
  gap: 0.75rem;
  animation: fadeInDown 0.2s ease-out;
}

.demo-popover-card.open {
  display: flex;
}

.demo-popover-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 0.5rem;
}

.demo-popover-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--slate-900);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.demo-scenario-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.demo-scenario-btn {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 0.65rem;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  background: var(--slate-50);
  color: var(--slate-700);
  font-size: 0.82rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.demo-scenario-btn:hover {
  background: var(--primary-50);
  color: var(--primary-800);
  border-color: var(--primary-200);
}

.demo-scenario-icon {
  width: 24px;
  height: 24px;
  border-radius: var(--radius-sm);
  background: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary-600);
  font-size: 0.75rem;
  box-shadow: var(--shadow-xs);
  flex-shrink: 0;
}

/* --------------------------------------------------------------------------
   CONNECTIVITY DRAWER / SYNC PANEL
   -------------------------------------------------------------------------- */
.sync-drawer-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(4px);
  z-index: 90;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-normal);
}

.sync-drawer-overlay.open {
  opacity: 1;
  visibility: visible;
}

.sync-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: 380px;
  max-width: 100vw;
  height: 100vh;
  background: var(--bg-surface);
  box-shadow: var(--shadow-xl);
  z-index: 100;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--transition-normal);
}

.sync-drawer.open {
  transform: translateX(0);
}

.sync-drawer-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sync-drawer-body {
  flex: 1;
  padding: 1.5rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.sync-status-card {
  padding: 1.25rem;
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.sync-status-card.online {
  background: var(--success-bg);
  border: 1px solid var(--success-border);
}

.sync-status-card.offline {
  background: var(--warning-bg);
  border: 1px solid var(--warning-border);
}

.sync-stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.sync-stat-item {
  padding: 0.85rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.sync-stat-val {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--slate-900);
}

.sync-stat-lbl {
  font-size: 0.75rem;
  color: var(--slate-500);
}

.sync-progress-box {
  display: none;
  flex-direction: column;
  gap: 0.5rem;
  padding: 1rem;
  background: var(--slate-50);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.sync-progress-box.active {
  display: flex;
}

.sync-progress-bar-bg {
  width: 100%;
  height: 8px;
  background: var(--slate-200);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.sync-progress-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary-500), var(--primary-400));
  transition: width 0.3s ease;
}

/* Animations */
@keyframes fadeInDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}
