.rulelab-shell {
    display: grid;
    gap: 14px;
    width: 100%;
}

.rulelab-panel {
    border: 1px solid var(--admin-line);
    border-radius: 4px;
    background: var(--admin-card);
    box-shadow: var(--admin-shadow);
    padding: 14px;
}

.rulelab-filter {
    background: linear-gradient(180deg, #f8fafc 0%, #ffffff 100%);
}

.rulelab-global {
    border-color: #cbd5e1;
    background: linear-gradient(135deg, #f8fafc 0%, #eef7f4 100%);
}

.rulelab-work-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    border: 1px solid var(--admin-line);
    border-radius: 4px;
    padding: 8px;
    background: #f1f5f9;
}

.rulelab-work-tabs button {
    width: auto;
    min-width: 112px;
    min-height: 34px;
    flex: 0 0 auto;
    border: 1px solid transparent;
    border-radius: 4px;
    padding: 0 14px;
    color: #475569;
    background: transparent;
    font-weight: 900;
    cursor: pointer;
}

.rulelab-work-tabs button.active {
    border-color: #0f766e;
    color: #0f766e;
    background: #ffffff;
    box-shadow: 0 8px 18px rgba(15, 118, 110, 0.12);
}

.rulelab-tab-panel {
    display: none;
}

.rulelab-tab-panel.active {
    display: block;
}

.panel-head.compact {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.panel-head.compact h2 {
    margin: 0;
}

.panel-head.compact p {
    margin: 4px 0 0;
    color: var(--admin-muted);
}

.panel-head.compact button,
.rulelab-row-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: auto;
    min-width: 82px;
    max-width: max-content;
    flex: 0 0 auto;
    justify-self: end;
    align-self: flex-start;
    min-height: 32px;
    border: 1px solid #0f766e;
    border-radius: 4px;
    padding: 0 12px;
    color: #fff;
    background: #0f766e;
    font-weight: 800;
    cursor: pointer;
}

.quant-admin-content #btnSearchRules,
.quant-admin-content #btnEvaluateRule,
.quant-admin-content #btnSearchMarketRules {
    width: auto;
    min-width: 96px;
    max-width: max-content;
    height: 34px;
    padding: 0 14px;
    white-space: nowrap;
}

.rulelab-form-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(150px, 1fr));
    gap: 10px;
}

.rulelab-form-grid.manual {
    grid-template-columns: repeat(6, minmax(120px, 1fr));
}

.rulelab-form-grid label {
    display: grid;
    gap: 5px;
    color: #475569;
    font-size: 12px;
    font-weight: 800;
}

.rulelab-form-grid input,
.rulelab-form-grid select {
    min-height: 34px;
    border: 1px solid #dbe3ef;
    border-radius: 4px;
    padding: 0 9px;
    color: #0f172a;
    background: #fff;
}

.rulelab-checks {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
    margin-top: 12px;
    color: #334155;
    font-size: 13px;
}

.rulelab-checks span {
    color: #0f766e;
    font-weight: 900;
}

.rulelab-checks label {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.rulelab-market-note {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    border: 1px solid #ccfbf1;
    border-radius: 4px;
    padding: 10px 12px;
    color: #334155;
    background: #f0fdfa;
    font-size: 13px;
}

.rulelab-market-note strong {
    color: #0f766e;
}

.rulelab-table-wrap {
    max-height: 520px;
}

.rulelab-table-wrap table {
    min-width: 1120px;
}

.rulelab-table-wrap th:first-child,
.rulelab-table-wrap td:first-child {
    min-width: 360px;
}

.rulelab-rule-text {
    display: block;
    color: #0f172a;
    font-weight: 900;
    line-height: 1.5;
}

.rulelab-rule-sub {
    display: block;
    margin-top: 3px;
    color: #64748b;
    font-size: 12px;
}

.rulelab-good {
    color: #dc2626;
    font-weight: 900;
}

.rulelab-bad {
    color: #16a34a;
    font-weight: 900;
}

.rulelab-code-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 12px;
}

.rulelab-code-grid pre {
    overflow: auto;
    min-height: 74px;
    margin: 0;
    border: 1px solid #dbe3ef;
    border-radius: 4px;
    padding: 10px;
    color: #0f172a;
    background: #f8fafc;
    font-size: 12px;
    line-height: 1.6;
}

.rulelab-probs {
    color: #475569;
    font-size: 12px;
    line-height: 1.5;
}

.rulelab-modal-open {
    overflow: hidden;
}

.rulelab-modal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: none;
    padding: 24px;
}

.rulelab-modal.active {
    display: block;
}

.rulelab-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.58);
    backdrop-filter: blur(3px);
}

.rulelab-modal-card {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: min(1280px, calc(100vw - 48px));
    max-height: calc(100vh - 48px);
    margin: 0 auto;
    border: 1px solid #dbe3ef;
    border-radius: 4px;
    padding: 16px;
    background: #ffffff;
    box-shadow: 0 28px 80px rgba(15, 23, 42, 0.28);
}

.rulelab-modal-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid #e2e8f0;
    padding-bottom: 12px;
}

.rulelab-modal-head h2 {
    margin: 0;
    color: #0f172a;
    font-size: 20px;
}

.rulelab-modal-head p {
    margin: 5px 0 0;
    color: #475569;
    font-size: 13px;
    line-height: 1.6;
}

.rulelab-modal-close {
    width: 34px;
    height: 34px;
    flex: 0 0 auto;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    color: #334155;
    background: #f8fafc;
    font-size: 22px;
    font-weight: 800;
    line-height: 1;
    cursor: pointer;
}

.rulelab-modal-actions {
    display: flex;
    justify-content: flex-end;
}

.rulelab-modal-actions button {
    width: auto;
    min-width: 90px;
    min-height: 32px;
    border: 1px solid #0f766e;
    border-radius: 4px;
    padding: 0 12px;
    color: #ffffff;
    background: #0f766e;
    font-weight: 800;
    cursor: pointer;
}

.rulelab-modal-table {
    max-height: min(52vh, 560px);
}

.poster-league-tag {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 52px;
    height: 22px;
    padding: 0 7px;
    border-radius: 4px;
    color: #fff;
    font-size: 12px;
    font-weight: 800;
}

.rulelab-help-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    width: 100%;
}

.rulelab-help-card {
    border: 1px solid var(--admin-line);
    border-radius: 4px;
    padding: 16px;
    color: #334155;
    background: var(--admin-card);
    box-shadow: var(--admin-shadow);
}

.rulelab-help-card.emphasis {
    grid-column: 1 / -1;
    border-color: #99f6e4;
    background: linear-gradient(135deg, #f0fdfa 0%, #ffffff 100%);
}

.rulelab-help-card h2 {
    margin: 0 0 10px;
    color: #0f172a;
    font-size: 18px;
}

.rulelab-help-card p {
    margin: 0 0 9px;
    line-height: 1.7;
}

.rulelab-help-card p:last-child {
    margin-bottom: 0;
}

.rulelab-help-card dl {
    display: grid;
    gap: 8px;
    margin: 0;
}

.rulelab-help-card dt {
    color: #0f766e;
    font-weight: 900;
}

.rulelab-help-card dd {
    margin: -5px 0 5px;
    line-height: 1.6;
}

.rulelab-help-card ol {
    margin: 0;
    padding-left: 20px;
    line-height: 1.8;
}

@media (max-width: 1180px) {
    .rulelab-form-grid,
    .rulelab-form-grid.manual,
    .rulelab-code-grid,
    .rulelab-help-grid {
        grid-template-columns: 1fr;
    }

    .rulelab-modal {
        padding: 10px;
    }

    .rulelab-modal-card {
        width: calc(100vw - 20px);
        max-height: calc(100vh - 20px);
    }
}
