/* Rp1 juta simulator. Site tokens from assets/site.css; series colours are the chart's
   (assets/chart.css), light and dark. */
.sim {
  --sim-fund: var(--chart-fund);
  --sim-ihsg: var(--chart-ihsg);
  --sim-spx: var(--chart-spx);
  --sim-gold: var(--chart-gold);
  --sim-track: var(--chart-grid);
  container: sim / inline-size;
  margin-top: var(--s-7);
  background: var(--paper-raised);
  border-radius: 2px;
  padding: var(--s-4) var(--s-3);
}
@media (min-width: 40rem) {
  .sim { padding: var(--s-5); }
}

.sim-title {
  font-family: var(--serif);
  font-size: var(--f1);
  line-height: var(--l1);
  font-weight: 500;
}

/* Inputs */
.sim-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: var(--s-4) var(--s-4);
  margin-top: var(--s-4);
  padding-bottom: var(--s-5);
  border-bottom: 1px solid var(--ink);
}
.sim-field { display: grid; grid-template-columns: minmax(0, 1fr); row-gap: var(--s-1); flex: 1 1 9.5rem; min-width: 0; max-width: 14rem; }
/* The month list gets the room: "September 2024" must not run under the chevron. */
.sim-field:first-child { flex-basis: 8.5rem; }
.sim-field:nth-child(2) { flex-basis: 10.5rem; }
.sim-field label, .sim-k {
  font-size: var(--fm2);
  line-height: var(--lm2);
  font-weight: 500;
  color: var(--ink-muted);
}
.sim-amt {
  display: flex;
  align-items: center;
  width: 100%;
  height: 2.75rem;
  background: var(--paper);
  border: 1px solid var(--ink-muted);
  border-radius: 2px;
}
.sim-amt span {
  padding-left: var(--s-3);
  font-size: 1rem;
  line-height: var(--l0);
  color: var(--ink-muted);
}
.sim-amt input {
  flex: 1;
  width: 100%;
  min-width: 0;
  height: 100%;
  padding: 0 var(--s-3) 0 var(--s-1);
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
  font-variant-numeric: tabular-nums lining-nums;
}
.sim-amt input:focus { outline: none; }
.sim-amt:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.sim-amt:hover { border-color: var(--ink); }
.sim-amt:has(input[aria-invalid="true"]) { border-color: var(--accent); border-width: 2px; }

.sim-start {
  height: 2.75rem;
  width: 100%;
  padding: 0 1.75rem 0 var(--s-3);
  background-color: var(--paper);
  color: var(--ink);
  border: 1px solid var(--ink-muted);
  border-radius: 2px;
  font: inherit;
  font-size: 1rem;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%238C8476' stroke-width='1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--s-3) center;
  cursor: pointer;
}
.sim-start:hover { border-color: var(--ink); }
.sim-start:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.sim-end-v {
  display: flex;
  align-items: center;
  height: 2.75rem;
  font-size: 1rem;
  line-height: var(--l0);
}

/* When the end date wraps under the inputs, it reads as one line. */
@container sim (max-width: 30.49rem) {
  .sim-field:nth-child(2), .sim-field:last-child { flex-basis: 100%; max-width: none; display: flex; align-items: baseline; column-gap: var(--s-2); }
  .sim-end-v { height: auto; }
}

.sim-err {
  display: flex;
  align-items: baseline;
  gap: var(--s-2);
  font-size: var(--fm2);
  line-height: var(--lm2);
  font-weight: 500;
  color: var(--ink);
}
/* A second cue beside the border, so the error never reads as a focus ring. */
.sim-err::before {
  content: "";
  flex: none;
  width: 3px;
  height: 0.9em;
  align-self: center;
  background: var(--accent);
}
.sim-err[hidden] { display: none; }

/* Invalid amount: results for the last valid one fade until the field is fixed. */
.sim.is-stale .sim-rows,
.sim.is-stale .sim-axis { opacity: 0.35; }

/* Results */
.sim-rows { margin-top: var(--s-2); }
.sim-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  grid-template-areas: "name name" "val pct" "bar bar" "note note";
  column-gap: var(--s-3);
  align-items: baseline;
  padding-block: var(--s-3);
  border-bottom: 1px solid var(--rule);
  font-variant-numeric: tabular-nums lining-nums;
}
.sim-name { grid-area: name; font-size: var(--fm1); line-height: var(--lm1); color: var(--ink-muted); }
.sim-row[data-k="fund"] .sim-name { color: var(--ink); font-weight: 500; }
.sim-val { grid-area: val; font-size: var(--f0); line-height: var(--l0); font-weight: 500; color: var(--ink); }
.sim-pct { grid-area: pct; font-size: var(--fm1); line-height: var(--lm1); color: var(--ink-muted); text-align: right; }

@container sim (min-width: 30rem) {
  .sim-row {
    grid-template-columns: minmax(0, 1fr) auto 4.5rem;
    grid-template-areas: "name val pct" "bar bar bar" "note note note";
  }
  .sim-name { font-size: var(--f0); line-height: var(--l0); }
}

.sim-bar {
  grid-area: bar;
  position: relative;
  display: block;
  height: 8px;
  margin-top: var(--s-2);
  background: var(--sim-track);
  border-radius: 2px;
}
.sim-fill {
  position: absolute;
  inset: 0 auto 0 0;
  display: block;
  background: var(--sim-ihsg);
  border-radius: 2px 4px 4px 2px;
}
.sim-row[data-k="fund"] .sim-fill { background: var(--sim-fund); }
.sim-row[data-k="spx"] .sim-fill { background: var(--sim-spx); }
.sim-row[data-k="gold"] .sim-fill { background: var(--sim-gold); }
.sim-mark {
  position: absolute;
  top: -4px;
  bottom: -4px;
  width: 2px;
  margin-left: -1px;
  background: var(--ink);
  box-shadow: 0 0 0 1px var(--paper-raised);
}

/* Scale label under the bars: the starting amount, at the marker. */
.sim-axis {
  position: relative;
  height: var(--s-5);
  margin-top: var(--s-1);
  font-size: var(--fm2);
  line-height: var(--lm2);
  color: var(--ink-muted);
  font-variant-numeric: tabular-nums;
}
.sim-axis-l { position: absolute; top: 0; white-space: nowrap; transform: translateX(-1px); padding-left: var(--s-1); border-left: 2px solid var(--ink); }
.sim-axis-l.is-end { transform: translateX(calc(-100% + 1px)); padding: 0 var(--s-1) 0 0; border-left: 0; border-right: 2px solid var(--ink); }

.sim-gap, .sim-fine, .sim-nojs {
  font-size: var(--fm2);
  line-height: var(--lm2);
  color: var(--ink-muted);
  max-width: 40rem;
}
.sim-gap { grid-area: note; margin-top: var(--s-2); }
.sim-gap[hidden] { display: none; }
.sim-fine { margin-top: var(--s-3); }
.sim-nojs { margin-top: var(--s-2); }

/* Without JS: the default result as static rows, no inputs. */
.sim:not(.is-ready) .sim-form { display: none; }
.sim.is-ready .sim-nojs { display: none; }

@media (prefers-reduced-motion: no-preference) {
  .sim-fill { transition: width 200ms ease; }
  .sim-mark { transition: left 200ms ease; }
  .sim-rows, .sim-axis { transition: opacity 150ms ease; }
}

@media (forced-colors: active) {
  .sim-fill { background: CanvasText; forced-color-adjust: none; }
  .sim-row[data-k="fund"] .sim-fill { background: Highlight; }
  .sim-bar { border: 1px solid CanvasText; background: Canvas; }
  .sim-mark { background: CanvasText; }
  .sim-err::before { background: CanvasText; forced-color-adjust: none; }
}
