/* Telegram supplies the theme colours; fall back to a light scheme in a browser. */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #16213a);
  --hint: var(--tg-theme-hint-color, #7b8aa6);
  --card: var(--tg-theme-secondary-bg-color, #f3f5f9);
  --accent: var(--tg-theme-button-color, #1d3b8b);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --line: rgba(127, 143, 173, .35);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 12px 12px 32px;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

header { text-align: center; margin: 4px 0 14px; }
h1 { font-size: 19px; margin: 0; }
.sub { margin: 2px 0 0; color: var(--hint); font-size: 13px; }

h2 {
  font-size: 13px; text-transform: uppercase; letter-spacing: .6px;
  color: var(--hint); margin: 18px 2px 6px; font-weight: 600;
}
.count { font-weight: 400; text-transform: none; letter-spacing: 0; }
.km { color: var(--hint); font-weight: 400; font-size: 12px; }

.card {
  background: var(--card);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 8px;
}

label { display: block; font-size: 12px; color: var(--hint); margin-bottom: 10px; }
label:last-child { margin-bottom: 0; }

input[type=text], input[type=date], input[type=search], select, textarea {
  width: 100%;
  margin-top: 4px;
  padding: 9px 10px;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 8px;
  -webkit-appearance: none;
}
textarea { resize: vertical; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.row { display: flex; gap: 8px; }
.row > label { flex: 1; min-width: 0; }

.task-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 8px;
}
.task-no { font-size: 12px; font-weight: 700; color: var(--hint); letter-spacing: .5px; }
.remove {
  border: none; background: transparent; color: var(--hint);
  font-size: 16px; padding: 2px 6px; cursor: pointer;
}

/* ---- Sub-sections inside a task: people, materials, photos, drawing ---- */
.sub {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}
.sub-head {
  font-size: 11px; font-weight: 700; letter-spacing: .5px;
  text-transform: uppercase; color: var(--hint);
  margin-bottom: 8px;
}
.sub-head .km { text-transform: none; letter-spacing: 0; }

/* A repeating person or material row. The remove button sits in its own column
   so it never wraps under the inputs on a narrow phone. */
.line {
  display: grid;
  gap: 6px;
  margin-bottom: 8px;
  align-items: start;
}
.line.person { grid-template-columns: 1fr 1fr 30px; }
.line.person .p-name { grid-column: 1 / 3; }
.line.person .x-line { grid-column: 3; grid-row: 1 / 3; }
.line.material { grid-template-columns: 1fr 88px 30px; }
.line input { margin-top: 0; }

/* A worker chosen from the crew list: one compact line, not three inputs — a
   40-name task has to stay scrollable. Its values sit in hidden inputs. */
.line.person.picked {
  grid-template-columns: 1fr 30px;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
}
.who { min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.who-name { font-size: 14px; color: var(--text); }
.who-meta {
  font-size: 11px; color: var(--hint);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.line.person.picked .x-line { align-self: center; height: 30px; }

/* The two manpower buttons share a row: pick from the list, or type a name in. */
.btn-row { display: flex; gap: 8px; }
.btn-row > button { flex: 1; }

.x-line {
  align-self: stretch;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: transparent;
  color: var(--hint);
  font-size: 13px;
  padding: 0;
  cursor: pointer;
}

button.ghost {
  width: 100%;
  padding: 11px;
  font: inherit;
  color: var(--accent);
  background: transparent;
  border: 1px dashed var(--line);
  border-radius: 10px;
  cursor: pointer;
}
button.ghost.sm { padding: 8px; font-size: 13px; }
button.primary {
  width: 100%;
  margin-top: 14px;
  padding: 13px;
  font: inherit; font-weight: 600;
  color: var(--accent-text);
  background: var(--accent);
  border: none;
  border-radius: 10px;
  cursor: pointer;
}
button:disabled { opacity: .5; }

.thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.thumb { position: relative; width: 72px; }
.thumb img {
  width: 72px; height: 72px; object-fit: cover;
  border-radius: 8px; display: block; border: 1px solid var(--line);
}
.thumb .file {
  width: 72px; height: 72px; border-radius: 8px; border: 1px solid var(--line);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; color: var(--hint); text-align: center; padding: 4px;
  word-break: break-all; overflow: hidden;
}
.thumb .x {
  position: absolute; top: -6px; right: -6px;
  width: 20px; height: 20px; border-radius: 50%;
  border: none; background: #c0392b; color: #fff;
  font-size: 12px; line-height: 20px; padding: 0; cursor: pointer;
}

/* ---- Crew picker ---- */
/* A bottom sheet rather than a centre dialog: it sits above the thumb on a phone,
   and the list gets the full height left over once the search and filters are in. */
.modal {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(0, 0, 0, .45);
  display: flex; align-items: flex-end;
}
.modal[hidden] { display: none; }
.sheet {
  width: 100%; max-height: 88vh;
  display: flex; flex-direction: column;
  background: var(--bg);
  border-radius: 16px 16px 0 0;
  padding: 14px 14px calc(14px + env(safe-area-inset-bottom));
}
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px; font-size: 15px;
}
.sheet-head .x-line { width: 30px; height: 30px; flex: none; }
.sheet-tools { display: flex; align-items: center; gap: 8px; margin: 10px 0 4px; }
.sheet-tools .ghost { width: auto; flex: none; }
.sheet-tools .count { margin-left: auto; font-size: 12px; color: var(--hint); }
.sheet .primary { flex: none; }

/* Filter by position — the fastest cut when a site has 100 people. */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  padding: 6px 11px; font: inherit; font-size: 13px;
  color: var(--text); background: var(--card);
  border: 1px solid transparent; border-radius: 999px; cursor: pointer;
}
.chip.on {
  background: var(--accent); color: var(--accent-text);
  border-color: var(--accent); font-weight: 600;
}

.picker-list { flex: 1; overflow-y: auto; margin-top: 8px; -webkit-overflow-scrolling: touch; }
.pick-row {
  display: flex; align-items: center; gap: 12px;
  margin: 0; padding: 10px 4px;
  border-bottom: 1px solid var(--line);
  font-size: inherit; color: var(--text);
}
.pick-row input[type=checkbox] { width: 22px; height: 22px; flex: none; accent-color: var(--accent); }
/* Someone another task already has: visible, so the rule explains itself, but not
   selectable. One worker cannot be in two places at once. */
/* Dimmed, not struck through — a line through Khmer script cuts across the glyphs
   and costs more legibility than it buys. The label below carries the meaning. */
.pick-row.taken { opacity: .55; }
.who-taken { font-size: 11px; color: var(--accent); }
.picker-list .empty { color: var(--hint); text-align: center; padding: 24px 0; }

/* ---- Menu hub ---- */
.menu-item {
  display: flex; align-items: flex-start; gap: 14px;
  background: var(--card); border-radius: 14px;
  padding: 16px; margin-bottom: 12px;
  text-decoration: none; color: var(--text);
}
.mi-icon { font-size: 26px; line-height: 1.1; flex: none; }
.mi-text { min-width: 0; }
.mi-title { display: block; font-weight: 600; font-size: 16px; }
.mi-title .km { font-weight: 400; }
.mi-desc { display: block; font-size: 13px; color: var(--hint); margin-top: 3px; line-height: 1.4; }

/* ---- Worker list management ---- */
.listing { display: block; margin: 14px 2px 8px; font-size: 12px; color: var(--hint); }
.worker-row {
  display: block; width: 100%; text-align: left;
  background: var(--card); border: 1px solid transparent; border-radius: 12px;
  padding: 11px 12px; margin-bottom: 8px; font: inherit; color: var(--text);
  cursor: pointer;
}
.worker-row.retired { opacity: .55; }
.w-name { display: block; font-weight: 600; font-size: 15px; }
.w-meta { display: block; font-size: 12px; color: var(--hint); margin-top: 2px; }
.w-site { display: block; font-size: 11px; color: var(--accent); margin-top: 3px; }

/* The editor sheet scrolls its fields, keeping Save reachable without hunting. */
.sheet-body { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.switch { display: flex; align-items: center; gap: 10px; margin-top: 12px; font-size: 14px; color: var(--text); }
.switch input { width: 22px; height: 22px; flex: none; accent-color: var(--accent); margin: 0; }
.hint { font-size: 12px; color: var(--hint); margin: 6px 0 0; line-height: 1.45; }
#list .empty { color: var(--hint); text-align: center; padding: 24px 0; }

/* ---- Completion form ---- */
.plan-row {
  display: block; width: 100%; text-align: left;
  background: var(--card); border: 1px solid transparent; border-radius: 12px;
  padding: 11px 12px; margin-bottom: 8px; font: inherit; color: var(--text);
  cursor: pointer;
}
.plan-row.used { opacity: .55; }
.pr-no { display: block; font-weight: 700; font-size: 13px; color: var(--accent); }
.pr-site { display: block; margin-top: 1px; }
.pr-meta { display: block; font-size: 12px; color: var(--hint); margin-top: 2px; }

.plan-banner { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.plan-no { font-weight: 700; color: var(--accent); }
.plan-meta { font-size: 12px; color: var(--hint); margin-top: 2px; }
button.link {
  background: none; border: none; color: var(--accent);
  font: inherit; font-size: 13px; text-decoration: underline; cursor: pointer; padding: 0;
}

.task .planned { font-size: 12px; color: var(--hint); }
.task .c-desc { font-size: 15px; font-weight: 600; margin-bottom: 10px; line-height: 1.35; }

/* Three-way status picker. */
.seg { display: flex; gap: 6px; }
.seg button {
  flex: 1; padding: 9px 4px; font: inherit; font-size: 13px;
  color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; cursor: pointer;
}
.seg button.on {
  background: var(--accent); color: var(--accent-text);
  border-color: var(--accent); font-weight: 600;
}

.pct-row { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.pct-range { flex: 1; }
.pct-val { min-width: 42px; text-align: right; font-weight: 700; }

.issue-wrap { margin-top: 10px; margin-bottom: 0; }

.status { text-align: center; min-height: 18px; font-size: 13px; margin: 12px 0 0; }
.status.err { color: #c0392b; }
.status.ok { color: #1e8449; }
