/* ============================================================================
   KAMC — Brand Patterns  ·  أنماط الهوية
   Visual system: "الخط الحيّ / The Living Line"

   Requires kamc-tokens.css to be loaded first (--line-field*, --pitch-*).

   Five tiers, one grammar. In every one of them a strip is 42% of the pitch
   wide, and the pitches double: 6 · 12 · 24 · 48 · 96.

   TILING — this matters, and getting it wrong is the usual mistake:
     P1 Pulse        tiles on X only.  Fixed-height band.
     P2 Sample grid  tiles on X and Y. Safe behind body text.
     P3 Sampled wave does NOT tile. Composed full-bleed art, one per size.
     P4 The rule     tiles on X only.  Anchored to a page edge.
     P5 Grain        tiles on X and Y at 24px.
     P6 Pentad       does NOT tile. A single mark.
   ========================================================================== */

/* -- Base ------------------------------------------------------------------ */
.kamc-pattern {
  background-repeat: repeat-x;
  background-position: center;
  pointer-events: none;
}

/* Patterns are decoration. When one sits behind content, put it on a layer of
   its own so it can never intercept a click or confuse a screen reader. */
.kamc-pattern-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}
.kamc-pattern-layer + * { position: relative; z-index: 1; }


/* ══ P1 — PULSE · النبض · Primary Brand Pattern ═══════════════════════════
   Section bands, hero blocks, card headers, the strip under a page title. */

.kamc-p1-pulse {
  background-image: url("svg/p1-pulse-light.svg");
  background-repeat: repeat-x;
  background-size: auto 100%;
}
.kamc-p1-pulse--wide { background-image: url("svg/p1-pulse-wide-light.svg"); }
.kamc-p1-pulse--fine { background-image: url("svg/p1-pulse-fine-light.svg"); }

/* -- P2 — SAMPLE GRID · شبكة العيّنة · Subtle Digital ---------------------
   The default page texture. Low enough to sit under body copy.
   Expressed in pure CSS so it costs no request and follows the theme. */

.kamc-p2-sample {
  background-image: repeating-linear-gradient(
    90deg,
    var(--line-field-soft) 0,
    var(--line-field-soft) calc(var(--pitch-fine) * 0.42),
    transparent            calc(var(--pitch-fine) * 0.42),
    transparent            var(--pitch-fine)
  );
  background-repeat: repeat;
}
.kamc-p2-sample--24 { --pitch-fine: var(--pitch-base); }

/* -- P3 — SAMPLED WAVE · الموجة المُعاينة · Hero / Marketing --------------
   The pattern that carries the argument: Health Holding draws the Flow of
   Care as a continuous curve; this city samples it into measured strips.
   Pick the file that matches the box — it is composed, not tiled. */

.kamc-p3-wave {
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center;
}
.kamc-p3-wave--desktop  { background-image: url("svg/p3-wave-dark-desktop-1920x1080.svg"); }
.kamc-p3-wave--square   { background-image: url("svg/p3-wave-dark-square-1080x1080.svg"); }
.kamc-p3-wave--portrait { background-image: url("svg/p3-wave-dark-portrait-1080x1350.svg"); }
.kamc-p3-wave--story    { background-image: url("svg/p3-wave-dark-story-1080x1920.svg"); }
.kamc-p3-wave--banner   { background-image: url("svg/p3-wave-dark-banner-2560x720.svg"); }
.kamc-p3-wave--og       { background-image: url("svg/p3-wave-dark-og-1200x630.svg"); }

/* -- P4 — THE RULE · المسطرة · Corporate ---------------------------------
   Reports, letterhead, slide masters, certificates, the foot of a document.
   Anchor it to an edge; never float it in the middle of a page. */

.kamc-p4-rule {
  background-image: url("svg/p4-rule-light.svg");
  background-repeat: repeat-x;
  background-position: bottom center;
  background-size: auto 100%;
  height: 64px;
}
.kamc-p4-rule--top {
  background-image: url("svg/p4-rule-top-light.svg");
  background-position: top center;
}
.kamc-p4-rule--tall { background-image: url("svg/p4-rule-tall-light.svg"); height: 120px; }

/* -- P5 — GRAIN · الحبيبات · Micro texture -------------------------------
   Cards, tiles, empty states, small surfaces. Barely there by design. */

.kamc-p5-grain {
  background-image: url("svg/p5-grain-light.svg");
  background-repeat: repeat;
  background-size: 24px 24px;
}

/* -- P6 — PENTAD · البتلة المُعاينة --------------------------------------
   The star silhouette sampled by one field of vertical strips — the logo's
   own construction, in the system's own grammar. Splash, loading, watermark,
   empty states. It is NOT a substitute for the logo: never place it where
   the logo should be, and never set it beside the logo at similar size. */

.kamc-p6-pentad {
  background-image: url("svg/p6-pentad-light.svg");
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  aspect-ratio: 1;
}
.kamc-p6-pentad--spectrum { background-image: url("svg/p6-pentad-spectrum-light.svg"); }


/* ══ DARK THEME ═══════════════════════════════════════════════════════════
   Strips swap from PANTONE 299 C to 2985 C. The pure-CSS patterns follow
   the tokens on their own and need no override. */

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .kamc-p1-pulse            { background-image: url("svg/p1-pulse-dark.svg"); }
  :root:not([data-theme="light"]) .kamc-p1-pulse--wide      { background-image: url("svg/p1-pulse-wide-dark.svg"); }
  :root:not([data-theme="light"]) .kamc-p1-pulse--fine      { background-image: url("svg/p1-pulse-fine-dark.svg"); }
  :root:not([data-theme="light"]) .kamc-p4-rule             { background-image: url("svg/p4-rule-dark.svg"); }
  :root:not([data-theme="light"]) .kamc-p4-rule--top        { background-image: url("svg/p4-rule-top-dark.svg"); }
  :root:not([data-theme="light"]) .kamc-p4-rule--tall       { background-image: url("svg/p4-rule-tall-dark.svg"); }
  :root:not([data-theme="light"]) .kamc-p5-grain            { background-image: url("svg/p5-grain-dark.svg"); }
  :root:not([data-theme="light"]) .kamc-p6-pentad           { background-image: url("svg/p6-pentad-dark.svg"); }
  :root:not([data-theme="light"]) .kamc-p6-pentad--spectrum { background-image: url("svg/p6-pentad-spectrum-dark.svg"); }
}

[data-theme="dark"] .kamc-p1-pulse            { background-image: url("svg/p1-pulse-dark.svg"); }
[data-theme="dark"] .kamc-p1-pulse--wide      { background-image: url("svg/p1-pulse-wide-dark.svg"); }
[data-theme="dark"] .kamc-p1-pulse--fine      { background-image: url("svg/p1-pulse-fine-dark.svg"); }
[data-theme="dark"] .kamc-p4-rule             { background-image: url("svg/p4-rule-dark.svg"); }
[data-theme="dark"] .kamc-p4-rule--top        { background-image: url("svg/p4-rule-top-dark.svg"); }
[data-theme="dark"] .kamc-p4-rule--tall       { background-image: url("svg/p4-rule-tall-dark.svg"); }
[data-theme="dark"] .kamc-p5-grain            { background-image: url("svg/p5-grain-dark.svg"); }
[data-theme="dark"] .kamc-p6-pentad           { background-image: url("svg/p6-pentad-dark.svg"); }
[data-theme="dark"] .kamc-p6-pentad--spectrum { background-image: url("svg/p6-pentad-spectrum-dark.svg"); }


/* ══ FADES ════════════════════════════════════════════════════════════════
   A pattern must never end on a hard edge. Fade it out into the surface. */

.kamc-fade-b { -webkit-mask-image: linear-gradient(180deg, #000 45%, transparent 100%);
                       mask-image: linear-gradient(180deg, #000 45%, transparent 100%); }
.kamc-fade-t { -webkit-mask-image: linear-gradient(0deg,   #000 45%, transparent 100%);
                       mask-image: linear-gradient(0deg,   #000 45%, transparent 100%); }
.kamc-fade-x { -webkit-mask-image: linear-gradient(90deg,  transparent, #000 22%, #000 78%, transparent);
                       mask-image: linear-gradient(90deg,  transparent, #000 22%, #000 78%, transparent); }
/* Inline-aware: fades toward the end of the reading direction, so it behaves
   correctly in Arabic without a separate rule. */
.kamc-fade-inline { -webkit-mask-image: linear-gradient(to left, #000 40%, transparent 100%);
                            mask-image: linear-gradient(to left, #000 40%, transparent 100%); }
[dir="ltr"] .kamc-fade-inline { -webkit-mask-image: linear-gradient(to right, #000 40%, transparent 100%);
                                        mask-image: linear-gradient(to right, #000 40%, transparent 100%); }


/* ══ MOTION ═══════════════════════════════════════════════════════════════
   The line field breathes. It never bounces and it never races — the pulse
   is 2.4s, about the pace of a calm breath. Anything faster reads as alarm,
   which is the wrong signal in a hospital. */

@keyframes kamc-drift { from { background-position-x: 0; } to { background-position-x: var(--pitch-base); } }

.kamc-animate-drift {
  animation: kamc-drift var(--dur-pulse) linear infinite;
}

@keyframes kamc-breathe { 0%, 100% { opacity: .70; } 50% { opacity: 1; } }

.kamc-animate-breathe {
  animation: kamc-breathe var(--dur-pulse) var(--ease-flow) infinite;
}

@media (prefers-reduced-motion: reduce) {
  .kamc-animate-drift,
  .kamc-animate-breathe { animation: none; }
}
