/* Planner-specific refinements */
/* .form-grid mobile collapse now lives in components.css (shared). */

/* =====================================================================
 * Challenge cards
 *
 * A challenge card is a verdict, so the outcome is carried by a left rail
 * rather than by tinting the whole card: the card also holds progress bars
 * and a breach sentence that need a neutral background to stay readable.
 * ================================================================== */

.challenge-card {
  position: relative;
  padding-left: var(--space-4);
}

.challenge-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 2px;
  bottom: 2px;
  width: 3px;
  border-radius: var(--radius-pill);
  background: var(--color-border-strong);
}

.challenge-card--in-progress::before { background: var(--color-accent); }
.challenge-card--passed::before { background: var(--color-profit); }
.challenge-card--failed::before { background: var(--color-loss); }

.challenge-card__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.challenge-card__head > div:first-child {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  min-width: 0;
}

.challenge-card__name {
  font-size: var(--fs-body);
}

.challenge-card__attempt {
  font-variant-numeric: tabular-nums;
}

.challenge-card__ruleset {
  margin-top: var(--space-2);
  font-size: var(--fs-footnote);
  color: var(--color-text-secondary);
}

.challenge-card__timeline {
  margin-top: 2px;
  font-size: var(--fs-caption);
  color: var(--text-2);
}

.challenge-card__bar {
  margin-top: var(--space-4);
}

.challenge-card__risk {
  margin-top: var(--space-5);
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-border);
}

.challenge-card__risk .challenge-card__bar {
  margin-top: var(--space-2);
}

.challenge-card__breach,
.challenge-warning {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  margin-top: var(--space-4);
  padding: var(--space-3);
  border-radius: var(--radius-md);
  background: var(--color-loss-soft);
  color: var(--color-text-primary);
  font-size: var(--fs-footnote);
  line-height: 1.45;
}

.challenge-card__breach svg,
.challenge-warning svg {
  flex-shrink: 0;
  margin-top: 1px;
  color: var(--color-loss);
}

.challenge-warning--info {
  background: var(--color-accent-soft);
}

.challenge-warning--info svg {
  color: var(--color-accent);
}

.challenge-card__pace {
  margin-top: var(--space-3);
  font-size: var(--fs-footnote);
  color: var(--color-text-secondary);
}

.challenge-card__pace.is-warning {
  color: var(--color-loss);
}

.challenge-card__meta {
  margin-top: var(--space-3);
  font-size: var(--fs-caption);
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}

.challenge-card__note {
  margin-top: var(--space-3);
  font-size: var(--fs-caption);
  color: var(--text-2);
  line-height: 1.45;
}

/* ---- Earlier attempts ---------------------------------------------- */

.challenge-history {
  margin-top: var(--space-5);
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-border);
}

.challenge-history__row {
  display: grid;
  grid-template-columns: auto auto 1fr auto;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  font-size: var(--fs-footnote);
}

.challenge-history__row + .challenge-history__row {
  border-top: 1px solid var(--color-border);
}

.challenge-history__n {
  color: var(--color-text-secondary);
  white-space: nowrap;
}

.challenge-history__val {
  text-align: right;
  min-width: 0;
}

.challenge-history__date {
  font-size: var(--fs-caption);
  white-space: nowrap;
}

/* ---- Rule rows in the create/edit modal ------------------------------
 * Unit labels sit on the field itself, not only in the row title: this is
 * the one form in the app that mixes R and %, and a wrong unit here is a
 * wrong verdict later. */

.challenge-rule {
  display: grid;
  grid-template-columns: 1fr 128px;
  grid-template-areas:
    "toggle input"
    "hint   hint";
  align-items: center;
  gap: var(--space-2) var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  transition: border-color var(--dur-fast) var(--ease-standard), background var(--dur-fast) var(--ease-standard);
}

.challenge-rule.is-on {
  border-color: rgba(var(--color-accent-rgb), 0.35);
  background: var(--color-accent-soft);
}

.challenge-rule__toggle {
  grid-area: toggle;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--fs-footnote);
  cursor: pointer;
  min-width: 0;
}

.challenge-rule__input {
  grid-area: input;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.challenge-rule__input .input {
  min-width: 0;
  text-align: right;
}

.challenge-rule__unit {
  flex-shrink: 0;
  width: 14px;
  font-size: var(--fs-footnote);
  color: var(--color-text-secondary);
}

.challenge-rule__hint {
  grid-area: hint;
  font-size: var(--fs-caption);
  color: var(--text-2);
  line-height: 1.4;
}

@media (max-width: 560px) {
  .challenge-rule {
    grid-template-columns: 1fr;
    grid-template-areas:
      "toggle"
      "input"
      "hint";
  }

  .challenge-history__row {
    grid-template-columns: auto 1fr;
    row-gap: 2px;
  }

  .challenge-history__date {
    grid-column: 1 / -1;
  }
}

/* =====================================================================
   Etap 8: the Tapebook composition of the Planner
   ================================================================== */

/* ---- Goals: three fields on one row ---- */
.plan-goals {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-5);
}

/* ---- Day plan: the day on the left, its line on the right ---- */
.plan-days {
  display: flex;
  flex-direction: column;
}

.plan-day {
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr);
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-2) 0;
  border-top: 1px solid var(--color-border);
}

.plan-day:first-child {
  border-top: 0;
}

.plan-day__label {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.plan-day__name {
  font-size: 14px;
  font-weight: 600;
}

.plan-day__date {
  font-size: 13px;
  color: var(--text-2);
}

.plan-day.is-today .plan-day__date {
  color: var(--color-text-primary);
}

.challenge-card__risk .tb-bar {
  margin-top: var(--space-1);
}

.challenge-history .tb-label {
  display: flex;
  margin-bottom: var(--space-3);
}

@media (max-width: 700px) {
  .plan-goals {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-4);
  }

  .plan-day {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-2);
    padding: var(--space-3) 0;
  }

  .plan-day__label {
    flex-direction: row;
    align-items: baseline;
    gap: var(--space-2);
  }
}

/* =====================================================================
   The Planner (new look, stage 3). The shared parts (.vdesk, .vlead, .vbelow,
   .vwin) are in css/components/desk.css, the graphics and the windows' look
   (the segmented control, .dv-*) in css/components/dataviz.css.
   ===================================================================== */

.vdesk.pl-desk {
  min-height: 0;
}

.pl-desk__status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px 24px;
}

/* The week: the arrows around its number and days. */
.pl-week {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  min-width: 0;
}

.pl-week__step {
  flex: none;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--tile);
  color: var(--text-2);
  cursor: pointer;
}

.pl-week__step:hover {
  background: var(--tile-2);
  color: var(--text-1);
}

.pl-week__step:focus-visible {
  outline: 2px solid var(--lead);
  outline-offset: 2px;
}

.pl-week__chev {
  display: inline-flex;
}

.pl-week__chev.is-next {
  transform: rotate(180deg);
}

.pl-week__label {
  display: flex;
  flex-direction: column;
  min-width: 120px;
}

.pl-week__no {
  font-size: 13px;
  color: var(--text-2);
}

.pl-week__label b {
  font-size: 17px;
  font-weight: 600;
  white-space: nowrap;
}

.pl-tabs {
  flex: 0 1 auto;
}

/* ---- The desk body: the lead, then what the control chose ---- */
.pl-desk__body {
  display: grid;
  grid-template-columns: minmax(240px, 320px) minmax(0, 1fr) minmax(0, 1.1fr);
  gap: 24px 40px;
  margin-top: 28px;
  align-items: start;
}

.pl-lead .vlead__label {
  font-size: 13px;
  color: var(--text-2);
}

.pl-lead .vlead__figure {
  --fig-max: var(--fs-figure);
  margin-top: 6px;
}

.pl-lead .vlead__figure .dv-arrow {
  margin-right: 0.18em;
  font-size: 0.4em;
  vertical-align: 0.5em;
}

.pl-lead .vlead__sub {
  margin-top: 8px;
  font-size: 13px;
  color: var(--text-2);
}

.pl-side {
  min-width: 0;
}

.pl-side__k {
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--text-2);
}

.pl-today {
  margin: 0;
  font-size: 15px;
  line-height: 1.4;
  color: var(--text-1);
}

/* The week's days as a row of small squares (v13 .days). */
.pl-days {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 8px;
}

.pl-day {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.pl-day__box {
  display: block;
  width: 100%;
  height: 36px;
  border-radius: 10px;
  background: var(--track);
}

.pl-day__box.is-gain { background: color-mix(in srgb, var(--gain) 34%, transparent); }
.pl-day__box.is-loss { background: color-mix(in srgb, var(--loss) 34%, transparent); }
.pl-day__box.is-flat { background: var(--tile-2); }
.pl-day__box.is-part { background: color-mix(in srgb, var(--lead) 30%, transparent); }

.pl-day.is-today .pl-day__box {
  box-shadow: inset 0 0 0 1.5px var(--lead);
}

/* A day still to come: the box is dimmed, the words are not (opacity put the
   weekday at 2.9:1 in light; --text-3 holds 4.5:1 in both themes). */
.pl-day.is-future .pl-day__box {
  opacity: 0.55;
}

.pl-day.is-future .pl-day__name,
.pl-day.is-future .pl-day__val {
  color: var(--text-3);
}

.pl-day__name {
  font-size: 13px;
  color: var(--text-2);
}

.pl-day.is-today .pl-day__name {
  font-weight: 600;
  color: var(--text-1);
}

.pl-day__val {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  color: var(--text-1);
  font-variant-numeric: tabular-nums;
}

.pl-day__val.is-gain { color: var(--gain); }
.pl-day__val.is-loss { color: var(--loss); }

/* The goals: a label and a value, the bar on its track under them. */
.pl-goals {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.pl-goals > .pl-goal:last-child:nth-child(odd) {
  grid-column: 1 / -1;
}

.pl-goals__set {
  grid-column: 1 / -1;
  font-size: 13px;
  color: var(--text-2);
}

.tile.pl-goal {
  padding: 12px 14px;
  border-radius: 12px;
}

.pl-goal__row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  font-size: 13px;
  color: var(--text-2);
}

/* A label that does not fit goes to a second line beside the value, not under it. */
.pl-goal__row > span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.pl-goal__row b {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-1);
  white-space: nowrap;
}

.dv-track.pl-track {
  height: 6px;
  margin-top: 10px;
  border-radius: 3px;
}

.dv-track.pl-track > i {
  border-radius: 3px;
}

/* The Challenges tab: the running challenge across the desk. */
.pl-chal {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.pl-chal > .vlead__label {
  font-size: 13px;
  color: var(--text-2);
}

.pl-chal__tile {
  position: relative;
  min-height: 220px;
  padding: 0;
  border-radius: 12px;
}

.pl-chal__sub {
  font-size: 13px;
  color: var(--text-2);
}

.pl-nochal {
  grid-column: 1 / -1;
  margin: 0;
  font-size: 15px;
  color: var(--text-2);
}

/* ---- Windows under the desk: mockup v13's structure ----
   Recessed, radius 22, padding 18 / 20; the head is a title and quiet meta on
   one baseline; the foot link sits right under the content. */
.pl-view .vwin {
  padding: 18px 20px;
  border-radius: 22px;
  background: var(--recess, var(--window));
  box-shadow: var(--window-edge);
}

.pl-view .vwin .win__head {
  align-items: baseline;
  margin-bottom: 14px;
}

.pl-view .vwin .win__title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-1);
}

/* A phone: the windows a size down, as Portfolio's (the operator 21.10). */
@media (max-width: 560px) {
  .pl-view .vwin {
    padding: 14px 16px;
    border-radius: var(--r-window);
  }

  .pl-view .vwin .win__title {
    font-size: 14px;
  }
}

.pl-view .vwin .win__note {
  font-size: 13px;
  color: var(--text-2);
}

/* The rows of a shared list (dv-row) in this view: v13's sizes. */
.pl-view .dv-row__main b,
.pl-view .dv-row__value {
  font-size: 14px;
  font-weight: 600;
}

.pl-view .dv-row__sub {
  font-size: 13px;
  color: var(--text-2);
}

.pl-view .dv-row__state {
  font-size: 13px;
}

/* ---- Windows: an even grid under the desk ---- */
.vbelow .pl-wins {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  align-items: stretch; /* a row: every window as tall as the tallest, the foot at the bottom */
}

.pl-win__head {
  align-items: baseline;
}

.pl-win__head .win__note {
  flex: 1 1 auto;
  text-align: right;
}

.pl-win__aside {
  flex: none;
}

.pl-win__sub {
  margin: -6px 0 14px;
  font-size: 13px;
  color: var(--text-2);
  max-width: 72ch;
}

.pl-foot {
  margin-top: auto;
  padding-top: 8px;
}

/* The review runs across the row; alone on its tab. */
.pl-win--review {
  grid-column: 1 / -1;
}

.pl-wins[data-showing="dayplan"] .pl-win--days {
  grid-column: 1 / -1;
}

.pl-win .plan-goals {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.pl-win .field__label {
  font-size: 13px;
  color: var(--text-2);
}

.pl-win .field__hint {
  font-size: 13px;
  color: var(--text-2);
  /* A two-line hint breaks in balance, never with one word alone below (C-18, AI-slop L15). */
  text-wrap: balance;
}

.pl-win .plan-day {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding: 14px 0;
  border-top-color: var(--line);
}

.pl-win .plan-day:first-child {
  padding-top: 0;
}

/* A day: its name and date on the left, the checklist count on the right. */
.pl-win .plan-day__head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
}

.pl-win .plan-day__label {
  flex-direction: row;
  align-items: baseline;
  gap: 8px;
}

.pl-win .plan-day.is-today .plan-day__date {
  color: var(--text-1);
}

.plan-day__progress {
  font-size: 13px;
  color: var(--text-2);
  white-space: nowrap;
}

.pl-items {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.pl-items:empty {
  display: none;
}

.pl-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
}

/* A step is a circle (v13 .ck): open = a ring, done = filled with a check. */
.pl-item__box {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  flex: none;
  width: 22px;
  height: 22px;
  margin: 0;
  border-radius: 50%;
  background: none;
  box-shadow: inset 0 0 0 1.5px var(--text-3);
  cursor: pointer;
}

.pl-item__box:checked {
  background: var(--lead);
  box-shadow: none;
}

.pl-item__box:checked::after {
  content: "";
  position: absolute;
  left: 6px;
  top: 5px;
  width: 9px;
  height: 5px;
  border-left: 2.2px solid var(--on-lead);
  border-bottom: 2.2px solid var(--on-lead);
  transform: rotate(-45deg);
}

.pl-item__box:focus-visible {
  outline: 2px solid var(--lead);
  outline-offset: 2px;
}

/* The list's fields stay quiet until pointed at: a ruled line, not a box. */
.pl-item__text,
.pl-item-add {
  padding: 6px 8px;
  background: transparent;
  border-color: transparent;
}

.pl-item__text:hover,
.pl-item-add:hover {
  border-color: var(--line);
}

.pl-item__text:focus,
.pl-item-add:focus {
  border-color: var(--color-accent);
}

.pl-item.is-done .pl-item__text {
  color: var(--text-2);
  text-decoration: line-through;
}

.pl-review {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px 20px;
}

.pl-review__notes {
  grid-column: 1 / -1;
}

/* Challenges tab: the head runs across the windows. */
.pl-chal-full {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  align-items: stretch;
}

.pl-chal-full[hidden] {
  display: none;
}

.pl-chal-head {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: 0 8px;
}

.pl-chal-head .win__head {
  margin-bottom: 0;
}

.pl-chal-head .acct-filter {
  max-width: 100%;
}

.pl-chain .challenge-history {
  border-top-color: var(--line);
}

@container vwins (max-width: 900px) {
  .vbelow .pl-wins {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .pl-win--chals {
    grid-column: 1 / -1;
  }
}

@container vwins (max-width: 640px) {
  .vbelow .pl-wins,
  .pl-chal-full {
    grid-template-columns: minmax(0, 1fr);
  }

  .pl-review,
  .pl-win .plan-goals {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Medium widths: the goals go under the lead and the days. */
@container vdesk (max-width: 1000px) {
  .pl-desk__body {
    grid-template-columns: minmax(200px, 300px) minmax(0, 1fr);
  }

  .pl-desk__body > .pl-side:nth-child(3) {
    grid-column: 1 / -1;
  }
}

/* Phone: one column; the control scrolls and fades where it goes on. */
@container vdesk (max-width: 640px) {
  .pl-desk__status {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  /* A size down on a phone (the operator 21.10): tighter rows, the figure 40px. */
  .pl-desk__body {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
    margin-top: 10px;
  }

  .pl-lead .vlead__figure {
    --fig-max: 40px;
  }

  .pl-goals {
    grid-template-columns: minmax(0, 1fr);
  }

  .pl-day__box {
    height: 30px;
  }
}

/* A goal field refused in words (the most-trades goal): the hint turns to the loss colour. */
.plan-goal .field__hint.is-error {
  color: var(--loss);
}

/* ---- Day plan window: the quiet list on This week, the form on the Day plan tab ---- */
.pl-days-summary {
  display: block;
}

.pl-sum__day {
  margin-bottom: 4px;
  font-size: 13px;
  color: var(--text-2);
}

.pl-sum__row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.pl-sum__text {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-1);
  overflow-wrap: anywhere;
}

.pl-sum__row.is-done .pl-sum__text {
  font-weight: 500;
  color: var(--text-2);
}

.pl-sum__next {
  flex: none;
  font-size: 13px;
  color: var(--text-2);
}

/* A step's circle (v13 .ck). */
.pl-ck {
  flex: none;
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1.5px var(--text-3);
}

.pl-ck.is-done {
  background: var(--lead);
  box-shadow: none;
  color: var(--on-lead);
}

.pl-ck svg {
  stroke-width: 2.6;
}

.pl-add {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pl-add .pl-item-add {
  flex: 1 1 auto;
}

/* A round + button, not a dashed box. */
.pl-add__btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--tile);
  color: var(--text-1);
  cursor: pointer;
}

.pl-add__btn:hover {
  background: var(--tile-2);
}

/* A finger needs 44 px (the plus stays a small circle to the eye on a fine pointer). */
@media (pointer: coarse) {
  .pl-add__btn {
    width: 44px;
    height: 44px;
  }
}

/* Forced colours drop box-shadows: the step circles keep their ring as a border. */
@media (forced-colors: active) {
  .pl-item__box,
  .pl-ck {
    box-sizing: border-box;
    border: 1.5px solid CanvasText;
    box-shadow: none;
  }

  .pl-item__box:checked,
  .pl-ck.is-done {
    border-color: Highlight;
    background: Highlight;
    color: HighlightText;
  }

  .pl-item__box:checked::after {
    border-color: HighlightText;
  }
}

.pl-add__btn:focus-visible {
  outline: 2px solid var(--lead);
  outline-offset: 2px;
}

/* This week: the summary, today's count and the link. Day plan tab: the form. */
.pl-wins:not([data-showing="dayplan"]) .pl-win--days .pl-win__sub,
.pl-wins:not([data-showing="dayplan"]) .pl-win--days .plan-days,
.pl-wins:not([data-showing="dayplan"]) .pl-win--days .pl-note--form,
.pl-wins[data-showing="dayplan"] .pl-win--days .pl-days-summary,
.pl-wins[data-showing="dayplan"] .pl-win--days .pl-note--sum,
.pl-wins[data-showing="dayplan"] .pl-win--days .pl-edit {
  display: none;
}
