/* ============================================================
   LAYOUT.CSS — Sidebar (desktop), bottom nav (mobile), topbar
   ============================================================ */

/* ---- Sidebar ---- */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--color-sidebar-bg);
  border-right: 1px solid var(--color-sidebar-border);
  display: flex;
  flex-direction: column;
  z-index: 200;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--topbar-height);
  padding: 0 16px;
  border-bottom: 1px solid var(--color-sidebar-border);
  flex-shrink: 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  cursor: pointer;
}
.logo:hover { text-decoration: none; }

.logo-icon { display: none; }

/* Flow wordmark — JetBrains Mono, white, terminal cursor */
.logo-text {
  font-family: var(--font-display);
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--color-text);
  letter-spacing: -0.02em;
  line-height: 1;
}
.logo-text::after {
  content: '_';
  color: var(--color-text-muted);
}

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

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: var(--color-sidebar-text);
  font-weight: 500;
  font-size: 0.875rem;
  transition: background var(--transition), color var(--transition);
  text-decoration: none;
  position: relative;
  cursor: pointer;
}
.nav-item:hover { background: var(--color-surface-2); color: var(--color-text); text-decoration: none; }
.nav-item.active { background: var(--color-sidebar-active-bg); color: var(--color-sidebar-active-text); font-weight: 600; }
.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 20%; bottom: 20%;
  width: 2px;
  background: var(--color-primary);
  border-radius: 2px;
}
.nav-item--accent {
  margin-top: 12px;
  background: transparent;
  color: var(--color-text) !important;
  border: 1px solid var(--mono-outline);
}
.nav-item--accent:hover {
  background: var(--color-primary-light) !important;
  border-color: var(--mono-outline-strong) !important;
  color: var(--color-text) !important;
}
.nav-item--accent::before { display: none !important; }

.nav-icon { width: 20px; height: 20px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; opacity: 0.65; line-height: 0; }
.nav-item:hover .nav-icon, .nav-item.active .nav-icon, .nav-item--accent .nav-icon { opacity: 1; }
.nav-label { font-size: 0.875rem; }

.sidebar-footer {
  padding: 12px 10px 14px;
  border-top: 1px solid var(--color-sidebar-border);
}

/* ---- Overlay (mobile sidebar backdrop) ---- */
.overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.78);
  z-index: 150;
  opacity: 0;
  transition: opacity var(--transition);
  backdrop-filter: blur(2px);
}
.overlay.active { display: block; opacity: 1; }

/* ---- Main wrapper ---- */
.main-wrapper {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  animation: pageIn 0.22s ease both;
}

@keyframes pageIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

body.page-exit .main-wrapper {
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.15s ease, transform 0.15s ease;
}

/* ---- Topbar ---- */
.topbar {
  position: sticky;
  top: 0;
  height: var(--topbar-height);
  background: var(--chrome-topbar);
  border-bottom: 1px solid var(--color-border-light);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 24px;
  z-index: 100;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

/* Hamburger — mobile only */
.menu-btn {
  color: var(--color-text-muted);
  display: none;
  padding: 6px;
  border-radius: var(--radius-sm);
  transition: background var(--transition), color var(--transition);
  cursor: pointer;
  line-height: 0;
  flex-shrink: 0;
}
.menu-btn:hover { background: var(--color-surface-2); color: var(--color-text); }

.topbar-title { font-size: 0.9375rem; font-weight: 600; flex: 1; color: var(--color-text); letter-spacing: -0.01em; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

.topbar-icon-btn {
  display: flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  color: var(--color-text-muted); text-decoration: none; flex-shrink: 0;
  transition: background var(--transition), color var(--transition);
}
.topbar-icon-btn:hover { background: var(--color-surface-2); color: var(--color-text); text-decoration: none; }
.topbar-icon-btn--active { color: var(--color-text); background: var(--color-surface-2); }

/* ---- Desktop topbar: logo (mobile fallback) ---- */
.topbar-logo {
  display: none;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  font-family: var(--font-display);
  color: var(--color-text);
  font-weight: 600;
  font-size: 1rem;
  letter-spacing: -0.02em;
  flex-shrink: 0;
  white-space: nowrap;
}
.topbar-logo::after { content: '_'; color: var(--color-text-muted); }
.topbar-logo:hover { text-decoration: none; color: var(--color-text); }
.topbar-logo-icon { color: var(--color-accent); line-height: 0; }

/* ---- Desktop topbar: nav links ---- */
.topbar-nav {
  display: none;
  align-items: center;
  gap: 2px;
  flex: 1;
  justify-content: center;
}
.topbar-nav-link {
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-text-muted);
  text-decoration: none;
  transition: background var(--transition), color var(--transition);
  white-space: nowrap;
}
.topbar-nav-link:hover { color: var(--color-text); background: var(--color-surface-2); text-decoration: none; }
.topbar-nav-link.active { color: var(--color-text); font-weight: 600; background: var(--color-primary-light); }

/* ---- Desktop: sidebar visible, topbar shows title + actions only ---- */
@media (min-width: 769px) {
  .sidebar { display: flex; }
  .bottom-nav { display: none !important; }
  .menu-btn { display: none !important; }
  .topbar-title { display: block; flex: 1; }
  .topbar-logo { display: none; }
  .topbar-nav { display: none; }
  .topbar { padding: 0 24px; }
  .main-content { padding-bottom: 24px; }
}

/* ---- Main content ---- */
.main-content {
  flex: 1;
  padding: 24px;
  padding-bottom: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
}

/* ---- Bottom nav — HIDDEN on desktop, shown on mobile ---- */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: var(--bottom-nav-height);
  background: var(--chrome-bottom);
  border-top: 1px solid var(--color-border);
  z-index: 100;
  padding: 0 4px;
  align-items: center;
  /* 5 equal columns so the centre [+] is always dead-centre regardless of
     label widths (space-around drifted it right because the left labels are
     wider than the right ones). */
  grid-template-columns: repeat(5, 1fr);
  justify-items: center;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.bottom-nav__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 10px;
  border-radius: var(--radius-md);
  color: var(--color-text-muted);
  text-decoration: none;
  transition: color var(--transition), transform var(--transition);
  min-width: 52px;
  cursor: pointer;
  position: relative;
}
.bottom-nav__item:hover  { color: var(--color-text); text-decoration: none; }
.bottom-nav__item.active { color: var(--color-text); text-decoration: none; }
.bottom-nav__item.active::after {
  content: '';
  position: absolute;
  bottom: 3px;
  left: 50%; transform: translateX(-50%);
  width: 20px; height: 3px;
  border-radius: 2px;
  background: var(--color-primary);
}
.bottom-nav__item:not(.bottom-nav__item--add):active { transform: scale(0.92); }

.bottom-nav__item--add {
  background: var(--color-primary);
  color: var(--color-primary-contrast) !important;
  border-radius: 50%;
  width: 46px; height: 46px;
  min-width: unset; padding: 0;
  display: flex; align-items: center; justify-content: center;
  transition: transform var(--transition), box-shadow var(--transition) !important;
  line-height: 0;
  box-shadow: 0 0 0 1px rgba(255,255,255,.15), 0 4px 20px rgba(0,0,0,.5);
}
.bottom-nav__item--add:hover {
  transform: scale(1.08); color: var(--color-primary-contrast) !important;
  box-shadow: 0 0 0 1px rgba(255,255,255,.3), 0 6px 24px rgba(0,0,0,.6);
}

.bottom-nav__icon { width: 22px; height: 22px; display: flex; align-items: center; justify-content: center; line-height: 0; }
.bottom-nav__label { font-size: 0.625rem; font-weight: 600; letter-spacing: 0.02em; }

/* ============================================================
   MOBILE  ≤ 768px
   ============================================================ */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    /* fully hidden when closed: kills the 1px border peeking at the left edge
       and keeps the off-screen nav links out of the tab order */
    visibility: hidden;
    transition: transform 0.22s cubic-bezier(.4,0,.2,1), visibility 0.22s;
    box-shadow: none;
  }
  .sidebar.open {
    transform: translateX(0);
    visibility: visible;
    box-shadow: 4px 0 32px rgba(0,0,0,.6);
  }

  .sidebar-close { display: flex; }
  .menu-btn { display: flex; }
  .main-wrapper { margin-left: 0; }

  /* hamburger + settings sit at the edges (was 24px in from the base padding) */
  .topbar { padding: 0 8px; }

  .bottom-nav { display: grid; }

  .main-content {
    padding: 14px;
    padding-bottom: calc(14px + var(--bottom-nav-height));
    gap: 12px;
  }

  /* Touch targets */
  .btn:not(#submitBtn):not(.btn--sm), .nav-item, .bottom-nav__item, .type-btn,
  .category-btn, .page-btn, .tx-action-btn, .modal-close {
    min-height: 44px;
  }
  select.form-control, input.form-control { min-height: 44px; }
}

/* ---- Money hub pill tabs ---- */
.money-tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.money-tab {
  padding: 6px 14px;
  border-radius: 0;
  font-family: var(--font-display);
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
  text-decoration: none;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.money-tab:hover { color: var(--color-text); background: var(--color-surface-2); text-decoration: none; }
.money-tab.active {
  color: var(--color-text);
  font-weight: 600;
  background: var(--color-primary-light);
  border-color: var(--mono-outline);
}

/* ---- "More" bottom sheet (mobile) ---- */
.more-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.65);
  z-index: 170;
  opacity: 0;
  transition: opacity var(--transition);
  backdrop-filter: blur(2px);
}
.more-backdrop.open { display: block; opacity: 1; }

.more-sheet {
  position: fixed;
  left: 0; right: 0;
  bottom: var(--bottom-nav-height);
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  z-index: 180;
  padding: 10px 16px calc(16px + env(safe-area-inset-bottom, 0px));
  transform: translateY(calc(100% + var(--bottom-nav-height)));
  transition: transform 0.24s cubic-bezier(.4,0,.2,1);
  box-shadow: 0 -8px 32px rgba(0,0,0,.5);
}
.more-sheet.open { transform: translateY(0); }

.more-sheet__handle {
  width: 36px; height: 4px;
  border-radius: 2px;
  background: var(--color-border);
  margin: 0 auto 12px;
}
.more-sheet__grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.more-sheet__item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 14px 6px;
  border-radius: var(--radius-md);
  background: var(--color-surface-2);
  color: var(--color-text-muted);
  font-size: 0.75rem;
  font-weight: 500;
  text-decoration: none;
  transition: background var(--transition), color var(--transition);
}
.more-sheet__item:hover  { color: var(--color-text); text-decoration: none; }
.more-sheet__item.active { color: var(--color-text); background: var(--color-primary-light); font-weight: 600; }
.more-sheet__icon { line-height: 0; }

@media (min-width: 769px) {
  .more-sheet, .more-backdrop { display: none !important; }
}

/* ---- Tablet: tighten layout ---- */
@media (min-width: 769px) and (max-width: 1024px) {
  :root { --sidebar-width: 220px; }
  .main-content { padding: 16px; gap: 14px; }
  .nav-label { font-size: 0.8125rem; }
}
