* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
    color: #172033;
    background:
        radial-gradient(circle at top left, rgba(38, 110, 255, 0.12), transparent 30%),
        linear-gradient(180deg, #f7f9fc 0%, #eef3f8 100%);
}

code {
    padding: 0.12rem 0.35rem;
    border-radius: 0.35rem;
    background: #f1f5fb;
    font-family: "IBM Plex Mono", "SFMono-Regular", monospace;
}

.page-shell,
.tab-shell {
    min-height: 100vh;
}

.page,
.tab-page {
    max-width: 1120px;
    margin: 0 auto;
    padding: 2rem 1.25rem 3rem;
}

.hero,
.tab-header {
    display: flex;
    justify-content: space-between;
    gap: 1.5rem;
    align-items: flex-start;
    margin-bottom: 1.5rem;
}

.eyebrow {
    display: inline-block;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-size: 0.78rem;
    color: #3762d6;
}

h1,
h2 {
    margin: 0 0 0.5rem;
    line-height: 1.1;
}

.lead,
.panel p {
    margin: 0;
    color: #4f5d78;
}

.panel {
    padding: 1.25rem;
    margin-bottom: 1rem;
    border: 1px solid rgba(55, 98, 214, 0.12);
    border-radius: 1rem;
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 22px 48px rgba(26, 42, 73, 0.08);
}

.panel-danger {
    border-color: rgba(214, 55, 80, 0.25);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: flex-start;
    margin-bottom: 1rem;
}

.meta-card {
    min-width: 240px;
    padding: 1rem;
    border-radius: 1rem;
    background: #14213d;
    color: #edf2fb;
    box-shadow: 0 22px 48px rgba(20, 33, 61, 0.24);
}

.meta-card.compact {
    min-width: 220px;
}

.meta-card div + div {
    margin-top: 0.45rem;
}

.grid-two,
.grid-three {
    display: grid;
    gap: 1rem;
}

.grid-two {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-three {
    grid-template-columns: 160px 220px minmax(240px, 1fr);
}

.field {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.field span {
    font-weight: 600;
}

.field small,
.hint {
    color: #5f6c86;
}

input[type="text"],
input[type="password"],
input[type="search"],
select {
    width: 100%;
    min-height: 2.8rem;
    padding: 0.75rem 0.85rem;
    border: 1px solid #ccd6e5;
    border-radius: 0.8rem;
    background: #fff;
    font: inherit;
    color: inherit;
}

.tab-shell {
    min-height: 100vh;
    background: #eef2f7;
}

.tab-page {
    max-width: 1040px;
    padding: 1rem 1rem 1.5rem;
}

.tab-header {
    align-items: center;
    margin-bottom: 0.75rem;
}

.tab-header h1 {
    margin-bottom: 0;
    font-size: 1.35rem;
}

.tab-context {
    color: #45546a;
    font-size: 0.9rem;
}

.tab-shell .panel {
    padding: 0.9rem;
    margin-bottom: 0.75rem;
    border-color: #dce3ec;
    border-radius: 0.5rem;
    box-shadow: none;
    background: #fff;
}

.tab-status-panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.75rem;
    align-items: center;
}

.compact-header {
    margin-bottom: 0.75rem;
}

.compact-header h2 {
    margin-bottom: 0.2rem;
    font-size: 1.05rem;
}

.compact-header p {
    font-size: 0.9rem;
}

.state-card-compact {
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
}

.state-summary {
    display: grid;
    gap: 0.75rem;
    align-items: center;
}

.state-main {
    display: grid;
    gap: 0.15rem;
    min-width: 0;
}

.state-main strong,
.state-project-link {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.98rem;
}

.state-project-link {
    color: #172033;
    font-weight: 700;
    text-decoration: none;
}

.state-project-link:hover {
    color: #2452b8;
    text-decoration: underline;
}

.state-main span,
.state-error {
    color: #66758a;
    font-size: 0.86rem;
}

.state-error {
    grid-column: 1 / -1;
    color: #a03647;
}

.tab-shell .action-bar {
    justify-content: flex-end;
    flex-wrap: nowrap;
}

.tab-shell .button {
    min-height: 2.15rem;
    padding: 0.45rem 0.75rem;
    border-radius: 0.45rem;
    background: #2f6fed;
    font-size: 0.86rem;
}

.tab-shell .button-secondary {
    background: #edf3ff;
    color: #2452b8;
}

.tab-shell .button-ghost {
    background: #fff;
    color: #53657a;
    border: 1px solid #d4deea;
}

.tab-shell .search-row.project-filter-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.tab-shell input[type="search"] {
    min-height: 2.25rem;
    min-width: 0;
    padding: 0.45rem 0.65rem;
    border-radius: 0.45rem;
    font-size: 0.9rem;
}

.project-list {
    display: grid;
    max-height: 360px;
    overflow: auto;
    border: 1px solid #dde5ef;
    border-radius: 0.5rem;
    background: #fff;
    scrollbar-gutter: stable;
}

.project-row {
    display: grid;
    grid-template-columns: 72px minmax(0, 1fr) auto;
    gap: 0.75rem;
    align-items: center;
    min-height: 3.4rem;
    padding: 0.55rem 0.65rem;
    border-bottom: 1px solid #edf1f6;
}

.project-row:last-child {
    border-bottom: 0;
}

.project-row-current {
    background: #f3f8ff;
}

.project-id {
    color: #66758a;
    font-size: 0.86rem;
}

.project-name {
    display: grid;
    gap: 0.15rem;
    min-width: 0;
}

.project-name strong,
.project-name a {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 0.94rem;
}

.project-name a {
    color: #172033;
    font-weight: 700;
    text-decoration: none;
}

.project-name a:hover {
    color: #2452b8;
    text-decoration: underline;
}

.project-name span {
    color: #728095;
    font-size: 0.8rem;
}

.project-empty {
    padding: 1.25rem;
    color: #66758a;
    text-align: center;
}

input:focus,
select:focus {
    outline: 2px solid rgba(55, 98, 214, 0.2);
    border-color: #3762d6;
}

.rules-list {
    display: grid;
    gap: 0.9rem;
}

.rule-card,
.state-card,
.search-item {
    padding: 1rem;
    border: 1px solid #dde5f0;
    border-radius: 0.9rem;
    background: #fbfdff;
}

.rule-actions,
.action-bar,
.search-row,
.footer-bar {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    flex-wrap: wrap;
}

.footer-bar {
    justify-content: space-between;
    position: sticky;
    bottom: 1rem;
}

.checkbox-line {
    display: inline-flex;
    gap: 0.65rem;
    align-items: center;
    margin-bottom: 0.9rem;
    font-weight: 600;
}

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 2.8rem;
    padding: 0.7rem 1.15rem;
    border: 0;
    border-radius: 999px;
    background: linear-gradient(135deg, #265df2 0%, #21a0ff 100%);
    color: #fff;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: transform 120ms ease, opacity 120ms ease;
}

.button:hover {
    transform: translateY(-1px);
}

.button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
}

.button-secondary {
    background: #ecf2ff;
    color: #2343a5;
}

.button-ghost {
    background: transparent;
    color: #4e5d78;
    border: 1px solid #ccd6e5;
}

.tab-shell .action-bar,
.tab-shell .search-row.project-filter-row {
    flex-wrap: nowrap;
}

.tab-shell .button {
    min-width: 6.5rem;
    min-height: 2.25rem;
    padding: 0.45rem 0.85rem;
    border-radius: 0.45rem;
    background: #2f6fed;
    font-size: 0.86rem;
    white-space: nowrap;
}

.tab-shell .button-secondary {
    background: #edf3ff;
    color: #2452b8;
}

.tab-shell .button-ghost {
    background: #fff;
    color: #53657a;
    border: 1px solid #d4deea;
}

.tab-shell .project-filter-row .button {
    min-width: 6rem;
}

.tab-shell .state-card,
.tab-shell .search-item {
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
}

.status-line {
    color: #385076;
}

.status-success {
    color: #1d6b4c;
}

.status-error {
    color: #a03647;
}

.token-grid {
    display: flex;
    gap: 0.65rem;
    flex-wrap: wrap;
    margin-bottom: 0.75rem;
}

.state-list {
    display: grid;
    gap: 0.75rem;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.state-list div {
    display: grid;
    gap: 0.2rem;
}

.state-list dt {
    color: #62708a;
}

.state-list dd {
    margin: 0;
    font-weight: 600;
}

.badge {
    display: inline-flex;
    padding: 0.35rem 0.65rem;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 700;
}

.badge-success {
    background: #d8f5e7;
    color: #156744;
}

.badge-danger {
    background: #ffe2e7;
    color: #a03647;
}

.badge-muted {
    background: #edf1f7;
    color: #465672;
}

.search-results {
    display: grid;
    gap: 0.75rem;
    margin-top: 1rem;
}

.search-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.search-meta {
    margin-top: 0.25rem;
    color: #64748b;
}

@media (max-width: 900px) {
    .hero,
    .tab-header,
    .panel-header,
    .footer-bar {
        flex-direction: column;
    }

    .grid-two,
    .grid-three,
    .state-list {
        grid-template-columns: 1fr;
    }

    .meta-card {
        width: 100%;
    }

    .tab-status-panel,
    .project-filter-row,
    .project-row {
        grid-template-columns: 1fr;
    }

    .tab-shell .action-bar {
        justify-content: flex-start;
        flex-wrap: wrap;
    }
}

/* Правила вкладки стоят в конце файла, чтобы общий flex для форм не ломал плотную сетку Bitrix24. */
.tab-shell .tab-page {
    width: min(920px, 100%);
}

.tab-shell .tab-header {
    min-height: 2.25rem;
}

.tab-shell .panel-header.compact-header {
    align-items: center;
    margin-bottom: 0.65rem;
}

.tab-shell .status-line {
    flex-shrink: 0;
    max-width: 20rem;
    overflow-wrap: anywhere;
    text-align: right;
    white-space: normal;
    font-size: 0.9rem;
}

.tab-shell .tab-status-panel {
    grid-template-columns: minmax(0, 1fr) max-content;
}

.tab-shell .action-bar {
    gap: 0.5rem;
}

.tab-shell .button {
    min-width: 6.25rem;
    height: 2.25rem;
    min-height: 2.25rem;
    padding: 0 0.85rem;
    border-radius: 0.5rem;
    font-size: 0.9rem;
    line-height: 1;
}

.tab-shell .search-row.project-filter-row {
    display: grid;
    grid-template-columns: minmax(20rem, 1fr) max-content;
    gap: 0.5rem;
    align-items: stretch;
    flex-wrap: nowrap;
    width: 100%;
}

.tab-shell .project-filter-row input[type="search"] {
    width: 100%;
    min-width: 0;
    height: 2.25rem;
    min-height: 2.25rem;
    padding: 0 0.65rem;
    border-radius: 0.5rem;
    font-size: 0.9rem;
}

.tab-shell .project-filter-row .button {
    width: 6.75rem;
    min-width: 6.75rem;
}

.tab-shell .project-row {
    grid-template-columns: 4.5rem minmax(0, 1fr) 7rem;
    min-height: 3rem;
    padding: 0.5rem 0.65rem;
}

.tab-shell .project-list {
    max-height: min(360px, calc(100vh - 17rem));
    padding-bottom: 0.35rem;
}

.tab-shell .link-project-button {
    width: 100%;
}

.tab-shell .state-summary {
    min-height: 2.25rem;
}

@media (max-width: 900px) {
    .tab-shell .tab-status-panel,
    .tab-shell .search-row.project-filter-row,
    .tab-shell .project-row {
        grid-template-columns: 1fr;
    }

    .tab-shell .status-line {
        max-width: 100%;
        text-align: left;
    }

    .tab-shell .project-filter-row .button,
    .tab-shell .link-project-button {
        width: 100%;
        min-width: 0;
    }
}

@media (max-width: 640px) {
    .tab-shell .button,
    .tab-shell .project-filter-row input[type="search"] {
        height: 2.75rem;
        min-height: 2.75rem;
    }
}
