/* ckanext-feedback — RTL-first feedback block for the dataset page.
   ---------------------------------------------------------------------------
   Nests into the portal's GitHub-Primer DARK system: each section mirrors the
   site's .panel shell, comments echo .resource-card, and primary actions use
   the royal-blue .btn-royal language. Royal blue is the single accent here:
     • ROYAL (var(--fb-rating), i.e. --royal-blue) marks ratings — stars and
       histogram bars — and the submit buttons.
   Uses only real design tokens, so light theme (:root[data-theme="light"]),
   which remaps the same token names, works for free.

   JS CONTRACT (feedback-public.js) — do NOT rename these hooks/classes:
     [data-feedback-root] [data-fb-avg-num] [data-fb-avg-count] [data-fb-avg-stars]
     [data-fb-hist] .fb-hist__row .fb-hist__label .fb-hist__bar .fb-hist__fill
     .fb-hist__pct  [data-fb-rate] [data-fb-rate-hint] .fb-rate-hint .fb-form__msg
     .fb-ok .fb-error  [data-report-comment]  [data-feedback-comment-form]
     [data-feedback-issue-form]
   ========================================================================== */

.fb-block {
  --fb-rating: var(--royal-blue, #4169e1);      /* آبی دربار: ستاره‌ها و لوله‌های امتیاز */
  --fb-rating-deep: var(--royal-blue-mid, #1b4fbd);
  display: grid;
  gap: 20px;
  color: var(--fg);
  font-family: var(--font-sans);
}

/* ---- Section card: a .panel clone with a frosted top edge --------------- */
.fb-section {
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 26px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .04), var(--shadow-card);
}

.fb-section__head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 18px;
  flex-wrap: wrap;
}
.fb-section__head h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 800;
  line-height: 1.3;
  color: var(--fg-strong);
}

/* caption pills next to a section title. inline-flex, not inline-grid: a pill
   can hold an icon plus text (.fb-pill--issue), and grid's implicit auto-flow
   stacks unrelated children into separate rows instead of sitting them side
   by side, which is what pushed the warning icon above its label. */
.fb-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  padding: 5px 11px;
  border-radius: 999px;
}
.fb-pill svg { flex-shrink: 0; }
.fb-pill--count {
  font-family: var(--font-mono);
  color: var(--accent-bright);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--accent) 28%, transparent);
}
.fb-pill--issue {
  color: var(--warning);
  background: color-mix(in srgb, var(--warning) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--warning) 26%, transparent);
}
/* light theme: the 12% tinted fill drops the 12px pill text below AA; let the
   accent/warning text sit on the plain section surface (keeps the chip border) */
:root[data-theme="light"] .fb-pill--count,
:root[data-theme="light"] .fb-pill--issue { background: transparent; }

.fb-muted { color: var(--fg-muted); font-size: 13px; line-height: 1.7; margin: 0; }
/* status colors are part of the JS contract; declared after base text rules
   below so the state class always wins the cascade. */

/* ---- Rating: aggregate hero + histogram + interactive ------------------- */
.fb-rating {
  display: grid;
  grid-template-columns: minmax(168px, 210px) 1fr;
  gap: 28px;
  align-items: start;
}

/* hero plate — recessed so the glow halo blooms on the dark inset */
.fb-avg {
  position: relative;
  isolation: isolate;
  text-align: center;
  background: var(--canvas-inset);
  border: 1px solid var(--border-muted);
  border-radius: var(--radius-lg);
  padding: 20px 16px;
}
.fb-avg::before { /* graft C — soft glow halo behind the number */
  content: "";
  position: absolute;
  top: 26px;
  left: 50%;
  transform: translateX(-50%); /* physical centering — direction-agnostic */
  width: 160px;
  height: 160px;
  background: radial-gradient(circle, color-mix(in srgb, var(--glow-blue) 22%, transparent) 0%, transparent 68%);
  z-index: 0;
  pointer-events: none;
}
/* light theme: --canvas-inset (#fff) resolves LIGHTER than --surface-raised
   (#f6f8fa), inverting the intended recess into a raised, popped-out plate;
   mix toward black instead so the hero plate still reads sunken, as it does
   in dark theme. The glow halo relies on that dark inset for contrast, so on
   a light plate it would only read as a faint blue smudge — drop it here. */
:root[data-theme="light"] .fb-avg { background: color-mix(in srgb, var(--surface-raised) 90%, black); }
:root[data-theme="light"] .fb-avg::before { display: none; }
.fb-avg > * { position: relative; z-index: 1; }
.fb-avg__line { display: flex; align-items: baseline; justify-content: center; gap: 7px; }
.fb-avg__num { /* Compact headline average, above the supporting label. */
  font-size: clamp(1.75rem, 3vw, 2rem);
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -.02em;
  color: var(--warning);
  text-shadow: 0 0 18px color-mix(in srgb, var(--warning) 35%, transparent);
}
.fb-avg__num.is-empty { color: var(--fg-muted); text-shadow: none; }
.fb-avg:has(.fb-avg__num.is-empty)::before { display: none; }
.fb-avg__out { font-size: 1rem; font-weight: 600; color: var(--fg-muted); }

/* read-only aggregate stars (frozen mechanism: forced LTR so the gold ::after
   fill maps to score consistently regardless of page direction) */
.fb-stars-static {
  --pct: 0%;
  display: inline-block;
  margin-top: 10px;
  font-size: 1.55rem;
  line-height: 1;
  position: relative;
  unicode-bidi: bidi-override;
  direction: ltr;
}
.fb-stars-static::before { content: "★★★★★"; color: var(--border-strong); }
.fb-stars-static::after {
  content: "★★★★★";
  color: var(--fb-rating);
  position: absolute;
  inset-inline-start: 0;
  top: 0;
  width: var(--pct);
  overflow: hidden;
  white-space: nowrap;
  text-shadow: 0 0 10px color-mix(in srgb, var(--fb-rating) 30%, transparent);
  transition: width var(--transition);
}

/* vote-count caption as a warm pill (graft B); node stays JS-owned */
.fb-avg__count {
  display: inline-block;
  margin-top: 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--fg-muted);
  background: color-mix(in srgb, var(--warning) 10%, transparent);
  border: 1px solid color-mix(in srgb, var(--warning) 24%, transparent);
  border-radius: 999px;
  padding: 3px 12px;
}

/* histogram */
.fb-hist { display: grid; gap: 9px; width: min(100%, 880px); }
.fb-hist__row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 12px; align-items: center; }
.fb-hist__label { font-size: 13px; color: var(--fg-muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.fb-hist__bar {
  display: block;
  height: 6px;
  border-radius: 999px;
  overflow: hidden;
  background: color-mix(in srgb, var(--border-strong) 45%, transparent);
}
/* display:block is required: as an inline span, the width % below is ignored */
.fb-hist__fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--fb-rating-deep), var(--fb-rating));
  transition: width 600ms var(--ease-out); /* WIDTH only — no transform (RTL-safe) */
}
.fb-hist__pct {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--fg-muted);
  min-width: 3.5ch;
  text-align: start;
}

/* interactive star radio group. Forced LTR + row-reverse with DOM order 5→1 so
   selecting star N lights 1..N. Page stays RTL; only this widget flips. */
.fb-rate {
  margin-top: 16px;
  padding: 14px 16px;
  border: 0;
  border-radius: var(--radius-lg);
  /* subtle sub-card tint (distinct from .fb-section's --surface-raised in both
     themes) so the interactive control reads as its own affordance rather than
     a hairline-separated tail of the read-only stats above it. No border-top
     on top of this — that would be a second, redundant separator cue. */
  background: var(--surface-overlay);
}
.fb-rate__legend {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--fg-strong);
}
.fb-rate-input { display: flex; direction: ltr; flex-direction: row-reverse; justify-content: flex-end; gap: 4px; margin-top: 8px; }
.fb-rate-input input[type="radio"] { position: absolute; width: 1px; height: 1px; opacity: 0; }
.fb-rate-input label {
  cursor: pointer;
  font-size: 1.85rem;
  line-height: 1;
  color: var(--border-strong);
  transition: color 120ms ease, transform var(--ease-spring);
  /* the star glyph alone is a ~30px tap target on the primary rating input;
     grow the hit area without changing visual size/spacing (small negative
     margin — kept modest since labels sit only 4px apart in .fb-rate-input) */
  padding: 6px;
  margin: -6px;
}
.fb-rate-input label::before { content: "★"; }
.fb-rate-input input:checked ~ label,
.fb-rate-input label:hover,
.fb-rate-input label:hover ~ label { color: var(--fb-rating); }
.fb-rate-input label:hover { transform: scale(1.12); }
.fb-rate-input input:focus-visible + label {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}
.fb-rate-hint { margin-top: 10px; font-size: 13px; min-height: 1.2em; color: var(--fg-muted); }

/* ---- Comments ----------------------------------------------------------- */
.fb-comment-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.fb-comment { /* .resource-card clone — border+bg hover only, no lift (avoids list jitter) */
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 14px;
  align-items: start;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .03);
  transition: border-color var(--transition), background var(--transition);
}
.fb-comment:hover { border-color: var(--border-strong); background: var(--surface-overlay); }
.fb-comment__avatar {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 999px;
  background: var(--accent-soft);
  border: 1px solid color-mix(in srgb, var(--accent) 28%, transparent);
  color: var(--accent-bright);
  font-size: 15px;
  font-weight: 800;
  user-select: none;
}
.fb-comment__main { min-width: 0; }
.fb-comment__head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.fb-comment__author { min-width: 0; font-weight: 700; font-size: 14px; color: var(--fg-strong); overflow-wrap: anywhere; word-break: break-word; }
.fb-comment__date { font-family: var(--font-mono); font-size: 12px; color: var(--fg-muted); direction: ltr; unicode-bidi: isolate; }
.fb-comment__body { margin: 6px 0 0; white-space: pre-wrap; word-break: break-word; line-height: 1.8; font-size: 14.5px; color: var(--fg); }
.fb-comment__actions {
  margin-top: 8px;
  opacity: 0;
  transform: translateY(2px);
  transition: opacity var(--transition), transform var(--transition);
}
.fb-comment:hover .fb-comment__actions,
.fb-comment:focus-within .fb-comment__actions,
.fb-comment:has(.fb-report-btn:disabled) .fb-comment__actions { opacity: 1; transform: none; }
.fb-report-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  font: inherit;
  font-size: 12.5px;
  color: var(--fg-muted);
  transition: color var(--transition);
}
.fb-report-btn:hover { color: var(--danger); }
.fb-report-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--radius-sm); }
.fb-report-btn:disabled { color: var(--fg-muted); cursor: default; opacity: 1; }
@media (hover: none) {
  .fb-comment__actions { opacity: 1; transform: none; }
}

/* ---- Forms -------------------------------------------------------------- */
.fb-form { display: grid; gap: 14px; }
.fb-form--comment { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--border-muted); }
.fb-form label { font-size: 13px; font-weight: 700; color: var(--fg-strong); }
.fb-form__row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.fb-form__field { display: grid; gap: 8px; }

.fb-field {
  width: 100%;
  min-height: 44px;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--fg);
  font: inherit;
  font-size: 14px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .03);
  transition: border-color var(--transition), background var(--transition), box-shadow var(--transition);
}
.fb-field::placeholder { color: var(--fg-subtle); }
.fb-field:hover { border-color: var(--border-strong); }
.fb-field:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus-ring); }
textarea.fb-field { min-height: 110px; resize: vertical; line-height: 1.7; }
.fb-form--comment textarea.fb-field { min-height: 96px; }

/* custom select with an RTL-correct chevron */
.fb-select { position: relative; }
.fb-select select.fb-field { appearance: none; padding-inline-start: 38px; cursor: pointer; font-weight: 600; }
.fb-select::after {
  content: "";
  position: absolute;
  inset-inline-start: 16px;
  top: 50%;
  width: 8px;
  height: 8px;
  border-inline-start: 2px solid var(--fg-muted);
  border-bottom: 2px solid var(--fg-muted);
  transform: translateY(-65%) rotate(-45deg);
  pointer-events: none;
}

.fb-honeypot { position: absolute; inset-inline-start: -9999px; width: 1px; height: 1px; overflow: hidden; }
.fb-form__actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.fb-form__msg { font-size: 13.5px; min-height: 1.2em; color: var(--fg-muted); }

/* primary button = .btn-royal verbatim */
.fb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding-inline: 20px;
  border: 1px solid var(--royal-blue-border);
  border-radius: var(--radius-md);
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.2;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(180deg, var(--royal-blue-light) 0%, var(--royal-blue-mid) 52%, var(--royal-blue-deep) 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .22), 0 8px 20px var(--royal-blue-shadow), 0 0 0 1px rgba(65, 105, 225, .12);
  transition: background var(--transition), border-color var(--transition), box-shadow var(--transition), transform var(--transition);
}
.fb-btn:hover {
  background: linear-gradient(180deg, #4169e1 0%, #2456c9 52%, #002c7a 100%);
  border-color: rgba(212, 225, 255, .42);
  transform: translateY(-1px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .28), 0 10px 24px rgba(65, 105, 225, .52), 0 0 0 1px rgba(111, 141, 255, .22);
}
.fb-btn:active { transform: translateY(0); box-shadow: inset 0 2px 4px rgba(0, 0, 0, .18), 0 4px 14px rgba(65, 105, 225, .34); }
.fb-btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.fb-btn:disabled {
  background: var(--surface-overlay);
  color: var(--fg-subtle);
  border-color: var(--border);
  box-shadow: none;
  cursor: not-allowed;
  transform: none;
}

/* empty / login gates */
.fb-empty, .fb-login-gate {
  display: grid;
  gap: 8px;
  justify-items: center;
  text-align: center;
  padding: 22px 16px;
  border: 1px dashed var(--border-muted);
  border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--surface-overlay) 60%, transparent);
  color: var(--fg-muted);
  font-size: 13.5px;
}
.fb-empty__icon { color: var(--fg-subtle); opacity: .8; }
.fb-login-gate { margin-top: 16px; }
.fb-block a { color: var(--accent-bright); text-decoration: none; }
.fb-block a:hover { text-decoration: underline; }

/* status colors — JS toggles these; keep last so the state wins */
.fb-ok { color: var(--success-bright); font-weight: 700; }
.fb-error { color: var(--danger); font-weight: 700; }
/* light theme: --success-bright (#2da44e) is too light on the light surface at
   body size; use the darker on-system green (matches --code-prop) to clear AA */
:root[data-theme="light"] .fb-ok { color: #116329; }

/* ---- Responsive --------------------------------------------------------- */
@media (max-width: 640px) {
  .fb-section { padding: 20px; }
  .fb-rating { grid-template-columns: 1fr; gap: 22px; }
  .fb-form__row { grid-template-columns: 1fr; }
  .fb-avg::before { width: 130px; height: 130px; }
  .fb-comment__actions { opacity: 1; transform: none; }
  /* the page's other primary actions (.download-link, .resource-preview__toggle)
     were bumped to 44px on this same breakpoint; the feedback submit button
     is an equally primary action and should match */
  .fb-btn { min-height: 44px; }
}

/* ---- Reduced motion ----------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  .fb-stars-static::after,
  .fb-hist__fill,
  .fb-rate-input label,
  .fb-comment,
  .fb-comment__actions,
  .fb-field,
  .fb-btn { transition: none; }
  .fb-rate-input label:hover,
  .fb-btn:hover { transform: none; }
}
