/* ═══════════════════════════════════════════════════════════════════
   MOBILE UX POLISH
   Touch-friendly targets, bottom navigation, card layouts
   for data tables, FAB optimization for small screens.
═══════════════════════════════════════════════════════════════════ */

/* ── Touch-friendly targets (min 44px) ── */
@media (max-width: 768px) {
  .btn, .sb-item, .fab-btn, .fab-action-icon,
  .notif-bell, .theme-toggle, .lang-toggle {
    min-height: 44px;
    min-width: 44px;
  }

  .btn-xs {
    min-height: 36px;
    min-width: 36px;
    padding: 6px 12px;
    font-size: 12px;
  }

  .btn-sm {
    min-height: 40px;
    padding: 8px 14px;
  }

  /* ── Hide sidebar, show bottom nav ── */
  .sidebar {
    display: none !important;
  }

  .sidebar-overlay {
    display: none !important;
  }

  .main {
    margin-right: 0 !important;
    width: 100% !important;
  }

  /* ── Bottom Navigation Bar ── */
  .bottom-nav {
    display: flex !important;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--white);
    border-top: 1px solid var(--n200);
    box-shadow: 0 -2px 12px rgba(0,0,0,0.08);
    z-index: 1000;
    padding: 4px 0;
    padding-bottom: env(safe-area-inset-bottom, 4px);
  }

  .bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 6px 4px;
    font-size: 10px;
    color: var(--n500);
    text-decoration: none;
    cursor: pointer;
    border: none;
    background: none;
    font-family: inherit;
    min-height: 52px;
    transition: color 0.15s;
  }

  .bottom-nav-item.active {
    color: var(--g600);
  }

  .bottom-nav-item .bn-icon {
    font-size: 20px;
    margin-bottom: 2px;
  }

  .bottom-nav-item .bn-label {
    font-size: 9px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 60px;
  }

  /* ── Adjust main content for bottom nav ── */
  #main {
    padding-bottom: 70px !important;
  }

  /* ── Topbar adjustments ── */
  .topbar {
    padding: 8px 12px;
    gap: 8px;
    flex-wrap: wrap;
  }

  .tb-right {
    gap: 6px;
    flex-wrap: wrap;
  }

  .tb-breadcrumb {
    font-size: 13px;
  }

  .tb-session-badge {
    display: none;
  }

  #btn-export, #btn-add-emp {
    font-size: 11px;
    padding: 6px 10px;
  }

  /* ── Page headers ── */
  .page-header h1 {
    font-size: 18px;
  }

  .page-header p {
    font-size: 11px;
  }

  /* ── Stats grid — 2 columns on mobile ── */
  .stats-grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 10px;
  }

  .stat-card {
    padding: 12px;
  }

  .stat-num {
    font-size: 20px;
  }

  /* ── Data tables — Card layout on small screens ── */
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .data-table {
    font-size: 12px;
  }

  .data-table th, .data-table td {
    padding: 8px 10px;
    white-space: nowrap;
  }

  /* ── Salary cards — single column ── */
  .sal-grid {
    grid-template-columns: 1fr !important;
  }

  /* ── Charts ── */
  .chart-grid-3, .chart-grid-2 {
    grid-template-columns: 1fr !important;
  }

  .analytics-kpi-grid {
    grid-template-columns: 1fr 1fr !important;
  }

  .analytics-table-row {
    grid-template-columns: 1fr !important;
  }

  /* ── Dashboard 2-column → 1-column ── */
  #page-dash > div[style*="grid-template-columns: 1fr 1fr"],
  #page-dash > div[style*="grid-template-columns:1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* ── Modals fullscreen on mobile ── */
  .modal {
    width: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
    border-radius: 0 !important;
    margin: 0 !important;
  }

  .overlay {
    align-items: stretch;
  }

  /* ── Form grid ── */
  .form-grid {
    grid-template-columns: 1fr !important;
  }

  /* ── FAB optimization ── */
  .fab-wrap {
    bottom: 72px !important; /* Above bottom nav */
  }

  .fab-btn {
    width: 52px;
    height: 52px;
    font-size: 24px;
  }

  .fab-menu {
    bottom: 60px;
  }

  /* ── Timesheet scroll ── */
  .ts-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .ts-table {
    min-width: 800px;
  }

  .ts-toolbar {
    flex-direction: column;
    gap: 8px;
  }

  /* ── Login page ── */
  .login-brand {
    display: none;
  }

  .login-form-panel {
    width: 100%;
    padding: 16px;
  }

  .login-card {
    border-radius: 12px;
  }

  .demo-grid {
    grid-template-columns: 1fr 1fr !important;
  }

  /* ── Spotlight ── */
  .spotlight-box {
    width: 95% !important;
    max-width: 95% !important;
    margin: 16px auto;
  }

  /* ── Notifications ── */
  .notif-dropdown {
    width: 300px;
    right: -20px;
  }

  /* ── Laws page — single column ── */
  #page-laws > div[style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }

  /* ── Role dashboard widgets ── */
  #dash-role-widgets > div[style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }

  /* ── Permit filter bar ── */
  #page-permits > div[style*="display:flex"] {
    flex-direction: column;
  }
}

/* ── Extra small screens ── */
@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr !important;
  }

  .analytics-kpi-grid {
    grid-template-columns: 1fr !important;
  }

  .demo-grid {
    grid-template-columns: 1fr !important;
  }

  .topbar {
    padding: 6px 10px;
  }

  .tb-right .btn {
    font-size: 10px;
    padding: 4px 8px;
  }

  .page {
    padding: 12px;
  }
}

/* ── Bottom nav hidden by default (shown only on mobile via @media) ── */
.bottom-nav {
  display: none;
}

/* ── Dark mode bottom nav ── */
[data-theme="dark"] .bottom-nav {
  background: var(--dk-surface, #111827);
  border-top-color: var(--dk-border, rgba(30,148,104,0.1));
}
[data-theme="dark"] .bottom-nav-item { color: #b0b8c4; }
[data-theme="dark"] .bottom-nav-item.active { color: #86EFAC; }

/* ═══════════════════════════════════════════════════════════════════
   MOBILE BOTTOM NAVIGATION BAR (mobile-bottom-nav)
   Secondary compact nav with active state highlighting
═══════════════════════════════════════════════════════════════════ */

/* Hidden by default — shown only below 768px */
.mobile-bottom-nav {
  display: none;
}

@media (max-width: 768px) {
  /* Show the mobile-bottom-nav and hide sidebar */
  .mobile-bottom-nav {
    display: flex !important;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--white, #fff);
    border-top: 1px solid var(--n200, #e2e8f0);
    box-shadow: 0 -2px 16px rgba(0, 0, 0, 0.10);
    z-index: 1050;
    padding: 2px 0;
    padding-bottom: env(safe-area-inset-bottom, 2px);
    justify-content: space-around;
    align-items: stretch;
  }

  .mob-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 6px 2px 4px;
    font-size: 20px;
    color: var(--n400, #a0aec0);
    text-decoration: none;
    cursor: pointer;
    border: none;
    background: none;
    font-family: inherit;
    min-height: 52px;
    transition: color 0.18s, transform 0.15s;
    position: relative;
    -webkit-tap-highlight-color: transparent;
  }

  .mob-nav-item span {
    display: block;
    font-size: 9px;
    font-weight: 700;
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 64px;
    color: inherit;
  }

  /* Active state */
  .mob-nav-item.active {
    color: var(--g600, #276749);
  }

  .mob-nav-item.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 25%;
    right: 25%;
    height: 3px;
    background: var(--g600, #276749);
    border-radius: 0 0 3px 3px;
  }

  /* Pressed state */
  .mob-nav-item:active {
    transform: scale(0.92);
  }

  /* Ensure page content doesn't get hidden behind the bottom nav */
  #app-screen {
    padding-bottom: 68px !important;
  }

  #main {
    padding-bottom: 72px !important;
  }

  /* Hide sidebar on mobile — prefer bottom nav */
  .sidebar {
    display: none !important;
  }

  .sidebar-overlay {
    display: none !important;
  }

  .main {
    margin-right: 0 !important;
    width: 100% !important;
  }
}

/* ── Dark mode for mobile-bottom-nav ── */
[data-theme="dark"] .mobile-bottom-nav {
  background: var(--dk-surface, #111827);
  border-top-color: var(--dk-border, rgba(30,148,104,0.1));
}
[data-theme="dark"] .mob-nav-item { color: #b0b8c4; }
[data-theme="dark"] .mob-nav-item.active { color: #86EFAC; }
[data-theme="dark"] .mob-nav-item.active::before { background: #1e9468; }
