/* ========================================
   UNIFY.PRO — Layout System
   App shell, navigation, responsive
   ======================================== */

/* ---- App Shell ---- */
.app-shell {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--background);
  position: relative;
}

/* ---- Page Content ---- */
#page-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding-bottom: 80px;
  animation: fadeIn 200ms ease;
}

/* ---- Page Headers ---- */
.page-header {
  padding: 40px 24px 8px;
}
.page-header-compact {
  padding: 16px 24px;
}
.page-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}
.page-title {
  font: var(--headline-medium);
  font-weight: 700;
  color: var(--on-background);
}
.page-subtitle {
  font: var(--title-medium);
  color: var(--primary);
}

/* ---- Section Titles ---- */
.section-title {
  font: var(--title-large);
  font-weight: 700;
  color: var(--on-background);
  padding: 16px 0;
}
.section-padding {
  padding: 0 20px;
}

/* ---- Bottom Navigation ---- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 6px 0;
  box-shadow: 0 -2px 12px rgba(36,42,55,0.06);
  z-index: 100;
  
  /* Glassmorphism by default */
  background: rgba(255, 255, 255, 0.72) !important;
  backdrop-filter: blur(20px) saturate(190%) !important;
  -webkit-backdrop-filter: blur(20px) saturate(190%) !important;
  border-top: 1px solid rgba(255, 255, 255, 0.15);
}

.dark-theme .bottom-nav {
  background: rgba(32, 38, 50, 0.75) !important;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 16px;
  cursor: pointer;
  transition: all var(--transition-fast);
  border-radius: var(--radius-md);
  position: relative;
  background: none;
  border: none;
  color: var(--on-surface-variant);
  min-width: 56px;
}
.nav-item:hover { color: var(--primary); }
.nav-item.active { color: var(--primary); }
.nav-item.active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 48px;
  height: 32px;
  background: var(--primary-container);
  border-radius: var(--radius-lg);
  z-index: -1;
}
.nav-item .material-symbols-outlined { font-size: 24px; }
.nav-item-label { font: var(--label-small); }

/* ---- Top Bar for sub-screens ---- */
.top-bar {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: 16px 24px;
  z-index: 90;
  
  /* Glassmorphism */
  background: rgba(255, 255, 255, 0.75) !important;
  backdrop-filter: blur(20px) saturate(190%) !important;
  -webkit-backdrop-filter: blur(20px) saturate(190%) !important;
  box-shadow: var(--shadow-sm);
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}

.dark-theme .top-bar {
  background: rgba(32, 38, 50, 0.75) !important;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.top-bar-title {
  font: var(--headline-medium);
  font-weight: 700;
  flex: 1;
}

/* ---- Content sections ---- */
.content-section {
  padding: 0 20px;
}
.content-section + .content-section {
  margin-top: var(--space-md);
}

/* ---- Grid Layouts ---- */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-md);
}
.grid-3 {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: var(--space-md);
}
.grid-4 {
  display: flex;
  justify-content: space-between;
}

/* ---- Flex Utilities ---- */
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.gap-xs { gap: var(--space-xs); }
.gap-sm { gap: var(--space-sm); }
.gap-md { gap: var(--space-md); }
.gap-lg { gap: var(--space-lg); }
.gap-xl { gap: var(--space-xl); }

/* ---- Spacing Utilities ---- */
.p-md { padding: var(--space-md); }
.p-lg { padding: var(--space-lg); }
.px-lg { padding-left: var(--space-lg); padding-right: var(--space-lg); }
.py-md { padding-top: var(--space-md); padding-bottom: var(--space-md); }
.mt-xs { margin-top: var(--space-xs); }
.mt-sm { margin-top: var(--space-sm); }
.mt-md { margin-top: var(--space-md); }
.mt-lg { margin-top: var(--space-lg); }
.mb-md { margin-bottom: var(--space-md); }
.mb-lg { margin-bottom: var(--space-lg); }
.w-full { width: 100%; }

/* ---- List items ---- */
.list-item {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-md);
  cursor: pointer;
  transition: background var(--transition-fast);
  border-radius: var(--radius-xl);
}
.list-item:hover { background: rgba(36,42,55,0.03); }
.list-item-content { flex: 1; min-width: 0; }
.list-item-title { font: var(--body-large); font-weight: 700; }
.list-item-subtitle { font: var(--body-medium); color: gray; }
.list-item-trailing { text-align: right; }

/* ---- Modal Overlay ---- */
#modal-container {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: none;
}
#modal-container.active { display: flex; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(4px);
  animation: fadeIn 200ms ease;
  z-index: 200;
}

.modal-dialog {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  border-radius: var(--radius-2xl) var(--radius-2xl) 0 0;
  animation: slideUp 300ms cubic-bezier(0.4, 0, 0.2, 1);
  z-index: 201;
  display: flex;
  flex-direction: column;
  
  /* Glassmorphism */
  background: rgba(255, 255, 255, 0.8) !important;
  backdrop-filter: blur(20px) saturate(190%) !important;
  -webkit-backdrop-filter: blur(20px) saturate(190%) !important;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.dark-theme .modal-dialog {
  background: rgba(32, 38, 50, 0.8) !important;
  border: 1px solid rgba(255, 255, 255, 0.05);
}
.modal-header {
  padding: 24px 24px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-title {
  font: var(--title-large);
  font-weight: 700;
}
.modal-body {
  padding: 0 24px 16px;
  overflow-y: auto;
  flex: 1;
}
.modal-footer {
  padding: 12px 24px 24px;
  display: flex;
  gap: var(--space-sm);
  justify-content: flex-end;
  border-top: 1px solid rgba(36,42,55,0.06);
}

/* ---- Toast Container ---- */
#toast-container {
  position: fixed;
  bottom: 96px;
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 32px);
  max-width: 448px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  pointer-events: none;
}
.toast {
  background: var(--dark-navy);
  color: white;
  padding: 14px 20px;
  border-radius: var(--radius-md);
  font: var(--body-medium);
  box-shadow: var(--shadow-xl);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-md);
  animation: toastIn 300ms cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: auto;
}
.toast.hiding { animation: toastOut 300ms cubic-bezier(0.4, 0, 0.2, 1); }
.toast-action {
  color: var(--sage-green);
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.sidebar-logo-container {
  display: none;
}
.sidebar-footer-theme {
  display: none;
}
/* Secondary sidebar tabs (Clients, Bureautique, Forum, Support) — PC only */
.nav-item-secondary {
  display: none;
}
.sidebar-divider {
  display: none;
}

/* ---- Responsive ---- */
@media (min-width: 481px) {
  .app-shell {
    border-left: 1px solid var(--surface-variant);
    border-right: 1px solid var(--surface-variant);
    box-shadow: 0 0 40px rgba(36,42,55,0.08);
  }
}

@media (min-width: 768px) {
  /* PC Layout */
  .app-shell {
    max-width: 100%;
    width: 100%;
    margin: 0;
    flex-direction: row;
    border: none;
    box-shadow: none;
  }

  /* Page Content occupies remaining space and centered max-width */
  #page-content {
    margin-left: 240px;
    padding: 40px 48px !important;
    width: calc(100% - 240px);
    max-width: 1200px;
  }

  /* Bottom Nav turns into Sidebar Nav */
  .bottom-nav {
    display: flex !important; /* Sidebar stays persistent on every screen, incl. sub-screens */
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 240px;
    max-width: 240px;
    height: 100vh;
    transform: none;
    flex-direction: column;
    justify-content: flex-start;
    align-items: flex-start;
    padding: 24px 16px;
    gap: 8px;
    overflow-y: auto;
    box-shadow: 2px 0 12px rgba(36,42,55,0.06);

    /* Glassmorphism sidebar */
    background: rgba(255, 255, 255, 0.72) !important;
    backdrop-filter: blur(20px) saturate(190%) !important;
    -webkit-backdrop-filter: blur(20px) saturate(190%) !important;
    border-right: 1px solid rgba(0, 0, 0, 0.05);
    border-top: none !important;
  }

  /* Reveal secondary tabs + divider in the PC sidebar */
  .nav-item-secondary {
    display: flex !important;
  }
  .sidebar-divider {
    display: block;
    width: 100%;
    height: 1px;
    background: var(--surface-variant);
    margin: 8px 0;
    flex-shrink: 0;
  }

  .dark-theme .bottom-nav {
    background: rgba(32, 38, 50, 0.72) !important;
    border-right: 1px solid rgba(255, 255, 255, 0.05);
  }

  .sidebar-logo-container {
    display: block !important;
    width: 100%;
    padding: 0 12px 24px;
    border-bottom: 1px solid var(--surface-variant);
    margin-bottom: 16px;
  }

  .sidebar-footer-theme {
    display: block !important;
    margin-top: auto;
    width: 100%;
    padding-top: 16px;
    border-top: 1px solid var(--surface-variant);
  }
  
  .sidebar-logo {
    height: 40px;
    object-fit: contain;
  }

  .nav-item {
    flex-direction: row !important;
    width: 100%;
    padding: 12px 16px;
    gap: 12px;
    border-radius: var(--radius-md);
    justify-content: flex-start;
    min-width: unset;
  }

  .nav-item.active::before {
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 100%;
    height: 100%;
  }

  .nav-item-label {
    font: var(--body-large) !important;
    font-weight: 600 !important;
  }

  /* Center Modals on PC */
  .modal-dialog {
    position: fixed;
    top: 50% !important;
    bottom: auto !important;
    left: 50%;
    transform: translate(-50%, -50%) !important;
    max-width: 600px;
    width: 90%;
    border-radius: var(--radius-2xl) !important;
    box-shadow: var(--shadow-xl);
    animation: scaleIn 250ms cubic-bezier(0.4, 0, 0.2, 1) !important;
  }
  
  .modal-dialog.modal-wide {
    max-width: 800px;
  }

  /* Center Toasts on PC */
  #toast-container {
    bottom: 24px;
    right: 24px;
    left: auto;
    transform: none;
    width: 350px;
  }

  /* Make grids and sections look better on wide screens */
  .grid-2 {
    grid-template-columns: repeat(2, 1fr);
  }
  .grid-3 {
    grid-template-columns: repeat(3, 1fr);
  }
  .grid-4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-md);
  }

  /* FAB button position on PC */
  .btn-fab {
    bottom: 32px;
    right: 32px;
  }
  
  .btn-fab-secondary {
    bottom: 110px;
    right: 32px;
  }

  /* ---- Dashboard Harmonization ---- */
  /* 1. Hide the duplicate header logo on Dashboard */
  .dashboard-logo {
    display: none !important;
  }
  
  .dashboard-header {
    justify-content: flex-end !important;
    padding: 0 0 16px 0 !important;
  }

  /* 2. Format 3 stat cards on a single row */
  .stats-section > .flex-col {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr) !important;
    gap: var(--space-lg) !important;
  }

  .stats-section > .flex-col > .grid-2 {
    display: contents !important;
  }

  /* Make all stats cards horizontal and consistent on PC */
  .stats-section .stat-card {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    gap: var(--space-md) !important;
    padding: 24px !important;
    height: 100% !important;
  }

  .stats-section .stat-card .icon-box {
    width: 56px !important;
    height: 56px !important;
    padding: 0 !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
  }

  .stats-section .stat-card .stat-value {
    font-size: 24px !important;
    margin-top: 4px;
  }

  .stats-section .stat-card .stat-label {
    font-size: 14px !important;
  }

  /* 3. Harmonize Quick Actions: turning them into rich cards */
  #quick-actions-row {
    display: grid !important;
    grid-template-columns: repeat(4, 1fr) !important;
    gap: var(--space-lg) !important;
  }

  .quick-action {
    flex-direction: row !important;
    background: var(--surface);
    border-radius: var(--radius-xl);
    padding: 16px 20px !important;
    box-shadow: var(--shadow-sm);
    gap: 16px !important;
    width: 100%;
    justify-content: flex-start;
    border: 1px solid rgba(0,0,0,0.03);
  }

  .quick-action:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
  }

  .quick-action-icon {
    box-shadow: none !important;
    width: 48px !important;
    height: 48px !important;
  }

  .quick-action-icon-inner {
    width: 40px !important;
    height: 40px !important;
  }

  .quick-action-label {
    font: var(--title-medium) !important;
    font-weight: 700 !important;
    color: var(--on-surface) !important;
  }

  /* ---- Sub-screens Header Top Bar Harmonization ---- */
  .top-bar {
    padding: 24px 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    border-bottom: 1px solid var(--surface-variant);
    margin-bottom: 24px;
  }

  /* ---- Tasks / Planning Day Selector Harmonization ---- */
  .day-strip {
    justify-content: flex-start !important;
    gap: 16px !important;
  }

  .day-card {
    width: 80px !important;
    height: 90px !important;
    flex-shrink: 0;
  }
}

/* Header Buttons styling (independent of hardcoded backgrounds) */
.header-btn {
  border-radius: 50% !important;
  border: 1.5px solid var(--surface-variant) !important;
  background: var(--surface) !important;
  color: var(--on-surface) !important;
  box-shadow: var(--shadow-sm) !important;
}

.header-btn:hover {
  background: var(--surface-variant) !important;
  border-color: var(--primary) !important;
}

/* Invert Logo color in dark mode */
.dark-theme .sidebar-logo,
.dark-theme .dashboard-logo {
  filter: brightness(0) invert(1) !important;
  opacity: 0.95 !important;
}


