/* ============================================================
   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 -2px 16px rgba(26,66,138,.10);
}

.bottom-nav-inner {
  display: flex;
  height: var(--bottom-nav-h);
  align-items: stretch;
  justify-content: space-around;
  padding: 0 4px;
}

/* ── Individual tab button ── */
.bn-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  text-decoration: none;
  color: #94a3b8;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .2px;
  flex: 1;
  min-width: 0;
  padding: 6px 2px 4px;
  border: none;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: color .15s;
  position: relative;
}

/* ── Icon wrapper — the "thumbnail tile" ── */
.bn-icon-wrap {
  width: 40px;
  height: 32px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .18s, transform .15s;
  font-size: 20px;
  line-height: 1;
}

/* ── Label ── */
.bn-tab span:not(.bn-icon-wrap) {
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: .1px;
  max-width: 52px;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Active state ── */
.bn-tab.active {
  color: #1A428A;
}
.bn-tab.active .bn-icon-wrap {
  background: rgba(26,66,138,.10);
  transform: scale(1.06);
}

/* ── Active indicator dot above icon ── */
.bn-tab.active::before {
  content: '';
  position: absolute;
  top: 3px;
  left: 50%;
  transform: translateX(-50%);
  width: 20px;
  height: 3px;
  background: #1A428A;
  border-radius: 0 0 3px 3px;
}

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

/* ── 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; hide desktop tab bar ── */
@media (max-width: 768px) {
  .bottom-nav { display: block; }

  /* Hide horizontal desktop tab bar — replaced by bottom nav on mobile */
  .tab-bar { display: none !important; }

  /* Extra bottom padding so last card isn't hidden behind nav */
  .page { padding-bottom: calc(var(--bottom-nav-h) + var(--safe-bottom) + 16px); }
}

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