:root {
  --bg: #f4f5f2; --card: #ffffff; --text: #1d2420; --muted: #6b746f; --line: #e2e5df;
  --accent: #1f6f5c; --accent-soft: #e2f0eb; --danger: #b3261e;
  --k-n: #2e7d4f; --k-n-soft: #dcefe2; --k-night: #3550a8; --k-night-soft: #e0e7fa; --k-h: #b25f12; --k-h-soft: #fbe9d6; --k-o: #8a8f8c; --k-o-soft: #eceeec;
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121513; --card: #1c201e; --text: #e8ece9; --muted: #9aa39e; --line: #2c322f;
    --accent: #5fbf9f; --accent-soft: #1e3a31; --danger: #f2827a;
    --k-n: #6fcf94; --k-n-soft: #1f3a29; --k-night: #94aaf0; --k-night-soft: #222c4a; --k-h: #f0a85e; --k-h-soft: #3d2a17; --k-o: #9aa39e; --k-o-soft: #2a2e2c;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.4 -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 22px; margin: 4px 0 12px; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 18px 0 6px; }
small { color: var(--muted); display: block; font-size: 13px; }
[hidden] { display: none !important; }

#app { max-width: 720px; margin: 0 auto; min-height: 100vh; }
header {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px; background: var(--bg); border-bottom: 1px solid var(--line);
}
header .who { flex: 1; min-width: 0; border: 0; background: none; text-align: left; padding: 4px 0; cursor: pointer; }
header .who b, header .who small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
header .who b { font-size: 14px; }
header .help { display: grid; place-items: center; text-decoration: none; font-weight: 700; border: 1px solid var(--line); border-radius: 50%; min-width: 34px; min-height: 34px; font-size: 16px; color: var(--muted); }
header .month { display: flex; align-items: center; gap: 2px; font-weight: 600; }
header .month span { min-width: 120px; text-align: center; }
main { padding: 12px 16px calc(90px + env(safe-area-inset-bottom)); }
nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5; display: flex; justify-content: center;
  background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
nav button { flex: 1; max-width: 144px; border: 0; background: none; padding: 8px 0 6px; color: var(--muted); }
nav button span { display: block; font-size: 20px; line-height: 1.2; }
nav button.on { color: var(--accent); }
nav button.on small { color: var(--accent); font-weight: 600; }

.btn {
  border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 10px 14px;
  min-height: 44px; cursor: pointer; font-weight: 500;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 14px; }
.icon { border: 0; background: none; font-size: 20px; min-width: 40px; min-height: 40px; cursor: pointer; color: var(--muted); border-radius: 10px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin: 10px 0; }
.row { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; }
.summary .total { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 8px; }
.due.open b, .due.open { color: var(--accent); }
.summary .due { font-size: 18px; margin-top: 4px; }
.worker-row { display: flex; width: 100%; text-align: left; align-items: center; justify-content: space-between; cursor: pointer; }
.worker-row .due { font-weight: 700; white-space: nowrap; }

.item {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; background: var(--card);
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin: 6px 0; min-height: 52px;
}
button.item { cursor: pointer; }
.item > div { flex: 1; min-width: 0; }
.item .sum { font-weight: 600; white-space: nowrap; }
.badge { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; font-weight: 700; flex: none; }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 8px 0; }
.toolbar select { flex: 1; min-width: 140px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 6px; }
.chips.wrap { flex-wrap: wrap; }
.chips button { border: 1px solid var(--line); background: var(--card); border-radius: 20px; padding: 7px 14px; white-space: nowrap; cursor: pointer; }
.chips button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.seg { display: flex; background: var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: none; border-radius: 9px; padding: 8px 10px; cursor: pointer; font-weight: 600; }
.seg button small { font-weight: 400; }
.seg button.on { background: var(--card); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.seg.small button { padding: 5px 12px; font-size: 14px; }
.seg.brush button { min-width: 42px; }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0; }
.empty { color: var(--muted); text-align: center; padding: 40px 16px; }

.k-n .k, .badge.k-n, .seg button.k-n.on { background: var(--k-n-soft); color: var(--k-n); }
.k-night .k, .badge.k-night, .seg button.k-night.on { background: var(--k-night-soft); color: var(--k-night); }
.k-h .k, .badge.k-h, .seg button.k-h.on { background: var(--k-h-soft); color: var(--k-h); }
.seg.special { margin-top: 8px; }
.k-o .k, .badge.k-o, .seg button.k-o.on { background: var(--k-o-soft); color: var(--k-o); }

.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin: 8px 0; }
.cal .wd { text-align: center; font-size: 12px; color: var(--muted); padding: 2px 0; }
.cal .wd.we { color: var(--danger); opacity: .7; }
.cal .day {
  aspect-ratio: 1 / 1.1; border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 3px;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 1px; cursor: pointer; min-width: 0; overflow: hidden;
}
.cal .day .n { font-size: 12px; color: var(--muted); align-self: flex-start; line-height: 1; }
.cal .day .k { font-weight: 700; font-size: 15px; border-radius: 7px; padding: 1px 7px; }
.cal .day .o { font-size: 9px; color: var(--muted); max-width: 100%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal .day.today { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.cal .day.k-n { background: var(--k-n-soft); border-color: transparent; }
.cal .day.k-night { background: var(--k-night-soft); border-color: transparent; }
.cal .day.k-h { background: var(--k-h-soft); border-color: transparent; }
.cal .day.k-o { background: var(--k-o-soft); border-color: transparent; }

.field { display: block; margin: 10px 0; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field input, .field select, .field textarea, .toolbar select, textarea.copy {
  width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 10px 12px; min-height: 44px;
}
input[type="file"] { padding: 8px; }
.pair { display: flex; gap: 10px; }
.pair .field { flex: 1; }
.check { display: flex; gap: 10px; align-items: flex-start; margin: 12px 0; cursor: pointer; }
.check input { width: 20px; height: 20px; flex: none; margin-top: 1px; }

.sheet-wrap { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, 0); transition: background .2s; display: flex; align-items: flex-end; justify-content: center; }
.sheet-wrap.show { background: rgba(0, 0, 0, .35); }
.sheet {
  background: var(--bg); width: 100%; max-width: 720px; max-height: 92vh; border-radius: 18px 18px 0 0; display: flex; flex-direction: column;
  transform: translateY(100%); transition: transform .2s ease-out; padding-bottom: env(safe-area-inset-bottom);
}
.sheet-wrap.show .sheet { transform: none; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 12px 4px 16px; }
.sheet-body { overflow-y: auto; padding: 0 16px 8px; }
.sheet-actions { display: flex; gap: 8px; padding: 10px 16px 14px; border-top: 1px solid var(--line); }
.sheet-actions .btn { flex: 1; }

.login { max-width: 340px; margin: 0 auto; padding: 18vh 20px 0; display: flex; flex-direction: column; gap: 12px; text-align: center; }
.login .logo { width: 72px; height: 72px; margin: 0 auto; }
.login h1 { margin-top: 4px; }
.login .hint { margin: 0 0 8px; }
.login input { border: 1px solid var(--line); background: var(--card); border-radius: 12px; padding: 12px 14px; min-height: 48px; }

.toast {
  position: fixed; left: 50%; bottom: calc(86px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); opacity: 0; z-index: 30;
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; transition: all .25s; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--danger); color: #fff; }

/* этап 2: журнал, фото, баннеры */
.banner { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--accent-soft);
  border-radius: 12px; padding: 8px 12px; margin: 6px 0; font-size: 14px; }
.banner.bad { background: #fde8e6; color: var(--danger); }
.thumbs { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.photo { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; background: var(--line); }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.photo.big { width: 100%; height: auto; aspect-ratio: 1; }
.photo.pdf { display: grid; place-items: center; text-decoration: none; color: var(--text); font-size: 12px; font-weight: 600; }
.photo.pdf.big { font-size: 20px; }
.att { position: relative; }
.att .icon { position: absolute; top: 2px; right: 2px; background: var(--card); min-width: 32px; min-height: 32px; }
.picker { flex: 1; margin: 10px 0; }
.note { white-space: pre-wrap; }
.item.entry { align-items: flex-start; }
small.market { color: var(--accent); }
.item.sub { margin-left: 18px; width: calc(100% - 18px); }
.badge.doc { background: var(--accent-soft); color: var(--accent); width: auto; min-width: 32px; padding: 0 6px; }
.row.small { font-size: 14px; border-bottom: 1px solid var(--line); padding: 5px 0; }
@media (prefers-color-scheme: dark) { .banner.bad { background: #3a1f1d; } }
