/* Project Manager UI. No external fonts or assets — the CSP is default-src 'self', and the
   service must work on a VPS with no outbound network access. */

/* `color-scheme` is what makes the browser's *own* surfaces follow the theme:
   the date field's picker icon, the <select> popup, scrollbars, and the default
   rendering of controls this file does not style. Without it the dark theme gets
   light UA defaults inside a dark page — a black calendar icon on a near-black
   field. */
:root {
  color-scheme: light dark;

  --bg: #f6f7f9;
  --surface: #ffffff;

  /* Two border tokens, because they answer different questions. `--border`
     separates containers, where it only has to be visible. `--border-strong`
     draws the boundary of a control, where WCAG 1.4.11 wants 3:1 against the
     adjacent surface — and for a field whose own fill matches the card behind
     it, that line is the only thing identifying the control. */
  --border: #dfe3e8;
  --border-strong: #868e98;

  --text: #1c2024;
  --muted: #646c78;

  --accent: #2f6feb;
  --accent-hover: #2560d4;
  /* The accent as *text*, which needs more headroom than the accent as a fill or
     a border. Tinted from the accent hue rather than greyed. */
  --accent-strong: #1c56c9;
  --accent-soft: #e8f0fe;
  --on-accent: #ffffff;

  --danger: #c0392b;
  --ok: #178244;
  --warn: #a16309;

  --radius: 8px;
  --gap: 16px;
  /* A readable line length for prose. The main column is wide enough at desktop
     sizes for an unconstrained paragraph to run far past it. */
  --measure: 72ch;
  /* One duration for every state change, so hover and focus read as one
     interface rather than several. */
  --speed: 150ms;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171a;
    --surface: #1c2024;
    --border: #2e343b;
    --border-strong: #656b72;
    --text: #e8eaed;
    --muted: #9aa3ad;
    --accent: #6ea8fe;
    --accent-hover: #8bbcff;
    --accent-strong: #6ea8fe;
    --accent-soft: #1e2a3d;
    /* Near-black, not white. The dark accent is a light blue, so white on it
       measures 2.42:1 — the primary button was the least readable control on
       the page. */
    --on-accent: #0d1116;
    --danger: #f0776a;
    --ok: #57c98a;
    --warn: #e0b054;
  }
}

* { box-sizing: border-box; }

/* Text selection and the caret are browser surfaces this design does not draw.
   Left alone they belong to no palette. */
::selection { background: var(--accent); color: var(--on-accent); }

/* The `hidden` attribute is how app.js swaps views (showLogin / showApp), and
   how every disclosure in this UI opens and closes.

   It needs `!important` because a rule in *this* file that sets `display` beats
   the UA stylesheet's `[hidden] { display: none }` — any author rule outranks
   any UA rule, whatever the specificity. `.login` and `.layout` are both
   `display: grid`, so without this line the `hidden` attribute did nothing to
   either view: a successful sign-in flipped a property with no visual effect
   and left the sign-in card on screen, and the app shell rendered while signed
   out. */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 8px; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }

.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* Prose keeps a readable measure; the row that holds it still spans the column. */
#project-desc, .task-details, .entry-text { max-width: var(--measure); }

/* Keyboard focus, including for keyboard-only users, on the palette's accent
   rather than the browser's default ring. The reference at /docs carries the
   same rule in docs.css. */
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--surface);
  color: var(--text);
  padding: 8px 12px;
  border-radius: var(--radius);
  z-index: 10;
}
.skip-link:focus { left: 8px; top: 8px; }

/* --------------------------------------------------------------- controls */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: .875rem;
  text-decoration: none;
  cursor: pointer;
  transition: border-color var(--speed) ease, background-color var(--speed) ease,
              color var(--speed) ease;
}
.btn:hover { border-color: var(--accent); }
.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}
/* An explicit hover colour rather than `filter: brightness()`. A filter is opaque
   to contrast tooling, and it pushed this button further below AA in both themes:
   4.57:1 -> 3.99:1 in light, 2.42:1 -> 2.13:1 in dark. */
.btn--primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}
.btn--ghost { background: transparent; }
/* No `border-color` override: `.btn` already carries `--border-strong`, which is
   what keeps this control's boundary above 3:1. The destructive signal is the
   text colour. */
.btn--danger { color: var(--danger); }
.btn--danger:hover { border-color: var(--danger); }
.btn[disabled] { opacity: .5; cursor: default; }

input, textarea, select {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  caret-color: var(--accent);
  transition: border-color var(--speed) ease;
}

/* Three intrinsic heights, deliberately left alone: the text input computes to
   38.5px, the select to 36px and the date input to 40.5px. A select with
   `appearance: auto` discards `line-height` (set it and the computed value stays
   `normal`), so the only ways to force a match are a magic pixel `min-height` or
   `appearance: none` with a hand-drawn chevron. Neither is worth it here: the
   composer lays these out in separate rows of a stacked grid, so they are never
   adjacent and there is no optical misalignment to see. Aligning them would cost
   a brittle constant to fix a difference nothing renders side by side. */

/* Native form controls follow `accent-color` for their filled parts. Left at
   `auto`, the range input was the only control on the page not drawn from the
   palette — a navy thumb in light mode, a default blue fill in dark. */
input[type="range"] { accent-color: var(--accent); }
label { display: block; font-size: .8rem; color: var(--muted); margin-bottom: 4px; }

.error {
  color: var(--danger);
  font-size: .85rem;
  margin: 8px 0 0;
}

.pill {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: .8rem;
  font-variant-numeric: tabular-nums;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin: 0 0 var(--gap);
}
.card-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }

/* Collapsible "New task" composer.

   Native <details>/<summary> rather than a button toggling `hidden`: the browser
   supplies the disclosure role, keyboard operation and aria-expanded for free,
   and there is no second copy of the state for app.js to drift out of step with.

   Hiding is done by `content-visibility`, not `display`, so an author `display`
   declaration on the child cannot defeat it — checked by screenshot in both
   Chrome and Firefox before relying on it, because that is exactly how the
   `hidden` attribute broke in T-017.

   For the same reason, do not test this with getBoundingClientRect(): a closed
   <details> still reports a size for its contents. Element.checkVisibility() is
   the predicate that reflects what was painted. */
/* The minimum is 24x24 CSS px (WCAG 2.5.8). The content is 12.8px text at
   line-height 1.5, so 2px of padding left this at 23px — under the floor, on the
   only control that opens the composer. */
#task-compose > summary {
  cursor: pointer;
  user-select: none;
  list-style-position: inside;
  padding: 4px 0;
  border-radius: var(--radius);
}
#task-compose > summary::marker { color: var(--muted); }
#task-compose > summary:hover { color: var(--text); }
#task-compose > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#task-compose[open] > summary { margin-bottom: 10px; }
#task-compose > form { padding-top: 2px; }
.row { display: flex; gap: 8px; align-items: flex-start; }

/* ------------------------------------------------------------------ login */

.login {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: var(--gap);
}
.login-card {
  width: min(360px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}
.login-title { font-size: 1.6rem; letter-spacing: -.02em; }
.login-card .btn { width: 100%; justify-content: center; margin-top: 14px; }

/* ----------------------------------------------------------------- layout */

.layout {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  grid-template-areas: "top top" "side main";
  min-height: 100%;
  gap: var(--gap);
  padding: var(--gap);
}

.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  flex-wrap: wrap;
}
.brand { font-weight: 650; letter-spacing: -.02em; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.exports { display: flex; flex-wrap: wrap; gap: 6px; }
/* Keep each button's label on one line; the group wraps between buttons instead. */
.exports .btn { white-space: nowrap; }

.conn { font-size: .8rem; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--border); }
.conn--live { color: var(--ok); border-color: var(--ok); }
.conn--off { color: var(--warn); border-color: var(--warn); }

.sidebar { grid-area: side; min-width: 0; }
.main { grid-area: main; min-width: 0; }

/* --------------------------------------------------------------- projects */

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

.project-button {
  width: 100%;
  display: grid;
  gap: 6px;
  padding: 9px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color var(--speed) ease, background-color var(--speed) ease;
}
.project-button:hover { border-color: var(--accent); }
.project-button[aria-current="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.project-row { display: flex; justify-content: space-between; gap: 8px; }
.project-name { overflow-wrap: anywhere; }
.project-pct { color: var(--muted); font-variant-numeric: tabular-nums; }

/* Native <progress>, restyled. Chosen over a div whose width is set from
   JavaScript because it needs no inline style: the value is an attribute, so the
   page contains no style attributes for a CSP to have an opinion about — and it
   carries a real progressbar role for assistive technology. */
.project-bar, .progress {
  display: block;
  width: 100%;
  height: 6px;
  border: 0;
  border-radius: 999px;
  background: var(--border);
  overflow: hidden;
  appearance: none;
  -webkit-appearance: none;
}
.progress { height: 10px; margin-bottom: var(--gap); }

/* WebKit draws the track and the value as pseudo-elements; Firefox draws the
   value as ::-moz-progress-bar over the element's own background. */
.project-bar::-webkit-progress-bar, .progress::-webkit-progress-bar {
  background: var(--border);
  border-radius: 999px;
}
.project-bar::-webkit-progress-value, .progress::-webkit-progress-value {
  background: var(--accent);
  border-radius: 999px;
  transition: width var(--speed) ease; /* impeccable-disable-line layout-transition */
}
.project-bar::-moz-progress-bar, .progress::-moz-progress-bar {
  background: var(--accent);
  border-radius: 999px;
  transition: width var(--speed) ease; /* impeccable-disable-line layout-transition */
}
/* The two lines above are a deliberate exception, recorded rather than left for
   the detector to re-report. `transform: scaleX()` is the usual advice for
   animating a width, and it does not apply here: <progress> paints its value in
   a UA-drawn pseudo-element that has no independent box, scaleX would stretch
   the fill's border radius with it, and the element is 6px tall in a column it
   already spans, so the layout it invalidates is one box. */

/* ------------------------------------------------------------------ panel */

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--gap);
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.panel-head-text { min-width: 0; }
.panel-head-actions { display: flex; align-items: center; gap: 8px; }
.section-title { margin: 20px 0 8px; }

.field-grid {
  display: grid;
  grid-template-columns: 90px minmax(0, 1fr);
  gap: 8px 10px;
  align-items: center;
  margin-bottom: 12px;
}
.field-grid label { margin: 0; }

.empty {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  color: var(--muted);
}

/* `aria-busy` is set by app.js only when a project switch is slow enough to
   notice, so a fast local round-trip does not flash. It also tells assistive
   technology to wait for the region to settle before announcing it. */
#project-panel { transition: opacity var(--speed) ease; }
#project-panel[aria-busy="true"] { opacity: .55; }

/* ------------------------------------------------------------------ tasks */

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

.task {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
}
.task-head { display: flex; align-items: center; gap: 8px; }
.task-title { flex: 1; min-width: 0; overflow-wrap: anywhere; font-weight: 550; }
/* Deliberately not `white-space: nowrap`. The metadata is a variable-length
   fragment (priority, due date, status), and nowrap makes the whole task row's
   min-content width depend on that string — so a longer status or date pushes
   the row past its column instead of wrapping, which is how a 768px viewport
   ended up 15px wider than its own document. */
.task-meta { color: var(--muted); font-size: .8rem; }
.task-details {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: .875rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.task-details:empty { display: none; }

.task-done { padding: 2px 8px; font-size: .8rem; }
.task--done .task-title { text-decoration: line-through; color: var(--muted); }

.task-progress {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}
/* `align-self: stretch` is doing accessibility work, not layout work. Zeroing
   padding and border on a UA-drawn control halves the browser's own hit area —
   the default is 32px and this measured 16px — and a size the author imposes
   forfeits the user-agent exemption in WCAG 2.5.8. Stretched, the slider's hit
   area becomes the height of the row it sits in, set by the number field beside
   it; the track and the thumb keep the size the browser paints. */
.task-range {
  flex: 1;
  min-width: 0;
  align-self: stretch;
  /* Also a UA default this rule has to clear, along with the padding and border:
     2px of margin on each side kept the stretched box at 35px of a 39px row. */
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
}

/* The spin buttons are removed, not merely tolerated. `text-align: right` in a
   72px field puts the value exactly where the browser draws them, so a focused
   field rendered `100` underneath a spinner ~15px wide — the control obscuring
   the number just typed. Keeping them would need a right gutter wider than the
   9px padding, and they are a mouse-only target a few pixels across that cannot
   meet the 24px minimum either. The slider beside this field is the nudge
   affordance, and the arrow keys still step the value. */
.task-number {
  width: 72px;
  text-align: right;
  appearance: textfield;
  -moz-appearance: textfield;
}
.task-number::-webkit-outer-spin-button,
.task-number::-webkit-inner-spin-button {
  appearance: none;
  -webkit-appearance: none;
  margin: 0;
}
.task-percent { color: var(--muted); font-size: .8rem; }

/* --------------------------------------------------------------- timeline */

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

.entry { display: flex; gap: 10px; padding: 7px 0; }
.entry-dot {
  width: 7px; height: 7px;
  margin-top: 7px;
  border-radius: 50%;
  background: var(--accent);
  flex: none;
}
.entry-body { min-width: 0; }
.entry-text { margin: 0; overflow-wrap: anywhere; }
.entry-meta { margin: 2px 0 0; color: var(--muted); font-size: .78rem; }

/* ------------------------------------------------------------------ toast */

/* No interactive content, so it has no reason to take the pointer. At 900px
   tall it overlaps the last task row, and for its 3.5s life a click meant for
   the slider under it landed on the toast instead. */
.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  max-width: min(480px, calc(100vw - 32px));
  margin: 0;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--text);
  color: var(--bg);
  font-size: .875rem;
  pointer-events: none;
}

/* ------------------------------------------------------------- responsive */

@media (max-width: 720px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "top" "side" "main";
  }
  .field-grid { grid-template-columns: minmax(0, 1fr); }
  .field-grid label { margin-bottom: 0; }
  .panel-head { flex-direction: column; }
  .topbar-actions { width: 100%; }
  .task-head { flex-wrap: wrap; }

  /* `.task-title` is `flex: 1 1 0%` with `overflow-wrap: anywhere`, so its min-content
     width is a single character. A zero flex-basis means it always "fits" beside the
     other controls, so it is never the item that wraps — it is shrunk into whatever
     space is left instead. At 360px that left 25px, which rendered the title one
     letter per line.

     A real basis makes it wrap onto its own row. `order` is deliberately not used:
     moving the title visually while leaving it second in the DOM would put the
     layout out of step with the reading order. */
  .task-title { flex: 1 1 100%; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
