:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel2: #1e222b;
  --border: #2a2f3a;
  --text: #e6e8ec;
  --muted: #9aa1ad;
  --accent: #5b8def;
  --accent-text: #ffffff;
  --ok: #3fb67b;
  --warn: #e0a526;
  --danger: #d9534f;
  --focus: rgba(91, 141, 239, 0.35);
  --radius: 10px;
  color-scheme: dark;
}
@media (prefers-color-scheme: light) {
  :root {
    --bg: #f5f6f8; --panel: #ffffff; --panel2: #f0f2f5; --border: #dde1e7; --text: #1b1e24;
    --muted: #5f6673; --focus: rgba(91, 141, 239, 0.25); color-scheme: light;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 14px; }
h2 { font-size: 17px; margin: 22px 0 10px; }
h3 { font-size: 15px; margin: 16px 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.hidden { display: none !important; }
.warn { color: var(--warn); }
.danger-text { color: var(--danger); }
.ok-text { color: var(--ok); }

/* навигация */
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--panel); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 4px; padding: 0 16px; min-height: 52px; overflow-x: auto;
}
.topbar .brand { font-weight: 700; margin-right: 12px; white-space: nowrap; }
.topbar a.nav { color: var(--muted); padding: 8px 10px; border-radius: 8px; white-space: nowrap; }
.topbar a.nav:hover { background: var(--panel2); text-decoration: none; color: var(--text); }
.topbar a.nav.active { color: var(--text); background: var(--panel2); }
.topbar form { margin: 0; }
.count-badge { background: var(--accent); color: var(--accent-text); border-radius: 10px; padding: 0 7px; font-size: 12px; margin-left: 4px; }

.container { max-width: 1240px; margin: 0 auto; padding: 18px 16px 80px; }

/* сообщения */
.messages { list-style: none; padding: 0; margin: 0 0 14px; }
.messages li { background: var(--panel2); border-left: 3px solid var(--ok); padding: 8px 12px; border-radius: 6px; margin-bottom: 6px; }
.messages li.error { border-color: var(--danger); }

/* элементы */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.card + .card { margin-top: 12px; }
.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; white-space: nowrap;
  background: color-mix(in srgb, var(--c, #8b8f98) 22%, transparent); color: var(--text);
  border: 1px solid color-mix(in srgb, var(--c, #8b8f98) 55%, transparent);
}
.tag { display: inline-block; padding: 0 6px; border-radius: 4px; background: var(--panel2); font-size: 12px; color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center; cursor: pointer;
  padding: 7px 12px; min-height: 36px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--panel2); color: var(--text); font: inherit; font-size: 14px; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); text-decoration: none; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-danger { color: var(--danger); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 3px 8px; min-height: 28px; font-size: 13px; }
kbd { font: 11px/1 ui-monospace, monospace; border: 1px solid var(--border); border-radius: 4px; padding: 2px 4px; color: var(--muted); }
.btn kbd { border-color: currentColor; color: inherit; opacity: 0.7; }

input[type=text], input[type=search], input[type=number], input[type=date], input[type=datetime-local],
input[type=password], input[type=email], select, textarea {
  font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px; min-height: 36px; max-width: 100%;
}
textarea { width: 100%; resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus); border-color: var(--accent); }
label { display: block; font-size: 13px; color: var(--muted); margin: 8px 0 4px; }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px; }

/* таблицы */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; background: var(--panel2); }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--panel2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.bar { height: 8px; border-radius: 4px; background: var(--accent); min-width: 2px; }
.ci { color: var(--muted); font-size: 12px; white-space: nowrap; }

/* фильтры и вкладки */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.tabs a { padding: 5px 10px; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); font-size: 13px; }
.tabs a.active { color: var(--text); border-color: var(--accent); }
.filters { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.filters input[type=search] { flex: 1 1 220px; }
.filters select, .filters input { font-size: 13px; }
.bulkbar { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin: 10px 0; }
.pager { display: flex; gap: 8px; align-items: center; margin-top: 12px; }

/* «Сегодня» */
.today-head { display: flex; gap: 14px; flex-wrap: wrap; align-items: baseline; margin-bottom: 8px; }
.stat { font-size: 13px; color: var(--muted); }
.stat b { color: var(--text); font-size: 18px; margin-right: 3px; }
.banner { background: color-mix(in srgb, var(--warn) 15%, var(--panel)); border: 1px solid var(--warn); border-radius: var(--radius); padding: 8px 12px; margin-bottom: 12px; }
.section-title { display: flex; align-items: baseline; gap: 8px; margin: 22px 0 8px; font-size: 15px; }
.section-title .n { color: var(--muted); font-weight: 400; }
.trow {
  background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 10px; scroll-margin-top: 70px;
}
.trow.focused { border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus); }
.trow.done { padding: 8px 14px; color: var(--muted); border-style: dashed; }
.trow-head { display: flex; gap: 8px; flex-wrap: wrap; align-items: baseline; }
.trow-head .name { font-weight: 600; font-size: 16px; color: var(--text); }
.trow-head .due { margin-left: auto; font-size: 13px; color: var(--muted); }
.trow-head .due.overdue { color: var(--danger); }
.history { font-size: 13px; color: var(--muted); margin-top: 2px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--border); background: var(--panel2); color: var(--text); font: inherit; font-size: 14px; min-height: 36px;
}
.chip .t { font-size: 11px; font-weight: 700; color: var(--muted); }
.chip.selected { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.chip.dead { opacity: 0.45; text-decoration: line-through; }
.chip.copied::after { content: "скопировано"; font-size: 11px; color: var(--ok); }
.chip-link { padding: 5px 7px; color: var(--muted); }
.chip-group { display: inline-flex; gap: 4px; max-width: 100%; }
.chip-group .chip:first-child { min-width: 0; overflow: hidden; }
.trow textarea { min-height: 96px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 8px; }
.actions select { min-height: 36px; font-size: 13px; }
.reply-box { margin-top: 10px; padding: 10px; border: 1px dashed var(--border); border-radius: 8px; }
.radio-chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.radio-chips label { margin: 0; }
.radio-chips input { position: absolute; opacity: 0; pointer-events: none; }
.radio-chips span { display: inline-block; padding: 5px 10px; border-radius: 999px; border: 1px solid var(--border); color: var(--text); cursor: pointer; font-size: 13px; }
.radio-chips input:checked + span { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 20%, transparent); }
.ask { display: none; margin-top: 8px; padding: 8px 10px; border-radius: 8px; background: color-mix(in srgb, var(--accent) 16%, var(--panel)); }
.trow.asking .ask { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.draft-note { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 4px; color: var(--accent); }
.draft-note .btn { min-height: 24px; padding: 0 8px; }
.missing { font-size: 12px; color: var(--warn); margin-top: 4px; }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }

/* карточка */
.card-grid { display: grid; grid-template-columns: 330px minmax(0, 1fr) 300px; gap: 14px; align-items: start; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 4px 10px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { border-left: 2px solid var(--border); padding: 4px 0 12px 12px; position: relative; }
.timeline li.in { border-color: var(--ok); }
.timeline li.out { border-color: var(--accent); }
.timeline li.voided { opacity: 0.45; text-decoration: line-through; }
.timeline .meta { font-size: 12px; color: var(--muted); }
.timeline .body { white-space: pre-wrap; margin-top: 2px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg label { margin: 0; }
.seg input { display: none; }
.seg span { display: inline-block; padding: 6px 12px; cursor: pointer; color: var(--muted); font-size: 14px; }
.seg input:checked + span { background: var(--accent); color: var(--accent-text); }

.chan-line { display: flex; gap: 4px; align-items: center; margin-bottom: 6px; }
.chan-line .chip { flex: 1 1 auto; min-width: 0; justify-content: flex-start; }
.chan-line .chip .v { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chan-line select { min-height: 32px; padding: 2px 4px; font-size: 12px; width: 96px; flex: 0 0 auto; }
.chan-line .btn { padding: 2px 6px; }

/* канбан */
.kanban { display: flex; gap: 10px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; }
.kcol { flex: 0 0 250px; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px; min-height: 120px; }
.kcol.over { border-color: var(--accent); }
.kcol h3 { margin: 2px 4px 8px; display: flex; gap: 6px; align-items: center; }
.kcard { background: var(--panel2); border: 1px solid var(--border); border-radius: 8px; padding: 8px; margin-bottom: 6px; cursor: grab; font-size: 13px; }
.kcard a { color: var(--text); font-weight: 600; }

/* импорт */
.map-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; }
.map-grid .card { padding: 10px; }
.act-create { color: var(--ok); }
.act-update, .act-updated { color: var(--accent); }
.act-error { color: var(--danger); }

@media (max-width: 1000px) {
  .card-grid { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .container { padding: 12px 12px 80px; }
  .trow { padding: 12px; }
  .btn { min-height: 44px; }
  .chip { min-height: 44px; }
  .hide-mobile { display: none; }
  kbd { display: none; }
}
