/* Public-site components (spec §8) with motion (spec §9).
   Every value is a token from ../out/tokens.css. Anything that moves uses transform and
   opacity only (spec §9 rule 8). Paint-only effects (background-color, border-color,
   colour, the flash and the skeleton shimmer's background-position) never trigger layout
   and are the only other things animated. Nothing animates width, height, padding or margin. */
@import '../out/tokens.css';

.sg-root {
  font-family: var(--sg-font-stack);
  font-size: var(--sg-text-body-size);
  line-height: var(--sg-text-body-lh);
  color: var(--sg-color-lapis);
  background: var(--sg-color-white);
}
.sg-root *, .sg-root *::before, .sg-root *::after { box-sizing: border-box; }

/* ---------- numbers: always LTR, tabular ---------- */
.sg-num {
  direction: ltr;
  unicode-bidi: isolate;
  display: inline-block;
  font-variant-numeric: tabular-nums;
}
.sg-num--display {
  font-size: var(--sg-text-display-size);
  line-height: var(--sg-text-display-lh);
  font-weight: var(--sg-text-display-weight);
}

/* ---------- button ---------- */
.sg-btn {
  font-family: var(--sg-font-stack);
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sg-space-8);
  height: 48px;
  padding: 0 var(--sg-space-20);
  border: 0;
  border-radius: var(--sg-radius-control);
  font-size: var(--sg-text-body-size);
  font-weight: var(--sg-text-label-weight);
  line-height: 1;
  cursor: pointer;
  text-decoration: none;
  transition:
    transform var(--sg-motion-t1) var(--sg-motion-ease-out),
    background-color var(--sg-motion-t2) var(--sg-motion-ease-out);
}
.sg-btn:active { transform: scale(var(--sg-motion-press-scale)); }
.sg-btn:focus-visible { outline: 2px solid var(--sg-color-lapis); outline-offset: 2px; }
.sg-btn--primary { background: var(--sg-color-lapis); color: var(--sg-color-white); }
.sg-btn--primary:hover { background: color-mix(in srgb, var(--sg-color-lapis), var(--sg-color-white) 12%); }
.sg-btn--secondary { background: var(--sg-color-fill); color: var(--sg-color-lapis); }
.sg-btn--secondary:hover { background: color-mix(in srgb, var(--sg-color-fill), var(--sg-color-charcoal) 7%); }
.sg-btn--tertiary { background: transparent; color: var(--sg-color-lapis); padding: 0 var(--sg-space-12); }
.sg-btn--tertiary:hover { background: var(--sg-color-fill2); }
.sg-btn--small { height: 36px; padding: 0 var(--sg-space-12); font-size: var(--sg-text-label-size); }
.sg-btn--block { width: 100%; }

/* ---------- field + input ---------- */
.sg-field { display: block; }
.sg-field__label {
  display: block; margin-bottom: var(--sg-space-8);
  font-size: var(--sg-text-label-size); line-height: var(--sg-text-label-lh); font-weight: var(--sg-text-label-weight);
}
.sg-field__help {
  display: block; margin-top: var(--sg-space-4);
  font-size: var(--sg-text-caption-size); line-height: var(--sg-text-caption-lh); color: var(--sg-color-muted);
}
.sg-input {
  display: flex; align-items: center; gap: var(--sg-space-8);
  height: 48px;
  padding: 0 var(--sg-space-12);
  background: var(--sg-color-fill);
  border: 2px solid transparent;
  border-radius: var(--sg-radius-control);
  transition:
    border-color var(--sg-motion-t2) var(--sg-motion-ease-out),
    background-color var(--sg-motion-t2) var(--sg-motion-ease-out);
}
.sg-input:focus-within { border-color: var(--sg-color-lapis); background: var(--sg-color-fill2); }
.sg-input input {
  flex: 1; min-width: 0; border: 0; outline: 0; background: none;
  font: inherit; font-family: var(--sg-font-stack); font-size: var(--sg-text-body-size);
  color: var(--sg-color-lapis);
  direction: ltr; text-align: right; font-variant-numeric: tabular-nums;
}
.sg-input__end { font-size: var(--sg-text-caption-size); color: var(--sg-color-muted); white-space: nowrap; }

/* ---------- segmented control ---------- */
.sg-seg {
  --sg-seg-pad: var(--sg-space-4);
  position: relative; display: inline-grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  padding: var(--sg-seg-pad);
  background: var(--sg-color-fill);
  border-radius: var(--sg-radius-control);
}
.sg-seg__opt {
  position: relative; z-index: 1;
  padding: var(--sg-space-8) var(--sg-space-16);
  border: 0; background: none; cursor: pointer;
  font-family: var(--sg-font-stack); font-size: var(--sg-text-label-size); font-weight: var(--sg-text-label-weight); line-height: 1.2;
  color: var(--sg-color-muted);
  transition: color var(--sg-motion-t2) var(--sg-motion-ease-out);
}
.sg-seg__opt[aria-pressed="true"] { color: var(--sg-color-lapis); }
.sg-seg__thumb {
  position: absolute; top: var(--sg-seg-pad); bottom: var(--sg-seg-pad);
  inset-inline-start: var(--sg-seg-pad);
  width: calc((100% - 2 * var(--sg-seg-pad)) / var(--sg-seg-n, 2));
  background: var(--sg-color-white);
  border-radius: calc(var(--sg-radius-control) - 2px);
  box-shadow: var(--sg-shadow-raised);
  transition: transform var(--sg-motion-t3) var(--sg-motion-ease-out);
}
/* thumb follows the pressed option (2 options: gram / mithqal). setSegment() in motion.js mirrors
   the pressed index into data-active="0|1" on .sg-seg (server-rendered markup sets it too), so the
   thumb works without :has(). The :has() rules are progressive enhancement for markup that only
   carries aria-pressed. Each selector is its own rule: one unsupported selector drops a whole list. */
.sg-seg[data-active="1"] .sg-seg__thumb { transform: translateX(-100%); }
[dir="ltr"] .sg-seg[data-active="1"] .sg-seg__thumb { transform: translateX(100%); }
.sg-seg:has(.sg-seg__opt:nth-of-type(2)[aria-pressed="true"]) .sg-seg__thumb { transform: translateX(-100%); }
.sg-seg:dir(ltr):has(.sg-seg__opt:nth-of-type(2)[aria-pressed="true"]) .sg-seg__thumb { transform: translateX(100%); }

/* ---------- tabs ---------- */
.sg-tabs {
  position: relative; display: flex; gap: var(--sg-space-24);
  border-bottom: 1px solid var(--sg-color-line);
}
.sg-tab {
  padding: var(--sg-space-12) 0; border: 0; background: none; cursor: pointer;
  font-family: var(--sg-font-stack); font-size: var(--sg-text-body-size); font-weight: var(--sg-text-label-weight);
  color: var(--sg-color-muted);
  transition: color var(--sg-motion-t2) var(--sg-motion-ease-out);
}
.sg-tab[aria-selected="true"] { color: var(--sg-color-lapis); }
/* 1px-wide bar; placeIndicator() in motion.js sets translateX(x) scaleX(width), so only
   transform animates and it works in either direction */
.sg-tabs__ind {
  position: absolute; left: 0; bottom: -1px; height: 3px; width: 1px;
  transform-origin: left center;
  background: var(--sg-color-lapis); border-radius: 1px;
  transition: transform var(--sg-motion-t3) var(--sg-motion-ease-out);
}

/* ---------- tag ---------- */
.sg-tag {
  display: inline-flex; align-items: center; gap: var(--sg-space-8);
  height: 24px; padding: 0 var(--sg-space-12);
  border-radius: var(--sg-radius-pill);
  background: var(--sg-color-fill); color: var(--sg-color-lapis);
  font-size: var(--sg-text-caption-size); font-weight: var(--sg-text-label-weight); line-height: 1;
  white-space: nowrap;
}
.sg-tag--neutral { background: var(--sg-color-fill); color: var(--sg-color-lapis); }
.sg-tag--official { background: var(--sg-color-gold-tint); color: var(--sg-color-gold-ink); }
.sg-tag--ok { background: var(--sg-color-up-bg); color: var(--sg-color-up); }
.sg-tag--down { background: var(--sg-color-down-bg); color: var(--sg-color-down); }
/* «السعر الرسمي» dot: static on purpose (founder 2026-11-21, spec §9 rule 6: nothing loops). */
.sg-tag__live {
  width: 7px; height: 7px; border-radius: 50%; background: currentColor;
}

/* ---------- notice ---------- */
.sg-notice {
  padding: var(--sg-space-12) var(--sg-space-16);
  border-radius: var(--sg-radius-control);
  font-size: var(--sg-text-label-size); line-height: 1.6;
  background: var(--sg-color-info-bg); color: var(--sg-color-info);
}
.sg-notice--info { background: var(--sg-color-info-bg); color: var(--sg-color-info); }
.sg-notice--warn { background: var(--sg-color-warn-bg); color: var(--sg-color-warn); }
.sg-notice--ok { background: var(--sg-color-up-bg); color: var(--sg-color-up); }
.sg-notice--error { background: var(--sg-color-down-bg); color: var(--sg-color-down); }

/* ---------- table ---------- */
.sg-table { width: 100%; border-collapse: collapse; font-size: var(--sg-text-body-size); }
.sg-table th {
  padding: var(--sg-space-12) 0; text-align: start;
  font-size: var(--sg-text-label-size); font-weight: var(--sg-text-label-weight); color: var(--sg-color-muted);
  border-bottom: 1px solid var(--sg-color-line);
}
.sg-table td { padding: var(--sg-space-12) 0; border-bottom: 1px solid var(--sg-color-line); }
.sg-table__num { direction: ltr; unicode-bidi: isolate; text-align: right; font-variant-numeric: tabular-nums; }
.sg-table__cell { transition: opacity var(--sg-motion-t2) var(--sg-motion-ease-out); }
.sg-table__cell.is-fading { opacity: .15; }

/* ---------- list row ---------- */
.sg-list-row {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sg-space-12);
  padding: var(--sg-space-16) 0;
  border-bottom: 1px solid var(--sg-color-line);
  color: inherit; text-decoration: none;
  /* the inset is permanent (padding + negative margin) so hover only changes paint, never layout */
  padding-inline: var(--sg-space-8); margin-inline: calc(-1 * var(--sg-space-8));
  border-radius: var(--sg-radius-control);
  transition: background-color var(--sg-motion-t2) var(--sg-motion-ease-out);
}
.sg-list-row:hover { background: var(--sg-color-fill2); }
.sg-list-row__title { font-size: var(--sg-text-h3-size); line-height: var(--sg-text-h3-lh); font-weight: var(--sg-text-h3-weight); margin-top: var(--sg-space-8); }
.sg-list-row__meta { font-size: var(--sg-text-caption-size); line-height: var(--sg-text-caption-lh); color: var(--sg-color-muted); margin-top: var(--sg-space-4); }
.sg-list-row__chev { color: var(--sg-color-muted); transition: transform var(--sg-motion-t2) var(--sg-motion-ease-out); }
.sg-list-row:hover .sg-list-row__chev { transform: translateX(-4px); }

/* ---------- card ---------- */
.sg-card {
  background: var(--sg-color-white);
  border: 1px solid var(--sg-color-line);
  border-radius: var(--sg-radius-card);
  padding: var(--sg-space-16);
}

/* ---------- scrim + bottom sheet (centred modal from the first breakpoint up) ---------- */
.sg-scrim {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(28, 28, 30, .4); /* = charcoal at 40 %, for browsers without color-mix() */
  background: color-mix(in srgb, var(--sg-color-charcoal), transparent 60%);
  opacity: 0; visibility: hidden;
  transition: opacity var(--sg-motion-t3) var(--sg-motion-ease-out), visibility 0s linear var(--sg-motion-t3);
}
.sg-scrim.is-open { opacity: 1; visibility: visible; transition-delay: 0s; }
.sg-sheet {
  position: fixed; inset-inline: 0; bottom: 0; z-index: 50;
  padding: var(--sg-space-20) var(--sg-space-20) var(--sg-space-24);
  background: var(--sg-color-white);
  border-radius: var(--sg-radius-card) var(--sg-radius-card) 0 0;
  box-shadow: var(--sg-shadow-sheet);
  transform: translateY(100%); visibility: hidden;
  transition: transform var(--sg-motion-t4) var(--sg-motion-ease-out), visibility 0s linear var(--sg-motion-t4);
}
.sg-sheet.is-open { transform: none; visibility: visible; transition-delay: 0s; }
.sg-sheet__handle { width: 36px; height: 4px; margin: 0 auto var(--sg-space-12); border-radius: 2px; background: var(--sg-color-line); }
@media (min-width: 600px) { /* = --sg-layout-bp1; custom properties can't be used in media queries */
  .sg-sheet {
    inset-inline: auto; bottom: auto; top: 50%; left: 50%;
    width: min(480px, calc(100% - 2 * var(--sg-layout-gutter)));
    border-radius: var(--sg-radius-card);
    box-shadow: var(--sg-shadow-overlay);
    transform: translate(-50%, -46%); opacity: 0;
    transition: transform var(--sg-motion-t4) var(--sg-motion-ease-out), opacity var(--sg-motion-t3) var(--sg-motion-ease-out), visibility 0s linear var(--sg-motion-t4);
  }
  .sg-sheet.is-open { transform: translate(-50%, -50%); opacity: 1; }
  .sg-sheet__handle { display: none; }
}

/* ---------- toast ---------- */
.sg-toast {
  position: fixed; top: var(--sg-space-16); inset-inline: var(--sg-layout-gutter-phone); z-index: 60;
  margin-inline: auto; max-width: 480px;
  display: flex; align-items: center; gap: var(--sg-space-12);
  padding: var(--sg-space-12) var(--sg-space-16);
  background: var(--sg-color-lapis); color: var(--sg-color-white);
  border-radius: var(--sg-radius-control);
  box-shadow: var(--sg-shadow-overlay);
  font-size: var(--sg-text-label-size);
  opacity: 0; transform: translateY(-16px); pointer-events: none;
  transition: opacity var(--sg-motion-t3) var(--sg-motion-ease-out), transform var(--sg-motion-t3) var(--sg-motion-ease-out);
}
.sg-toast.is-shown { opacity: 1; transform: none; }

/* ---------- skeleton ---------- */
.sg-skel {
  display: block;
  background: linear-gradient(90deg, var(--sg-color-fill) 0%, var(--sg-color-fill2) 40%, var(--sg-color-fill) 80%);
  background-size: 300% 100%;
  border-radius: 6px;
  animation: sg-shimmer 1.4s linear infinite;
}
.sg-skel[hidden] { display: none; }
@keyframes sg-shimmer { from { background-position: 100% 0; } to { background-position: -200% 0; } }

/* ---------- price change chip + flash ---------- */
.sg-delta {
  display: inline-flex; align-items: center; gap: var(--sg-space-4);
  padding: 2px var(--sg-space-8);
  border-radius: var(--sg-radius-pill);
  font-size: var(--sg-text-label-size); font-weight: var(--sg-text-h3-weight); font-variant-numeric: tabular-nums;
  direction: ltr; unicode-bidi: isolate;
  opacity: 0; transform: translateY(6px);
  transition: opacity var(--sg-motion-t3) var(--sg-motion-ease-out), transform var(--sg-motion-t3) var(--sg-motion-ease-out);
}
.sg-delta.is-shown { opacity: 1; transform: none; }
.sg-delta--up { background: var(--sg-color-up-bg); color: var(--sg-color-up); }
.sg-delta--down { background: var(--sg-color-down-bg); color: var(--sg-color-down); }
.sg-flash { animation: sg-flash 1.2s var(--sg-motion-ease-out); }
@keyframes sg-flash { 0% { background-color: var(--sg-color-flash); } 100% { background-color: transparent; } }

/* ---------- header / footer ---------- */
.sg-header {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sg-space-16);
  padding: var(--sg-space-12) var(--sg-layout-gutter-phone);
  background: var(--sg-color-white); border-bottom: 1px solid var(--sg-color-line);
}
.sg-footer {
  padding: var(--sg-space-32) var(--sg-layout-gutter-phone);
  background: var(--sg-color-alabaster); color: var(--sg-color-lapis);
  font-size: var(--sg-text-label-size);
}
.sg-footer--emerald { background: var(--sg-color-emerald); color: var(--sg-color-alabaster); }
.sg-footer__credit { margin-top: var(--sg-space-16); font-size: var(--sg-text-caption-size); color: var(--sg-color-muted); }
.sg-footer--emerald .sg-footer__credit { color: color-mix(in srgb, var(--sg-color-alabaster), transparent 30%); }

/* ---------- page reveal: secondary content only, never the price ---------- */
.sg-reveal {
  animation: sg-rise var(--sg-motion-t3) var(--sg-motion-ease-out) both;
  animation-delay: calc(var(--i, 0) * var(--sg-motion-stagger));
}
@keyframes sg-rise { from { opacity: 0; transform: translateY(var(--sg-motion-rise)); } }

/* ---------- reduced motion: everything instant, nothing loops ---------- */
@media (prefers-reduced-motion: reduce) {
  .sg-root *, .sg-root *::before, .sg-root *::after,
  .sg-btn, .sg-input, .sg-seg__opt, .sg-seg__thumb, .sg-tab, .sg-tabs__ind, .sg-table__cell,
  .sg-list-row, .sg-list-row__chev, .sg-scrim, .sg-sheet, .sg-toast, .sg-skel, .sg-delta,
  .sg-flash, .sg-reveal {
    animation: none !important;
    transition: none !important;
  }
}
