/* ==========================================================================
   Breeder Portal - application layout
   Phone  (< 768):  top bar + content + bottom navigation with a centre New button
   Tablet (>= 768): 72px navigation rail + top bar + content
   Desktop(>= 1024): 232px sidebar + compact header + content
   Mobile-first: the rules without a media query are the phone layout.
   ========================================================================== */

.p-app {
  min-height: 100vh;
  min-height: 100dvh;
  display: block;
}

.p-shell { min-width: 0; display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }

/* ---------- Top bar (phone: 52px, desktop: 48px) ---------- */
.p-topbar {
  position: sticky; top: 0; z-index: var(--z-nav);
  display: flex; align-items: center; gap: var(--sp-2);
  height: calc(var(--h-topbar) + var(--safe-top));
  padding: var(--safe-top) var(--sp-2) 0 var(--sp-4);
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
}
.p-topbar--back { padding-left: var(--sp-1); }
.p-topbar__title {
  flex: 1 1 auto; min-width: 0;
  font-size: var(--fs-xl); line-height: var(--lh-tight); font-weight: var(--fw-semibold);
  letter-spacing: -0.005em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.p-topbar__sub { display: block; font-size: var(--fs-xs); font-weight: var(--fw-regular); color: var(--c-text-3); letter-spacing: 0; }
.p-topbar__actions { display: flex; align-items: center; gap: var(--sp-1); flex-shrink: 0; }
.p-topbar__search { display: none; }

/* ---------- Content ---------- */
.p-main { flex: 1 1 auto; min-width: 0; padding: var(--sp-4) var(--sp-4) calc(var(--h-bottomnav) + var(--safe-bottom) + var(--sp-6)); }
.p-page { max-width: var(--w-content); margin: 0 auto; display: flex; flex-direction: column; gap: var(--sp-5); }
.p-page--form { max-width: var(--w-form); }
.p-page--narrow { max-width: 800px; }

/* Optional page heading row (tablet and up show tools next to the page; phones keep tools in the page body) */
.p-page-tools { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap; }

/* Two-column content */
.p-cols { display: grid; gap: var(--sp-4); grid-template-columns: minmax(0, 1fr); align-items: start; }

/* Section heading inside a page (small, quiet: not a second page title) */
.p-section-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-3); margin-bottom: var(--sp-2); }
.p-section-head h2 { font-size: var(--fs-md); }

/* ---------- Bottom navigation (phones) ---------- */
.p-bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-nav);
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--h-bottomnav) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--c-surface);
  border-top: 1px solid var(--c-border);
}
.p-bottomnav__item {
  position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 44px;
  color: var(--c-text-3);
  font-size: var(--fs-2xs); line-height: 1.1; font-weight: var(--fw-medium);
  text-decoration: none;
  transition: color var(--dur-fast) var(--ease);
}
.p-bottomnav__item:hover { text-decoration: none; color: var(--c-text-2); }
.p-bottomnav__item[aria-current="page"] { color: var(--c-primary-text); font-weight: var(--fw-semibold); }
.p-bottomnav__item[aria-current="page"]::before {
  content: ""; position: absolute; top: 0; left: 50%; width: 24px; height: 2px; margin-left: -12px;
  background: var(--c-primary); border-radius: 0 0 2px 2px;
}
.p-bottomnav__badge {
  position: absolute; top: 6px; left: calc(50% + 6px);
  min-width: 16px; height: 16px; padding: 0 4px; border-radius: var(--r-full);
  background: var(--c-danger); color: var(--c-on-danger); font-size: 10px; line-height: 16px; font-weight: var(--fw-semibold); text-align: center;
}

/* Centre action: the "New transaction" button sits in the middle of the bottom nav (two destinations each side).
   48px, lifted 10px above the bar; the surface-coloured ring cuts a notch in the bar's top border. */
.p-bottomnav__add {
  position: relative; z-index: 1;
  justify-self: center; align-self: center;
  width: 48px; height: 48px; padding: 0; border: 0; border-radius: var(--r-lg);
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--c-primary); color: var(--c-on-primary);
  transform: translateY(-10px);
  box-shadow: 0 0 0 4px var(--c-surface), var(--sh-2);
  transition: background var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.p-bottomnav__add:hover { background: var(--c-primary-hover); }
.p-bottomnav__add:active { transform: translateY(-10px) scale(0.96); background: var(--c-primary-press); }
.p-bottomnav__add:focus-visible { border-radius: var(--r-lg); }   /* base.css resets the radius on focus; keep the shape */

/* Focus mode: full-page forms hide the bottom navigation so the action bar owns the bottom edge */
.p-focus .p-bottomnav { display: none; }
.p-focus .p-main { padding-bottom: calc(76px + var(--safe-bottom)); }

/* ---------- Sidebar / rail (tablet and desktop) ---------- */
.p-sidebar { display: none; }

@media (min-width: 768px) {
  .p-app { display: grid; grid-template-columns: var(--w-rail) minmax(0, 1fr); }

  .p-sidebar {
    position: sticky; top: 0; height: 100vh; height: 100dvh;
    display: flex; flex-direction: column; align-items: stretch; gap: var(--sp-2);
    padding: var(--sp-3) var(--sp-2);
    background: var(--c-surface);
    border-right: 1px solid var(--c-border);
    z-index: var(--z-nav);
  }
  .p-bottomnav { display: none; }
  .p-focus .p-sidebar { display: flex; }

  .p-topbar { height: var(--h-topbar-desktop); padding: 0 var(--sp-4) 0 var(--sp-6); }
  .p-topbar--back { padding-left: var(--sp-3); }
  .p-topbar__title { font-size: var(--fs-lg); }

  .p-main, .p-focus .p-main { padding: var(--sp-6); }

  .p-cols { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .p-page { gap: var(--sp-6); }
}

@media (min-width: 1024px) {
  .p-app { grid-template-columns: var(--w-sidebar) minmax(0, 1fr); }
  .p-sidebar { padding: var(--sp-3); }
  .p-topbar__search { display: block; width: 280px; }
  .p-cols--aside { grid-template-columns: minmax(0, 1fr) 340px; }
}

/* ---------- Sidebar parts ---------- */
.p-brand { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-1) var(--sp-1) var(--sp-3); min-height: 44px; }
.p-brand__logo { flex-shrink: 0; width: var(--h-sm); height: var(--h-sm); border-radius: 50%; }   /* the app icon (img/app/icon-192.png) */
.p-brand__text { display: none; min-width: 0; line-height: var(--lh-tight); }
.p-brand__name { display: block; font-weight: var(--fw-semibold); font-size: var(--fs-md); }
.p-brand__branch { display: block; font-size: var(--fs-xs); color: var(--c-text-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.p-nav { display: flex; flex-direction: column; gap: 2px; }
.p-nav__item {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 52px; padding: var(--sp-2) 0; border-radius: var(--r-md);
  color: var(--c-text-2); font-size: var(--fs-2xs); font-weight: var(--fw-medium); line-height: 1.1;
  text-decoration: none;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}
.p-nav__item:hover { background: var(--c-surface-hover); color: var(--c-text); text-decoration: none; }
.p-nav__item[aria-current="page"] { background: var(--c-primary-soft); color: var(--c-primary-text); font-weight: var(--fw-semibold); }
.p-nav__count { margin-left: auto; font-size: var(--fs-xs); color: var(--c-text-3); font-variant-numeric: tabular-nums; display: none; }

.p-sidebar__foot { margin-top: auto; display: flex; flex-direction: column; gap: 2px; }
.p-sidebar__foot .p-nav__label { display: none; }   /* the rail shows the avatar only */
/* the signed-in person at the foot of the sidebar (the first preview used inline styles for these; the real pages forbid inline styles) */
.p-sidebar__foot .p-menu-wrap { width: 100%; }
.p-nav__item--user { width: 100%; border: 0; background: none; }
.p-nav__label--grow { flex: 1; text-align: left; }

@media (min-width: 1024px) {
  .p-brand__text { display: block; }
  .p-nav__item {
    flex-direction: row; justify-content: flex-start; gap: var(--sp-3);
    min-height: var(--h-lg); padding: 0 var(--sp-3);
    font-size: var(--fs-md);
  }
  .p-nav__count { display: inline; }
  .p-sidebar__foot .p-nav__label { display: inline; }
}

/* ---------- Form page action bar ---------- */
.p-actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-nav);
  display: flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4) calc(var(--sp-3) + var(--safe-bottom));
  background: var(--c-surface); border-top: 1px solid var(--c-border);
}
.p-actionbar > .p-btn--primary { flex: 1 1 auto; }

@media (min-width: 768px) {
  .p-actionbar {
    position: static; z-index: auto; justify-content: flex-end;
    padding: var(--sp-4) 0 0; background: transparent; border-top: 1px solid var(--c-divider);
    margin-top: var(--sp-2);
  }
  .p-actionbar > .p-btn--primary { flex: 0 0 auto; }
  .p-card .p-actionbar { padding: var(--sp-4); margin: var(--sp-4) calc(var(--sp-4) * -1) calc(var(--sp-4) * -1); }
}
