/* Shared controls. Scoped selectors intentionally outrank #theme-dynamic.
   The existing theme slider remains the source of --accent and surface colors. */
:root {
    --ui-ease: cubic-bezier(0.22, 1, 0.36, 1);
    --ui-surface: var(--card-bg, oklch(99% 0.005 190));
    --ui-text: var(--text, oklch(31% 0.01 190));
    --ui-border: var(--border, oklch(90% 0.008 190));
    --ui-accent: var(--accent, oklch(76% 0.13 190));
    --btn-glow-ink: oklch(99% 0.005 190);
}

/* Repeated .btn-glow increases specificity against the legacy theme selector
   with five :not() clauses. Add the class only ONCE in HTML.

   Add BOTH classes to an <a> or a <button>: class="btn btn-glow".
   ::before fades the accent fill and halo without animating layout. */
html body .btn.btn-glow.btn-glow.btn-glow.btn-glow {
    position: relative;
    isolation: isolate;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    padding: 12px 24px;
    border: none !important;
    border-radius: 6px;
    background: var(--ui-surface) !important;
    color: var(--ui-text) !important;
    font: inherit;
    font-weight: 500;
    line-height: 1.25;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    box-shadow: 0 1px 3px oklch(20% 0.01 190 / 0.04);
    filter: none !important;
    transition: transform 160ms var(--ui-ease);
}
html body .btn.btn-glow.btn-glow.btn-glow.btn-glow::before {
    content: "";
    position: absolute;
    inset: -1px;
    z-index: -1;
    border: transparent !important;
    border-radius: inherit;
    background: none;
    box-shadow: 0 4px 12px rgba(var(--accent-rgb, 0, 204, 204), 0.15);
    opacity: 0;
    pointer-events: none;
    transition: opacity 200ms var(--ui-ease);
}
html body .btn.btn-glow.btn-glow.btn-glow.btn-glow:hover,
html body .btn.btn-glow.btn-glow.btn-glow.btn-glow:focus-visible {
    /* Keep the base surface stable; the pseudo-element supplies the fill. */
    background: var(--ui-surface) !important;
    color: var(--ui-text) !important;
    border-color: none !important;
    box-shadow: none;
    filter: none !important;
}
html body .btn.btn-glow.btn-glow.btn-glow.btn-glow:hover::before,
html body .btn.btn-glow.btn-glow.btn-glow.btn-glow:focus-visible::before { opacity: 1; }
html body .btn.btn-glow.btn-glow.btn-glow.btn-glow:active { transform: translateY(1px); }
html body .btn.btn-glow.btn-glow.btn-glow.btn-glow:focus-visible,
html body button.submit-btn.submit-no-fill:focus-visible,
html body .progress-disclosure > .progress-summary:focus-visible,
html body .progress-table-scroll:focus-visible {
    outline: 2px solid var(--ui-accent);
    outline-offset: 4px;
}
html body .btn.btn-glow.btn-glow.btn-glow.btn-glow:disabled,
html body .btn.btn-glow.btn-glow.btn-glow.btn-glow[aria-disabled="true"] {
    background: var(--ui-surface) !important;
    color: var(--ui-text) !important;
    border-color: var(--ui-border) !important;
    opacity: 0.5;
    box-shadow: none;
    cursor: not-allowed;
    transform: none;
}
html body .btn.btn-glow.btn-glow.btn-glow.btn-glow:disabled::before,
html body .btn.btn-glow.btn-glow.btn-glow.btn-glow[aria-disabled="true"]::before { opacity: 0; }

/* Opt-in only: login/logout backgrounds never change on hover, at ANY slider value.
   Higher specificity also overrides body.theme-dark-mode .submit-btn:hover. */
html body button.submit-btn.submit-no-fill,
html body button.submit-btn.submit-no-fill:hover,
html body button.submit-btn.submit-no-fill:focus-visible {
    min-height: 44px;
    background: var(--ui-surface) !important;
    color: var(--ui-text) !important;
    border-color: var(--ui-border) !important;
    box-shadow: none !important;
    filter: none !important;
    transition: transform 160ms var(--ui-ease);
}
html body button.submit-btn.submit-no-fill:hover,
html body button.submit-btn.submit-no-fill:focus-visible {
    color: var(--ui-accent) !important;
    border-color: var(--ui-accent) !important;
}

/* /user: primary navigation immediately follows user-info. */
.user-shortcuts {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
    margin-top: 20px;
}
.user-shortcuts .btn-glow { flex: 1 1 180px; }
.auth-section > .user-actions { margin-top: 24px; }

/* Native <details> provides collapsed first render, keyboard operation and
   expanded/collapsed accessibility state, even with JavaScript disabled. */
html body details.progress-disclosure {
    padding: 0;
    border: 1px solid var(--ui-border);
    border-radius: 10px;
    background: var(--ui-surface);
    color: var(--ui-text);
}
.progress-disclosure > .progress-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 76px;
    padding: 16px;
    border-radius: 10px;
    cursor: pointer;
    list-style: none;
}
.progress-summary::-webkit-details-marker { display: none; }
.progress-summary::marker { content: ""; }
.progress-summary-copy { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.progress-summary-title { font-size: 1rem; font-weight: 700; line-height: 1.4; overflow-wrap: anywhere; }
.progress-summary-copy small { font-size: .8125rem; line-height: 1.5; color: var(--text-sub, oklch(50% 0.01 190)); }
.progress-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    gap: 8px;
    min-height: 44px;
    padding: 8px 12px;
    border: 1px solid var(--ui-border);
    border-radius: 6px;
    font-size: .8125rem;
    font-weight: 600;
    color: var(--ui-text);
}
.progress-summary:hover .progress-toggle,
.progress-summary:focus-visible .progress-toggle { border-color: var(--ui-accent); color: var(--ui-accent); }
.progress-chevron { flex-shrink: 0; transition: transform 200ms var(--ui-ease); }
.progress-disclosure .when-open { display: none; }
.progress-disclosure[open] > .progress-summary .when-open { display: inline; }
.progress-disclosure[open] > .progress-summary .when-closed { display: none; }
.progress-disclosure[open] > .progress-summary .progress-chevron { transform: rotate(180deg); }
.progress-disclosure[open] > .progress-summary { border-radius: 10px 10px 0 0; }
.progress-content { padding: 0 16px 16px; min-width: 0; }
.progress-content .progress-tiles {
    display: flex;
    flex-wrap: wrap;
    gap: 16px 32px;
    padding: 16px 0;
    border-top: 1px solid var(--ui-border);
    margin-bottom: 8px;
}
.progress-content .progress-tile { border: 0; border-radius: 0; padding: 0; background: transparent; }
.progress-content .progress-tile .v { font-size: 1.25rem; }
.progress-content .progress-tile .k { margin-top: 4px; font-size: .75rem; }
.progress-table-scroll { max-width: 100%; overflow-x: auto; overscroll-behavior-x: contain; }
.progress-table-scroll:not(:has(table)) { display: none; }
.progress-table-scroll .p-table { min-width: 480px; }
.progress-disclosure[open] .progress-content { animation: progress-reveal 200ms var(--ui-ease); }
@keyframes progress-reveal { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
@media (max-width: 420px) {
    .progress-disclosure > .progress-summary { align-items: flex-start; flex-direction: column; gap: 12px; }
    .progress-toggle { align-self: flex-end; }
    .user-shortcuts { flex-direction: column; }
    .user-shortcuts .btn-glow { flex: auto; width: 100%; }
}
@media (prefers-reduced-motion: reduce) {
    html body .btn.btn-glow.btn-glow.btn-glow.btn-glow,
    html body .btn.btn-glow.btn-glow.btn-glow.btn-glow::before,
    html body button.submit-btn.submit-no-fill,
    .progress-chevron { transition: none; }
    .progress-disclosure[open] .progress-content { animation: none; }
}

/* Constrain the outer flex item so an expanded table cannot widen /user. */
.user-page-container { width: 100%; min-width: 0; }
.user-page-container .main-container { min-width: 0; }
.user-page-container .logo-section { max-width: 100%; }
.user-page-container .logo-section h1 { overflow-wrap: anywhere; }

/* ==========================================================================
   Выезжающая кнопка «Импорт» (/admin/tests, /admin/knowledge).

   Обёртка .split-action держит основную кнопку («+ Новый тест» / «+ Новая
   статья») и скрытую .slide-btn. На hover обёртки, а также при попадании
   фокуса внутрь (:focus-within — работает с клавиатуры), вторая кнопка
   выезжает вправо.

   Класс .slide-btn повторён пять раз: он обязан перебивать
   `html body .btn.btn-glow.btn-glow.btn-glow.btn-glow` из блока выше,
   иначе padding/визуал btn-glow не даст кнопке свернуться.
   ========================================================================== */
.split-action {
    position: relative;
    display: inline-flex;
    align-items: center;
    vertical-align: middle;
}

html body .split-action > .slide-btn.slide-btn.slide-btn.slide-btn.slide-btn {
    max-width: 0 !important;
    margin-left: 0 !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
    border-width: 0 !important;
    opacity: 0 !important;
    overflow: hidden !important;
    white-space: nowrap !important;
    transform: translateX(-10px);
    pointer-events: none;
    transition: max-width 280ms var(--ui-ease), opacity 180ms var(--ui-ease),
                transform 280ms var(--ui-ease), margin-left 280ms var(--ui-ease),
                padding 280ms var(--ui-ease);
}

html body .split-action:hover > .slide-btn.slide-btn.slide-btn.slide-btn.slide-btn,
html body .split-action:focus-within > .slide-btn.slide-btn.slide-btn.slide-btn.slide-btn,
html body .split-action.is-open > .slide-btn.slide-btn.slide-btn.slide-btn.slide-btn {
    max-width: 180px !important;
    margin-left: 8px !important;
    padding-left: 20px !important;
    padding-right: 20px !important;
    opacity: 1 !important;
    transform: none;
    pointer-events: auto;
}

/* Курсор не должен «проваливаться» в щель между кнопками */
.split-action::after {
    content: "";
    position: absolute;
    inset: -6px -12px -6px -6px;
    z-index: -1;
    pointer-events: auto;
}

@media (prefers-reduced-motion: reduce) {
    html body .split-action > .slide-btn.slide-btn.slide-btn.slide-btn.slide-btn { transition: none; }
}

/* На узких экранах прятать импорт за hover неудобно — показываем сразу */
@media (max-width: 768px), (hover: none) {
    html body .split-action > .slide-btn.slide-btn.slide-btn.slide-btn.slide-btn {
        max-width: 180px !important;
        margin-left: 8px !important;
        padding-left: 20px !important;
        padding-right: 20px !important;
        opacity: 1 !important;
        transform: none;
        pointer-events: auto;
    }
}
