/**
 * P2 aesthetic batch 05 — Activities list / timeline / calendar modes
 * ---------------------------------------------------------------------------
 * Wire (parent): <link rel='stylesheet' href='/static/p2/05_aes_modes.css'>
 *   after app.css (or @import url('/static/p2/05_aes_modes.css'); at end of app.css).
 * JS: none required — toast/attempt already cover mode mutations; see act_p2_modes.js
 *   header if a future additive hook is needed.
 *
 * Selectors match activities.js: .act-list, .timeline/.tl-*, .act-calendar/*
 * Builds on --act-* / --skin-grid-* from app.css; KS-better, not a third aesthetic.
 *
 * Component-spec tokens (AXS-0775 / 0791 / 0807) — default states:
 *   list:     --act-list-row-h, --act-list-pad-x, --act-list-title-sticky-bg, …
 *   timeline: --act-tl-row-h, --act-tl-label-w, --act-tl-track-min, …
 *   calendar: --act-cal-cell-min, --act-cal-gap, --act-cal-chip-*, …
 */

/* -------------------------------------------------------------------------- */
/* Shared mode tokens (default @ ≥1280 KS rhythm; density media refine below) */
/* -------------------------------------------------------------------------- */
:root {
  /* List — row rhythm ≈ skin grid (±2px of KS list denseness @1280) */
  --act-list-row-h: var(--skin-grid-row);
  --act-list-head-h: var(--skin-grid-header-h);
  --act-list-pad-x: var(--skin-grid-pad-x);
  --act-list-gap-y: 0;
  --act-list-title-sticky-bg: var(--panel);
  --act-list-row-hover: var(--row-hover, var(--bg-2));
  --act-list-group-bg: var(--bg-2);
  --act-list-focus-ring: color-mix(in srgb, var(--accent) 65%, transparent);

  /* Timeline */
  --act-tl-row-h: var(--act-ctl-h);
  --act-tl-label-w: var(--act-tl-label-min, 13.75rem);
  --act-tl-track-min: 12rem;
  --act-tl-pad-y: var(--act-space-1);
  --act-tl-pad-x: var(--act-space-2);
  --act-tl-hover: var(--bg-2);
  --act-tl-focus-ring: color-mix(in srgb, var(--accent) 65%, transparent);

  /* Calendar — already tokenized in app.css; alias for component-spec docs */
  --act-cal-focus-ring: color-mix(in srgb, var(--accent) 65%, transparent);
  --act-cal-chip-hover-line: var(--accent);
  --act-cal-today-ink: var(--accent);
}

/* Calm density @1600 (AXS-0472 / 0473 / 0474) */
@media (min-width: 1600px) {
  :root {
    --act-list-row-h: calc(var(--skin-grid-row) + 0.2rem);
    --act-list-pad-x: calc(var(--skin-grid-pad-x) + 0.1rem);
    --act-tl-row-h: calc(var(--act-ctl-h) + 0.2rem);
    --act-tl-pad-y: var(--act-space-2);
    --act-tl-label-w: max(var(--act-tl-label-min, 13.75rem), 15rem);
    --act-cal-cell-min: 6.25rem;
    --act-cal-gap: 0.75rem;
    --act-cal-cell-pad: 0.35rem;
  }
}

/* Compact density @1100 (AXS-0472 / 0473 / 0474) */
@media (max-width: 1100px) {
  :root {
    --act-list-row-h: calc(var(--skin-grid-row) * 0.96);
    --act-list-pad-x: max(0.35rem, calc(var(--skin-grid-pad-x) * 0.9));
    --act-list-title-min-md: 8.5rem;
    --act-list-table-min-md: 48rem;
    --act-tl-row-h: max(1.75rem, calc(var(--act-ctl-h) * 0.95));
    --act-tl-label-w: min(var(--act-tl-label-min, 13.75rem), 11rem);
    --act-tl-pad-y: 0.2rem;
    --act-tl-pad-x: var(--act-space-1);
    --act-cal-cell-min: 4.75rem;
    --act-cal-gap: 0.45rem;
    --act-cal-cell-pad: 0.2rem;
    --act-cal-chip-fs: 0.7rem;
  }
}

/* Token parity @1280 (AXS-0572 / 0590 / 0608) — lock rhythm to KS 28px control scale */
@media (min-width: 1200px) and (max-width: 1360px) {
  :root {
    --act-list-row-h: 2.24rem; /* ≈36px skin grid */
    --act-list-pad-x: 0.53rem;
    --act-tl-row-h: 1.75rem;   /* --act-ctl-h 28px */
    --act-tl-pad-y: 0.25rem;
    --act-tl-pad-x: 0.5rem;
    --act-cal-gap: 0.625rem;
    --act-cal-cell-gap: 0.25rem;
    --act-cal-cell-min: 5.75rem;
    --act-cal-cell-pad: 0.25rem;
  }
}

/* ========================================================================== */
/* LIST (.act-list) — AXS-0381 journey · 0405 IA · 0429 affordance · …       */
/* ========================================================================== */

/* Journey: scan→open — sticky chrome, clear hover, title stays readable */
.act-list.dt-wrap {
  max-width: 100%;
  min-width: 0;
  /* Contain horizontal scroll inside the wrap (no page scroll) */
  overflow-x: auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}

.act-list table.dt {
  width: 100%;
  border-collapse: separate;
  border-spacing: var(--act-list-gap-y) 0;
}

.act-list table.dt thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  height: var(--act-list-head-h);
  padding-left: var(--act-list-pad-x);
  padding-right: var(--act-list-pad-x);
  background: var(--act-list-title-sticky-bg);
  box-shadow: 0 1px 0 var(--line-2);
  /* Affordance: headers are sort/select, not row-open */
  cursor: default;
  font-weight: var(--act-chrome-w, 560);
  color: var(--ink-2);
}

.act-list table.dt thead th[tabindex],
.act-list table.dt thead th[role='columnheader'][aria-sort] {
  cursor: pointer;
}

.act-list table.dt tbody td {
  height: var(--act-list-row-h);
  padding-left: var(--act-list-pad-x);
  padding-right: var(--act-list-pad-x);
  vertical-align: middle;
}

/* IA: title column sticky so horizontal scan keeps identity first (KS order).
   thead uses .act-title-col; tbody titleCell often omits the class — cover both
   via class and check-col adjacent sibling (title-first column layouts). */
.act-list th.act-title-col,
.act-list td.act-title-col,
.act-list tbody tr:not(.act-group-row) > td.act-check-col + td {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--act-list-title-sticky-bg);
  min-width: var(--act-list-title-min, 20rem);
  font-weight: var(--act-title-w, 650);
  letter-spacing: var(--act-tracking, -0.01em);
  color: var(--ink);
  box-shadow: 1px 0 0 var(--line-2);
}

.act-list thead th.act-title-col {
  z-index: 3;
  left: 0;
}

/* Check column sits before title — keep it sticky too when present */
.act-list th.act-check-col,
.act-list td.act-check-col {
  position: sticky;
  left: 0;
  z-index: 2;
  background: var(--act-list-title-sticky-bg);
  width: 2.5rem;
  min-width: 2.5rem;
  cursor: default;
  box-shadow: none;
}

/* Offset sticky title past the check column */
.act-list thead tr:has(.act-check-col) th.act-title-col,
.act-list tbody tr:not(.act-group-row) > td.act-check-col + td,
.act-list tbody tr:not(.act-group-row) > td.act-check-col + td.act-title-col {
  left: 2.5rem;
}

.act-list .act-check-col input {
  cursor: pointer;
}

/* Affordance: data rows open detail; group rows collapse; never grab (not DnD) */
.act-list tbody tr:not(.act-group-row) {
  cursor: pointer;
}

.act-list tbody tr:not(.act-group-row):hover > td {
  background: var(--act-list-row-hover);
}

.act-list tbody tr:not(.act-group-row):hover .act-title-col,
.act-list tbody tr:not(.act-group-row):hover .act-check-col {
  background: var(--act-list-row-hover);
}

.act-list tbody tr:not(.act-group-row):active {
  transform: scale(var(--act-press-scale, 0.985));
}

.act-list .act-group-row {
  cursor: pointer;
  background: var(--act-list-group-bg);
}

.act-list .act-group-row td {
  font-weight: var(--act-chrome-w, 560);
  cursor: pointer;
  background: var(--act-list-group-bg);
}

/* Interactive controls inside cells keep their own cursor */
.act-list tbody tr a,
.act-list tbody tr button,
.act-list tbody tr select,
.act-list tbody tr .pop,
.act-list tbody tr .inline-assignees,
.act-list tbody tr .inline-status {
  cursor: pointer;
}

.act-list tbody tr input[type='checkbox'] {
  cursor: pointer;
}

/* Meta quieter than title (journey scan) */
.act-list .muted,
.act-list .small {
  color: var(--ink-3);
  font-weight: var(--act-meta-w, 450);
  max-width: var(--act-meta-max, 70ch);
}

.act-list tbody tr:not(.act-group-row):focus-visible,
.act-list .act-group-row:focus-visible {
  outline: 2px solid var(--act-list-focus-ring);
  outline-offset: -2px;
}

/* Empty state inside list wrap — not clickable chrome */
.act-list > .empty {
  cursor: default;
  max-width: 100%;
}

/* ========================================================================== */
/* TIMELINE (.timeline / .tl-*) — AXS-0383 · 0407 · 0431 · …                 */
/* ========================================================================== */

.timeline {
  max-width: 100%;
  min-width: 0;
  overflow: clip;
  background: var(--panel);
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  cursor: default;
}

.tl-row {
  display: flex;
  align-items: stretch;
  min-height: var(--act-tl-row-h);
  border-top: 1px solid var(--line-2);
  cursor: pointer;
  transition: background-color var(--act-motion-d, 160ms) var(--act-motion-ease, ease-out);
}

.tl-row:hover {
  background: var(--act-tl-hover);
}

.tl-row:active {
  transform: scale(var(--act-press-scale, 0.985));
}

.tl-row:focus-visible {
  outline: 2px solid var(--act-tl-focus-ring);
  outline-offset: -2px;
}

/* Head is chrome, not an open target */
.tl-row.tl-head {
  cursor: default;
  border-top: 0;
  font-size: var(--act-chip-fs, 0.75rem);
  color: var(--ink-3);
  font-weight: var(--act-meta-w, 450);
}

.tl-row.tl-head:hover,
.tl-row.tl-head:active {
  background: transparent;
  transform: none;
}

.tl-label {
  padding: var(--act-tl-pad-y) var(--act-tl-pad-x);
  overflow: hidden;
  white-space: normal;
  font-size: var(--act-ctl-fs, 0.875rem);
  font-weight: var(--act-chrome-w, 560);
  color: var(--ink);
  letter-spacing: var(--act-tracking, -0.01em);
  border-right: 1px solid var(--line-2);
  padding-right: 0.85rem;
  min-width: 0;
  display: flex;
  align-items: flex-start;
  gap: 0.375rem;
}

.tl-label .status-text { display: none; }
.tl-label .status { flex-shrink: 0; margin-top: 0.1rem; }

.tl-label a {
  flex: 1;
  min-width: 0;
  overflow: visible;
  text-overflow: unset;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.35;
  color: inherit;
  font-weight: var(--act-title-w, 650);
  text-decoration: none;
  cursor: pointer;
}

.tl-group-row { cursor: pointer; background: var(--bg-2); }
.tl-group-label {
  background: var(--bg-2);
  font-weight: var(--act-chrome-w, 650);
  white-space: normal;
  align-items: center;
  z-index: 4;
}
.tl-group-track { background: var(--bg-2); }

.tl-label a:hover {
  text-decoration: underline;
  color: var(--accent);
}

.tl-track {
  position: relative;
  overflow: visible;
  flex-shrink: 0;
  min-width: 0;
  cursor: inherit;
}

.tl-group {
  padding: var(--act-tl-group-pad-y, 0.375rem) var(--act-tl-group-pad-x, 0.5rem);
  border-top: 1px solid var(--line-2);
  background: var(--bg-2);
  font-weight: var(--act-chrome-w, 560);
  cursor: pointer; /* collapse only */
}

.tl-group:focus-visible {
  outline: 2px solid var(--act-tl-focus-ring);
  outline-offset: -2px;
}

.tl-undated {
  cursor: default;
  pointer-events: none;
}

.tl-bar,
.tl-dot {
  pointer-events: auto; /* hover date tip; click still bubbles to row */
  cursor: default;
}

.tl-month,
.tl-grid,
.tl-today {
  pointer-events: none;
}

/* ========================================================================== */
/* CALENDAR (.act-calendar) — AXS-0385 · 0409 · 0433 · …                     */
/* ========================================================================== */

.act-calendar {
  display: grid;
  gap: var(--act-cal-gap);
  max-width: 100%;
  min-width: 0;
  /* Affordance: grid chrome is not draggable */
  cursor: default;
}

.act-calendar-head {
  gap: var(--act-cal-gap);
  align-items: center;
  flex-wrap: wrap;
  min-width: 0;
}

.act-calendar-head .btn {
  cursor: pointer;
  min-height: var(--act-ctl-h);
}

.act-calendar-dow,
.act-calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: var(--act-cal-cell-gap);
  max-width: 100%;
  min-width: 0;
}

.act-calendar-dow > div {
  text-align: center;
  padding: var(--act-cal-cell-pad);
  cursor: default;
  font-weight: var(--act-meta-w, 450);
  color: var(--ink-3);
}

.act-calendar-cell {
  min-height: var(--act-cal-cell-min);
  min-width: 0;
  border: 1px solid var(--line-2);
  border-radius: var(--radius);
  padding: var(--act-cal-cell-pad);
  background: var(--panel);
  /* Cells are not click targets — chips are */
  cursor: default;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.act-calendar-cell.has-day {
  background: var(--kanban-lane, var(--bg-2));
}

.act-calendar-daynum {
  font-size: var(--act-cal-day-fs);
  font-weight: 650;
  color: var(--ink-3);
  margin-bottom: var(--act-cal-cell-pad);
  font-variant-numeric: tabular-nums;
  cursor: default;
  flex: 0 0 auto;
}

.act-calendar-chip {
  display: block;
  width: 100%;
  max-width: 100%;
  text-align: left;
  border: 0;
  background: var(--panel);
  border-radius: var(--act-type-radius, 0.25rem);
  padding: var(--act-cal-chip-pad-y) var(--act-cal-chip-pad-x);
  margin-bottom: 0;
  font-size: var(--act-cal-chip-fs);
  line-height: 1.25;
  /* Affordance: chips open activities — pointer, never grab */
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  box-shadow: inset 0 0 0 1px var(--line);
  color: var(--ink);
  font-weight: var(--act-title-w, 650);
  letter-spacing: var(--act-tracking, -0.01em);
  transition:
    color var(--act-motion-d, 160ms) var(--act-motion-ease, ease-out),
    box-shadow var(--act-motion-d, 160ms) var(--act-motion-ease, ease-out),
    background-color var(--act-motion-d, 160ms) var(--act-motion-ease, ease-out);
}

.act-calendar-chip:hover {
  box-shadow: inset 0 0 0 1px var(--act-cal-chip-hover-line);
  color: var(--accent);
}

.act-calendar-chip:focus-visible {
  outline: 2px solid var(--act-cal-focus-ring);
  outline-offset: 1px;
}

.act-calendar-chip:active {
  transform: scale(var(--act-press-scale, 0.985));
}

.act-calendar-cell > .muted.small {
  cursor: default;
  flex: 0 0 auto;
}

/* ========================================================================== */
/* Error recovery — toast stays above mode surfaces (AXS-0453 / 0455 / 0457) */
/* Inline list mutations + bulk already use attempt()→toast; elevate stacking */
/* ========================================================================== */

body:has(.act-list) .toast,
body:has(.timeline) .toast,
body:has(.act-calendar) .toast {
  z-index: 2600;
  max-width: min(520px, calc(100vw - 1rem));
}

body:has(.act-list) .toast.err,
body:has(.timeline) .toast.err,
body:has(.act-calendar) .toast.err {
  /* Error toasts slightly longer-lived visually via weight */
  font-weight: 560;
}

body:has(.act-list) .toast .toast-action,
body:has(.timeline) .toast .toast-action,
body:has(.act-calendar) .toast .toast-action {
  cursor: pointer;
  flex: 0 0 auto;
}

/* Modes must not create containing blocks that clip fixed toasts */
.act-list,
.timeline,
.act-calendar {
  transform: none;
  filter: none;
  perspective: none;
}

/* ========================================================================== */
/* State-matrix + responsive @375 — no clip/overlap / no page x-scroll       */
/* AXS-1007 / 1031 / 1055 / 1391 / 1403 / 1415                               */
/* ========================================================================== */

@media (max-width: 375px) {
  .page:has(.act-list),
  .page:has(.timeline),
  .page:has(.act-calendar) {
    overflow-x: clip;
    max-width: 100vw;
  }

  .act-list.dt-wrap {
    max-width: 100%;
    width: 100%;
    overflow-x: auto;
  }

  .act-list table.dt {
    /* Keep columns reachable via wrap scroll, not page scroll */
    min-width: min(var(--act-list-table-min-md, 48rem), 200vw);
    width: max-content;
    max-width: none;
  }

  .act-list .act-title-col {
    min-width: min(var(--act-list-title-min-md, 8.5rem), 40vw);
    max-width: 55vw;
  }

  .act-list th.act-check-col,
  .act-list td.act-check-col {
    width: 2rem;
    min-width: 2rem;
  }

  .act-list thead tr:has(.act-check-col) th.act-title-col,
  .act-list tbody tr:has(.act-check-col) td.act-title-col,
  .act-list tbody tr:has(.act-check-col) td:nth-child(2) {
    left: 2rem;
  }

  .timeline {
    max-width: 100%;
    width: 100%;
    overflow: clip;
  }

  .tl-row {
    min-height: max(var(--act-target-min, 1.5rem), 2rem);
  }

  .tl-label {
    padding: 0.2rem 0.35rem;
    font-size: 0.8rem;
  }

  .act-calendar {
    width: 100%;
    max-width: 100%;
    gap: var(--act-space-1);
  }

  .act-calendar-head {
    gap: var(--act-space-1);
  }

  .act-calendar-head b {
    font-size: 0.95rem;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .act-calendar-cell {
    min-height: 3.5rem;
    padding: 0.15rem;
    border-radius: calc(var(--radius) - 1px);
  }

  .act-calendar-daynum {
    font-size: 0.65rem;
    margin-bottom: 0.1rem;
  }

  .act-calendar-chip {
    font-size: 0.65rem;
    padding: 0.05rem 0.2rem;
  }

  /* Avoid chip text overflowing cell bounds */
  .act-calendar-chip,
  .act-calendar-cell > .muted {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

/* Narrow but >375: still contain page scroll (phones ~390–430) */
@media (max-width: 480px) {
  .act-list.dt-wrap,
  .timeline,
  .act-calendar {
    max-width: 100%;
    min-width: 0;
  }

  .page:has(.act-list) > *:not(.activity-detail-drawer),
  .page:has(.timeline) > *:not(.activity-detail-drawer),
  .page:has(.act-calendar) > *:not(.activity-detail-drawer) {
    max-width: 100%;
    min-width: 0;
  }
}

/* ========================================================================== */
/* Reduced motion                                                             */
/* ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  .act-list tbody tr:not(.act-group-row),
  .tl-row,
  .act-calendar-chip {
    transition: none !important;
  }

  .act-list tbody tr:not(.act-group-row):active,
  .tl-row:active,
  .act-calendar-chip:active {
    transform: none !important;
  }
}

/* ========================================================================== */
/* Reference-diff helpers @1280 (AXS-1208 / 1214 / 1220)                       */
/* Visual rhythm locks for side-by-side KS scrape comparison                  */
/* ========================================================================== */
@media (min-width: 1260px) and (max-width: 1300px) {
  .act-list table.dt thead th {
    height: 1.88rem; /* --skin-grid-header-h */
  }

  .act-list table.dt tbody td {
    height: 2.24rem; /* --skin-grid-row */
  }

  .tl-row {
    min-height: 28px; /* KS tool height lock */
  }

  .act-calendar-cell {
    min-height: 5.75rem;
  }

  .act-calendar-chip {
    font-size: 0.75rem;
  }
}
