:root{
    --ui-canvas:1500px;
    --ui-gutter:clamp(16px,2vw,28px);
    --ui-section-gap:clamp(18px,2vw,28px);
    --ui-card-gap:clamp(14px,1.5vw,20px);
    --ui-card-radius:clamp(16px,1.5vw,22px);
    --ui-control-height:52px;
    --ui-readable:78ch;
}

html{overflow-x:hidden}
body{min-width:320px;overflow-x:hidden}
*,*::before,*::after{box-sizing:border-box}
main,section,article,aside,header,footer,nav,form,fieldset,div{min-width:0}
img,svg,video,canvas{max-width:100%}
img,video{height:auto}
h1,h2,h3,h4,p,li,dt,dd,td,th,label,a,button{max-width:100%;overflow-wrap:break-word;word-break:normal}
h1,h2,h3,h4{hyphens:auto;text-wrap:balance}
p,li{max-width:var(--ui-readable)}
pre,code,kbd,samp{max-width:100%;overflow-wrap:anywhere;white-space:pre-wrap}

/* Единая ширина рабочих холстов. Локальные шаблоны отвечают только за контент. */
body.theme-events>.page,
body.theme-knowledge>.page,
body.theme-support>.page,
body.theme-public>.page{
    width:min(var(--ui-canvas),calc(100% - (var(--ui-gutter) * 2)))!important;
    max-width:var(--ui-canvas)!important;
}
body.theme-cabinet .app,
.theme-admin .wrap{
    width:min(var(--ui-canvas),calc(100% - (var(--ui-gutter) * 2)));
    max-width:var(--ui-canvas);
}

/* Ритм и одинаковая высота смысловых карточек. */
:where(.theme-home,.theme-events,.theme-knowledge,.theme-support,.theme-public,.theme-cabinet,.theme-admin)
:where(.grid,.metrics,.cards,.docs,.faq,.services,.quick,.bookmarks,.summary-grid,.learning-grid,.material-grid,.attendance-grid){
    align-items:stretch;
}
:where(.theme-home,.theme-events,.theme-knowledge,.theme-support,.theme-public,.theme-cabinet,.theme-admin)
:where(.card,.panel,.metric,.service-card,.service,.doc,.qa,.entry,.event,.bookmark,.material,.attendance-card){
    min-width:0;
    max-width:100%;
}
:where(.theme-home,.theme-events,.theme-knowledge,.theme-support,.theme-public,.theme-cabinet,.theme-admin)
:where(.card,.panel,.metric,.service-card,.doc,.entry,.bookmark,.material,.attendance-card){
    height:100%;
}
:where(.theme-knowledge,.theme-public) :where(.doc,.card,.qa) :where(h2,h3,strong,p,span){
    min-width:0;
    max-width:100%;
    overflow-wrap:break-word;
}
.theme-knowledge .doc h2{
    font-size:clamp(20px,2vw,24px);
    line-height:1.22;
    text-wrap:pretty;
}

/* Формы образуют ровные строки независимо от длины подписи. */
:where(.theme-events,.theme-knowledge,.theme-support,.theme-public,.theme-cabinet,.theme-admin,.theme-security)
:where(input:not([type="checkbox"]):not([type="radio"]),select,button,.button,.btn,.nav-link){
    min-height:var(--ui-control-height);
}
:where(.theme-events,.theme-knowledge,.theme-support,.theme-public,.theme-cabinet,.theme-admin,.theme-security)
:where(input:not([type="checkbox"]):not([type="radio"]),select,textarea){
    width:100%;
    max-width:100%;
    font:inherit;
}
:where(.theme-events,.theme-knowledge,.theme-support,.theme-public,.theme-cabinet,.theme-admin,.theme-security)
textarea{min-height:132px;resize:vertical}
:where(.theme-events,.theme-knowledge,.theme-support,.theme-public,.theme-cabinet,.theme-admin,.theme-security)
fieldset{width:100%;margin:0}

/* Таблицы не ломают холст и остаются читаемыми на узких экранах. */
:where(.theme-admin,.theme-cabinet,.theme-events,.theme-knowledge,.theme-support,.theme-public)
:where(.table-wrap,.table-scroll,.panel:has(> table)){
    max-width:100%;
    overflow-x:auto;
    overscroll-behavior-inline:contain;
}
:where(.theme-admin,.theme-cabinet,.theme-events,.theme-knowledge,.theme-support,.theme-public) table{
    width:100%;
    table-layout:auto;
}
:where(.theme-admin,.theme-cabinet,.theme-events,.theme-knowledge,.theme-support,.theme-public) :where(th,td){
    min-width:0;
    vertical-align:top;
    line-height:1.45;
    overflow-wrap:break-word;
}
:where(.theme-admin,.theme-cabinet,.theme-events,.theme-knowledge,.theme-support,.theme-public) th{
    text-wrap:balance;
}

/* Минимальная читаемость служебных подписей. */
:where(.theme-home,.theme-events,.theme-knowledge,.theme-support,.theme-public,.theme-cabinet,.theme-admin,.theme-security)
:where(.meta,.muted,.hint,.lead,small,.eyebrow,.badge,.status,.state){
    font-size:max(14px,.875rem)!important;
    line-height:1.45;
}
.theme-home :where(.brand,.benefit,.footer){font-size:max(14px,.875rem)!important}
.theme-admin :where(.admin-activity-list time,.compact-actions .button,.context,.flow-step span,.ticket-event .meta,.choice span){
    font-size:max(14px,.875rem)!important;
    line-height:1.45;
}

/* Административная оболочка и ЛК используют одну вертикальную ось. */
.theme-admin .wrap>*+*{margin-top:var(--ui-section-gap)}
.theme-admin :where(.metrics,.admin-grid,.dashboard-grid){gap:var(--ui-card-gap)}
.theme-admin :where(.panel,.metric,.entry){border-radius:var(--ui-card-radius)}
.theme-admin :where(.tools,.page-actions,.form-actions,.head-actions){
    align-items:center;
    gap:12px;
}
.theme-cabinet .main>*+*{margin-top:var(--ui-section-gap)}
.theme-cabinet :where(.metrics,.dashboard,.quick,.stack){gap:var(--ui-card-gap)}
.theme-cabinet :where(.panel,.metric,.event,.quick a,.security){border-radius:var(--ui-card-radius)}

@media(max-width:900px){
    :root{--ui-gutter:16px}
    :where(.theme-events,.theme-knowledge,.theme-support,.theme-public,.theme-cabinet,.theme-admin)
    :where(.grid,.metrics,.cards,.docs,.faq,.services,.summary-grid,.learning-grid,.material-grid){
        grid-template-columns:repeat(2,minmax(0,1fr));
    }
}

@media(max-width:760px){
    :root{--ui-gutter:0px;--ui-section-gap:18px;--ui-card-gap:14px}
    body.theme-events>.page,
    body.theme-knowledge>.page,
    body.theme-support>.page,
    body.theme-public>.page,
    body.theme-cabinet .app,
    .theme-admin .wrap{
        width:100%!important;
        max-width:100%!important;
    }
    :where(.theme-events,.theme-knowledge,.theme-support,.theme-public,.theme-cabinet,.theme-admin)
    :where(.grid,.metrics,.cards,.docs,.faq,.services,.quick,.bookmarks,.summary-grid,.learning-grid,.material-grid,.attendance-grid){
        grid-template-columns:minmax(0,1fr);
    }
    :where(.theme-events,.theme-knowledge,.theme-support,.theme-public,.theme-cabinet,.theme-admin)
    :where(.actions,.head-actions,.form-actions,.page-actions){
        display:grid;
        grid-template-columns:minmax(0,1fr);
        width:100%;
    }
    :where(.theme-events,.theme-knowledge,.theme-support,.theme-public,.theme-cabinet,.theme-admin)
    :where(.actions,.head-actions,.form-actions,.page-actions)>:where(a,button,.button,.btn){
        width:100%;
        justify-content:center;
    }
    :where(.theme-home,.theme-events,.theme-knowledge,.theme-support,.theme-public,.theme-cabinet,.theme-admin,.theme-security)
    :where(.meta,.muted,.hint,.lead,small,.eyebrow,.badge,.status,.state){
        font-size:max(15px,.9375rem)!important;
    }
}

@media(prefers-reduced-motion:reduce){
    *,*::before,*::after{
        scroll-behavior:auto!important;
        animation-duration:.01ms!important;
        animation-iteration-count:1!important;
        transition-duration:.01ms!important;
    }
}
