/* Chart layer for «رابطهٔ ما» — hand-built SVG/CSS, no library (see js/components/charts.js).

   Time flows RIGHT → LEFT everywhere (oldest at the inline-start), matching the
   Jalali date picker and Persian reading order. Marks are thin, grids are solid
   hairlines one shade off the surface, and nothing depends on animation: every
   chart also has a table view, because motion is disabled globally under
   prefers-reduced-motion. See docs/11-relationship.md. */

:root {
  /* Two people = two entities = two fixed hues, assigned by SIDE and never by rank:
     the admin side is the teal, the partner side the pink. They are the same two
     identities the rest of the app uses (--p-a / --p-b), so a person's colour is
     the same in a chart, in a compare card, and on a feed row. Colour never has to
     carry identity alone regardless — the legend, the direct labels, and the
     filled-vs-ringed dot all repeat it.
     --viz-accent is for magnitude bars that belong to *nobody* (رشدِ ما), which
     must not borrow either person's hue. */
  --viz-me: var(--p-a);
  --viz-you: var(--p-b);
  --viz-accent: var(--accent);

  /* Ordinal rose ramp, weakest → strongest (😢 → 😄, and heat 1 → 4).
     Single hue, monotone lightness, adjacent ΔL ≥ 0.06, palest step ≥ 2:1 on the
     surface — validated with `validate_palette.js --ordinal`. */
  --viz-o1: #f19ab0;
  --viz-o2: #e97596;
  --viz-o3: #de4c7d;
  --viz-o4: #cb2266;
  --viz-o5: #ad0052;

  /* Chart chrome — recessive by design. */
  --viz-grid: color-mix(in srgb, var(--hint) 22%, transparent);
  --viz-axis: color-mix(in srgb, var(--hint) 38%, transparent);
  --viz-track: var(--bg-4);
  --viz-empty: var(--bg-3);
}

:root[data-theme="dark"] {
  /* The dark column is the same hues re-stepped for the dark surface, not a flip.
     The two identity hues follow --p-a/--p-b, which the palette already re-steps. */
  --viz-o1: #a61c53;
  --viz-o2: #c72b67;
  --viz-o3: #e2477d;
  --viz-o4: #f16e95;
  --viz-o5: #f697af;
  --viz-grid: color-mix(in srgb, var(--hint) 28%, transparent);
  --viz-axis: color-mix(in srgb, var(--hint) 45%, transparent);
  --viz-track: var(--bg-4);
  --viz-empty: var(--bg-3);
}

/* --- card shell ------------------------------------------------------------- */

.chart-card { margin-block-start: var(--s4); }
.chart-head { display: flex; align-items: flex-start; gap: var(--s2); margin-block-end: var(--s3); }
.chart-head .grow { min-width: 0; }
.chart-title {
  display: flex; align-items: center; gap: var(--s2);
  font-size: var(--fs-h2); font-weight: 600;
}
.chart-title .icon { color: var(--accent); }
.chart-sub { font-size: var(--fs-meta); color: var(--hint); margin-block-start: 2px; }
.chart-tools { display: flex; gap: var(--s1); flex: none; }
.chart-tool {
  min-width: 32px; min-height: 32px; padding-inline: var(--s2);
  display: inline-grid; place-items: center;
  border: none; border-radius: var(--r-pill);
  background: var(--bg-3); color: var(--hint);
  font-size: var(--fs-meta); font-weight: 600; font-family: inherit; cursor: pointer;
}
.chart-tool[aria-pressed="true"] { background: var(--rose-soft); color: var(--rose-strong); }

/* Refetch holds the previous render at reduced opacity — no skeleton flash, no jump. */
.chart-stale { opacity: 0.45; transition: opacity var(--dur-micro); }

/* Legends: always present for two or more series, so identity is never colour-only. */
.chart-legend { display: flex; flex-wrap: wrap; gap: var(--s3); margin-block-end: var(--s2); }
.chart-legend .li { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-meta); color: var(--hint); }
.chart-legend .sw { inline-size: 10px; block-size: 10px; border-radius: 3px; flex: none; }
.chart-legend .sw-line { inline-size: 14px; block-size: 3px; border-radius: 2px; }

/* --- line chart ------------------------------------------------------------- */

.chart-plot { position: relative; }
.chart-plot svg { display: block; width: 100%; height: auto; overflow: visible; }
.viz-grid-line { stroke: var(--viz-grid); stroke-width: 1; }
.viz-axis-line { stroke: var(--viz-axis); stroke-width: 1; }
.viz-tick { fill: var(--hint); font-size: 9px; font-variant-numeric: tabular-nums; }
.viz-line { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.viz-area { stroke: none; opacity: 0.14; }
.viz-dot { stroke: var(--card); stroke-width: 2; }
.viz-cross { stroke: var(--viz-axis); stroke-width: 1; }
.viz-hit { fill: transparent; }
.viz-label { font-size: 9.5px; font-weight: 700; }

/* --- horizontal bars (magnitude; grow from the inline-start = the right) ----- */

.bar-rows { display: flex; flex-direction: column; gap: var(--s3); }
.bar-row { display: grid; grid-template-columns: 1fr auto; gap: 2px var(--s2); align-items: center; }
.bar-row .bar-name { font-size: var(--fs-body); min-width: 0; }
.bar-row .bar-val { font-size: var(--fs-meta); color: var(--hint); font-variant-numeric: tabular-nums; }
.bar-track {
  grid-column: 1 / -1;
  block-size: 10px; border-radius: 5px;
  background: var(--viz-track); overflow: hidden;
}
.bar-fill { display: block; block-size: 100%; border-radius: 5px; min-inline-size: 4px; }
/* Grouped: one thin bar per person, a 2px surface gap between them (no borders),
   and each value at the end of its own bar so RTL can't swap whose is whose. */
.bar-group { grid-column: 1 / -1; display: flex; flex-direction: column; gap: 2px; }
.bar-line { display: flex; align-items: center; gap: var(--s2); }
.bar-line .bar-track { flex: 1; block-size: 7px; }
.bar-line .bar-val { min-inline-size: 2.2em; text-align: end; }

/* --- 100% stacked bar (ordered categories → the ordinal ramp) ---------------- */

.stack {
  display: flex; gap: 2px; /* the gap IS the separator — never a border */
  block-size: 26px; border-radius: var(--r-btn); overflow: hidden;
}
.stack > span {
  display: grid; place-items: center;
  font-size: 11px; font-weight: 700; color: #fff;
  min-inline-size: 3px; white-space: nowrap;
}
.stack-legend { display: flex; flex-wrap: wrap; gap: var(--s2) var(--s3); margin-block-start: var(--s2); }
.stack-legend .li { display: inline-flex; align-items: center; gap: 5px; font-size: var(--fs-meta); color: var(--hint); }

/* --- activity heatmap (Jalali weeks, Saturday-first rows, newest column last) */

.heat {
  display: grid; grid-auto-flow: column; grid-template-rows: repeat(7, 1fr);
  gap: 3px; direction: rtl; /* first column lands on the right = oldest week */
}
.heat-cell {
  aspect-ratio: 1; border-radius: 3px; border: none; padding: 0;
  background: var(--viz-empty); cursor: pointer; min-inline-size: 9px;
}
.heat-l1 { background: var(--viz-o1); }
.heat-l2 { background: var(--viz-o2); }
.heat-l3 { background: var(--viz-o3); }
.heat-l4 { background: var(--viz-o5); }
.heat-today { box-shadow: inset 0 0 0 1.5px var(--text); }
.heat-wrap { display: flex; gap: var(--s2); align-items: stretch; }
.heat-days {
  display: grid; grid-template-rows: repeat(7, 1fr); gap: 3px;
  font-size: 9px; color: var(--hint); flex: none;
}
.heat-days span { display: grid; place-items: center; }
.heat-scale { display: flex; align-items: center; gap: 4px; font-size: var(--fs-meta); color: var(--hint); }
.heat-scale i { inline-size: 10px; block-size: 10px; border-radius: 3px; }

/* --- tooltip (enhances; never the only way to read a value) ------------------ */

#chart-tip {
  position: fixed; z-index: 70; pointer-events: none; opacity: 0;
  transform: translate(-50%, -100%);
  background: color-mix(in srgb, var(--text) 90%, transparent);
  color: var(--bg);
  border-radius: var(--r-btn); padding: 6px var(--s2);
  font-size: var(--fs-meta); font-weight: 600; white-space: nowrap;
  transition: opacity var(--dur-micro);
  max-inline-size: 70vw; text-align: center;
}
#chart-tip.on { opacity: 1; }
#chart-tip b { font-weight: 800; }

/* --- table view (the WCAG-clean twin of every chart) ------------------------- */

.chart-table-wrap { overflow-x: auto; }
.chart-table { inline-size: 100%; border-collapse: collapse; font-size: var(--fs-meta); }
.chart-table th, .chart-table td {
  padding: 6px var(--s2); text-align: start;
  border-block-end: 1px solid color-mix(in srgb, var(--hint) 15%, transparent);
}
.chart-table th { color: var(--hint); font-weight: 700; }
.chart-table td { font-variant-numeric: tabular-nums; }
.chart-table tr:last-child td { border-block-end: none; }

/* --- page bits: badges, timeline, profiles ----------------------------------- */

.badge-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: var(--s2); }
.badge-cell {
  text-align: center; padding: var(--s3) var(--s2);
  border-radius: var(--r-card); background: var(--bg-3);
  font-size: var(--fs-meta);
}
.badge-cell .em { font-size: 24px; line-height: 1.3; }
.badge-cell.locked { opacity: 0.5; }
.badge-cell.got { background: var(--rose-soft); }
.badge-cell .t { font-weight: 700; margin-block-start: 2px; line-height: 1.35; }
.badge-cell .p { color: var(--hint); }

.tl { display: flex; flex-direction: column; }
.tl-item { display: grid; grid-template-columns: 26px 1fr; gap: var(--s3); position: relative; padding-block-end: var(--s4); }
.tl-item:last-child { padding-block-end: 0; }
.tl-item::before {
  content: ""; position: absolute; inset-block: 26px 0; inset-inline-start: 12px;
  border-inline-start: 1px solid color-mix(in srgb, var(--hint) 25%, transparent);
}
.tl-item:last-child::before { display: none; }
.tl-dot {
  inline-size: 26px; block-size: 26px; border-radius: 50%;
  display: grid; place-items: center; background: var(--rose-soft); font-size: 13px;
}

.person-grid { display: grid; gap: var(--s3); }
.person-card { padding: var(--s4); border-radius: var(--r-card); background: var(--bg-3); }
.person-card.mine { background: var(--rose-soft); }
.person-top { display: flex; align-items: center; gap: var(--s3); }
.person-av {
  inline-size: 44px; block-size: 44px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-size: 20px; font-weight: 800; color: #fff;
}
.person-facts { display: flex; flex-wrap: wrap; gap: var(--s1) var(--s3); margin-block-start: var(--s3); font-size: var(--fs-meta); color: var(--hint); }
.person-facts b { color: var(--text); font-weight: 700; }

.report-note { padding: var(--s3); border-radius: var(--r-btn); background: var(--bg-3); }
.report-note + .report-note { margin-block-start: var(--s2); }
.report-note .t { font-weight: 700; }
.report-note .x { color: var(--hint); font-size: var(--fs-meta); margin-block-start: 2px; }
.report-sig {
  font-size: 1.05rem; font-weight: 700; line-height: 1.7;
  padding: var(--s3); border-radius: var(--r-card); background: var(--rose-soft);
}
