.telegram-flow-header .eyebrow,
.flow-panel-heading .eyebrow {
    display: block;
    margin-bottom: 4px;
    color: var(--brand-accent);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .14em;
    line-height: 1.2;
    text-transform: uppercase;
}

.telegram-flow-header h1 {
    margin-bottom: 4px;
}

.telegram-flow-context {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 18px;
}

.flow-bot-selector {
    min-width: min(360px, 100%);
}

.flow-bot-selector .field {
    margin: 0;
}

.flow-plan-note {
    display: flex;
    align-items: center;
    gap: 9px;
    max-width: 530px;
    padding: 11px 14px;
    border: 1px solid rgba(240, 90, 65, .18);
    border-radius: 12px;
    background: var(--coral-soft);
    color: var(--text);
    font-size: 12px;
    font-weight: 600;
}

.flow-plan-note svg {
    flex: 0 0 auto;
    width: 16px;
    color: var(--brand-accent);
}

.telegram-empty-state {
    min-height: 420px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.telegram-empty-state p {
    max-width: 480px;
    color: var(--muted);
}

.telegram-flow-editor {
    display: grid;
    grid-template-columns: 250px minmax(540px, 1fr) 330px;
    min-height: 700px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.flow-palette,
.flow-inspector {
    min-width: 0;
    background: var(--surface);
}

.flow-palette {
    padding: 22px 16px 18px;
    border-right: 1px solid var(--line);
}

.flow-inspector {
    padding: 22px 18px 18px;
    border-left: 1px solid var(--line);
}

.flow-panel-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.flow-panel-heading h2 {
    margin: 0;
    color: var(--brand-dark);
    font-size: 16px;
    letter-spacing: -.02em;
}

.flow-panel-mark {
    display: grid;
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    place-items: center;
    border-radius: 10px;
    background: var(--coral-soft);
    color: var(--brand-accent);
}

.flow-panel-mark.inspector {
    background: #e9f3ee;
    color: var(--brand-dark);
}

.flow-panel-mark svg {
    width: 17px;
}

.flow-panel-help {
    margin: 10px 0 20px;
    color: var(--muted);
    font-size: 11px;
    line-height: 1.5;
}

.flow-palette-group {
    display: grid;
    gap: 8px;
    margin-top: 18px;
}

.flow-palette-label {
    color: var(--muted);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .12em;
    text-transform: uppercase;
}

.flow-palette-item {
    display: grid;
    grid-template-columns: 30px minmax(0, 1fr) 15px;
    align-items: center;
    gap: 9px;
    width: 100%;
    min-height: 54px;
    padding: 8px 9px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    text-align: left;
    transition: border-color .18s ease, background .18s ease, transform .18s ease;
}

.flow-palette-item:hover:not(:disabled) {
    border-color: rgba(240, 90, 65, .42);
    background: #fffaf8;
    transform: translateY(-1px);
}

.flow-palette-item:disabled {
    cursor: not-allowed;
    opacity: .65;
}

.flow-palette-item > svg {
    width: 14px;
    color: var(--muted);
}

.flow-palette-item strong,
.flow-palette-item small {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.flow-palette-item strong {
    font-size: 11px;
}

.flow-palette-item small {
    margin-top: 2px;
    color: var(--muted);
    font-size: 9px;
}

.flow-node-icon {
    display: grid;
    width: 30px;
    height: 30px;
    place-items: center;
    border-radius: 9px;
    background: var(--coral-soft);
    color: var(--brand-accent);
}

.flow-node-icon.reply {
    background: #e8f4ed;
    color: var(--green-deep);
}

.flow-node-icon.media {
    background: #edf2ff;
    color: #4963a4;
}

.flow-node-icon.buttons {
    background: #f7f0ff;
    color: #7b4caa;
}

.flow-node-icon.pix {
    background: #fff6dd;
    color: #a36d13;
}

.flow-node-icon svg {
    width: 16px;
}

.flow-palette-tip {
    display: flex;
    gap: 8px;
    margin-top: 24px;
    padding: 11px;
    border-radius: 10px;
    background: var(--deep);
    color: var(--muted);
    font-size: 10px;
    line-height: 1.45;
}

.flow-palette-tip svg {
    flex: 0 0 auto;
    width: 14px;
    color: var(--brand-accent);
}

.flow-canvas-shell {
    display: flex;
    min-width: 0;
    flex-direction: column;
    background: var(--deep);
}

.flow-canvas-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 66px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--line);
    background: var(--surface);
}

.flow-toolbar-title {
    display: grid;
    grid-template-columns: 8px auto;
    align-items: center;
    column-gap: 8px;
}

.flow-toolbar-title strong {
    color: var(--brand-dark);
    font-size: 12px;
}

.flow-toolbar-title small {
    grid-column: 2;
    color: var(--muted);
    font-size: 10px;
}

.flow-live-dot {
    grid-row: 1 / span 2;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 0 4px rgba(21, 149, 106, .12);
}

.flow-toolbar-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.flow-toolbar-actions .icon-button {
    width: 30px;
    height: 30px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--muted);
}

.flow-toolbar-actions .icon-button svg {
    width: 14px;
}

.flow-zoom-value {
    min-width: 43px;
    color: var(--muted);
    font-size: 10px;
    font-weight: 700;
    text-align: center;
}

.btn-small {
    min-height: 30px;
    padding: 7px 10px;
    font-size: 10px;
}

.btn-small svg {
    width: 13px;
}

.flow-canvas-viewport {
    position: relative;
    flex: 1 1 auto;
    min-height: 570px;
    overflow: hidden;
    cursor: grab;
    background-color: var(--deep);
    background-image: radial-gradient(rgba(6, 59, 47, .18) 1px, transparent 1px), radial-gradient(rgba(6, 59, 47, .08) 1px, transparent 1px);
    background-position: 0 0, 14px 14px;
    background-size: 28px 28px;
}

.flow-canvas-viewport.is-panning {
    cursor: grabbing;
}

.flow-canvas-world {
    position: absolute;
    top: 0;
    left: 0;
    width: 2400px;
    height: 1600px;
    transform-origin: 0 0;
}

.flow-edge-layer,
.flow-node-layer {
    position: absolute;
    top: 0;
    left: 0;
    width: 2400px;
    height: 1600px;
    overflow: visible;
}

.flow-edge {
    fill: none;
    stroke: #9baea8;
    stroke-width: 2;
    stroke-dasharray: 5 5;
}

.flow-edge-dot {
    fill: var(--brand-accent);
    stroke: var(--surface);
    stroke-width: 2;
}

.flow-node {
    position: absolute;
    z-index: 2;
    display: grid;
    width: 244px;
    min-height: 116px;
    padding: 12px 14px 13px;
    border: 1px solid #d7e2dd;
    border-top: 3px solid var(--brand-accent);
    border-radius: 13px;
    background: var(--surface);
    box-shadow: 0 8px 20px rgba(6, 59, 47, .1);
    cursor: grab;
    transition: box-shadow .16s ease, border-color .16s ease;
    user-select: none;
}

.flow-node-reply {
    border-top-color: var(--green);
}

.flow-node:hover,
.flow-node.is-selected {
    border-color: var(--brand-accent);
    box-shadow: 0 12px 28px rgba(6, 59, 47, .17);
}

.flow-node-reply:hover,
.flow-node-reply.is-selected {
    border-color: var(--green);
}

.flow-node:active {
    cursor: grabbing;
}

.flow-node-topline {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}

.flow-node-topline .flow-node-icon {
    width: 25px;
    height: 25px;
    border-radius: 7px;
}

.flow-node-topline .flow-node-icon svg {
    width: 14px;
}

.flow-node-type {
    color: var(--muted);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .06em;
    text-transform: uppercase;
}

.flow-node-menu {
    display: grid;
    width: 24px;
    height: 24px;
    margin-left: auto;
    padding: 0;
    place-items: center;
    border: 0;
    background: transparent;
    color: var(--muted);
}

.flow-node-menu svg {
    width: 16px;
}

.flow-node > strong {
    overflow: hidden;
    color: var(--brand-dark);
    font-size: 12px;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.flow-node > small {
    margin-top: 3px;
    overflow: hidden;
    color: var(--muted);
    font-size: 10px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.flow-node-port {
    position: absolute;
    top: 50%;
    width: 10px;
    height: 10px;
    margin-top: -5px;
    border: 2px solid var(--surface);
    border-radius: 50%;
    background: var(--brand-accent);
    box-shadow: 0 0 0 1px var(--brand-accent);
}

.flow-node-reply .flow-node-port {
    background: var(--green);
    box-shadow: 0 0 0 1px var(--green);
}

.port-out {
    right: -6px;
}

.port-in {
    left: -6px;
}

.flow-canvas-hint {
    position: absolute;
    top: 50%;
    left: 50%;
    display: grid;
    justify-items: center;
    gap: 5px;
    width: 230px;
    padding: 18px;
    color: var(--muted);
    text-align: center;
    transform: translate(-50%, -50%);
    pointer-events: none;
}

.flow-canvas-hint svg {
    width: 26px;
    margin-bottom: 4px;
    color: var(--brand-accent);
}

.flow-canvas-hint strong {
    color: var(--brand-dark);
    font-size: 13px;
}

.flow-canvas-hint span {
    font-size: 11px;
}

.flow-canvas-footer {
    display: flex;
    gap: 18px;
    min-height: 34px;
    padding: 8px 16px;
    border-top: 1px solid var(--line);
    background: var(--surface);
    color: var(--muted);
    font-size: 10px;
}

.flow-canvas-footer span {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.flow-canvas-footer svg {
    width: 13px;
}

.flow-inspector-form {
    display: flex;
    min-height: 0;
    flex-direction: column;
}

.flow-inspector-fields {
    min-height: 0;
    overflow-y: auto;
    padding-right: 3px;
}

.flow-inspector .field {
    margin-bottom: 13px;
}

.flow-inspector .field label {
    margin-bottom: 5px;
    font-size: 10px;
}

.flow-inspector input,
.flow-inspector select,
.flow-inspector textarea {
    min-height: 36px;
    padding: 8px 10px;
    border-radius: 8px;
    font-size: 11px;
}

.flow-inspector textarea {
    line-height: 1.45;
}

.flow-inspector small {
    display: block;
    margin-top: 5px;
    color: var(--muted);
    font-size: 9px;
    line-height: 1.35;
}

.flow-inspector small a {
    color: var(--brand-dark);
    font-weight: 700;
}

.flow-keyword-control {
    display: flex;
    align-items: stretch;
    gap: 6px;
}

.flow-keyword-control input {
    min-width: 0;
    flex: 1 1 auto;
}

.flow-keyword-control .btn {
    flex: 0 0 auto;
    min-width: 58px;
    padding-inline: 9px;
    color: var(--brand-dark);
    font-weight: 800;
}

.flow-inspector-actions {
    display: flex;
    gap: 8px;
    padding-top: 10px;
    border-top: 1px solid var(--line);
}

.flow-inspector-actions .btn {
    flex: 1 1 auto;
    min-height: 38px;
    padding: 8px 10px;
    font-size: 11px;
}

.flow-inspector-actions .btn-danger {
    flex: 0 0 auto;
}

.is-hidden {
    display: none !important;
}

@media (max-width: 1240px) {
    .telegram-flow-editor {
        grid-template-columns: 220px minmax(480px, 1fr) 290px;
    }
}

@media (max-width: 1040px) {
    .telegram-flow-editor {
        grid-template-columns: 200px minmax(420px, 1fr);
    }

    .flow-inspector {
        grid-column: 1 / -1;
        border-top: 1px solid var(--line);
        border-left: 0;
    }

    .flow-inspector-form {
        display: grid;
        grid-template-columns: 1fr auto;
        align-items: end;
        gap: 16px;
    }

    .flow-inspector-fields {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 0 12px;
        overflow: visible;
    }

    .flow-inspector-actions {
        border-top: 0;
    }
}

@media (max-width: 760px) {
    .telegram-flow-context {
        align-items: stretch;
        flex-direction: column;
    }

    .flow-bot-selector {
        min-width: 0;
    }

    .telegram-flow-editor {
        display: flex;
        flex-direction: column;
        min-height: 0;
    }

    .flow-palette {
        overflow-x: auto;
        padding: 16px;
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

    .flow-palette-group {
        display: flex;
        align-items: stretch;
        gap: 8px;
        overflow-x: auto;
    }

    .flow-palette-label,
    .flow-palette-tip,
    .flow-panel-help {
        display: none;
    }

    .flow-palette-item {
        flex: 0 0 190px;
    }

    .flow-canvas-viewport {
        min-height: 560px;
    }

    .flow-inspector {
        border-top: 1px solid var(--line);
    }

    .flow-inspector-form {
        display: block;
    }

    .flow-inspector-fields {
        display: block;
    }

    .flow-inspector-actions {
        margin-top: 8px;
        border-top: 1px solid var(--line);
    }

    .flow-canvas-toolbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .flow-toolbar-actions {
        width: 100%;
    }

    .flow-toolbar-actions .btn-small {
        margin-left: auto;
    }

    .flow-canvas-footer {
        flex-wrap: wrap;
        gap: 5px 12px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .flow-palette-item,
    .flow-node {
        transition: none;
    }
}

/* Telegram flow library */
.telegram-library-header .eyebrow,
.telegram-library-list .eyebrow,
.telegram-import-card .eyebrow,
.telegram-library-guide .eyebrow {
    display: block;
    margin-bottom: 4px;
    color: var(--brand-accent);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .14em;
    line-height: 1.2;
    text-transform: uppercase;
}

.telegram-library-header h1 {
    margin-bottom: 4px;
}

.telegram-library-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.1fr) minmax(300px, .9fr);
    gap: 18px;
    margin-bottom: 28px;
}

.telegram-import-card,
.telegram-library-guide {
    min-width: 0;
}

.telegram-import-card form {
    margin-top: 20px;
}

.telegram-import-card textarea {
    min-height: 105px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 11px;
    letter-spacing: .01em;
}

.telegram-import-card .field {
    margin-bottom: 13px;
}

.library-bot-picker {
    margin: 17px 0 14px;
}

.library-bot-picker > label,
.library-bot-picker > small {
    display: block;
    margin-bottom: 8px;
    color: var(--muted);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.library-bot-options {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
}

.library-check {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 30px;
    padding: 6px 9px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--deep);
    color: var(--text);
    cursor: pointer;
    font-size: 10px;
    font-weight: 700;
}

.library-check:has(input:checked) {
    border-color: rgba(240, 90, 65, .4);
    background: var(--coral-soft);
    color: var(--brand-dark);
}

.library-check input {
    accent-color: var(--brand-accent);
}

.library-toggle {
    display: flex;
    align-items: flex-start;
    gap: 7px;
    margin: 12px 0 16px;
    color: var(--muted);
    cursor: pointer;
    font-size: 10px;
    line-height: 1.4;
}

.library-toggle input {
    flex: 0 0 auto;
    margin-top: 2px;
    accent-color: var(--brand-accent);
}

.library-steps {
    display: grid;
    gap: 13px;
    margin: 24px 0;
}

.library-steps > div {
    display: grid;
    grid-template-columns: 28px minmax(0, 1fr);
    align-items: start;
    gap: 10px;
}

.library-steps > div > span {
    display: grid;
    width: 26px;
    height: 26px;
    place-items: center;
    border-radius: 50%;
    background: var(--coral-soft);
    color: var(--brand-accent);
    font-size: 11px;
    font-weight: 800;
}

.library-steps p {
    display: grid;
    gap: 2px;
    margin: 2px 0 0;
}

.library-steps strong {
    color: var(--brand-dark);
    font-size: 12px;
}

.library-steps small {
    color: var(--muted);
    font-size: 10px;
}

.library-section-heading {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 14px;
}

.library-section-heading h2 {
    margin: 0;
    color: var(--brand-dark);
    font-size: 18px;
}

.telegram-template-card {
    min-width: 0;
}

.template-card-top,
.template-card-meta,
.template-assigned-bots {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.template-card-top {
    margin-bottom: 16px;
}

.template-card-top .flow-node-icon {
    width: 34px;
    height: 34px;
}

.telegram-template-card h3 {
    margin-bottom: 5px;
}

.telegram-template-card > p {
    min-height: 24px;
    margin-bottom: 14px;
}

.template-card-meta {
    justify-content: flex-start;
    margin-bottom: 14px;
    color: var(--muted);
    font-size: 10px;
}

.template-card-meta span {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.template-card-meta svg {
    width: 13px;
}

.template-code-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 6px;
    margin-bottom: 12px;
}

.template-code-row input {
    min-width: 0;
    padding: 9px 10px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--deep);
    color: var(--muted);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 9px;
    text-overflow: ellipsis;
}

.template-code-row .btn {
    min-height: 34px;
    padding: 8px 10px;
}

.template-code-row svg {
    width: 14px;
}

.template-assigned-bots {
    justify-content: flex-start;
    min-height: 23px;
    margin-bottom: 16px;
}

.template-assigned-bots .badge {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.template-card-actions {
    align-items: center;
    flex-wrap: wrap;
}

.template-card-actions > .btn,
.template-card-actions > form > .btn {
    min-height: 34px;
    padding: 8px 11px;
    font-size: 10px;
}

.template-assign-details {
    position: relative;
}

.template-assign-details summary {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    list-style: none;
    cursor: pointer;
}

.template-assign-details summary::-webkit-details-marker {
    display: none;
}

.template-assign-details summary svg {
    width: 13px;
}

.template-assign-form {
    position: absolute;
    z-index: 5;
    right: 0;
    bottom: calc(100% + 8px);
    display: grid;
    gap: 7px;
    width: 245px;
    padding: 13px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    box-shadow: var(--shadow-lg);
}

.template-assign-form .library-bot-options {
    display: grid;
    max-height: 140px;
    overflow-y: auto;
}

.template-assign-form .library-toggle {
    margin: 3px 0 4px;
}

.template-assign-form .btn {
    width: 100%;
}

@media (max-width: 840px) {
    .telegram-library-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 560px) {
    .library-section-heading {
        align-items: flex-start;
        flex-direction: column;
    }

    .template-assign-form {
        right: auto;
        left: 0;
    }
}
