/* Every colour is a light-dark() pair, so the theme follows the device unless
   the account dialog forces one (theme.js sets data-theme on <html>). */
:root {
  color-scheme: light dark;
  --bg: light-dark(#f6f5f1, #161614);
  --panel: light-dark(#ffffff, #201f1d);
  --soft: light-dark(#ebe9e2, #2b2a27);
  --line: light-dark(#dcd9d0, #3b3934);
  --line-strong: light-dark(#aaa69b, #625f57);
  --text: light-dark(#23221f, #e9e6df);
  --muted: light-dark(#736f66, #a09c91);
  --accent: light-dark(#2b59c3, #92b1ff);
  --primary: light-dark(#2b59c3, #3f6ad8);
  --red: light-dark(#b42318, #ff8f85);
  --red-bg: light-dark(#fde3e1, #4b201c);
  --danger: light-dark(#b42318, #c0392b);
  --amber: light-dark(#b45309, #f0b45c);
  --ok: light-dark(#1b7a3d, #7fd49b);
  --blocked-fill: light-dark(#e8e7e2, #34332f);
  --done-text: light-dark(#9a968d, #777369);
  --overdue-fill: light-dark(#f6a3a0, #8c2a24);
  --overdue-text: light-dark(#5c0b08, #ffe5e2);
  --chip-bg: light-dark(#edf1fc, #263250);
  --chip-line: light-dark(#b7c5ec, #46598d);
  --chip-text: light-dark(#1f3f96, #bccdff);
  --ready-bg: light-dark(#dff3e4, #1e3d29);
  --ready-text: light-dark(#1b6b36, #8fdba6);
  --held-bg: light-dark(#d3d1ca, #4d4b45);
  --held-text: light-dark(#45423c, #dbd8cf);
  --warn-bg: light-dark(#fff3d6, #3c3115);
  --warn-line: light-dark(#e6c56a, #7c6524);
  --highlight: light-dark(#e6ecfb, #2b3758);
  --flash: light-dark(#ffe9a8, #5e4c13);
  --shadow: light-dark(rgb(0 0 0 / 0.16), rgb(0 0 0 / 0.55));
  --detail-width: 340px;
}
:root[data-theme='light'] { color-scheme: light; }
:root[data-theme='dark'] { color-scheme: dark; }

/* Category colours: fill, text and edge stripe for each. */
.g-blue { --g-bg: light-dark(#dbe7ff, #22345c); --g-text: light-dark(#1d3f94, #b4c9ff); --g-line: light-dark(#4f7be0, #6d93f0); }
.g-green { --g-bg: light-dark(#d9f2df, #1c3d27); --g-text: light-dark(#1b6b36, #93dba8); --g-line: light-dark(#3aa35c, #4fb873); }
.g-amber { --g-bg: light-dark(#fdeecb, #46360f); --g-text: light-dark(#8a5a00, #f1c56b); --g-line: light-dark(#d79a1b, #e0aa37); }
.g-purple { --g-bg: light-dark(#ebe0fb, #37285a); --g-text: light-dark(#5b2fa3, #cdb6ff); --g-line: light-dark(#8a5fd6, #a383e6); }
.g-teal { --g-bg: light-dark(#d3f1f0, #173d3d); --g-text: light-dark(#0f6362, #86d9d6); --g-line: light-dark(#2aa3a0, #43bcb8); }
.g-rose { --g-bg: light-dark(#fbdde2, #4a1f28); --g-text: light-dark(#a1263b, #ffb0bd); --g-line: light-dark(#e0556b, #ee7386); }
.g-orange { --g-bg: light-dark(#fde3d0, #48290f); --g-text: light-dark(#9a4a0c, #f8b98a); --g-line: light-dark(#e8822f, #f09650); }
.g-lime { --g-bg: light-dark(#e6f2c4, #323c12); --g-text: light-dark(#55690d, #c6dc7c); --g-line: light-dark(#8fae24, #a5c540); }
.g-pink { --g-bg: light-dark(#fbdcf1, #47203c); --g-text: light-dark(#9c2a7a, #f7aede); --g-line: light-dark(#d858b2, #e678c4); }
.g-slate { --g-bg: light-dark(#e3e6ea, #2e3238); --g-text: light-dark(#47505c, #c3cad3); --g-line: light-dark(#7b8794, #93a0ad); }
.g-indigo { --g-bg: light-dark(#e0e2ff, #272a5e); --g-text: light-dark(#3138a8, #bcc1ff); --g-line: light-dark(#5a63e0, #7c84f0); }
.g-sky { --g-bg: light-dark(#d6eefb, #163a4d); --g-text: light-dark(#0c5f86, #8fd3f4); --g-line: light-dark(#2f9fd6, #52b5e6); }
.g-brown { --g-bg: light-dark(#efe0d2, #40301f); --g-text: light-dark(#7a4a1e, #e0b88f); --g-line: light-dark(#a8703a, #c08a55); }
.g-yellow { --g-bg: light-dark(#fbf3bf, #3f390f); --g-text: light-dark(#6f6100, #e8d96a); --g-line: light-dark(#cdb81a, #d8c63a); }
.g-magenta { --g-bg: light-dark(#f3dcfb, #3f1f4a); --g-text: light-dark(#8a2aa3, #e6aef5); --g-line: light-dark(#b95bd3, #cc7de2); }
.g-graphite { --g-bg: light-dark(#d9d9d9, #3a3a3a); --g-text: light-dark(#2e2e2e, #e2e2e2); --g-line: light-dark(#555555, #b5b5b5); }
.g-red { --g-bg: light-dark(#fdd9d5, #4d1a16); --g-text: light-dark(#a31b12, #ffa79e); --g-line: light-dark(#dc3b2e, #f0584a); }
.g-mint { --g-bg: light-dark(#d4f6e8, #123d30); --g-text: light-dark(#0b6b4b, #86e2c0); --g-line: light-dark(#34b98a, #4fcf9f); }
.g-olive { --g-bg: light-dark(#e8e9c6, #35360f); --g-text: light-dark(#5b5d10, #d3d57a); --g-line: light-dark(#8a8d22, #a9ac3e); }
.g-navy { --g-bg: light-dark(#d5dbee, #1c2547); --g-text: light-dark(#1c2c66, #aebbee); --g-line: light-dark(#2c3f8f, #5b6fc4); }
.g-plum { --g-bg: light-dark(#ead8ee, #3a2040); --g-text: light-dark(#6b2a78, #dba9e6); --g-line: light-dark(#8b3f9a, #a862b6); }
.g-sand { --g-bg: light-dark(#f1e7d3, #3d3524); --g-text: light-dark(#6e5a2c, #dccb9c); --g-line: light-dark(#b79d5c, #c9b274); }
.g-maroon { --g-bg: light-dark(#f1d5db, #451821); --g-text: light-dark(#7d1630, #f0a3b5); --g-line: light-dark(#9c2543, #c04d6a); }
.g-forest { --g-bg: light-dark(#d3e8d6, #17331c); --g-text: light-dark(#1d5a2a, #9fd4a9); --g-line: light-dark(#2c7a3c, #4a9a5a); }

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, 'Segoe UI', sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
body.with-detail { padding-right: var(--detail-width); }

button, input, select, textarea { font: inherit; color: inherit; }
button {
  padding: 5px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--line-strong); }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: -1px; }

input, select, textarea {
  padding: 5px 7px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--panel);
}

.muted, .hint { color: var(--muted); }
.error-text, .late { color: var(--red); }
.warn-text { color: var(--amber); }
.ok-text { color: var(--ok); }
.error-text:empty, .muted:empty { display: none; }

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

.login {
  width: min(340px, calc(100vw - 32px));
  margin: 14vh auto 0;
  padding: 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  display: grid;
  gap: 14px;
}
.login h1 { margin: 0; font-size: 20px; }
.login label { display: grid; gap: 4px; color: var(--muted); }
.login label input { color: var(--text); }
.login .note { margin: 0; padding: 10px; background: var(--warn-bg); border-radius: 6px; }

/* ---------- header and summary ---------- */

/* The env() insets leave room for a phone's status bar, notch and home
   indicator when the app runs full-screen; everywhere else they are 0. */
.top {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) 10px calc(16px + env(safe-area-inset-left));
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.top .spacer { flex: 1; }
/* On a wide screen the menu's buttons simply sit in the header. */
.menu { display: contents; }
#menu-btn { display: none; }
#list-select { font-size: 16px; font-weight: 600; max-width: 45vw; }
.save-status { color: var(--muted); font-size: 12px; }
.save-status.failed { color: var(--red); font-weight: 600; }

.no-list { padding: 60px 16px; text-align: center; }

.summary { display: flex; flex-wrap: wrap; gap: 10px; padding: 14px 16px 4px; }
.tile {
  min-width: 132px;
  padding: 9px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.tile b { display: block; font-size: 22px; line-height: 1.2; }
.tile span { color: var(--muted); font-size: 12px; }
.tile.alert b { color: var(--red); }

.banner { margin: 10px 16px 0; padding: 8px 12px; border-radius: 8px; }
.banner.warn { background: var(--warn-bg); border: 1px solid var(--warn-line); }
.banner.update { display: flex; align-items: center; gap: 12px; background: var(--highlight); border: 1px solid var(--chip-line); }
.banner p { margin: 2px 0; }

/* ---------- toolbar and add bar ---------- */

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 12px 16px 0; }
.tabs { display: flex; flex-wrap: wrap; gap: 4px; flex: 1; }
.tabs button { border-radius: 16px; padding: 4px 12px; }
.tabs button[aria-pressed='true'] { background: var(--text); border-color: var(--text); color: var(--bg); }
.tabs i { font-style: normal; opacity: 0.65; font-size: 12px; }
#search { width: 260px; }
#sort-select { display: none; }

.now-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; padding: 10px 16px 0; }
.now-bar input { width: 70px; margin: 0 4px; }
.now-bar span { color: var(--muted); }

.add { display: flex; align-items: center; gap: 8px; padding: 10px 16px; }
.add label { font-weight: 600; }
.add #add-task { flex: 1; min-width: 180px; max-width: 640px; }
.next-id { min-width: 40px; padding: 3px 8px; border-radius: 5px; background: var(--soft); font-weight: 600; text-align: center; }

/* ---------- the grid ---------- */

#grid {
  width: calc(100% - 32px);
  min-width: 960px;
  margin: 0 16px;
  border-collapse: collapse;
  table-layout: fixed;
  background: var(--panel);
}
.w-drag { width: 22px; } .w-id { width: 62px; } .w-area { width: 112px; } .w-prio { width: 96px; }
 .w-due { width: 124px; } .w-hrs { width: 66px; } .w-deps { width: 140px; }
.w-state { width: 104px; } .w-done { width: 30px; }

#grid th {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 7px 7px;
  background: var(--soft);
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
#grid th button { padding: 0; border: 0; border-radius: 3px; background: none; font-weight: inherit; }
#grid th button::after { content: '↕'; margin-left: 4px; opacity: 0; }
#grid th button:hover::after, #grid th button:focus-visible::after { opacity: 0.45; }
#grid th button[data-dir='asc']::after { content: '▲'; opacity: 1; font-size: 9px; }
#grid th button[data-dir='desc']::after { content: '▼'; opacity: 1; font-size: 9px; }
/* Cells line up along the top, so a row expanded for reading keeps its controls on the task's own line. */
#grid td { padding: 0; border-bottom: 1px solid var(--soft); vertical-align: top; height: 32px; }
#grid .c-drag, #grid .c-done, #grid .c-id { line-height: 30px; }

/* Cells are real inputs that only look like inputs when hovered or focused. */
#grid td input, #grid td select {
  width: 100%;
  height: 31px;
  padding: 4px 7px;
  border: 1px solid transparent;
  border-radius: 0;
  background: transparent;
  text-overflow: ellipsis;
}
#grid td select { appearance: none; cursor: pointer; }
#grid td input:hover, #grid td select:hover { border-color: var(--line); }
#grid td input:focus, #grid td select:focus { background: var(--panel); outline: 2px solid var(--accent); outline-offset: -2px; color: var(--text); }
#grid td input[readonly] { cursor: default; }
#grid td input[type='number'] { text-align: right; }
#grid td input[type='date'].blank:not(:focus):not(:hover) { color: transparent; }
#grid td input[type='date'].blank:not(:focus):not(:hover)::-webkit-calendar-picker-indicator { opacity: 0; }

.c-drag { text-align: center; box-shadow: inset 3px 0 0 var(--g-line, transparent); }
.gpill { max-width: 100%; padding: 1px 9px; overflow: hidden; border-radius: 10px; background: var(--g-bg); color: var(--g-text); font-size: 12px; font-weight: 600; white-space: nowrap; text-overflow: ellipsis; }
.task-line { display: flex; align-items: center; }
.task-line input { flex: 1; min-width: 0; }
.task-text { display: none; }
/* The description sits under the task name, in full unless it is long. */
.note-line { display: flex; align-items: baseline; gap: 6px; padding: 0 8px 7px; font-size: 13px; line-height: 1.4; color: color-mix(in srgb, var(--text) 72%, transparent); }
.note-line .more { flex: none; }
.note-text { min-width: 0; white-space: pre-wrap; overflow-wrap: anywhere; cursor: pointer; }
tr.done .note-line { color: var(--done-text); }
.detail textarea[data-field='notes'] { resize: vertical; }
.note-text.cut { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; }
.more { padding: 0; border: 0; background: none; color: var(--accent); font-size: 12px; text-decoration: underline; }
.thumbs { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0; }
.thumb { padding: 0; overflow: hidden; border-radius: 6px; line-height: 0; }
.thumb img { width: 84px; height: 84px; object-fit: cover; }
.open-btn { flex: none; display: flex; margin-right: 4px; padding: 4px; border-color: transparent; background: transparent; color: var(--line-strong); }
tr:hover .open-btn, .open-btn:focus-visible, tr.open .open-btn { color: var(--accent); border-color: var(--line); background: var(--panel); }
tr.open td { box-shadow: inset 0 1px 0 var(--accent), inset 0 -1px 0 var(--accent); }
tr.open td.c-drag { box-shadow: inset 3px 0 0 var(--g-line, transparent), inset 0 1px 0 var(--accent), inset 0 -1px 0 var(--accent); }
.swatch { flex: none; display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; padding: 0; border: 2px solid var(--g-line); border-radius: 50%; background: var(--g-bg); color: var(--g-text); font-size: 12px; font-weight: 700; }
.color-pop { position: fixed; inset: auto; margin: 0; width: 460px; max-width: calc(100vw - 16px); max-height: calc(100vh - 16px); overflow-y: auto; padding: 10px 12px 12px; background: var(--panel); border: 1px solid var(--line-strong); border-radius: 8px; color: var(--text); box-shadow: 0 10px 30px var(--shadow); }
.color-pop p { margin: 0 0 8px; }
.palette { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.palette button { display: flex; align-items: center; gap: 8px; padding: 4px 6px; border-color: transparent; text-align: left; }
.palette button:hover, .palette button[aria-pressed='true'] { border-color: var(--line-strong); }
.palette button[aria-pressed='true'] { background: var(--g-bg); }
.palette small { display: block; color: var(--muted); font-size: 11px; line-height: 1.1; }
.palette button.used > .swatch { opacity: 0.35; }
.handle { display: none; cursor: grab; color: var(--line-strong); font-size: 11px; letter-spacing: -2px; user-select: none; }
#grid.can-reorder .handle { display: inline; }
.c-id { white-space: nowrap; padding-left: 4px !important; }
.idlink { padding: 2px 5px; border-color: transparent; background: transparent; font-weight: 600; color: var(--accent); }
.cycle-flag { color: var(--amber); }
mark { padding: 0 1px; border-radius: 2px; background: var(--flash); color: inherit; }
.reading { padding: 2px 8px 8px; font-size: 13px; line-height: 1.45; color: var(--text); }
.reading p { margin: 0 0 4px; white-space: pre-wrap; overflow-wrap: anywhere; }
.reading b { color: var(--muted); font-size: 12px; }
.read-btn { flex: none; margin-right: 4px; padding: 1px 7px; border-radius: 10px; border-color: var(--line); background: var(--panel); color: var(--ok); font-size: 12px; font-weight: 600; white-space: nowrap; }
/* Priority and status cells: a pill or badge showing the computed value, under
   an invisible dropdown that sets the user's own. */
.pick { position: relative; display: flex; align-items: center; height: 31px; padding: 0 7px; border: 1px solid transparent; }
.pick:hover { border-color: var(--line); }
.pick:focus-within { outline: 2px solid var(--accent); outline-offset: -2px; }
#grid td .pick select { position: absolute; inset: 0; width: 100%; max-width: none; height: 100%; opacity: 0; }
#grid td input[type='checkbox'] { width: 16px; height: 16px; margin: 0 7px; padding: 0; vertical-align: middle; accent-color: var(--primary); cursor: pointer; }
.pill { padding: 1px 9px; border-radius: 10px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill:empty { display: none; }
.pill.high, .high { color: var(--red); background: var(--red-bg); }
.pill.medium, .medium { color: var(--amber); }
.pill.medium { background: var(--warn-bg); }
.pill.low { color: var(--muted); background: var(--soft); }
.c-deps { padding: 5px 4px 2px !important; }
.c-deps .chips { display: inline; }
.dep-edit { padding: 0 6px; border-color: transparent; background: transparent; color: var(--muted); }
.dep-edit:hover, .dep-edit:focus-visible { border-color: var(--line); background: var(--panel); }

.chip {
  margin: 1px 3px 1px 0;
  padding: 0 7px;
  border: 1px solid var(--chip-line);
  border-radius: 10px;
  background: var(--chip-bg);
  color: var(--chip-text);
  font-size: 12px;
  font-weight: 600;
}
.chip.done { border-color: var(--line); background: transparent; color: var(--muted); text-decoration: line-through; font-weight: 400; }

.badge { padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.ready { background: var(--ready-bg); color: var(--ready-text); }
.badge.blocked { background: var(--held-bg); color: var(--held-text); }
.badge.doing { background: var(--chip-bg); color: var(--chip-text); }
.badge.done { color: var(--done-text); }

/* Row states, as in the spreadsheet. */
tr.blocked td { background: var(--blocked-fill); }
tr.done td { color: var(--done-text); }
tr.done .idlink { color: var(--done-text); }
tr.first-done td { border-top: 3px solid var(--line); }
#grid td.c-due.overdue { background: var(--overdue-fill); color: var(--overdue-text); font-weight: 600; }
tr.drop-before td { box-shadow: inset 0 2px 0 var(--accent); }
tr.drop-after td { box-shadow: inset 0 -2px 0 var(--accent); }
tr.flash td { animation: flash 1.6s ease-out; }
@keyframes flash { from { background-color: var(--flash); } }

.elsewhere { margin: 18px 16px 0; }
.elsewhere h3 { margin: 0 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.hit { padding: 8px 10px; background: var(--panel); border-bottom: 1px solid var(--soft); }
.hit > button { margin-right: 6px; padding: 1px 8px; border-radius: 10px; color: var(--accent); font-size: 12px; font-weight: 600; }
.hit .reading { padding: 4px 0 0; }

.empty { margin: 0 16px; padding: 28px; background: var(--panel); text-align: center; color: var(--muted); }
.hint { margin: 10px 16px 24px; font-size: 12px; }

/* ---------- task detail panel ---------- */

.detail {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 5;
  width: var(--detail-width);
  padding: calc(14px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right)) calc(24px + env(safe-area-inset-bottom)) 16px;
  overflow-y: auto;
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: -6px 0 18px var(--shadow);
}
.detail header, .dialog header { display: flex; align-items: center; justify-content: space-between; }
.detail h2, .dialog h2 { margin: 0; font-size: 18px; }
.detail h3, .dialog h3 { margin: 16px 0 6px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.detail header button, .dialog header button { border-color: transparent; font-size: 20px; line-height: 1; padding: 2px 8px; }
.detail label, .detail .field { display: grid; gap: 3px; margin-top: 10px; color: var(--muted); font-size: 12px; }
.detail label > *, .detail output { font-size: 14px; color: var(--text); }
.detail .grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.detail output { padding: 5px 8px; border-radius: 5px; background: var(--bg); font-weight: 600; }
.detail output.high { color: var(--red); background: var(--red-bg); }
.detail output.medium { color: var(--amber); }
.detail textarea { resize: vertical; }
.d-ready { margin: 14px 0 0; line-height: 1.9; }
.d-ready .late { display: block; }
.dep { display: flex; align-items: center; gap: 4px; padding: 2px 0; }
.dep span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dep button:not(.chip) { padding: 0 7px; border-color: transparent; color: var(--muted); }
.d-related .fix { padding: 5px 0; }
.d-related .fix p { margin: 2px 0 0; font-size: 13px; line-height: 1.45; color: var(--text); white-space: pre-wrap; overflow-wrap: anywhere; }
.d-related .more { margin-top: 2px; }
.detail textarea::placeholder { color: var(--muted); opacity: 0.8; }
.d-photos { margin-bottom: 6px; }
.d-delete { margin-top: 24px; padding-top: 14px; border-top: 1px solid var(--line); }

/* ---------- dependency picker ---------- */

.picker {
  position: fixed;
  z-index: 20;
  width: 400px;
  max-width: calc(100vw - 16px);
  padding: 8px;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  box-shadow: 0 10px 30px var(--shadow);
}
.picker input { width: 100%; }
.picker ul { max-height: 280px; margin: 6px 0 0; padding: 0; overflow-y: auto; list-style: none; }
.picker li { display: flex; align-items: center; gap: 6px; padding: 4px 6px; border-radius: 5px; cursor: pointer; }
.picker li.hi { background: var(--highlight); }
.picker li.none { color: var(--muted); cursor: default; }
.picker .tick { width: 14px; color: var(--accent); font-weight: 700; }
.picker .title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker em { font-style: normal; font-size: 11px; color: var(--muted); white-space: nowrap; }
.picker em.loop { color: var(--amber); font-weight: 600; }
.picker-hint { margin: 6px 2px 0; font-size: 11px; color: var(--muted); }

/* ---------- dialogs ---------- */

.dialog {
  width: min(700px, calc(100vw - 24px));
  max-height: calc(100vh - 40px);
  padding: 18px 22px 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
}
.dialog.small { width: min(460px, calc(100vw - 24px)); }
.dialog::backdrop { background: rgb(20 19 17 / 0.45); }
.dialog section { padding-bottom: 14px; border-bottom: 1px solid var(--soft); }
.dialog section:last-child { border-bottom: 0; padding-bottom: 0; }
.dialog p { margin: 6px 0; }
.dialog ul { margin: 4px 0 8px; padding-left: 20px; }
.dialog .row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 8px 0; }
.dialog .stack, .dialog.small form { display: grid; gap: 10px; justify-items: start; }
.dialog .stack label, .dialog.small form label { display: grid; gap: 3px; width: 100%; max-width: 420px; color: var(--muted); }
.dialog label > input, .dialog label > select { color: var(--text); }
.dialog .inline { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.dialog .inline input { flex: 1; min-width: 0; max-width: 360px; }
.dialog .check { display: flex; align-items: center; gap: 5px; }
.dialog input.days { width: 64px; }
.dialog input.prefix { width: 72px; text-transform: uppercase; }
.plain { width: 100%; border-collapse: collapse; }
.plain th { padding: 4px 6px; text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; }
.plain td { padding: 3px 6px; border-top: 1px solid var(--soft); }
.plain td.actions { text-align: right; }
.plain td input:not([type='checkbox']) { width: 100%; }
.plain td input.prefix { width: 72px; }
.plain td.actions input { width: 170px; }
#import-file { max-width: 100%; }
.dest { min-width: 0; margin: 12px 0 0; padding: 8px 12px 10px; border: 1px solid var(--line); border-radius: 8px; }
.dest legend { padding: 0 4px; color: var(--muted); font-size: 12px; }
.dest .check { padding: 3px 0; }
.dest #import-new { margin: 2px 0 6px 22px; }
.dest .inline { flex: 1 1 100%; min-width: 0; }
.dest .inline select { flex: 1; min-width: 0; max-width: 360px; }
.no-list button { margin: 4px; }
.plain td.actions input.new-name { width: 150px; }
.plain td.actions input.reset-url { width: 100%; margin: 4px 0; font-size: 12px; }
.plain td.actions span { display: block; text-align: left; }
.trash { list-style: none; padding: 0 !important; }
.trash li { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 10px; padding: 4px 0; border-top: 1px solid var(--soft); }
.steps { margin: 12px 0; padding-left: 22px; }
.steps li { margin: 8px 0; line-height: 1.5; }
.steps svg { vertical-align: -3px; color: var(--accent); }
.photo-view { width: min(900px, calc(100vw - 24px)); }
.photo-view h2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.photo-view img { display: block; max-width: 100%; max-height: calc(100vh - 190px); margin: 12px auto; border-radius: 6px; }
.members { list-style: none; padding: 0 !important; }
.members li { display: flex; align-items: center; justify-content: space-between; max-width: 360px; padding: 3px 0; }
#import-report { margin-top: 10px; }
#import-report li .error-text { margin-left: 8px; }

/* Pull down to refresh (home-screen app on an iPhone): a spinner in the
   space that opens above the list as it is pulled down. */
.pull {
  position: fixed;
  top: env(safe-area-inset-top);
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  pointer-events: none;
}
.pull span { width: 26px; height: 26px; border: 3px solid var(--muted); border-top-color: transparent; border-radius: 50%; }
body.settling #app, body.settling .pull { transition: transform 0.25s ease-out, opacity 0.25s; }
body.refreshing #app { transform: translateY(56px); transition: transform 0.2s ease-out; }
body.refreshing .pull { display: flex !important; opacity: 1 !important; transform: translateY(15px); }
body.refreshing .pull span { animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  inset: auto auto calc(18px + env(safe-area-inset-bottom)) 50%;
  transform: translateX(-50%);
  margin: 0;
  max-width: min(560px, calc(100vw - 32px));
  padding: 10px 16px;
  border: 0;
  border-radius: 8px;
  background: var(--text);
  color: var(--bg);
  box-shadow: 0 8px 24px var(--shadow);
}
.toast button { margin-left: 8px; padding: 2px 10px; border-color: currentColor; background: transparent; color: inherit; font-weight: 600; }

/* ---------- phones ----------
   The same table, restyled: each row becomes a card showing the task, its
   status, area, priority, due date and dependencies. Everything else is one
   tap away in the detail panel, which takes the whole screen. */

@media (max-width: 720px) {
  input, select, textarea { font-size: 16px; } /* smaller text makes iOS zoom in on focus */
  button { padding: 7px 12px; }

  /* One header line: the list, Undo, and a menu holding the rest. */
  .top { position: relative; gap: 6px; padding: calc(8px + env(safe-area-inset-top)) calc(10px + env(safe-area-inset-right)) 8px calc(10px + env(safe-area-inset-left)); }
  #list-select { flex: 1; min-width: 0; max-width: none; }
  .top { flex-wrap: wrap; }
  .top .spacer, .save-status:empty { display: none; }
  .save-status.failed, #retry-btn { order: 9; } /* a save problem gets a line of its own */
  .save-status.failed { flex-basis: 100%; }
  #menu-btn { display: block; }
  .menu { display: none; position: absolute; top: 100%; right: 10px; z-index: 30; flex-direction: column; gap: 6px; min-width: 180px; padding: 8px; background: var(--panel); border: 1px solid var(--line-strong); border-radius: 8px; box-shadow: 0 10px 30px var(--shadow); }
  .top.menu-open .menu { display: flex; }
  .menu button { text-align: left; }
  .now-bar { padding: 10px 10px 0; }
  .elsewhere { margin: 14px 10px 0; }

  .summary { flex-wrap: nowrap; gap: 8px; padding: 10px 10px 2px; overflow-x: auto; }
  .tile { flex: none; min-width: 104px; padding: 7px 10px; }
  .tile b { font-size: 19px; }
  .banner { margin: 8px 10px 0; }

  .toolbar { padding: 10px 10px 0; }
  .tabs { flex: 1 1 100%; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; }
  .tabs button { flex: none; }
  #search { flex: 1; width: auto; min-width: 0; }
  #sort-select { display: block; }

  .add { flex-wrap: wrap; padding: 10px; }
  .add label { display: none; }
  .add #add-area { flex: 1 1 60%; }
  .add #add-task { flex: 1 1 60%; min-width: 0; max-width: none; }

  #grid { display: block; width: auto; min-width: 0; margin: 0 10px; }
  #grid colgroup, #grid thead { display: none; }
  #grid tbody { display: block; }
  #grid tr {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 8px;
    padding: 6px 8px 8px;
    border-bottom: 1px solid var(--soft);
  }
  #grid tr::after { content: ''; order: 4; flex-basis: 100%; } /* ends the first line */
  #grid td { display: block; height: auto; padding: 0 !important; border: 0 !important; background: transparent; }
  #grid .c-drag, #grid .c-hrs { display: none; }
  #grid .c-id { order: 1; }
  #grid .c-task { order: 2; flex: 1 1 0; min-width: 0; }
  #grid .c-done { order: 0; }
  #grid .c-state { order: 3; }
  #grid td input[type='checkbox'] { width: 22px; height: 22px; margin: 0 2px 0 0; }
  #grid .c-area { order: 6; }
  #grid .c-prio { order: 7; }
  #grid .c-prio:has(.pill:empty) { display: none; } /* no priority: set one in the detail panel */
  .pick { height: 36px; padding: 0 2px; }
  .pill { padding: 3px 11px; font-size: 14px; }
  #grid .c-due { order: 8; border-radius: 6px; }
  #grid .c-deps { order: 9; }

  #grid td input, #grid td select { height: 36px; }
  #grid td select, #grid .c-due input { width: auto; max-width: 42vw; border-color: var(--line); border-radius: 6px; }
  #grid .c-due:has(input.blank) { display: none; } /* a date is added in the detail panel */
  #grid td select { padding: 4px 8px; }
  .idlink { padding: 6px 6px; }
  .dep-edit { padding: 4px 10px; border-color: var(--line); }

  #grid tr { border-left: 4px solid var(--g-line, transparent); }
  .gpill { padding: 3px 11px; font-size: 14px; }
  .open-btn { padding: 8px; color: var(--accent); }
  /* The whole task name, wrapped; tapping it opens the task for editing. */
  .task-line { align-items: flex-start; }
  .task-line input { display: none; }
  .note-line { padding: 0 2px 4px; font-size: 14px; }
  .task-text { display: block; flex: 1; min-width: 0; padding: 7px 2px; overflow-wrap: anywhere; cursor: pointer; }
  #grid tr.open td { box-shadow: none; }
  #grid tr.blocked { background: var(--blocked-fill); }
  #grid tr.first-done { border-top: 3px solid var(--line); }
  .empty { margin: 0 10px; }
  .hint { display: none; }

  body.with-detail { padding-right: 0; overflow: hidden; }
  .detail { width: 100%; border-left: 0; padding-left: calc(16px + env(safe-area-inset-left)); }
  .detail header button { font-size: 26px; padding: 4px 12px; }

  .dialog { padding: 14px 14px 18px; }
  .palette { grid-template-columns: 1fr 1fr; }
  .plain .next { display: none; }
  .plain td { padding: 3px 3px; }
  .plain td.actions input { width: 100%; }
}
