/* Layout & Structure */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  font-family: var(--font-family);
  background-color: var(--bg-page);
  color: var(--text-main);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

img, svg, canvas {
  max-width: 100%;
}

/* App Shell Container */
#app-shell {
  display: flex;
  min-height: 100vh;
  background-color: var(--bg-page);
  position: relative;
}

/* Desktop & Drawer Sidebar */
.app-sidebar {
  width: var(--sidebar-width);
  background: #ffffff;
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 30;
  transition: transform var(--transition-normal), box-shadow var(--transition-normal);
  box-sizing: border-box;
}

.sidebar-brand {
  height: var(--header-height, 68px);
  min-height: var(--header-height, 68px);
  padding: 0 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
  background: #ffffff;
  box-sizing: border-box;
  flex-shrink: 0;
}

.brand-wrapper {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
  flex: 1;
}

.brand-icon {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, #059669 0%, #047857 100%);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  box-shadow: 0 4px 10px rgba(5, 150, 105, 0.25);
  flex-shrink: 0;
}

.brand-icon svg {
  display: block;
}

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

.brand-title {
  font-size: 1.0625rem;
  font-weight: 800;
  color: var(--color-slate-900);
  line-height: 1.2;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-subtitle {
  font-size: 0.6875rem;
  font-weight: 600;
  color: var(--color-primary-600);
  letter-spacing: 0.01em;
}

.sidebar-close-btn {
  display: flex;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  background: #f8fafc;
  color: var(--color-slate-500);
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  flex-shrink: 0;
  padding: 0;
  margin-left: 0.5rem;
}

.sidebar-close-btn:hover {
  background: #fee2e2;
  color: #dc2626;
  border-color: #fca5a5;
}

/* Sidebar Collapsed State (Desktop & Mobile) */
#app-shell.sidebar-collapsed .app-sidebar {
  transform: translateX(-100%);
  box-shadow: none;
}

#app-shell.sidebar-collapsed .app-main {
  margin-left: 0;
  width: 100%;
}

#app-shell.sidebar-collapsed .mobile-menu-btn {
  display: flex !important;
}

.sidebar-nav {
  padding: 1.25rem 0.875rem;
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  padding: 0.6875rem 0.875rem;
  border-radius: 10px;
  color: var(--color-slate-600);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 600;
  transition: all 0.15s ease;
  cursor: pointer;
  border: 1px solid transparent;
  user-select: none;
}

.nav-item:hover {
  background-color: #f1f5f9;
  color: var(--color-slate-900);
}

.nav-item.active {
  background: #ecfdf5;
  color: #047857;
  border-color: #a7f3d0;
  font-weight: 700;
  box-shadow: 0 1px 2px rgba(5, 150, 105, 0.06);
}

.nav-item svg {
  width: 19px;
  height: 19px;
  flex-shrink: 0;
  color: var(--color-slate-400);
  transition: color 0.15s ease;
}

.nav-item.active svg {
  color: #059669;
}

.sidebar-footer {
  padding: 1rem 0.875rem;
  border-top: 1px solid var(--border-subtle);
  background: #ffffff;
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
  flex-shrink: 0;
}

.user-profile-badge {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 0.75rem;
  border-radius: 10px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.user-profile-badge:hover {
  border-color: #cbd5e1;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #1e293b, #0f172a);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.8125rem;
  letter-spacing: 0.02em;
  flex-shrink: 0;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.user-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.user-name {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--color-slate-900);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

.user-role-tag {
  display: inline-block;
  font-size: 0.625rem;
  font-weight: 800;
  padding: 1.5px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  width: fit-content;
  line-height: 1.2;
}

.sidebar-logout-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.8125rem;
  font-weight: 700;
  color: #dc2626;
  background: #fef2f2;
  border: 1px solid #fee2e2;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  font-family: inherit;
}

.sidebar-logout-btn:hover {
  background: #fee2e2;
  border-color: #fca5a5;
  color: #b91c1c;
  transform: translateY(-1px);
  box-shadow: 0 2px 5px rgba(220, 38, 38, 0.1);
}

.sidebar-logout-btn:active {
  transform: translateY(0);
}

.sidebar-logout-btn svg {
  display: block;
  flex-shrink: 0;
}

.role-owner {
  background-color: #fef3c7;
  color: #92400e;
  border: 1px solid #fde68a;
}

.role-admin {
  background-color: #e0e7ff;
  color: #3730a3;
  border: 1px solid #c7d2fe;
}

.role-member {
  background-color: #f1f5f9;
  color: #475569;
  border: 1px solid #e2e8f0;
}

/* Main Content Area */
.app-main {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  min-width: 0;
  width: calc(100% - var(--sidebar-width));
  display: flex;
  flex-direction: column;
  transition: margin-left var(--transition-normal);
  background-color: var(--bg-page);
}

/* Header */
.app-header {
  height: var(--header-height);
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  width: 100%;
}

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

.header-family-selector {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.45rem 0.85rem;
  border-radius: var(--radius-md);
  background: var(--color-slate-50);
  border: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.header-family-selector:hover {
  background: white;
  border-color: var(--color-slate-300);
}

.family-home-icon {
  color: var(--color-primary-600);
}

.header-family-name {
  font-weight: 700;
  font-size: 0.9375rem;
  color: var(--color-slate-900);
}

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

/* Role / Member Switcher Simulator (for easy role testing) */
.role-switcher-container {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--color-primary-50);
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius-full);
  border: 1px solid var(--color-primary-200);
}

.role-switcher-label {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--color-primary-800);
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.role-select {
  background: white;
  border: 1px solid var(--color-primary-300);
  border-radius: var(--radius-sm);
  padding: 0.25rem 0.5rem;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--color-slate-800);
  cursor: pointer;
  outline: none;
}

.btn-header-add {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.625rem 1.125rem;
  background: linear-gradient(135deg, var(--color-primary-600), var(--color-primary-700));
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(16, 185, 129, 0.3);
  transition: all var(--transition-fast);
}

.btn-header-add:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.4);
}

/* Content Viewport */
.content-viewport {
  flex: 1;
  padding: 2rem;
  max-width: var(--max-content-width);
  width: 100%;
  margin: 0 auto;
}

/* Mobile Bottom Navigation */
.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bottom-nav-height);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border-subtle);
  z-index: var(--z-bottom-nav);
  justify-content: space-around;
  align-items: center;
  padding: 0 0.5rem;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.05);
}

.bottom-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--color-slate-500);
  text-decoration: none;
  font-size: 0.6875rem;
  font-weight: 600;
  gap: 3px;
  flex: 1;
  height: 100%;
  padding-bottom: 4px;
  transition: color var(--transition-fast);
  cursor: pointer;
  position: relative;
  background: transparent;
  border: none;
  font-family: var(--font-family);
}

.mobile-menu-indicator {
  position: absolute;
  top: 5px;
  left: calc(50% + 7px);
  min-width: 15px;
  height: 15px;
  padding: 0 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-primary-600);
  color: white;
  border: 2px solid white;
  border-radius: var(--radius-full);
  font-size: 0.5rem;
  font-weight: 800;
  line-height: 1;
}

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

.bottom-nav-item.active {
  color: var(--color-primary-600);
}

.bottom-nav-item.active svg {
  stroke-width: 2.5;
}

/* Center Floating Add Button for Mobile */
.mobile-add-btn-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
}

.mobile-fab-add {
  position: absolute;
  top: -26px;
  width: 54px;
  height: 54px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--color-primary-500), var(--color-primary-700));
  color: white;
  border: 3px solid #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(16, 185, 129, 0.45);
  cursor: pointer;
  transition: transform var(--transition-bounce), box-shadow var(--transition-fast);
}

.mobile-fab-add:active {
  transform: scale(0.92);
}

/* Responsive Media Queries */
@media (max-width: 900px) {
  .app-sidebar {
    transform: translateX(-100%);
    box-shadow: none;
    z-index: var(--z-sidebar, 90);
  }

  .app-sidebar.open {
    transform: translateX(0);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
  }

  .sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(4px);
    z-index: var(--z-sidebar-backdrop, 80);
    opacity: 0;
    transition: opacity var(--transition-normal);
  }

  .sidebar-backdrop.open {
    display: block;
    opacity: 1;
  }

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

  .app-main {
    margin-left: 0;
    width: 100%;
    padding-bottom: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom));
  }

  .app-header {
    padding: 0 1rem;
    height: 60px;
  }

  .content-viewport {
    padding: 1.25rem 1rem;
  }

  .mobile-bottom-nav {
    display: flex;
  }

  .btn-header-add {
    display: none;
  }

  .role-switcher-label span {
    display: none;
  }
}

@media (max-width: 640px) {
  .app-header {
    gap: 0.5rem;
    padding: 0 0.75rem;
  }

  .header-left {
    flex: 1;
    min-width: 0;
    gap: 0.5rem;
  }

  .header-family-selector {
    min-width: 0;
    max-width: 100%;
    padding: 0.4rem 0.625rem;
  }

  .header-family-name {
    display: block;
    min-width: 0;
    max-width: 145px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .header-right {
    flex-shrink: 0;
    gap: 0.375rem;
  }

  .role-switcher-container {
    display: none;
  }

  .content-viewport {
    min-width: 0;
    padding: 1rem 0.75rem;
    overflow-x: hidden;
  }

  .mobile-bottom-nav {
    height: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom));
    padding: 0 0.125rem env(safe-area-inset-bottom);
  }

  .bottom-nav-item {
    min-width: 0;
    font-size: 0.625rem;
  }

  .bottom-nav-item svg {
    width: 20px;
    height: 20px;
  }
}

@media (max-width: 400px) {
  .header-family-name {
    max-width: 118px;
    font-size: 0.8125rem;
  }

  .content-viewport {
    padding-inline: 0.625rem;
  }
}

/* ==========================================================================
   ELEGANT MOBILE MENU & BOTTOM SHEET STYLING
   ========================================================================== */
.mobile-nav-sheet-wrapper {
  display: flex;
  flex-direction: column;
  gap: 1.15rem;
  padding: 0.25rem 0 0.5rem 0;
}

/* Profile Header Card in Sheet */
.mobile-nav-sheet-profile {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  padding: 0.875rem 1rem;
  background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
  border: 1px solid #e2e8f0;
  border-radius: 16px;
  position: relative;
  overflow: hidden;
}

.mobile-nav-sheet-profile::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 90px;
  height: 100%;
  background: radial-gradient(circle at right, rgba(5, 150, 105, 0.08), transparent 70%);
  pointer-events: none;
}

.mobile-sheet-avatar {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--color-primary-600, #059669), var(--color-primary-700, #047857));
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.125rem;
  box-shadow: 0 4px 10px rgba(5, 150, 105, 0.25);
  flex-shrink: 0;
}

.mobile-sheet-user-info {
  flex: 1;
  min-width: 0;
}

.mobile-sheet-user-name {
  font-size: 0.9375rem;
  font-weight: 800;
  color: var(--color-slate-900, #0f172a);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.25;
}

.mobile-sheet-user-sub {
  font-size: 0.75rem;
  color: var(--color-slate-500, #64748b);
  margin-top: 3px;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.mobile-sheet-badge-pro {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 0.65rem;
  font-weight: 800;
  background: #fef3c7;
  color: #92400e;
  padding: 2px 7px;
  border-radius: 9999px;
  border: 1px solid #fde68a;
  letter-spacing: 0.02em;
}

/* Section Header */
.mobile-nav-sheet-section-title {
  font-size: 0.6875rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #64748b;
  margin-bottom: 0.625rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.mobile-nav-sheet-section-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: #e2e8f0;
}

/* Features Grid - 2 Columns (AI & Scanner) */
.mobile-sheet-features-grid {
  display: grid !important;
  grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  gap: 0.625rem !important;
}

.mobile-sheet-feature-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 0.85rem;
  border-radius: 14px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  border: 1px solid #e2e8f0;
  background: white;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  position: relative;
  overflow: hidden;
}

.mobile-sheet-feature-card:active {
  transform: scale(0.97);
}

.mobile-sheet-feature-card.card-ai {
  background: linear-gradient(135deg, #faf5ff 0%, #f3e8ff 100%);
  border-color: #e9d5ff;
}

.mobile-sheet-feature-card.card-scan {
  background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
  border-color: #bfdbfe;
}

.mobile-sheet-feature-icon {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
}

.mobile-sheet-feature-info {
  flex: 1;
  min-width: 0;
}

.mobile-sheet-feature-title {
  font-size: 0.8125rem;
  font-weight: 800;
  color: var(--color-slate-900, #0f172a);
  line-height: 1.2;
}

.mobile-sheet-feature-desc {
  font-size: 0.6875rem;
  color: var(--color-slate-500, #64748b);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Nav Grid - 4 Columns */
.mobile-nav-sheet-grid {
  display: grid !important;
  grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
  gap: 0.65rem 0.25rem !important;
  padding: 0 !important;
  margin: 0 !important;
}

.mobile-nav-sheet-item {
  display: flex !important;
  flex-direction: column !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 0.5rem 0.2rem !important;
  border-radius: 14px !important;
  background: transparent !important;
  cursor: pointer !important;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1) !important;
  user-select: none !important;
  -webkit-tap-highlight-color: transparent !important;
  text-decoration: none !important;
  position: relative !important;
  border: 1px solid transparent !important;
}

.mobile-nav-sheet-item:hover,
.mobile-nav-sheet-item:active {
  background: #f8fafc !important;
  border-color: #f1f5f9 !important;
  transform: translateY(-2px) scale(0.97) !important;
}

.mobile-nav-sheet-item.is-active {
  background: #ecfdf5 !important;
  border-color: #a7f3d0 !important;
}

.mobile-nav-sheet-icon {
  width: 50px !important;
  height: 50px !important;
  min-width: 50px !important;
  min-height: 50px !important;
  max-width: 50px !important;
  max-height: 50px !important;
  border-radius: 16px !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  margin: 0 auto 0.4rem auto !important;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.04) !important;
  transition: all 0.2s ease !important;
  flex-shrink: 0 !important;
}

.mobile-nav-sheet-item:hover .mobile-nav-sheet-icon,
.mobile-nav-sheet-item:active .mobile-nav-sheet-icon {
  transform: scale(1.06) !important;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.08) !important;
}

.mobile-nav-sheet-label {
  font-size: 0.75rem !important;
  font-weight: 700 !important;
  color: #334155 !important;
  line-height: 1.2 !important;
  text-align: center !important;
  white-space: nowrap !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
  max-width: 100% !important;
  padding: 0 2px !important;
}

.mobile-nav-sheet-item.is-active .mobile-nav-sheet-label {
  color: #059669 !important;
}

/* Logout Button in Sheet */
.mobile-sheet-logout-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  background: #fef2f2;
  border: 1px solid #fee2e2;
  color: #dc2626;
  font-size: 0.8125rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  font-family: inherit;
}

.mobile-sheet-logout-btn:active {
  background: #fee2e2;
  transform: scale(0.98);
}

