:root {
  --bg: #f5f6f8; --surface: #ffffff; --surface-2: #f9fafb; --border: #e2e5ea; --border-strong: #cdd2da;
  --text: #1a1f29; --muted: #6a7382; --accent: #4f46e5; --accent-hover: #4338ca; --accent-soft: #eef0ff;
  --danger: #d92d20; --danger-soft: #fdeceb; --ok: #12a150; --ok-soft: #e6f6ed; --warn: #c26a00; --warn-soft: #fff4e0;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08); --shadow-lg: 0 12px 32px rgba(16,24,40,.18);
  --radius: 10px; --radius-sm: 6px; --sidebar: 236px; --topbar: 56px;
  --gantt-weekend: rgba(100,116,139,.07); --gantt-grid: rgba(100,116,139,.14); --gantt-today: #ef4444;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1218; --surface: #171b23; --surface-2: #1d222c; --border: #2a303c; --border-strong: #3a4252;
    --text: #e8ebf1; --muted: #98a2b3; --accent: #8b87ff; --accent-hover: #a3a0ff; --accent-soft: #23253f;
    --danger: #f97066; --danger-soft: #3a1f1d; --ok: #47cd89; --ok-soft: #14301f; --warn: #fdb022; --warn-soft: #33260c;
    --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 12px 32px rgba(0,0,0,.6);
    --gantt-weekend: rgba(148,163,184,.08); --gantt-grid: rgba(148,163,184,.16);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1218; --surface: #171b23; --surface-2: #1d222c; --border: #2a303c; --border-strong: #3a4252;
  --text: #e8ebf1; --muted: #98a2b3; --accent: #8b87ff; --accent-hover: #a3a0ff; --accent-soft: #23253f;
  --danger: #f97066; --danger-soft: #3a1f1d; --ok: #47cd89; --ok-soft: #14301f; --warn: #fdb022; --warn-soft: #33260c;
  --shadow: 0 1px 2px rgba(0,0,0,.4); --shadow-lg: 0 12px 32px rgba(0,0,0,.6);
  --gantt-weekend: rgba(148,163,184,.08); --gantt-grid: rgba(148,163,184,.16); color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 8px; }
.col { display: flex; flex-direction: column; gap: 8px; }
.wrap { flex-wrap: wrap; }
.right { margin-left: auto; }
.hidden { display: none !important; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* кнопки и поля */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 12px; border: 1px solid var(--border-strong); background: var(--surface); border-radius: var(--radius-sm); cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s; }
.btn:hover { background: var(--surface-2); border-color: var(--muted); }
.btn:focus-visible, .input:focus-visible, .select:focus-visible, textarea:focus-visible, .tab:focus-visible, .card:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.sm { height: 28px; padding: 0 9px; font-size: 13px; }
.btn.icon { width: 34px; padding: 0; }
.btn.sm.icon { width: 28px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.input, .select, textarea { width: 100%; height: 34px; padding: 0 10px; border: 1px solid var(--border-strong); background: var(--surface); border-radius: var(--radius-sm); }
textarea { height: auto; padding: 8px 10px; resize: vertical; min-height: 84px; }
.input.sm, .select.sm { height: 28px; font-size: 13px; padding: 0 8px; }
.input.borderless { border-color: transparent; background: transparent; }
.input.borderless:hover { border-color: var(--border); }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > label { font-size: 12px; color: var(--muted); }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

/* каркас */
.layout { display: grid; grid-template-columns: var(--sidebar) 1fr; grid-template-rows: var(--topbar) 1fr; height: 100vh; }
.sidebar { grid-row: 1 / 3; background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; }
.brand { height: var(--topbar); display: flex; align-items: center; gap: 10px; padding: 0 16px; font-weight: 650; font-size: 15px; border-bottom: 1px solid var(--border); }
.brand .logo { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); display: grid; place-items: center; color: #fff; }
.nav { padding: 10px 8px; overflow: auto; flex: 1; }
.nav h4 { margin: 12px 10px 6px; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.nav a { display: flex; align-items: center; gap: 9px; padding: 7px 10px; border-radius: var(--radius-sm); color: var(--text); }
.nav a:hover { background: var(--surface-2); }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.count { margin-left: auto; font-size: 12px; color: var(--muted); }
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px; padding: 0 20px; min-width: 0; }
.main { overflow: auto; min-width: 0; position: relative; }
.page { padding: 20px 24px 40px; }
.burger { display: none; }
.tabs { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 2px; gap: 2px; }
.tab { border: 0; background: transparent; padding: 5px 14px; border-radius: 6px; cursor: pointer; color: var(--muted); font-weight: 500; }
.tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.avatar { width: 24px; height: 24px; border-radius: 50%; display: inline-grid; place-items: center; font-size: 10.5px; font-weight: 650; color: #fff; flex: none; border: 2px solid var(--surface); }
.avatars { display: inline-flex; }
.avatars .avatar + .avatar { margin-left: -6px; }
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 500; background: var(--surface-2); border: 1px solid var(--border); white-space: nowrap; }
.pill .dot { width: 8px; height: 8px; border-radius: 50%; }
.pill.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.pill.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.pill.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.empty { padding: 48px 20px; text-align: center; color: var(--muted); }
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.search { position: relative; width: 260px; }
.search input { padding-left: 30px; }
.search::before { content: "⌕"; position: absolute; left: 10px; top: 4px; color: var(--muted); font-size: 16px; }

/* таблица */
table.tbl { width: 100%; border-collapse: separate; border-spacing: 0; }
.tbl th { position: sticky; top: 0; background: var(--surface-2); text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; user-select: none; z-index: 1; }
.tbl th.sortable { cursor: pointer; }
.tbl th.sortable:hover { color: var(--text); }
.tbl td { padding: 7px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tr.task-row { cursor: pointer; }
.tbl tr.task-row:hover td { background: var(--surface-2); }
.tbl tr.group-row td { background: var(--surface-2); font-weight: 600; cursor: pointer; padding: 9px 10px; }
.tbl .num { color: var(--muted); font-variant-numeric: tabular-nums; width: 54px; }
.due-over { color: var(--danger); font-weight: 600; }
.due-today { color: var(--warn); font-weight: 600; }
.prio { width: 4px; height: 18px; border-radius: 2px; display: inline-block; vertical-align: middle; margin-right: 6px; }
.prio-1 { background: #94a3b8; } .prio-2 { background: #60a5fa; } .prio-3 { background: #f59e0b; } .prio-4 { background: #ef4444; }
.tag { font-size: 11px; background: var(--accent-soft); color: var(--accent); border-radius: 4px; padding: 0 6px; }
.progress { height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; }
.progress > i { display: block; height: 100%; background: var(--ok); }

/* канбан */
.board { display: flex; gap: 14px; align-items: flex-start; padding: 0 24px 24px; overflow-x: auto; min-height: calc(100vh - var(--topbar) - 70px); }
.column { width: 288px; flex: none; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; max-height: calc(100vh - var(--topbar) - 90px); }
.column.over { border-color: var(--accent); background: var(--accent-soft); }
.column header { display: flex; align-items: center; gap: 8px; padding: 10px 12px; font-weight: 600; }
.cards { padding: 4px 8px 8px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; min-height: 30px; }
.kcard { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 9px 10px; cursor: grab; box-shadow: var(--shadow); position: relative; }
.kcard:hover { border-color: var(--border-strong); }
.kcard.dragging { opacity: .4; }
.kcard .title { font-weight: 500; margin-bottom: 6px; word-break: break-word; }
.kcard .meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.kcard::before { content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--pc, transparent); }
.drop-line { height: 3px; border-radius: 2px; background: var(--accent); margin: -5px 0; }
.quick-add { padding: 0 8px 10px; }

/* модалки и панели */
.overlay { position: fixed; inset: 0; background: rgba(15,18,24,.45); z-index: 50; display: flex; justify-content: flex-end; }
.overlay.center { justify-content: center; align-items: center; }
.drawer { width: min(720px, 100vw); background: var(--surface); height: 100%; overflow-y: auto; box-shadow: var(--shadow-lg); display: flex; flex-direction: column; }
.drawer > header { position: sticky; top: 0; background: var(--surface); z-index: 2; padding: 14px 20px; border-bottom: 1px solid var(--border); display: flex; gap: 10px; align-items: center; }
.drawer .body { padding: 18px 20px 60px; display: flex; flex-direction: column; gap: 18px; }
.modal { background: var(--surface); border-radius: 12px; box-shadow: var(--shadow-lg); width: min(560px, 94vw); max-height: 90vh; overflow: auto; }
.modal.wide { width: min(820px, 96vw); }
.modal > header { padding: 16px 20px; border-bottom: 1px solid var(--border); font-weight: 650; display: flex; align-items: center; }
.modal .body { padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; }
.modal > footer { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }
.section-title { font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.list-item { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow-lg); max-width: 380px; }
.toast.error { background: var(--danger); color: #fff; }

/* ассистент */
.fab { position: fixed; right: 20px; bottom: 20px; width: 52px; height: 52px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; box-shadow: var(--shadow-lg); cursor: pointer; font-size: 22px; z-index: 40; }
.chat { position: fixed; right: 20px; bottom: 84px; width: min(400px, calc(100vw - 24px)); height: min(620px, calc(100vh - 110px)); z-index: 45; display: flex; flex-direction: column; box-shadow: var(--shadow-lg); }
.chat header { padding: 12px 14px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 8px; font-weight: 650; }
.msgs { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 88%; padding: 8px 11px; border-radius: 12px; white-space: pre-wrap; word-break: break-word; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 3px; }
.msg.bot { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--border); border-bottom-left-radius: 3px; }
.msg.heard { align-self: flex-end; font-size: 12px; color: var(--muted); padding: 0 4px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 2px; }
.chat footer { padding: 10px; border-top: 1px solid var(--border); display: flex; gap: 6px; align-items: flex-end; }
.chat footer textarea { min-height: 36px; max-height: 110px; height: 36px; padding: 7px 10px; }
.mic.rec { background: var(--danger); border-color: var(--danger); color: #fff; animation: pulse 1.1s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(217,45,32,.25); } }
.typing { display: inline-flex; gap: 3px; padding: 4px 2px; }
.typing i { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }

/* логин */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login .card { width: 360px; padding: 28px; display: flex; flex-direction: column; gap: 14px; }

/* Гант */
.gantt-wrap { display: flex; flex-direction: column; height: calc(100vh - var(--topbar)); }
.gantt-bar { padding: 10px 24px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; border-bottom: 1px solid var(--border); background: var(--surface); }
.gantt-body { flex: 1; display: flex; min-height: 0; background: var(--surface); }
.g-table { flex: none; overflow: hidden; border-right: 1px solid var(--border); display: flex; flex-direction: column; position: relative; }
.g-scroll { flex: 1; overflow: auto; position: relative; min-width: 0; }
.g-head { position: sticky; top: 0; z-index: 3; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.g-row { display: flex; align-items: center; height: 32px; border-bottom: 1px solid var(--gantt-grid); font-size: 13px; }
.g-row:hover { background: var(--surface-2); }
.g-row.sel { background: var(--accent-soft); }
.g-cell { padding: 0 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: none; }
.g-cell.name { flex: 1; min-width: 0; }
.g-resizer { position: absolute; top: 0; right: -3px; width: 6px; height: 100%; cursor: col-resize; z-index: 4; }
.g-canvas { position: relative; }
.g-bar { position: absolute; height: 18px; border-radius: 4px; background: #6366f1; cursor: grab; display: flex; align-items: center; user-select: none; }
.g-bar.critical { background: #ef4444; }
.g-bar.summary { background: var(--text); height: 9px; border-radius: 1px; cursor: default; }
.g-bar.summary::before, .g-bar.summary::after { content: ""; position: absolute; top: 6px; border: 5px solid transparent; border-top-color: var(--text); }
.g-bar.summary::before { left: 0; border-left-color: var(--text); } .g-bar.summary::after { right: 0; border-right-color: var(--text); }
.g-bar.milestone { width: 16px !important; height: 16px; border-radius: 2px; transform: rotate(45deg); }
.g-bar .prog { position: absolute; left: 0; top: 0; bottom: 0; background: rgba(0,0,0,.28); border-radius: 4px 0 0 4px; pointer-events: none; }
.g-bar .lbl { position: absolute; left: calc(100% + 8px); font-size: 12px; white-space: nowrap; color: var(--text); pointer-events: none; background: var(--surface); padding: 0 4px; border-radius: 3px; z-index: 2; transform: rotate(0); }
.g-bar.milestone .lbl { transform: rotate(-45deg); left: calc(100% + 2px); top: 10px; }
.g-bar .rs { position: absolute; right: 0; top: 0; width: 7px; height: 100%; cursor: ew-resize; }
.g-bar .lk { position: absolute; right: -9px; top: 4px; width: 10px; height: 10px; border-radius: 50%; background: var(--surface); border: 2px solid var(--accent); cursor: crosshair; opacity: 0; }
.g-bar:hover .lk, .linking .g-bar .lk { opacity: 1; }
.g-bar.late { box-shadow: 0 0 0 2px var(--warn); }
.g-bl { position: absolute; height: 5px; border-radius: 2px; background: #94a3b8; opacity: .85; }
.g-today { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--gantt-today); z-index: 1; pointer-events: none; }
.g-links { position: absolute; left: 0; top: 0; pointer-events: none; overflow: visible; }
.g-links path { fill: none; stroke: #94a3b8; stroke-width: 1.4; }
.g-links path.crit { stroke: #ef4444; stroke-width: 1.8; }
.g-links path.hit { stroke: transparent; stroke-width: 10; pointer-events: stroke; cursor: pointer; }
.g-links path.rel { stroke-dasharray: 3 3; }
.g-hcell { display: flex; align-items: center; justify-content: center; font-size: 11px; color: var(--muted); border-right: 1px solid var(--gantt-grid); flex: none; overflow: hidden; }
.g-res { border-top: 1px solid var(--border); background: var(--surface); max-height: 220px; overflow: auto; }
.res-row { display: flex; align-items: center; height: 26px; }
.res-cell { position: absolute; height: 18px; border-radius: 3px; font-size: 10px; text-align: center; color: #fff; line-height: 18px; }

/* дерево реальности */
.crt-canvas { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: auto; }
.crt-node rect { fill: var(--surface); stroke: var(--border-strong); stroke-width: 1.5; }
.crt-node.ude rect { fill: var(--danger-soft); stroke: var(--danger); }
.crt-node.best rect { stroke: var(--ok); stroke-width: 2.5; fill: var(--ok-soft); }
.crt-node.hyp rect { stroke-dasharray: 5 3; }
.crt-node text { fill: var(--text); font-size: 12px; }
.crt-edge { fill: none; stroke: #94a3b8; stroke-width: 1.6; }
.crt-edge.conf { stroke: var(--ok); stroke-width: 2.2; }
.crt-edge.weak { stroke: var(--warn); stroke-dasharray: 4 3; }

@media (max-width: 860px) {
  .burger { display: inline-flex; }
  .layout { grid-template-columns: 1fr; grid-template-rows: var(--topbar) 1fr; }
  .sidebar { position: fixed; z-index: 30; width: var(--sidebar); height: 100%; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: var(--shadow-lg); }
  .page { padding: 14px 12px 40px; }
  .board { padding: 0 12px 20px; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .search { width: 100%; }
  .topbar { padding: 0 10px; gap: 6px; }
  .topbar h2 { display: none; }
}
