/* ==========================================================================
   Global CSS - Only global resets, variables, and screen container
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --font-inter: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --color-primary: #5170FF;
  --footer-height: 58px;
  --mobile-max-width: 480px;
  --bg-page: #f8fafc;
  --bg-app: #ffffff;
  --text-main: #111827;
  --text-secondary: #374151; /* Darker secondary text for maximum contrast and legibility */
  --text-muted: #4b5563; /* Darker muted secondary label text */
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  font-family: var(--font-inter);
  background-color: var(--bg-page);
  color: var(--text-main);
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden; /* Lock root document to prevent mobile Chrome URL bar collapse */
  position: fixed;
  width: 100%;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  justify-content: center;
  align-items: stretch;
}

/* Mobile container matching desktop to mobile viewport */
.app-container {
  width: 100%;
  max-width: var(--mobile-max-width);
  height: 100%;
  height: 100dvh;
  background-color: var(--bg-app);
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.05);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow-y: auto; /* Internal scroll container */
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  /* Space for lifted pinned footer at the bottom */
  padding-bottom: calc(var(--footer-height) + 24px + env(safe-area-inset-bottom, 0px));
}

/* Desktop Adaptability (Docked Left Sidebar & Hidden Bottom Sheet on Desktop) */
@media (min-width: 768px) {
  :root {
    --mobile-max-width: 1200px;
  }

  html, body {
    position: relative !important;
    height: auto !important;
    min-height: 100vh !important;
    max-height: none !important;
    overflow-y: auto !important;
    background-color: #f8fafc;
  }

  body {
    display: flex !important;
    flex-direction: row !important;
    justify-content: flex-start !important;
    align-items: flex-start !important;
  }

  /* 1. Hide bottom navigation sheet and gradient backdrop on desktop */
  .pinned-footer,
  .pinned-footer-backdrop {
    display: none !important;
  }

  /* 2. Hide top-right hamburger icon on desktop */
  .app-header-right {
    display: none !important;
  }

  /* 3. Dock Sidebar permanently on Desktop Left Side (240px wide) */
  .app-sidebar-overlay {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    transform: none !important;
    width: 240px !important;
    max-width: 240px !important;
    height: 100vh !important;
    display: block !important;
    pointer-events: auto !important;
    z-index: 100 !important;
  }

  .app-sidebar-backdrop {
    display: none !important;
  }

  .app-sidebar-drawer {
    position: relative !important;
    width: 240px !important;
    max-width: 240px !important;
    height: 100vh !important;
    transform: translateX(0) !important;
    box-shadow: none !important;
    border-right: 1px solid #e5e7eb !important;
  }

  /* 4. Position main app container to the right of the docked 240px sidebar */
  .app-container {
    margin-left: 240px !important;
    width: calc(100% - 240px) !important;
    max-width: 1200px !important;
    min-height: 100vh;
    height: auto;
    overflow-y: visible !important;
    padding-bottom: 24px !important; /* No extra padding for bottom navigation */
    box-shadow: none !important;
    border-left: none !important;
  }
}

/* Main screen: shows switch on top if category page, and title below */
.main-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  padding: 0;
}

.switch-wrapper {
  position: sticky;
  top: 54px;
  z-index: 45;
  background-color: #ffffff;
  height: 56px;
  min-height: 56px;
  max-height: 56px;
  padding: 10px 16px;
  margin-bottom: 0px;
  border-bottom: 1px solid #f1f5f9;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.switch-wrapper:empty {
  display: none;
}

.screen-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  width: 100%;
}

.screen-placeholder {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 200px;
}

.main-screen-title {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text-main);
  text-align: center;
  transition: opacity 0.15s ease, transform 0.15s ease;
}

/* ==========================================================================
   Smooth App Loading Screen
   ========================================================================== */
.app-loader {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  background-color: #ffffff;
  z-index: 99999;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 1;
  visibility: visible;
  transition: opacity 1.3s cubic-bezier(0.16, 1, 0.3, 1), visibility 1.3s cubic-bezier(0.16, 1, 0.3, 1);
  user-select: none;
  -webkit-user-select: none;
}

.app-loader.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.loader-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  box-sizing: border-box;
}

.loader-badge {
  width: 90px;
  height: 90px;
  border-radius: 22px;
  background-color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  box-sizing: border-box;
  border: 1px solid rgba(0, 0, 0, 0.04);
  box-shadow: 0 16px 36px -6px rgba(0, 0, 0, 0.08), 0 4px 16px rgba(81, 112, 255, 0.07);
  animation: loader-badge-pulse 2.2s ease-in-out infinite;
}

.loader-logo-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 12px;
  display: block;
}

.loader-title {
  margin: 20px 0 0 0;
  font-family: var(--font-inter, 'Inter', -apple-system, BlinkMacSystemFont, sans-serif);
  font-size: 26px;
  font-weight: 800;
  color: #111827;
  letter-spacing: -0.4px;
  line-height: 1.2;
}

.loader-spinner {
  margin-top: 24px;
  width: 24px;
  height: 24px;
  border: 2.5px solid rgba(81, 112, 255, 0.16);
  border-top-color: #5170FF;
  border-radius: 50%;
  animation: loader-spin 0.75s linear infinite;
}

@keyframes loader-spin {
  to { transform: rotate(360deg); }
}

@keyframes loader-badge-pulse {
  0%, 100% {
    transform: scale(1);
    box-shadow: 0 16px 36px -6px rgba(0, 0, 0, 0.08), 0 4px 16px rgba(81, 112, 255, 0.07);
  }
  50% {
    transform: scale(1.025);
    box-shadow: 0 20px 42px -6px rgba(0, 0, 0, 0.11), 0 6px 20px rgba(81, 112, 255, 0.12);
  }
}

/* ==========================================================================
   Floating Action Buttons (FAB) - Pinned 8px corner radius at bottom right
   ========================================================================== */
.floating-add-btn {
  position: fixed;
  bottom: calc(78px + env(safe-area-inset-bottom, 0px));
  right: calc(18px + env(safe-area-inset-right, 0px));
  z-index: 1005; /* Above gradient backdrop (z-index 990) so gradient never covers buttons */
  background-color: var(--color-primary, #5170FF);
  color: #ffffff;
  border: none;
  border-radius: 8px; /* Strict 8px corner radius requirement */
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(81, 112, 255, 0.4), 0 2px 6px rgba(0, 0, 0, 0.1);
  transition: transform 0.15s ease, background-color 0.15s ease, box-shadow 0.15s ease;
  font-family: var(--font-inter, 'Inter', sans-serif);
  font-size: 13.5px;
  font-weight: 600;
  padding: 10px 16px;
  outline: none;
}

.floating-add-btn.floating-icon-only {
  width: 44px;
  height: 44px;
  padding: 0;
}

.floating-add-btn:hover {
  background-color: #3b5bdb;
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(81, 112, 255, 0.5);
}

.floating-add-btn:active {
  transform: translateY(0);
}
