:root {
  --bg: #0e1124; --bg2: #151936; --panel: #1a1f3d; --panel2: #212748; --line: #2c3360; --text: #e7e9f5; --muted: #9aa0c3;
  --accent: #8b5cf6; --accent2: #6d3fe0; --accent-soft: rgba(139, 92, 246, .16); --ok: #34d399; --warn: #fbbf24; --err: #f87171;
  --blue: #60a5fa; --radius: 10px; --shadow: 0 6px 20px rgba(0, 0, 0, .25);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; --mono: ui-monospace, "Cascadia Code", Consolas, monospace;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f5fb; --bg2: #eceefa; --panel: #ffffff; --panel2: #f6f6fd; --line: #dfe1f0; --text: #1b1d33; --muted: #646a8f;
    --accent-soft: rgba(139, 92, 246, .12); --shadow: 0 4px 14px rgba(30, 30, 80, .08); color-scheme: light;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 16px; font-weight: 650; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 650; }
code, .mono, pre { font-family: var(--mono); font-size: 13px; }
:not(pre) > code { background: var(--panel2); border: 1px solid var(--line); padding: 1px 5px; border-radius: 5px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.hidden { display: none !important; }
.grow { flex: 1; min-width: 0; }
.pad { padding: 6px 12px; }
.center { text-align: center; }

/* ── Каркас ── */
.layout { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.side { background: var(--bg2); border-right: 1px solid var(--line); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; gap: 10px; align-items: center; padding: 18px 16px; color: var(--text); font-weight: 700; }
.brand img { width: 34px; height: 34px; border-radius: 9px; }
.brand small, .auth-brand small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.side nav { flex: 1; display: flex; flex-direction: column; padding: 0 8px; gap: 2px; }
.side a { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: 8px; color: var(--text); }
.side a:hover { background: var(--panel2); text-decoration: none; }
.side a.on { background: var(--accent-soft); color: var(--accent); }
.side-title { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 14px 10px 4px; }
.side .count { margin-left: auto; font-size: 12px; color: var(--muted); }
.side-foot { padding: 10px 8px 16px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 2px; }
.side-foot form { padding: 2px 10px; }
.main { padding: 24px 28px 60px; min-width: 0; max-width: 1500px; }
.pkey { display: inline-block; font: 600 11px/1 var(--mono); background: var(--accent-soft); color: var(--accent); padding: 4px 6px; border-radius: 6px; letter-spacing: .03em; }
.pkey.big { font-size: 15px; padding: 7px 9px; }
a.pkey:hover { text-decoration: none; }

/* ── Кнопки и формы ── */
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel2); color: var(--text); padding: 7px 14px;
  border-radius: 8px; font: inherit; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent2); }
.btn.danger, .danger { color: var(--err); }
.btn.danger:not(.ghost):not(.tiny) { background: var(--err); border-color: var(--err); color: #fff; }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.tiny { padding: 2px 8px; font-size: 12px; border-radius: 6px; }
.btn.wide { width: 100%; justify-content: center; padding: 10px; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; font: inherit; }
.link.danger { color: var(--err); }
input, select, textarea { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { resize: vertical; min-height: 80px; }
input[type=checkbox] { width: auto; accent-color: var(--accent); }
input[type=file] { padding: 6px; background: transparent; }
input.upper { text-transform: uppercase; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 14px; }
label.check { flex-direction: row; align-items: center; gap: 8px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; align-items: end; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
form.inline { display: inline; }
.inline select { width: auto; padding: 3px 6px; font-size: 13px; }
.copy-row { display: flex; gap: 8px; }

/* ── Блоки ── */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.panel.highlight { border-color: var(--accent); background: var(--accent-soft); }
.two-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; align-items: start; }
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; border: 1px solid; }
.flash.ok { border-color: rgba(52, 211, 153, .4); background: rgba(52, 211, 153, .1); }
.flash.err { border-color: rgba(248, 113, 113, .45); background: rgba(248, 113, 113, .1); }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.page-head h1 { margin: 0; display: flex; align-items: center; gap: 10px; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg a { padding: 6px 12px; color: var(--muted); }
.seg a.on { background: var(--accent-soft); color: var(--accent); }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 10px; }
.empty { text-align: center; padding: 40px 20px; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 500; padding: 8px; border-bottom: 1px solid var(--line); }
.table td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr.muted td { opacity: .6; }
.actions-cell { display: flex; gap: 6px; flex-wrap: wrap; }
.event { padding: 5px 0; border-bottom: 1px dashed var(--line); display: flex; gap: 8px; flex-wrap: wrap; align-items: baseline; }
.row-link { display: flex; gap: 10px; align-items: center; padding: 8px 6px; border-radius: 8px; color: var(--text); }
.row-link:hover { background: var(--panel2); text-decoration: none; }
details summary { cursor: pointer; color: var(--muted); }
details.desc { margin-bottom: 12px; }
progress.meter { width: 100%; height: 8px; accent-color: var(--accent); }

/* ── Метки и бейджи ── */
.badge { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 99px; background: var(--panel2); border: 1px solid var(--line); white-space: nowrap; }
.st-new { color: var(--blue); } .st-progress { color: var(--warn); } .st-review { color: var(--accent); } .st-done { color: var(--ok); } .st-hold { color: var(--muted); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: currentColor; margin-right: 6px; }
.pr-high { color: #fb923c; border-color: rgba(251, 146, 60, .4); }
.pr-urgent { color: #fff; background: var(--err); border-color: var(--err); }
.pr-low { color: var(--muted); }
.label { display: inline-block; font-size: 12px; padding: 1px 7px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); margin-right: 4px; }
.person.agent { color: var(--accent); }
.card-ref { font: 600 12px var(--mono); color: var(--muted); white-space: nowrap; }
.due { font-size: 12px; color: var(--warn); }

/* ── Главная ── */
.grid-projects { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px; margin-bottom: 20px; }
.project-tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 6px; color: var(--text); }
.project-tile:hover { border-color: var(--accent); text-decoration: none; }
.tile-name { font-weight: 600; }

/* ── Фильтры и доска ── */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.filters select, .filters input { width: auto; }
.filters input.grow { min-width: 220px; }
.board { display: grid; grid-template-columns: repeat(5, minmax(200px, 1fr)); gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.column { background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 200px; }
.column header { padding: 10px 12px; font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 4px; border-bottom: 1px solid var(--line); }
.column header .count { color: var(--muted); font-weight: 400; margin-left: 4px; }
.column header .add { margin-left: auto; font-size: 18px; line-height: 1; padding: 0 6px; border-radius: 6px; }
.column header .add:hover { background: var(--panel2); text-decoration: none; }
.column-body { padding: 8px; display: flex; flex-direction: column; gap: 8px; flex: 1; }
.column.drop { outline: 2px dashed var(--accent); outline-offset: -4px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 9px; padding: 10px; display: flex; flex-direction: column; gap: 6px; box-shadow: var(--shadow); }
.card[draggable=true] { cursor: grab; }
.card.dragging { opacity: .45; }
.card-link { color: var(--text); display: block; }
.card-link:hover { text-decoration: none; }
.card-link:hover .card-title { color: var(--accent); }
.card-title { display: block; font-weight: 500; margin-top: 2px; word-break: break-word; }
.claude-mark { float: right; font-size: 13px; }
.card-meta { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.card-meta:empty { display: none; }
.card-foot { display: flex; justify-content: space-between; align-items: center; gap: 6px; font-size: 13px; }

/* ── Задача ── */
.task-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 18px; align-items: start; }
.task-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; }
.task-head h1 { margin: 0; word-break: break-word; }
.task-side { position: sticky; top: 16px; }
.side-fields { display: flex; flex-direction: column; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 3px; }
.field select { padding: 5px 8px; }
.notes h2 { margin-top: 8px; }
.note { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 10px; }
.note.by-claude { border-left: 3px solid var(--accent); }
.note header { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; margin-bottom: 4px; }
.note form.stack { margin-top: 10px; }
.danger-zone summary { color: var(--err); }
.history .event { border: 0; padding: 3px 0; }

/* ── Markdown ── */
.md { word-wrap: break-word; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p, .md ul, .md ol { margin: 0 0 10px; }
.md h1, .md h2, .md h3 { margin: 16px 0 8px; }
.md blockquote { margin: 0 0 10px; padding: 4px 12px; border-left: 3px solid var(--line); color: var(--muted); }
.md table { border-collapse: collapse; margin-bottom: 10px; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 5px 10px; }
.md img { max-width: 100%; }
.code-block { position: relative; margin: 0 0 12px; }
.code-block pre { margin: 0; padding: 14px; border-radius: 9px; overflow-x: auto; background: #0b0d1c; border: 1px solid var(--line); color: #e6edf3; line-height: 1.45; }
.code-lang { position: absolute; top: 6px; left: 12px; font: 11px var(--mono); color: #8b92b8; }
.code-lang + .copy + pre { padding-top: 26px; }
.copy { position: absolute; top: 6px; right: 8px; font-size: 12px; padding: 2px 8px; border-radius: 6px; border: 1px solid #2c3360; background: #151936; color: #c7cbe6; cursor: pointer; opacity: 0; transition: opacity .15s; }
.code-block:hover .copy, .copy:focus { opacity: 1; }
pre.lines { counter-reset: line; }

/* ── Файлы ── */
.files { display: flex; flex-direction: column; gap: 8px; margin: 8px 0; }
.file { display: flex; align-items: center; gap: 10px; padding: 6px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel2); }
.thumb img { width: 64px; height: 48px; object-fit: cover; border-radius: 6px; display: block; }
.file-icon { width: 64px; text-align: center; font-size: 24px; }
.file-icon:hover { text-decoration: none; }
.file-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.file-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inline-upload { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.inline-upload input { width: auto; flex: 1; }
img.preview { max-width: 100%; max-height: 80vh; border-radius: 8px; }
.file-title { word-break: break-all; }

/* ── Вход ── */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(800px 500px at 10% 0%, rgba(80, 60, 200, .35), transparent), radial-gradient(700px 500px at 100% 100%, rgba(20, 110, 130, .3), transparent), var(--bg); }
.auth-box { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px; box-shadow: var(--shadow); }
.auth-brand { display: flex; gap: 12px; align-items: center; font-weight: 700; margin-bottom: 20px; }
.auth-brand img { width: 42px; height: 42px; border-radius: 11px; }
.code-input { font: 600 26px var(--mono); letter-spacing: .3em; text-align: center; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: static; height: auto; }
  .side nav { flex-direction: row; flex-wrap: wrap; }
  .side-title { width: 100%; }
  .main { padding: 16px; }
  .task-layout { grid-template-columns: 1fr; }
  .task-side { position: static; }
  .board { grid-template-columns: repeat(5, 260px); }
}
