/* ============================================================
   SKELETONS + INLINE LOADING
   ------------------------------------------------------------
   Replaces the old full-screen branded overlay. Pages paint their
   shell (navbar, sidebar, title, filters) immediately and only the
   data regions show placeholder geometry.

   Every colour comes from the --skel-* tokens in tokens.css, so light
   and dark use the same rules. Fallbacks are included for the few pages
   that do not load tokens.css.

   Class API:
     .sk               base surface (shimmer)
     .sk-line          text line        .sk-title   heading line
     .sk-circle        avatar           .sk-rect    block
     .sk-img           image (--sk-ar)  .sk-btn     button
     .sk-w-25/50/75/100  width helpers  .sk-h-*     fixed heights
   ============================================================ */

:root {
  --sk-base: #dbe3ee;
  --sk-highlight: var(--white);
  --sk-edge: #ccd7e6;
  --sk-radius: 8px;
  --sk-sweep: 900px;
  --sk-speed: 1.35s;
}

/* Dark theme. Explicit attribute first (theme.js always sets it), then the OS
   preference for the handful of pages that do not load theme.js — guarded so a
   deliberate light choice is never overridden. The dark ramp is deliberately
   lighter than --skel-base: a sweep between #1c2740 and #2a3a5c read as a flat
   grey block on a #121a2b surface. */
[data-theme="dark"] {
  --sk-base: #18233c;
  --sk-highlight: #3f5480;
  --sk-edge: #22304e;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --sk-base: #18233c;
    --sk-highlight: #3f5480;
    --sk-edge: #22304e;
  }
}

@keyframes sk-shimmer {
  0%   { background-position: calc(var(--sk-sweep) * -1) 0; }
  100% { background-position: var(--sk-sweep) 0; }
}

@keyframes sk-breathe {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.55; }
}

.sk,
.sk-line,
.sk-title,
.sk-circle,
.sk-rect,
.sk-btn,
.sk-img {
  display: block;
  position: relative;
  overflow: hidden;
  background-color: var(--sk-base);
  /* A wider, brighter band than the token ramp: the placeholder has to read as
     "content is arriving" at a glance, on a navy card and on white. */
  background-image: linear-gradient(
    90deg,
    var(--sk-base) 18%,
    var(--sk-highlight) 44%,
    var(--sk-base) 70%
  );
  background-size: var(--sk-sweep) 100%;
  background-repeat: no-repeat;
  animation: sk-shimmer var(--sk-speed) ease-in-out infinite;
  border-radius: var(--sk-radius);
  will-change: background-position;
}

.sk { min-height: 14px; }

.sk-line {
  height: 12px;
  margin-bottom: 9px;
}
.sk-line:last-child { margin-bottom: 0; }

.sk-title {
  height: 22px;
  width: 62%;
  margin-bottom: 12px;
  border-radius: 7px;
}

.sk-circle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  flex: 0 0 auto;
}

.sk-rect { width: 100%; height: 120px; }

.sk-btn {
  width: 120px;
  height: 40px;
  border-radius: 999px;
}

/* Image placeholder: set --sk-ar to match the real media. Product cards use a
   square media box (.mk-card-img is 1/1), which is the default here so the grid
   does not jump when the photos land. */
.sk-img {
  width: 100%;
  aspect-ratio: var(--sk-ar, 1 / 1);
  border-radius: var(--sk-radius);
}

/* Category tile placeholder: same 56px rounded square as .mk-cat-icon. */
.sk-cat-tile {
  width: 56px;
  height: 56px;
  border-radius: 16px;
  flex: 0 0 auto;
}

/* The skeleton classes above are also used directly inside .mk-cat tiles, whose
   own background is a light surface gradient; keep them opaque there. */
.mk-cat-skeleton {
  pointer-events: none;
  cursor: default;
  gap: 12px;
}

.sk-w-25 { width: 25%; }
.sk-w-50 { width: 50%; }
.sk-w-75 { width: 75%; }
.sk-w-100 { width: 100%; }
.sk-h-14 { height: 14px; }
.sk-h-20 { height: 20px; }
.sk-h-32 { height: 32px; }
.sk-h-44 { height: 44px; }

/* Layered skeleton blocks ------------------------------------------------ */
.sk-wrap > * + * { margin-top: 10px; }

.sk-card {
  background: var(--sk-card-bg, var(--white));
  background-image: none;
  border: 1px solid var(--sk-edge);
  border-radius: 14px;
  padding: 12px;
  animation: none;
  overflow: hidden;
}
[data-theme="dark"] .sk-card { --sk-card-bg: #16213a; }

.sk-card .sk-img { border-radius: 10px; }

.sk-card .sk-body { padding-top: 10px; }

.sk-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 14px;
}
.sk-foot .sk-line { margin-bottom: 0; height: 16px; }

/* Stagger sibling placeholders so a list cascades instead of pulsing flat. */
.sk-stagger > * { animation-delay: calc(90ms * var(--sk-i, 0)); }

/* Visually hidden text that screen readers still announce. */
.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Bottom-of-list skeleton row (infinite scroll) */
.mk-skel-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
  margin-top: 18px;
}
@media (max-width: 1024px) { .mk-skel-row { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 768px) { .mk-skel-row { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* Reduced motion: no sweep, just a gentle brightness breath. */
@media (prefers-reduced-motion: reduce) {
  .sk, .sk-line, .sk-title, .sk-circle, .sk-rect, .sk-btn, .sk-img {
    animation-name: sk-breathe;
    animation-duration: 1.8s;
    background-image: none;
  }
  .sk-stagger > * { animation-delay: 0s; }
}

/* ============================================================
   EMPTY / ERROR / END STATES
   ============================================================ */
.sk-empty,
.sk-error,
.sk-end {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 34px 20px;
  text-align: center;
  border: 1px dashed var(--sk-edge);
  border-radius: 14px;
  background: var(--sk-card-bg, var(--white));
}
[data-theme="dark"] .sk-empty,
[data-theme="dark"] .sk-error,
[data-theme="dark"] .sk-end { --sk-card-bg: #16213a; }

.sk-empty p,
.sk-error p,
.sk-end p {
  margin: 0;
  max-width: 420px;
  color: var(--text-secondary, #5a6b7a);
  font-size: 0.9rem;
  line-height: 1.55;
}

.sk-end-title { font-weight: 700; color: var(--text-primary, var(--brand-navy-700, var(--brand-navy-700))) !important; }
[data-theme="dark"] .sk-end-title { color: var(--neutral-200, var(--neutral-200)) !important; }

.sk-end-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

.sk-retry,
.sk-refine,
.sk-open-filters {
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 8px 18px;
  border-radius: 999px;
  border: 1px solid var(--sk-edge);
  background: var(--white);
  color: var(--brand-navy-700, var(--brand-navy-700));
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease;
}
.sk-retry:hover,
.sk-refine:hover,
.sk-open-filters:hover { background: #eef3f9; transform: translateY(-1px); }
[data-theme="dark"] .sk-retry,
[data-theme="dark"] .sk-refine,
[data-theme="dark"] .sk-open-filters {
  background: #1a2640;
  color: #a0c4e8;
  border-color: #2a3854;
}

/* ============================================================
   REUSABLE ERROR STATE (legacy class, still used in page JS)
   ============================================================ */
.error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 20px;
  text-align: center;
  gap: 12px;
}

.error-state svg { color: #e74c3c; opacity: 0.7; }

.error-state p {
  font-size: 0.88rem;
  color: #6b7d95;
  margin: 0;
  max-width: 280px;
}

.retry-btn {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 7px 18px;
  border: 1px solid #d0d7e2;
  border-radius: 8px;
  background: var(--white);
  color: var(--brand-navy-700, var(--brand-navy-700));
  cursor: pointer;
  transition: background 0.2s;
}
.retry-btn:hover { background: #eef3f9; }
[data-theme="dark"] .retry-btn {
  background: #1a2640;
  border-color: #2a3854;
  color: #a0c4e8;
}

/* ============================================================
   BUTTON LOADING STATES
   Add .btn-loading to a button; it is disabled visually and
   clicks are ignored. Small inline spinners are allowed — this
   is the only spinner that remains in the product.
   ============================================================ */
@keyframes oletra-spin { to { transform: rotate(360deg); } }
@keyframes oletra-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }

.btn-loading {
  position: relative;
  pointer-events: none;
  opacity: 0.75;
  cursor: progress;
}

.btn-loading::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 18px;
  height: 18px;
  margin: -9px 0 0 -9px;
  border: 2px solid color-mix(in srgb, currentColor 28%, transparent);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: oletra-spin 0.6s linear infinite;
}

.btn-loading > *:not(.skel) { visibility: hidden; }

/* ============================================================
   LEGACY LOADING CONTAINERS -> SKELETONS
   ------------------------------------------------------------
   Many admin/user views still print one of these shapes while their
   fetch runs:
       <div class="loading"><div class="spinner"></div><p>Loading…</p></div>
       <tr><td class="adm-table-loading" colspan="8">Loading…</td></tr>
       <div class="loading-text">Loading…</div>
   The CSS upgrades the SHAPE once, here, so every one of them reads as
   the page's own content arriving instead of a spinner. When a fetch
   fails these containers are free to swap in an error message, which
   stays readable because the inner nodes are hidden, not removed.
   ============================================================ */
.loading,
.loading-text,
.adm-table-loading,
.sm-loading,
.mk-loading,
.oc-loading,
.sp-loading,
.followers-loading,
.cd-loading,
.co-loading,
.ur-loading,
.cmp-loading,
.perms-loading {
  background-color: var(--sk-base);
  background-image: linear-gradient(
    90deg,
    var(--sk-base) 18%,
    var(--sk-highlight) 44%,
    var(--sk-base) 70%
  );
  background-size: var(--sk-sweep) 100%;
  background-repeat: no-repeat;
  animation: sk-shimmer var(--sk-speed) ease-in-out infinite;
  border-radius: var(--sk-radius);
  color: transparent;
  min-height: 14px;
  will-change: background-position;
}

.loading > .spinner,
.loading > .spinner-wrap,
.loading > .loader,
.loading > p,
.loading > span,
.adm-table-loading > .spinner,
.loading-text > .spinner { visibility: hidden; }

.loading {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 18px;
  min-height: 84px;
}

.adm-table-loading {
  padding: 16px;
  min-height: 52px;
  background-image:
    repeating-linear-gradient(180deg, var(--sk-edge) 0 1px, transparent 1px 22px),
    linear-gradient(90deg, var(--sk-base) 18%, var(--sk-highlight) 44%, var(--sk-base) 70%);
  background-size: 100% 100%, var(--sk-sweep) 100%;
}

.loading-text,
.cd-loading,
.co-loading,
.ur-loading,
.cmp-loading,
.perms-loading,
.followers-loading {
  display: block;
  min-height: 14px;
  max-width: 320px;
}

.sm-loading,
.mk-loading,
.oc-loading,
.sp-loading { min-height: 120px; }

@media (prefers-reduced-motion: reduce) {
  .loading,
  .loading-text,
  .adm-table-loading,
  .sm-loading,
  .mk-loading,
  .oc-loading,
  .sp-loading,
  .followers-loading,
  .cd-loading,
  .co-loading,
  .ur-loading,
  .cmp-loading,
  .perms-loading {
    animation-name: sk-breathe;
    animation-duration: 1.8s;
    background-image: none;
  }
  .adm-table-loading {
    background-image: repeating-linear-gradient(180deg, var(--sk-edge) 0 1px, transparent 1px 22px);
  }
}

/* ============================================================
   INFINITE SCROLL CHROME
   ------------------------------------------------------------
   Sentinel (nothing to see — it only marks where the next batch
   starts), the keyboard/no-IO fallback button, and the end-of-list
   block. All three are theme-aware through the aliases in
   theme.css.
   ============================================================ */
.mk-sentinel {
  height: 1px;
  margin-top: 8px;
}

.mk-load-more {
  display: block;
  margin: 22px auto 6px;
  padding: 11px 26px;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-primary, var(--brand-navy-700, var(--brand-navy-700)));
  background: var(--bg-card, var(--white));
  border: 1px solid var(--sk-edge);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.mk-load-more:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 20px rgba(6, 24, 44, 0.14);
}

.mk-load-more:focus-visible {
  outline: 2px solid var(--color-ring, var(--brand-gold, var(--brand-gold)));
  outline-offset: 2px;
}

.mk-end {
  margin: 6px 0 4px;
}

/* Skeleton geometry used by the JS-rendered bottom row keeps the card metrics
   (square media box, three text lines, two-column footer) of a real card. */
.mk-skel-row .mk-card-skeleton .sk-img { --sk-ar: 1 / 1; }

/* Skeleton card that stands in for a real .mk-card: it borrows the card's own
   themed surface (--mk-card) instead of the generic white .sk-card fill, so
   dark mode shows a dark card placeholder rather than a white block. Hover
   lift is disabled — a placeholder is not interactive. */
.mk-card.mk-card-skeleton {
  background: var(--mk-card, var(--sk-card-bg, var(--white)));
  pointer-events: none;
  cursor: default;
}

.mk-card.mk-card-skeleton:hover {
  transform: none;
  border-color: var(--mk-line, var(--sk-edge));
  box-shadow: 0 10px 24px rgba(11, 31, 49, 0.1);
}

.mk-card.mk-card-skeleton .sk-body {
  padding: 12px 14px 16px;
}
