/* Dashboard navigation: a sidebar that is always visible on desktop, tabs inside each section,
   and a bottom tab bar on phones. Loaded after the dashboard styles so it wins over older rules. */

/* ---------- Sidebar (desktop) ---------- */
#dash .d-shell { grid-template-columns: 216px minmax(0, 1fr); gap: 32px; align-items: start; }
.d-side { position: sticky; top: calc(env(safe-area-inset-top, 0px) + 84px); max-height: calc(100vh - 100px); max-height: calc(100dvh - 100px); overflow-y: auto; }
#d-nav.d-nav { position: static; display: grid; gap: 2px; padding: 0; margin: 0; background: transparent; overflow: visible; }
#d-nav button, #d-bottom button, #d-more-list button { all: unset; box-sizing: border-box; cursor: pointer; display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 9px 12px; border-radius: 10px; font: 500 15px/1.25 var(--body); color: var(--muted); transition: background .15s ease, color .15s ease; }
#d-nav button:hover, #d-more-list button:hover { background: var(--surface); color: var(--fg); }
#d-nav button:focus-visible, #d-bottom button:focus-visible, #d-more-list button:focus-visible, .d-tabs button:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
#d-nav button[aria-current="page"] { background: color-mix(in srgb, var(--gold) 14%, var(--bg)); color: var(--fg); font-weight: 600; box-shadow: inset 3px 0 var(--gold); }
.ni { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#d-nav .nl, #d-more-list .nl { flex: 1; }
#dash .badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--gold); color: var(--on-gold, #111); font: 700 11px/20px var(--body); text-align: center; }

/* ---------- Tabs inside a section ---------- */
.d-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; margin-top: -8px; }
.d-tabs::-webkit-scrollbar { display: none; }
.d-tabs[hidden] { display: none; }
.d-tabs button { all: unset; box-sizing: border-box; cursor: pointer; display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; min-height: 44px; padding: 10px 14px; font: 600 14px/1 var(--body); color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.d-tabs button:hover { color: var(--fg); }
.d-tabs button[aria-current="page"] { color: var(--fg); border-bottom-color: var(--gold); }

/* ---------- Header + account menu ---------- */
.d-top .d-wrap { flex-wrap: nowrap; }
.d-account .d-actions { min-width: 220px; }
#d-menu-sections { display: none !important; }

/* ---------- Bottom bar and "More" sheet (phones) ---------- */
.d-bottom, .d-more { display: none; }

@media (max-width: 860px) {
  #dash .d-shell { grid-template-columns: minmax(0, 1fr); gap: 0; }
  .d-side { display: none; }
  #dash .d-main { padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px)); }
  .d-bottom:not([hidden]) { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); position: fixed; z-index: 30; left: 0; right: 0; bottom: 0; padding: 6px 6px calc(6px + env(safe-area-inset-bottom, 0px)); background: var(--bg); border-top: 1px solid var(--line); box-shadow: 0 -6px 20px #0000000f; }
  #d-bottom button { position: relative; flex-direction: column; justify-content: center; gap: 3px; min-height: 56px; padding: 6px 2px; font-size: 11px; font-weight: 600; text-align: center; border-radius: 12px; }
  #d-bottom button .ni { width: 22px; height: 22px; }
  #d-bottom button[aria-current="page"] { color: var(--fg); background: color-mix(in srgb, var(--gold) 14%, var(--bg)); }
  #d-bottom .badge { position: absolute; top: 2px; left: calc(50% + 6px); min-width: 18px; height: 18px; font-size: 10px; line-height: 18px; padding: 0 5px; }
  .d-more:not([hidden]) { display: block; position: fixed; inset: 0; z-index: 29; background: #0006; }
  .d-more-in { position: absolute; left: 8px; right: 8px; bottom: calc(76px + env(safe-area-inset-bottom, 0px)); background: var(--bg); border: 1px solid var(--line); border-radius: 16px; padding: 8px; box-shadow: 0 12px 32px #0003; }
  .d-more-list { display: grid; gap: 2px; }
  #d-more-list button { min-height: 52px; font-size: 16px; }
  #d-more-list button[aria-current="page"] { color: var(--fg); font-weight: 600; background: color-mix(in srgb, var(--gold) 14%, var(--bg)); }

  /* One-row header: logo, role, add, account. */
  .d-top { position: sticky; top: 0; }
  .d-top .d-wrap { gap: 8px; padding-block: 8px; }
  .d-logo { width: 74px; }
  .d-title { flex: 1; flex-wrap: nowrap; gap: 6px; min-width: 0; }
  .d-title h1 { font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .d-title .pv-switcher { display: none; }
  .d-top #d-add { margin-left: 0; padding-inline: 12px; white-space: nowrap; }
  .d-account { margin-left: 0; }
  .d-account summary { padding-inline: 12px; }

  .v-head h2 { font-size: 26px; }
  .d-tabs { margin-top: -4px; margin-inline: calc(-1 * var(--gutter-l, 16px)) calc(-1 * var(--gutter-r, 16px)); padding-inline: var(--gutter-l, 16px); }
  .d-tabs button { padding-inline: 12px; }
  /* Money figures never break across lines. */
  .kpi .k-val { font-size: clamp(22px, 7vw, 30px); white-space: nowrap; overflow-wrap: normal; }
}
@media (max-width: 420px) {
  .d-title .role-chip { display: none; }
  .d-title h1 { font-size: 17px; }
  .kpi { padding: 12px; }
  .kpi .k-val { font-size: clamp(20px, 6.4vw, 26px); }
  .kpi .k-sub { font-size: 12px; }
}
@media (prefers-reduced-motion: reduce) { #d-nav button, #d-bottom button { transition: none; } }
@media print { .d-side, .d-bottom, .d-more, .d-tabs { display: none !important; } }
@media (max-width: 480px) {
  /* The page title below already says where you are; the logo is enough up top. */
  .d-title h1 { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .d-title { flex: 1; }
}
/* Panels that slide over the dashboard (lead, client, member) get the whole screen on phones:
   the bottom tab bar steps aside so their Save buttons are never covered. */
@media (max-width: 860px) {
  body:has(.drawer:not([hidden])) .d-bottom, body:has(.drawer:not([hidden])) .d-more { display: none !important; }
  .drawer .dr-foot { padding-bottom: max(14px, env(safe-area-inset-bottom)); }
}
