:root {
  --bg: #0f1115;
  --bg2: #161922;
  --panel: #1b1f2a;
  --panel2: #222736;
  --border: #2a3040;
  --text: #e7e9ee;
  --muted: #8a8f9c;
  --accent: #3b82f6;
  --accent-text: #fff;
  --danger: #ef4444;
  --ok: #22c55e;
  --warn: #f59e0b;
  --report: #22c55e;
  --shadow: 0 8px 30px rgba(0, 0, 0, .45);
  --radius: 10px;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f5f8;
    --bg2: #eceef3;
    --panel: #ffffff;
    --panel2: #f6f7fa;
    --border: #dfe2ea;
    --text: #1d2130;
    --muted: #6b7180;
    --shadow: 0 8px 30px rgba(20, 25, 40, .15);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  display: flex; flex-direction: column;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
input, textarea, select, button { font: inherit; color: inherit; }
input, textarea, select {
  background: var(--bg2); border: 1px solid var(--border); border-radius: 7px; padding: 7px 9px; width: 100%;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; min-height: 70px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.btn {
  border: 1px solid var(--border); background: var(--panel2); border-radius: 7px; padding: 6px 12px;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { color: var(--text); }
.btn.sm { padding: 3px 8px; font-size: 12px; }

/* --- Вход --- */
.login {
  margin: auto; width: 300px; display: flex; flex-direction: column; gap: 10px;
  background: var(--panel); padding: 28px; border-radius: 14px; border: 1px solid var(--border);
}
.login h1 { margin: 0; font-size: 26px; }
.login p { margin: 0 0 8px; }
.login-or { text-align: center; font-size: 12px; }
.btn.tg-login { background: #229ed9; border-color: #229ed9; color: #fff; text-align: center; }
.btn.tg-login:hover { text-decoration: none; filter: brightness(1.1); }
.error { color: var(--danger); min-height: 1em; }

/* --- Шапка --- */
.top {
  display: flex; align-items: center; gap: 14px; padding: 10px 16px; border-bottom: 1px solid var(--border);
  background: var(--bg2); flex-wrap: wrap;
}
.logo { font-weight: 800; font-size: 18px; color: var(--text); letter-spacing: .5px; }
.logo:hover { text-decoration: none; }
#crumbs { display: flex; gap: 8px; align-items: center; min-width: 0; }
#crumbs .sep { color: var(--muted); }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
#search { width: 220px; }
.top-link { color: var(--muted); }
.me { display: flex; align-items: center; gap: 6px; }

main { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* --- Аватары --- */
.av {
  width: 22px; height: 22px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700; color: #fff; flex: none; text-transform: uppercase;
}
.av.agent { border-radius: 6px; }
.av.lg { width: 30px; height: 30px; font-size: 12px; }

/* --- Обзор --- */
.home { padding: 20px; display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 20px; overflow: auto; }
.home h2 { font-size: 15px; margin: 0 0 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }
.projects { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 12px; }
.pcard {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px;
  cursor: pointer; border-top: 3px solid var(--c); display: flex; flex-direction: column; gap: 8px;
}
.pcard:hover { border-color: var(--muted); border-top-color: var(--c); }
.pcard h3 { margin: 0; font-size: 16px; }
.pcard .desc { color: var(--muted); font-size: 12.5px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pcard.new { align-items: center; justify-content: center; color: var(--muted); border-style: dashed; border-top-width: 1px; min-height: 120px; }
.counts { display: flex; gap: 4px; flex-wrap: wrap; font-size: 12px; }
.cnt { background: var(--bg2); border-radius: 5px; padding: 1px 7px; color: var(--muted); }
.cnt b { color: var(--text); font-weight: 600; }
.cnt.red { background: rgba(239, 68, 68, .15); color: var(--danger); }
.subs { display: flex; gap: 4px; flex-wrap: wrap; font-size: 12px; }
.sub {
  border: 1px solid var(--border); border-left: 3px solid var(--c, var(--muted)); border-radius: 5px; padding: 1px 7px;
  color: var(--text); text-decoration: none; white-space: nowrap;
}
.sub:hover { border-color: var(--muted); border-left-color: var(--c, var(--muted)); }
.sub b { font-weight: 600; color: var(--muted); }
.sub .red { color: var(--danger); }
.lbl.sp { background: var(--bg2); color: var(--muted); border-left: 3px solid var(--c, var(--muted)); }
.bar { display: flex; height: 4px; border-radius: 2px; overflow: hidden; background: var(--bg2); }
.bar span { display: block; }
.side-block { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 16px; }
.tlist { display: flex; flex-direction: column; gap: 6px; }
.titem { display: flex; gap: 8px; align-items: center; padding: 6px 8px; border-radius: 7px; cursor: pointer; }
.titem:hover { background: var(--panel2); }
.titem .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--bg2); color: var(--muted); white-space: nowrap; }

/* --- Лента --- */
.feed { display: flex; flex-direction: column; gap: 10px; }
.ev { display: flex; gap: 9px; align-items: flex-start; }
.ev .ev-main { flex: 1; min-width: 0; }
.ev .ev-head { font-size: 12.5px; color: var(--muted); }
.ev .ev-head b { color: var(--text); font-weight: 600; }
.ev .ev-head a { cursor: pointer; }
.ev .ev-body {
  margin-top: 4px; background: var(--panel2); border: 1px solid var(--border); border-radius: 8px; padding: 8px 11px;
  overflow-wrap: anywhere;
}
.ev.report .ev-body { border-left: 3px solid var(--report); }
.ev.blocked .ev-body { border-left: 3px solid var(--danger); }
.ev-kind { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; margin-left: 4px; }
.ev.report .ev-kind { color: var(--report); }
.ev.blocked .ev-kind { color: var(--danger); }

/* --- Доска --- */
.board-bar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; flex-wrap: wrap; }
.board-bar h1 { font-size: 18px; margin: 0; display: flex; align-items: center; gap: 8px; }
.board-bar .dot { width: 12px; height: 12px; border-radius: 3px; background: var(--c); }
.board-bar .filters { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.board-bar select, .board-bar input { width: auto; padding: 5px 8px; }
.board { flex: 1; min-height: 0; display: flex; gap: 12px; padding: 0 16px 16px; overflow-x: auto; }
.column {
  flex: 0 0 290px; display: flex; flex-direction: column; background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); max-height: 100%;
}
.col-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px 6px; font-weight: 600; }
.col-head .n { color: var(--muted); font-weight: 400; }
.col-head .btn { margin-left: auto; }
.col-list { flex: 1; overflow-y: auto; padding: 4px 8px 8px; display: flex; flex-direction: column; gap: 7px; min-height: 60px; }
.col-add { padding: 0 8px 8px; }
.col-add textarea { min-height: 54px; margin-bottom: 6px; }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; cursor: grab;
  border-left: 3px solid var(--pc, transparent); display: flex; flex-direction: column; gap: 6px; user-select: none;
}
.card:hover { border-color: var(--muted); border-left-color: var(--pc, var(--muted)); }
.card.blocked { box-shadow: inset 0 0 0 1px var(--danger); }
.card .ttl { overflow-wrap: anywhere; }
.card .meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; font-size: 11.5px; color: var(--muted); }
.card .meta .grow { flex: 1; }
.card .id { font-variant-numeric: tabular-nums; }
.lbl { font-size: 11px; padding: 0 6px; border-radius: 4px; background: rgba(59, 130, 246, .15); color: #7fb0ff; }
.badge-block { font-size: 11px; padding: 0 6px; border-radius: 4px; background: rgba(239, 68, 68, .18); color: var(--danger); font-weight: 600; }
.due.over { color: var(--danger); font-weight: 600; }
.ghost-card { opacity: .35; }
.chosen-card { box-shadow: var(--shadow); }
.hidden { display: none !important; }
.done-more { text-align: center; font-size: 12px; color: var(--muted); padding: 4px; }

.pri-urgent { --pc: var(--danger); }
.pri-high { --pc: var(--warn); }
.pri-normal { --pc: transparent; }
.pri-low { --pc: #64748b; }

/* --- Модалка --- */
.overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .55); display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px; overflow-y: auto; z-index: 50;
}
.modal {
  background: var(--panel); border: 1px solid var(--border); border-radius: 14px; width: 100%; max-width: 920px;
  box-shadow: var(--shadow); position: relative;
}
.modal.narrow { max-width: 480px; }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-head .x { margin-left: auto; }
.modal-body { padding: 18px; }
.task-grid { display: grid; grid-template-columns: minmax(0, 1fr) 240px; gap: 22px; }
.title-input { font-size: 19px; font-weight: 600; background: transparent; border-color: transparent; padding: 4px 6px; margin-left: -7px; }
.title-input:hover { border-color: var(--border); }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin: 18px 0 8px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.desc-view { min-height: 40px; padding: 8px 10px; border-radius: 8px; border: 1px dashed transparent; cursor: text; overflow-wrap: anywhere; }
.desc-view:hover { border-color: var(--border); }
.desc-view.empty { color: var(--muted); }
.desc-edit textarea { min-height: 180px; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.row-btns { display: flex; gap: 8px; margin-top: 8px; align-items: center; }
.side label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }
.side label:first-child { margin-top: 0; }
.check { display: flex !important; align-items: center; gap: 8px; color: var(--text) !important; cursor: pointer; font-size: 13px !important; }
.check input { width: auto; }
.side .facts { font-size: 12px; color: var(--muted); margin-top: 14px; display: flex; flex-direction: column; gap: 3px; }
.side .danger-zone { margin-top: 16px; display: flex; gap: 8px; flex-wrap: wrap; }
.comment-box { margin-top: 14px; }
.comment-box textarea { min-height: 80px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 7px; overflow: hidden; }
.seg button { border: 0; background: transparent; padding: 5px 10px; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--panel2); color: var(--text); }
.form-grid { display: flex; flex-direction: column; gap: 10px; }
.form-grid label { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }

/* --- Markdown --- */
.md p { margin: 0 0 8px; }
.md p:last-child { margin-bottom: 0; }
.md h4 { margin: 10px 0 6px; font-size: 14.5px; }
.md ul, .md ol { margin: 0 0 8px; padding-left: 20px; }
.md code { background: var(--bg2); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; font-family: ui-monospace, Consolas, monospace; }
.md pre { background: var(--bg2); padding: 9px 11px; border-radius: 7px; overflow-x: auto; margin: 0 0 8px; }
.md pre code { background: none; padding: 0; }

/* --- Участники --- */
.page { padding: 20px; max-width: 1000px; width: 100%; margin: 0 auto; overflow: auto; }
.page h1 { font-size: 20px; margin: 0 0 16px; }
table.list { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
table.list th, table.list td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); }
table.list th { font-size: 12px; color: var(--muted); font-weight: 600; }
table.list tr:last-child td { border-bottom: 0; }
table.list tr.off td { opacity: .5; }
.who { display: flex; align-items: center; gap: 8px; }
.secret { background: var(--bg2); border: 1px solid var(--warn); border-radius: 8px; padding: 12px; margin: 14px 0; }
.secret code, pre.snippet { font-family: ui-monospace, Consolas, monospace; font-size: 12.5px; overflow-wrap: anywhere; }
pre.snippet { background: var(--bg2); padding: 10px; border-radius: 7px; white-space: pre-wrap; margin: 6px 0 12px; }

#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--border);
  padding: 9px 16px; border-radius: 8px; box-shadow: var(--shadow); opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 100;
}
#toast.show { opacity: 1; }
#toast.err { border-color: var(--danger); color: var(--danger); }

@media (max-width: 900px) {
  .home { grid-template-columns: 1fr; }
  .task-grid { grid-template-columns: 1fr; }
  #search { width: 140px; }
  .overlay { padding: 0; }
  .modal { border-radius: 0; min-height: 100%; }
}
@media (max-width: 560px) {
  .top { padding: 8px 12px; gap: 8px; }
  .top-link, .me { display: none; }
  .logo { font-size: 15px; }
  .board { padding: 0 12px 12px; }
  .column { flex-basis: 85vw; }
  .home, .page { padding: 16px; }
}
/* Архив проектов */
.tabs { display: flex; gap: 4px; margin: 0 0 12px; border-bottom: 1px solid var(--border); }
.tabs a { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); padding: 4px 10px 8px; border-bottom: 2px solid transparent; margin-bottom: -1px; text-decoration: none; }
.tabs a:hover { color: var(--text); }
.tabs a.on { color: var(--text); border-bottom-color: var(--accent); }
.tabs a b { font-weight: 600; color: var(--muted); }
.projects.archived .pcard { opacity: .8; border-top-style: dashed; }
.projects.archived .pcard:hover { opacity: 1; }
.archive-note { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 10px 16px 0; padding: 8px 12px; border-radius: 8px; border: 1px dashed var(--warn); background: var(--bg2); font-size: 13px; }
.archive-note .btn { margin-left: auto; }

/* --- Картинки (1.6.0) --- */
.thumbs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.thumb { position: relative; }
.thumb img { width: 92px; height: 92px; object-fit: cover; display: block; border-radius: 7px; border: 1px solid var(--border); background: var(--panel2); }
.side .thumb img { width: 70px; height: 70px; }
.thumb-x {
  position: absolute; top: 3px; right: 3px; width: 20px; height: 20px; padding: 0; border: 0; border-radius: 50%;
  background: rgba(0, 0, 0, .65); color: #fff; font-size: 11px; line-height: 20px; cursor: pointer; opacity: 0; transition: opacity .15s;
}
.thumb:hover .thumb-x, .comment-box .thumb-x { opacity: 1; }
.md .md-img { display: inline-block; }
.md .md-img img { max-width: 100%; max-height: 360px; border-radius: 7px; border: 1px solid var(--border); display: block; margin: 4px 0; }
.lightbox {
  position: fixed; inset: 0; z-index: 200; background: rgba(0, 0, 0, .88); display: flex; align-items: center; justify-content: center;
  cursor: zoom-out; padding: 20px;
}
.lightbox img { max-width: 100%; max-height: calc(100vh - 70px); border-radius: 6px; box-shadow: var(--shadow); }
.lightbox .lb-open { position: absolute; bottom: 14px; color: #fff; opacity: .8; font-size: 13px; }
.lightbox .lb-open:hover { opacity: 1; }

/* --- Лимиты нейронок (главная) --- */
.limits .lim-agent { margin-top: 8px; }
.limits .lim-agent:first-of-type { margin-top: 0; }
.limbar { height: 6px; background: var(--bg2); border-radius: 3px; overflow: hidden; margin: 3px 0 6px; }
.limbar span { display: block; height: 100%; }
.limbar .green { background: var(--ok); }
.limbar .orange { background: var(--warn); }
.limbar .red { background: var(--danger); }
.limits .lim-policy { margin-top: 8px; }
.lim-form { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 6px; margin-top: 8px; }
.lim-field { display: flex; flex-direction: column; gap: 2px; color: var(--muted); }
.lim-field input { padding: 4px 6px; }
