/* Layout Shell */
#app-layout {
  display: flex;
  min-height: 100vh;
  position: relative;
  z-index: 1;
}

/* Sidebar for Desktop */
.sidebar {
  display: none;
  width: 260px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-subtle);
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: var(--z-nav);
  padding: 1.5rem 1.25rem;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.5rem 1.5rem;
  border-bottom: 1px solid var(--border-subtle);
}

.sidebar-logo-container {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.sidebar-logo-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 2px 8px rgba(56, 189, 248, 0.2));
}

.logo-badge {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  background: var(--primary-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 4px 12px var(--primary-glow);
}

.logo-badge svg {
  width: 22px;
  height: 22px;
}

.logo-text {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #ffffff 30%, #94a3b8 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 1.5rem;
  flex: 1;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.95rem;
  transition: all var(--transition-fast);
  cursor: pointer;
}

.nav-link svg {
  width: 20px;
  height: 20px;
  transition: transform var(--transition-fast);
}

.nav-link:hover {
  color: var(--text-main);
  background: var(--bg-surface-hover);
}

.nav-link:hover svg {
  transform: translateX(2px);
}

.nav-link.active {
  color: #ffffff;
  background: var(--primary-gradient);
  box-shadow: 0 4px 15px var(--primary-glow);
  font-weight: 600;
}

.nav-link:active {
  transform: scale(0.97) !important;
}

.sidebar-footer {
  padding-top: 1rem;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.user-profile-badge {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.55rem 0.65rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  transition: border-color var(--transition-fast), background var(--transition-fast);
}

.user-profile-badge:hover {
  border-color: var(--border-light);
}

.user-avatar {
  width: 32px;
  height: 32px;
  min-width: 32px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, #1e293b, #0f172a);
  border: 1.5px solid rgba(99, 102, 241, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
  color: #fff;
  flex-shrink: 0;
  overflow: hidden;
}

.user-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
  overflow: hidden;
}

.user-name-line {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
}

.user-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.user-email {
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.btn-icon-ghost {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  width: 26px;
  height: 26px;
  min-width: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  flex-shrink: 0;
  padding: 0;
}

.btn-icon-ghost:hover {
  color: var(--expense);
  background: rgba(239, 68, 68, 0.12);
}

/* Main Content Area */
.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  width: 100%;
}

/* Header */
.top-header {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  background: var(--bg-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0.85rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header-title {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.main-content {
  flex: 1;
  padding: 1.25rem;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding-bottom: 5.5rem; /* Space for mobile nav */
}

@media (max-width: 480px) {
  .top-header {
    padding: 0.75rem 1rem;
    padding-top: calc(0.75rem + env(safe-area-inset-top, 0px));
  }
  .main-content {
    padding: 0.9rem 0.85rem;
    padding-bottom: calc(6.5rem + env(safe-area-inset-bottom, 0px));
  }
}

/* Mobile Bottom Navigation */
.mobile-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(15, 23, 42, 0.94);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 0.35rem 0.35rem calc(0.35rem + env(safe-area-inset-bottom, 0px));
  z-index: var(--z-nav);
  height: calc(58px + env(safe-area-inset-bottom, 0px));
  box-sizing: border-box;
}

.mobile-nav-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  color: var(--text-muted);
  font-size: 0.68rem;
  font-weight: 500;
  padding: 0.35rem 0.4rem;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
  flex: 1;
  max-width: 72px;
  min-height: 44px; /* Touch ergonomic standard (44x44px target) */
  -webkit-tap-highlight-color: transparent;
}

.mobile-nav-link svg {
  width: 20px;
  height: 20px;
  transition: transform var(--transition-fast);
}

.mobile-nav-link.active {
  color: var(--primary);
  font-weight: 700;
}

.mobile-nav-link.active svg {
  transform: translateY(-2px);
  stroke: var(--primary);
}

.mobile-nav-link:active {
  transform: scale(0.92) !important;
}

@media (max-width: 360px) {
  .mobile-nav-link {
    font-size: 0.6rem;
    padding: 0.25rem 0.15rem;
  }
  .mobile-nav-link svg {
    width: 18px;
    height: 18px;
  }
}

/* Floating Action Button (FAB) */
.fab-btn {
  position: fixed !important;
  bottom: calc(4.8rem + env(safe-area-inset-bottom, 0px));
  right: 1.25rem;
  width: 56px;
  height: 56px;
  border-radius: var(--radius-full);
  -webkit-tap-highlight-color: transparent;
  background: var(--primary-gradient);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 24px var(--primary-glow);
  z-index: var(--z-fab);
  cursor: pointer;
  overflow: hidden;
  transition: transform var(--transition-instant), box-shadow var(--transition-fast), filter var(--transition-fast);
}

.fab-btn svg {
  width: 26px;
  height: 26px;
  transition: transform var(--transition-fast);
}

.fab-btn:hover {
  transform: translateY(-2px) scale(1.04);
  box-shadow: 0 12px 28px var(--primary-glow);
  filter: brightness(1.08);
}

.fab-btn:hover svg {
  transform: rotate(90deg);
}

.fab-btn:active {
  transform: scale(0.95) translateY(0);
}

/* Desktop Enhancements */
@media (min-width: 992px) {
  .sidebar {
    display: flex;
  }

  .main-wrapper {
    margin-left: 260px;
  }

  .mobile-nav {
    display: none;
  }

  .main-content {
    padding: 2rem 2.5rem;
    padding-bottom: 2.5rem;
  }

  .fab-btn {
    position: fixed !important;
    bottom: 2.5rem;
    right: 2.5rem;
    width: auto;
    height: 50px;
    padding: 0 1.5rem;
    border-radius: var(--radius-lg);
    gap: 0.5rem;
    font-weight: 600;
    font-size: 0.95rem;
  }

  .fab-btn .fab-label {
    display: inline;
  }
}

@media (max-width: 991px) {
  .fab-btn .fab-label {
    display: none;
  }
}

/* Light Mode Layout Overrides */
[data-theme="light"] .sidebar {
  background: #ffffff;
  border-right: 1px solid var(--border-subtle);
}

[data-theme="light"] .top-header {
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--border-subtle);
}

[data-theme="light"] .mobile-nav {
  background: rgba(255, 255, 255, 0.96);
  border-top: 1px solid var(--border-subtle);
}

[data-theme="light"] .logo-text {
  background: linear-gradient(135deg, #0f172a 30%, #475569 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

[data-theme="light"] .user-profile-badge {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
}

/* AMOLED Specific High-Contrast Refinements */
:root:not([data-theme="light"]) .sidebar {
  background: #000000;
  border-right: 1px solid var(--border-subtle);
}

:root:not([data-theme="light"]) .top-header {
  background: rgba(0, 0, 0, 0.9);
  border-bottom: 1px solid var(--border-subtle);
}

:root:not([data-theme="light"]) .mobile-nav {
  background: rgba(0, 0, 0, 0.95);
  border-top: 1px solid var(--border-subtle);
}
