/* Roommate Cleaning Schedule demo. The palette, fonts, buttons, chips,
   tables and the readout screen come from site.css and demo.css. This file
   lays out the three steps and restyles the original app with those tokens. */

.cs {
  max-width: var(--wrap);

  /* Some elements here set their own display, which would beat the hidden attribute. */
  [hidden] {
    display: none !important;
  }

  /* The wrapper takes its width from the panel and never from the table, so on
     a phone a wide table scrolls sideways instead of widening the whole page. */
  .table-wrap {
    contain: inline-size;
  }

  .table th {
    white-space: normal;
    vertical-align: bottom;
  }

  /* Row headers read like the cells beside them, not like column labels. */
  .table tbody th {
    border-bottom: 1px solid var(--rule);
    font-family: var(--font-sans);
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: normal;
    text-transform: none;
    color: var(--ink);
    vertical-align: top;
  }
}

/* ---------- rename ---------- */

.rename {
  margin-bottom: 8px;

  summary {
    width: fit-content;
    font-weight: 600;
    cursor: pointer;
  }
}

.rename-body {
  display: grid;
  gap: 10px;
  max-width: 48rem;
  margin-top: 12px;
}

.rename-fields {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 8.5rem), 1fr));
  gap: 10px;
}

/* ---------- steps ---------- */

.cs-step {
  display: grid;
  gap: clamp(18px, 3vw, 28px);
  padding-block: clamp(28px, 5vw, 48px);
  border-top: var(--line) solid var(--ink);
}

.cs-step-head {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 16px;
  align-items: start;
  max-width: 50em;

  .balloon {
    margin: 0;
  }

  h2 {
    font-size: clamp(2rem, 4.6vw, 2.9rem);
    font-stretch: 70%;
    font-weight: 400;
  }

  p {
    color: var(--ink-2);
  }

  /* On a phone the intro runs under the balloon too, so it gets the full width. */
  @media (max-width: 560px) {
    align-items: center;

    > .stack {
      display: contents;
    }

    p {
      grid-column: 1 / -1;
    }
  }
}

.step-split {
  display: grid;
  gap: clamp(16px, 2.5vw, 24px);
  align-items: start;

  @media (min-width: 1100px) {
    grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr);
  }
}

/* ---------- step 1: chores and the old lists ---------- */

.chores {
  display: grid;
  gap: 14px;
  margin: 0;
  padding: 0;
  list-style: none;

  @media (min-width: 760px) {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

.chore {
  display: grid;
  gap: 8px;
  align-content: start;
  padding: 16px 18px;
  border: 1px solid var(--rule);
  border-radius: 12px;
  background: var(--paper);

  h3 {
    font-size: 1.35rem;
    font-stretch: 78%;
    font-weight: 600;
  }

  p:not(.label) {
    font-size: 0.98rem;
    color: var(--ink-2);
  }

  .label {
    margin-top: 4px;
  }
}

.old-list {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin: 0;
  padding: 0;
  list-style: none;
  counter-reset: turn;
  font-family: var(--font-mono);
  font-size: 0.82rem;

  li {
    counter-increment: turn;
  }

  li::before {
    content: counter(turn) ". ";
    color: var(--ink-3);
  }
}

/* ---------- tables ---------- */

.schedule-table td {
  white-space: nowrap;
}

.break-row td {
  font-style: italic;
  color: var(--ink-3);
}

/* A name with more than one chore that weekend. The wavy line marks it without relying on color. */
.clash {
  font-weight: 600;
  color: var(--danger);
  text-decoration: underline wavy;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}

.doubled {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--danger);

  &:empty::before {
    content: "–";
    color: var(--ink-3);
  }
}

.is-now td {
  background: color-mix(in srgb, var(--accent) 12%, transparent);

  &:first-child {
    box-shadow: inset 3px 0 0 var(--accent);
  }
}

.me,
.is-me th {
  font-weight: 700;
  text-decoration: underline;
  text-decoration-color: var(--accent);
  text-decoration-thickness: 2px;
  text-underline-offset: 0.22em;
}

.rules-table {
  td {
    vertical-align: middle;
  }

  .rule-text {
    display: block;
  }

  .rule-detail {
    display: block;
    margin-top: 2px;
    font-size: 0.88rem;
    color: var(--ink-2);
  }

  b {
    font-family: var(--font-mono);
    font-weight: 500;
    color: var(--ink);
  }

  .chip {
    min-width: 2.4em;
    font-size: 0.8rem;
    text-align: center;
  }
}

.rules-score {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--ink-2);

  b {
    font-weight: 500;
    color: var(--ink);
  }
}

.totals-table .total {
  font-weight: 700;
}

/* ---------- step 2: the optimizer ---------- */

.run-split {
  align-items: start;
}

.run-copy p {
  max-width: 36em;
  color: var(--ink-2);
}

.run-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 10px;
  margin-top: 6px;
}

.seed-field {
  width: 7.5rem;
}

.run-readout {
  --chart-grid: color-mix(in srgb, var(--screen-ink) 14%, transparent);

  [data-run-state="running"] {
    color: var(--screen-hi);
  }

  dd {
    font-variant-numeric: tabular-nums;
  }
}

.cost-chart {
  position: relative;
  height: 140px;
  margin-top: 14px;
  border-bottom: 1px solid var(--chart-grid);
  /* Gridlines at 100,000, 10,000, 1,000 and 100. */
  background-image: linear-gradient(var(--chart-grid) 1px, transparent 1px);
  background-size: 100% 25%;

  svg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    overflow: visible;
  }
}

.cost-line {
  fill: none;
  stroke: var(--screen-ink);
  stroke-width: 1;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}

/* Drawn first and thicker, so the cost-now line shows on top wherever it climbs above. */
.best-line {
  stroke: var(--screen-hi);
  stroke-width: 3;
}

/* The script places each tick on its log scale. */
.tick {
  position: absolute;
  font-size: 0.66rem;
  color: var(--screen-dim);
}

.tick-cost {
  right: 4px;
  translate: 0 -120%;
}

.chart-steps {
  position: relative;
  height: 1.4em;
  margin-top: 2px;

  .tick {
    top: 0;
    translate: -50% 0;
  }

  .tick:last-child {
    translate: -80% 0;
  }
}

.chart-key {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin-top: 8px;
  font-size: 0.7rem;
  color: var(--screen-dim);

  .key-best::before,
  .key-current::before {
    content: "";
    display: inline-block;
    width: 14px;
    height: 2px;
    margin-right: 6px;
    vertical-align: middle;
    background: var(--screen-hi);
  }

  .key-current::before {
    height: 1px;
    background: var(--screen-ink);
  }
}

.run-summary {
  min-height: 1.6em;
  font-weight: 500;

  a {
    margin-left: 6px;
    font-weight: 600;
    color: var(--accent-ink);
  }
}

/* ---------- step 3: the result ---------- */

.result-empty {
  padding: 18px 20px;
  border: var(--line) dashed var(--ink-3);
  border-radius: 12px;
  color: var(--ink-2);
}

.result-body {
  --stack-gap: clamp(16px, 2.5vw, 24px);
}

.misses {
  max-width: 52em;
  padding: 12px 16px;
  border: var(--line) solid var(--danger);
  border-radius: 12px;
}

.app-split {
  display: grid;
  gap: clamp(16px, 2.5vw, 24px);
  align-items: start;

  @media (min-width: 1100px) {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }
}

/* ---------- the app ---------- */

.app {
  display: grid;
  gap: 16px;
  align-content: start;

  h4 {
    font-size: 1.15rem;
    font-stretch: 85%;
    font-weight: 600;
  }
}

.app-head {
  display: grid;
  gap: 4px;

  h3 {
    font-size: 1.8rem;
    font-stretch: 72%;
    font-weight: 500;
  }
}

/* The date control belongs to the demo, so it's drawn apart from the app. */
.today-control {
  display: grid;
  gap: 8px;
  padding: 12px 14px;
  border: var(--line) dashed var(--ink-3);
  border-radius: 12px;
}

.today-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;

  .input {
    width: auto;
  }
}

.today-weekday {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--ink-2);
}

.people {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 96px), 1fr));
  gap: 10px;
  margin-top: 12px;
}

.person-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 14px 8px;
  border: var(--line) solid var(--ink);
  border-radius: 12px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition:
    border-color 0.15s,
    color 0.15s;

  &:hover {
    border-color: var(--accent-ink);
    color: var(--accent-ink);
  }
}

/* Initials in a circle, like the balloons that number the steps. */
.avatar {
  display: grid;
  flex: none;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 2px solid currentColor;
  border-radius: 50%;
  font-family: var(--font-mono);
  font-size: 1.05rem;
  font-weight: 500;
}

.me-bar {
  display: flex;
  align-items: center;
  gap: 12px;

  .avatar {
    width: 38px;
    height: 38px;
    font-size: 0.95rem;
  }
}

.me-name {
  flex: 1;
  font-size: 1.35rem;
  font-stretch: 80%;
  font-weight: 600;
}

.banner {
  padding: 10px 14px;
  border: 1px solid var(--rule);
  border-radius: 10px;
  background: var(--paper-2);
  font-size: 0.95rem;
}

.week-card {
  display: grid;
  gap: 14px;
  padding: 16px;
  border: var(--line) solid var(--ink);
  border-radius: var(--radius);
  background: var(--paper);
  box-shadow: 5px 5px 0 var(--shade);
}

.weeknav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.nav-btn {
  display: grid;
  flex: none;
  place-items: center;
  width: 40px;
  height: 40px;
  border: var(--line) solid var(--ink);
  border-radius: 50%;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;

  svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  &:hover {
    border-color: var(--accent-ink);
    color: var(--accent-ink);
  }

  &[aria-disabled="true"] {
    border-color: var(--rule);
    color: var(--ink-3);
    cursor: not-allowed;
  }
}

.weekhead {
  display: grid;
  justify-items: center;
  gap: 4px;
  text-align: center;
}

.week-title {
  font-size: 2rem;
  font-stretch: 70%;
  font-weight: 500;
}

.week-dates {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--ink-2);

  span {
    white-space: nowrap;
  }
}

.tasks {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.task {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 14px 16px;
  border: 1px solid var(--rule);
  border-radius: 12px;
  background: var(--paper-2);
}

.task-icon {
  flex: none;
  width: 30px;
  height: 30px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.task-name {
  font-weight: 700;
}

.task-with {
  font-weight: 400;
  color: var(--ink-2);
}

.task-desc {
  margin-top: 3px;
  font-size: 0.92rem;
  line-height: 1.45;
  color: var(--ink-2);
}

.free {
  padding: 16px;
  border-radius: 12px;
  background: var(--paper-2);
  font-weight: 600;
  text-align: center;

  small {
    display: block;
    margin-top: 4px;
    font-size: 0.92rem;
    font-weight: 400;
    color: var(--ink-2);
  }
}

.week-hint,
.week-back {
  text-align: center;
}

.my-weekends {
  display: grid;
  gap: 6px;
}

.my-list {
  display: grid;
  gap: 2px;
  margin: 4px 0 0;
  padding: 0;
  list-style: none;
}

.my-weekend {
  position: relative;
  display: grid;
  grid-template-columns: 3.2rem 6.2rem minmax(0, 1fr);
  align-items: center;
  gap: 4px 8px;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: none;
  color: var(--ink);
  font: inherit;
  text-align: left;
  cursor: pointer;

  &:hover {
    background: var(--paper-2);
  }

  &[aria-current="true"] {
    border-color: var(--rule);
    background: var(--paper-2);
  }

  &.is-now {
    box-shadow: inset 3px 0 0 var(--accent);
  }

  &.is-past,
  &.is-past .chip {
    color: var(--ink-3);
  }

  @media (max-width: 480px) {
    grid-template-columns: 3.2rem minmax(0, 1fr);

    .my-what {
      grid-column: 2;
    }
  }
}

.my-week {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--ink-2);
}

.my-dates {
  font-size: 0.95rem;
}

.my-what {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;

  .chip {
    border-color: var(--ink-3);
    color: var(--ink);
  }
}

.my-off {
  font-size: 0.9rem;
  color: var(--ink-3);
}

.calendar-card {
  display: grid;
  gap: 10px;
  padding-top: 16px;
  border-top: 1px solid var(--rule);

  p {
    color: var(--ink-2);
  }

  a {
    overflow-wrap: anywhere;
  }
}

.calendar-steps {
  display: grid;
  gap: 6px;
  padding-left: 1.4em;
}

.calendar-tips {
  display: grid;
  gap: 4px;
  padding-left: 1.2em;
  font-size: 0.88rem;
  color: var(--ink-2);
}

.app-foot {
  font-size: 0.85rem;
  text-align: center;
  color: var(--ink-3);
}

.icon-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

@media (max-width: 560px) {
  .cs .table th,
  .cs .table td {
    padding: 7px 8px;
  }

  .cs-step-head {
    gap: 12px;
  }
}
