/* Phone / tablet layer for RECMS (installed web app). Desktop (>=992px) is untouched. */
html { -webkit-text-size-adjust: 100%; }
body { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
.app-navbar { padding-top: env(safe-area-inset-top); }
#offlineBar { position: sticky; top: 0; z-index: 2000; background: #b42318; color: #fff; text-align: center; font-size: .85rem; padding: .35rem; }
#menuBackdrop { display: none; }

@media (max-width: 991.98px) {
  body { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  body.menu-open { overflow: hidden; }
  .app-navbar > .container-fluid { flex-wrap: nowrap; }
  .app-navbar .ms-auto { gap: .25rem !important; flex-shrink: 0; }
  .app-navbar .navbar-brand { font-size: 1rem; max-width: 46vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .app-sidebar { top: calc(56px + env(safe-area-inset-top)); height: calc(100dvh - 56px - env(safe-area-inset-top) - 64px - env(safe-area-inset-bottom)); overflow-y: auto; overscroll-behavior: contain; }
  #menuBackdrop.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 1025; }
  .container-fluid { padding-left: .85rem; padding-right: .85rem; }
  main .container-fluid.py-4 { padding-top: 1rem !important; }

  /* Touch-sized controls; 16px text stops iOS zooming into fields */
  .form-control, .form-select { font-size: 16px; min-height: 44px; }
  textarea.form-control { min-height: 88px; }
  .btn { min-height: 40px; }
  .btn-sm { min-height: 34px; padding-left: .7rem; padding-right: .7rem; }
  .nav-link, .dropdown-item { padding-top: .6rem; padding-bottom: .6rem; }
  .app-sidebar .nav-link { padding-top: .7rem; padding-bottom: .7rem; }
  h4, .h4 { font-size: 1.2rem; }
  .card-body { padding: .9rem; }
  .dropdown-menu { max-width: 94vw; }
  .modal-dialog { margin: .5rem; }
  .d-flex.justify-content-between.align-items-center, .d-flex.justify-content-between.align-items-start { flex-wrap: wrap; gap: .5rem; }
  .stat-card .stat-value { font-size: 1.4rem; }
  .estate-map-wrap { overflow-x: auto; }

  /* Bottom navigation */
  .bottom-nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 1040; display: flex; background: #fff; border-top: 1px solid #dfe3e8;
    padding-bottom: env(safe-area-inset-bottom); box-shadow: 0 -2px 8px rgba(0,0,0,.06); }
  .bottom-nav a { flex: 1; text-align: center; padding: .45rem .25rem .35rem; color: #5b6770; text-decoration: none; font-size: .7rem; position: relative; min-height: 56px; }
  .bottom-nav a i { display: block; font-size: 1.35rem; line-height: 1.2; }
  .bottom-nav a.active { color: var(--recms-primary); font-weight: 600; }
  .bottom-nav .bn-badge { position: absolute; top: 4px; left: 54%; background: #dc3545; color: #fff; border-radius: 10px; font-size: .6rem; padding: 0 5px; line-height: 1.3; }
}

/* Tables become stacked cards on phones */
@media (max-width: 575.98px) {
  main .table-responsive { overflow: visible; }
  table.table-cards, table.table-cards tbody, table.table-cards tr, table.table-cards td { display: block; width: 100%; }
  table.table-cards thead { position: absolute; left: -9999px; }
  table.table-cards tr { background: #fff; border: 1px solid #e3e6ea; border-radius: .6rem; margin-bottom: .7rem; padding: .35rem .75rem; box-shadow: 0 1px 2px rgba(0,0,0,.04); }
  table.table-cards td { border: 0 !important; padding: .3rem 0 !important; display: flex; justify-content: space-between; gap: 1rem; text-align: right; }
  table.table-cards td::before { content: attr(data-label); font-weight: 600; color: #5b6770; text-align: left; flex: 0 0 38%; font-size: .8rem; }
  table.table-cards td:not([data-label])::before { content: none; }
  table.table-cards td:not([data-label]) { justify-content: flex-end; }
  table.table-cards tfoot { display: block; }
  table.table-cards tfoot tr { background: #f1f3f8; }
}
@media (min-width: 992px) { .bottom-nav, #pwaIosHint { display: none !important; } }
@media print { .bottom-nav, #offlineBar, #pwaIosHint { display: none !important; } }
