/* Fursa UI v2 — /agencies/{id}/tenders (slice 3.2). One calm column: a quiet
   breadcrumb over the agency's name, a single awards card (two fx-stat
   tiles over a compact per-year fx-table, the lede tucked behind an info
   popover), then the tender 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), a
   centred pager, and a ghost refresh link at the bottom for admins. Every
   selector is scoped to html[data-ui="v2"] under .fx-page--agency; colours,
   spacing and motion come from tokens only. */

/* ---------------------------------------------------------------------------
   1. Frame — stacked sections; the shared fx-page column carries width.
--------------------------------------------------------------------------- */

html[data-ui="v2"] .fx-page--agency{
  display:grid; gap:var(--fx-space-6);
  max-inline-size:880px; margin-inline:auto; inline-size:100%;
}
html[data-ui="v2"] .fx-page--agency .fx-crumbs{margin-block-end:calc(-1 * var(--fx-space-2))}
html[data-ui="v2"] .fx-page--agency .fx-crumbs .chev{
  display:inline-block; transform:scaleX(var(--fx-dir));
  color:var(--fx-text-subtle);
}
html[data-ui="v2"] .fx-page--agency .fx-agency__head{display:grid; gap:4px}
html[data-ui="v2"] .fx-page--agency .fx-agency__head .fx-title{margin:0}
html[data-ui="v2"] .fx-page--agency .fx-agency__sub{
  margin:0; font-size:var(--fx-text-sm); color:var(--fx-text-muted);
}

/* ---------------------------------------------------------------------------
   2. Awards — one fx-card. The h2's trailing info cue opens the lede in a
      native popover (same pattern as the inbox match-why panel); below, the
      two fx-stat tiles sit in one row above the compact per-year fx-table
      at every width (they stack under 480px).
--------------------------------------------------------------------------- */

html[data-ui="v2"] .fx-page--agency .fx-agency__awards{
  display:grid; gap:var(--fx-space-4);
}
html[data-ui="v2"] .fx-page--agency .fx-agency__awards-head{
  display:flex; align-items:baseline; gap:var(--fx-space-2);
}
html[data-ui="v2"] .fx-page--agency .fx-agency__info{
  padding:2px; color:var(--fx-text-subtle); line-height:0;
}
html[data-ui="v2"] .fx-page--agency .fx-agency__info:hover{color:var(--fx-primary)}
html[data-ui="v2"] .fx-page--agency .fx-agency__info svg{display:block}
html[data-ui="v2"] .fx-page--agency .fx-agency__lede-pop.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--agency .fx-agency__lede-pop.fx-popover:popover-open{
  animation:fx-pop-in var(--fx-dur-fast) var(--fx-ease-out) both;
}
html[data-ui="v2"] .fx-page--agency .fx-agency__lede-pop p{margin:0}
/* Anchored under its cue where the browser supports anchor positioning. */
@supports (top:anchor(bottom)){
  html[data-ui="v2"] .fx-page--agency .fx-agency__lede-pop.fx-popover{
    margin:0; inset:auto;
    top:calc(anchor(bottom) + 8px);
    inset-inline-start:anchor(start);
    position-try-fallbacks:flip-block;
  }
}
html[data-ui="v2"] .fx-page--agency .fx-award-panel{
  display:grid; gap:var(--fx-space-4); align-items:start;
}
html[data-ui="v2"] .fx-page--agency .fx-award-panel__stats{
  display:grid; gap:var(--fx-space-3);
  grid-template-columns:repeat(2, minmax(0, 1fr));
}
@media (max-width:480px){
  html[data-ui="v2"] .fx-page--agency .fx-award-panel__stats{
    grid-template-columns:minmax(0, 1fr);
  }
}
/* The total can be a long number («1,523,355.34»): it shrinks with the
   viewport and may wrap, but never clips inside its tile. */
html[data-ui="v2"] .fx-page--agency .fx-stat__value{
  min-inline-size:0; overflow-wrap:anywhere;
  font-size:clamp(var(--fx-text-xl), 4vw, var(--fx-text-3xl));
}
html[data-ui="v2"] .fx-page--agency .fx-stat__value bdi{white-space:nowrap}
html[data-ui="v2"] .fx-page--agency .fx-stat__unit{
  font-size:var(--fx-text-sm); font-weight:var(--fx-weight-medium);
  color:var(--fx-text-muted);
}
html[data-ui="v2"] .fx-page--agency .fx-award-years{margin:0}
/* app.css gives every table.tender-results min-width:1080px + fixed layout for
   wide lists; this 3-column year table fills its card column instead. */
html[data-ui="v2"] .fx-page--agency .fx-award-years table.tender-results{
  min-width:0; min-inline-size:0; inline-size:100%; table-layout:auto;
}
html[data-ui="v2"] .fx-page--agency .fx-award-years table.tender-results thead th,
html[data-ui="v2"] .fx-page--agency .fx-award-years table.tender-results td.num{
  text-align:end;
}
/* ≤1279px app.css treats label-less tables as wide reference data — 8rem cell
   floors, a 12rem sticky first column and nowrap .num cells — which pushes
   this 3-short-column year table past its card at phone width. Its cells
   shrink and wrap instead: a long total drops «ريال» under the number rather
   than scrolling the wrap sideways. */
html[data-ui="v2"] .fx-page--agency .tablewrap.fx-award-years table.tender-results :is(th,td){
  min-inline-size:0; min-width:0; padding-inline:10px; white-space:normal;
}
html[data-ui="v2"] .fx-page--agency .tablewrap.fx-award-years table.tender-results :is(th,td):first-child{
  position:static; inset-inline-start:auto; z-index:auto;
  box-shadow:none; background:transparent;
}
/* The un-stuck first th takes back the same surface-2 as its sibling ths. */
html[data-ui="v2"] .fx-page--agency .tablewrap.fx-award-years table.tender-results thead th:first-child{
  background:var(--surface-2);
}
/* app.css sticks every v2 thead th under the floating header at ≥1280px;
   this wrap keeps §20.6's overflow-x:auto scroller, so that top offset
   would land the header on the first body row — the year table's thead
   scrolls with its wrap instead. */
html[data-ui="v2"] .fx-page--agency .fx-award-years thead th{
  position:static; top:auto; z-index:auto;
}
html[data-ui="v2"] .fx-page--agency .fx-agency__note{
  margin:0; font-size:var(--fx-text-sm); color:var(--fx-text-muted);
}

/* ---------------------------------------------------------------------------
   3. Tender list — shared .fx-tcards rows; this page's column template puts
      the title on line 1 and one meta phrase on line 2
      («ref · نُشرت DATE · STATUS» flowing from the start edge), with the
      deadline cell (date + countdown chip) in the 11rem end column spanning
      both lines. The row-number cell stays in the DOM for the sorter but is
      clipped out.
--------------------------------------------------------------------------- */

html[data-ui="v2"] .fx-page--agency .fx-agency__list{display:grid; gap:var(--fx-space-3)}
html[data-ui="v2"] .fx-page--agency .fx-agency__sec-head{
  display:flex; align-items:baseline; justify-content:space-between;
  gap:var(--fx-space-4); flex-wrap:wrap;
}
html[data-ui="v2"] .fx-page--agency .fx-agency__list-title{
  display:flex; align-items:baseline; gap:var(--fx-space-3); min-inline-size:0;
}
html[data-ui="v2"] .fx-page--agency .fx-agency__count{
  margin:0; font-size:var(--fx-text-sm); color:var(--fx-text-muted); white-space:nowrap;
}
html[data-ui="v2"] .fx-page--agency .fx-agency__export{margin:0}

/* The agency card: title / «ref · نُشرت DATE · STATUS» / 11rem deadline. */
html[data-ui="v2"] .fx-page--agency .tablewrap.fx-tcards .fx-tcards__table tbody tr.fx-card-row{
  grid-template-columns:max-content max-content fit-content(40%) minmax(0,1fr) 11rem;
  grid-template-areas:
    "title title title  title  end"
    "ref   pub   status .      end";
  column-gap:var(--fx-space-4);
}
/* The row number is only there for ordering; clipped like the sortbar th. */
html[data-ui="v2"] .fx-page--agency .tablewrap.fx-tcards .fx-tcards__table tbody td.n{
  position:absolute; inset-inline-start:auto; top:auto; z-index:auto;
  inline-size:1px; block-size:1px; margin:-1px; padding:0;
  overflow:hidden; clip:rect(0 0 0 0); clip-path:inset(50%); white-space:nowrap;
}
html[data-ui="v2"] .fx-page--agency .tablewrap.fx-tcards .fx-tcards__table tbody td.col-ref{
  grid-area:ref;
}
html[data-ui="v2"] .fx-page--agency .tablewrap.fx-tcards .fx-tcards__table tbody td.col-title{
  grid-area:title; min-inline-size:0;
}
html[data-ui="v2"] .fx-page--agency .tablewrap.fx-tcards .fx-tcards__table tbody td.col-status{
  grid-area:status; min-inline-size:0; color:var(--fx-text-subtle);
}
/* Most stored tenders have no Etimad status text: the cell stays in the
   DOM for the row's cell contract but drops out of the meta line. */
html[data-ui="v2"] .fx-page--agency .tablewrap.fx-tcards .fx-tcards__table tbody td.col-status:empty{
  display:none;
}
/* The announced date is the «pub» meta cell: «نُشرت» key + date only. */
html[data-ui="v2"] .fx-page--agency .tablewrap.fx-tcards .fx-tcards__table tbody td.col-date:nth-of-type(5){
  grid-area:pub;
}
html[data-ui="v2"] .fx-page--agency .tablewrap.fx-tcards .fx-tcards__table tbody td.col-date:nth-of-type(5) .dt-time{
  display:none;
}
/* The deadline cell is the end column (mirrors the shared .fx-tcards__end
   look): hairline at its start edge, content centred across both lines. */
html[data-ui="v2"] .fx-page--agency .tablewrap.fx-tcards .fx-tcards__table tbody td.col-date:nth-of-type(6){
  grid-area:end; align-self:stretch; justify-self:stretch;
  display:flex; align-items:center; flex-wrap:wrap; gap:4px 8px;
  padding-inline-start:var(--fx-space-4); border-inline-start:1px solid var(--fx-border);
}
/* Quiet «·» separators ride on the preceding meta cell so a wrapped line
   never opens with a separator. */
html[data-ui="v2"] .fx-page--agency .tablewrap.fx-tcards .fx-tcards__table tbody td.col-ref::after,
html[data-ui="v2"] .fx-page--agency .tablewrap.fx-tcards .fx-tcards__table tbody td.col-date:nth-of-type(5)::after{
  content:"·" / ""; margin-inline-start:6px; color:var(--fx-text-subtle);
}
/* With no status to separate it from, the published cell's «·» goes too —
   the meta line never ends on a lone separator. (col-status sits right
   before the published cell in the DOM.) */
html[data-ui="v2"] .fx-page--agency .tablewrap.fx-tcards .fx-tcards__table tbody td.col-status:empty + td.col-date::after{
  content:none;
}

/* ≤768px — title, then the meta phrase with the deadline at its end; a
   pushed deadline wraps to its own line start-aligned. No cell's ::after
   ever opens a line. */
@media (max-width:768px){
  html[data-ui="v2"] .fx-page--agency .tablewrap.fx-tcards .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--agency .tablewrap.fx-tcards .fx-tcards__table tbody td.col-title{order:1; flex-basis:100%}
  html[data-ui="v2"] .fx-page--agency .tablewrap.fx-tcards .fx-tcards__table tbody td.col-ref{order:2}
  html[data-ui="v2"] .fx-page--agency .tablewrap.fx-tcards .fx-tcards__table tbody td.col-date:nth-of-type(5){order:3}
  html[data-ui="v2"] .fx-page--agency .tablewrap.fx-tcards .fx-tcards__table tbody td.col-status{order:4; margin-inline-end:auto}
  /* An empty status cell is display:none, so the published cell takes over
     the end-push and the deadline still lands flush at the line's end. */
  html[data-ui="v2"] .fx-page--agency .tablewrap.fx-tcards .fx-tcards__table tbody td.col-status:empty + td.col-date{margin-inline-end:auto}
  html[data-ui="v2"] .fx-page--agency .tablewrap.fx-tcards .fx-tcards__table tbody td.col-date:nth-of-type(6){
    order:5;
    padding-inline-start:0; border-inline-start:0;
  }
}

/* ---------------------------------------------------------------------------
   4. Footer — the admin refresh is one quiet ghost link; its help text is
      the link's title, not a visible paragraph.
--------------------------------------------------------------------------- */

html[data-ui="v2"] .fx-page--agency .fx-agency__refresh{
  margin:var(--fx-space-4) 0 0; text-align:center;
}
html[data-ui="v2"] .fx-page--agency .fx-agency__refresh .btn.ghost{
  color:var(--fx-text-subtle); font-weight:var(--fx-weight-medium);
}
html[data-ui="v2"] .fx-page--agency .fx-agency__refresh .btn.ghost:hover{
  color:var(--fx-text);
}
