/* ============================================
   FINANCE SUITE — App Layout (Shell)
   ============================================ */

.app-shell {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  background: var(--bg-app);
}

/* ---- Sidebar (Liquid Glass) ---- */
.sidebar {
  width: var(--sidebar-width);
  height: 100%;
  background: var(--bg-surface);
  backdrop-filter: blur(var(--glass-blur)) saturate(1.5);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(1.5);
  border-right: 1px solid var(--glass-border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform var(--transition-base);
  z-index: var(--z-sticky);
}

.sidebar-brand {
  height: var(--header-height);
  display: flex;
  align-items: center;
  padding: 0 var(--space-5);
  border-bottom: 1px solid var(--border-subtle);
}

.sidebar-brand-icon {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #007AFF, #5856D6);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: var(--space-3);
  box-shadow: 0 3px 10px rgba(0, 122, 255, 0.25);
}

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

.sidebar-brand-text {
  display: flex;
  flex-direction: column;
}

.sidebar-brand-name {
  font-size: var(--text-md);
  font-weight: var(--weight-bold);
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.sidebar-brand-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: var(--weight-semibold);
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-5) var(--space-3);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar-section-title {
  font-size: 11px;
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin: var(--space-4) 0 var(--space-2) var(--space-3);
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  transition: all var(--transition-fast);
}

.sidebar-link svg {
  width: 18px;
  height: 18px;
  color: var(--text-muted);
  transition: color var(--transition-fast);
}

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

.sidebar-link:hover svg {
  color: var(--text-primary);
}

.sidebar-link.active {
  background: var(--accent-muted);
  color: var(--accent);
  font-weight: var(--weight-semibold);
}

.sidebar-link.active svg {
  color: var(--accent);
}

.sidebar-user {
  padding: var(--space-4);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.sidebar-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: var(--bg-surface-hover);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: var(--weight-bold);
  font-size: var(--text-sm);
  border: 1px solid var(--border-primary);
}

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

.sidebar-user-name {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-email {
  font-size: var(--text-xs);
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-logout {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  transition: all var(--transition-fast);
}

.sidebar-logout:hover {
  background: var(--color-danger-muted);
  color: var(--color-danger);
}

/* ---- Main Content ---- */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.page-header {
  height: var(--header-height);
  padding: 0 var(--space-8);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: transparent;
  border-bottom: 1px solid transparent;
  flex-shrink: 0;
}

.page-header-left {
  display: flex;
  flex-direction: column;
}

.page-title {
  font-size: var(--text-xl);
  font-weight: var(--weight-bold);
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

.page-subtitle {
  font-size: var(--text-sm);
  color: var(--text-muted);
}

.page-header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.page-body {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-6) var(--space-8) var(--space-12) var(--space-8);
}

/* ---- Mobile Menu Overlay ---- */
.mobile-menu-toggle {
  display: none;
  position: fixed;
  bottom: calc(var(--space-6) + env(safe-area-inset-bottom, 0px));
  right: var(--space-6);
  width: 52px;
  height: 52px;
  border-radius: var(--radius-pill);
  background: linear-gradient(135deg, #007AFF, #5856D6);
  color: white;
  z-index: 1000;
  box-shadow: 0 4px 20px rgba(0, 122, 255, 0.35);
  align-items: center;
  justify-content: center;
  border: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: transform var(--transition-spring);
}

.mobile-menu-toggle:active {
  transform: scale(0.92);
}

.mobile-menu-toggle svg {
  width: 24px;
  height: 24px;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: calc(var(--z-sticky) - 1);
  opacity: 0;
  transition: opacity var(--transition-base);
}

/* ---- Responsive: Tablet ---- */
@media (max-width: 1024px) {
  .page-header { padding: 0 var(--space-6); }
  .page-body { padding: var(--space-6); }
  .grid-stats { grid-template-columns: repeat(2, 1fr) !important; }
  .grid-3 { grid-template-columns: repeat(2, 1fr) !important; }
}

/* ---- Responsive: Mobile (iPhone) ---- */
@media (max-width: 768px) {
  /* Safe area for notch/dynamic island */
  body {
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  /* Sidebar drawer */
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-100%);
    width: 280px;
    height: 100vh;
    z-index: 1100;
  }
  .sidebar.open {
    transform: translateX(0);
  }

  /* Mobile menu FAB */
  .mobile-menu-toggle {
    display: flex;
  }

  /* Overlay */
  .sidebar-overlay.visible {
    display: block;
    opacity: 1;
  }

  /* Page layout */
  .page-header {
    padding: 0 var(--space-4);
    height: auto;
    min-height: 48px;
    padding-top: var(--space-3);
    padding-bottom: var(--space-3);
    flex-wrap: wrap;
    gap: var(--space-3);
  }

  .page-body {
    padding: var(--space-4);
    padding-bottom: calc(var(--space-12) + 56px + env(safe-area-inset-bottom, 0px));
  }

  /* Grids → single column on mobile */
  .grid-stats {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: var(--space-3) !important;
  }
  .grid-2, .grid-3, .dashboard-lists {
    grid-template-columns: 1fr !important;
    gap: var(--space-4) !important;
  }

  /* Stat cards smaller on mobile */
  .stat-card {
    padding: var(--space-4) !important;
  }
  .stat-card-value {
    font-size: var(--text-lg) !important;
  }

  /* Cards responsive */
  .card {
    padding: var(--space-4);
  }

  /* Tabs scroll horizontally */
  .tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    scrollbar-width: none;
    gap: var(--space-4);
  }
  .tabs::-webkit-scrollbar { display: none; }

  /* Tables horizontal scroll */
  .table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  .data-table {
    min-width: 600px;
  }

  /* Forms — bigger touch targets */
  .form-input, .form-select, .form-textarea {
    min-height: 48px;
    font-size: 16px !important; /* Prevents iOS zoom on focus */
    padding: var(--space-3) var(--space-4);
  }

  /* Buttons — touch friendly */
  .btn {
    min-height: 44px;
    padding: var(--space-3) var(--space-5);
    font-size: var(--text-sm);
  }
  .btn-sm {
    min-height: 36px;
    padding: var(--space-2) var(--space-3);
  }

  /* Auth screen mobile */
  .auth-card {
    margin: var(--space-4);
    max-width: calc(100vw - var(--space-8));
    padding: var(--space-6) var(--space-5);
  }

  /* Modal full-width on mobile */
  .modal-content {
    max-width: calc(100vw - var(--space-8));
    max-height: calc(100vh - var(--space-12));
    margin: var(--space-4);
    border-radius: var(--radius-xl);
  }

  /* Page title smaller on mobile */
  .page-title {
    font-size: var(--text-lg);
  }
  .page-subtitle {
    font-size: var(--text-xs);
  }

  /* Hide page header actions text, show only icons */
  .page-header-actions .btn span {
    display: none;
  }
}

/* ---- Small phones (SE, etc.) ---- */
@media (max-width: 380px) {
  .grid-stats {
    grid-template-columns: 1fr !important;
  }
  .stat-card-value {
    font-size: var(--text-base) !important;
  }
  .page-body {
    padding: var(--space-3);
  }
}
