/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 * Copyright © 2026 Marcel Rymenhout and IniqDash contributors */
/* ==========================================================================
   Person / Presence Widget V1 — widget-specific CSS only (theme from assets/css/tokens.css).

   Identity: an avatar (photo or initials) inside a presence ring with a small badge — home (house,
   success colour), away (arrow, muted), zone (pin, accent). The presence is always written too.

   Arrangements (container "pr" = the widget's own box):
     short     < 120px tall   avatar | name + presence (+ last seen) on one line
     tall      ≥ 120px tall, narrow   avatar on top, name, presence, last seen
     standard  ≥ 260px wide          avatar | name, presence, last seen · secondary
   ========================================================================== */

.pr {
  --pr-tone: var(--text-muted);
  --pr-av: 44px;
  position: relative;
  container: pr / size;
  min-width: 0;
  min-height: 92px;
  overflow: hidden;
  border-radius: var(--radius-device);
  color: var(--text-primary);
  font-family: var(--font);
  background: var(--device-surface);
  box-shadow: var(--device-shadow);
}
.pr[data-presence="home"] { --pr-tone: var(--success); }
.pr[data-presence="zone"] { --pr-tone: var(--accent); }
.pr[data-presence="away"] { --pr-tone: var(--text-secondary); }

.pr__in {
  height: 100%;
  padding: 12px;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas: "av" "." "id";
}

/* ---- avatar in its presence ring ---- */
.pr__av { grid-area: av; position: relative; width: var(--pr-av); height: var(--pr-av); flex: none; }
.pr__ring { position: absolute; inset: 0; border-radius: 50%; box-shadow: inset 0 0 0 2px var(--pr-tone); opacity: .9; }
.pr[data-presence="away"] .pr__ring { box-shadow: inset 0 0 0 2px var(--border-primary); }
.pr__face {
  position: absolute;
  inset: 4px;
  border-radius: 50%;
  overflow: hidden;
  display: grid;
  place-items: center;
  background: var(--surface-tertiary);
  box-shadow: var(--shadow-icon);
}
.pr__face img { display: none; width: 100%; height: 100%; object-fit: cover; }
.pr[data-img="yes"] .pr__face img { display: block; }
.pr[data-img="yes"] .pr__ini { display: none; }
.pr__ini { font-size: calc(var(--pr-av) * .32); font-weight: 600; letter-spacing: .02em; color: var(--text-secondary); display: grid; place-items: center; }
.pr__ini svg { width: calc(var(--pr-av) * .42); height: calc(var(--pr-av) * .42); }
/* presence badge + progress ring: shared primitives (components/widget-visuals), sized from the avatar */
.pr__av { --iqv-anchor: var(--pr-av); }
.pr .pr__badge { --iqv-bs: max(18px, calc(var(--pr-av) * .24)); box-shadow: 0 0 0 2px var(--surface-primary); }
.pr__level { position: absolute; inset: 0; }
.pr[data-ring="yes"] .pr__ring { display: none; }                 /* the level ring takes the presence ring's place… */
.pr[data-ring="yes"] .pr__face { inset: calc(var(--pr-av) * .125); }   /* …inside it (thickness .075 + gap .05) */
.pr[data-presence="unavailable"] .pr__level { opacity: var(--unavailable-opacity); }
.pr[data-presence="away"] .pr__face, .pr[data-presence="unknown"] .pr__face { filter: saturate(.4) brightness(.8); }
.pr[data-presence="unavailable"] .pr__av { opacity: var(--unavailable-opacity); filter: grayscale(1); }

/* ---- text ---- */
.pr__id { grid-area: id; min-width: 0; }
.pr__name { margin: 0; font-size: 14px; font-weight: var(--iq-fw-title); line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pr__state { margin: 2px 0 0; display: flex; align-items: center; gap: 6px; font-size: 12.5px; line-height: 1.3; min-width: 0; }
.pr__state-t { font-weight: var(--iq-fw-status); color: var(--pr-tone); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pr__dot { flex: none; width: 7px; height: 7px; border-radius: 50%; background: var(--pr-tone); }
.pr[data-presence="unknown"] .pr__dot, .pr[data-presence="unavailable"] .pr__dot { background: transparent; box-shadow: inset 0 0 0 1.5px var(--text-muted); }
.pr[data-presence="unavailable"] .pr__name { color: var(--text-muted); }
.pr__more { margin: 1px 0 0; font-size: 11.5px; line-height: 1.3; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pr__more[hidden] { display: none; }

/* ---------------------------------------------------------------- standard: ≥ 260px wide */
@container pr (min-width: 260px) {
  .pr__in { --pr-av: clamp(48px, calc(100cqh - 28px), 72px); padding: 14px 18px; grid-template-columns: auto minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); grid-template-areas: "av id"; column-gap: 14px; align-items: center; }
  .pr__name { font-size: 16px; }
  .pr__state { font-size: 13.5px; }
  .pr__more { font-size: 12px; }
}

/* ---------------------------------------------------------------- short: one line (narrow, < 120px tall) */
@container pr (max-width: 259px) and (max-height: 119px) {
  .pr__in { --pr-av: 40px; padding: 10px 12px; grid-template-columns: auto minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); grid-template-areas: "av id"; column-gap: 10px; align-items: center; }
  .pr__name { font-size: 13.5px; }
  .pr__state { font-size: 12px; }
  .pr__more { display: none; }
}

/* ================================================================ own size (width AND height)
   The picture is the identity: it grows with the room it has, the name and the real presence stay with it.
     narrow, 120–199 tall   avatar top-left (larger), name + presence at the bottom
     ≥ 200 tall (not wide)  PORTRAIT: avatar centred and large (up to 220px), name + presence centred under it
     wide (< 200 tall, or ≥ 1.8 : 1)   ROW: avatar sized by the height (up to 160px), name + presence beside it
   The badge (and the optional level ring) scale with the avatar. */
@container pr (max-width: 259px) and (min-height: 120px) and (max-height: 199px) {
  .pr__in { --pr-av: clamp(44px, min(calc(100cqh - 74px), 45cqw), 76px); }
}
@container pr (min-width: 260px) and ((max-height: 199px) or (min-aspect-ratio: 9 / 5)) {
  .pr__in { --pr-av: clamp(48px, calc(100cqh - 28px), 160px); column-gap: clamp(14px, 6cqh, 24px); }
  .pr__name { font-size: clamp(16px, 13cqh, 24px); }
  .pr__state { font-size: clamp(13.5px, 10cqh, 17px); }
}
@container pr (min-height: 200px) and (min-width: 140px) and (max-aspect-ratio: 9 / 5) {
  .pr__in {
    --pr-av: clamp(64px, min(62cqw, calc(100cqh - 96px)), 220px);
    padding: clamp(14px, 5cqmin, 26px);
    grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto auto minmax(0, 1fr);
    grid-template-areas: "." "av" "id" "."; justify-items: center; align-items: center; row-gap: clamp(10px, 4cqh, 20px);
  }
  .pr__id { text-align: center; justify-self: stretch; }
  .pr__name { font-size: clamp(15px, calc(var(--pr-av) * .12), 24px); }
  .pr__state { justify-content: center; font-size: clamp(13px, calc(var(--pr-av) * .085), 17px); }
  .pr__ring { box-shadow: inset 0 0 0 max(2px, calc(var(--pr-av) * .02)) var(--pr-tone); }
}

/* ================================================================ variants: Row · Compact · Status (Portrait = the adaptive arrangements above)
   Forced presentations: they win over the own-size arrangements above, and still size from the widget's own box. */
.pr[data-variant="row"] .pr__in, .pr[data-variant="compact"] .pr__in {
  grid-template-columns: auto minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); grid-template-areas: "av id"; justify-items: start; align-items: center; text-align: left; padding: 10px 14px;
}
.pr[data-variant="row"] .pr__in { --pr-av: clamp(40px, calc(100cqh - 24px), 120px); column-gap: clamp(10px, 5cqh, 20px); }
.pr[data-variant="row"] .pr__id, .pr[data-variant="compact"] .pr__id { text-align: left; justify-self: stretch; }
.pr[data-variant="row"] .pr__state, .pr[data-variant="compact"] .pr__state { justify-content: flex-start; }
.pr[data-variant="row"] .pr__name { font-size: clamp(14px, 11cqh, 22px); }
.pr[data-variant="compact"] .pr__in { --pr-av: 34px; column-gap: 10px; padding: 8px 12px; }
.pr[data-variant="compact"] .pr__name { font-size: 13px; }
.pr[data-variant="compact"] .pr__state { font-size: 11.5px; margin-top: 0; }
.pr[data-variant="compact"] .pr__more { display: none; }
.pr[data-variant="status"] .pr__av { display: none; }
.pr[data-variant="status"] .pr__in { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); grid-template-areas: "id"; align-items: center; justify-items: start; text-align: left; padding: 10px 16px; }
.pr[data-variant="status"] .pr__id { justify-self: stretch; text-align: left; }
.pr[data-variant="status"] .pr__state { justify-content: flex-start; font-size: clamp(14px, 16cqh, 22px); margin-top: 3px; }
.pr[data-variant="status"] .pr__dot { width: clamp(8px, 4cqh, 12px); height: clamp(8px, 4cqh, 12px); }
.pr[data-variant="status"] .pr__name { font-size: clamp(12px, 10cqh, 17px); color: var(--text-secondary); }
.pr[data-variant="status"][data-presence="unavailable"] .pr__name { color: var(--text-muted); }
.pr[data-variant="compact"], .pr[data-variant="status"] { min-height: 56px; }
@container pr (max-height: 80px) { .pr[data-variant="status"] .pr__more { display: none; } }

/* ---------------------------------------------------------------- micro (pass 2): too narrow to share a row — the picture above, then name and the home / away state at full width */
@container pr (max-width: 139px) {
  .pr.pr:not([data-variant="status"]) .pr__in { --pr-av: 38px; padding: 10px 12px; grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); grid-template-areas: "av" "id"; row-gap: 6px; align-items: start; justify-items: start; }
  .pr.pr:not([data-variant="status"]) .pr__id { align-self: end; justify-self: stretch; }
  .pr.pr:not([data-variant="status"]) .pr__name { font-size: 13px; }
  .pr.pr:not([data-variant="status"]) .pr__state { font-size: 12px; }
  .pr.pr .pr__more { display: none; }
}

/* ================================================================ pass 2 — a polished avatar when there is no picture: lit, tinted by presence, initials as a monogram */
.pr[data-img="no"] .pr__face, .pr:not([data-img="yes"]) .pr__face { background: radial-gradient(circle at 32% 24%, color-mix(in srgb, var(--pr-tone) 34%, var(--surface-interactive)), var(--surface-tertiary) 68%); box-shadow: var(--shadow-icon), inset 0 1px 0 var(--edge-highlight); }
.pr[data-presence="away"]:not([data-img="yes"]) .pr__face, .pr[data-presence="unknown"]:not([data-img="yes"]) .pr__face { background: radial-gradient(circle at 32% 24%, var(--surface-interactive), var(--surface-tertiary) 70%); }
.pr:not([data-img="yes"]) .pr__ini { color: var(--text-primary); font-weight: var(--iq-fw-title); letter-spacing: .04em; text-shadow: 0 1px 2px rgba(0, 0, 0, .4); }
.pr__av { position: relative; }
@container pr (min-height: 200px) and (min-width: 140px) and (max-aspect-ratio: 9 / 5) {
  .pr__av::before { content: ""; position: absolute; inset: -14%; border-radius: 50%; background: radial-gradient(closest-side, color-mix(in srgb, var(--pr-tone) 22%, transparent), transparent); pointer-events: none; }
}

/* ================================================================ PROFILE (variant 'profile') — avatar · name · connection badge */
.iq-prof { display: flex; flex-direction: column; align-items: center; min-width: 0; font-family: var(--mai-font, var(--font)); color: #fff; }
.iq-prof__av { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-size: 11.5px; font-weight: 700; letter-spacing: .02em; color: #fff;
  background: radial-gradient(circle at 30% 25%, #ffb27a 0%, #f06d4f 45%, #9b3fd6 100%); box-shadow: 0 0 0 2px rgba(255, 255, 255, .9), 0 4px 10px rgba(0, 0, 0, .4); }
.iq-prof__name { margin-top: 8px; font-size: 10px; font-weight: 600; line-height: 14px; max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.iq-prof__live { display: inline-flex; align-items: center; gap: 3px; margin-top: 5px; padding: 1px 5px; border-radius: 99px; font-size: 6.2px; font-weight: 600; letter-spacing: .06em;
  text-transform: uppercase; color: #ffcf7a; background: rgba(255, 170, 60, .12); border: 1px solid rgba(255, 170, 60, .3); white-space: nowrap; line-height: 8px; }
.iq-prof__live::before { content: ""; width: 4px; height: 4px; border-radius: 50%; background: currentColor; }
.iq-prof__live[data-state="live"] { color: #b6f77a; background: rgba(143, 241, 46, .1); border-color: rgba(143, 241, 46, .3); }
.iq-prof__live[data-state="offline"] { color: #ff8b8b; background: rgba(241, 60, 60, .1); border-color: rgba(241, 60, 60, .3); }
