/* ============================================================
   Silverworld ERP — Mobile & PWA Stylesheet
   Applies on top of each page's base styles
   ============================================================ */

/* ── Safe area insets (iPhone notch / Dynamic Island) ─────── */
:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --bottom-nav-h: 64px;
}

/* ── Global touch improvements ────────────────────────────── */
* { -webkit-tap-highlight-color: transparent; }

button, a, [onclick], [role="button"] {
  touch-action: manipulation; /* eliminates 300ms tap delay */
}

/* ── Hide top nav links on mobile (use bottom nav instead) ── */
@media (max-width: 768px) {
  .topnav .nav-links { display: none !important; }
  .topnav .user-info-pill { display: none !important; }

  /* Compact topnav */
  .topnav {
    height: 48px;
    padding: 0 16px;
    padding-top: var(--safe-top);
  }

  /* Push page content above bottom nav */
  body { padding-bottom: calc(var(--bottom-nav-h) + var(--safe-bottom)); }

  /* Dashboard page padding */
  .page { padding: 16px; }

  /* KPI grid: 2 columns on mobile */
  .kpi-row { grid-template-columns: 1fr 1fr !important; gap: 10px !important; }
  .kpi-card { padding: 12px 14px !important; }
  .kpi-card .kpi-value { font-size: 20px !important; }
  .kpi-card .kpi-icon { width: 32px; height: 32px; font-size: 15px; margin-bottom: 8px; }

  /* Grids → single column */
  .grid-2, .grid-3, .grid-3-1 {
    grid-template-columns: 1fr !important;
  }

  /* Section cards full width */
  .card { border-radius: 12px; }

  /* Branch filter: scrollable pill row */
  .branch-filter {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    flex-wrap: nowrap !important;
    gap: 6px;
    margin-left: 0 !important;
    width: 100%;
  }
  .branch-filter::-webkit-scrollbar { display: none; }
  .branch-btn { white-space: nowrap; flex-shrink: 0; }

  /* Dash header: stack vertically */
  .dash-header {
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
  }
  .dash-header h1 { font-size: 17px; }

  /* Silver badge in nav: compact */
  .silver-badge { padding: 3px 8px; }
  .silver-badge .sb-val { font-size: 12px; }

  /* Dropdowns: open from bottom on mobile */
  .user-dropdown {
    position: fixed !important;
    top: auto !important;
    bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 8px) !important;
    left: 12px !important;
    right: 12px !important;
    min-width: unset !important;
    border-radius: 16px !important;
    transform: translateY(20px) scale(.97) !important;
    transform-origin: bottom center !important;
  }
  .user-menu-wrap.open .user-dropdown {
    transform: translateY(0) scale(1) !important;
  }

  /* Tables: horizontal scroll */
  .table-wrap, table { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 480px; }

  /* Modal full-screen on mobile */
  .modal { align-items: flex-end !important; }
  .modal-box {
    width: 100% !important;
    max-width: 100% !important;
    border-radius: 20px 20px 0 0 !important;
    max-height: 92vh !important;
    overflow-y: auto;
    padding-bottom: calc(16px + var(--safe-bottom)) !important;
  }

  /* Forms: full width inputs */
  input, select, textarea {
    font-size: 16px !important; /* prevents iOS zoom on focus */
  }
}

/* ── Bottom Tab Navigation ────────────────────────────────── */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--bottom-nav-h) + var(--safe-bottom));
  background: #fff;
  border-top: 1px solid #e2e8f4;
  padding-bottom: var(--safe-bottom);
  z-index: 200;
  box-shadow: 0 -4px 20px rgba(26,66,138,.08);
}

.bottom-nav-inner {
  display: flex;
  height: var(--bottom-nav-h);
  align-items: center;
  justify-content: space-around;
}

.bn-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  text-decoration: none;
  color: #8896b3;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .2px;
  flex: 1;
  padding: 6px 4px;
  border-radius: 12px;
  transition: color .15s;
  position: relative;
}

.bn-tab .bn-icon {
  font-size: 20px;
  line-height: 1;
  transition: transform .15s;
}

.bn-tab.active { color: #1A428A; }
.bn-tab.active .bn-icon { transform: scale(1.1); }

.bn-tab .bn-dot {
  position: absolute;
  top: 4px; right: 50%;
  transform: translateX(10px);
  width: 6px; height: 6px;
  border-radius: 50%;
  background: #dc2626;
}

/* ── More Menu (overflow tabs on mobile) ─────────────────── */
.more-menu {
  position: fixed;
  bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 8px);
  left: 12px; right: 12px;
  background: #fff;
  border-radius: 16px;
  border: 1px solid #e2e8f4;
  box-shadow: 0 8px 40px rgba(26,66,138,.18);
  padding: 8px;
  display: none;
  flex-wrap: wrap;
  gap: 4px;
  z-index: 300;
}

.more-menu.open { display: flex; }

.mm-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: calc(50% - 2px);
  padding: 12px 14px;
  border-radius: 12px;
  text-decoration: none;
  color: #1a1a2e;
  font-size: 13px;
  font-weight: 500;
  transition: background .1s;
}
.mm-item:hover, .mm-item:active { background: #f0f4fa; }
.mm-item .mm-icon { font-size: 18px; }

.more-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.3);
  z-index: 299;
  display: none;
}
.more-overlay.open { display: block; }

/* ── Show bottom nav only on mobile ──────────────────────── */
@media (max-width: 768px) {
  .bottom-nav { display: block; }
}

/* ── PWA standalone: tighten status bar ──────────────────── */
@media (display-mode: standalone) {
  .topnav {
    padding-top: calc(var(--safe-top) + 4px);
    height: calc(52px + var(--safe-top));
  }
}
