:root {
  --bg: #f5f5f3;
  --surface: #ffffff;
  --text: #18181b;
  --muted: #8b8b92;
  --line: #e6e6e3;
  --soft: #ececea;
  --panel: #ebebe8;
  --accent: #3d5afe;
  --on-accent: #ffffff;
  --danger: #e5484d;
  --r: 14px;
  --top: env(safe-area-inset-top);
  --bottom: env(safe-area-inset-bottom);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111113;
    --surface: #26262a;
    --panel: #19191c;
    --text: #ededf0;
    --muted: #7d7d85;
    --line: #2a2a2e;
    --soft: #26262a;
    --accent: #6b82ff;
    --on-accent: #0b0b0d;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", system-ui, sans-serif;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input, textarea { font: inherit; color: inherit; }
svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; display: block; }

.icon { width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; flex: none; }
.icon:active { background: var(--soft); }
.icon.accent { background: var(--accent); color: var(--on-accent); }
.icon.danger { color: var(--danger); }

/* ---------- вход ---------- */
#login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
#login form { width: 100%; max-width: 320px; display: grid; gap: 12px; justify-items: center; }
#login img { margin-bottom: 12px; }
#login input, #login button { width: 100%; height: 52px; border-radius: var(--r); padding: 0 16px; }
#login input { background: var(--surface); border: 1px solid var(--line); outline: none; }
#login input:focus { border-color: var(--accent); }
#code { text-align: center; }
#code:not(:placeholder-shown) { letter-spacing: .3em; }
#login button { background: var(--accent); color: var(--on-accent); font-weight: 600; }
#login-err { margin: 0; min-height: 20px; color: var(--danger); font-size: 14px; }
.shake { animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

/* ---------- приложение ---------- */
#app { height: 100dvh; display: flex; flex-direction: column; }
header { display: flex; align-items: center; gap: 4px; padding: calc(max(var(--top), 20px) + 10px) 8px 0 16px; }
#boards { flex: 1; display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 4px 0; }
#boards::-webkit-scrollbar { display: none; }
.chip { flex: none; height: 36px; padding: 0 14px; border-radius: 18px; background: var(--soft); font-weight: 600; font-size: 15px; white-space: nowrap; }
.chip.on { background: var(--text); color: var(--bg); }
.chip.add { width: 36px; padding: 0; display: grid; place-items: center; }
.chip.add svg { width: 18px; height: 18px; }

#tabs { display: flex; gap: 20px; padding: 12px 16px 0; overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--line); }
#tabs::-webkit-scrollbar { display: none; }
.tab { flex: none; display: flex; align-items: center; gap: 6px; padding: 8px 0 10px; color: var(--muted); font-weight: 600; font-size: 15px; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab.on { color: var(--text); border-color: var(--dot, var(--text)); }
.tab.add { padding: 6px 0 8px; }
.tab.add svg { width: 18px; height: 18px; }

#cols { flex: 1; display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; overscroll-behavior-x: contain; }
#cols::-webkit-scrollbar { display: none; }
.col { flex: none; width: 100%; scroll-snap-align: start; overflow-y: auto; padding: 12px 12px 96px; }
.panel { min-height: 100%; background: linear-gradient(var(--tint, transparent), var(--tint, transparent)) var(--panel); border-radius: 18px; padding: 8px; display: flex; flex-direction: column; }
.col.over .panel { background: linear-gradient(var(--tint2), var(--tint2)) var(--panel); box-shadow: inset 0 0 0 2px var(--dot); }
.head { display: none; align-items: center; gap: 8px; padding: 6px 8px 10px; font-weight: 700; font-size: 15px; text-align: left; }
.head i, .tab i { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.head i, .tab i { background: var(--dot); }
.head b, .tab b { font-weight: 500; color: var(--muted); }
.list { display: flex; flex-direction: column; gap: 8px; flex: 1; }
.empty { margin: 40px auto; color: var(--muted); }
.list:has(.card) .empty { display: none; }
.add-col { display: none; }

.card { display: flex; align-items: flex-start; background: var(--surface); border-radius: 12px; min-height: 52px; box-shadow: 0 1px 2px rgb(0 0 0 / .06); user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: manipulation; }
.card .body { flex: 1; min-width: 0; padding: 14px 4px 12px 14px; display: grid; gap: 8px; cursor: pointer; }
.card .t { white-space: pre-wrap; overflow-wrap: anywhere; -webkit-touch-callout: none; }
.card .icon { margin: 4px; color: var(--muted); }
.card.done .t { color: var(--muted); text-decoration: line-through; text-decoration-color: var(--line); }
.card.new { animation: pop .18s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } }
.card.placeholder { background: var(--tint, #3d5afe24); box-shadow: none; }
.card.placeholder > * { visibility: hidden; }
.ghost { position: fixed; left: 0; top: 0; z-index: 50; pointer-events: none; box-shadow: 0 14px 34px rgb(0 0 0 / .22); transition: none; }
body.dragging, body.dragging * { cursor: grabbing !important; user-select: none; -webkit-user-select: none; }
.tab.over { color: var(--accent); }

#composer { position: fixed; left: 0; right: 0; bottom: 0; display: flex; gap: 8px; padding: 10px 16px calc(var(--bottom) + 10px); background: var(--bg); border-top: 1px solid var(--line); }
#new { flex: 1; min-width: 0; height: 44px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); padding: 0 14px; outline: none; }
#new:focus { border-color: var(--accent); }

/* ---------- лист снизу ---------- */
dialog { border: 0; padding: 0; margin: auto 0 0; width: 100%; max-width: 100%; max-height: 85dvh; background: var(--surface); color: var(--text); border-radius: 20px 20px 0 0; }
dialog::backdrop { background: rgb(0 0 0 / .35); }
dialog[open] { animation: up .2s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: .5; } }
#sheet-body { padding: 8px 16px calc(var(--bottom) + 16px); display: grid; gap: 12px; }
.grab { width: 36px; height: 4px; border-radius: 2px; background: var(--line); margin: 4px auto 4px; }
.field { width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 12px; padding: 12px 14px; outline: none; resize: none; }
.field:focus { border-color: var(--accent); }
.row { display: flex; gap: 8px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.row .grow { flex: 1; }
.spacer { flex: 1; }
.label { font-size: 13px; color: var(--muted); margin: 8px 0 -4px; }
.btn { height: 44px; padding: 0 16px; border-radius: 12px; background: var(--soft); font-weight: 600; }
.btn.accent { background: var(--accent); color: var(--on-accent); }
.btn.danger { color: var(--danger); }
.colrow .field { padding: 10px 12px; }
.colrow .icon { width: 40px; height: 40px; }

/* ---------- широкий экран ---------- */
@media (min-width: 900px) {
  header { padding: 16px 24px 0; }
  #tabs { display: none; }
  #cols { scroll-snap-type: none; gap: 12px; padding: 16px 24px 0; }
  .col { width: 300px; padding: 0 0 100px; }
  .col .panel { min-height: 0; }
  .head { display: flex; }
  .empty { margin: 4px 8px 8px; font-size: 14px; }
  .add-col { display: block; }
  .add-col .panel { width: 100%; min-height: 0; flex-direction: row; align-items: center; justify-content: center; gap: 6px; height: 48px; color: var(--muted); font-weight: 600; background: transparent; box-shadow: inset 0 0 0 1.5px var(--line); }
  .add-col .panel:hover { color: var(--text); background: var(--panel); }
  #composer { left: 50%; right: auto; width: 560px; transform: translateX(-50%); bottom: 16px; border: 1px solid var(--line); border-radius: 18px; padding: 8px; }
  dialog { margin: auto; max-width: 440px; border-radius: 20px; }
}

/* ---------- фото, «Все», архив ---------- */
.chip.all { background: transparent; box-shadow: inset 0 0 0 1.5px var(--line); }
.chip.all.on { background: var(--text); box-shadow: none; }
.thumbs { display: flex; gap: 6px; align-items: center; }
.thumbs img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; background: var(--soft); pointer-events: none; }
.thumbs span { font-size: 13px; color: var(--muted); font-weight: 600; }
.tag { justify-self: start; justify-self: start; font-size: 12px; font-weight: 600; color: var(--muted); background: var(--soft); border-radius: 6px; padding: 2px 7px; }
.card.leaving { transition: transform .22s, opacity .22s; transform: translateX(40px); opacity: 0; }
.archive-all { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 4px; background: transparent; color: var(--muted); }
.archive-all:active { background: var(--soft); }
.archive-all svg { width: 18px; height: 18px; }
#arch { width: auto; padding: 0 10px; gap: 6px; display: flex; align-items: center; color: var(--muted); }
#arch b { font-weight: 700; font-size: 15px; color: var(--text); }
#arch b:empty { display: none; }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 96px)); gap: 8px; }
.gimg { position: relative; aspect-ratio: 1; }
.gimg img { width: 100%; height: 100%; object-fit: cover; border-radius: 10px; cursor: zoom-in; background: var(--soft); }
.gimg button { position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; border-radius: 13px; background: rgb(0 0 0 / .55); color: #fff; display: grid; place-items: center; }
.gimg button svg { width: 14px; height: 14px; }
.gadd { aspect-ratio: 1; border-radius: 10px; background: var(--soft); display: grid; place-items: center; color: var(--muted); cursor: pointer; }

#composer { flex-direction: column; gap: 8px; }
#composer .bar { display: flex; gap: 8px; align-items: center; }
#pick { cursor: pointer; color: var(--muted); }
#pending { display: none; gap: 8px; overflow-x: auto; }
#composer.has-pending #pending { display: flex; }
.pthumb { position: relative; flex: none; }
.pthumb img { width: 56px; height: 56px; object-fit: cover; border-radius: 10px; display: block; }
.pthumb button { position: absolute; top: -6px; right: -6px; width: 22px; height: 22px; border-radius: 11px; background: var(--text); color: var(--bg); display: grid; place-items: center; }
.pthumb button svg { width: 12px; height: 12px; }

#viewer { margin: auto; max-width: 100vw; max-height: 100dvh; background: transparent; border-radius: 0; }
#viewer::backdrop { background: rgb(0 0 0 / .9); }
#viewer img { max-width: 100vw; max-height: 100dvh; display: block; object-fit: contain; }

.big { display: flex; align-items: baseline; gap: 10px; padding: 4px 4px 8px; }
.big b { font-size: 56px; line-height: 1; font-weight: 800; letter-spacing: -.02em; }
.big span { color: var(--muted); font-weight: 600; }
.alist { display: grid; gap: 2px; max-height: 55dvh; overflow-y: auto; }
.arow { display: flex; align-items: center; gap: 8px; padding: 8px 4px; border-bottom: 1px solid var(--line); }
.at { overflow-wrap: anywhere; }
.am { font-size: 13px; color: var(--muted); }
.btn svg { display: inline-block; vertical-align: -4px; margin-right: 8px; }
.arow .grow { flex: 1; min-width: 0; }

/* ---------- матрица ---------- */
#cols.is-matrix { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; min-width: 0; gap: 8px; padding: 12px 12px 92px; overflow: hidden; scroll-snap-type: none; }
body.mx #tabs { display: none; }
.matrix { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; min-height: 0; }
.quad { background: linear-gradient(var(--tint), var(--tint)) var(--panel); border-radius: 16px; padding: 8px; display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.quad.over, .tray.over { background: linear-gradient(var(--tint2, #3d5afe38), var(--tint2, #3d5afe38)) var(--panel); box-shadow: inset 0 0 0 2px var(--dot, var(--accent)); }
.qh { display: flex; align-items: center; gap: 6px; font-weight: 700; font-size: 13px; padding: 2px 4px 8px; }
.qh i { width: 8px; height: 8px; border-radius: 50%; background: var(--dot); flex: none; }
.qh b { font-weight: 500; color: var(--muted); }
.quad .list { overflow-y: auto; gap: 6px; min-height: 0; }
.card.mini { min-height: 0; border-radius: 10px; }
.card.mini .body { padding: 9px 10px; gap: 6px; }
.card.mini .t { font-size: 14px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.card.mini .thumbs img { width: 34px; height: 34px; border-radius: 6px; }
.card.mini .tag { font-size: 11px; padding: 1px 6px; }
.tray { background: var(--panel); border-radius: 16px; padding: 8px; }
.tray .list { flex-direction: row; overflow-x: auto; gap: 8px; min-height: 52px; align-items: stretch; scrollbar-width: none; }
.tray .card { flex: none; width: 150px; }
.quad .empty { display: none; }
.tray .empty { margin: auto; font-size: 13px; }
#mode { color: var(--muted); }

/* въезд доски при переключении */
#cols.in-r { animation: inR .26s cubic-bezier(.2, .8, .2, 1); }
#cols.in-l { animation: inL .26s cubic-bezier(.2, .8, .2, 1); }
@keyframes inR { from { transform: translateX(48px); opacity: .3; } }
@keyframes inL { from { transform: translateX(-48px); opacity: .3; } }
@media (prefers-reduced-motion: reduce) { #cols.in-r, #cols.in-l { animation: none; } }

/* ---------- календарь ---------- */
header .icon { width: 40px; }
#cal.on { color: var(--accent); }
#cal, #arch { color: var(--muted); }
body.cal #tabs, body.cal #mode { display: none; }
#cols.is-cal { display: block; overflow-y: auto; scroll-snap-type: none; padding: 8px 16px 110px; }
.calbar { display: flex; justify-content: center; padding: 4px 0 12px; }
.seg { display: inline-flex; background: var(--soft); border-radius: 12px; padding: 3px; }
.seg button { height: 34px; padding: 0 16px; border-radius: 9px; font-weight: 600; font-size: 14px; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgb(0 0 0 / .08); }
.month { background: var(--surface); border-radius: 18px; padding: 8px 8px 10px; max-width: 520px; margin: 0 auto; }
.mhead { display: flex; align-items: center; justify-content: space-between; padding: 0 0 4px; }
.mhead b { font-size: 17px; }
.grid7 { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 2px; }
.dow { text-align: center; font-size: 12px; color: var(--muted); font-weight: 600; padding: 4px 0; }
.day { height: 46px; border-radius: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-weight: 600; font-variant-numeric: tabular-nums; }
.day.out { color: var(--muted); opacity: .45; }
.day.today span { color: var(--accent); }
.day.sel { background: var(--text); color: var(--bg); opacity: 1; }
.day.sel.today span { color: var(--bg); }
.day i { display: flex; gap: 3px; height: 5px; }
.day i b { width: 5px; height: 5px; border-radius: 50%; background: var(--dot); }
.agenda { max-width: 520px; margin: 12px auto 0; display: grid; gap: 8px; }
.agenda .label { margin: 8px 4px 0; font-weight: 700; font-size: 15px; color: var(--text); }
.agenda .empty { margin: 24px auto; }
.ev { display: flex; align-items: stretch; gap: 12px; text-align: left; background: var(--surface); border-radius: 14px; padding: 12px 14px; }
.ev .time::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--dot); margin-right: 6px; vertical-align: 2px; }
.ev .time { width: 58px; }
.ev .time { width: 44px; flex: none; font-weight: 700; font-variant-numeric: tabular-nums; font-size: 15px; line-height: 1.25; }
.ev .time small { font-weight: 500; color: var(--muted); }
.ev .et { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.ev .et small { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }
.ev.done .et { color: var(--muted); text-decoration: line-through; }
.ev.past { opacity: .5; }
.meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.due { font-size: 12px; font-weight: 600; color: var(--muted); }
.due.hot { color: var(--danger); }
.duerow { color: var(--muted); }
.duerow svg { flex: none; }
.row input[type="time"] { width: 104px; flex: none; }
#sheet-body { grid-template-columns: minmax(0, 1fr); }
.row input[type="date"] { min-width: 0; }
.row input[type="time"] { width: 96px; padding-left: 10px; padding-right: 6px; }
.wd .chip { flex: 1; min-width: 0; padding: 0; }

/* приоритет: цвет квадрата матрицы */
.q1 { --qc: #e5484d; } .q2 { --qc: #3d5afe; } .q3 { --qc: #f5a524; } .q4 { --qc: #8b8b92; }
.card.q1 { background: linear-gradient(#e5484d10, #e5484d10) var(--surface); }
.prio { font-size: 12px; font-weight: 700; color: var(--qc); }
.prio::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--qc); margin-right: 5px; vertical-align: 1px; }
.prios { gap: 6px; flex-wrap: wrap; }
.prios .chip { height: 32px; padding: 0 12px; font-size: 13px; }
.prios .chip.on { background: var(--qc); color: #fff; }

/* важные события */
.day.imp:not(.sel) { background: #e5484d1f; }
.day.imp:not(.sel) span { color: #e5484d; }
.day.imp.sel { background: #e5484d; color: #fff; }
.ev.imp { background: linear-gradient(#e5484d14, #e5484d14) var(--surface); }
.ev em { display: flex; align-items: center; gap: 4px; font-style: normal; font-size: 12px; font-weight: 700; color: #e5484d; margin-bottom: 2px; }
.ev em svg, .impchip svg { width: 14px; height: 14px; }
.impchip { display: flex; align-items: center; gap: 6px; }
.impchip.on { background: #e5484d; color: #fff; }
.imps { max-width: 520px; margin: 0 auto 12px; display: grid; gap: 8px; }
.impc { display: flex; align-items: center; gap: 12px; text-align: left; background: #e5484d; color: #fff; border-radius: 18px; padding: 12px 16px; }
.impc b { font-size: 40px; line-height: 1; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.impc span { font-size: 13px; font-weight: 700; opacity: .85; margin-left: -6px; align-self: flex-end; padding-bottom: 4px; }
.impc i { font-style: normal; font-weight: 700; flex: 1; min-width: 0; }
.impc small { display: block; font-weight: 500; opacity: .85; font-size: 13px; }

/* исполнитель: одна доска, без календаря и настроек колонок */
body.artem #cal { display: none; }
body.artem .head, body.artem #boards .chip { pointer-events: none; }
