/* ==========================================================================
   HAQI FINANCE - LAYOUT & RESPONSIVE ARCHITECTURE
   ========================================================================== */

/* App Container */
.app-layout {
  display: flex;
  min-height: 100vh;
  position: relative;
}

/* SIDEBAR (DESKTOP) */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-surface);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 90;
  transition: transform var(--transition-normal), background-color var(--transition-normal);
  overflow-x: hidden;
}

.sidebar-brand {
  padding: 20px 18px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border-subtle);
  position: relative;
}

.brand-icon-wrapper {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--forest-primary), var(--leaf-green));
  color: var(--text-white);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  box-shadow: 0 4px 12px rgba(45, 106, 79, 0.25);
  flex-shrink: 0;
}

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

.brand-info h1 {
  font-size: 18px;
  line-height: 1.2;
  color: var(--forest-dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

[data-theme="dark"] .brand-info h1 {
  color: var(--soft-sage);
}

.brand-info p {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
  letter-spacing: 0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-close-sidebar {
  display: none;
  background: transparent;
  border: none;
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.btn-close-sidebar:hover {
  background: var(--bg-surface-alt);
  color: var(--forest-dark);
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
}

.nav-section-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: var(--text-subtle);
  padding: 12px 14px 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 16px;
  border-radius: var(--radius-md);
  color: var(--text-body);
  text-decoration: none;
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
  min-width: 0;
}

.nav-link span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.nav-link i {
  width: 20px;
  height: 20px;
  color: var(--text-muted);
  transition: color var(--transition-fast);
  flex-shrink: 0;
}

.nav-link:hover {
  background: var(--bg-surface-alt);
  color: var(--forest-dark);
}

[data-theme="dark"] .nav-link:hover {
  color: var(--text-white);
}

.nav-link:hover i {
  color: var(--leaf-green);
}

.nav-link.active {
  background: var(--forest-primary);
  color: var(--text-white);
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(27, 67, 50, 0.2);
}

.nav-link.active i {
  color: var(--muted-gold);
}

.nav-badge {
  margin-left: auto;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: var(--radius-full);
  background: rgba(233, 196, 106, 0.2);
  color: var(--muted-gold);
  font-weight: 700;
}

/* Sidebar Footer / Companion Card */
.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-x: hidden;
}

.companion-mini-card {
  background: linear-gradient(135deg, rgba(82, 183, 136, 0.12), rgba(233, 196, 106, 0.12));
  border: 1px dashed var(--soft-sage);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: transform var(--transition-fast);
  min-width: 0;
  overflow: hidden;
}

.companion-mini-card:hover {
  transform: translateY(-2px);
}

.companion-avatar {
  font-size: 22px;
  flex-shrink: 0;
}

.companion-text {
  min-width: 0;
  flex: 1;
}

.companion-text h5 {
  font-size: 12.5px;
  color: var(--forest-dark);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

[data-theme="dark"] .companion-text h5 {
  color: var(--soft-sage);
}

.companion-text p {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-theme-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface-alt);
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  border: none;
  width: 100%;
  min-width: 0;
  overflow: hidden;
}

.sidebar-actions-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 2px;
  width: 100%;
}

.sidebar-actions-grid .btn {
  font-size: 10px;
  padding: 5px 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  width: 100%;
}

.sidebar-actions-grid .btn i {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
}

.sidebar-actions-grid .btn span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* MAIN CONTENT WRAPPER */
.main-wrapper {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background-color: transparent;
}

/* TOPBAR / HEADER */
.topbar {
  height: var(--header-height);
  padding: 0 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(251, 249, 244, 0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  transition: background-color var(--transition-normal);
}

[data-theme="dark"] .topbar {
  background: rgba(18, 26, 21, 0.88);
}

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

.menu-toggle-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-heading);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
}

.topbar-greeting {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
}

.topbar-greeting h2 {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-greeting p {
  font-size: 11.5px;
  color: var(--text-muted);
  margin: 2px 0 0 0;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.period-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  padding: 6px 14px;
  border-radius: var(--radius-full);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--forest-dark);
  box-shadow: var(--shadow-sm);
}

[data-theme="dark"] .period-pill {
  color: var(--soft-sage);
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-body);
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
}

.icon-btn:hover {
  background: var(--bg-surface-alt);
  color: var(--leaf-green);
  border-color: var(--soft-sage);
}

.notification-dot {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 8px;
  height: 8px;
  background: var(--terracotta);
  border-radius: 50%;
  border: 2px solid var(--bg-surface);
}

.btn-quick-add {
  display: flex;
  align-items: center;
  gap: 8px;
  background: linear-gradient(135deg, var(--botanical-green), var(--forest-primary));
  color: var(--text-white);
  border: none;
  padding: 9px 18px;
  border-radius: var(--radius-full);
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(45, 106, 79, 0.25);
  transition: all var(--transition-fast);
}

.btn-quick-add:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(45, 106, 79, 0.35);
  background: linear-gradient(135deg, var(--leaf-green), var(--botanical-green));
}

.user-avatar-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  padding: 4px 12px 4px 4px;
  border-radius: var(--radius-full);
  font-size: 13px;
  font-weight: 600;
}

.user-avatar-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, #FFE8D6, #DDBEA9);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}

/* MAIN VIEW CONTAINER */
.page-container {
  flex: 1;
  padding: 28px 32px 60px;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

.view-section {
  display: none;
  animation: fadeInScale 0.35s ease forwards;
}

.view-section.active {
  display: block;
}

/* MOBILE BOTTOM NAVIGATION */
.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bottom-nav-height);
  background: var(--bg-surface);
  border-top: 1px solid var(--border-color);
  z-index: 100;
  box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.05);
  padding: 0 12px;
  justify-content: space-around;
  align-items: center;
}

.mobile-nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 10.5px;
  font-weight: 500;
  cursor: pointer;
  background: none;
  border: none;
  padding: 4px 4px;
  transition: color var(--transition-fast);
  white-space: nowrap;
  min-width: 50px;
}

.mobile-nav-item i {
  width: 20px;
  height: 20px;
}

.mobile-nav-item.active {
  color: var(--forest-primary);
  font-weight: 700;
}

[data-theme="dark"] .mobile-nav-item.active {
  color: var(--soft-sage);
}

.mobile-fab-wrapper {
  position: relative;
  top: -16px;
}

.mobile-fab {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--leaf-green), var(--forest-primary));
  color: var(--text-white);
  border: 4px solid var(--bg-surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  cursor: pointer;
  box-shadow: var(--shadow-float);
  transition: transform var(--transition-fast);
}

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

/* OVERLAYS & SLIDE-OUT DRAWERS */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 30, 24, 0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 110;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--transition-normal), visibility var(--transition-normal);
}

.overlay.active {
  opacity: 1;
  visibility: visible;
}

.drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  right: 0;
  width: min(380px, 88vw);
  max-width: 400px;
  background: var(--bg-surface);
  border-left: 1px solid var(--border-color);
  z-index: 130;
  box-shadow: -8px 0 32px rgba(0, 0, 0, 0.18);
  display: none;
  flex-direction: column;
}

.drawer.open {
  display: flex;
  animation: slideInDrawer 0.25s ease forwards;
}

@keyframes slideInDrawer {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

.drawer-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.drawer-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-subtle);
}

/* RESPONSIVE MEDIA QUERIES: 1024px & below (All Mobile Phones, Tablets & 980px Viewports) */
@media (max-width: 1024px) {
  .sidebar {
    width: min(290px, 80vw);
    max-width: 310px;
    z-index: 125; /* Above .overlay (z-index: 110) so sidebar NEVER blurs */
    transform: translateX(-100%);
    box-shadow: 6px 0 32px rgba(16, 32, 22, 0.35);
    overflow-x: hidden;
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .btn-close-sidebar {
    display: flex;
  }
  .main-wrapper {
    margin-left: 0 !important;
    width: 100% !important;
    max-width: 100vw !important;
    overflow-x: hidden !important;
  }
  .menu-toggle-btn {
    display: block;
  }
  .topbar {
    padding: 0 12px !important;
    height: 56px !important;
    width: 100% !important;
    max-width: 100vw !important;
    overflow: hidden !important;
    box-sizing: border-box !important;
  }
  .topbar-left {
    gap: 8px !important;
    min-width: 0 !important;
    flex: 1 !important;
  }
  .topbar-greeting {
    min-width: 0 !important;
  }
  .topbar-greeting h2 {
    font-size: 15px !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
  }
  .topbar-greeting p {
    display: none !important;
  }
  .topbar-right {
    gap: 6px !important;
    flex-shrink: 0 !important;
  }
  #btn-open-coach-topbar,
  .topbar-coach-btn {
    display: none !important;
  }
  #btn-topbar-quick-add {
    display: none !important;
  }
  .user-avatar-pill span {
    display: none !important;
  }
  .user-avatar-pill {
    padding: 2px !important;
    background: transparent !important;
    border: none !important;
  }
  .user-avatar-icon {
    width: 30px !important;
    height: 30px !important;
    font-size: 14px !important;
  }
  .icon-btn {
    width: 36px !important;
    height: 36px !important;
  }
  .mobile-bottom-nav {
    display: flex !important;
    width: 100% !important;
    max-width: 100vw !important;
    box-sizing: border-box !important;
    padding: 0 4px !important;
    height: 60px !important;
  }
  .mobile-nav-item {
    flex: 1 !important;
    min-width: 0 !important;
    max-width: 65px !important;
    padding: 4px 1px !important;
    font-size: 10px !important;
  }
  .mobile-nav-item i {
    width: 18px !important;
    height: 18px !important;
  }
  .mobile-fab-wrapper {
    top: -14px !important;
  }
  .mobile-fab {
    width: 48px !important;
    height: 48px !important;
  }
  .page-container {
    padding: 14px 12px 90px !important;
    width: 100% !important;
    max-width: 100vw !important;
    overflow-x: hidden !important;
    box-sizing: border-box !important;
  }

  /* Grid & Multi-Column Responsive Fixes - Prevent Column and Text Overflow on Mobile */
  .grid-dashboard-top,
  .grid-2col,
  .grid-3col {
    grid-template-columns: 1fr !important;
    gap: 14px !important;
    width: 100% !important;
  }

  .spending-chart-wrapper {
    grid-template-columns: 1fr !important;
    gap: 18px !important;
    justify-items: center !important;
  }

  .review-grid {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }

  .review-habits-box {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }

  .hero-balance-card {
    padding: 20px 16px !important;
    border-radius: var(--radius-lg) !important;
    width: 100% !important;
    box-sizing: border-box !important;
  }

  .hero-balance-label-row {
    flex-wrap: wrap !important;
    gap: 6px !important;
  }

  .hero-balance-period {
    font-size: 11px !important;
    padding: 3px 9px !important;
    white-space: nowrap !important;
    flex-shrink: 0 !important;
  }

  .hero-balance-amount {
    font-size: clamp(24px, 6.8vw, 34px) !important;
    word-break: break-word !important;
  }

  .hero-balance-footer {
    grid-template-columns: 1fr 1fr !important;
    gap: 10px !important;
    padding-top: 14px !important;
  }

  .card {
    padding: 16px 14px !important;
    border-radius: var(--radius-md) !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  .card-header {
    flex-wrap: wrap !important;
    gap: 8px !important;
  }

  .modal-card {
    max-width: calc(100vw - 20px) !important;
    width: 100% !important;
    margin: 10px auto !important;
  }

  .modal-header,
  .modal-body,
  .modal-footer {
    padding: 14px 16px !important;
  }
}

@media (max-width: 480px) {
  .hero-balance-period {
    display: none !important;
  }
  .hero-balance-footer {
    grid-template-columns: 1fr !important;
    gap: 8px !important;
  }
  .filter-bar {
    flex-wrap: wrap !important;
    gap: 6px !important;
  }
  .modal-card {
    border-radius: var(--radius-md) !important;
  }
}
