/* ==========================================================================
   ApexPOS - Layout & Shell Structure
   ========================================================================== */

#app-root {
  display: flex;
  width: 100vw;
  height: 100vh;
  background-color: var(--bg-canvas);
  overflow: hidden;
}

/* Sidebar Navigation */
.app-sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100%;
  background-color: var(--bg-surface);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  transition: width var(--trans-smooth), min-width var(--trans-smooth);
  z-index: 50;
}

.app-sidebar.collapsed {
  width: var(--sidebar-collapsed-width);
  min-width: var(--sidebar-collapsed-width);
}

.sidebar-header {
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-muted);
}

.brand-badge {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}

.brand-icon {
  width: 32px;
  height: 32px;
  background: var(--bg-elevated);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  font-weight: 800;
  font-size: 1rem;
  border: 1px solid var(--border-subtle);
}

.sidebar-toggle-btn {
  background: transparent;
  border: 1px solid var(--border-muted);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--trans-fast), color var(--trans-fast);
}

.sidebar-toggle-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-focus);
}

/* Sidebar Navigation Items */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-section-label {
  font-size: 0.72rem;
  text-transform: none;
  letter-spacing: normal;
  color: var(--text-muted);
  font-weight: 500;
  padding: 10px 10px 4px;
}

.app-sidebar.collapsed .nav-section-label {
  display: none;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background var(--trans-fast), color var(--trans-fast), transform var(--trans-fast);
  position: relative;
}

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

.nav-item.active {
  background-color: var(--bg-hover);
  color: #ffffff;
  font-weight: 600;
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 3px;
  background-color: var(--accent-amber);
  border-radius: 0 4px 4px 0;
}

.nav-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 1.1rem;
}

.nav-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-sidebar.collapsed .nav-label {
  display: none;
}

.nav-badge {
  margin-left: auto;
  background: var(--accent-amber);
  color: #000;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: var(--radius-pill);
}

.app-sidebar.collapsed .nav-badge {
  display: none;
}

/* Sidebar Footer & User Profile */
.sidebar-footer {
  padding: 14px;
  border-top: 1px solid var(--border-muted);
  display: flex;
  flex-direction: column;
  gap: 10px;
  background-color: var(--bg-card);
}

.user-profile-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px;
  border-radius: var(--radius-md);
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-pill);
  background-color: var(--border-focus);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  border: 1px solid var(--border-subtle);
}

.user-meta {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.user-name {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-primary);
}

.user-role-badge {
  font-size: 0.72rem;
  color: var(--accent-amber);
  text-transform: none;
  font-weight: 500;
}

/* Main Viewport Workspace */
.main-viewport {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-canvas);
}

/* Top Action & System Bar */
.top-system-bar {
  height: 54px;
  border-bottom: 1px solid var(--border-subtle);
  background-color: var(--bg-surface);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 40;
}

.top-bar-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.page-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: normal;
}

.branch-select-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-hover);
  border: 1px solid var(--border-muted);
  border-radius: var(--radius-pill);
  padding: 3px 10px;
  font-size: 0.78rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.top-bar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.quick-action-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  background-color: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--trans-fast), border-color var(--trans-fast), transform var(--trans-fast);
}

.quick-action-btn:hover {
  background-color: var(--bg-hover);
  border-color: var(--border-focus);
  transform: translateY(-1px);
}

.quick-action-btn.primary {
  background-color: var(--accent-amber);
  color: #000000;
  border-color: var(--accent-amber);
  font-weight: 700;
  box-shadow: var(--shadow-sm);
}

.quick-action-btn.primary:hover {
  background-color: var(--accent-amber-dark);
  border-color: var(--accent-amber-dark);
  color: #000000;
}

.quick-action-btn.danger {
  background-color: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--border-subtle);
}

.quick-action-btn.danger:hover {
  background-color: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-focus);
}

.shift-status-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  background: var(--bg-hover);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.status-dot {
  width: 6px;
  height: 6px;
  background-color: var(--accent-amber);
  border-radius: 50%;
  box-shadow: 0 0 6px rgba(245, 158, 11, 0.6);
}

/* Module Container */
.module-container {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.module-view {
  width: 100%;
  height: 100%;
  display: none;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
}

.module-view.active {
  display: flex;
  flex-direction: column;
}

/* Mobile Navigation Components */
.mobile-menu-btn {
  display: none;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  width: 36px;
  height: 36px;
  align-items: center;
  justify-content: center;
  font-size: 1.15rem;
  cursor: pointer;
  flex-shrink: 0;
  transition: all var(--trans-fast);
}

.mobile-menu-btn:hover, .mobile-menu-btn:active {
  background: var(--bg-hover);
  border-color: var(--border-focus);
}

.sidebar-close-btn {
  display: none;
  background: transparent;
  border: 1px solid var(--border-muted);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  width: 30px;
  height: 30px;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.95rem;
  transition: background var(--trans-fast), color var(--trans-fast);
}

.sidebar-close-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 95;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--trans-smooth);
}

.sidebar-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

/* ==========================================================================
   Responsive Media Queries (Mobile & Tablet)
   ========================================================================== */

@media (max-width: 768px) {
  #app-root {
    height: 100dvh;
    height: 100vh;
    overflow: hidden;
    position: relative;
    padding-bottom: var(--safe-area-bottom);
    padding-top: var(--safe-area-top);
  }

  .mobile-menu-btn {
    display: flex;
  }

  .sidebar-close-btn {
    display: flex;
  }

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

  /* Off-Canvas Sidebar Drawer on Mobile */
  .app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 275px;
    max-width: 82vw;
    z-index: 100;
    transform: translateX(-100%);
    transition: transform var(--trans-smooth);
    box-shadow: none;
    border-right: 1px solid var(--border-focus);
  }

  .app-sidebar.mobile-open {
    transform: translateX(0);
    box-shadow: 0 0 35px rgba(0, 0, 0, 0.85);
  }

  /* When collapsed class is toggled on mobile, don't shrink width */
  .app-sidebar.collapsed {
    width: 275px;
    min-width: 275px;
  }
  .app-sidebar.collapsed .nav-label,
  .app-sidebar.collapsed .nav-badge,
  .app-sidebar.collapsed .nav-section-label {
    display: block !important;
  }

  /* Top Bar Mobile Optimization */
  .top-system-bar {
    padding: 0 10px;
    height: 50px;
    gap: 6px;
    min-width: 0;
  }

  .top-bar-left {
    gap: 8px;
    min-width: 0;
    flex: 1;
    overflow: hidden;
  }

  .mobile-menu-btn {
    width: 34px;
    height: 34px;
    font-size: 1.05rem;
    flex-shrink: 0;
  }

  .page-title {
    font-size: clamp(0.85rem, 3.2vw, 0.96rem);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
  }

  .branch-select-pill {
    display: none; /* Hide verbose branch badge on small mobile screens */
  }

  .top-bar-right {
    gap: 5px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
  }

  #open-kitchen-drawer-btn {
    height: 32px;
    padding: 0 8px;
    gap: 4px;
  }
  #open-kitchen-drawer-btn span:first-child {
    display: none;
  }
  #open-kitchen-drawer-btn::before {
    content: "🍳";
    font-size: 0.82rem;
  }

  #theme-toggle-btn {
    height: 32px;
    padding: 0 8px;
  }
  #theme-toggle-btn span {
    display: none;
  }
  #theme-toggle-btn::before {
    content: "🌓";
    font-size: 0.85rem;
  }

  #top-db-status-label {
    display: none; /* Keep the green status dot, hide long label */
  }

  #top-db-status-pill {
    padding: 6px 8px;
    height: 32px;
  }

  .shift-status-pill span:not(.status-dot) {
    display: none;
  }
  .shift-status-pill {
    padding: 6px 8px;
    height: 32px;
    gap: 0;
  }
}

@media (max-width: 480px) {
  .top-system-bar {
    padding: 0 8px;
    height: 48px;
    gap: 4px;
  }

  .top-bar-left {
    gap: 6px;
  }

  .mobile-menu-btn {
    width: 32px;
    height: 32px;
    font-size: 0.95rem;
  }
}
