/* ================================================================
   UPAYOG PRO — Layout Styles  (Mobile-First)
   Sidebar · Topbar · Bottom Nav · Page Shell · Responsive
================================================================ */

/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
body { overflow-x: hidden; overscroll-behavior: none; }

::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 99px; }

/* ═══════════════════════════════════════════════════
   LOGIN SCREEN
═══════════════════════════════════════════════════ */
#loginScreen {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(145deg, #1e3a5f 0%, #2563eb 55%, #0f172a 100%);
  padding: 16px;
  padding-top: calc(16px + var(--safe-top));
  padding-bottom: calc(16px + var(--safe-bottom));
}
#loginScreen.hidden { display: none; }

.login-wrap {
  width: 100%; max-width: 400px;
  background: rgba(255,255,255,.97);
  border-radius: 20px;
  padding: 32px 28px;
  box-shadow: var(--shadow-lg);
}
.login-brand {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 28px;
}
.login-logo {
  width: 46px; height: 46px; flex-shrink: 0;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  border-radius: 13px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  box-shadow: 0 4px 12px rgba(37,99,235,.4);
}
.login-brand-name { font-size: 18px; font-weight: 800; letter-spacing: -.5px; color: var(--text); }
.login-brand-sub  { font-size: 11px; color: var(--text3); margin-top: 1px; font-weight: 500; }

.login-title { font-size: 21px; font-weight: 800; margin-bottom: 5px; letter-spacing: -.5px; }
.login-sub   { font-size: 13px; color: var(--text3); margin-bottom: 22px; }

.role-toggle {
  display: grid; grid-template-columns: 1fr 1fr; gap: 5px;
  margin-bottom: 20px;
  background: var(--bg); padding: 4px; border-radius: 10px;
}
.role-btn {
  padding: 10px 8px; border-radius: 7px; border: none;
  background: transparent; cursor: pointer;
  font-size: 13px; font-weight: 600; font-family: var(--font);
  color: var(--text3); transition: all var(--dur);
  display: flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--touch-min);
}
.role-btn.active { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }

.login-err {
  background: var(--red-l); border: 1px solid var(--red-m);
  border-radius: var(--radius-sm); padding: 10px 13px;
  font-size: 13px; color: var(--red); margin-bottom: 14px; display: none;
}
.login-hint {
  margin-top: 14px; background: var(--accent-l); border: 1px solid var(--accent-m);
  border-radius: var(--radius-sm); padding: 10px 13px;
  font-size: 12px; color: var(--accent-d);
}
.login-hint code {
  font-family: var(--mono); background: rgba(37,99,235,.1);
  padding: 1px 5px; border-radius: 4px; font-size: 11px;
}
.btn-login {
  width: 100%; padding: 14px;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  border: none; border-radius: var(--radius-sm);
  color: #fff; font-size: 15px; font-weight: 700;
  cursor: pointer; font-family: var(--font);
  transition: opacity .2s, transform .1s;
  box-shadow: 0 4px 16px rgba(37,99,235,.35);
  min-height: var(--touch-min);
  margin-top: 4px;
}
.btn-login:hover  { opacity: .92; }
.btn-login:active { transform: scale(.99); }

/* ═══════════════════════════════════════════════════
   APP SHELL
═══════════════════════════════════════════════════ */
#app { display: none; min-height: 100vh; }
#app.active { display: flex; }

/* ════════════════════════════════════════════════════
   SIDEBAR  (desktop pinned / mobile drawer)
════════════════════════════════════════════════════ */
.sidebar {
  width: var(--sidebar);
  height: 100vh; /* 🚀 FIXED: Strict height locks it to the screen and forces vertical scrolling */
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; z-index: 200;
  overflow-y: auto; 
  overflow-x: hidden; /* 🚀 SAFETY: Prevents accidental side-to-side scrolling */
  overscroll-behavior: contain;
  transition: transform var(--dur-slow) var(--ease);
}

.sb-logo { padding: 16px 14px 12px; border-bottom: 1px solid var(--border); }
.sb-logo-row { display: flex; align-items: center; gap: 10px; }
.sb-logo-icon {
  width: 34px; height: 34px; flex-shrink: 0;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
}
.sb-logo-name { font-size: 14px; font-weight: 800; letter-spacing: -.3px; }
.sb-logo-sub  { font-size: 10.5px; color: var(--text3); margin-top: 1px; font-weight: 500; }

.sb-user {
  margin: 10px 10px 4px;
  padding: 10px 12px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}
.sb-user-name { font-size: 13px; font-weight: 700; color: var(--text); }
.sb-user-role {
  display: inline-flex; align-items: center; gap: 4px;
  margin-top: 3px; font-size: 10.5px; font-weight: 600;
  padding: 2px 8px; border-radius: 99px;
  letter-spacing: .3px; text-transform: uppercase;
}
.role-admin    { background: var(--accent-l); color: var(--accent); }
.role-gatherer { background: var(--cyan-l);   color: var(--cyan); }

/* 🚀 FIXED: Forces perfect uniform spacing and ignores invisible text lines */
.sb-nav { 
  padding: 6px 8px; 
  flex: 1; 
  display: flex; 
  flex-direction: column; 
  gap: 4px; /* Change this number to make the gap bigger or smaller! */
}
.sb-section {
  font-size: 10px; font-weight: 700; color: var(--text4);
  letter-spacing: .9px; text-transform: uppercase;
  padding: 12px 10px 4px;
}
.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 10px 11px; border-radius: var(--radius-sm);
  cursor: pointer; color: var(--text3);
  font-size: 13px; font-weight: 500;
  transition: all var(--dur-fast);
  margin-bottom: 1px; user-select: none;
  border: 1px solid transparent;
  min-height: var(--touch-min);
}
.nav-item:hover  { background: var(--bg); color: var(--text); }
.nav-item.active {
  background: var(--accent-l); color: var(--accent);
  font-weight: 600; border-color: var(--accent-m);
}
.nav-item .ni { width: 18px; text-align: center; font-size: 15px; flex-shrink: 0; }
.nav-badge {
  margin-left: auto; font-size: 10px;
  background: var(--red); color: #fff;
  padding: 2px 7px; border-radius: 99px; font-weight: 700;
  min-width: 20px; text-align: center;
}

.sb-foot { padding: 8px; border-top: 1px solid var(--border); }
.sb-stat { font-size: 11.5px; color: var(--text3); padding: 4px 10px; line-height: 1.4; }
.sb-stat strong { color: var(--text); display: block; font-size: 13px; font-weight: 700; font-family: var(--mono); }
.btn-logout {
  width: 100%; margin-top: 6px; padding: 10px;
  background: var(--red-l); border: 1px solid var(--red-m);
  border-radius: var(--radius-sm); color: var(--red);
  font-size: 13px; font-weight: 600; cursor: pointer;
  font-family: var(--font); transition: opacity .2s;
  min-height: var(--touch-min);
}
.btn-logout:hover { opacity: .8; }

/* ════════════════════════════════════════════════════
   MAIN AREA
════════════════════════════════════════════════════ */
.main {
  margin-left: var(--sidebar);
  flex: 1; min-height: 100vh;
  display: flex; flex-direction: column;
}

/* ── TOPBAR ── */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  padding-left: calc(20px + var(--safe-left));
  padding-right: calc(20px + var(--safe-right));
  height: var(--topbar-h);
  display: flex; align-items: center;
  justify-content: space-between;
  position: sticky; top: 0; z-index: 50;
  flex-shrink: 0; gap: 10px;
}
.topbar-title {
  font-size: 15px; font-weight: 700; color: var(--text);
  flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar-search {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg); border: 1.5px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 12px;
  width: 220px; transition: border var(--dur-fast);
}
.topbar-search:focus-within { border-color: var(--accent); }
.topbar-search input {
  background: none; border: none; outline: none;
  color: var(--text); font-size: 13px; width: 100%; font-family: var(--font);
}
.topbar-actions { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }

/* ── PAGE CONTENT ── */
.page {
  padding: 20px 22px 48px;
  animation: pageFadeIn .18s ease;
}
@keyframes pageFadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }

/* ── HAMBURGER BUTTON ── */
.btn-hamburger {
  display: none;
  background: none; border: 1.5px solid var(--border);
  border-radius: var(--radius-xs); padding: 7px 9px;
  cursor: pointer; font-size: 17px; color: var(--text2);
  min-width: 40px; min-height: 40px;
  align-items: center; justify-content: center;
  flex-shrink: 0;
}

/* ── SIDEBAR OVERLAY ── */
.sidebar-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 199;
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}

/* ── CLOUD SYNC STATUS BAR ── */
.sync-bar {
  background: var(--green-l); border-bottom: 1px solid var(--green-m);
  padding: 6px 20px; font-size: 12px; color: #065f46;
  display: flex; align-items: center; gap: 8px;
}
.sync-bar.warning { background: var(--amber-l); border-color: var(--amber-m); color: #78350f; }
.sync-bar.error   { background: var(--red-l);   border-color: var(--red-m);   color: #991b1b; }
.sync-bar.hidden  { display: none; }
.sync-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--green); animation: dotPulse 2s infinite; flex-shrink: 0;
}
@keyframes dotPulse { 0%,100%{opacity:1;} 50%{opacity:.4;} }
@keyframes spin      { to { transform: rotate(360deg); } }

/* ── GRID HELPERS ── */
.two-col   { display: grid; grid-template-columns: 1fr 1fr;     gap: 16px; }
.three-col { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }

/* ════════════════════════════════════════════════════
   BOTTOM NAVIGATION  (mobile only — hidden on desktop)
════════════════════════════════════════════════════ */
#bottomNav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 150;
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: var(--shadow-up);
  padding-bottom: var(--safe-bottom);
}
.bottom-nav-inner {
  display: flex;
  height: var(--bottom-nav-h);
}
.bn-item {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 3px; cursor: pointer; border: none;
  background: transparent; font-family: var(--font);
  color: var(--text4); transition: color var(--dur-fast);
  padding: 0 4px; position: relative;
  -webkit-tap-highlight-color: transparent;
}
.bn-item.active { color: var(--accent); }
.bn-icon {
  font-size: 20px; line-height: 1;
  transition: transform var(--dur-fast) var(--ease-bounce);
}
.bn-item.active .bn-icon { transform: scale(1.18); }
.bn-label { font-size: 10px; font-weight: 600; letter-spacing: .1px; white-space: nowrap; }
.bn-badge {
  position: absolute; top: 6px; right: calc(50% - 18px);
  background: var(--red); color: #fff;
  font-size: 9px; font-weight: 700;
  padding: 1px 5px; border-radius: 99px;
  min-width: 16px; text-align: center;
  border: 1.5px solid var(--surface);
}

.bn-item::before {
  content: '';
  position: absolute; top: 0; left: 20%; right: 20%; height: 2px;
  background: var(--accent); border-radius: 0 0 3px 3px;
  transform: scaleX(0); transition: transform var(--dur) var(--ease-bounce);
}
.bn-item.active::before { transform: scaleX(1); }

/* ════════════════════════════════════════════════════
   FAB  (Floating Action Button — mobile quick entry)
════════════════════════════════════════════════════ */
#mobileFab {
  display: none;
  position: fixed;
  right: 18px;
  bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 14px);
  z-index: 149;
  width: 54px; height: 54px;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  border-radius: 50%;
  box-shadow: 0 4px 16px rgba(37,99,235,.45);
  border: none; cursor: pointer; font-size: 22px;
  align-items: center; justify-content: center;
  transition: transform .2s var(--ease-bounce), box-shadow .2s;
  color: #fff;
}
#mobileFab:active { transform: scale(.92); }

/* ════════════════════════════════════════════════════
   RESPONSIVE  — Mobile breakpoint
════════════════════════════════════════════════════ */
@media (max-width: 768px) {

  .sidebar {
    transform: translateX(-100%);
    width: min(280px, 85vw);
    height: 100%;
    top: 0;
    padding-top: var(--safe-top);
    padding-bottom: calc(var(--safe-bottom) + var(--bottom-nav-h));
  }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .sidebar-overlay.open { display: block; }

  .btn-hamburger { display: flex; }
  .sb-foot { padding-bottom: 8px; }

  .main {
    margin-left: 0;
    padding-bottom: calc(var(--bottom-nav-h) + var(--safe-bottom));
  }

  .topbar {
    padding: 0 12px;
    padding-top: var(--safe-top);
    height: calc(var(--topbar-h) + var(--safe-top));
    gap: 8px;
  }
  .topbar-title { font-size: 14px; }
  .topbar-search { width: 160px; }

  .page { padding: 14px 14px 24px; }

  #bottomNav { display: block; }
  #mobileFab { display: flex; }

  .two-col, .three-col { grid-template-columns: 1fr; gap: 12px; }
}

@media (max-width: 480px) {
  .topbar-search { width: 140px; padding: 6px 10px; }
  .topbar-search input { font-size: 12px; }
  .page { padding: 12px 12px 20px; }
  .login-wrap { padding: 26px 20px; border-radius: 16px; }
}

@media (max-width: 360px) {
  :root { --bottom-nav-h: 58px; }
  .bn-label { font-size: 9px; }
  .bn-icon  { font-size: 18px; }
  .topbar   { padding: 0 8px; }
}

@media (min-width: 769px) {
  #bottomNav { display: none !important; }
  #mobileFab { display: none !important; }
}

/* --- PREMIUM SAAS UI OVERRIDES --- */

/* Fix the broken sidebar menu buttons */
.sb-nav .menu-item {
  background: transparent;
  border: none;
  width: 100%;
  text-align: left;
  padding: 12px 16px;
  border-radius: 8px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  color: #64748b; /* Sleek muted slate */
  cursor: pointer;
  display: flex;
  align-items: center;
  transition: all 0.2s ease;
  margin-bottom: 0; /* 🚀 FIXED: Margin removed. The 'gap' property above now handles all spacing perfectly. */
}

.sb-nav .menu-item:hover {
  background: #f1f5f9;
  color: #2563eb;
}

.sb-nav .menu-item.active {
  background: rgba(37, 99, 235, 0.1);
  color: #2563eb;
  border-left: 4px solid #2563eb;
}

/* Make Cards look like a high-end dashboard */
.card {
  background: #ffffff;
  border-radius: 12px;
  border: 1px solid rgba(0,0,0,0.05);
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
  transition: box-shadow 0.2s ease;
}

.card:hover {
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.04);
}

/* Modernize the Topbar */
.topbar {
  background: rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(0,0,0,0.05);
}

/* Mobile Optimization Upgrades */
@media (max-width: 768px) {
  .entry-grid, .grid-2, .form-grid {
    grid-template-columns: 1fr !important;
  }
  .card {
    padding: 16px !important;
  }
  .topbar-title {
    font-size: 16px;
  }
  .photo-zone {
    width: 100% !important;
    height: 200px !important;
  }
}