/* Fursa UI v2 — «ملف الشركة» (sales_profile) + the shared keyword-match
   preview panel (_profile_preview.html, also rendered inside /setup).
   Loaded last in v2/base.html; every rule is scoped to html[data-ui="v2"].
   Keyword chips are keyword-tags.js's frozen markup: styles hang off
   .keyword-tags/.keyword-tag/[data-remove-keyword] inside
   :is(.fx-page--profile, .fx-page--research) only, so the setup wizard
   keeps its own look while /research's category editors share it.
   The preview panel itself is styled under .fx-profile-preview (global to
   v2) so it looks the same inside /setup; only its page placement
   (grid column, sticky) is scoped to .fx-page--profile. */

/* -- page entrance ------------------------------------------------------ */

/* The shell staggers the first five children up to 160 ms; this page has six
   (crumbs, head, refresh, review, company, form), and 160 + 320 ms would push
   the last card past the 90–420 ms page window. Only the first three rows
   stagger; everything else rises with them. */
html[data-ui="v2"] .fx-page--profile > :nth-child(n+4){animation-delay:90ms}

/* -- page head ---------------------------------------------------------- */

/* Two columns on ≥768 px: eyebrow + title at the start, the completeness
   block at the end aligned with the title's baseline; the notes strip spans
   the full width under them. Below that it all stacks in DOM order. */
html[data-ui="v2"] .fx-page--profile .fx-profile-head{
  display:grid;gap:var(--fx-space-3) var(--fx-space-6);
  margin-block-end:var(--fx-space-5);
}
html[data-ui="v2"] .fx-page--profile .fx-profile-head__title{
  display:grid;gap:var(--fx-space-2);justify-items:start;
}
html[data-ui="v2"] .fx-page--profile .fx-profile-head__title .fx-title{margin:0}
html[data-ui="v2"] .fx-page--profile .fx-profile-progress{
  display:grid;gap:var(--fx-space-2);min-inline-size:0;
}
html[data-ui="v2"] .fx-page--profile .fx-profile-progress__label{
  margin:0;font-size:var(--fx-text-sm);line-height:var(--fx-leading-ui);
  color:var(--fx-text-muted);
}
@media (min-width:768px){
  html[data-ui="v2"] .fx-page--profile .fx-profile-head{
    grid-template-columns:minmax(0,1fr) auto;align-items:end;
  }
  html[data-ui="v2"] .fx-page--profile .fx-profile-progress{
    inline-size:clamp(320px,32vw,420px);justify-self:end;align-self:end;
  }
}

/* Track one step stronger than the page background so the missing share
   reads in both themes; the quiet fill sits on top of it. */
html[data-ui="v2"] .fx-page--profile .fx-profile-meter{
  inline-size:100%;block-size:4px;
  border-radius:var(--fx-radius-pill);background:var(--fx-border);
  overflow:hidden;
}
html[data-ui="v2"] .fx-page--profile .fx-profile-meter__bar{
  display:block;block-size:100%;border-radius:var(--fx-radius-pill);
  background:var(--fx-gradient-brand);inline-size:calc(var(--fx-pct, 0) * 1%);
  transform-origin:left;
  animation:fx-meter var(--fx-dur-page) var(--fx-ease-out) 200ms both;
}
html[data-ui="v2"][dir="rtl"] .fx-page--profile .fx-profile-meter__bar{transform-origin:right}

/* One neutral strip: the missing-fields hint (only when there is one), then
   the editable-note line in smaller muted text. */
html[data-ui="v2"] .fx-page--profile .fx-profile-notes{
  grid-column:1/-1;
  padding:var(--fx-space-2) var(--fx-space-3);
  border:1px solid var(--fx-border);border-radius:var(--fx-radius-md);
  background:var(--fx-surface-sunken);
  display:grid;gap:2px;
}
html[data-ui="v2"] .fx-page--profile .fx-profile-notes__missing{
  display:flex;align-items:baseline;gap:var(--fx-space-2);
  margin:0;font-size:var(--fx-text-sm);line-height:var(--fx-leading-ui);
  color:var(--fx-text);
}
html[data-ui="v2"] .fx-page--profile .fx-profile-notes__icon{
  flex:none;position:relative;inset-block-start:2px;color:var(--fx-primary);
}
html[data-ui="v2"] .fx-page--profile .fx-profile-notes__note{
  margin:0;font-size:var(--fx-text-xs);line-height:var(--fx-leading-ui);
  color:var(--fx-text-muted);
}
html[data-ui="v2"] .fx-page--profile .fx-profile-notes__label{
  font-weight:var(--fx-weight-semibold);
}

/* -- cards: shared title/lede ------------------------------------------- */

html[data-ui="v2"] .fx-page--profile .fx-group__title{
  margin:0 0 var(--fx-space-4);
  font-size:var(--fx-text-lg);font-weight:var(--fx-weight-semibold);
  line-height:var(--fx-leading-tight);
}
html[data-ui="v2"] .fx-page--profile .fx-group__lede{
  margin:-6px 0 var(--fx-space-4);max-inline-size:75ch;
  font-size:var(--fx-text-sm);line-height:var(--fx-leading-body);color:var(--fx-text-muted);
}

/* -- the source-refresh card (home company only) ------------------------- */

html[data-ui="v2"] .fx-page--profile .fx-refresh{
  display:flex;align-items:center;justify-content:space-between;
  gap:var(--fx-space-4);
}
html[data-ui="v2"] .fx-page--profile .fx-refresh__body{flex:1;min-inline-size:0}
html[data-ui="v2"] .fx-page--profile .fx-refresh__body .fx-group__title{margin:6px 0 2px}
html[data-ui="v2"] .fx-page--profile .fx-refresh__body .fx-group__lede{margin:0 0 var(--fx-space-2)}
html[data-ui="v2"] .fx-page--profile .fx-refresh__form{flex:none}
@media (max-width:640px){
  html[data-ui="v2"] .fx-page--profile .fx-refresh{flex-direction:column;align-items:stretch}
}

/* -- pending review ----------------------------------------------------- */

html[data-ui="v2"] .fx-page--profile .fx-review__list{
  margin:0;padding:0;list-style:none;
}
html[data-ui="v2"] .fx-page--profile .fx-review-row{padding-block:var(--fx-space-4)}
html[data-ui="v2"] .fx-page--profile .fx-review-row + .fx-review-row{border-block-start:1px solid var(--fx-border)}
html[data-ui="v2"] .fx-page--profile .fx-review-row__head{
  display:flex;align-items:center;gap:var(--fx-space-3);flex-wrap:wrap;
}
html[data-ui="v2"] .fx-page--profile .fx-review-row__field{
  margin:0;font-size:var(--fx-text-base);font-weight:var(--fx-weight-semibold);
}
html[data-ui="v2"] .fx-page--profile .fx-review-row__reason{
  margin:var(--fx-space-1) 0 0;font-size:var(--fx-text-sm);color:var(--fx-text-muted);
}
html[data-ui="v2"] .fx-page--profile .fx-check{
  display:flex;align-items:center;gap:var(--fx-space-2);
  margin-block-start:var(--fx-space-3);
  font-size:var(--fx-text-sm);font-weight:var(--fx-weight-semibold);cursor:pointer;
}
html[data-ui="v2"] .fx-page--profile .fx-check input{
  inline-size:18px;block-size:18px;accent-color:var(--fx-primary);flex:none;
}
html[data-ui="v2"] .fx-page--profile .fx-review-row__value{
  margin-block-start:var(--fx-space-2);background:var(--fx-surface-sunken);
}
html[data-ui="v2"] .fx-page--profile .fx-review-row .fx-hint{margin-block-start:var(--fx-space-2)}
html[data-ui="v2"] .fx-page--profile .fx-review__actions{
  margin-block-start:var(--fx-space-4);display:flex;justify-content:flex-start;
}

/* -- group cards and the field grid -------------------------------------- */

/* Top-level cards space themselves; inside the form the grid gap does it. */
html[data-ui="v2"] .fx-page--profile > .fx-card{margin-block-end:var(--fx-space-5)}
html[data-ui="v2"] .fx-page--profile .fx-group__grid{
  display:grid;gap:var(--fx-space-4);align-items:start;
}
/* A stretched .fx-field would spread its auto rows (label, control, hint)
   over the extra height and sink the control below its row-mate's. */
html[data-ui="v2"] .fx-page--profile .fx-field{align-content:start}
html[data-ui="v2"] .fx-page--profile .fx-group__grid .fx-field{margin-block-start:0}
html[data-ui="v2"] .fx-page--profile .fx-field--wide{grid-column:1/-1}
html[data-ui="v2"] .fx-page--profile .fx-group__actions{grid-column:1/-1;display:flex;justify-content:flex-start}
html[data-ui="v2"] .fx-page--profile .fx-field .fx-hint{margin:0}
@media (min-width:1024px){
  html[data-ui="v2"] .fx-page--profile .fx-group__grid{grid-template-columns:repeat(2,minmax(0,1fr))}
}

/* Textareas size to their content; rows keeps the minimum, so empty fields
   keep their v1 height. field-sizing is progressive — where unsupported the
   rows attribute alone rules. */
html[data-ui="v2"] .fx-page--profile textarea.fx-input{
  field-sizing:content;resize:vertical;
  min-block-size:calc(3 * 1.5em + 20px);max-block-size:18em;
}
html[data-ui="v2"] .fx-page--profile textarea.fx-input[rows="4"]{min-block-size:calc(4 * 1.5em + 20px)}
html[data-ui="v2"] .fx-page--profile textarea.fx-input[rows="5"]{min-block-size:calc(5 * 1.5em + 20px)}
html[data-ui="v2"] .fx-page--profile textarea.fx-input[rows="6"]{min-block-size:calc(6 * 1.5em + 20px)}
html[data-ui="v2"] .fx-page--profile textarea.fx-input[rows="7"]{min-block-size:calc(7 * 1.5em + 20px)}

/* -- keyword tag editors (scoped: /setup shares the same markup and keeps
      the plain v1 look under the v2 shell; /research's category editor takes
      this styling too) ------------------------------------------------------ */

/* The whole control reads as one field: chips wrap inside it and the input +
   add button share the chips' last row while there is room. */
html[data-ui="v2"] :is(.fx-page--profile, .fx-page--research, .fx-page--setup) .keyword-tags{
  display:flex;flex-wrap:wrap;align-items:center;gap:var(--fx-space-2);
  padding:6px 8px;min-block-size:var(--fx-control-h);
  border:1px solid var(--fx-border-strong);border-radius:var(--fx-radius-md);
  background:var(--fx-surface);box-shadow:var(--fx-shadow-xs);
  transition:border-color var(--fx-dur-fast) var(--fx-ease-out),
    box-shadow var(--fx-dur-fast) var(--fx-ease-out);
}
html[data-ui="v2"] :is(.fx-page--profile, .fx-page--research, .fx-page--setup) .keyword-tags:focus-within{
  border-color:var(--fx-primary);box-shadow:var(--fx-ring);
}
html[data-ui="v2"] :is(.fx-page--profile, .fx-page--research, .fx-page--setup) .keyword-tag-list{display:contents}
html[data-ui="v2"] :is(.fx-page--profile, .fx-page--research, .fx-page--setup) .keyword-tag{
  display:inline-flex;align-items:center;gap:2px;max-inline-size:100%;
  min-block-size:28px;padding-block:1px;padding-inline-start:10px;padding-inline-end:4px;
  border:1px solid var(--fx-info-border);border-radius:var(--fx-radius-pill);
  background:var(--fx-primary-soft);color:var(--fx-primary);
  font-size:var(--fx-text-xs);font-weight:var(--fx-weight-medium);line-height:1.5;
}
html[data-ui="v2"] :is(.fx-page--profile, .fx-page--research, .fx-page--setup) .keyword-tag button[data-remove-keyword]{
  flex:none;display:inline-grid;place-items:center;
  inline-size:24px;block-size:24px;margin:0;padding:0;border:0;
  border-radius:50%;background:transparent;
  color:inherit;font:inherit;font-size:15px;line-height:1;cursor:pointer;
  opacity:.65;
  transition:color var(--fx-dur-fast) var(--fx-ease-out),
    background-color var(--fx-dur-fast) var(--fx-ease-out),
    opacity var(--fx-dur-fast) var(--fx-ease-out);
}
html[data-ui="v2"] :is(.fx-page--profile, .fx-page--research, .fx-page--setup) .keyword-tag button[data-remove-keyword]:hover{
  color:var(--fx-danger);background:var(--fx-danger-bg);opacity:1;
}
/* «فرص لا نريدها»: danger-soft chips read as exclusions. */
html[data-ui="v2"] :is(.fx-page--profile, .fx-page--research, .fx-page--setup) .keyword-tags[data-keyword-field="exclusions"] .keyword-tag{
  background:var(--fx-danger-bg);color:var(--fx-danger);border-color:var(--fx-danger-border);
}
html[data-ui="v2"] :is(.fx-page--profile, .fx-page--research, .fx-page--setup) .keyword-tag-add{
  flex:1 1 220px;display:flex;align-items:center;gap:var(--fx-space-2);
  min-inline-size:180px;
}
html[data-ui="v2"] :is(.fx-page--profile, .fx-page--research, .fx-page--setup) .keyword-tag-add input[data-keyword-input]{
  flex:1;min-inline-size:0;min-block-size:32px;max-inline-size:none;
  padding:0 4px;border:0;background:transparent;box-shadow:none;
  font:inherit;font-size:var(--fx-text-sm);color:var(--fx-text);
}
html[data-ui="v2"] :is(.fx-page--profile, .fx-page--research, .fx-page--setup) .keyword-tag-add input[data-keyword-input]:focus,
html[data-ui="v2"] :is(.fx-page--profile, .fx-page--research, .fx-page--setup) .keyword-tag-add input[data-keyword-input]:focus-visible{
  outline:none;border-color:transparent;box-shadow:none;background:transparent;
}

/* -- the live match preview --------------------------------------------- */

/* The panel (shared with /setup). */
html[data-ui="v2"] .fx-profile-preview{
  position:relative;overflow:hidden;
  padding:var(--fx-space-4) var(--fx-space-5);
  border:1px solid var(--fx-info-border);border-radius:var(--fx-radius-md);
  background:var(--fx-info-bg);
  transition:opacity var(--fx-dur-fast) var(--fx-ease-out);
}
html[data-ui="v2"] .fx-profile-preview__count{
  margin:0;font-size:var(--fx-text-lg);font-weight:var(--fx-weight-semibold);
  line-height:var(--fx-leading-tight);color:var(--fx-text);
}
html[data-ui="v2"] .fx-profile-preview__list{
  margin:var(--fx-space-3) 0 0;padding:0;list-style:none;
  display:grid;gap:var(--fx-space-2);
}
html[data-ui="v2"] .fx-profile-preview__item{
  display:flex;flex-wrap:wrap;align-items:baseline;gap:4px var(--fx-space-2);
  font-size:var(--fx-text-sm);line-height:var(--fx-leading-ui);
}
html[data-ui="v2"] .fx-profile-preview__title{min-inline-size:0;color:var(--fx-text)}
html[data-ui="v2"] .fx-profile-preview__terms{display:inline-flex;flex-wrap:wrap;gap:4px}
html[data-ui="v2"] .fx-profile-preview__term{
  padding:0 8px;border:1px solid var(--fx-border);border-radius:var(--fx-radius-pill);
  background:var(--fx-surface);color:var(--fx-text-muted);
  font-size:var(--fx-text-2xs);font-weight:var(--fx-weight-medium);line-height:1.6;
  white-space:nowrap;
}
html[data-ui="v2"] .fx-profile-preview__none{
  margin:var(--fx-space-2) 0 0;font-size:var(--fx-text-sm);color:var(--fx-text-muted);
}

/* Before htmx's load request answers, the empty target draws a quiet
   three-line placeholder (no markup, so it disappears when the swap lands). */
html[data-ui="v2"] #profile-preview:empty{
  min-block-size:88px;
  border:1px solid var(--fx-border);border-radius:var(--fx-radius-md);
  background:
    linear-gradient(var(--fx-surface-sunken), var(--fx-surface-sunken)) 16px 16px / calc(100% - 32px) 12px no-repeat,
    linear-gradient(var(--fx-surface-sunken), var(--fx-surface-sunken)) 16px 38px / calc(88% - 32px) 12px no-repeat,
    linear-gradient(var(--fx-surface-sunken), var(--fx-surface-sunken)) 16px 60px / calc(64% - 32px) 12px no-repeat,
    var(--fx-surface);
}
html[data-ui="v2"][dir="rtl"] #profile-preview:empty{
  background:
    linear-gradient(var(--fx-surface-sunken), var(--fx-surface-sunken)) right 16px top 16px / calc(100% - 32px) 12px no-repeat,
    linear-gradient(var(--fx-surface-sunken), var(--fx-surface-sunken)) right 16px top 38px / calc(88% - 32px) 12px no-repeat,
    linear-gradient(var(--fx-surface-sunken), var(--fx-surface-sunken)) right 16px top 60px / calc(64% - 32px) 12px no-repeat,
    var(--fx-surface);
}

/* While a request is in flight the panel dims and a thin progress band runs
   along its top edge — an overlay, so nothing moves. */
html[data-ui="v2"] #profile-preview.htmx-request .fx-profile-preview{opacity:.55}
html[data-ui="v2"] .fx-profile-preview::before{
  content:"";position:absolute;inset-inline:0;inset-block-start:0;block-size:2px;
  background:var(--fx-gradient-brand);background-size:50% 100%;background-repeat:no-repeat;
  opacity:0;pointer-events:none;
}
html[data-ui="v2"] #profile-preview.htmx-request .fx-profile-preview::before{
  opacity:1;animation:fx-preview-load 1.1s linear infinite;
}
html[data-ui="v2"][dir="rtl"] #profile-preview.htmx-request .fx-profile-preview::before{
  animation-direction:reverse;
}
@keyframes fx-preview-load{
  from{background-position:150% 0}
  to{background-position:-50% 0}
}

/* In the «كلمات المطابقة» card on wide screens the preview is its own
   column at the reading end and stays visible while the tags column scrolls. */
html[data-ui="v2"] .fx-page--profile #profile-preview{min-inline-size:0}
@media (min-width:1024px){
  html[data-ui="v2"] .fx-page--profile .fx-group__grid--matching #profile-preview{
    grid-column:2;grid-row:1/3;align-self:start;
    position:sticky;inset-block-start:calc(var(--fx-header-h) + var(--fx-space-4));
  }
}

/* -- the profile form and its sticky save bar ---------------------------- */

html[data-ui="v2"] .fx-page--profile .fx-profile-form{
  display:grid;gap:var(--fx-space-5);
}
html[data-ui="v2"] .fx-page--profile .fx-profile-sources{
  display:flex;flex-wrap:wrap;align-items:center;gap:4px var(--fx-space-2);
  font-size:var(--fx-text-xs);color:var(--fx-text-muted);
}
html[data-ui="v2"] .fx-page--profile .fx-profile-sources__label{font-weight:var(--fx-weight-semibold)}

/* The bar sticks to the viewport bottom while the form is on screen; its
   start edge is pushed past the «راصد» launcher lane (24 + 48 + a gap on
   desktop, 12 + 44 on phones — --fx-rased-lane minus the page gutter and
   minus the space a wider-than-page viewport adds beside the page). */
html[data-ui="v2"] .fx-page--profile .fx-savebar{
  position:sticky;inset-block-end:0;z-index:var(--fx-z-sticky);
  display:flex;align-items:center;justify-content:flex-end;gap:var(--fx-space-3);
  margin-inline-start:max(0px, calc(80px - var(--fx-gutter) - max(0px, (100vw - var(--fx-page-max)) / 2)));
  padding:var(--fx-space-3) var(--fx-space-4);
  background:var(--fx-surface-raised);
  border-block-start:1px solid var(--fx-border);
  border-radius:var(--fx-radius-lg) var(--fx-radius-lg) 0 0;
  box-shadow:0 -8px 24px color-mix(in srgb, var(--fx-gray-900) 10%, transparent);
}
@media (max-width:768px){
  /* Floating above the tab bar: --fx-tabbar-h is the bar's nominal height,
     the gap keeps the shadowed card clear of its top edge (the launcher
     floats the same distance up). */
  html[data-ui="v2"] .fx-page--profile .fx-savebar{
    inset-block-end:calc(var(--fx-tabbar-h) + env(safe-area-inset-bottom) + 12px);
    margin-inline-start:max(0px, calc(64px - var(--fx-gutter) - max(0px, (100vw - var(--fx-page-max)) / 2)));
    border:1px solid var(--fx-border);border-radius:var(--fx-radius-lg);
    box-shadow:var(--fx-shadow-lg);
  }
}
