/*
 * Wspólna warstwa reflow dla telefonów. Ładowana jako ostatni arkusz, aby
 * ekrany projektowane pierwotnie dla desktopu zachowywały jeden czytelny tok.
 */

body.has-open-drawer :where(.krc-a11y-trigger, .pwa-widget),
body.has-user-drawer :where(.krc-a11y-trigger, .pwa-widget),
body.has-document-drawer :where(.krc-a11y-trigger, .pwa-widget) {
    visibility: hidden;
    pointer-events: none;
}

@media (max-width: 760px) {
    html,
    body {
        width: 100%;
        min-width: 0;
        max-width: 100%;
    }

    html {
        overflow-x: auto;
    }

    body.mobile-shell-ready {
        overflow-x: visible;
    }

    :where(.skip-link, .profile-skip-link, .legal-skip, .portal-skip) {
        z-index: 1000;
        top: calc(8px + env(safe-area-inset-top));
    }

    body {
        font-size: 16px;
        overflow-wrap: anywhere;
    }

    :where(input, select, textarea):not([type="checkbox"]):not([type="radio"]):not([type="hidden"]) {
        min-width: 0;
        min-height: 48px;
        font-size: 16px !important;
    }

    .workspace :where(button, [role="button"], .primary-action, .quiet-action, .danger-action),
    .login-shell :where(button, [role="button"]),
    .profile-page :where(.profile-header, .profile-main) :where(button, [role="button"]),
    .participant-portal-page :where(.portal-header, main) :where(button, [role="button"]) {
        min-height: 44px;
        font-size: 14px !important;
        line-height: 1.3;
    }

    :where(.workspace, .login-shell, .profile-page, .participant-portal-page, .legal-page)
    :where(small, .eyebrow, .field-error, [class*="-error"], [class*="-note"], [class*="-meta"], dt, dd) {
        font-size: 12px !important;
        line-height: 1.5;
    }

    .workspace :where(label > span, legend, table td, .status-pill, .role-tag, .account-status, .document-status) {
        font-size: 12px !important;
        line-height: 1.45;
    }

    body.mobile-shell-ready .content-canvas {
        padding-top: 30px;
        padding-right: max(16px, env(safe-area-inset-right));
        padding-bottom: calc(var(--mobile-bottom-nav-height) + var(--mobile-safe-bottom) + 46px);
        padding-left: max(16px, env(safe-area-inset-left));
        overflow-x: visible;
    }

    body.mobile-shell-ready .topbar {
        align-items: stretch;
        min-height: 72px;
    }

    body.mobile-shell-ready .topbar .club-indicator {
        flex: 1 1 auto;
        max-width: none;
        overflow: visible;
    }

    body.mobile-shell-ready .topbar .club-indicator > span:nth-child(2),
    body.mobile-shell-ready .topbar .club-indicator strong,
    body.mobile-shell-ready .topbar-actions .primary-action {
        overflow: visible;
        text-overflow: initial;
        white-space: normal;
    }

    .content-canvas > .page-intro,
    .content-canvas > [class$="-intro"] {
        gap: 18px;
        margin-bottom: 28px;
    }

    .content-canvas h1 {
        font-size: clamp(34px, 11vw, 44px);
        line-height: 1.02;
    }

    .content-canvas h2 {
        line-height: 1.2;
    }

    .intro-note {
        max-width: 58ch;
        font-size: 14px;
        line-height: 1.65;
    }

    .participant-portal-page :where(
        .schedule-date span,
        .schedule-topline p,
        .schedule-status,
        .schedule-facts,
        .schedule-topic-actions > p,
        .schedule-topic > span,
        .schedule-item-footer small,
        .schedule-message,
        .competency-copy > p,
        .source-topics span,
        .score-fieldset legend,
        .score-scale,
        .comparison span,
        .posttest-message,
        .password-message
    ) {
        font-size: 12px !important;
        line-height: 1.5;
    }

    .participant-portal-page :where(.schedule-transfer, .schedule-cancel) {
        min-height: 48px;
        font-size: 14px;
    }

    .participant-portal-page .schedule-facts span[data-fact="location"]::before {
        font-size: 9px;
    }

    .participant-portal-page .comparison strong {
        font-size: 14px;
    }

    .metrics-strip,
    .individual-stats,
    .admin-stats,
    .document-stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .metric-label,
    .individual-stats small,
    .admin-stats span,
    .admin-stats small,
    .document-stats span,
    .document-stats small {
        font-size: 12px !important;
        line-height: 1.4;
    }

    .session-row .session-meta,
    .session-row .capacity {
        display: block;
        grid-column: 2 / -1;
    }

    [data-responsive-table-container] {
        margin-inline: 0 !important;
    }

    table[data-responsive-table] tbody tr {
        padding: 4px 15px !important;
        overflow: visible;
        border-radius: 12px !important;
        box-shadow: none;
    }

    table[data-responsive-table] tbody td {
        grid-template-columns: minmax(96px, 38%) minmax(0, 1fr) !important;
        gap: 12px;
        padding: 12px 0 !important;
        font-size: 13px !important;
        line-height: 1.5;
    }

    table[data-responsive-table] tbody td::before {
        font-size: 11px !important;
        line-height: 1.4;
    }

    .participants-table tbody tr {
        padding: 18px 50px 17px 0;
    }

    .participants-table .person-cell small {
        display: block !important;
        margin-top: 5px;
    }

    .participants-table td,
    .participants-table :where(strong, small) {
        font-size: 13px !important;
        line-height: 1.45;
    }

    .audit-details dl {
        grid-template-columns: 1fr;
        width: 100%;
        min-width: 0;
        padding: 13px;
    }

    .audit-details :where(dt, dd, code) {
        font-size: 12px !important;
    }

    .workshop-filters,
    .individual-filters,
    .report-filters,
    .admin-filters,
    .audit-filters,
    .document-filters,
    .list-toolbar {
        grid-template-columns: minmax(0, 1fr) !important;
    }

    :where(.workshop-filters, .individual-filters, .report-filters, .admin-filters, .audit-filters, .document-filters, .list-toolbar) > * {
        grid-column: 1 !important;
        width: 100%;
        min-width: 0;
        justify-self: stretch !important;
    }

    .workshop-inspector,
    .support-inspector {
        scroll-margin-top: calc(var(--mobile-appbar-height) + var(--mobile-safe-top) + 12px);
    }

    .settings-mobile-nav {
        position: sticky;
        z-index: 12;
        top: calc(var(--mobile-appbar-height) + var(--mobile-safe-top));
        margin: 0 0 24px;
        padding-block: 8px;
        background: var(--canvas);
    }

    .settings-mobile-nav select {
        width: 100%;
    }

    .settings-layout,
    .settings-content,
    .settings-section,
    .catalog-layout,
    .mapping-layout,
    .branding-admin-item,
    .updates-layout,
    .updates-summary,
    .updates-meta {
        width: 100%;
        min-width: 0;
        max-width: 100%;
    }

    .editor-row,
    .branding-admin-fields,
    .mapping-option,
    .project-result-target {
        grid-template-columns: minmax(0, 1fr) !important;
    }

    .planner-weekdays > div {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .planner-weekdays label span {
        min-height: 48px;
        font-size: 12px;
    }

    .planner-topic-picker,
    .planner-topic-row,
    .planner-preview-row {
        grid-template-columns: minmax(0, 1fr);
        gap: 10px;
        padding-block: 14px;
    }

    .planner-topic-capacity {
        grid-template-columns: minmax(0, 1fr) 88px;
        font-size: 12px;
    }

    .planner-topic-capacity input {
        width: 88px;
    }

    .planner-topic-actions {
        justify-content: flex-start;
    }

    .planner-topic-actions button {
        width: 44px;
        height: 44px;
    }

    .planner-preview-row span {
        justify-self: start;
        text-align: left;
    }

    .planner-actions,
    .planner-actions > div,
    .dialog-actions {
        align-items: stretch;
        flex-direction: column;
        width: 100%;
    }

    .planner-actions :where(button, .primary-action, .quiet-action),
    .dialog-actions :where(button, .primary-action, .quiet-action) {
        width: 100%;
    }

    dialog.session-dialog,
    dialog.planner-dialog,
    dialog.assessment-dialog,
    dialog.support-dialog {
        inset: 0;
        width: 100vw;
        max-width: none;
        height: 100dvh;
        max-height: 100dvh;
        margin: 0;
        border-radius: 0;
    }

    :where(.session-form, .planner-form, .assessment-form, .support-form) {
        width: 100%;
        height: 100dvh;
        max-height: 100dvh;
    }

    :where(.session-dialog, .planner-dialog, .assessment-dialog, .support-dialog) .dialog-header {
        position: sticky;
        z-index: 4;
        top: 0;
        padding-top: calc(18px + env(safe-area-inset-top));
        background: rgba(251, 250, 247, .98);
    }

    :where(.session-dialog, .planner-dialog, .assessment-dialog, .support-dialog) .dialog-body,
    .planner-body {
        flex: 1 1 auto;
        min-height: 0;
        padding-inline: 18px;
    }

    :where(.session-dialog, .planner-dialog, .assessment-dialog, .support-dialog) .dialog-actions {
        position: sticky;
        z-index: 4;
        bottom: 0;
        padding: 14px 18px calc(14px + env(safe-area-inset-bottom));
        background: rgba(251, 250, 247, .98);
    }

    .confirmation-dialog {
        width: calc(100vw - 24px);
        max-width: none;
    }

    .participant-drawer,
    .user-drawer,
    .document-drawer {
        width: 100%;
        height: 100dvh;
        max-height: 100dvh;
        padding-bottom: env(safe-area-inset-bottom);
    }

    :where(.participant-drawer, .user-drawer, .document-drawer) .drawer-header {
        padding-top: calc(18px + env(safe-area-inset-top));
    }

    .requirements-content {
        padding-inline: 18px;
    }

    body.mobile-shell-ready .krc-a11y-trigger {
        bottom: calc(var(--mobile-bottom-nav-height) + var(--mobile-safe-bottom) + 12px);
    }

    body:has(.login-shell) .krc-a11y-trigger {
        top: calc(12px + env(safe-area-inset-top));
        right: max(12px, env(safe-area-inset-right));
        bottom: auto;
    }

    body.mobile-shell-ready .pwa-widget {
        bottom: calc(var(--mobile-bottom-nav-height) + var(--mobile-safe-bottom) + 12px);
    }

    body.mobile-shell-ready :where(.toast, .portal-toast) {
        z-index: 880;
        right: 96px;
        bottom: calc(var(--mobile-bottom-nav-height) + var(--mobile-safe-bottom) + 12px);
        left: 16px;
        width: auto;
        max-width: none;
    }

    body.has-pwa-notice .krc-a11y-trigger,
    body:has(.pwa-widget.is-visible) .krc-a11y-trigger {
        top: auto;
        bottom: var(--krc-pwa-notice-offset, calc(var(--mobile-bottom-nav-height) + var(--mobile-safe-bottom) + 218px));
        visibility: visible;
    }

    body.mobile-nav-open :where(.krc-a11y-trigger, .pwa-widget) {
        visibility: hidden;
        pointer-events: none;
    }

    .legal-footer {
        padding-bottom: calc(18px + env(safe-area-inset-bottom));
    }

    body.mobile-shell-ready .legal-footer {
        padding-bottom: calc(var(--mobile-bottom-nav-height) + var(--mobile-safe-bottom) + 18px);
    }
}

@media (max-width: 380px) {
    body.mobile-shell-ready .content-canvas {
        padding-right: max(14px, env(safe-area-inset-right));
        padding-left: max(14px, env(safe-area-inset-left));
    }

    .content-canvas h1 {
        font-size: clamp(32px, 11vw, 39px);
    }

    .metrics-strip,
    .individual-stats,
    .document-stats,
    .admin-stats--audit {
        grid-template-columns: minmax(0, 1fr);
    }

    .metrics-strip > *,
    .individual-stats > *,
    .document-stats > *,
    .admin-stats--audit > * {
        padding-left: 0 !important;
        border-left: 0 !important;
        border-top: 1px solid var(--line);
    }

    .metrics-strip > :first-child,
    .individual-stats > :first-child,
    .document-stats > :first-child,
    .admin-stats--audit > :first-child {
        border-top: 0;
    }

    table[data-responsive-table] tbody td {
        grid-template-columns: minmax(0, 1fr) !important;
        gap: 5px;
    }

    .planner-weekdays > div {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (display-mode: standalone) and (max-width: 760px) {
    body.mobile-shell-ready .mobile-appbar {
        background: rgba(251, 250, 247, .985);
    }
}
