/* Fursa UI v2 — /research (slice 3.3). One calm 880px column: title + lede,
   an optional AI-review callout, the query card (shared .fx-searchbar,
   category toggle pills, the frozen year-range slider restyled in tokens,
   both help texts tucked behind one info popover), «إدارة الفئات» as one
   quiet disclosure row, then the results head (scope · count · years +
   export), four underline tabs and the four views — fx-stat tiles, fx-table
   tables, the pricing SVG restyled through its class hooks only, and the
   records list as shared .fx-tcards card rows (components.css §21 owns the
   face, sort strip, entrance and pager — this file owns only the page's
   column template and per-cell placement). Every selector is scoped to
   html[data-ui="v2"] under .fx-page--research; colours, spacing and motion
   come from tokens only. */

/* ---------------------------------------------------------------------------
   1. Frame — one column like /search and the agency page.
--------------------------------------------------------------------------- */

html[data-ui="v2"] .fx-page--research{
  display:grid; gap:var(--fx-space-6); align-content:start;
  max-inline-size:880px; margin-inline:auto; inline-size:100%;
}
html[data-ui="v2"] .fx-page--research > *{min-inline-size:0}
html[data-ui="v2"] .fx-page--research .fx-research__head{display:grid; gap:4px}

/* ---------------------------------------------------------------------------
   2. Query card — the shared .fx-searchbar on top, categories as toggle
      pills (the real checkbox covers its label invisibly, like .scope-pills;
      :has() draws checked and focus), the two help texts behind one info
      popover, then the frozen year-range mechanics in token colours.
--------------------------------------------------------------------------- */

html[data-ui="v2"] .fx-page--research .fx-research__form{
  display:grid; gap:var(--fx-space-4); max-inline-size:none; margin:0;
}
html[data-ui="v2"] .fx-page--research .fx-cats{
  display:grid; gap:var(--fx-space-2); min-inline-size:0;
}
html[data-ui="v2"] .fx-page--research .fx-cats__head{
  display:flex; align-items:baseline; gap:var(--fx-space-2);
}
html[data-ui="v2"] .fx-page--research .fx-cats__head .flabel{margin:0}
html[data-ui="v2"] .fx-page--research .fx-cats__info{
  padding:2px; color:var(--fx-text-subtle); line-height:0;
}
html[data-ui="v2"] .fx-page--research .fx-cats__info:hover{color:var(--fx-primary)}
html[data-ui="v2"] .fx-page--research .fx-cats__info svg{display:block}
html[data-ui="v2"] .fx-page--research .fx-cats__help.fx-popover{
  inline-size:min(26rem, calc(100vw - 24px)); block-size:auto;
  padding:var(--fx-space-3) var(--fx-space-4);
  border:1px solid var(--fx-border); border-radius:var(--fx-radius-md);
  background:var(--fx-surface-raised); color:var(--fx-text);
  box-shadow:var(--fx-shadow-lg);
  font-size:var(--fx-text-sm); line-height:var(--fx-leading-body);
  overflow-wrap:normal; word-break:normal; white-space:normal;
}
html[data-ui="v2"] .fx-page--research .fx-cats__help.fx-popover:popover-open{
  animation:fx-pop-in var(--fx-dur-fast) var(--fx-ease-out) both;
}
html[data-ui="v2"] .fx-page--research .fx-cats__help p{margin:0}
html[data-ui="v2"] .fx-page--research .fx-cats__help p + p{margin-block-start:var(--fx-space-2)}
/* Anchored under its cue where the browser supports anchor positioning. */
@supports (top:anchor(bottom)){
  html[data-ui="v2"] .fx-page--research .fx-cats__help.fx-popover{
    margin:0; inset:auto;
    top:calc(anchor(bottom) + 8px);
    inset-inline-start:anchor(start);
    position-try-fallbacks:flip-block;
  }
}

/* Category pills — brand-soft fill + primary border when checked; the ring
   lands on the pill via :has(:focus-visible) since the input is invisible. */
html[data-ui="v2"] .fx-page--research .fx-cats__list{
  display:flex; flex-wrap:wrap; align-items:center; gap:var(--fx-space-2);
  margin:0; font-size:inherit;
}
html[data-ui="v2"] .fx-page--research .fx-cats__list .market-area{
  position:relative; display:inline-flex; align-items:center; gap:0;
  min-block-size:var(--fx-control-h-sm); padding:0 var(--fx-space-4);
  border:1px solid var(--fx-border-strong); border-radius:var(--fx-radius-pill);
  background:var(--fx-surface); color:var(--fx-text);
  font-size:var(--fx-text-sm); font-weight:var(--fx-weight-medium);
  cursor:pointer; user-select:none;
  transition:background-color var(--fx-dur-fast) var(--fx-ease-out),
    border-color var(--fx-dur-fast) var(--fx-ease-out),
    color var(--fx-dur-fast) var(--fx-ease-out),
    box-shadow var(--fx-dur-fast) var(--fx-ease-out);
}
html[data-ui="v2"] .fx-page--research .fx-cats__list .market-area:hover{
  background:var(--fx-surface-hover);
}
html[data-ui="v2"] .fx-page--research .fx-cats__list .market-area:has(input:checked){
  background:var(--fx-primary-soft); border-color:var(--fx-primary);
  color:var(--fx-primary); font-weight:var(--fx-weight-semibold);
}
html[data-ui="v2"] .fx-page--research .fx-cats__list .market-area input{
  position:absolute; inset:0; margin:0; opacity:0; cursor:pointer;
}
html[data-ui="v2"] .fx-page--research .fx-cats__list .market-area input:focus-visible{
  outline:none;
}
html[data-ui="v2"] .fx-page--research .fx-cats__list .market-area:has(input:focus-visible){
  box-shadow:var(--fx-ring);
}
html[data-ui="v2"] .fx-page--research .fx-cats__list .market-area .market-area__name{
  overflow-wrap:anywhere;
}

/* Year range — the frozen dual-range keeps year-range.js's mechanics; only
   its palette moves to tokens (hairline track, primary fill + thumbs with a
   surface border, token focus ring, subtle ticks, text value, «كل السنوات»
   as a small pill that's primary when pressed). */
html[data-ui="v2"] .fx-page--research .year-range{
  --track-accent:var(--fx-primary); margin:0;
}
html[data-ui="v2"] .fx-page--research .year-range-head{margin-bottom:var(--fx-space-2)}
html[data-ui="v2"] .fx-page--research .year-range-head .flabel{margin:0}
html[data-ui="v2"] .fx-page--research .year-range-value{
  color:var(--fx-text); font-weight:var(--fx-weight-semibold);
  font-variant-numeric:tabular-nums lining-nums;
}
html[data-ui="v2"] .fx-page--research .year-all{
  min-block-size:var(--fx-control-h-sm); padding:0 var(--fx-space-3);
  border:1px solid var(--fx-border-strong); border-radius:var(--fx-radius-pill);
  background:var(--fx-surface); color:var(--fx-text-muted);
  font:inherit; font-size:var(--fx-text-xs); font-weight:var(--fx-weight-medium);
  cursor:pointer;
  transition:background-color var(--fx-dur-fast) var(--fx-ease-out),
    border-color var(--fx-dur-fast) var(--fx-ease-out),
    color var(--fx-dur-fast) var(--fx-ease-out),
    box-shadow var(--fx-dur-fast) var(--fx-ease-out);
}
html[data-ui="v2"] .fx-page--research .year-all:hover{
  border-color:var(--fx-primary); color:var(--fx-primary);
}
html[data-ui="v2"] .fx-page--research .year-all[aria-pressed="true"]{
  background:var(--fx-primary); border-color:var(--fx-primary); color:var(--fx-on-primary);
}
html[data-ui="v2"] .fx-page--research .year-all:focus-visible{
  outline:none; box-shadow:var(--fx-ring);
}
html[data-ui="v2"] .fx-page--research .year-range-track{background:var(--fx-border)}
html[data-ui="v2"] .fx-page--research .year-range-slider input[type=range]::-webkit-slider-thumb{
  background:var(--fx-primary); border:2px solid var(--fx-surface);
  box-shadow:var(--fx-shadow-sm);
}
html[data-ui="v2"] .fx-page--research .year-range-slider input[type=range]::-moz-range-thumb{
  background:var(--fx-primary); border:2px solid var(--fx-surface);
  box-shadow:var(--fx-shadow-sm);
}
html[data-ui="v2"] .fx-page--research .year-range-slider input[type=range]:focus-visible::-webkit-slider-thumb{
  box-shadow:var(--fx-shadow-sm), var(--fx-ring);
}
html[data-ui="v2"] .fx-page--research .year-range-slider input[type=range]:focus-visible::-moz-range-thumb{
  box-shadow:var(--fx-shadow-sm), var(--fx-ring);
}
html[data-ui="v2"] .fx-page--research .year-range-ticks{color:var(--fx-text-subtle)}

/* ---------------------------------------------------------------------------
   3. «إدارة الفئات» — one quiet disclosure row; inside, each category a
      compact row (name + muted keyword count + end chevron) whose body holds
      the frozen edit form. The keyword chips themselves get the profile
      look: profile.css widens its selectors to .fx-page--research.
--------------------------------------------------------------------------- */

html[data-ui="v2"] .fx-page--research details.fx-disclosure{
  margin:0; padding:0; border:0; border-radius:0; background:none;
}
html[data-ui="v2"] .fx-page--research details.fx-disclosure > summary{
  padding-block:10px; padding-inline:0; min-height:0;
}
html[data-ui="v2"] .fx-page--research details.fx-disclosure > summary .hint{
  margin-inline-start:8px;
  font-size:var(--fx-text-xs); font-weight:var(--fx-weight-regular);
  color:var(--fx-text-subtle);
}
html[data-ui="v2"] .fx-page--research details.fx-disclosure[open] > summary{border-block-end:0}
html[data-ui="v2"] .fx-page--research details.fx-disclosure > .disclosure-body{padding:0}
html[data-ui="v2"] .fx-page--research .fx-cats-manage__body{
  display:grid; gap:var(--fx-space-2);
}
html[data-ui="v2"] .fx-page--research .fx-cats-manage__body .fx-hint{margin:0}
html[data-ui="v2"] .fx-page--research .kwgroup{
  border:0; border-block-end:1px solid var(--fx-border); border-radius:0;
  padding:0 0 var(--fx-space-2); margin:0; background:none;
}
html[data-ui="v2"] .fx-page--research .kwgroup:last-child{
  border-block-end:0; padding-block-end:0;
}
html[data-ui="v2"] .fx-page--research .kwgroup > summary{
  list-style:none; display:flex; align-items:center; gap:8px;
  padding:var(--fx-space-2) 0; font-size:var(--fx-text-sm);
  font-weight:var(--fx-weight-semibold); color:var(--fx-text); cursor:pointer;
}
html[data-ui="v2"] .fx-page--research .kwgroup > summary::-webkit-details-marker{display:none}
html[data-ui="v2"] .fx-page--research .kwgroup > summary:hover{color:var(--fx-primary); background:none}
html[data-ui="v2"] .fx-page--research .kwgroup > summary:focus-visible{outline:none; box-shadow:var(--fx-ring)}
html[data-ui="v2"] .fx-page--research .kwgroup > summary .hint{
  font-size:var(--fx-text-xs); color:var(--fx-text-subtle); font-weight:var(--fx-weight-regular);
}
html[data-ui="v2"] .fx-page--research .kwgroup > summary::after{
  content:""; flex:none; inline-size:12px; block-size:12px; margin-inline-start:auto;
  background:var(--fx-text-subtle);
  -webkit-mask:url('/static/icons/chevron-down.svg?v=ui2-1') center/contain no-repeat;
  mask:url('/static/icons/chevron-down.svg?v=ui2-1') center/contain no-repeat;
  transition:transform var(--fx-dur-base) var(--fx-ease-out);
}
html[data-ui="v2"] .fx-page--research .kwgroup[open] > summary::after{transform:rotate(180deg)}
html[data-ui="v2"] .fx-page--research .kwgroup .field{
  display:grid; gap:var(--fx-space-2); margin:var(--fx-space-2) 0 var(--fx-space-1);
}
html[data-ui="v2"] .fx-page--research .kwgroup .field .flabel{margin:0}
html[data-ui="v2"] .fx-page--research .kwgroup .page-actions{
  display:flex; flex-wrap:wrap; align-items:center; gap:var(--fx-space-2);
  margin:var(--fx-space-1) 0 0;
}
html[data-ui="v2"] .fx-page--research .fx-cat__delete{color:var(--fx-danger)}
html[data-ui="v2"] .fx-page--research .fx-cat__delete:not([disabled]):hover{
  background:var(--fx-danger-bg); color:var(--fx-danger);
}

/* ---------------------------------------------------------------------------
   4. Results head — one row: scope · count · years as an .fx-meta line on
      the start side, export on the end side; then the four view tabs as
      underline tabs over the shared .market-tabs.app-tabs contract.
--------------------------------------------------------------------------- */

html[data-ui="v2"] .fx-page--research .fx-results__head{
  display:flex; flex-wrap:wrap; align-items:baseline; gap:8px 14px;
  margin:0; padding:0 0 var(--fx-space-3);
  border:0; border-block-end:1px solid var(--fx-border);
  border-radius:0; background:none; font-size:inherit; color:inherit;
}
html[data-ui="v2"] .fx-page--research .fx-results__head .fx-meta{
  flex:1 1 auto; min-inline-size:0;
}
html[data-ui="v2"] .fx-page--research .fx-research__export{
  flex:none; align-self:center; margin:0; margin-inline-start:auto;
}

html[data-ui="v2"] .fx-page--research nav.market-tabs{
  display:flex; align-items:baseline; gap:4px 18px; margin:0; padding:0;
  min-inline-size:0; overflow-x:auto; scrollbar-width:none;
  border:0; border-block-end:1px solid var(--fx-border);
  background:none; position:static; z-index:auto;
}
html[data-ui="v2"] .fx-page--research nav.market-tabs::-webkit-scrollbar{display:none}
html[data-ui="v2"] .fx-page--research nav.market-tabs a{
  flex:none; position:relative; padding-block:8px; padding-inline:0;
  border:0; background:none; box-shadow:none;
  color:var(--fx-text-muted);
  font-size:var(--fx-text-sm); font-weight:var(--fx-weight-medium);
  text-decoration:none; white-space:nowrap;
  transition:color var(--fx-dur-fast) var(--fx-ease-out);
}
html[data-ui="v2"] .fx-page--research nav.market-tabs a:hover{
  color:var(--fx-text); background:none;
}
html[data-ui="v2"] .fx-page--research nav.market-tabs a:focus-visible{
  outline:none; box-shadow:var(--fx-ring);
}
html[data-ui="v2"] .fx-page--research nav.market-tabs a::after{
  content:""; position:absolute; inset-inline:0; inset-block-end:-1px;
  block-size:2px; border-radius:2px; background:transparent;
  transition:background-color var(--fx-dur-fast) var(--fx-ease-out);
}
html[data-ui="v2"] .fx-page--research nav.market-tabs a[aria-current="page"]{
  color:var(--fx-text); font-weight:var(--fx-weight-semibold); box-shadow:none;
}
html[data-ui="v2"] .fx-page--research nav.market-tabs a[aria-current="page"]::after{
  background:var(--fx-primary);
}

/* ---------------------------------------------------------------------------
   5. Shared view chrome — h2/sub heads, muted ledes, fx-stat grids, the
      verdict chip line and quiet hints.
--------------------------------------------------------------------------- */

html[data-ui="v2"] .fx-page--research .fx-research__view{
  display:grid; gap:var(--fx-space-4); align-content:start;
}
html[data-ui="v2"] .fx-page--research .fx-research__view > *{min-inline-size:0}
html[data-ui="v2"] .fx-page--research .fx-research__h{
  margin:0; font-size:var(--fx-text-xl); font-weight:var(--fx-weight-bold);
  line-height:var(--fx-leading-tight); color:var(--fx-text);
}
html[data-ui="v2"] .fx-page--research .fx-research__sub-h{
  margin:var(--fx-space-2) 0 0; font-size:var(--fx-text-lg);
  font-weight:var(--fx-weight-semibold); color:var(--fx-text);
  line-height:var(--fx-leading-tight);
}
html[data-ui="v2"] .fx-page--research .fx-research__lede,
html[data-ui="v2"] .fx-page--research .fx-research__note{
  margin:0; font-size:var(--fx-text-sm); color:var(--fx-text-muted);
}
html[data-ui="v2"] .fx-page--research .fx-stats{
  display:grid; gap:var(--fx-space-3); margin:0;
  grid-template-columns:repeat(auto-fit, minmax(min(100%, 200px), 1fr));
}
html[data-ui="v2"] .fx-page--research .fx-stats--four{
  grid-template-columns:repeat(4, minmax(0, 1fr));
}
@media (max-width:768px){
  html[data-ui="v2"] .fx-page--research .fx-stats--four{
    grid-template-columns:repeat(2, minmax(0, 1fr));
  }
}
@media (max-width:480px){
  /* The four-tile pricing grid stays 2×2 (its values are short); the other
     stat rows collapse to one column. */
  html[data-ui="v2"] .fx-page--research .fx-stats:not(.fx-stats--four){
    grid-template-columns:minmax(0, 1fr);
  }
}
/* Compact values (price ranges, company names) shrink with the viewport and
   may wrap, but never clip inside their tile. */
html[data-ui="v2"] .fx-page--research .fx-stat__value--sm{
  min-inline-size:0; overflow-wrap:anywhere;
  font-size:clamp(var(--fx-text-xl), 3.5vw, var(--fx-text-3xl));
}
/* A min – max pair sized like the agency total; each half is nowrap so a
   wrap can only land after the dash, never inside a number. */
html[data-ui="v2"] .fx-page--research .fx-stat__value .fx-range{
  min-inline-size:0;
  font-size:clamp(var(--fx-text-lg), 3vw, var(--fx-text-2xl));
}
html[data-ui="v2"] .fx-page--research .fx-range span{white-space:nowrap}
/* Company-name values read as text, not display numerals: small, semibold,
   clamped to two lines (the link's title carries the full name). */
html[data-ui="v2"] .fx-page--research .fx-stat__value--text{
  display:-webkit-box; -webkit-box-orient:vertical;
  -webkit-line-clamp:2; line-clamp:2; overflow:hidden;
  font-size:var(--fx-text-lg); font-weight:var(--fx-weight-semibold);
  line-height:1.4;
}
/* v1 hides these two disclosures under .market-intelligence; v2 keeps the
   markup (contract) and hides them the same way. */
html[data-ui="v2"] .fx-page--research #overview-price-evidence,
html[data-ui="v2"] .fx-page--research #award-differences{display:none}
html[data-ui="v2"] .fx-page--research .fx-stat__link{
  color:var(--fx-link); text-decoration:none;
}
html[data-ui="v2"] .fx-page--research .fx-stat__link:hover{
  color:var(--fx-link-hover); text-decoration:underline; text-underline-offset:3px;
}
html[data-ui="v2"] .fx-page--research .fx-stat__link:focus-visible{
  outline:none; box-shadow:var(--fx-ring);
}
html[data-ui="v2"] .fx-page--research .fx-research__verdict{
  margin:0; font-size:var(--fx-text-sm); color:var(--fx-text-muted);
}
html[data-ui="v2"] .fx-page--research .help.fx-hint{max-inline-size:none}

/* ---------------------------------------------------------------------------
   6. Pricing chart — the shared SVG restyled through its class hooks only;
      .chartscroll keeps the 480px floor inside the card, never the page.
--------------------------------------------------------------------------- */

html[data-ui="v2"] .fx-page--research .chartcard{margin:0}
html[data-ui="v2"] .fx-page--research .charthead{margin-bottom:var(--fx-space-2)}
html[data-ui="v2"] .fx-page--research .charthead h3{
  font-size:var(--fx-text-base); font-weight:var(--fx-weight-semibold); color:var(--fx-text);
}
html[data-ui="v2"] .fx-page--research .charthead .unit{
  font-size:var(--fx-text-2xs); color:var(--fx-text-subtle);
}
html[data-ui="v2"] .fx-page--research .chartscroll{overflow-x:auto}
html[data-ui="v2"] .fx-page--research svg.chart{inline-size:100%; min-inline-size:480px}
html[data-ui="v2"] .fx-page--research svg.chart .gridline{stroke:var(--fx-border)}
html[data-ui="v2"] .fx-page--research svg.chart .axislabel{fill:var(--fx-text-subtle)}
html[data-ui="v2"] .fx-page--research svg.chart .chart-range{stroke:var(--fx-text-muted)}
html[data-ui="v2"] .fx-page--research svg.chart .chart-range.is-small{stroke-dasharray:4 6}
html[data-ui="v2"] .fx-page--research svg.chart .chart-median{
  fill:var(--fx-primary); stroke:var(--fx-surface); stroke-width:2;
}
html[data-ui="v2"] .fx-page--research svg.chart .chartvalue{fill:var(--fx-text)}
html[data-ui="v2"] .fx-page--research .chart-caption{
  margin:var(--fx-space-2) 0 0; font-size:var(--fx-text-2xs); color:var(--fx-text-subtle);
}

/* ---------------------------------------------------------------------------
   7. Records — the shared .fx-tcards card rows; this page owns only the
      column template and per-cell placement: the tender link on line 1,
      «YEAR · WINNER» muted on line 2, the award value end-aligned in the
      shared 11rem end column. On phones the row becomes a wrapping line:
      title, meta, value flush at the line's end.
--------------------------------------------------------------------------- */

html[data-ui="v2"] .fx-page--research .fx-records .fx-tcards__table tbody tr.fx-card-row{
  grid-template-columns:max-content minmax(0,1fr) 11rem;
  grid-template-areas:
    "title title end"
    "year  winner end";
  column-gap:var(--fx-space-4);
}
html[data-ui="v2"] .fx-page--research .fx-records .fx-tcards__table tbody td.col-year{grid-area:year}
html[data-ui="v2"] .fx-page--research .fx-records .fx-tcards__table tbody td.col-title{grid-area:title}
html[data-ui="v2"] .fx-page--research .fx-records .fx-tcards__table tbody td.col-winner{
  grid-area:winner; min-inline-size:0; overflow-wrap:anywhere;
}
/* The «·» separator trails the year, so a winner that wraps to its own line
   never starts with it. */
html[data-ui="v2"] .fx-page--research .fx-records .fx-tcards__table tbody td.col-year::after{
  content:"·" / ""; margin-inline:6px; color:var(--fx-text-subtle);
}
html[data-ui="v2"] .fx-page--research .fx-records .fx-tcards__table tbody td.col-value{
  grid-area:end; justify-content:flex-end;
  font-variant-numeric:tabular-nums lining-nums; color:var(--fx-text);
}
@media (max-width:768px){
  html[data-ui="v2"] .fx-page--research .fx-records .fx-tcards__table tbody tr.fx-card-row{
    display:flex; flex-wrap:wrap; align-items:baseline;
    column-gap:8px; row-gap:2px;
  }
  html[data-ui="v2"] .fx-page--research .fx-records .fx-tcards__table tbody td.col-title{order:1; flex-basis:100%}
  html[data-ui="v2"] .fx-page--research .fx-records .fx-tcards__table tbody td.col-year{order:2}
  html[data-ui="v2"] .fx-page--research .fx-records .fx-tcards__table tbody td.col-winner{order:3; margin-inline-end:auto}
  html[data-ui="v2"] .fx-page--research .fx-records .fx-tcards__table tbody td.col-value{order:4}
}

/* Optional AI suggestions stay alongside the category being edited. */
html[data-ui="v2"] .fx-page--research .fx-category-name{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:var(--fx-space-2);align-items:center}
html[data-ui="v2"] .fx-page--research .fx-category-name button{display:inline-flex;gap:6px;align-items:center;white-space:normal}
html[data-ui="v2"] .fx-page--research .fx-keyword-preview{padding:var(--fx-space-3);border:1px solid var(--fx-border);border-radius:var(--fx-radius-md);margin-block-end:var(--fx-space-3)}
html[data-ui="v2"] .fx-page--research .fx-keyword-preview[hidden]{display:none}
html[data-ui="v2"] .fx-page--research .fx-keyword-options{display:flex;flex-wrap:wrap;gap:var(--fx-space-2)}
html[data-ui="v2"] .fx-page--research .fx-keyword-options label{display:flex;gap:5px;align-items:center;padding:5px 8px;border:1px solid var(--fx-border);border-radius:var(--fx-radius-md)}
html[data-ui="v2"] .fx-page--research .fx-keyword-error{color:var(--fx-danger)}
@media(max-width:560px){html[data-ui="v2"] .fx-page--research .fx-category-name{grid-template-columns:1fr}}
