/* ==========================================================================
   FleetDesk — perf.css
   Load AFTER styles.css:
     <link rel="stylesheet" href="/styles.css">
     <link rel="stylesheet" href="/perf.css">

   Targets modern Android (Pixel 8/9/10, 120Hz LTPO, Galaxy S24/25).
   Goal: no blank/black frames between screens, everything composited,
   zero continuous repaint while idle.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. NO BLANK / BLACK FRAME BETWEEN SCREENS
   Root cause: .main, .page-head, .dash-grid>div, .card etc. all use
   `animation: nb-rise/nb-fade ... both`, which pins them at opacity:0 on
   the FIRST frame of every render. Because the whole shell innerHTML is
   rebuilt on each navigation, every screen change started invisible and
   faded up — that is the flash you are seeing.

   Fix: paint at full opacity immediately. One cheap composited transition
   on the content wrapper replaces ~10 separate element animations.
   -------------------------------------------------------------------------- */
.main,
.page-head,
.dash-focus,
.ring-card,
.dash-grid > div,
.alert-banner,
.card,
.login-card,
.cb-msg,
.chart-bars .cb .cb-fill {
  animation: none !important;
  opacity: 1 !important;
  transform: none !important;
}

/* Opaque surfaces at every layer so a dropped frame reveals the app
   background, never the WebView's default black. */
html,
body,
#app,
#app-shell,
.shell,
.main,
.content,
#workspace,
#fleet-frame {
  background-color: var(--bg, #f4f5fa);
}
html {
  color-scheme: light;
}

/* One composited screen transition. transform+opacity only — never touches
   layout or paint, so the compositor can run it at 120Hz off the main thread
   even while JS is still hydrating the page. */
.content {
  animation: fd-screen-in 170ms cubic-bezier(0.22, 0.7, 0.28, 1) both;
}
@keyframes fd-screen-in {
  from {
    opacity: 0.55;
    transform: translate3d(0, 6px, 0);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* --------------------------------------------------------------------------
   2. KILL THE backdrop-filter STORM  (single biggest GPU win)
   `.apk-native .card, .modal, .drawer { backdrop-filter: blur(24px)
   saturate(155%) }` plus blur(28px) on every dashboard widget means each
   card forces its own offscreen backdrop snapshot + blur pass, EVERY frame.
   With 8–14 widgets on the dashboard that is 8–14 full-screen blur passes
   per frame. At 120Hz you have 8.3ms per frame; this alone can cost 40ms+.

   Replaced with visually near-identical solid/gradient surfaces.
   -------------------------------------------------------------------------- */
.apk-native .card,
.apk-native .modal,
.apk-native .drawer,
.apk-native .mobile-topbar,
.apk-native .bottom-nav,
.dash-widget-grid > .card,
.dash-widget-grid > .dash-wide > .card,
.dash-widget-grid > .dash-kpis,
.widget-menu-btn,
.widget-drag,
.widget-floating-controls .widget-controls,
.widget-library-modal,
.quick-results,
.chat-shell,
.chat-bubble,
.chat-heads-up,
.chat-sticker-picker,
.chat-sticker > small,
.resize-tooltip,
.topbar,
.mnav-scrim,
.drawer-scrim,
#modal-root .overlay {
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}

/* Restore the frosted look with opaque paint (free) instead of blur (costly) */
.apk-native .mobile-topbar,
.topbar {
  background: #ffffff !important;
}
.apk-native .bottom-nav {
  background: #ffffff !important;
}
.dash-widget-grid > .card,
.dash-widget-grid > .dash-wide > .card,
.dash-widget-grid > .dash-kpis,
.apk-native .card {
  background: linear-gradient(145deg, #ffffff, #fbfbfe) !important;
  border-color: #ececf4 !important;
}
.apk-native .modal,
.widget-library-modal,
.quick-results,
.chat-sticker-picker {
  background: #ffffff !important;
}
.chat-shell {
  background: #fbfbfe !important;
}
.chat-bubble {
  background: #ffffff !important;
}
.chat-message.mine .chat-bubble {
  background: linear-gradient(145deg, var(--primary), var(--primary-dark)) !important;
}
#modal-root .overlay,
.drawer-scrim,
.mnav-scrim {
  background: rgba(16, 20, 34, 0.44) !important;
}

/* The dashboard's layered radial-gradient body background is repainted on
   every scroll frame. Pin it so it rasterises once. */
.page-dashboard {
  background-attachment: fixed;
}

/* --------------------------------------------------------------------------
   3. STOP INFINITE ANIMATIONS
   `animation: nb-pulse 1.5s infinite` on .badge.red-solid and .notif .dot
   never stops. An always-animating element keeps the compositor awake
   forever: the display cannot drop to its low-power refresh rate, the main
   thread is woken continuously, and battery drains. On an LTPO panel this
   also blocks the 1Hz idle state.

   Replaced with a static high-contrast treatment. Same urgency, zero cost.
   -------------------------------------------------------------------------- */
.badge.red-solid,
.notif .dot.expired {
  animation: none !important;
  box-shadow: 0 0 0 3px rgba(240, 68, 56, 0.16);
}

/* --------------------------------------------------------------------------
   4. LONG LISTS: SKIP OFFSCREEN WORK
   Vehicles / Drivers / Maintenance / Audit render every row into one big
   table. content-visibility lets the engine skip layout, paint AND style
   for rows outside the viewport. contain-intrinsic-size supplies a
   placeholder height so the scrollbar stays stable and nothing jumps.
   -------------------------------------------------------------------------- */
.table-wrap {
  contain: layout paint style;
}
.grid tbody tr {
  content-visibility: auto;
  contain-intrinsic-size: auto 52px;
}
.dash-widget,
.dash-widget-grid > .card,
.notif,
.chat-message {
  contain: layout paint style;
}
.chat-message {
  content-visibility: auto;
  contain-intrinsic-size: auto 64px;
}

/* --------------------------------------------------------------------------
   5. INSTANT TOUCH RESPONSE
   Removes the tap highlight flash and — critically — `touch-action:
   manipulation` removes the browser's 300ms double-tap-zoom wait on any
   element it is applied to. Buttons feel immediate.
   -------------------------------------------------------------------------- */
a,
button,
.btn,
.icon-btn,
.mt-btn,
.chat-person,
.bottom-nav a,
.sidebar nav a,
[onclick] {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* Composited press feedback — transform only, no layout, no paint. */
.btn:active,
.icon-btn:active,
.mt-btn:active,
.bottom-nav a:active,
.sidebar nav a:active,
.dash-kpi:active {
  transform: scale(0.972);
  transition: transform 60ms linear;
}
.btn,
.icon-btn,
.mt-btn,
.bottom-nav a,
.sidebar nav a,
.dash-kpi {
  transition: transform 140ms cubic-bezier(0.22, 0.7, 0.28, 1);
}

/* --------------------------------------------------------------------------
   6. SCROLL QUALITY
   -------------------------------------------------------------------------- */
html,
body,
.content,
.table-wrap,
.chat-message-list,
.drawer,
.modal {
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}
.content,
.table-wrap,
.chat-message-list {
  will-change: scroll-position;
}

/* Replace `transition:.15s` (= transition:all, which watches every animatable
   property and can force style recalc on unrelated changes) with an explicit
   composited list. */
.quick-combo-input,
.sticker-grid > button,
.widget-floating-controls,
.widget-resizer {
  transition-property: transform, opacity, background-color, border-color,
    box-shadow !important;
}

/* --------------------------------------------------------------------------
   7. GPU PROMOTION FOR MOVING SURFACES ONLY
   will-change is applied only while an element is actually open/animating.
   Leaving it on permanently wastes GPU memory and can cause texture
   thrashing on high-DPI panels like the Pixel 10 Pro's 1280p display.
   -------------------------------------------------------------------------- */
.drawer,
.modal,
.chat-heads-up,
.mnav-open .sidebar {
  will-change: transform, opacity;
}
.drawer:not([class*="open"]),
.modal:not([class*="open"]) {
  will-change: auto;
}

/* Sidebar drawer on mobile: animate transform, never `left`/`width`
   (those trigger layout on every frame). */
@media (max-width: 900px) {
  .sidebar {
    transition: transform 220ms cubic-bezier(0.22, 0.7, 0.28, 1);
  }
}

/* --------------------------------------------------------------------------
   8. FONT: NEVER BLOCK FIRST PAINT
   -------------------------------------------------------------------------- */
@font-face {
  font-family: "Inter";
  font-display: swap;
  src: local("Inter");
}

/* --------------------------------------------------------------------------
   9. NAVIGATION PROGRESS BAR (driven by perf-patch.js)
   Composited scaleX — runs on the compositor thread, so it keeps moving
   smoothly even while the main thread is busy building the next screen.
   -------------------------------------------------------------------------- */
#fd-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 2.5px;
  z-index: 9999;
  background: var(--primary, #2f6bff);
  transform: scaleX(0);
  transform-origin: 0 50%;
  opacity: 0;
  pointer-events: none;
  will-change: transform, opacity;
}
#fd-progress.run {
  opacity: 1;
  transform: scaleX(0.78);
  transition: transform 900ms cubic-bezier(0.1, 0.8, 0.2, 1), opacity 90ms;
}
#fd-progress.done {
  opacity: 0;
  transform: scaleX(1);
  transition: transform 130ms ease-out, opacity 180ms ease-out 90ms;
}

/* Skeleton shown only if a screen takes >140ms (i.e. a genuine cache miss).
   Uses transform, not background-position, so it is composited. */
.fd-skel {
  padding: 4px 2px;
}
.fd-skel i {
  display: block;
  height: 78px;
  margin-bottom: 12px;
  border-radius: 16px;
  background: #edeef4;
  position: relative;
  overflow: hidden;
}
.fd-skel i::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.72),
    transparent
  );
  transform: translate3d(-100%, 0, 0);
  animation: fd-shimmer 1.1s linear infinite;
}
@keyframes fd-shimmer {
  to {
    transform: translate3d(100%, 0, 0);
  }
}

/* --------------------------------------------------------------------------
   10. ACCESSIBILITY / BATTERY
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
