.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(360px, .95fr) minmax(300px, 1.05fr);
    align-items: start;
    gap: 18px;
    margin-bottom: 28px;
}

.telegram-import-card {
    max-width: 680px;
    padding: 22px 24px;
}

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

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

.telegram-import-meta {
    gap: 12px;
}

.telegram-import-meta .field {
    min-width: 0;
}

.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,
.library-toggle 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;
}

.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;
}

.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%;
}

.telegram-save-library-panel {
    margin-top: 18px;
}

.telegram-save-library-panel .flow-panel-help {
    max-width: 680px;
}

.library-save-form .field {
    margin-bottom: 0;
}

.template-edit-meta {
    display: grid;
    grid-template-columns: minmax(180px, .8fr) minmax(240px, 1.2fr) auto;
    align-items: end;
    gap: 12px;
    width: 100%;
    margin-top: 14px;
}

.template-edit-meta .field {
    margin: 0;
}

.template-edit-meta .badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    min-height: 36px;
    white-space: nowrap;
}

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

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

    .template-edit-meta {
        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;
    }
}

/* Biblioteca Telegram: hierarquia, busca e cartões de operação. */
.telegram-library-shell {
    width: 100%;
    max-width: 1380px;
    margin: 0 auto;
}

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

.telegram-library-header .eyebrow {
    background: var(--coral-soft);
    border-color: rgba(240, 90, 65, .2);
}

.telegram-library-header h1 {
    margin-top: 10px;
    font-size: clamp(30px, 4vw, 42px);
}

.telegram-library-summary {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 22px;
}

.library-stat {
    display: flex;
    align-items: center;
    gap: 13px;
    min-width: 0;
    padding: 17px 18px;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.library-stat-icon {
    display: grid;
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    place-items: center;
    border-radius: 12px;
    background: var(--coral-soft);
    color: var(--brand-accent);
}

.library-stat-icon svg {
    width: 18px;
}

.library-stat div {
    display: grid;
    gap: 1px;
    min-width: 0;
}

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

.library-stat small {
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.library-stat strong {
    color: var(--brand-dark);
    font-size: 25px;
    line-height: 1.1;
}

.telegram-library-grid {
    grid-template-columns: minmax(0, 1.2fr) minmax(320px, .8fr);
    align-items: stretch;
    gap: 20px;
}

.telegram-import-card,
.telegram-library-guide {
    max-width: none;
    padding: 27px;
}

.telegram-import-card {
    display: flex;
    flex-direction: column;
}

.telegram-import-card .flow-panel-help {
    max-width: 680px;
}

.telegram-import-form {
    display: grid;
    gap: 2px;
    margin-top: 18px !important;
}

.telegram-import-form .field {
    margin-bottom: 11px;
}

.telegram-import-form .field label {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
}

.telegram-import-form .field label small {
    color: var(--muted);
    font-size: 9px;
    font-weight: 500;
}

.import-code-field textarea {
    min-height: 92px;
    border-color: rgba(6, 59, 47, .28);
    background: #fbfdfc;
    font-size: 11px;
}

.import-code-field small {
    color: var(--muted);
    font-size: 10px;
}

.telegram-import-assignment {
    padding: 7px 0 3px;
    border-top: 1px solid var(--line);
}

.telegram-import-assignment .library-bot-picker {
    margin-top: 12px;
}

.telegram-import-card .btn-primary {
    width: 100%;
    margin-top: 4px;
}

.telegram-library-guide {
    display: flex;
    flex-direction: column;
}

.telegram-library-guide .flow-palette-tip {
    margin-top: auto;
}

.library-steps {
    gap: 18px;
    margin: 27px 0;
}

.library-steps > div {
    grid-template-columns: 34px minmax(0, 1fr);
    gap: 12px;
}

.library-steps > div > span {
    width: 32px;
    height: 32px;
    background: var(--brand-dark);
    color: #fff;
    font-size: 10px;
}

.library-steps strong {
    font-size: 13px;
}

.library-steps small {
    font-size: 11px;
}

.telegram-library-list {
    margin-top: 30px;
}

.library-section-heading {
    align-items: end;
    margin-bottom: 18px;
}

.library-section-heading h2 {
    margin-top: 5px;
    font-size: 22px;
}

.library-section-heading p {
    margin: 5px 0 0;
    color: var(--muted);
    font-size: 12px;
}

.library-collection-tools {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}

.library-search {
    display: flex;
    align-items: center;
    gap: 7px;
    min-width: min(270px, 100%);
    height: 38px;
    padding: 0 11px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    color: var(--muted);
}

.library-search svg {
    flex: 0 0 auto;
    width: 15px;
}

.library-search input {
    min-width: 0;
    width: 100%;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--text);
    font-size: 11px;
}

.library-collection-tools select {
    height: 38px;
    padding: 0 10px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    font-size: 11px;
}

.telegram-template-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(330px, 1fr));
    align-items: stretch;
    gap: 18px;
}

.telegram-template-card {
    display: flex;
    min-width: 0;
    min-height: 360px;
    flex-direction: column;
    padding: 22px;
}

.telegram-template-card[hidden],
.library-filter-empty[hidden] {
    display: none;
}

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

.template-status {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    color: var(--muted);
    font-size: 10px;
    font-weight: 800;
}

.template-status .status-dot {
    width: 6px;
    height: 6px;
    margin: 0;
    background: var(--muted);
    box-shadow: none;
}

.template-status.is-assigned {
    color: var(--green-deep);
}

.template-status.is-assigned .status-dot {
    background: var(--green);
    box-shadow: 0 0 8px rgba(21, 149, 106, .5);
}

.template-card-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
}

.telegram-template-card h3 {
    margin: 0 0 5px;
    overflow-wrap: anywhere;
}

.template-card-description {
    max-width: 30ch;
    margin: 0;
    overflow: hidden;
    color: var(--muted);
    font-size: 11px;
    line-height: 1.45;
    text-overflow: ellipsis;
}

.template-updated {
    display: inline-flex;
    align-items: center;
    flex: 0 0 auto;
    gap: 4px;
    color: var(--muted);
    font-size: 9px;
    white-space: nowrap;
}

.template-updated svg {
    width: 12px;
}

.template-card-meta {
    margin: 18px 0 15px;
    padding: 10px 0;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    font-size: 10px;
}

.template-code-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 9px;
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.template-copy-button {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 0;
    border: 0;
    background: transparent;
    color: var(--brand-accent);
    font-size: 9px;
    font-weight: 800;
}

.template-copy-button svg {
    width: 12px;
}

.template-code-row {
    margin-bottom: 14px;
}

.template-code-row .icon-button {
    border: 1px solid var(--line);
    background: var(--high);
}

.template-assigned-bots {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    flex-wrap: wrap;
    min-height: 35px;
    margin-bottom: 18px;
    gap: 5px;
}

.assigned-label {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    width: 100%;
    color: var(--muted);
    font-size: 9px;
    font-weight: 800;
    letter-spacing: .06em;
    text-transform: uppercase;
}

.assigned-label svg {
    width: 12px;
}

.template-card-actions {
    align-items: stretch;
    margin-top: auto;
    padding-top: 15px;
    border-top: 1px solid var(--line);
}

.template-card-actions > .btn,
.template-card-actions > form > .btn,
.template-card-actions > details > summary {
    min-height: 36px;
    padding: 9px 11px;
    font-size: 10px;
}

.template-card-actions > .btn-primary {
    flex: 1 1 auto;
}

.template-delete-button {
    width: 38px;
    padding: 8px !important;
}

.template-delete-button svg {
    width: 15px;
}

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

.template-assign-form {
    top: calc(100% + 8px);
    right: 0;
    bottom: auto;
    width: 260px;
}

.library-filter-empty {
    display: grid;
    justify-items: center;
    gap: 6px;
    padding: 42px 20px;
    border: 1px dashed var(--line);
    border-radius: var(--radius-lg);
    background: rgba(255, 255, 255, .55);
    color: var(--muted);
    text-align: center;
}

.library-filter-empty svg {
    width: 28px;
    color: var(--brand-accent);
}

.library-filter-empty strong {
    color: var(--brand-dark);
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

@media (max-width: 980px) {
    .telegram-library-summary {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .telegram-library-grid {
        grid-template-columns: 1fr;
    }

    .telegram-import-card,
    .telegram-library-guide {
        max-width: none;
    }
}

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

    .library-section-heading {
        align-items: flex-start;
    }

    .library-collection-tools {
        width: 100%;
        justify-content: stretch;
    }

    .library-search,
    .library-collection-tools select {
        flex: 1 1 100%;
        width: 100%;
    }

    .library-collection-tools .badge {
        margin-top: 2px;
    }

    .telegram-template-grid {
        grid-template-columns: 1fr;
    }
}

/* Import card spacing refinement */
.telegram-import-card {
    padding: 32px;
}

.telegram-import-card .flow-panel-heading {
    margin-bottom: 2px;
}

.telegram-import-card .flow-panel-help {
    margin: 12px 0 24px;
}

.telegram-import-form {
    gap: 16px;
    margin-top: 0 !important;
}

.telegram-import-form .field {
    margin-bottom: 0;
}

.telegram-import-meta {
    gap: 16px;
    margin-top: 0;
}

.telegram-import-assignment {
    margin-top: 2px;
    padding: 18px 0 6px;
}

.telegram-import-assignment .library-bot-picker {
    margin: 0 0 14px;
}

.telegram-import-card .library-toggle {
    margin: 0;
}

.telegram-import-card .btn-primary {
    margin-top: 0;
}

@media (max-width: 700px) {
    .telegram-import-card {
        padding: 22px 18px;
    }

    .telegram-import-form {
        gap: 13px;
    }
}
