/**
 * SYSTEM shell scaffold (B-001, phase-2 start)
 * Non-breaking layer over existing sidebar/main-content layout.
 */

:is(body.sys-crm-page, body.portal-crm-shell-ui-ready).sys-shell-ready .main-content {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    min-width: 0;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

:is(body.sys-crm-page, body.portal-crm-shell-ui-ready) .sys-shell-topbar {
    position: sticky;
    top: 0;
    z-index: 1200;
    background: #fff;
    border-bottom: 1px solid #e5e7eb;
    padding: 7px 14px 8px 10px;
    min-height: 56px;
    box-sizing: border-box;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px 14px;
}

:is(body.sys-crm-page, body.portal-crm-shell-ui-ready) .sys-shell-topbar__primary {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    flex: 1;
    min-width: min(100%, 220px);
}

:is(body.sys-crm-page, body.portal-crm-shell-ui-ready) .sys-shell-topbar__brand {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 3px;
    align-self: flex-start;
    margin-top: -3px;
    flex-shrink: 0;
}

:is(body.sys-crm-page, body.portal-crm-shell-ui-ready) .sys-shell-topbar__title {
    margin: 0;
    font-size: 12px;
    font-weight: 700;
    color: #111827;
    line-height: 1.05;
    letter-spacing: 0.02em;
}

:is(body.sys-crm-page, body.portal-crm-shell-ui-ready) .sys-shell-topbar__meta {
    margin: 0;
    font-size: 12px;
    font-weight: 700;
    color: #111827;
    text-align: right;
    line-height: 1.25;
    flex: 1;
    min-width: 0;
    align-self: center;
}

:is(body.sys-crm-page, body.portal-crm-shell-ui-ready) .sys-shell-messages-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    padding: 0;
    margin: 0;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    background: #f8fafc;
    color: #1e293b;
    cursor: pointer;
    flex-shrink: 0;
}

:is(body.sys-crm-page, body.portal-crm-shell-ui-ready) .sys-shell-messages-btn:hover {
    background: #eef2f7;
    border-color: #94a3b8;
    color: #0f172a;
}

:is(body.sys-crm-page, body.portal-crm-shell-ui-ready) .sys-shell-messages-btn .portal-inbox-link__wrap {
    position: relative;
    display: inline-flex;
    width: 16px;
    height: 16px;
}

:is(body.sys-crm-page, body.portal-crm-shell-ui-ready) .sys-shell-messages-btn .portal-inbox-link__icon--full {
    display: none;
}

:is(body.sys-crm-page, body.portal-crm-shell-ui-ready) .sys-shell-messages-btn.portal-inbox-link--unread .portal-inbox-link__icon--empty {
    display: none;
}

:is(body.sys-crm-page, body.portal-crm-shell-ui-ready) .sys-shell-messages-btn.portal-inbox-link--unread .portal-inbox-link__icon--full {
    display: flex;
}

:is(body.sys-crm-page, body.portal-crm-shell-ui-ready) .sys-shell-messages-btn .portal-inbox-link__dot {
    display: none;
    position: absolute;
    top: -2px;
    right: -4px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #e53935;
    box-shadow: 0 0 0 2px #fff;
}

:is(body.sys-crm-page, body.portal-crm-shell-ui-ready) .sys-shell-messages-btn.portal-inbox-link--unread .portal-inbox-link__dot {
    display: block;
}

:is(body.sys-crm-page, body.portal-crm-shell-ui-ready) .sys-shell-topbar__actions {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    align-self: center;
}

:is(body.sys-crm-page, body.portal-crm-shell-ui-ready) .sys-shell-pref-label {
    font-size: 11px;
    color: #64748b;
    white-space: nowrap;
}

:is(body.sys-crm-page, body.portal-crm-shell-ui-ready) .sys-shell-density-select {
    font: inherit;
    font-size: 12px;
    padding: 5px 8px;
    border-radius: 6px;
    border: 1px solid #cbd5e1;
    background: #fff;
    color: #334155;
    min-width: 8.5rem;
}

/* Полоса закладок: компактные вкладки, перенос в 2+ строки без горизонтальной прокрутки */
:is(body.sys-crm-page, body.portal-crm-shell-ui-ready) .sys-shell-tabbar {
    position: sticky;
    top: 56px;
    z-index: 1190;
    background: linear-gradient(to bottom, #e8edf3 0%, #dfe6ee 100%);
    border-bottom: 1px solid #b8c3d0;
    padding: 6px 8px 0 8px;
    display: flex;
    flex-wrap: wrap;
    gap: 2px 3px;
    align-items: flex-end;
    align-content: flex-end;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    flex: 0 0 auto;
    overflow: hidden;
    box-shadow: inset 0 -1px 0 rgba(255, 255, 255, 0.35);
}

:is(body.sys-crm-page, body.portal-crm-shell-ui-ready) .sys-shell-tab {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex: 0 1 auto;
    max-width: 11.5rem;
    border: 1px solid #b8c3d0;
    border-bottom: none;
    border-radius: 8px 8px 0 0;
    background: linear-gradient(to bottom, #f4f6f9 0%, #e8ecf1 100%);
    color: #334155;
    padding: 4px 6px 6px;
    font-size: 11px;
    font-weight: 500;
    white-space: nowrap;
    text-decoration: none;
    box-shadow: 0 -1px 0 rgba(0, 0, 0, 0.04);
    margin-bottom: -1px;
    position: relative;
    min-height: 28px;
    box-sizing: border-box;
}

:is(body.sys-crm-page, body.portal-crm-shell-ui-ready) .sys-shell-tab__label {
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

:is(body.sys-crm-page, body.portal-crm-shell-ui-ready) .sys-shell-tab:hover {
    background: linear-gradient(to bottom, #fafbfd 0%, #eef1f6 100%);
    color: #1e293b;
}

:is(body.sys-crm-page, body.portal-crm-shell-ui-ready) .sys-shell-tab.is-active {
    border-color: #94a3b8;
    border-bottom: 1px solid #fff;
    color: #1e40af;
    background: #fff;
    font-weight: 600;
    z-index: 2;
    box-shadow: 0 -2px 8px rgba(37, 99, 235, 0.08);
}

:is(body.sys-crm-page, body.portal-crm-shell-ui-ready) .sys-shell-tab--pinned {
    border-left: 3px solid #2563eb;
    padding-left: 6px;
}

:is(body.sys-crm-page, body.portal-crm-shell-ui-ready) .sys-shell-tab-context {
    position: fixed;
    z-index: 1300;
    min-width: 220px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.12);
    padding: 4px 0;
}

:is(body.sys-crm-page, body.portal-crm-shell-ui-ready) .sys-shell-tab-context__btn {
    display: block;
    width: 100%;
    text-align: left;
    border: none;
    background: transparent;
    padding: 8px 14px;
    font-size: 13px;
    color: #334155;
    cursor: pointer;
    font-family: inherit;
}

:is(body.sys-crm-page, body.portal-crm-shell-ui-ready) .sys-shell-tab-context__btn:hover {
    background: #f1f5f9;
}

:is(body.sys-crm-page, body.portal-crm-shell-ui-ready) .sys-shell-tab__star {
    border: none;
    background: transparent;
    color: #ca8a04;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    padding: 0;
    flex-shrink: 0;
    min-width: 22px;
    min-height: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    margin: -2px 0;
}

:is(body.sys-crm-page, body.portal-crm-shell-ui-ready) .sys-shell-tab__star:hover {
    color: #a16207;
    background: rgba(202, 138, 4, 0.12);
}

:is(body.sys-crm-page, body.portal-crm-shell-ui-ready) .sys-shell-tab.is-active .sys-shell-tab__star {
    color: #b45309;
}

:is(body.sys-crm-page, body.portal-crm-shell-ui-ready) .sys-shell-tab__close {
    border: none;
    background: transparent;
    color: #64748b;
    cursor: pointer;
    font-size: 15px;
    line-height: 1;
    padding: 0;
    min-width: 20px;
    min-height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    margin: -2px -2px -2px 0;
    flex-shrink: 0;
}

:is(body.sys-crm-page, body.portal-crm-shell-ui-ready) .sys-shell-tab__close:hover {
    color: #b91c1c;
}

:is(body.sys-crm-page, body.portal-crm-shell-ui-ready) .sys-shell-content-mount {
    flex: 1 1 auto;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    padding-top: 0;
    background: #fff;
    border-radius: 0;
    box-sizing: border-box;
}

:is(body.sys-crm-page, body.portal-crm-shell-ui-ready) .sys-shell-content-mount > .card.sys-list-page-card {
    flex: 1 1 auto;
    align-self: stretch;
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

:is(body.sys-crm-page, body.portal-crm-shell-ui-ready).sys-shell-ready {
    background: #fff;
}

/* Ещё компактнее при выбранной плотности «Компактная» */
:is(body.sys-crm-page, body.portal-crm-shell-ui-ready).sys-density-compact .sys-shell-tabbar {
    padding: 4px 6px 0 6px;
    gap: 2px;
}

:is(body.sys-crm-page, body.portal-crm-shell-ui-ready).sys-density-compact .sys-shell-tab {
    padding: 3px 5px 5px;
    font-size: 10px;
    min-height: 24px;
    max-width: 9.5rem;
    border-radius: 6px 6px 0 0;
}

:is(body.sys-crm-page, body.portal-crm-shell-ui-ready).sys-density-compact .sys-shell-tab__star {
    font-size: 12px;
    min-width: 18px;
    min-height: 18px;
}

:is(body.sys-crm-page, body.portal-crm-shell-ui-ready).sys-density-compact .sys-shell-tab__close {
    font-size: 13px;
    min-width: 18px;
    min-height: 18px;
}
