/* ============== boot screen ============== */
.boot {
    position: fixed;
    inset: 0;
    background: radial-gradient(ellipse at center, #060b1a 0%, #000 100%);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.9s ease, visibility 0.9s ease;
}
.boot.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.boot-inner {
    width: min(520px, 86vw);
    text-align: center;
    color: #aee5ff;
    font-family: "SF Mono", "JetBrains Mono", monospace;
}
.boot-logo {
    font-size: 64px;
    letter-spacing: 18px;
    font-weight: 200;
    background: linear-gradient(90deg, #5cb6ff, #b388ff, #ff8aa6, #ffd166, #5cb6ff);
    background-size: 300% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    animation: hueShift 4s linear infinite;
    text-shadow: 0 0 30px rgba(120, 180, 255, 0.4);
    margin-bottom: 8px;
}
.boot-sub {
    font-size: 12px;
    letter-spacing: 6px;
    color: #6b88ad;
    margin-bottom: 36px;
    text-transform: uppercase;
}
.boot-lines {
    text-align: left;
    font-size: 12px;
    line-height: 1.9;
    min-height: 160px;
    color: #7fc8ff;
}
.boot-lines .ok { color: #6effb3; }
.boot-lines .dim { color: #4a6c92; }
.boot-bar {
    margin-top: 24px;
    height: 3px;
    background: rgba(120, 180, 255, 0.1);
    border-radius: 2px;
    overflow: hidden;
}
.boot-bar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, #5cb6ff, #b388ff, #ff8aa6);
    transition: width 0.2s ease;
    box-shadow: 0 0 12px rgba(120, 180, 255, 0.8);
}
.boot-prompt {
    margin-top: 28px;
    padding: 10px 22px;
    border: 1px solid rgba(120, 230, 255, 0.5);
    border-radius: 999px;
    color: rgba(200, 240, 255, 0.95);
    letter-spacing: 0.16em;
    text-transform: uppercase;
    font-size: 12px;
    cursor: pointer;
    background: rgba(20, 40, 80, 0.25);
    box-shadow: 0 0 18px rgba(120, 200, 255, 0.35), inset 0 0 12px rgba(120, 200, 255, 0.25);
    animation: bootPromptPulse 1.6s ease-in-out infinite;
}
.boot-prompt:hover {
    background: rgba(40, 80, 140, 0.35);
}
@keyframes bootPromptPulse {
    0%, 100% { opacity: 0.85; }
    50% { opacity: 1; }
}
@keyframes hueShift {
    0%, 100% { background-position: 0% 50%; }
    50%      { background-position: 100% 50%; }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
    background: radial-gradient(ellipse at center, #0a0e1a 0%, #02030a 100%);
    color: #cfe6ff;
    font-family: -apple-system, "SF Pro Display", "Segoe UI", sans-serif;
    overflow: hidden;
}

.layout {
    display: grid;
    grid-template-columns: 260px 1fr;
    height: 100vh;
}

aside.sidebar {
    background: rgba(8, 14, 28, 0.7);
    border-right: 1px solid rgba(120, 180, 255, 0.15);
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    backdrop-filter: blur(12px);
    overflow-y: auto;
    min-height: 0;
}

.brand {
    font-size: 22px;
    letter-spacing: 8px;
    font-weight: 200;
    color: #7fb6ff;
    text-shadow: 0 0 12px rgba(100, 180, 255, 0.6);
    margin-bottom: 20px;
    text-align: center;
}

.side-search input {
    width: 100%;
    background: rgba(10, 20, 40, 0.7);
    border: 1px solid rgba(120, 180, 255, 0.18);
    border-radius: 10px;
    padding: 9px 12px;
    color: #cfe6ff;
    font-size: 12px;
    outline: none;
    transition: border 0.2s;
}
.side-search input:focus {
    border-color: rgba(120, 200, 255, 0.5);
    box-shadow: 0 0 12px rgba(100, 180, 255, 0.25);
}

.side-section { margin-top: 22px; }
.side-h {
    font-size: 10px;
    letter-spacing: 2px;
    color: #6b88ad;
    text-transform: uppercase;
    margin-bottom: 10px;
}

.quick-cmds { display: flex; flex-direction: column; gap: 5px; }
.qc {
    text-align: left;
    background: rgba(14, 22, 40, 0.55);
    color: #cfe6ff;
    border: 1px solid rgba(120, 180, 255, 0.12);
    border-radius: 8px;
    padding: 8px 11px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.18s;
    font-family: inherit;
}
.qc:hover {
    border-color: rgba(120, 200, 255, 0.45);
    background: rgba(28, 40, 70, 0.7);
    transform: translateX(2px);
}

.activity { display: flex; flex-direction: column; gap: 6px; max-height: 300px; overflow-y: auto; }
.act-empty {
    font-size: 11px;
    color: #4a6c92;
    text-align: center;
    padding: 14px 8px;
    font-style: italic;
    border: 1px dashed rgba(120, 180, 255, 0.1);
    border-radius: 8px;
}
.act-item {
    display: flex;
    gap: 8px;
    color: #cfe6ff;
    padding: 8px 9px;
    border-left: 2px solid rgba(120, 200, 255, 0.45);
    background: rgba(16, 24, 44, 0.55);
    border-radius: 4px;
    line-height: 1.4;
}
.act-mark {
    flex: 0 0 18px;
    width: 18px;
    height: 18px;
    display: grid;
    place-items: center;
    border: 1px solid rgba(120, 200, 255, 0.35);
    border-radius: 50%;
    color: #7fb6ff;
    font-size: 10px;
}
.act-copy { min-width: 0; }
.act-title { font-size: 11px; color: #dceeff; }
.act-meta {
    margin-top: 2px;
    font-size: 10px;
    color: #6b88ad;
    word-break: break-word;
}
.act-item.done { opacity: 0.58; }
.act-item.check_ok,
.act-item.complete,
.act-item.report { border-left-color: rgba(110, 255, 179, 0.7); }
.act-item.check_ok .act-mark,
.act-item.complete .act-mark,
.act-item.report .act-mark { color: #6effb3; border-color: rgba(110, 255, 179, 0.45); }
.act-item.execute { border-left-color: rgba(255, 209, 102, 0.75); }
.act-item.execute .act-mark { color: #ffd166; border-color: rgba(255, 209, 102, 0.45); }
.act-item.error,
.act-item.blocked { border-left-color: rgba(255, 126, 157, 0.8); }
.act-item.error .act-mark,
.act-item.blocked .act-mark { color: #ff7e9d; border-color: rgba(255, 126, 157, 0.5); }
.act-item .who { color: #7fb6ff; font-weight: 500; }
.act-item .when { color: #6b88ad; font-size: 10px; }

.status-list { display: flex; flex-direction: column; gap: 5px; }
.sl-row {
    display: flex; align-items: center; gap: 8px;
    font-size: 12px;
    color: #cfe6ff;
    padding: 5px 4px;
}
.sl-dot {
    width: 7px; height: 7px; border-radius: 50%;
    background: #3a5a8c;
}
.sl-dot.ok  { background: #6effb3; box-shadow: 0 0 6px #6effb3; }
.sl-dot.bad { background: #ff7e9d; box-shadow: 0 0 6px #ff7e9d; animation: pulseBad 1.5s infinite; }
@keyframes pulseBad { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

.owner {
    font-size: 11px;
    color: #6b88ad;
    text-align: center;
    padding-top: 14px;
    margin-top: auto;
    border-top: 1px solid rgba(120,180,255,0.1);
}

main.stage {
    position: relative;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;   /* grid-элемент: иначе растёт выше экрана и прокрутка не работает */
    min-width: 0;
}

/* ============== top nav (tabs) ============== */
.topnav {
    position: relative;
    z-index: 5;
    display: flex;
    align-items: center;
    height: 52px;
    padding: 0 24px;
    border-bottom: 1px solid rgba(120, 180, 255, 0.12);
    background: rgba(8, 14, 28, 0.45);
    backdrop-filter: blur(8px);
}
.tabs { display: flex; gap: 6px; }
.tab {
    background: transparent;
    color: #6b88ad;
    border: 1px solid transparent;
    padding: 7px 16px;
    border-radius: 8px;
    font-size: 13px;
    letter-spacing: 1.5px;
    cursor: pointer;
    transition: all 0.2s;
}
.tab:hover { color: #cfe6ff; }
.tab.active {
    color: #cfe6ff;
    background: rgba(100, 180, 255, 0.10);
    border-color: rgba(120, 200, 255, 0.35);
    box-shadow: 0 0 14px rgba(100, 180, 255, 0.2) inset;
}

/* ============== page containers ============== */
.page {
    display: none;
    flex: 1;
    min-height: 0;   /* без этого внутренняя прокрутка не работает — контент режется */
    position: relative;
    overflow: hidden;
}
.page.active { display: flex; flex-direction: column; min-height: 0; }

.page-chat {
    align-items: center;
    justify-content: flex-end;
    padding: 24px;
}

.page-header { padding: 24px 32px 10px; }
.page-header h2 {
    font-size: 22px; font-weight: 300;
    letter-spacing: 4px; color: #cfe6ff;
}
.page-header .hint { font-size: 12px; color: #6b88ad; margin-top: 6px; letter-spacing: 1px; }

canvas#core {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    z-index: 0;
}

.status {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, 220px);
    font-size: 12px;
    letter-spacing: 4px;
    color: #6b88ad;
    text-transform: uppercase;
    z-index: 2;
}

.chat {
    position: relative; z-index: 2;
    width: 100%;
    max-width: 720px;
    max-height: 35vh;
    overflow-y: auto;
    margin-bottom: 16px;
    padding: 12px;
    display: flex; flex-direction: column; gap: 8px;
    mask-image: linear-gradient(to top, black 80%, transparent);
}
.bubble {
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    max-width: 80%;
    backdrop-filter: blur(6px);
}
.bubble.user {
    align-self: flex-end;
    background: rgba(60, 120, 200, 0.25);
    border: 1px solid rgba(120, 180, 255, 0.3);
}
.bubble.stefan {
    align-self: flex-start;
    background: rgba(20, 40, 80, 0.5);
    border: 1px solid rgba(120, 180, 255, 0.2);
    color: #e8f4ff;
}
.bubble.agent {
    align-self: flex-start;
    background: rgba(20, 40, 80, 0.5);
    border: 1px solid rgba(120, 180, 255, 0.2);
    color: #e8f4ff;
    padding: 8px 14px 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.bubble.agent .b-head {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    color: #7fb6ff;
    letter-spacing: 0.5px;
    margin-bottom: 2px;
}
.bubble.agent .b-icon { font-size: 14px; }
.bubble.agent .b-name { font-weight: 500; }
.bubble.agent .b-text { font-size: 14px; line-height: 1.5; color: #e8f4ff; }

/* ============== JARVIS Flow log ============== */
.flowlog {
    position: relative;
    z-index: 2;
    width: 100%;
    max-width: 720px;
    margin: 0 0 12px;
    background: rgba(4, 10, 22, 0.85);
    border: 1px solid rgba(110, 255, 179, 0.25);
    border-radius: 10px;
    backdrop-filter: blur(8px);
    overflow: hidden;
    transition: max-height 0.3s ease;
    max-height: 220px;
}
.flowlog.collapsed { max-height: 32px; }
.flowlog.empty { display: none; }
.flowlog-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 7px 12px;
    background: rgba(0,0,0,0.4);
    font-size: 10px;
    letter-spacing: 2px;
    color: #6effb3;
    text-transform: uppercase;
    border-bottom: 1px solid rgba(110, 255, 179, 0.15);
}
.flowlog-toggle {
    background: transparent;
    border: 1px solid rgba(110, 255, 179, 0.3);
    color: #6effb3;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 10px;
    cursor: pointer;
    font-family: inherit;
    letter-spacing: 1px;
}
.flowlog-toggle:hover { background: rgba(110, 255, 179, 0.1); }
.flowlog-body {
    padding: 6px 12px 10px;
    font-family: "SF Mono", "JetBrains Mono", monospace;
    font-size: 10.5px;
    line-height: 1.55;
    max-height: 175px;
    overflow-y: auto;
    color: #8aa9c9;
}
.flow-line {
    display: flex;
    gap: 8px;
    align-items: baseline;
    padding: 1px 0;
    opacity: 0;
    animation: flowFadeIn 0.3s ease forwards;
}
@keyframes flowFadeIn { to { opacity: 1; } }
.flow-time { color: #4a6c92; flex-shrink: 0; width: 56px; }
.flow-arrow { color: #6effb3; flex-shrink: 0; }
.flow-text { color: #cfe6ff; word-break: break-word; }
.flow-line.send   .flow-arrow { color: #5cc4ff; }
.flow-line.delegate .flow-arrow { color: #ff8aa6; text-shadow: 0 0 6px rgba(255,138,166,0.7); }
.flow-line.tool   .flow-arrow { color: #ffd166; }
.flow-line.result .flow-arrow { color: #6effb3; text-shadow: 0 0 4px rgba(110,255,179,0.6); }
.flow-line.error  .flow-arrow { color: #ff7e9d; }
.flow-line.info   .flow-arrow { color: #b388ff; }
.flow-line .src { color: #7fb6ff; font-weight: 500; }
.flow-line .dst { color: #ffd166; font-weight: 500; }

/* карточка реального выполненного инструмента */
.tool-card {
    align-self: flex-start;
    max-width: 92%;
    background: rgba(20, 38, 70, 0.6);
    border: 1px solid rgba(110, 255, 179, 0.35);
    border-left: 3px solid #6effb3;
    border-radius: 10px;
    padding: 8px 12px;
    font-family: "SF Mono", "JetBrains Mono", monospace;
    font-size: 11.5px;
    color: #cfe6ff;
    box-shadow: 0 4px 14px rgba(0,0,0,0.25);
}
.tool-card.err     { border-color: rgba(255, 126, 157, 0.45); border-left-color: #ff7e9d; }
.tool-card.denied  { border-color: rgba(255, 184, 122, 0.45); border-left-color: #ffb87a; }
.tool-head {
    font-size: 10px;
    letter-spacing: 1px;
    color: #7fb6ff;
    margin-bottom: 4px;
    text-transform: uppercase;
}
.tool-card.err     .tool-head { color: #ff7e9d; }
.tool-card.denied  .tool-head { color: #ffb87a; }
.tool-cmd {
    color: #aee5ff;
    margin-bottom: 6px;
    word-break: break-all;
}
.tool-out {
    max-height: 220px;
    overflow-y: auto;
    background: rgba(0,0,0,0.35);
    border-radius: 6px;
    padding: 6px 8px;
    margin: 0;
    color: #8aa9c9;
    font-size: 11px;
    line-height: 1.4;
    white-space: pre-wrap;
    word-break: break-word;
}

form.input {
    position: relative; z-index: 2;
    display: flex; gap: 8px;
    width: 100%;
    max-width: 720px;
}
form.input input {
    flex: 1;
    background: rgba(10, 20, 40, 0.7);
    border: 1px solid rgba(120, 180, 255, 0.3);
    border-radius: 10px;
    padding: 14px 18px;
    color: #e8f4ff;
    font-size: 15px;
    outline: none;
}
form.input input:focus { border-color: #5cb6ff; box-shadow: 0 0 16px rgba(100,180,255,0.3); }
form.input button {
    background: rgba(60, 120, 200, 0.3);
    border: 1px solid rgba(120, 180, 255, 0.3);
    color: #e8f4ff;
    border-radius: 10px;
    padding: 0 18px;
    font-size: 18px;
    cursor: pointer;
}
form.input button:hover { background: rgba(80, 140, 220, 0.5); }
form.input button#mic { font-size: 20px; }
form.input button#mic.on {
    background: linear-gradient(135deg, #ff5e87, #ff8a5b, #ffd166);
    border-color: rgba(255, 200, 150, 0.7);
    box-shadow: 0 0 20px rgba(255, 120, 150, 0.55);
    animation: micPulse 1.4s ease-in-out infinite;
}
@keyframes micPulse {
    0%, 100% { box-shadow: 0 0 12px rgba(255, 120, 150, 0.45); }
    50%      { box-shadow: 0 0 28px rgba(255, 200, 150, 0.85); }
}

/* ================= DASHBOARD ================= */
.dash-grid {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 12px 32px 32px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    grid-auto-rows: max-content;
    gap: 16px;
    align-content: start;
}
.dash-card {
    background: rgba(14, 22, 40, 0.55);
    border: 1px solid rgba(120, 180, 255, 0.12);
    border-radius: 14px;
    padding: 18px 20px;
    backdrop-filter: blur(8px);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3) inset;
    transition: border 0.2s, box-shadow 0.2s;
}
.dash-card:hover {
    border-color: rgba(120, 200, 255, 0.35);
    box-shadow: 0 0 20px rgba(100, 180, 255, 0.12);
}
.dash-card.wide { grid-column: span 2; }
.dash-card-h {
    font-size: 14px;
    letter-spacing: 2px;
    color: #7fb6ff;
    margin-bottom: 14px;
    text-transform: uppercase;
}
.dash-card-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 6px 0;
    font-size: 13px;
    color: #cfe6ff;
    border-bottom: 1px dashed rgba(120,180,255,0.08);
}
.dash-card-row:last-of-type { border-bottom: none; }
.dash-card-row span { color: #6b88ad; font-size: 12px; }
.dash-card-row b { font-weight: 500; color: #cfe6ff; }
.dash-card-row b.ok { color: #6effb3; }
.dash-card-row b.bad { color: #ff7e9d; }
.dash-card-foot {
    margin-top: 12px;
    font-size: 10px;
    color: #4a6c92;
    letter-spacing: 1px;
    text-transform: uppercase;
}
.dash-feed { display: flex; flex-direction: column; gap: 6px; max-height: 340px; overflow-y: auto; }
.feed-item { font-size: 12px; color: #cfe6ff; padding: 6px 0; border-bottom: 1px dashed rgba(120,180,255,0.06); }
.feed-item.dim { color: #4a6c92; font-style: italic; text-align: center; padding: 16px; }

/* ================= STRUCTURE (n8n-style) ================= */
.org-wrap {
    position: relative;
    flex: 1;
    min-height: 0;
    margin: 8px 24px 24px;
    border: 1px solid rgba(120, 180, 255, 0.12);
    border-radius: 14px;
    background: linear-gradient(180deg, rgba(6,10,22,0.85), rgba(4,8,18,0.95));
    overflow: auto;   /* короткое окно — карту можно прокрутить, узлы не обрезаются */
}
#orgchart {
    width: 100%;
    height: 100%;
    display: block;
}

/* группы (биз/личное/инфра) — цветные акценты слева у нод */
.node-bg {
    fill: rgba(16, 24, 44, 0.92);
    stroke: rgba(120, 180, 255, 0.18);
    stroke-width: 1;
    transition: stroke 0.2s, filter 0.2s;
}
.node:hover .node-bg { stroke: rgba(120, 220, 255, 0.7); filter: url(#node-glow); }
.node.selected .node-bg { stroke: #5cc4ff; stroke-width: 1.5; filter: url(#node-glow); }
.node.dim { opacity: 0.35; transition: opacity 0.2s; }
.node { cursor: pointer; }

.node-accent { fill: rgba(120, 180, 255, 0.7); }
.node-owner  .node-accent { fill: #ffd166; }
.node-owner  .node-bg     { stroke: rgba(255, 209, 102, 0.55); }
.node-owner:hover .node-bg { stroke: #ffd166; }
.node-core   .node-accent { fill: #b388ff; }
.node-biz    .node-accent { fill: #5cc4ff; }
.node-personal .node-accent { fill: #b388ff; }
.node-infra  .node-accent { fill: #6effb3; }
.node-service .node-accent { fill: #ffb87a; }
.node-human  .node-accent { fill: #ff8aa6; }
.node-human  .node-bg     { stroke: rgba(255, 138, 166, 0.40); }
.node-human:hover .node-bg { stroke: #ff8aa6; }
.node-assistant .node-accent { fill: #c7a8ff; }
.node-assistant .node-bg     { stroke: rgba(199, 168, 255, 0.40); }
.node-assistant:hover .node-bg { stroke: #c7a8ff; }
.team-card.team-owner::before { background: #ffd166; }
.team-card.team-human::before { background: #ff8aa6; }
.team-card.team-assistant::before { background: #c7a8ff; }

/* ============== Обучение агента (в drawer) ============== */
.dr-tabs {
    display: flex;
    gap: 4px;
    margin-top: 14px;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(120, 180, 255, 0.12);
}
.dr-tab {
    background: transparent;
    color: #6b88ad;
    border: 1px solid transparent;
    padding: 6px 14px;
    border-radius: 6px;
    font-size: 12px;
    letter-spacing: 1px;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.18s;
}
.dr-tab:hover { color: #cfe6ff; }
.dr-tab.active {
    color: #cfe6ff;
    background: rgba(100, 180, 255, 0.10);
    border-color: rgba(120, 200, 255, 0.35);
}
.dr-train {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.dr-help {
    font-size: 11px;
    color: #6b88ad;
    line-height: 1.5;
    padding: 8px 10px;
    background: rgba(80, 140, 220, 0.07);
    border-left: 2px solid rgba(120, 200, 255, 0.35);
    border-radius: 4px;
    margin-bottom: 4px;
}
.dr-label {
    font-size: 11px;
    color: #7fb6ff;
    letter-spacing: 1px;
    margin-top: 6px;
    margin-bottom: 4px;
}
.dr-textarea {
    width: 100%;
    background: rgba(8, 14, 28, 0.7);
    border: 1px solid rgba(120, 180, 255, 0.2);
    border-radius: 8px;
    padding: 10px 12px;
    color: #cfe6ff;
    font-family: "SF Mono", "JetBrains Mono", monospace;
    font-size: 12px;
    line-height: 1.55;
    outline: none;
    resize: vertical;
    transition: border 0.2s;
}
.dr-textarea:focus {
    border-color: rgba(120, 200, 255, 0.55);
    box-shadow: 0 0 12px rgba(80, 140, 220, 0.25);
}
.dr-save-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 10px;
}
.dr-save {
    background: linear-gradient(135deg, #5cb6ff, #b388ff);
    border: none;
    color: #ffffff;
    padding: 9px 22px;
    border-radius: 8px;
    font-size: 13px;
    letter-spacing: 1px;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.18s;
    box-shadow: 0 4px 14px rgba(100, 180, 255, 0.3);
}
.dr-save:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(100, 180, 255, 0.45); }
.dr-save:disabled { opacity: 0.6; cursor: wait; }
.dr-save-status { font-size: 12px; }
.dr-save-status.saving { color: #6b88ad; }
.dr-save-status.ok { color: #6effb3; }
.dr-save-status.err { color: #ff7e9d; }
.dr-loading, .dr-err {
    text-align: center;
    color: #6b88ad;
    padding: 30px 10px;
    font-size: 12px;
}
.dr-err { color: #ff7e9d; }
.link-tasks { opacity: 0.6; }
.link-tasks.hl { opacity: 1; }

.node-name {
    fill: #e8f4ff;
    font-size: 14px;
    font-weight: 500;
    font-family: -apple-system, "SF Pro Display", "Segoe UI", sans-serif;
}
.node-role {
    fill: #6b88ad;
    font-size: 11px;
    letter-spacing: 0.5px;
}
.node-short {
    fill: #8aa9c9;
    font-size: 10px;
}
.node-status {
    fill: #6effb3;
    filter: drop-shadow(0 0 4px #6effb3);
}

/* линии */
.link-path { transition: stroke-width 0.2s, opacity 0.2s; }
.link-path.hl { stroke-width: 2.5; filter: drop-shadow(0 0 4px rgba(120,200,255,0.8)); }
.link-path.flowing {
    stroke-width: 3;
    filter: drop-shadow(0 0 8px rgba(110,255,179,0.9));
    animation: flowDash 1.5s linear;
}
@keyframes flowDash {
    from { stroke-dashoffset: 0; }
    to   { stroke-dashoffset: -60; }
}

/* drawer */
.agent-drawer {
    position: absolute;
    top: 70px; right: 24px;
    width: 460px;
    max-height: calc(100% - 110px);
    background: rgba(8, 14, 28, 0.92);
    border: 1px solid rgba(120, 200, 255, 0.3);
    border-radius: 14px;
    padding: 20px;
    backdrop-filter: blur(12px);
    box-shadow: 0 12px 40px rgba(0,0,0,0.5), 0 0 30px rgba(80,140,220,0.2);
    transform: translateX(520px);
    transition: transform 0.3s ease;
    overflow-y: auto;
    z-index: 4;
}
.agent-drawer.open { transform: translateX(0); }
.drawer-close {
    position: absolute; top: 10px; right: 12px;
    background: transparent; border: none; color: #6b88ad;
    font-size: 22px; cursor: pointer; line-height: 1;
}
.drawer-close:hover { color: #cfe6ff; }
.dr-h { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.dr-icon { font-size: 32px; }
.dr-name { font-size: 18px; font-weight: 500; color: #e8f4ff; letter-spacing: 1px; }
.dr-role { font-size: 12px; color: #7fb6ff; }
.dr-short { font-size: 13px; color: #cfe6ff; line-height: 1.5; margin-bottom: 16px; }
.dr-section { margin-top: 16px; }
.dr-section h4 {
    font-size: 11px;
    letter-spacing: 2px;
    color: #6b88ad;
    text-transform: uppercase;
    margin-bottom: 10px;
}
.dr-section ul { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.dr-section ul li {
    padding: 6px 10px;
    background: rgba(16, 24, 44, 0.6);
    border-left: 2px solid rgba(120, 200, 255, 0.4);
    border-radius: 4px;
    font-size: 12px;
    color: #cfe6ff;
}
.dr-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
    font-size: 10px;
    padding: 4px 10px;
    background: rgba(80, 140, 220, 0.15);
    border: 1px solid rgba(120, 200, 255, 0.25);
    border-radius: 999px;
    color: #cfe6ff;
    letter-spacing: 0.5px;
}

/* ================= TEAM page (cards grid) ================= */
.team-grid {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 12px 32px 32px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    grid-auto-rows: max-content;   /* иначе при нехватке высоты строки схлопываются (overflow:hidden у карточки) */
    gap: 14px;
    align-content: start;
}
.team-card {
    background: rgba(14, 22, 40, 0.6);
    border: 1px solid rgba(120, 180, 255, 0.12);
    border-radius: 14px;
    padding: 18px;
    cursor: pointer;
    transition: border 0.2s, transform 0.2s, box-shadow 0.2s;
    position: relative;
    overflow: hidden;
}
.team-card::before {
    content: '';
    position: absolute; top: 0; left: 0; right: 0; height: 3px;
    background: rgba(120, 180, 255, 0.5);
}
.team-card.team-core::before { background: #b388ff; }
.team-card.team-biz::before { background: #5cc4ff; }
.team-card.team-personal::before { background: #b388ff; }
.team-card.team-infra::before { background: #6effb3; }
.team-card.team-service::before { background: #ffb87a; }
.team-card:hover {
    border-color: rgba(120, 220, 255, 0.5);
    transform: translateY(-2px);
    box-shadow: 0 8px 28px rgba(80, 140, 220, 0.18);
}
.team-icon { font-size: 28px; margin-bottom: 8px; }
.team-name { font-size: 15px; font-weight: 500; color: #e8f4ff; margin-bottom: 2px; letter-spacing: 1px; }
.team-role { font-size: 11px; color: #7fb6ff; margin-bottom: 8px; letter-spacing: 0.5px; }
.team-short { font-size: 11px; color: #8aa9c9; line-height: 1.5; margin-bottom: 10px; min-height: 32px; }
.team-tags { display: flex; flex-wrap: wrap; gap: 4px; }

/* ================= АДАПТИВНОСТЬ ================= */

/* SVG карта: holst фиксированной высоты, чтобы узлы оставались читаемыми; короткое
   окно — org-wrap прокручивается (overflow:auto), нижние узлы не обрезаются. */
#orgchart {
    width: 100%;
    height: 100%;
    min-height: 540px;
}

/* drawer становится full-width на узких экранах */
@media (max-width: 1200px) {
    .agent-drawer {
        width: 320px;
    }
    .dash-card.wide { grid-column: span 1; }
}

@media (max-width: 1000px) {
    .layout {
        grid-template-columns: 220px 1fr;
    }
    .topnav { padding: 0 14px; }
    .tab { padding: 6px 10px; font-size: 12px; letter-spacing: 1px; }
    .agent-drawer {
        top: 64px; right: 12px;
        width: calc(100% - 24px);
        max-width: 380px;
    }
    .page-header { padding: 18px 18px 8px; }
    .dash-grid, .team-grid { padding: 8px 16px 20px; }
    .org-wrap { margin: 8px 14px 14px; }
}

@media (max-width: 760px) {
    /* На телефоне фокус — ЧАТ. Сайдбар (вторичная инфа) прячем, чтобы освободить экран. */
    .layout { grid-template-columns: 1fr; grid-template-rows: 1fr; }
    aside.sidebar { display: none; }

    .topnav { height: 46px; padding: 0 8px; }
    .tabs { gap: 2px; }
    .tab { padding: 6px 9px; font-size: 12px; letter-spacing: 0.4px; }
    .user-badge { padding: 4px 8px; gap: 6px; }
    .ub-name { display: none; }   /* оставляем иконку пользователя + кнопку выхода */

    /* чат во весь доступный экран */
    .page-chat { padding: 6px 6px 0; align-items: stretch; justify-content: flex-end; }
    canvas#core { opacity: 0.26; }     /* декоративное ядро приглушаем, чтобы не мешало читать */
    .status { display: none; }
    .chat {
        max-width: 100%; max-height: none; flex: 1; min-height: 0;
        margin-bottom: 6px; padding: 8px 4px; mask-image: none;
    }
    .bubble { max-width: 90%; font-size: 15px; }

    .flowlog { display: none; }   /* «поток данных» — это для отладки, на мобиле скрываем */

    /* поле ввода — крупное и удобное для пальца */
    form.input { max-width: 100%; gap: 6px; padding-bottom: env(safe-area-inset-bottom); }
    form.input input { font-size: 16px; padding: 12px 14px; }   /* 16px — iOS не зумит при фокусе */
    form.input button { padding: 0 16px; min-width: 48px; }
    form.input button#mic { min-width: 48px; }

    /* дашборд/команда — одна колонка, компактнее */
    .dash-grid, .team-grid { grid-template-columns: 1fr; padding: 8px 10px 24px; }
    .page-header { padding: 14px 14px 6px; }
    .page-header h2 { font-size: 18px; letter-spacing: 2px; }

    .agent-drawer { top: 52px; left: 8px; right: 8px; width: auto; max-width: none; }
    .org-wrap { min-height: 420px; margin: 6px 8px 8px; }

    .login-h { font-size: 26px; }
}

/* ============== LOGIN ============== */
.login {
    position: fixed; inset: 0; z-index: 9000;
    background: radial-gradient(ellipse at center, #060b1a 0%, #000 100%);
    display: flex; align-items: center; justify-content: center;
    transition: opacity 0.6s, visibility 0.6s;
}
.login.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.login-inner {
    text-align: center;
    color: #cfe6ff;
    width: min(720px, 92vw);
}
.login-h {
    font-size: 32px;
    font-weight: 200;
    letter-spacing: 8px;
    color: #cfe6ff;
    text-shadow: 0 0 20px rgba(120,180,255,0.4);
    margin-bottom: 8px;
}
.login-sub {
    font-size: 12px;
    letter-spacing: 3px;
    color: #6b88ad;
    text-transform: uppercase;
    margin-bottom: 38px;
}
.login-cards {
    display: flex; gap: 18px;
    justify-content: center;
    flex-wrap: wrap;
}
.login-card {
    background: rgba(14, 22, 40, 0.7);
    border: 1px solid rgba(120, 180, 255, 0.2);
    border-radius: 16px;
    padding: 26px 22px;
    cursor: pointer;
    min-width: 180px;
    transition: all 0.2s;
    font-family: inherit;
    color: inherit;
}
.login-card:hover {
    border-color: #5cc4ff;
    background: rgba(28, 46, 80, 0.85);
    transform: translateY(-3px);
    box-shadow: 0 8px 30px rgba(80,140,220,0.3);
}
.lc-icon { font-size: 44px; margin-bottom: 10px; }
.lc-name { font-size: 18px; font-weight: 500; letter-spacing: 2px; color: #e8f4ff; }
.lc-role { font-size: 11px; color: #6b88ad; letter-spacing: 2px; margin-top: 4px; text-transform: uppercase; }

/* ============== USER BADGE в шапке ============== */
.user-badge {
    margin-left: auto;
    display: flex; align-items: center; gap: 8px;
    padding: 6px 12px;
    background: rgba(14, 22, 40, 0.55);
    border: 1px solid rgba(120, 180, 255, 0.18);
    border-radius: 999px;
    font-size: 12px;
    color: #cfe6ff;
}
.ub-icon { font-size: 16px; }
.ub-name { letter-spacing: 1px; }
.ub-switch {
    background: transparent;
    border: none;
    color: #6b88ad;
    cursor: pointer;
    font-size: 14px;
    padding: 0 2px;
    transition: color 0.2s, transform 0.3s;
}
.ub-switch:hover { color: #cfe6ff; transform: rotate(180deg); }

/* ===================== Календарь задач (drawer) ===================== */
.cal-wrap { display: flex; flex-direction: column; gap: 14px; }

.cal-add { display: flex; flex-direction: column; gap: 8px;
    background: rgba(120,180,255,0.05); border: 1px solid rgba(120,180,255,0.12);
    border-radius: 12px; padding: 10px 12px; }
.cal-in { width: 100%; background: rgba(0,0,0,0.25); border: 1px solid rgba(120,180,255,0.18);
    color: #e8f1ff; border-radius: 8px; padding: 8px 10px; font-size: 13.5px; }
.cal-add-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.cal-sel, .cal-date { background: rgba(0,0,0,0.25); border: 1px solid rgba(120,180,255,0.18);
    color: #e8f1ff; border-radius: 8px; padding: 7px 8px; font-size: 12.5px; }
.cal-addbtn { margin-left: auto; background: linear-gradient(135deg,#5cc4ff,#b388ff); color: #06121f;
    border: none; border-radius: 8px; padding: 8px 14px; font-weight: 700; font-size: 13px; cursor: pointer; }
.cal-addbtn:hover { filter: brightness(1.08); }
.cal-msg { font-size: 12px; color: #9fb6d4; min-height: 14px; }

.cal-board { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.cal-col { background: rgba(255,255,255,0.02); border: 1px solid rgba(120,180,255,0.10);
    border-radius: 12px; padding: 8px; min-height: 60px; }
.cal-col-h { font-size: 11px; letter-spacing: 1px; text-transform: uppercase; color: #9fb6d4;
    margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center; }
.cal-count { background: rgba(120,180,255,0.15); color: #cfe6ff; border-radius: 999px;
    padding: 1px 7px; font-size: 11px; }
.cal-empty { font-size: 12px; color: #607592; padding: 6px 2px; }

.cal-chip { background: rgba(120,180,255,0.06); border: 1px solid rgba(120,180,255,0.14);
    border-radius: 10px; padding: 7px 8px; margin-bottom: 7px; display: flex; gap: 6px;
    justify-content: space-between; align-items: flex-start; }
.cal-chip.auto { border-left: 3px solid #ffd166; }
.cal-chip.done { opacity: 0.6; }
.cal-chip.done .cal-chip-title { text-decoration: line-through; }
.cal-chip-title { font-size: 12.5px; color: #e8f1ff; line-height: 1.35; }
.cal-chip-det { font-size: 11.5px; color: #9fb6d4; margin-top: 3px; }
.cal-chip-by { font-size: 10.5px; color: #6f86a6; margin-top: 3px; }
.cal-due { font-size: 10.5px; color: #ffd166; background: rgba(255,209,102,0.12);
    border-radius: 6px; padding: 0 5px; margin-left: 4px; white-space: nowrap; }
.cal-chip-ctrls { display: flex; flex-direction: column; gap: 4px; }
.cal-btn { background: rgba(0,0,0,0.25); border: 1px solid rgba(120,180,255,0.2); color: #cfe6ff;
    border-radius: 6px; width: 24px; height: 22px; font-size: 12px; cursor: pointer; line-height: 1; }
.cal-btn.ok:hover { background: rgba(120,255,180,0.18); border-color: #6cffb0; }
.cal-btn.del:hover { background: rgba(255,120,150,0.18); border-color: #ff8aa6; }
.cal-btn:hover { filter: brightness(1.15); }

.cal-month { border-top: 1px solid rgba(120,180,255,0.1); padding-top: 12px; }
.cal-month-h { display: flex; justify-content: space-between; align-items: center;
    font-size: 13px; color: #cfe6ff; font-weight: 600; margin-bottom: 8px; }
.cal-nav { background: rgba(120,180,255,0.1); border: none; color: #cfe6ff; border-radius: 6px;
    width: 26px; height: 24px; cursor: pointer; font-size: 15px; }
.cal-nav:hover { background: rgba(120,180,255,0.2); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.cal-dow { text-align: center; font-size: 10px; color: #6f86a6; padding: 2px 0; }
.cal-cell { position: relative; text-align: center; font-size: 12px; color: #c2d4ec;
    padding: 6px 0; border-radius: 7px; cursor: pointer; border: 1px solid transparent; min-height: 26px; }
.cal-cell.empty { cursor: default; }
.cal-cell.has { color: #e8f1ff; font-weight: 600; }
.cal-cell:not(.empty):hover { background: rgba(120,180,255,0.1); }
.cal-cell.today { border-color: rgba(120,180,255,0.4); }
.cal-cell.sel { background: rgba(120,180,255,0.2); }
.cal-dot { position: absolute; bottom: 3px; left: 50%; transform: translateX(-50%);
    width: 5px; height: 5px; border-radius: 50%; background: #5cc4ff; }
.cal-daylist { margin-top: 12px; }
.cal-daylist-h { font-size: 12px; color: #9fb6d4; margin-bottom: 8px; }

/* отчёт по задаче */
.cal-report { margin-top: 7px; font-size: 11.5px; color: #c2d4ec; line-height: 1.4;
    background: rgba(0,0,0,0.22); border: 1px solid rgba(120,180,255,0.12);
    border-radius: 8px; padding: 6px 8px; }
.cal-report.hidden { display: none; }
.cal-report b { color: #9fb6d4; }
.cal-btn.rep.has { border-color: #6cffb0; color: #aef7d2; }

/* обучение из задачи */
.cal-btn.teach.has, .cal-btn.teach:hover { border-color: #ffd166; color: #ffe39a; }
.cal-teach { margin-top: 7px; }
.cal-teach.hidden { display: none; }
.cal-teach-in { width: 100%; background: rgba(0,0,0,0.25); border: 1px solid rgba(255,209,102,0.25);
    color: #e8f1ff; border-radius: 8px; padding: 6px 8px; font-size: 12px; resize: vertical; }
.cal-teach-row { display: flex; align-items: center; gap: 8px; margin-top: 5px; }
.cal-teach-save { background: rgba(255,209,102,0.16); border: 1px solid rgba(255,209,102,0.35);
    color: #ffe39a; border-radius: 7px; padding: 5px 12px; font-size: 12px; font-weight: 700; cursor: pointer; }
.cal-teach-save:hover { background: rgba(255,209,102,0.28); }
.cal-teach-msg { font-size: 11.5px; color: #9fb6d4; }

/* ===== форма входа (логин+пароль) ===== */
.login-form { display: flex; flex-direction: column; gap: 12px; width: min(340px, 86vw); margin: 22px auto 0; }
.login-form input {
    background: rgba(10,18,36,0.85); border: 1px solid rgba(120,180,255,0.25); color: #e8f1ff;
    border-radius: 12px; padding: 13px 16px; font-size: 15px; outline: none; transition: border 0.2s, box-shadow 0.2s;
}
.login-form input:focus { border-color: #5cc4ff; box-shadow: 0 0 0 3px rgba(92,196,255,0.15); }
.login-form input::placeholder { color: #5f7a9c; }
.login-form button {
    margin-top: 4px; background: linear-gradient(135deg,#5cc4ff,#b388ff); color: #06121f; border: none;
    border-radius: 12px; padding: 13px; font-size: 15px; font-weight: 700; cursor: pointer; letter-spacing: 1px;
    transition: filter 0.2s, transform 0.1s;
}
.login-form button:hover { filter: brightness(1.08); }
.login-form button:active { transform: translateY(1px); }
.login-err { min-height: 16px; font-size: 13px; color: #ff8aa6; text-align: center; }

/* ===== окно отчёта по задаче (с фото и текстами) ===== */
.report-modal {
    position: fixed; inset: 0; z-index: 9500;
    background: rgba(2, 6, 16, 0.78); backdrop-filter: blur(4px);
    display: none; align-items: center; justify-content: center; padding: 24px;
}
.report-modal.open { display: flex; }
.report-card {
    width: min(760px, 96vw); max-height: 88vh; display: flex; flex-direction: column;
    background: #0c1426; border: 1px solid rgba(120,180,255,0.25); border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.6); overflow: hidden;
}
.report-head {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 14px 18px; border-bottom: 1px solid rgba(120,180,255,0.15);
    background: rgba(20,40,80,0.4);
}
.report-title { font-size: 15px; font-weight: 600; color: #dceeff; letter-spacing: 0.3px; }
.report-close {
    background: rgba(120,180,255,0.12); border: 1px solid rgba(120,180,255,0.25); color: #cfe6ff;
    width: 32px; height: 32px; border-radius: 9px; cursor: pointer; font-size: 15px; flex: 0 0 auto;
}
.report-close:hover { background: rgba(255,126,157,0.25); border-color: rgba(255,126,157,0.5); }
.report-body {
    padding: 16px 20px; overflow-y: auto; color: #cfe6ff; font-size: 14px; line-height: 1.6;
    white-space: normal; word-break: break-word;
}
.report-img {
    display: block; max-width: 280px; width: 100%; height: auto; margin: 10px 0 14px;
    border-radius: 12px; border: 1px solid rgba(120,180,255,0.2); background: #060b16;
}
.report-empty { color: #6b88ad; font-style: italic; text-align: center; padding: 30px 0; }
@media (max-width: 760px) {
    .report-modal { padding: 0; }
    .report-card { width: 100vw; max-height: 100vh; height: 100vh; border-radius: 0; }
    .report-img { max-width: 100%; }
}

/* ===== Вкладка Календарь ===== */
.calendar-root { padding: 4px 2px 28px; max-width: 920px; flex: 1; min-height: 0; overflow-y: auto; width: 100%; }
.cal-h { margin: 18px 0 8px; font-size: 14px; letter-spacing: .04em; text-transform: uppercase; opacity: .75; }
.cal-date { margin: 0 0 14px; }
.cal-date-h { font-weight: 600; font-size: 13px; opacity: .65; margin: 6px 0 4px; border-bottom: 1px solid rgba(255,255,255,.08); padding-bottom: 3px; }
.cal-task { padding: 7px 10px; margin: 5px 0; border-radius: 8px; background: rgba(255,255,255,.04); }
.cal-line { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.cal-agent { font-size: 12px; opacity: .7; min-width: 120px; }
.cal-title { font-size: 14px; }
.cal-rep { font-size: 12px; opacity: .6; margin-top: 4px; white-space: normal; }

/* ===== Календарь: тулбар вида + сетка по дням ===== */
.cal-toolbar { display: flex; gap: 8px; margin: 4px 0 12px; }
.cal-vbtn { padding: 6px 14px; border-radius: 8px; border: 1px solid rgba(255,255,255,.15); background: transparent; color: inherit; cursor: pointer; font-size: 13px; }
.cal-vbtn.active { background: rgba(120,170,255,.22); border-color: rgba(120,170,255,.5); }
.cal-gridhead { display: flex; align-items: center; gap: 14px; margin: 6px 0 10px; }
.cal-month { font-weight: 600; font-size: 15px; min-width: 150px; text-align: center; }
.cal-nav { width: 30px; height: 30px; border-radius: 8px; border: 1px solid rgba(255,255,255,.15); background: transparent; color: inherit; cursor: pointer; font-size: 16px; }
.cal-wd { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; opacity: .6; font-size: 12px; margin-bottom: 4px; }
.cal-wd > div { text-align: center; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-cell { min-height: 84px; border-radius: 8px; background: rgba(255,255,255,.04); padding: 4px 5px; overflow: hidden; }
.cal-cell.empty { background: transparent; }
.cal-cell.today { outline: 1px solid rgba(120,170,255,.55); }
.cal-cell-d { font-size: 12px; opacity: .6; margin-bottom: 3px; }
.cal-cell .cal-task { padding: 3px 5px; margin: 3px 0; border-radius: 6px; font-size: 11px; line-height: 1.25; }
.cal-task.q { background: rgba(120,170,255,.16); }
.cal-task.d { background: rgba(120,255,170,.10); opacity: .8; }
.cal-task .cal-agent { font-size: 10px; opacity: .65; display: block; }
.cal-undated { margin-top: 18px; }
