/* ============================================================================
   Tilfully navigation shell — structure only (colors live in tilfully-theme.css).
   Desktop: left sidebar (brand / 5 tabs / corner controls).
   Mobile (<=880px): slim fixed top bar (brand + controls) + fixed bottom tab bar.
   ========================================================================== */

/* ---- app-level contour canvas sits behind everything --------------------- */
#appTopo { position: fixed; inset: 0; width: 100vw; height: 100vh; z-index: 0; pointer-events: none; }
#appView aside, #appView main { position: relative; z-index: 1; }

/* ---- desktop sidebar ------------------------------------------------------ */
#appView aside {
  display: flex !important;
  flex-direction: column;
  gap: 18px;
}
#appView .brand {
  display: flex !important;
  align-items: center;
  gap: 12px;
  min-height: 44px;
}
#appView .brand h1 {
  font-size: 1.3rem !important;
  white-space: nowrap;
  overflow: visible !important;
  margin: 0;
}
#appView .brand .top-actions { display: none !important; } /* legacy slot, replaced by .shell-corner */

#appView #nav { flex: 0 0 auto; align-content: start; }  /* nav is a grid; without this, spare height stretches the buttons */
/* corner controls sit right under the tabs (bottom-pinning felt disconnected) */

#appView .shell-corner {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding-top: 14px;
  margin-top: 4px;
  border-top: 1px solid rgba(150, 150, 130, 0.18);
}
#appView .shell-corner .icon-button {
  width: 38px; height: 38px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
  font-size: 1rem;
}
#appView .shell-corner #profileBtn svg { width: 19px; height: 19px; display: block; }
#appView .shell-corner #logoutBtn { margin-left: auto; }
#appView .shell-corner #globalMessage { flex-basis: 100%; margin: 0; }

/* ---- desktop: floating dock (Josh, 2026-07-11) ----------------------------
       The sidebar is no longer a full-height column. It floats as a vertically
       centered, content-hugging glass island over the app; main owns the full
       viewport width so the dashboard map (and the greeting) reach the left edge.
       Non-map pages pad left so content never sits under the dock. */
@media (min-width: 641px) {
  #appView.app { grid-template-columns: 1fr !important; }
  #appView aside {
    position: fixed !important;
    left: 12px;
    /* vertically CENTERED on the left (Josh, 2026-07-14 round 2: "the tab bar I
       want left centered vertically") — the earlier dead space was the empty
       brand pocket INSIDE the pill, which is gone; the pill itself hugs its
       content and floats mid-edge */
    top: 50% !important;
    transform: translateY(-50%);
    width: 208px;
    height: auto !important;
    max-height: calc(100vh - 24px);
    padding: 14px !important;
    gap: 14px;
    border-radius: 18px;
    overflow: visible !important;   /* the drawer handle protrudes past the edge */
    z-index: 45;
    box-shadow: 0 26px 64px -34px rgba(0, 0, 0, 0.55);
  }
  /* every icon vertical, one column — never side-by-side (Josh, 2026-07-14) */
  #appView .shell-corner { flex-direction: column; align-items: center; flex-wrap: nowrap; }
  #appView .shell-corner #logoutBtn { margin-left: 0; }
  /* the retired T tile left an empty 48px grid column pushing the wordmark right */
  #appView .brand { grid-template-columns: minmax(0, 1fr) auto; }
  /* collapsed: the brand block is empty now — hiding it removes the dead pocket
     at the top of the rail (Josh, 2026-07-14) */
  body.sidebar-collapsed #appView .brand { display: none !important; }   /* base rule is display:flex !important */
  /* nav stays one vertical column in BOTH dock states — never a horizontal
     row, never sideways scrolling (Josh, 2026-07-14). grid-template-columns
     must be pinned too: app.css's max-width-1050 rules set the nav to four
     columns / flex overflow-x, which shoved Activity+Accounts sideways out of
     the collapsed pill on 881-1050px windows (Josh's photo, 2026-07-14). */
  #appView #nav {
    display: grid !important;
    grid-auto-flow: row;
    grid-template-columns: 1fr !important;
    overflow: visible !important;
  }
  #appView aside::after { display: none; }   /* trailing hairline = dead space in a dock */
  #appView main > section.page:not(#overview) { padding-left: 226px; }
  body.sidebar-collapsed #appView main > section.page:not(#overview) { padding-left: 78px; }
}

/* ---- sidebar drawer handle: a quiet tab just outside the edge, over the map;
       hidden until the sidebar (or the tab itself) is hovered (Josh, 2026-07-11) */
@media (min-width: 641px) {
  #sidebarToggleBtn {
    position: absolute;
    right: -22px;             /* fully outside the bar, flush against its edge */
    top: 50%;
    transform: translateY(-50%);
    z-index: 5;
    width: 22px !important;
    height: 52px !important;
    border-radius: 0 10px 10px 0 !important;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 0.8rem;
    padding: 0 !important;
    opacity: 0;
    transition: opacity 0.15s ease;
  }
  #appView aside:hover #sidebarToggleBtn,
  #sidebarToggleBtn:hover,
  #sidebarToggleBtn:focus-visible { opacity: 1; }
}

/* ---- collapsed dock: icon-only, the "minimum" default (Josh, 2026-07-11) -- */
@media (min-width: 641px) {
  body.sidebar-collapsed #appView aside { width: 64px; padding: 12px 8px !important; }
  body.sidebar-collapsed #appView .brand { flex-direction: column; gap: 8px; }
  body.sidebar-collapsed #appView .brand-copy { display: none; }
  body.sidebar-collapsed #appView .nav-btn span { display: none; }
  body.sidebar-collapsed #appView .nav-btn { justify-content: center; padding: 10px 0 !important; }
  body.sidebar-collapsed #appView .shell-corner { flex-direction: column; align-items: center; }
  body.sidebar-collapsed #appView .shell-corner #logoutBtn { display: none; }
  body.sidebar-collapsed #appView .shell-corner #globalMessage { display: none; }
}
@media (max-width: 640px) {
  #sidebarToggleBtn { display: none; }   /* mobile uses the fixed bars, nothing to collapse */
}

/* ---- mobile: top bar + bottom tab bar ------------------------------------ */
@media (max-width: 640px) {
  /* NOTE: aside must NOT carry backdrop-filter/transform on mobile — that would
     make it the containing block for the fixed-position brand/corner bars. The
     bar backgrounds live on #nav / .brand / .shell-corner themselves instead. */
  #appView aside {
    position: fixed !important;
    left: 0; right: 0; bottom: 0; top: auto !important;
    width: 100% !important;
    height: auto !important;
    padding: 0 !important;
    border-right: 0 !important;
    border-top: 0 !important;
    background: transparent !important;
    -webkit-backdrop-filter: none !important;
    backdrop-filter: none !important;
    box-shadow: none !important;
    z-index: 45;
    flex-direction: row;
    gap: 0;
  }

  /* brand becomes a slim fixed top bar */
  #appView .brand {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: calc(52px + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) 14px 0 14px;
    z-index: 46;
    margin: 0;
  }
  #appView .brand .mark { width: 30px; height: 30px; }
  #appView .brand h1 { font-size: 1.15rem !important; }
  #appView .brand #userLabel { display: none; }

  /* corner controls dock into the top bar, right side */
  #appView .shell-corner {
    position: fixed;
    top: 0; right: 8px;
    height: calc(52px + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) 0 0 0;
    z-index: 47;
    flex-wrap: nowrap;
  }
  #appView .shell-corner #globalMessage { display: none; }
  /* app.css hides #logoutBtn under 720px (legacy); the new top bar has room for it */
  #appView .shell-corner #logoutBtn { display: inline-flex !important; margin-left: 0; }

  /* nav becomes the bottom tab bar */
  #appView #nav {
    display: flex !important;
    flex-direction: row;
    width: 100%;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    gap: 2px;
  }
  #appView .nav-btn {
    flex: 1 1 0;
    flex-direction: column !important;
    justify-content: center;
    gap: 3px !important;
    padding: 6px 2px !important;
    font-size: 0.625rem !important;
    letter-spacing: 0.01em;
    border-radius: 10px !important;
    min-width: 0;
  }
  #appView .nav-btn svg { width: 21px; height: 21px; }
  #appView .nav-btn span { white-space: nowrap; }

  /* Prospects stays off the phone's bottom bar — five tabs is the limit there,
     and most users don't prospect (Josh, 2026-07-24). The phone drawer's
     Prospects entry still reaches it (it clicks this hidden button). */
  #appView .nav-btn[data-page="cold"] { display: none; }

  /* content clears both bars */
  #appView main {
    padding-top: calc(60px + env(safe-area-inset-top)) !important;
    padding-bottom: calc(76px + env(safe-area-inset-bottom)) !important;
  }
}

/* ---- 2026-07-14 (Josh): the dock reads as a vertical LABELED list ------------
   "Dashboard / Activities / Accounts / Profile" written out, one per row.
   THEME: the dock follows the day/night toggle (Josh, 2026-07-14 item 3 —
   an explicit reversal of his same-day "same color as night mode" ask):
   night keeps the notion-dark rows exactly as they were; day gets light
   glass — cream fill, day border, dark text. Geometry is shared.
   #appView in the selectors outranks tilfully-theme's !important resets
   (.nav-btn.active border-color / box-shadow), which load later. */
@media (min-width: 641px) {
  /* expanded: settings + profile become labeled rows like the nav tabs */
  body:not(.sidebar-collapsed) #appView .shell-corner { align-items: stretch; }
  body:not(.sidebar-collapsed) #appView #settingsBtn::after { content: 'Settings'; }
  body:not(.sidebar-collapsed) #appView #profileBtn::after { content: 'Profile'; }

  /* ---- geometry: ALL five rows identical (Josh, round 3: "I want all of
     them to be like that. Vertical."), expanded = labeled rows ... */
  body:not(.sidebar-collapsed) #appView aside .nav-btn:not(.nav-profile-tab),
  body:not(.sidebar-collapsed) #appView aside .shell-corner .icon-button {
    width: 100%; height: auto; min-height: 0;
    display: inline-flex; align-items: center; justify-content: flex-start;
    gap: 10px; padding: 9px 12px;
    border-width: 1px; border-style: solid;
    border-radius: 10px !important;
    font-size: 0.85rem; font-weight: 700;
    box-shadow: none !important;
  }
  body:not(.sidebar-collapsed) #appView aside .nav-btn:hover,
  body:not(.sidebar-collapsed) #appView aside .shell-corner .icon-button:hover { transform: none; }
  /* ... collapsed = one outlined square per tab */
  body.sidebar-collapsed #appView aside .nav-btn:not(.nav-profile-tab),
  body.sidebar-collapsed #appView aside .shell-corner .icon-button {
    width: 38px; height: 38px; min-height: 0; margin: 0 auto;
    display: inline-flex; align-items: center; justify-content: center;
    padding: 0 !important;
    border-width: 1px; border-style: solid;
    border-radius: 10px !important;
    box-shadow: none !important;
  }

  /* ---- night colors (unchanged from the round-3 look) */
  body.night-mode #appView aside .nav-btn:not(.nav-profile-tab),
  body.night-mode #appView aside .shell-corner .icon-button {
    background: #1a1f2b !important;
    border-color: #343a47 !important;
    color: rgba(245, 242, 236, 0.88) !important;
  }
  body.night-mode #appView aside .nav-btn:not(.nav-profile-tab):hover,
  body.night-mode #appView aside .shell-corner .icon-button:hover {
    background: #232939 !important;
    border-color: #4a5163 !important;
  }
  body.night-mode #appView aside .nav-btn.active {
    background: #232939 !important;
    border-color: rgba(217, 154, 43, 0.55) !important;   /* amber ring marks the page you're on */
    color: #fffefa !important;
  }

  /* ---- day colors: light glass, cream fill, day border, dark text */
  body:not(.night-mode) #appView aside {
    background: rgba(255, 253, 246, 0.88) !important;
    border-color: var(--t-day-line) !important;
  }
  body:not(.night-mode) #appView aside .brand h1 { color: var(--t-day-ink) !important; }
  body:not(.night-mode) #appView aside .brand #userLabel { color: var(--t-day-muted) !important; }
  body:not(.night-mode) #appView aside .nav-btn:not(.nav-profile-tab),
  body:not(.night-mode) #appView aside .shell-corner .icon-button {
    background: rgba(255, 253, 246, 0.9) !important;
    border-color: var(--t-day-line) !important;
    color: var(--t-day-ink) !important;
  }
  body:not(.night-mode) #appView aside .nav-btn:not(.nav-profile-tab):hover,
  body:not(.night-mode) #appView aside .shell-corner .icon-button:hover {
    background: #f4efe3 !important;
    border-color: var(--t-day-line-hi) !important;
  }
  body:not(.night-mode) #appView aside .nav-btn.active {
    background: rgba(169, 118, 29, 0.10) !important;
    border-color: rgba(169, 118, 29, 0.5) !important;   /* the same amber ring, day-weighted */
    color: var(--t-day-ink) !important;
  }
}
