/* ================================================
   Pippa's Farm — Frontend App Shell (Mobile-first)
   ================================================ */

:root {
  --pf-bottomnav-h: 64px;
  --pf-topbar-h:    56px;
  --pf-sidebar-w:   240px;
}
@media (min-width: 1024px) {
  :root { --pf-sidebar-w: 260px; --pf-topbar-h: 60px; }
}
@media (min-width: 1280px) {
  :root { --pf-sidebar-w: 280px; }
}

/* ── App container ── */
.pf-app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: #f0f4f1;
  position: relative;
  isolation: isolate;
}

/* ── Top Bar ── */
.pf-app-topbar {
  height: var(--pf-topbar-h);
  background: var(--pf-green, #2d6a4f);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  position: sticky;
  top: 0;
  z-index: 200;
  flex-shrink: 0;
  box-shadow: 0 1px 0 rgba(0,0,0,.15);
}
@media (min-width: 768px) { .pf-app-topbar { padding: 0 20px; } }

.pf-app-topbar-left,
.pf-app-topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Hamburger */
.pf-hamburger {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  width: 22px;
  height: 16px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}
@media (min-width: 768px) { .pf-hamburger { display: none; } }
.pf-hamburger span {
  display: block;
  height: 2px;
  background: rgba(255,255,255,.9);
  border-radius: 2px;
  transition: all .2s;
}
.pf-hamburger.open span:nth-child(1) { transform: rotate(45deg) translate(5px, 5px); }
.pf-hamburger.open span:nth-child(2) { opacity: 0; }
.pf-hamburger.open span:nth-child(3) { transform: rotate(-45deg) translate(5px, -5px); }

.pf-app-brand { display: flex; align-items: center; gap: 8px; }
.pf-app-brand-icon { font-size: 1.3rem; }
.pf-app-brand-name {
  font-size: 1rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: -.3px;
}
@media (max-width: 380px) { .pf-app-brand-name { display: none; } }

.pf-app-date {
  font-size: .75rem;
  color: rgba(255,255,255,.7);
}
@media (max-width: 600px) { .pf-app-date { display: none; } }

.pf-app-user { display: flex; align-items: center; gap: 8px; }
.pf-app-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255,255,255,.2);
  color: #fff;
  font-weight: 800;
  font-size: .85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  border: 2px solid rgba(255,255,255,.3);
}
.pf-app-username {
  color: rgba(255,255,255,.9);
  font-size: .85rem;
  font-weight: 600;
}
@media (max-width: 480px) { .pf-app-username { display: none; } }
.pf-app-logout {
  color: rgba(255,255,255,.7);
  text-decoration: none;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all .15s;
  font-size: 1rem;
}
.pf-app-logout:hover { background: rgba(255,255,255,.15); color: #fff; }

/* ── Body (sidebar + main) ── */
.pf-app-body {
  display: flex;
  flex: 1;
  min-height: 0;
  position: relative;
}

/* ── Sidebar ── */
.pf-app-sidebar {
  width: var(--pf-sidebar-w);
  background: #fff;
  border-right: 1px solid #e5e7eb;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
  z-index: 150;
  transition: transform .25s cubic-bezier(.4,0,.2,1);
  overscroll-behavior: contain;
  scrollbar-width: thin;
  scrollbar-color: #e5e7eb transparent;
}
@media (max-width: 767px) {
  .pf-app-sidebar {
    position: fixed;
    left: 0;
    top: var(--pf-topbar-h);
    bottom: 0;
    transform: translateX(-100%);
    box-shadow: 4px 0 24px rgba(0,0,0,.15);
  }
  .pf-app-sidebar.open { transform: translateX(0); }
}

.pf-app-nav { padding: 8px 0; flex: 1; }

.pf-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 16px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: .875rem;
  font-weight: 500;
  color: #4b5563;
  text-align: left;
  transition: all .15s;
  border-left: 3px solid transparent;
  border-radius: 0;
  font-family: inherit;
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
}
.pf-nav-item:hover { background: #f0f4f1; color: #2d6a4f; }
.pf-nav-item.active {
  background: #d8f3dc;
  color: #2d6a4f;
  border-left-color: #2d6a4f;
  font-weight: 700;
}
.pf-nav-icon { font-size: 1.1rem; width: 24px; text-align: center; flex-shrink: 0; }
.pf-nav-label { flex: 1; }

.pf-app-sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid #e5e7eb;
  font-size: .73rem;
  color: #9ca3af;
  text-transform: uppercase;
  letter-spacing: .5px;
}

/* ── Overlay ── */
.pf-sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 140;
  backdrop-filter: blur(1px);
}
.pf-sidebar-overlay.open { display: block; }

/* ── Main content ── */
.pf-app-main {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  /* Bottom padding for bottom nav on mobile */
  padding-bottom: calc(var(--pf-bottomnav-h) + env(safe-area-inset-bottom));
}
@media (min-width: 768px) { .pf-app-main { padding-bottom: 0; } }

/* ── Sections ── */
.pf-section { display: none; }
.pf-section.active { display: block; }

/* Remove padding from pf-wrap inside app sections */
.pf-app .pf-wrap { max-width: none; }

/* ── Bottom Navigation (mobile only) ── */
.pf-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--pf-bottomnav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: #fff;
  border-top: 1px solid #e5e7eb;
  z-index: 100;
  box-shadow: 0 -4px 20px rgba(0,0,0,.08);
}
@media (max-width: 767px) { .pf-bottom-nav { display: flex; } }

.pf-bottom-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: .63rem;
  font-weight: 600;
  color: #9ca3af;
  cursor: pointer;
  transition: color .15s;
  border: none;
  background: none;
  font-family: inherit;
  padding: 0 4px;
  letter-spacing: .2px;
  -webkit-tap-highlight-color: transparent;
  min-height: 44px;
  position: relative;
}
.pf-bottom-tab.active { color: #2d6a4f; }
.pf-bottom-tab.active::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 32px;
  height: 3px;
  background: #2d6a4f;
  border-radius: 0 0 4px 4px;
}
.pf-bottom-tab-icon {
  font-size: 1.35rem;
  line-height: 1;
}

/* ── More drawer ── */
.pf-more-drawer {
  position: fixed;
  bottom: calc(var(--pf-bottomnav-h) + env(safe-area-inset-bottom));
  left: 0;
  right: 0;
  background: #fff;
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -8px 32px rgba(0,0,0,.15);
  z-index: 99;
  transform: translateY(100%);
  transition: transform .3s cubic-bezier(.4,0,.2,1);
  max-height: 70dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.pf-more-drawer.open { transform: translateY(0); }
.pf-more-drawer-handle {
  width: 36px;
  height: 4px;
  background: #e5e7eb;
  border-radius: 4px;
  margin: 12px auto 8px;
}
.pf-more-drawer-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  background: #f3f4f6;
  border-top: 1px solid #e5e7eb;
}
.pf-more-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 16px 8px;
  background: #fff;
  cursor: pointer;
  font-size: .75rem;
  font-weight: 600;
  color: #374151;
  text-align: center;
  border: none;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  transition: background .1s;
}
.pf-more-item:active { background: #f0f4f1; }
.pf-more-item-icon { font-size: 1.6rem; }
.pf-more-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 98;
  background: rgba(0,0,0,.3);
}
.pf-more-overlay.open { display: block; }

/* ── Login / Access screens ── */
.pf-login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 24px 16px;
  background: linear-gradient(135deg, #1b4332 0%, #2d6a4f 50%, #40916c 100%);
}
.pf-login-box {
  background: #fff;
  border-radius: 24px;
  padding: 36px 28px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
@media (min-width: 480px) { .pf-login-box { padding: 44px 40px; } }

.pf-access-denied {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 40vh;
  padding: 40px 20px;
  text-align: center;
  color: #6b7280;
}

/* ── Scrollbar ── */
.pf-app-sidebar::-webkit-scrollbar,
.pf-app-main::-webkit-scrollbar,
.pf-more-drawer::-webkit-scrollbar { width: 3px; }
.pf-app-sidebar::-webkit-scrollbar-thumb,
.pf-app-main::-webkit-scrollbar-thumb,
.pf-more-drawer::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ================================================
   DESKTOP ENHANCEMENTS
   ================================================ */

/* Wider top bar on desktop */
@media (min-width: 768px) {
  .pf-app-topbar { height: var(--pf-topbar-h); padding: 0 24px; }
  .pf-app-sidebar { top: var(--pf-topbar-h); }
}

/* Sidebar — always visible, collapsible label on large */
@media (min-width: 768px) {
  .pf-app-sidebar {
    position: sticky;
    top: 0;
    height: calc(100dvh - var(--pf-topbar-h));
    transform: none !important;
    box-shadow: none;
  }
  .pf-app-body { height: calc(100dvh - var(--pf-topbar-h)); overflow: hidden; }
  .pf-app-main { height: 100%; }
}

/* Desktop nav items — larger, spaced */
@media (min-width: 1024px) {
  .pf-nav-item { padding: 11px 20px; font-size: .9rem; }
  .pf-nav-icon { font-size: 1.2rem; }
  .pf-app-sidebar-footer { padding: 16px 20px; }
}

/* Main content — max width on very wide screens */
@media (min-width: 1400px) {
  .pf-app-main { background: var(--pf-bg, #f0f4f1); }
  .pf-app .pf-wrap { max-width: 1280px; }
}

/* Desktop top bar — show all elements */
@media (min-width: 768px) {
  .pf-app-brand-name { display: flex !important; }
  .pf-app-date       { display: block !important; }
  .pf-app-username   { display: block !important; }
}

/* ── Mobile: full-width content padding ── */
@media (max-width: 479px) {
  .pf-app .pf-wrap { padding: 12px; }
}

/* ── iOS safe area: main content bottom ── */
.pf-app-main {
  padding-bottom: max(
    calc(var(--pf-bottomnav-h) + env(safe-area-inset-bottom)),
    env(safe-area-inset-bottom)
  );
}
@media (min-width: 768px) {
  .pf-app-main { padding-bottom: env(safe-area-inset-bottom, 0px); }
}

/* ═══════════════════════════════════════
   PHASE 1 — NEW MOBILE NAVIGATION
   ═══════════════════════════════════════ */

/* ── Updated color scheme ── */
:root {
  --pf-brand: #0F6E56;
  --pf-brand-dark: #085041;
  --pf-brand-pale: #E1F5EE;
  --pf-nav-h: 56px;
}

/* ── Bottom nav: 5 items ── */
.pf-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--pf-nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: #fff;
  border-top: 1px solid #e0e0d8;
  z-index: 1000;
  box-shadow: 0 -2px 12px rgba(0,0,0,.06);
}
@media (max-width: 768px) { .pf-bottom-nav { display: flex; } }

.pf-bottom-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 9px;
  font-weight: 600;
  color: #9ca3af;
  border: none;
  background: none;
  cursor: pointer;
  font-family: inherit;
  padding: 0 2px;
  min-height: 44px;
  letter-spacing: .1px;
  -webkit-tap-highlight-color: transparent;
  transition: color .15s;
  position: relative;
}
.pf-bottom-tab.active { color: #0F6E56; }
.pf-bottom-tab.active::before {
  content: '';
  position: absolute;
  top: 0; left: 50%;
  transform: translateX(-50%);
  width: 28px; height: 3px;
  background: #0F6E56;
  border-radius: 0 0 4px 4px;
}
.pf-bottom-tab-icon { font-size: 1.3rem; line-height: 1; }

/* ── Left Drawer ── */
.pf-drawer-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 10000;
  backdrop-filter: blur(1px);
}
.pf-drawer-overlay.open { display: block; }

.pf-left-drawer {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: 260px;
  background: #fff;
  z-index: 10001;
  transform: translateX(-100%);
  transition: transform .25s cubic-bezier(.4,0,.2,1);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 4px 0 32px rgba(0,0,0,.2);
}
.pf-left-drawer.open { transform: translateX(0); }

.pf-drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px;
  background: #0F6E56;
  flex-shrink: 0;
}
.pf-drawer-brand {
  font-size: 1rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: -.2px;
}
.pf-drawer-close {
  background: rgba(255,255,255,.15);
  border: none;
  color: #fff;
  width: 32px; height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.pf-drawer-nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0 16px;
  -webkit-overflow-scrolling: touch;
}
.pf-drawer-group { margin-bottom: 4px; }
.pf-drawer-group-label {
  padding: 10px 16px 4px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: #888780;
}
.pf-drawer-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 20px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: .875rem;
  font-weight: 500;
  color: #374151;
  text-align: left;
  font-family: inherit;
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
  transition: background .1s, color .1s;
}
.pf-drawer-item:hover,
.pf-drawer-item:active { background: #f0f4f1; }
.pf-drawer-item.active { color: #0F6E56; font-weight: 700; background: #E1F5EE; }

/* ── FAB ── */
.pf-fab-log {
  display: none;
  position: fixed;
  bottom: calc(var(--pf-nav-h) + env(safe-area-inset-bottom) + 12px);
  right: 16px;
  background: #0F6E56;
  color: #fff;
  font-size: .875rem;
  font-weight: 700;
  padding: 12px 20px;
  border-radius: 50px;
  text-decoration: none;
  box-shadow: 0 4px 16px rgba(15,110,86,.4);
  z-index: 999;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  transition: transform .15s, box-shadow .15s;
}
.pf-fab-log:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(15,110,86,.5); }
@media (max-width: 768px) {
  #pf-app.pf-on-dashboard .pf-fab-log { display: flex; align-items: center; gap: 6px; }
}

/* ── Main content bottom padding for nav ── */
@media (max-width: 768px) {
  #pf-app .pf-app-main {
    padding-bottom: calc(var(--pf-nav-h) + env(safe-area-inset-bottom) + 8px) !important;
  }
}

/* ── FIX 15: Compact header on mobile ── */
@media (max-width: 768px) {
  .pf-app-topbar {
    height: 44px !important;
    padding: 0 12px !important;
  }
  .pf-app-date { display: none !important; }
  .pf-app-brand-name { font-size: .9rem; }
  .pf-app-avatar { width: 28px; height: 28px; font-size: .75rem; }
  /* Push content down by correct amount */
  :root { --pf-topbar-h: 44px; }
}

/* ── FIX 16: Content area padding on mobile ── */
@media (max-width: 768px) {
  #pf-app .pf-wrap {
    padding-left: 12px !important;
    padding-right: 12px !important;
    padding-top: 12px;
  }
}

/* ── Farm logo in top bar + drawer ── */
.pf-app-brand-logo {
  width: 32px; height: 32px;
  border-radius: 8px;
  object-fit: cover;
  background: rgba(255,255,255,.15);
  flex-shrink: 0;
}
.pf-drawer-logo {
  width: 24px; height: 24px;
  border-radius: 6px;
  object-fit: cover;
  vertical-align: middle;
  margin-right: 4px;
}
