/* Dalton Dashboard.
   Split out of index.html so the Content Security Policy can forbid inline
   script and style outright rather than allowing 'unsafe-inline'. */

:root {
  /* Space. A 4px grid, no half steps. Every padding in the file comes from
     here, so text stacks on one optical axis instead of four. */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  --gutter: 16px;

  /* Type. Six integer steps. The old scale had eleven sizes crammed into a
     6px band, five of them half pixels, which is what nudging looks like
     after the fact. */
  --fs-xs: 12px; --fs-sm: 13px; --fs-md: 15px;
  --fs-lg: 17px; --fs-xl: 20px; --fs-2xl: 26px;
  /* A floor, not a step. Below 16px mobile Safari zooms the page on focus
     and never zooms back. */
  --fs-field: 16px;

  --r-sm: 8px; --r-md: 10px; --r-lg: 14px; --r-pill: 999px;

  /* Control height follows the input device. 44px is a floor for a thumb in
     a glove, not a law for a mouse. */
  --ctl: 44px;
  --ctl-pad: 0 14px;

  --dur-fast: 90ms; --dur: 160ms; --dur-slow: 240ms;
  --ease: cubic-bezier(.32, .72, 0, 1);

  --z-header: 30; --z-menu: 40; --z-toast: 50;

  --headroom: 72px;
  --max-content: 1180px;

  /* Dark is the default, whatever the phone is set to. Light is opt in
     through the toggle in the top right, and the choice is remembered. */
  color-scheme: dark;
  --bg: #101114;
  --panel: #1c1e23;
  --sunk: #24272d;
  --ink: #e9e9e4;
  --muted: #a6a69e;
  --line: #343841;
  --control-line: #6f737b;
  --accent: #6aa9d8;
  --on-accent: #10151a;
  --ready: #6fca92;
  --waiting: #e0a55a;
  --scheduled: #7bb8e8;
  --progress: #b39ae0;
  --blocked: #e08080;
  --danger: #e08080;
  --on-danger: #10151a;
  /* 12%, not 22%. In dark mode a higher tint moves the fill toward the text
     colour, so raising it makes badges harder to read, not easier. At 22%
     Blocked measured 4.09:1, Scheduled 4.32:1 and In progress 4.44:1, all
     under the 4.5:1 floor for text this size. */
  --tint: 12%;
  --card-shadow: none;
  --e1: 0 1px 2px rgba(0,0,0,.35);
  --e2: 0 10px 28px -10px rgba(0,0,0,.62), 0 0 0 1px rgba(255,255,255,.05);
  --e3: 0 18px 44px -12px rgba(0,0,0,.72), 0 0 0 1px rgba(255,255,255,.06);
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f4f1;
  --panel: #ffffff;
  --sunk: #ecece7;
  --ink: #1a1a18;
  --muted: #54544e;
  /* #e2e2dc measured 1.3 to 1 on white, which is a hairline nobody can see.
     In light the card is carried by a shadow, not a border. */
  --line: #d8d8d0;
  --control-line: #8a8a82;
  --accent: #2b6ea3;
  --on-accent: #ffffff;
  --ready: #1f6b3e;
  --waiting: #8a5209;
  --scheduled: #1d5580;
  --progress: #6b4fa8;
  --blocked: #9c3232;
  --danger: #9c3232;
  --on-danger: #ffffff;
  /* 14%, measured, not guessed. One seat argued light hues are darker so they
     need more mix. That is backwards: more mix moves the fill toward the text
     colour and cuts contrast, in either theme. At 18% Ready measured 3.31:1
     and Waiting 3.39:1, both under the floor. */
  --tint: 14%;
  --card-shadow: 0 1px 2px rgba(30,30,26,.08);
  --e1: 0 1px 2px rgba(30,30,26,.08);
  --e2: 0 10px 28px -10px rgba(30,30,26,.16);
  --e3: 0 18px 44px -12px rgba(30,30,26,.2);
}

/* A mouse does not need a 44px target, and on a desk those heights read as
   an app shouting. Touch keeps the floor. */
@media (pointer: fine) {
  :root { --ctl: 34px; --ctl-pad: 0 11px; }
}

* { box-sizing: border-box; }

/* Any rule setting display beats the browser's own [hidden] rule, which is
   how the menu and the message pill both ended up visible on load. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: var(--fs-md)/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  /* Lining tabular figures everywhere. This screen is mostly counts and day
     numbers, and proportional digits jitter down 112 stacked rows. */
  font-variant-numeric: tabular-nums lining;
}

/* The sticky header would otherwise cover whatever the keyboard focuses when
   tabbing back up the page. */
main :is(button, input, textarea, a, [tabindex]) { scroll-margin-top: var(--headroom); }

/* No border-radius here. It used to override each element's own radius, so
   every plain button visibly snapped from 8px corners to 6px on focus. */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.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;
}

/* ---------- header ---------- */

header {
  position: sticky; top: 0; z-index: var(--z-header);
  background: color-mix(in srgb, var(--panel) 86%, transparent);
  backdrop-filter: blur(16px) saturate(1.4);
  border-bottom: 1px solid var(--line);
  padding: var(--s2) var(--gutter);
  padding-top: calc(var(--s2) + env(safe-area-inset-top, 0px));
  display: flex; align-items: center; gap: var(--s2);
}
header h1 {
  font-size: var(--fs-lg); margin: 0; font-weight: 600; letter-spacing: -0.015em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.brand {
  width: 24px; height: 24px; border-radius: var(--r-sm); flex: none;
  background: var(--accent); color: var(--on-accent);
  display: grid; place-items: center;
  font-size: 11px; font-weight: 700; letter-spacing: 0.02em;
}
.spacer { margin-left: auto; }

/* One button family. Filled, outlined, ghost, plus pill and icon modifiers.
   Every borderless case keeps a transparent border so heights never differ
   by the 2px the border box would otherwise cost. */
button {
  font: inherit; font-size: var(--fs-sm); cursor: pointer;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--sunk); color: var(--ink);
  padding: var(--ctl-pad); min-height: var(--ctl);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: background-color var(--dur) var(--ease),
              border-color var(--dur) var(--ease),
              transform var(--dur-fast) var(--ease);
}
button:hover { border-color: var(--control-line); }
button:active { transform: scale(.975); }
button:disabled { opacity: .5; cursor: default; transform: none; }
button.primary {
  background: var(--accent); border-color: var(--accent);
  color: var(--on-accent); font-weight: 600; font-size: var(--fs-md);
}
button.primary:hover { filter: brightness(1.08); border-color: var(--accent); }
button.quiet { border-color: transparent; background: none; color: var(--muted); }
button.quiet:hover { background: var(--sunk); color: var(--ink); border-color: transparent; }
button.linkbtn {
  border-color: transparent; background: none; color: var(--accent);
  padding: 0 var(--s1); min-height: var(--ctl); font-size: var(--fs-sm);
}
button.linkbtn:hover { background: none; text-decoration: underline; border-color: transparent; }

/* The overflow menu keeps Sign out away from Refresh. Reaching for one and
   hitting the other means a full Entra sign in from a job site. */
.menuwrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px);
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: var(--s1); min-width: 190px;
  box-shadow: var(--e3); z-index: var(--z-menu);
  display: flex; flex-direction: column; gap: 2px;
}
.menu button {
  width: 100%; justify-content: flex-start;
  border-color: transparent; background: none;
}
.menu button:hover { background: var(--sunk); border-color: transparent; }
.menu button.danger { color: var(--danger); }

/* Theme toggle, far right. Shows the thing it will switch you to. */
.iconbtn {
  padding: 0; width: var(--ctl); min-height: var(--ctl); flex: none;
  color: var(--ink); border-color: transparent; background: none;
}
.iconbtn:hover { background: var(--sunk); border-color: transparent; }
.iconbtn svg { width: 19px; height: 19px; display: block; }
.iconbtn .moon { display: none; }
:root[data-theme="light"] .iconbtn .sun { display: none; }
:root[data-theme="light"] .iconbtn .moon { display: block; }

/* ---------- inputs ---------- */

input[type=text], input[type=search], input[type=date], textarea {
  color: var(--ink); background: var(--panel);
  border: 1px solid var(--control-line);
  border-radius: var(--r-sm); padding: 10px 12px;
  width: 100%; min-height: var(--ctl);
  font-family: inherit; font-size: var(--fs-field); line-height: 1.45;
}
input:focus, textarea:focus { border-color: var(--accent); }

/* Starts at one line and grows with what you say. It sat at four empty lines
   before, which took the top of the screen for nothing. */
#capture-text {
  min-height: var(--ctl); height: var(--ctl);
  resize: none; overflow-y: hidden;
  transition: height var(--dur) var(--ease);
}
textarea { resize: vertical; }

main { padding: var(--s3) var(--gutter) 80px; max-width: var(--max-content); margin: 0 auto; }

/* ---------- capture ---------- */

.capture {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: var(--s3);
  margin-bottom: var(--s4); box-shadow: var(--card-shadow);
}
.capture .row { display: flex; gap: var(--s2); margin-top: var(--s3); align-items: center; }
.capture .row .spacer { margin-left: auto; }
.hint { color: var(--muted); font-size: var(--fs-sm); margin: var(--s2) 0 0; }
.matches { display: flex; flex-direction: column; gap: var(--s2); margin-top: var(--s3); }
.matches button {
  width: 100%; min-height: 56px; text-align: left; justify-content: flex-start;
  padding: 10px 14px; line-height: 1.35; font-size: var(--fs-md);
}
.matches button.pick { border-color: var(--accent); }
.matches .sub { display: block; color: var(--muted); font-size: var(--fs-sm); margin-top: 2px; font-weight: 400; }
.matches button.review { margin-top: var(--s2); border-style: dashed; }
/* However many rows the proposal has, the action rides in the thumb arc. */
.matches button[data-pick="apply"] {
  position: sticky; bottom: calc(var(--s3) + env(safe-area-inset-bottom, 0px));
  box-shadow: var(--e2); justify-content: center;
}

.proposalbox { display: flex; flex-direction: column; gap: var(--s2); }
.proposal {
  background: var(--sunk); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: var(--s3);
}
.proposal label {
  display: flex; gap: var(--s3); align-items: flex-start;
  min-height: var(--ctl); cursor: pointer;
}
.proposal input[type=checkbox] {
  width: 22px; height: 22px; flex: none; margin: 1px 0 0;
  accent-color: var(--accent); min-height: 0;
}
.proposal .who strong { font-size: var(--fs-md); }
.proposal .sub { display: block; color: var(--muted); font-size: var(--fs-sm); margin-top: 2px; }
.proposal ul { margin: var(--s2) 0 0; padding-left: 34px; font-size: var(--fs-md); list-style: none; }
.proposal li { margin-bottom: var(--s1); display: flex; gap: var(--s2); }
.proposal .verb {
  flex: none; min-width: 66px; color: var(--muted);
  font-size: var(--fs-xs); letter-spacing: .06em; text-transform: uppercase;
  padding-top: 2px;
}

/* ---------- filters ---------- */

#search { margin-bottom: var(--s3); }
.scopes, .filters { display: flex; gap: var(--s2); flex-wrap: wrap; }
.scopes { margin-bottom: var(--s2); }
.filters { margin: var(--s3) 0 var(--s4); }
.scopes button, .filters button { border-radius: var(--r-pill); }
/* One selected treatment, not three. The old file had scope pills select blue
   and filter pills select near white, six inches apart on the same screen. */
.scopes button[aria-pressed="true"],
.filters button[aria-pressed="true"],
.statusrow button[aria-pressed="true"] {
  background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600;
}
.count { color: var(--muted); font-weight: 500; }
.scopes button[aria-pressed="true"] .count,
.filters button[aria-pressed="true"] .count { color: inherit; opacity: .85; }
.note { color: var(--muted); font-size: var(--fs-sm); margin: 0 0 var(--s3); }
.searchbar {
  display: flex; align-items: center; gap: var(--s3); flex-wrap: wrap;
  background: var(--sunk); border-radius: var(--r-sm); padding: var(--s2) var(--s3);
  margin-bottom: var(--s3); font-size: var(--fs-sm); color: var(--muted);
}
.stalebar {
  background: var(--sunk); border-left: 3px solid var(--waiting);
  border-radius: var(--r-sm); padding: var(--s2) var(--s3);
  margin-bottom: var(--s3); font-size: var(--fs-sm); color: var(--muted);
  display: flex; gap: var(--s3); align-items: center; flex-wrap: wrap;
}
.stalebar strong { color: var(--ink); }

/* ---------- job cards ---------- */

/* Sticky band headings explain the sort. Without them an ordering by neglect
   just looks like a broken alphabetical sort. */
.band {
  position: sticky; top: var(--headroom); z-index: 5;
  font-size: var(--fs-xs); letter-spacing: .07em; text-transform: uppercase;
  color: var(--muted); font-weight: 600;
  padding: var(--s3) 0 var(--s2);
  background: linear-gradient(var(--bg) 70%, transparent);
}

.job {
  background: var(--panel);
  border: 0;
  border-radius: var(--r-lg);
  margin-bottom: var(--s2);
  overflow: hidden;
  /* The status colour becomes structural rather than decorative: a rail you
     can scan down at arm's length without reading a word. It also replaces
     112 redundant grey outlines, which is what made this read as a
     spreadsheet with rounded corners. */
  box-shadow: inset 3px 0 0 var(--st, var(--line)),
              inset 0 1px 0 rgba(255,255,255,.045),
              var(--card-shadow);
}

button.head {
  display: block; width: 100%; text-align: left;
  background: none; border: 1px solid transparent; border-radius: 0;
  padding: var(--s3) var(--s4) var(--s3) 17px;
  font: inherit; font-size: var(--fs-md); color: inherit; min-height: 0;
}
button.head:hover { background: color-mix(in srgb, var(--ink) 4%, transparent); border-color: transparent; }
button.head:focus-visible { outline-offset: -2px; }

/* Title first. It used to render the badge above the name, so the eye hit a
   12px pill before the thing it was looking for. */
.titleline { display: flex; align-items: baseline; gap: var(--s3); }
.jobtitle {
  font-size: var(--fs-lg); margin: 0; font-weight: 600;
  letter-spacing: -0.015em; line-height: 1.25;
  flex: 1; min-width: 0;
}
.quiet-age { flex: none; color: var(--muted); font-size: var(--fs-sm); }
.quiet-age.stale { color: var(--danger); font-weight: 600; }

.badge {
  display: inline-block; font-size: var(--fs-xs); font-weight: 600;
  letter-spacing: .02em; padding: 3px 8px; border-radius: var(--r-pill);
  white-space: nowrap; flex: none;
}
.badge[data-status="Ready to schedule"] { color: var(--ready);     background: color-mix(in srgb, var(--ready) var(--tint), transparent); }
.badge[data-status="Waiting"]           { color: var(--waiting);   background: color-mix(in srgb, var(--waiting) var(--tint), transparent); }
.badge[data-status="Scheduled"]         { color: var(--scheduled); background: color-mix(in srgb, var(--scheduled) var(--tint), transparent); }
.badge[data-status="In progress"]       { color: var(--progress);  background: color-mix(in srgb, var(--progress) var(--tint), transparent); }
.badge[data-status="Blocked"]           { color: var(--blocked);   background: color-mix(in srgb, var(--blocked) var(--tint), transparent); }
.badge[data-status="Done"]              { color: var(--muted);     background: color-mix(in srgb, var(--muted) var(--tint), transparent); }
.badge.flag { color: var(--danger); background: color-mix(in srgb, var(--danger) var(--tint), transparent); }

.meta { font-size: var(--fs-sm); color: var(--muted); margin-top: var(--s1); }
.meta > span + span::before { content: "·"; margin: 0 var(--s2); opacity: .55; }
/* The next action is the answer to the question the card asks. It was styled
   as one more attribute, below the grey ribbon, so the eye reached it last. */
.next {
  margin-top: var(--s3); font-size: var(--fs-md); font-weight: 500;
  display: flex; gap: var(--s2); align-items: baseline;
}
.next::before { content: "→"; color: var(--accent); flex: none; }
/* A job with no next action is the neglect. It used to render as nothing. */
.next.none { color: var(--waiting); font-weight: 600; }
.next.none::before { content: "!"; color: var(--waiting); font-weight: 700; }
.stale { color: var(--danger); font-weight: 600; }

/* ---------- expanded detail ---------- */

.detail { padding: 0 var(--s4) var(--s4) 17px; }
.statusrow {
  display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2);
  margin: var(--s1) 0 var(--s3);
}
.statusrow button { font-size: var(--fs-sm); }

ul.items { list-style: none; margin: 0; padding: 0; }
ul.items li { border-bottom: 1px solid var(--line); }
ul.items li:last-child { border-bottom: 0; }
ul.items li.none { border: 0; padding: var(--s3) var(--s1); color: var(--muted); font-size: var(--fs-sm); }
ul.items label {
  display: flex; gap: var(--s3); align-items: center;
  padding: 11px var(--s1); min-height: 52px; cursor: pointer;
  -webkit-tap-highlight-color: color-mix(in srgb, var(--accent) 18%, transparent);
}
ul.items label:hover { background: color-mix(in srgb, var(--ink) 4%, transparent); }
ul.items input[type=checkbox] {
  width: 22px; height: 22px; flex: none; margin: 0;
  accent-color: var(--accent); min-height: 0;
}
.itype {
  font-size: var(--fs-xs); color: var(--muted);
  border: 1px solid var(--line); border-radius: var(--r-pill);
  padding: 2px 8px; flex: none;
}
.done .txt { text-decoration: line-through; color: var(--muted); }
.adder { display: flex; gap: var(--s2); margin-top: var(--s3); }
.adder input { flex: 1; }

/* ---------- states ---------- */

.empty {
  background: var(--panel); border-radius: var(--r-lg); box-shadow: var(--card-shadow);
  padding: 44px var(--s5); text-align: center; color: var(--muted);
}
.empty strong { display: block; color: var(--ink); font-size: var(--fs-md); margin-bottom: var(--s1); font-weight: 600; }
.empty.good strong { color: var(--ready); }
.empty button { margin-top: var(--s4); }
.msg { color: var(--muted); padding: var(--s5) 0; }

.errbox {
  background: var(--panel); border: 1px solid var(--danger);
  border-radius: var(--r-lg); padding: var(--s4); margin: var(--s2) 0;
}
.errbox h2 { font-size: var(--fs-lg); margin: 0 0 var(--s1); }
.errbox p { margin: 0 0 var(--s3); color: var(--muted); }
.errbox details { margin-top: var(--s3); font-size: var(--fs-xs); color: var(--muted); }
.errbox pre { white-space: pre-wrap; word-break: break-word; margin: var(--s1) 0 0; }

.skeleton {
  background: var(--panel); border-radius: var(--r-lg); box-shadow: var(--card-shadow);
  padding: var(--s4); margin-bottom: var(--s2);
}
.skeleton div {
  border-radius: var(--r-pill); height: 12px; margin-bottom: var(--s2);
  background: linear-gradient(90deg,
    var(--sunk) 25%, color-mix(in srgb, var(--ink) 9%, var(--sunk)) 37%, var(--sunk) 63%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}
.skeleton div:nth-child(1) { width: 42%; height: 16px; }
.skeleton div:nth-child(2) { width: 26%; }
.skeleton div:nth-child(3) { width: 68%; margin-bottom: 0; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* A failed write has to stay on screen. It used to be a pill that removed
   itself after 2.6 seconds, which is not long enough to read a problem, let
   alone act on one. */
.live {
  position: fixed; left: 50%;
  bottom: calc(var(--s5) + env(safe-area-inset-bottom, 0px));
  max-width: calc(100vw - var(--s6));
  background: var(--panel); color: var(--ink);
  border: 1px solid var(--line);
  padding: var(--s2) var(--s3) var(--s2) var(--s4);
  border-radius: var(--r-pill);
  font-size: var(--fs-md); z-index: var(--z-toast); text-align: center;
  box-shadow: var(--e3);
  display: flex; align-items: center; gap: var(--s3);
  transform: translateX(-50%);
  transition: transform var(--dur-slow) var(--ease), opacity var(--dur) ease;
}
.live.bad { background: var(--danger); color: var(--on-danger); border-color: var(--danger); }
.live.bad button { color: inherit; }
.live button { min-height: 36px; padding: 0 var(--s3); font-size: var(--fs-sm); }

.gate { max-width: 430px; margin: 14vh auto; text-align: center; padding: 0 var(--gutter); }
.gate h1 { font-size: var(--fs-2xl); margin: 0 0 var(--s2); letter-spacing: -0.022em; line-height: 1.15; }
.gate p { color: var(--muted); }
.gate .err { color: var(--danger); }

/* ---------- desktop ---------- */

@media (min-width: 900px) {
  header { padding: var(--s2) var(--s5); }
  main { padding: var(--s4) var(--s5) 80px; }
  .statusrow { grid-template-columns: repeat(6, 1fr); }
  #list, .band { max-width: 900px; }

  /* Four stacked lines on a 1050px card left three quarters of it empty.
     Two lines, with the meta pushed to the right edge where it belongs. */
  button.head {
    display: grid; grid-template-columns: minmax(0, 1fr) auto;
    align-items: baseline; column-gap: var(--s5); row-gap: var(--s1);
  }
  .titleline { grid-column: 1; grid-row: 1; }
  .quiet-age { display: none; }
  .meta { grid-column: 2; grid-row: 1; justify-self: end; text-align: right; margin-top: 0; }
  .next { grid-column: 1 / -1; grid-row: 2; margin-top: var(--s1); }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
  }
  button:active { transform: none; }
}
