/*
 * App mode for phones and tablets (≤ 991px) and the installed PWA.
 * Goal: feel like a native app — bottom tabs, card lists, sheets, no zooming.
 */
:root { --tabbar-height: 62px; }

/* No double-tap zoom or tap flashes anywhere. */
html { touch-action: manipulation; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
* { -webkit-tap-highlight-color: transparent; }

@media (max-width: 991.98px) {
  html, body { overscroll-behavior-y: none; }
  body { padding-bottom: 0; }
  /* iOS zooms into any field under 16px — keep every field at 16px. */
  input, select, textarea, .form-control, .form-select, .input-group-text { font-size: 16px !important; }
  .form-control, .form-select { min-height: 46px; border-radius: 12px; }
  .btn { min-height: 42px; }
  .btn-sm { min-height: 34px; }

  /* Shell: no sidebar or hamburger — tabs do the navigation. */
  .app-sidebar-nav, .nav-overlay, #navToggle { display: none !important; }
  .app-topbar { padding: env(safe-area-inset-top) 16px 0; height: calc(var(--topbar-height) + env(safe-area-inset-top)); }
  .topbar-crumb { display: none; }
  .topbar-greeting { font-size: 17px; }
  .topbar-date { display: none !important; }
  .user-chip { padding: 3px; }
  .app-main { padding: 16px 14px calc(var(--tabbar-height) + env(safe-area-inset-bottom) + 24px); }
  .has-fab .app-main { padding-bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom) + 92px); }

  /* Page header: title on top, secondary actions as a compact row. */
  .page-header { flex-direction: column; align-items: stretch; gap: 12px; margin-bottom: 16px; }
  .page-header-title h4 { font-size: 24px; letter-spacing: -.01em; }
  .page-header-actions { gap: 8px; }
  .page-header-actions .btn { flex: 1 1 auto; }

  /* The screen's create button floats above the tab bar. */
  .page-header-actions [data-fab] {
    position: fixed; right: 18px; bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom) + 18px); z-index: 1025;
    flex: none; width: 58px; height: 58px; min-height: 0; padding: 0; border-radius: 20px; font-size: 0;
    display: grid; place-items: center; box-shadow: 0 16px 32px -10px rgba(99, 102, 241, .75);
    animation: fabIn .45s var(--ease-spring, ease) both;
  }
  .page-header-actions [data-fab] i { font-size: 24px; margin: 0; }
  .page-header-actions [data-fab]:active { transform: scale(.92); }
  .page-header-actions [data-fab][hidden], .page-header-actions [data-fab].d-none { display: none !important; }

  .filter-bar { padding: 12px; border-radius: 18px; }
  .segmented { display: flex; overflow-x: auto; scrollbar-width: none; max-width: 100%; }
  .segmented::-webkit-scrollbar { display: none; }
  .segmented button { flex: 0 0 auto; white-space: nowrap; }

  /* Tables become card lists (cells are labelled from the header by app-tabbar.component.js). */
  .app-table:not(.keep-table) thead { display: none; }
  .app-table:not(.keep-table), .app-table:not(.keep-table) tbody { display: block; width: 100%; }
  .app-table:not(.keep-table) tbody tr {
    display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; margin: 0 0 12px; padding: 14px; border-radius: 18px;
    background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-xs);
  }
  .app-table:not(.keep-table) tbody tr:hover { background: var(--surface); }
  .app-table:not(.keep-table) tbody td { display: block; padding: 0; border: 0 !important; min-width: 0; text-align: left !important; overflow-wrap: anywhere; }
  .app-table:not(.keep-table) tbody td[data-label]::before {
    content: attr(data-label); display: block; margin-bottom: 2px; font-size: 10.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted-2);
  }
  /* First cell = card title, full width, no label. */
  .app-table:not(.keep-table) tbody td:first-child { grid-column: 1 / -1; }
  .app-table:not(.keep-table) tbody td:first-child::before { display: none; }
  .app-table:not(.keep-table) tbody td.actions {
    grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: 6px; padding-top: 10px !important; border-top: 1px dashed var(--border) !important;
  }
  .app-table:not(.keep-table) tbody td.actions::before { display: none; }
  .app-table:not(.keep-table) tbody td[colspan] { grid-column: 1 / -1; }
  .app-table:not(.keep-table) tbody td[colspan]::before { display: none; }
  .table-wrap:has(> .app-table:not(.keep-table)) { overflow: visible; }
  .app-card:has(.app-table:not(.keep-table)) { background: transparent; border: 0; box-shadow: none; }
  .app-card:has(.app-table:not(.keep-table)) > .app-card-header { background: var(--surface); border-radius: 16px; margin-bottom: 12px; border: 1px solid var(--border); }
  .btn-icon { width: 40px; height: 40px; }

  /* Drawers (forms) open as full-height sheets from the bottom. */
  .app-sidebar-panel, .app-sidebar.narrow .app-sidebar-panel {
    top: auto; left: 0; width: 100vw; height: calc(100% - env(safe-area-inset-top) - 18px); border-radius: 24px 24px 0 0;
    animation: sheetUp .35s var(--ease) both;
  }
  .app-sidebar.closing .app-sidebar-panel { animation: sheetDown .28s var(--ease) forwards; }
  .app-sidebar-header { padding: 18px 18px 14px; }
  .app-sidebar-body { padding: 16px 18px; }
  .app-sidebar-footer { padding: 12px 18px calc(12px + env(safe-area-inset-bottom)); }
  .app-sidebar-footer .btn { flex: 1; }

  .dropdown-menu { font-size: 15px; }
  .confirm-card { width: calc(100vw - 32px); }
  .modal-dialog { margin: 12px; }
  .toast-container, .app-toast-container { bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom) + 12px) !important; top: auto !important; }
}

/* Installed app: no text selection on chrome, no pull-to-refresh bounce. */
.is-standalone .app-tabbar, .is-standalone .app-topbar, .is-standalone .page-header-actions, .is-standalone .segmented { -webkit-user-select: none; user-select: none; }
.is-standalone body { overscroll-behavior: none; }

@keyframes fabIn { from { transform: scale(.4) rotate(-45deg); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: none; } }
@keyframes sheetDown { from { transform: none; } to { transform: translateY(100%); } }
