/* Work4Me (Mastercraft)
   Palette from the workshop: satin white board, charcoal Melteca, spruce
   machine green for the one thing to press. Rows carry a coloured left edge,
   like edge tape on a panel, that says how urgent they are. */

:root {
  --paper: #f5f6f3;
  --surface: #ffffff;
  --ink: #1d292d;
  --muted: #5d6a6d;
  --line: #dde2dd;
  --line-strong: #c7cec8;
  --spruce: #1f6b57;
  --spruce-ink: #ffffff;
  --spruce-soft: #e3efe9;

  --overdue: #b42318;
  --today: #b25d14;
  --week: #2c679b;
  --later: #8b9497;
  --undated: #b9c0bb;
  --overdue-soft: #fbe9e7;
  --today-soft: #fbefe2;
  --week-soft: #e6eef6;

  --radius-sm: 6px;
  --radius: 10px;
  --font: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --step--1: 0.8125rem;
  --step-0: 0.9375rem;
  --step-1: 1.125rem;
  --step-2: 1.5rem;
  --step-3: 2rem;
  --side: 232px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 var(--step-0)/1.5 var(--font);
  font-feature-settings: "tnum" 1;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--spruce); outline-offset: 2px; }
[hidden] { display: none !important; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: var(--side) 1fr; min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 4px;
  padding: 20px 14px; border-right: 1px solid var(--line); background: var(--surface);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 20px; text-decoration: none; }
.brand-mark { width: 30px; height: 30px; flex: none; }
.brand-name { font-weight: 650; letter-spacing: -0.01em; line-height: 1.15; }
.brand-name small { display: block; font-weight: 450; color: var(--muted); font-size: var(--step--1); }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--radius-sm);
  text-decoration: none; color: var(--muted); font-weight: 500;
}
.nav a svg { width: 18px; height: 18px; flex: none; }
.nav a:hover { background: var(--paper); color: var(--ink); }
.nav a[aria-current="page"] { background: var(--spruce-soft); color: var(--spruce); }
.side-foot { margin-top: auto; padding: 12px 10px 0; border-top: 1px solid var(--line); font-size: var(--step--1); color: var(--muted); }
.side-foot strong { display: block; color: var(--ink); font-weight: 600; font-size: var(--step-0); }
.linkish { background: none; border: 0; padding: 0; color: var(--muted); text-decoration: underline; cursor: pointer; font-size: var(--step--1); }

.main { min-width: 0; padding: 28px clamp(16px, 4vw, 48px) 96px; max-width: 1080px; }

/* ---------- Page header: title left, the one primary action right ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: var(--step-3); line-height: 1.1; letter-spacing: -0.02em; font-weight: 650; }
.page-head p { margin: 6px 0 0; color: var(--muted); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong); background: var(--surface); cursor: pointer;
  font-weight: 550; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--ink); }
.btn-primary { background: var(--spruce); border-color: var(--spruce); color: var(--spruce-ink); }
.btn-primary:hover { background: #185746; border-color: #185746; }
.btn-quiet { border-color: transparent; background: transparent; color: var(--muted); }
.btn-quiet:hover { color: var(--ink); border-color: var(--line); }
.btn-sm { min-height: 32px; padding: 0 12px; font-size: var(--step--1); }
.btn svg { width: 16px; height: 16px; }
.btn:disabled { opacity: 0.65; cursor: progress; }

/* ---------- Next up: the single most urgent thing ---------- */
.next-up {
  position: relative; display: grid; grid-template-columns: 1fr auto; gap: 8px 24px; align-items: center;
  padding: 22px 24px 22px 30px; margin-bottom: 28px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden;
}
.next-up::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 8px; background: var(--band, var(--later)); }
.next-up .when { font-size: var(--step--1); font-weight: 600; color: var(--band, var(--muted)); }
.next-up h2 { margin: 2px 0 0; font-size: var(--step-2); line-height: 1.2; letter-spacing: -0.015em; font-weight: 600; }
.next-up .sub { color: var(--muted); margin-top: 4px; }
.next-up .btn { min-height: 48px; padding: 0 22px; font-size: var(--step-1); }
.next-up.clear { --band: var(--spruce); }

/* ---------- Band filter ---------- */
.bands { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.band-pill {
  display: inline-flex; align-items: baseline; gap: 8px; padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 500; color: var(--muted);
}
.band-pill b { font-weight: 650; color: var(--ink); }
.band-pill[aria-pressed="true"] { border-color: var(--ink); color: var(--ink); }
.band-pill.overdue b { color: var(--overdue); }

/* ---------- Work rows ---------- */
.group-title { margin: 22px 0 8px; font-size: var(--step--1); font-weight: 600; color: var(--muted); }
.rows { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.row {
  position: relative; display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; align-items: center;
  padding: 14px 16px 14px 22px; border-top: 1px solid var(--line);
}
.row:first-child { border-top: 0; }
.row::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 5px; background: var(--band, var(--undated)); }
.row .title { font-weight: 550; }
.row .meta { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--muted); font-size: var(--step--1); }
.row .meta .due { font-weight: 600; color: var(--band, var(--muted)); }
.row .actions { display: flex; gap: 8px; align-items: center; }
.row.done { opacity: 0.45; }
.row.done .title { text-decoration: line-through; }
[data-band="overdue"] { --band: var(--overdue); }
[data-band="today"] { --band: var(--today); }
[data-band="this_week"] { --band: var(--week); }
[data-band="later"] { --band: var(--later); }
[data-band="undated"] { --band: var(--undated); }

.empty { padding: 36px 24px; text-align: center; color: var(--muted); background: var(--surface); border: 1px dashed var(--line-strong); border-radius: var(--radius); }
.empty strong { display: block; color: var(--ink); font-size: var(--step-1); margin-bottom: 4px; }
.empty .btn { margin-top: 14px; }

/* ---------- Tables ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 14px; border-top: 1px solid var(--line); vertical-align: middle; }
thead th { border-top: 0; font-size: var(--step--1); font-weight: 600; color: var(--muted); background: #fafbf9; }
td.num, th.num { text-align: right; }
tbody tr.link { cursor: pointer; }
tbody tr.link:hover { background: var(--paper); }
.count-overdue { color: var(--overdue); font-weight: 650; }
.centre-row th { background: var(--paper); font-size: var(--step--1); color: var(--ink); font-weight: 650; }

/* ---------- Search and chips ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.search {
  flex: 1 1 280px; min-height: 42px; padding: 0 14px 0 40px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235d6a6d' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m20 20-3.5-3.5'/%3E%3C/svg%3E") no-repeat 12px center / 18px;
}
.chip { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; color: var(--muted); font-weight: 500; font-size: var(--step--1); }
.chip[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--paper); border: 1px solid var(--line); font-size: var(--step--1); color: var(--muted); }

/* ---------- Detail layout ---------- */
.detail { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; }
.panel + .panel { margin-top: 20px; }
.panel h2 { margin: 0 0 12px; font-size: var(--step-1); font-weight: 600; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; }
.person { padding: 10px 0; border-top: 1px solid var(--line); }
.person:first-of-type { border-top: 0; padding-top: 0; }
.person strong { font-weight: 600; }
.person div { color: var(--muted); font-size: var(--step--1); }
.back { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); text-decoration: none; margin-bottom: 10px; font-size: var(--step--1); }
.back:hover { color: var(--ink); }
.back svg { width: 16px; height: 16px; }

/* ---------- Activity timeline ---------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 92px 1fr; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.timeline li:first-child { border-top: 0; }
.timeline time { color: var(--muted); font-size: var(--step--1); }
.timeline .who { font-weight: 600; }
.timeline .what { color: var(--muted); }

/* ---------- Forms and dialogs ---------- */
dialog {
  width: min(520px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 24px 60px -20px rgba(29, 41, 45, 0.35); color: var(--ink);
}
dialog::backdrop { background: rgba(29, 41, 45, 0.35); }
.dlg-head { padding: 18px 22px 0; }
.dlg-head h2 { margin: 0; font-size: var(--step-1); font-weight: 650; }
.dlg-body { padding: 16px 22px; display: grid; gap: 14px; }
.dlg-foot { padding: 14px 22px 18px; display: flex; justify-content: flex-end; gap: 10px; border-top: 1px solid var(--line); }
label { display: grid; gap: 6px; font-weight: 550; font-size: var(--step--1); }
label .hint { font-weight: 400; color: var(--muted); }
input[type="text"], input[type="email"], input[type="tel"], input[type="date"], input[type="number"], select, textarea {
  width: 100%; min-height: 42px; padding: 8px 12px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--surface); font-size: var(--step-0); font-weight: 400;
}
textarea { min-height: 84px; resize: vertical; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check-list { display: flex; flex-wrap: wrap; gap: 8px; }
.check-list label { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px; }
.error { color: var(--overdue); font-size: var(--step--1); }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: var(--radius-sm); font-weight: 500;
  display: flex; gap: 14px; align-items: center;
}
.toast button { background: none; border: 0; color: #9fd4c3; font-weight: 600; cursor: pointer; padding: 0; }

/* ---------- Sign in ---------- */
.signin { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.signin-card { width: min(420px, 100%); }
.signin-card .brand { padding: 0 0 28px; }
.signin-card h1 { font-size: var(--step-3); letter-spacing: -0.02em; margin: 0 0 8px; line-height: 1.1; }
.signin-card p { color: var(--muted); margin: 0 0 22px; }
.signin-card form { display: grid; gap: 12px; }
.signin-card .btn { min-height: 46px; }
.demo-note { margin-top: 18px; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--spruce-soft); color: var(--spruce); font-size: var(--step--1); }

.demo-banner { background: var(--ink); color: #fff; font-size: var(--step--1); padding: 6px 16px; text-align: center; }
.demo-banner select { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.4); border-radius: 4px; padding: 1px 4px; margin-left: 6px; min-height: 0; width: auto; }
.demo-banner select option { color: var(--ink); }

/* ---------- Small screens: bottom tab bar ---------- */
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side {
    position: fixed; inset: auto 0 0 0; top: auto; height: auto; z-index: 20;
    flex-direction: row; padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); border-right: 0; border-top: 1px solid var(--line);
  }
  .brand, .side-foot { display: none; }
  .nav { display: flex; flex: 1; justify-content: space-around; }
  .nav a { flex-direction: column; gap: 2px; padding: 6px 8px; font-size: 0.6875rem; }
  .main { padding-top: 20px; }
  .page-head h1 { font-size: var(--step-2); }
  .next-up { grid-template-columns: 1fr; padding: 18px 18px 18px 24px; }
  .next-up .btn { width: 100%; }
  .detail { grid-template-columns: 1fr; }
  .row { grid-template-columns: 1fr; }
  .row .actions { justify-content: flex-start; }
  .two { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
  .toast { bottom: calc(76px + env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: no-preference) {
  .row, .next-up { transition: opacity 180ms ease; }
  dialog[open] { animation: rise 160ms ease-out; }
  @keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
}
