/* ============================================================================
   Yaaleh app shell — authenticated layout, sidebar, topbar, bottom nav.
   Ported from the (dead) scoped CSS of MainLayout/NavMenu/MobileBottomNav/
   WalletDropdown into a single global layer, so the shell renders everywhere
   (desktop web + MAUI WebView) instead of relying on the scoped-CSS bundle
   that 302s to /404. Bootstrap-shared overrides (.nav-link, .accordion-*) are
   re-scoped to .sidebar-nav-inner so they don't leak into the app's other
   accordions/tabs.
   ============================================================================ */

/* ===== Authenticated app layout ===== */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ===== Sidebar ===== */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 280px;
  height: 100vh;
  background-color: #ffffff;
  border-right: 1px solid #e4e4e4;
  display: flex;
  flex-direction: column;
  z-index: 100;
  box-shadow: 2px 0 8px rgba(0, 0, 0, 0.05);
  overflow: hidden;
  transition: width 0.18s ease;
}

.sidebar-header {
  display: flex;
  align-items: center;
  padding: 0 24px;
  height: 64px;
  border-bottom: 1px solid #e4e4e4;
  flex-shrink: 0;
  overflow: hidden;
  transition: padding 0.18s ease, justify-content 0.18s ease;
}

.sidebar-logo-link {
  display: flex;
  align-items: center;
  text-decoration: none;
  overflow: hidden;
}

.sidebar-logo {
  height: 30px;
  width: auto;
  max-width: 200px;
  flex-shrink: 0;
}

/* ===== Content area ===== */
.content-area {
  margin-left: 280px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background-color: #f9f9f9;
  min-width: 0;
  transition: margin-left 0.18s ease;
}

/* ===== Top bar ===== */
.topbar {
  background-color: #ffffff;
  border-bottom: 1px solid #e4e4e4;
  height: 60px;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.04);
  flex-shrink: 0;
}

.topbar-user-btn {
  color: #413f3f !important;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 500;
  border-radius: 8px !important;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.topbar-user-btn:hover {
  background-color: #e7f5ff !important;
  color: #0077d4 !important;
}

/* ===== Main content ===== */
main {
  flex: 1;
}

/* The content article carries Bootstrap `.px-4` (24px, !important). `.content.main-container`
   (0,2,0) beats `.px-4` (0,1,0) by specificity and zeros the article gutter so each page owns its
   own padding (no doubled padding). */
.content.main-container {
  padding: 0 !important;
}

/* ===== Blazor error UI ===== */
#blazor-error-ui {
  background: lightyellow;
  bottom: 0;
  box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
  display: none;
  left: 0;
  padding: 0.6rem 1.25rem 0.7rem 1.25rem;
  position: fixed;
  width: 100%;
  z-index: 1000;
}

#blazor-error-ui .dismiss {
  cursor: pointer;
  position: absolute;
  right: 0.75rem;
  top: 0.5rem;
}

/* Compact brand shown only in the mobile top bar */
.topbar-mobile-brand {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.topbar-mobile-brand img {
  height: 24px;
  width: auto;
}

/* Global back button (every page) — iOS-style chevron in the top bar; calls history.back(). */
.topbar-left {
  display: flex !important;
  flex-direction: row !important;
  flex-wrap: nowrap !important;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}
.topbar-back {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  min-height: 36px;
  padding: 0;
  border: 1px solid var(--border-neutral-primary);
  border-radius: 10px;
  background: #fff;
  color: var(--color-ink-900);
  cursor: pointer;
}
.topbar-back:hover {
  background: var(--bg-app);
  color: var(--color-brand-70);
  border-color: var(--color-brand-30, #b9defc);
}
.topbar-back i {
  font-size: 1.15rem;
  line-height: 1;
}

/* ===== Wallet dropdown (topbar) ===== */
.wallet-dropdown {
  flex: 0 1 520px;
  min-width: 220px;
  max-width: min(520px, 42vw);
}

.wallet-mini {
  width: 100%;
  max-width: 100%;
  overflow: hidden;
  padding-right: 28px;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wallet-dropdown .dropdown-menu {
  width: min(520px, calc(100vw - 32px));
  max-width: min(520px, calc(100vw - 32px));
}

.wallet-dropdown .dropdown-item {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 860px) {
  .wallet-dropdown {
    flex-basis: 320px;
    max-width: 38vw;
    min-width: 160px;
  }
}

/* Phones: the wallet name must shrink/truncate so the topbar (logo + wallet + bell + user) fits in
   the viewport instead of overflowing and pushing the logo off-screen left. */
@media (max-width: 768px) {
  .wallet-dropdown {
    flex: 1 1 auto;
    min-width: 0;
    max-width: none;
  }
}

/* ===== Sidebar nav (NavMenu) ===== */
.sidebar-nav-inner {
  --sidebar-compact-width: 76px;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 64px); /* subtract sidebar-header height */
  width: 100%;
  overflow: hidden;
}

.sidebar-toggle-row {
  flex-shrink: 0;
  padding: 8px 12px 4px;
}

.sidebar-collapse-toggle {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  width: 100%;
  min-height: 38px;
  padding: 9px 12px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #565454;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.2;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.sidebar-collapse-toggle i {
  flex-shrink: 0;
  width: 18px;
  text-align: center;
  font-size: 15px;
}

.sidebar-collapse-toggle:hover {
  background-color: #e7f5ff;
  color: #0077d4;
}

.sidebar-collapse-toggle:focus {
  outline: none;
  box-shadow: none;
}

.sidebar-menu {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 10px 12px 8px;
}

.sidebar-menu::-webkit-scrollbar {
  width: 4px;
}

.sidebar-menu::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar-menu::-webkit-scrollbar-thumb {
  background-color: #e4e4e4;
  border-radius: 4px;
}

.nav-group-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #bcbcbc;
  padding: 14px 12px 5px;
}

.sidebar-nav-inner .nav-item {
  padding: 1px 0;
}

.sidebar-nav-inner .nav-item .nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  color: #565454 !important;
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  line-height: 1.4;
  height: auto;
  white-space: nowrap;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.sidebar-nav-inner .nav-item .nav-link i {
  font-size: 15px;
  flex-shrink: 0;
  width: 18px;
  text-align: center;
}

.sidebar-nav-inner .nav-item .nav-link:hover {
  background-color: #e7f5ff;
  color: #0077d4 !important;
}

.sidebar-nav-inner .nav-item .nav-link.active {
  background-color: #e7f5ff;
  color: #0077d4 !important;
  font-weight: 600;
}

/* ===== Sidebar accordion (re-scoped so it never touches page accordions) ===== */
.sidebar-nav-inner .accordion {
  --bs-accordion-bg: transparent;
  --bs-accordion-border-color: transparent;
  --bs-accordion-border-width: 0;
  --bs-accordion-inner-border-radius: 8px;
  --bs-accordion-btn-focus-box-shadow: none;
}

.sidebar-nav-inner .accordion-item {
  border: none !important;
  background: transparent !important;
  margin-bottom: 1px;
}

.sidebar-nav-inner .accordion-header {
  margin: 0;
}

.sidebar-nav-inner .accordion-button {
  display: flex !important;
  align-items: center !important;
  gap: 10px !important;
  padding: 9px 12px !important;
  border-radius: 8px !important;
  background-color: transparent !important;
  color: #565454 !important;
  font-size: 14px !important;
  font-weight: 500 !important;
  border: none !important;
  box-shadow: none !important;
  white-space: nowrap;
  transition: background-color 0.15s ease, color 0.15s ease;
  width: 100%;
}

.sidebar-nav-inner .accordion-button i {
  font-size: 15px;
  flex-shrink: 0;
  width: 18px;
  text-align: center;
}

.sidebar-nav-inner .accordion-button span {
  flex: 1;
  text-align: left;
}

.sidebar-nav-inner .accordion-button:hover {
  background-color: #e7f5ff !important;
  color: #0077d4 !important;
}

.sidebar-nav-inner .accordion-button:not(.collapsed) {
  background-color: #e7f5ff !important;
  color: #0077d4 !important;
  box-shadow: none !important;
}

.sidebar-nav-inner .accordion-button:focus {
  box-shadow: none !important;
  outline: none;
}

.sidebar-nav-inner .accordion-button::after {
  filter: none;
  flex-shrink: 0;
  margin-left: auto;
  opacity: 0.5;
}

.sidebar-nav-inner .accordion-button:not(.collapsed)::after {
  opacity: 0.8;
}

.sidebar-nav-inner .accordion-collapse,
.sidebar-nav-inner .accordion-body {
  border: none !important;
  background: transparent !important;
  box-shadow: none !important;
}

.sidebar-nav-inner .accordion-body {
  padding: 3px 0 3px 16px !important;
}

.sidebar-nav-inner .accordion-body .nav-link {
  display: flex;
  align-items: center;
  padding: 7px 12px;
  border-radius: 8px;
  color: #7e7e7e !important;
  font-size: 13px;
  font-weight: 400;
  text-decoration: none;
  white-space: nowrap;
  line-height: 1.4;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.sidebar-nav-inner .accordion-body .nav-link:hover {
  background-color: #e7f5ff;
  color: #0077d4 !important;
}

.sidebar-nav-inner .accordion-body .nav-link.active {
  background-color: #e7f5ff;
  color: #0077d4 !important;
  font-weight: 500;
}

/* ===== Sidebar footer (logout + version) ===== */
.sidebar-footer {
  flex-shrink: 0;
  padding: 10px 12px 14px;
  border-top: 1px solid #e4e4e4;
}

.logout-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 12px;
  border-radius: 8px;
  background: none;
  border: none;
  color: #565454;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
  text-align: left;
  white-space: nowrap;
}

.logout-btn i {
  font-size: 15px;
  flex-shrink: 0;
  width: 18px;
  text-align: center;
}

.logout-btn:hover {
  background-color: #ffe5e5;
  color: #d60000;
}

.version-label {
  font-size: 11px;
  color: #bcbcbc;
  padding: 8px 12px 0;
  text-align: center;
}

/* ===== Collapsed sidebar state ===== */
.sidebar-nav-inner.is-collapsed .sidebar-toggle-row {
  padding: 8px 8px 4px;
}

.sidebar-nav-inner.is-collapsed .sidebar-menu {
  padding: 8px;
}

.sidebar-nav-inner.is-collapsed .sidebar-footer {
  padding: 10px 8px 12px;
}

.sidebar-nav-inner.is-collapsed .sidebar-collapse-toggle,
.sidebar-nav-inner.is-collapsed .nav-item .nav-link,
.sidebar-nav-inner.is-collapsed .accordion-button,
.sidebar-nav-inner.is-collapsed .logout-btn {
  justify-content: center;
  gap: 0;
  min-height: 38px;
  padding-left: 0 !important;
  padding-right: 0 !important;
}

.sidebar-nav-inner.is-collapsed .sidebar-collapse-toggle span,
.sidebar-nav-inner.is-collapsed .nav-item .nav-link span,
.sidebar-nav-inner.is-collapsed .accordion-button span,
.sidebar-nav-inner.is-collapsed .logout-btn span,
.sidebar-nav-inner.is-collapsed .version-label,
.sidebar-nav-inner.is-collapsed .nav-group-label {
  display: none;
}

.sidebar-nav-inner.is-collapsed .accordion-button::after {
  display: none;
}

.sidebar-nav-inner.is-collapsed .accordion-collapse,
.sidebar-nav-inner.is-collapsed .accordion-body {
  display: none !important;
}

/* ===== Mobile bottom tab bar (hidden on desktop) ===== */
.mobile-bottom-nav {
  display: none;
}

.mobile-menu-backdrop,
.mobile-menu-sheet {
  display: none;
}

/* ===== Mobile shell (≤768px): sidebar → bottom tab bar + "Mais" sheet ===== */
@media (max-width: 768px) {
  .sidebar {
    display: none;
  }

  .content-area {
    /* override both the default 280px and the collapsed-rail 76px */
    margin-left: 0 !important;
  }

  .topbar {
    height: 56px;
    padding-left: 12px !important;
    padding-right: 12px !important;
    justify-content: space-between !important;
  }

  /* Leave room for the fixed bottom nav (60px) + iOS home indicator */
  main {
    padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px));
  }

  .mobile-bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1030;
    display: flex;
    align-items: stretch;
    justify-content: space-around;
    height: 60px;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: #ffffff;
    border-top: 1px solid #e4e4e4;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.06);
  }

  .mbn-tab {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 0;
    padding: 6px 2px;
    border: 0;
    background: transparent;
    color: #7e7e7e;
    font-size: 10.5px;
    font-weight: 600;
    line-height: 1.1;
    text-decoration: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: color 0.15s ease;
  }

  .mbn-tab i {
    font-size: 19px;
    line-height: 1;
  }

  .mbn-tab span {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mbn-tab:hover,
  .mbn-tab:focus-visible,
  .mbn-tab.active {
    color: #0077d4;
  }

  /* ===== "Mais" full-screen menu sheet ===== */
  .mobile-menu-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 1040;
    background: rgba(0, 0, 0, 0.35);
    animation: mbn-fade 0.15s ease;
  }

  .mobile-menu-sheet {
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: 0;
    z-index: 1045;
    background: #ffffff;
    animation: mbn-slide-up 0.2s ease;
  }

  .mobile-menu-sheet__header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 56px;
    padding: calc(14px + env(safe-area-inset-top)) 16px 14px;
    border-bottom: 1px solid #e4e4e4;
  }

  .mobile-menu-sheet__title {
    font-family: var(--m-display);
    font-size: 18px;
    font-weight: 700;
    color: #413f3f;
  }

  .mobile-menu-sheet__close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: #565454;
    font-size: 18px;
    cursor: pointer;
  }

  .mobile-menu-sheet__close:hover {
    background: #f2f2f2;
  }

  .mobile-menu-sheet__body {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 6px 8px calc(16px + env(safe-area-inset-bottom));
  }

  /* The reused NavMenu fills the sheet; its own collapse toggle is irrelevant here */
  .mobile-menu-sheet__body .sidebar-nav-inner {
    height: auto;
  }

  .mobile-menu-sheet__body .sidebar-toggle-row {
    display: none;
  }

  /* Section labels: from near-invisible to clear dividers. */
  .mobile-menu-sheet__body .nav-group-label {
    margin-top: 18px;
    padding: 0 8px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.06em;
    color: var(--m-ink-soft);
    text-transform: uppercase;
  }

  /* Items: larger touch area + readable size. */
  .mobile-menu-sheet__body .nav-link,
  .mobile-menu-sheet__body .accordion-button {
    padding-top: 12px;
    padding-bottom: 12px;
    font-size: 15px;
    border-radius: 10px;
  }

  /* Active item: brand tint + left accent. */
  .mobile-menu-sheet__body .nav-link.active {
    position: relative;
    background: var(--m-brand-tint);
    color: var(--m-brand);
  }

  .mobile-menu-sheet__body .nav-link.active::before {
    content: "";
    position: absolute;
    left: 0;
    top: 8px;
    bottom: 8px;
    width: 3px;
    border-radius: 0 3px 3px 0;
    background: var(--m-brand);
  }

  @keyframes mbn-fade {
    from { opacity: 0; }
    to { opacity: 1; }
  }

  @keyframes mbn-slide-up {
    from { transform: translateY(2%); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
  }
}

@media (prefers-reduced-motion: reduce) {
  .mobile-menu-backdrop,
  .mobile-menu-sheet {
    animation: none;
  }
}
