/* public/css/skeleton.css - calm loading placeholders for every role (Mobile UX Phase 1).

   How it works: a page's existing loading element holds the skeleton as plain HTML, so it paints
   before any page script runs. js/skeleton.js then shapes it from the real thing (table columns,
   last row count, last measured heights) and the page's own code replaces or hides it exactly as
   it did the old "Loading..." text - success and error paths are unchanged.

   Rules
   - Nothing literal below this :root block: colours come from yuniq-tokens.css, every size and
     time is a --sk-* variable. tests/browser/test-skeleton-ui.js S9 enforces this.
   - No width breakpoints: CSS cannot read a variable in @media, so layouts here are fluid instead
     (auto-fit grids, clamp()), which also means there is no breakpoint to keep in step.
   - Bars only: never a fake number, price or status.
   - The words stay in .sk-sr for screen readers, and show as plain text if this file fails to
     load - the old behaviour, so a missing stylesheet cannot hide the loading state.
   - Stuck-load safety net: the shimmer stops at --sk-giveup-s (just past CONFIG.REQUEST_TIMEOUT_MS,
     60 s) and .sk-slow says so. A page that never recovers cannot shimmer forever. */
@import url('/css/yuniq-tokens.css');

:root {
  /* colour */
  --sk-bar-color: var(--yuniq-border);
  --sk-shine-color: var(--yuniq-white);
  --sk-shine-opacity: 0.55;
  --sk-line-color: var(--yuniq-border);
  --sk-surface: var(--yuniq-white);
  --sk-caption-color: var(--yuniq-text-secondary);
  --sk-hero-surface: var(--ink, var(--yuniq-navy));    /* the driver trip header's own colour */
  --sk-hero-bar-color: var(--yuniq-navy-700);

  /* time (unitless seconds, so the run count below can be worked out from them) */
  --sk-show-delay-s: 0.12;   /* a fast load never flashes a skeleton */
  --sk-fade-s: 0.18;
  --sk-instant: 1ms;         /* a caption switches, it does not fade */
  --sk-cycle-s: 1.8;
  --sk-slow-after-s: 8;      /* Render cold start: say why it is slow */
  --sk-giveup-grace-s: 5;    /* js/skeleton.js: give up at CONFIG.REQUEST_TIMEOUT_MS + this */
  --sk-giveup-s: 65;         /* only until js/skeleton.js has run */
  --sk-header-quiet-s: 0.8;  /* the admin header's natural height is saved after this long unchanged */

  /* size */
  --sk-bar-h: 0.75rem;
  --sk-title-h: 1.125rem;
  --sk-block-h: 3.5rem;
  --sk-bar-gap: 0.625rem;
  --sk-pad: 1rem;
  --sk-row-pad: 0.75rem;
  --sk-row-h: 2.75rem;       /* first visit; js/skeleton.js sets the measured height afterwards */
  --sk-default-rows: 2;      /* first visit; measured at 375px, moves the page least */
  --sk-default-header-h: 8.875;  /* rem. First visit on a phone; measured per screen width afterwards */
  --sk-header-phone-max: 30; /* rem. Phone width: admin-portal/components/nav.css holds the same height from first paint */
  --sk-stat-h: 1.2em;        /* the line a stat tile's number takes */
  --sk-stat-bar-h: 0.7em;
  --sk-gutter: 2rem;
  --sk-cell-gutter: 4rem;
  --sk-tile-min: 9rem;       /* tiles per row follow the screen: two on a phone, more when wider */
  --sk-radius-bar: var(--radius-sm, 0.375rem);
  --sk-radius-card: var(--yuniq-radius-control);
  --sk-caption-size: 0.85rem;
  --sk-caption-h: 2.6em;
  --sk-caption-leading: 1.3;
  --sk-hairline: 1px;
  --sk-touch-target: clamp(2.75rem, 11vw, 3.5rem);     /* action placeholders, same as a real tap area */

  /* bar lengths */
  --sk-w-short: 30%;
  --sk-w-mid: 40%;
  --sk-w-long: 60%;
  --sk-w-full: 80%;
}

.sk-stat { display: flex; align-items: center; min-height: var(--sk-stat-h); }
.sk-stat .sk-bar { width: var(--sk-w-mid); height: var(--sk-stat-bar-h); margin: 0; }

.sk-wrap {
  position: relative;
  display: block;
  width: 100%;
  max-width: calc(100vw - var(--sk-gutter));
  text-align: left;
  font-style: normal;
  animation: sk-show calc(var(--sk-fade-s) * 1s) ease-out calc(var(--sk-show-delay-s) * 1s) both;
}
/* Before js/skeleton.js shapes a table (or if it cannot run): keep bars on a phone's screen. */
td .sk-wrap { max-width: calc(100vw - var(--sk-cell-gutter)); }
td .sk-row { padding: var(--sk-row-pad); }
td .sk-row .sk-bar:not(:first-of-type) { display: none; }
td .sk-row .sk-bar:first-of-type { margin-bottom: 0; }

/* A table's skeleton: real columns, from the table's own header. */
.sk-tr > td { height: var(--sk-row-h); padding-top: 0; padding-bottom: 0; vertical-align: middle; }
.sk-tr .sk-bar { margin: 0; width: var(--sk-w-full); }
.sk-tr > td:nth-child(3n+2) .sk-bar { width: var(--sk-w-long); }
.sk-tr > td:nth-child(3n) .sk-bar { width: var(--sk-w-mid); }
.sk-status > td { height: 0; padding: 0; border: 0; }

/* Admin loading notes are padded for centred text; bars should line up with the page instead. */
.loading-note:has(> .sk-wrap) { padding: var(--sk-pad) 0; text-align: left; }
#loadingState:has(> .sk-wrap > .sk-hero) { padding: 0; text-align: left; }
#loadingState > .sk-wrap:has(> .sk-hero) { max-width: none; } /* the trip header runs edge to edge */
.ref-grid > .sk-wrap, .grid > .sk-wrap { grid-column: 1 / -1; }

.sk-sr {
  position: absolute;
  width: var(--sk-hairline); height: var(--sk-hairline);
  margin: calc(var(--sk-hairline) * -1); padding: 0; border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.sk-bar {
  position: relative;
  display: block;
  height: var(--sk-bar-h);
  margin: 0 0 var(--sk-bar-gap);
  border-radius: var(--sk-radius-bar);
  overflow: hidden;
  background: var(--sk-bar-color);
}
.sk-bar::after {
  content: '';
  position: absolute;
  inset: 0;
  opacity: var(--sk-shine-opacity);
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, var(--sk-shine-color), transparent);
  /* A finite run, ending off the bar: nothing keeps animating once it has given up. */
  animation: sk-shimmer calc(var(--sk-cycle-s) * 1s) ease-in-out calc(var(--sk-giveup-s) / var(--sk-cycle-s)) backwards;
}
.sk-title { height: var(--sk-title-h); }
.sk-block { height: var(--sk-block-h); border-radius: var(--sk-radius-card); }
.sk-action { height: var(--sk-touch-target); border-radius: var(--sk-radius-card); }
.sk-w30 { width: var(--sk-w-short); }
.sk-w40 { width: var(--sk-w-mid); }
.sk-w60 { width: var(--sk-w-long); }
.sk-w80 { width: var(--sk-w-full); }

.sk-row {
  padding: var(--sk-row-pad) 0;
  border-bottom: var(--sk-hairline) solid var(--sk-line-color);
}
.sk-row:last-of-type { border-bottom: 0; }
.sk-row .sk-bar:last-child, .sk-card .sk-bar:last-child, .sk-tile .sk-bar:last-child { margin-bottom: 0; }

.sk-card {
  margin: 0 0 var(--sk-row-pad);
  padding: var(--sk-pad);
  border: var(--sk-hairline) solid var(--sk-line-color);
  border-radius: var(--sk-radius-card);
  background: var(--sk-surface);
}

.sk-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(var(--sk-tile-min), 1fr));
  gap: var(--sk-row-pad);
  margin: 0 0 var(--sk-pad);
}
.sk-tile {
  padding: var(--sk-row-pad);
  border: var(--sk-hairline) solid var(--sk-line-color);
  border-radius: var(--sk-radius-card);
  background: var(--sk-surface);
}

/* The driver trip screen's header and body. */
.sk-hero { padding: var(--sk-row-pad) var(--sk-pad); background: var(--sk-hero-surface); }
.sk-hero .sk-bar { background: var(--sk-hero-bar-color); }
.sk-body { padding: var(--sk-pad); }

/* The page's main skeleton explains a long wait (a Render cold start can take up to a minute),
   then admits it is stuck. Space is reserved from the start, so neither caption moves anything.
   The words are set on the element by js/skeleton.js, from its one i18n object. */
.sk-slow { padding-bottom: var(--sk-caption-h); }
.sk-slow::before, .sk-slow::after {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  font-size: var(--sk-caption-size);
  line-height: var(--sk-caption-leading);
  color: var(--sk-caption-color);
}
.sk-slow::before {
  content: attr(data-sk-slow-text);
  animation:
    sk-show var(--sk-instant) linear calc(var(--sk-slow-after-s) * 1s) both,
    sk-hide var(--sk-instant) linear calc(var(--sk-giveup-s) * 1s) forwards;
}
.sk-slow::after {
  content: attr(data-sk-stuck-text);
  animation: sk-show var(--sk-instant) linear calc(var(--sk-giveup-s) * 1s) both;
}

@keyframes sk-show { from { opacity: 0; } to { opacity: 1; } }
@keyframes sk-hide { from { opacity: 1; } to { opacity: 0; } }
@keyframes sk-shimmer { from { transform: translateX(-100%); } to { transform: translateX(100%); } }

@media (prefers-reduced-motion: reduce) {
  .sk-wrap { animation: none; }
  .sk-bar::after { animation: none; opacity: 0; }
}
