/* TidyPlan: page styles on top of the shared Tidy design system (tidy-core.css, design system v2).
   One suite, one teal (tidy-nest #326): every colour is a tidy-core token; TidyPlan has none of its own. */

/* Headings in Fraunces (the design system's display face); everything else reads in Atkinson
   Hyperlegible, which tidy-core.css sets on the body. */
h1, h2 { font-family: var(--font-display); font-weight: 600; letter-spacing: -0.01em; }
/* Tidy icons (#326): line icons that take the text colour. They sit beside a word. */
.tidy-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.ti { width: 1.15em; height: 1.15em; vertical-align: -0.2em; flex-shrink: 0; }

/* A class that sets display (a pill button, a panel) never shows what the page has hidden. */
[hidden] { display: none !important; }

body { padding-bottom: 0; }
main { flex: 1; }
.muted { color: var(--text-muted); }
.small { font-size: 0.875rem; }
.nowrap { white-space: nowrap; }
.spacer { flex: 1; }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: 1rem; top: -3rem; z-index: 10002;
  background: var(--surface); color: var(--primary); padding: 0.5rem 1rem;
  border: 2px solid var(--primary); border-radius: var(--radius-sm); font-weight: 700;
}
.skip-link:focus { top: 1rem; }
/* Focus: tidy-core.css draws the 2px focus ring on everything people can reach. */

/* ---------------------------------------------------------------- header */
/* v1's .tidy-nav (a hairline under the bar), on the paper. v2 gives .tidy-nav to the phone tab bar.
   The page's tools only: the dock's top bar holds the logo, and there is no brand link here (#1135). */
.plan-header { background: var(--bg); border-bottom: 1px solid var(--border); }
.plan-header-row {
  display: flex; align-items: center; justify-content: flex-end;
  gap: 1rem; flex-wrap: wrap; padding-top: 0.75rem; padding-bottom: 0.75rem;
}
.plan-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.count-pill {
  display: inline-block; min-width: 1.6em; padding: 0 0.45em;
  border-radius: var(--radius-full); background: var(--surface-subtle);
  color: var(--text-body); font-family: var(--font-sans); font-size: 0.8125rem; line-height: 1.5;
  font-weight: 700; text-align: center;
}

.plan-summary { padding-top: 1.75rem; padding-bottom: 1rem; }
.plan-type { color: var(--text-muted); font-weight: 700; font-size: 1rem; }
.plan-title { font-size: clamp(1.75rem, 4vw, 2.25rem); line-height: 1.2; margin-top: 0.25rem; overflow-wrap: anywhere; }
.plan-meta { color: var(--text-body); margin-top: 0.35rem; }
.plan-archived-note {
  margin-top: 0.75rem; padding: 0.6rem 0.9rem; border-radius: var(--radius-sm);
  background: var(--surface-subtle); color: var(--text-body); font-weight: 700;
}
.plan-archived-note .ti { margin-right: 0.4rem; }

/* ---------------------------------------------------------------- tabs */
/* The current view: a teal wash and a bead, as the Tidy subnav has it. The strip scrolls, so it
   clips at its padding: 4px all round leaves room for the focus ring (2px, 2px out) on the end tabs. */
.plan-tabs {
  display: flex; gap: 0.25rem; overflow-x: auto; padding: 4px 4px 0.5rem; scroll-padding-inline: 4px;
  border-bottom: 1px solid var(--border); margin-bottom: 1.25rem; scrollbar-width: thin;
}
.plan-tabs [role=tab] {
  position: relative; flex-shrink: 0; display: inline-flex; align-items: center;
  min-height: var(--touch-min); padding: 0 1rem; border: 0; border-radius: var(--radius-full);
  background: none; color: var(--text-muted); font-weight: 700; cursor: pointer; white-space: nowrap;
}
.plan-tabs [role=tab]:hover { color: var(--text-main); }
.plan-tabs [role=tab][aria-selected=true] { background: var(--primary-light); color: var(--text-main); }
.plan-tabs [role=tab][aria-selected=true]::after {
  content: ""; position: absolute; left: 50%; bottom: 5px; width: 6px; height: 6px; margin-left: -3px;
  border-radius: var(--radius-full); background: var(--primary);
}
.plan-view { padding-bottom: 3rem; }

.view-tools { display: flex; gap: 0.5rem; justify-content: flex-end; flex-wrap: wrap; margin-bottom: 1rem; }

/* ---------------------------------------------------------------- overview */
/* Figures rest on the paper under a hairline, not in raised tiles. */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0 1.25rem; margin-bottom: 1.25rem; }
.stat { padding: 0.75rem 0; border-top: 1px solid var(--border); display: flex; flex-direction: column; }
.stat-label { font-size: 1rem; font-weight: 700; color: var(--text-muted); }
.stat-value { font-size: 1.75rem; font-weight: 700; color: var(--text-main); line-height: 1.25; font-variant-numeric: tabular-nums; }
.stat-value.warn { color: var(--accent-dark); }
.stat-sub { font-size: 0.875rem; color: var(--text-muted); }
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 1.1rem 1.25rem; margin-bottom: 1rem;
}
.card-title { display: flex; align-items: center; gap: 0.5rem; font-size: 1.25rem; line-height: 1.3; margin-bottom: 0.5rem; }
.card-sub { font-size: 1rem; margin: 1rem 0 0.4rem; }
/* The schedule check: the words say it; the icon and the waiting wash only add to them. */
.card-ok .card-title .ti { color: var(--primary); }
.card-warn { background: var(--accent-light); border-color: var(--accent-light); }
.card-warn .card-title .ti { color: var(--accent-dark); }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(300px, 100%), 1fr)); gap: 1rem; }
.plain-list { list-style: none; display: flex; flex-direction: column; gap: 0.6rem; }
.issue-list { list-style: disc; padding-left: 1.25rem; }
.issue-list li + li { margin-top: 0.6rem; }
.sev {
  font-size: 0.8125rem; font-weight: 700; padding: 0.05em 0.6em; border-radius: var(--radius-full);
  background: var(--surface-subtle); color: var(--text-body); white-space: nowrap;
}
.risk-high .sev { background: var(--accent-light); color: var(--accent-dark); }
.check-row { display: flex; gap: 0.6rem; align-items: flex-start; cursor: pointer; }
.check-row input { margin-top: 0.3rem; width: 1.15rem; height: 1.15rem; accent-color: var(--primary); flex: none; }

/* A milestone's status: not started is recessed, in progress a teal wash, done solid teal with a tick. */
.status {
  display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.8125rem; font-weight: 700;
  padding: 0.1em 0.6em; border-radius: var(--radius-full); white-space: nowrap;
}
.status.todo { background: var(--surface-subtle); color: var(--text-body); }
.status.doing { background: var(--primary-light); color: var(--text-main); }
.status.done { background: var(--primary); color: var(--on-action); }

.link-btn {
  position: relative; background: none; border: 0; padding: 0.2rem 0.1rem; color: var(--primary);
  font-weight: 700; cursor: pointer; text-decoration: underline; text-underline-offset: 3px;
}
/* The tap target is touch-min (48px) tall and at least as wide, round the word, as tidy-core's
   .tidy-switch does it, so a table row with a text link stays as tall as its words. */
.link-btn::after {
  content: ""; position: absolute;
  top: calc(50% - var(--touch-min) / 2); bottom: calc(50% - var(--touch-min) / 2);
  left: min(0px, calc(50% - var(--touch-min) / 2)); right: min(0px, calc(50% - var(--touch-min) / 2));
}
.link-btn:hover { color: var(--primary-dark); }
.link-btn.danger, .tidy-btn--quiet.danger { color: var(--danger-ink); }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
  width: var(--touch-min); height: var(--touch-min); padding: 0; margin-right: -0.5rem;
  background: none; border: 0; border-radius: var(--radius-full);
  font-size: 1.15rem; color: var(--text-muted); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-subtle); color: var(--text-main); }

/* ---------------------------------------------------------------- timeline */
.timeline { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 0.75rem; overflow-x: auto; }
.tl-row, .tl-track { display: grid; grid-template-columns: 9rem minmax(560px, 1fr); gap: 0.75rem; align-items: start; }
.tl-track { padding: 0.5rem 0; border-top: 1px solid var(--border); }
.tl-label { font-weight: 700; font-size: 0.875rem; color: var(--text-body); padding-top: 0.35rem; }
.tl-lane-list { list-style: none; display: flex; flex-direction: column; gap: 0.35rem; }
.tl-lane { position: relative; height: 2rem; }
.tl-phases .tl-lane { height: 1.9rem; }
/* Phases sit side by side; the clear right edge leaves a gap between neighbours. */
.tl-phase {
  position: absolute; top: 0; bottom: 0; box-sizing: border-box;
  background: var(--surface-subtle); background-clip: padding-box; color: var(--text-body);
  border-right: 2px solid transparent; border-radius: var(--radius-xs);
  font-size: 0.8125rem; font-weight: 700; padding: 0.35rem 0.5rem;
  overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.tl-bar {
  position: absolute; top: 0.15rem; height: 1.7rem; border: 1px solid var(--border-control); border-radius: var(--radius-full);
  padding: 0 0.6rem; font-size: 0.8125rem; font-weight: 700; text-align: left;
  overflow: hidden; white-space: nowrap; cursor: pointer; min-width: 0.6rem;
}
.tl-bar span { display: block; overflow: hidden; text-overflow: ellipsis; }
.tl-bar.todo { background: var(--surface-subtle); color: var(--text-main); }
/* The state is not in the colour alone: in progress has a 2px edge (not started 1px), done a tick,
   and the sentence above the timeline says so in words. */
.tl-bar.doing { background: var(--primary-light); color: var(--text-main); border-color: var(--primary); border-width: 2px; }
.tl-bar.done { background: var(--primary); color: var(--on-action); border-color: var(--primary); }
.tl-bar .ti { margin-right: 0.25rem; }
.tl-bar:disabled { cursor: default; }
/* A checkpoint is a bead on its lane: open until it's passed, then filled. */
.tl-gate {
  position: absolute; top: 0.5rem; width: 0.95rem; height: 0.95rem; margin-left: -0.475rem; box-sizing: border-box;
  border-radius: var(--radius-full); background: var(--surface); border: 2px solid var(--primary);
}
.tl-gate.met { background: var(--primary); }
.tl-gate-label { position: absolute; top: 0.3rem; margin-left: 0.9rem; font-size: 0.8125rem; color: var(--text-body); white-space: nowrap; }
.tl-today { position: absolute; top: -0.2rem; bottom: -0.2rem; width: 2px; margin-left: -1px; background: var(--text-main); pointer-events: none; }
.tl-bar.short { overflow: visible; padding: 0; }
.tl-bar.short span {
  position: absolute; left: calc(100% + 0.4rem); top: 0; line-height: 1.7rem;
  color: var(--text-main); max-width: 16rem; text-overflow: ellipsis; overflow: hidden;
}
.tl-bar.short-left span { left: auto; right: calc(100% + 0.4rem); text-align: right; }

/* ---------------------------------------------------------------- board */
.board { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr)); gap: 1rem; }
.board-col { background: var(--surface-subtle); border-radius: var(--radius-md); padding: 0.85rem; }
.board-col > .board-list > .muted { color: var(--text-body); }
.board-head { display: flex; align-items: center; gap: 0.5rem; font-size: 1.15rem; margin-bottom: 0.6rem; }
.board-list { list-style: none; display: flex; flex-direction: column; gap: 0.6rem; }
.board-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 0.75rem; }
.board-title { font-weight: 700; overflow-wrap: anywhere; }
.board-actions { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; margin-top: 0.5rem; }

/* ---------------------------------------------------------------- table */
/* Positioned, so the table's hidden labels (.sr-only) scroll inside it, not the page sideways at 375px. */
.table-wrap { position: relative; overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); }
.plan-table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.plan-table th, .plan-table td { text-align: left; padding: 0.65rem 0.85rem; border-bottom: 1px solid var(--border); vertical-align: top; }
.plan-table thead th { font-size: 0.875rem; color: var(--text-body); background: var(--surface-subtle); }
.plan-table tbody th { font-weight: 700; }

/* ---------------------------------------------------------------- assistant */
.assistant {
  /* A sheet over the page: over the dock bar (9999, earlier in the page), under the dock's own dialogs (10000). */
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 9999; width: min(420px, 100vw);
  background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow-md);
  display: flex; flex-direction: column;
}
.assistant-head { display: flex; align-items: center; justify-content: space-between; padding: 0.75rem 1rem; border-bottom: 1px solid var(--border); }
.assistant-head h2 { font-size: 1.25rem; }
.assistant-body { flex: 1; overflow-y: auto; padding: 1rem; }
.assistant-gate { background: var(--primary-light); color: var(--text-main); border-radius: var(--radius-sm); padding: 1rem; display: flex; flex-direction: column; gap: 0.75rem; margin-bottom: 1rem; }
.assistant-log { list-style: none; display: flex; flex-direction: column; gap: 0.6rem; }
.msg { max-width: 90%; padding: 0.6rem 0.85rem; border-radius: var(--radius-sm); white-space: pre-wrap; overflow-wrap: anywhere; font-size: 0.95rem; }
.msg-agent { align-self: flex-start; background: var(--surface-subtle); color: var(--text-main); }
/* Teal is 4.37:1 on the bubble's surface-subtle; the dark teal is 7.5:1. */
.msg-agent .link-btn { color: var(--primary-dark); }
.msg-user { align-self: flex-end; background: var(--primary-light); color: var(--text-main); }
.msg.pending { color: var(--text-muted); font-style: italic; }
.msg.error { background: var(--danger-light); color: var(--danger-ink); }
.suggestion { display: flex; flex-direction: column; gap: 0.35rem; white-space: normal; }
.suggestion-actions { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; margin-top: 0.25rem; }
.assistant-form { border-top: 1px solid var(--border); padding: 0.75rem 1rem 1rem; display: flex; flex-direction: column; gap: 0.5rem; }
.quick-prompts { display: flex; gap: 0.4rem; flex-wrap: wrap; }
.assistant-input-row { display: flex; gap: 0.5rem; align-items: flex-end; }
.assistant-input-row textarea {
  flex: 1; min-width: 0; resize: vertical; min-height: var(--touch-min); max-height: 10rem; padding: 0.55rem 0.75rem;
  border: 1.5px solid var(--border-control); border-radius: var(--radius-sm); background: var(--surface); color: var(--text-main);
}
.fine-print { font-size: 0.875rem; color: var(--text-muted); }

/* ---------------------------------------------------------------- dialogs */
/* margin: auto puts a modal back in the middle of the screen (tidy-core.css zeroes every margin). */
dialog {
  margin: auto; border: 0; padding: 0; border-radius: var(--radius-md); box-shadow: var(--shadow-lg);
  width: min(540px, calc(100vw - 2rem)); max-height: calc(100vh - 2rem); color: var(--text-main); background: var(--surface);
}
dialog::backdrop { background: rgba(20, 33, 31, 0.45); }
.dialog-box { padding: 1.25rem 1.4rem; display: flex; flex-direction: column; gap: 0.75rem; }
dialog:has(.dialog-wide) { width: min(700px, calc(100vw - 2rem)); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.dialog-head h2, #confirm-title { font-size: 1.35rem; }
.dialog-foot { display: flex; gap: 0.5rem; justify-content: flex-end; align-items: center; flex-wrap: wrap; margin-top: 0.5rem; }
.field { display: flex; flex-direction: column; gap: 0.3rem; border: 0; }
.field label, .field legend { font-size: 1rem; font-weight: 700; color: var(--text-main); }
.field input, .field select, .field textarea {
  padding: 0.55rem 0.75rem; border: 1.5px solid var(--border-control); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text-main);
}
.field input:not([type=checkbox]), .field select { min-height: var(--touch-min); }
.field input:focus-visible, .field select:focus-visible, .field textarea:focus-visible,
.assistant-input-row textarea:focus-visible { border-color: var(--border-focus); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.dep-list { display: flex; flex-direction: column; gap: 0.3rem; max-height: 10rem; overflow-y: auto; padding: 0.25rem 0; }
.form-error { color: var(--danger-ink); font-weight: 700; }
.template-list { display: flex; flex-direction: column; gap: 0.6rem; }
.template-card {
  display: flex; flex-direction: column; gap: 0.2rem; text-align: left; cursor: pointer;
  background: var(--surface); color: var(--text-main); border: 1.5px solid var(--border-control);
  border-radius: var(--radius-sm); padding: 0.85rem 1rem;
}
.template-card:hover { background: var(--surface-subtle); }
.list-heading { font-size: 1rem; color: var(--text-muted); margin-top: 0.5rem; }
.plan-list { list-style: none; display: flex; flex-direction: column; gap: 0.5rem; }
.plan-row {
  display: flex; justify-content: space-between; gap: 1rem; align-items: center; flex-wrap: wrap;
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 0.7rem 0.85rem;
}
.plan-row.current { border-color: var(--primary); background: var(--primary-light); }
.row-actions { display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; }
.file-btn { position: relative; overflow: hidden; cursor: pointer; }
.file-btn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.file-btn:focus-within { outline: 2px solid var(--focus-ring); outline-offset: 2px; }

/* ---------------------------------------------------------------- toast, footer */
.toast {
  position: fixed; left: 50%; bottom: 1.25rem; transform: translateX(-50%); z-index: 10001;
  background: var(--field); color: var(--on-field); padding: 0.6rem 1.1rem; border-radius: var(--radius-full);
  font-weight: 700; font-size: 0.95rem; box-shadow: var(--shadow-md); max-width: calc(100vw - 2rem);
}
/* One navigation (tidy-nest #1135): with the dock's place bar the toast sits above the bottom bar below
   1024px and beside the 248px rail from 1024px. The assistant's sheet (9999) and the dialogs (top layer)
   are over the bar (9998). */
html.tidy-has-place-bar .toast { bottom: calc(64px + env(safe-area-inset-bottom) + 1rem); }
@media (min-width: 1024px) {
  html.tidy-has-place-bar .toast { bottom: 1.25rem; left: calc(50% + 124px); max-width: calc(100vw - 248px - 2rem); }
}
.plan-footer { margin-top: auto; padding: 0; }
.plan-footer-row { display: flex; gap: 1rem 2rem; flex-wrap: wrap; align-items: center; justify-content: space-between; padding-top: 1.25rem; padding-bottom: 1.25rem; font-size: 0.875rem; color: var(--text-muted); }
.plan-footer nav { display: flex; gap: 1rem; }
.plan-footer a { text-decoration: underline; text-underline-offset: 3px; color: var(--primary); }

.not-found { padding-top: 4rem; padding-bottom: 4rem; display: flex; flex-direction: column; gap: 0.75rem; }

@media (max-width: 640px) {
  /* Body text is 16px on phones; body-sm (14px) is for secondary lines from 640px up. */
  .small, .fine-print { font-size: 1rem; }
  .tl-row, .tl-track { grid-template-columns: 6rem minmax(480px, 1fr); }
  .field-row { grid-template-columns: 1fr; }
  .plan-actions .tidy-btn { flex: 1 1 auto; }
}

/* Under reduce motion nothing moves. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
  .tidy-btn:active { transform: none !important; }
}

@media print {
  #tidy-verse-dock, .plan-header, .plan-tabs, .view-tools, .assistant, .toast, .plan-footer, .board-actions, .link-btn { display: none !important; }
  .card, .stat, .timeline, .table-wrap { break-inside: avoid; }
}
