/**
 * DATA DARE — Batch UI-7 hardening
 * Responsive overflow, a11y focus/touch, modal/drawer scroll lock,
 * performance tiering for glass surfaces, reduced-motion.
 */

/* ── Scroll lock ── */
body.fi-dd-modal-open,
body.fi-dd-drawer-open {
    overflow: hidden;
}

body.fi-dd-drawer-open::before {
    content: '';
    position: fixed;
    inset: 0;
    z-index: 45;
    background: rgba(14, 14, 14, 0.35);
    pointer-events: auto;
    cursor: pointer;
}

/* ── Page overflow guard ── */
.fi-dd-page,
.fi-dd-community,
.fd-admin-page,
.fd-analytics-page {
    overflow-x: clip;
    max-width: 100%;
}

/* ── Focus visibility (buttons, chips, filters) ── */
.fd-btn:focus-visible,
.fd-chip:focus-visible,
.fi-dd-segment__btn:focus-visible,
.fi-dd-discussion-filter:focus-visible,
.fd-admin-nav__link:focus-visible,
.fd-analytics-section-nav a:focus-visible,
.fi-dd-dataset-card__expand:focus-visible {
    outline: 2px solid var(--fd-gold-highlight, #d99a16);
    outline-offset: 2px;
}

/* ── Touch targets (admin / analytics nav) ── */
.fd-admin-nav__link,
.fd-analytics-section-nav a,
.fi-dd-discussion-filter {
    min-height: var(--fd-touch-min, 44px);
    display: inline-flex;
    align-items: center;
}

.fi-dd-filter-count {
    min-width: 1.5rem;
    min-height: 1.5rem;
}

/* ── Performance: solid surfaces instead of nested blur ── */
.fi-dd-page .fi-dd-dataset-card,
.fi-dd-page .fi-dd-question-card,
.fi-dd-detail.fd-page .fi-dd-detail-section,
.fi-dd-detail.fd-page .fi-dd-discussion-detail,
.fi-dd-community .fi-dd-board-hero,
.fd-admin-page .fi-card:not(.fd-modal__panel),
.fd-analytics-page .fi-card:not(.fd-modal__panel) {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    background: var(--fd-white, #fffdf8);
}

/* Flatten page glass (not modal/drawer) — one soft surface language */
.fi-dd-page .fd-glass:not(.fd-modal__panel):not(.fd-drawer),
.fi-dd-community .fd-glass:not(.fd-modal__panel):not(.fd-drawer),
.fi-dd-detail.fd-page .fd-glass:not(.fd-modal__panel):not(.fd-drawer) {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    background: var(--fd-white, #fffdf8);
    box-shadow: var(--fd-shadow-sm, var(--fd-shadow-soft));
}

.fi-dd-page .fd-glass.fd-glass--strong:not(.fd-modal__panel):not(.fd-drawer),
.fi-dd-community .fd-glass.fd-glass--strong:not(.fd-modal__panel):not(.fd-drawer),
.fi-dd-detail.fd-page .fd-glass.fd-glass--strong:not(.fd-modal__panel):not(.fd-drawer) {
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    background: var(--fd-white, #fffdf8);
    box-shadow: var(--fd-shadow-sm, var(--fd-shadow-soft));
}

.fd-modal__panel.fd-glass--strong,
.fd-drawer.fd-glass--strong {
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
}

/* ── Intro: avoid clipping lead copy on tablet/desktop narrow ── */
@media (max-width: 1023px) {
    .fi-dd-intro {
        max-height: none;
        overflow: visible;
    }
}

/* ── Dataset card expand (touch / no-hover) ── */
.fi-dd-dataset-card__expand {
    display: none;
    width: calc(100% - var(--fd-space-8, 32px));
    margin: 0 var(--fd-space-4, 16px) var(--fd-space-3, 12px);
    min-height: var(--fd-touch-min, 44px);
    justify-content: center;
}

@media (hover: none), (max-width: 1023px) {
    .fi-dd-dataset-card__expand {
        display: inline-flex;
    }
}

.fi-dd-dataset-card.is-expanded .fi-dd-dataset-card__expand {
    display: inline-flex;
}

/* ── Admin tables: contained horizontal scroll ── */
.fd-admin-table-wrap {
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
}

.fd-admin-table-wrap:focus-within {
    outline: 1px solid rgba(217, 154, 22, 0.35);
    outline-offset: 2px;
}

/* ── Analytics chart labels on narrow viewports ── */
@media (max-width: 767px) {
    .fd-analytics-bar-row__label,
    .fd-analytics-funnel__label {
        word-break: break-word;
        hyphens: auto;
    }

    .fd-analytics-bar-row__value {
        font-size: 0.8125rem;
    }
}

/* ── Question prev/next sticky on small screens ── */
@media (max-width: 639px) {
    .fi-dd-question-nav {
        position: sticky;
        bottom: 0;
        z-index: 20;
        background: var(--fd-white, #fffdf8);
        border-top: 1px solid var(--fd-soft-border, rgba(40, 30, 10, 0.12));
        box-shadow: var(--fd-shadow-elevated);
    }

    .fi-dd-question-nav .fd-btn {
        min-height: var(--fd-touch-min, 44px);
        width: 100%;
        justify-content: center;
    }
}

/* ── Detail metadata / file rows wrap ── */
.fi-dd-detail-meta,
.fi-dd-lean-files,
.fi-dd-download-gate__meta {
    word-break: break-word;
}

.fi-dd-lean-file-row {
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* ── Selected state: not color-only (badge + border + aria-selected) ── */
.fi-dd-dataset-card.is-selected .fi-dd-dataset-card__code::after {
    content: ' · Selected';
    font-weight: 600;
    color: var(--fd-gold-text, #9a5d00);
}

/* Priority 23/24 — mobile drawer/modal viewport safety. */
@media (max-width: 960px) {
    .fi-dd-discussion,
    .fi-dd-detail-discussion-drawer {
        max-height: min(78dvh, 720px);
        overflow-y: auto;
        overscroll-behavior: contain;
        padding-bottom: max(var(--fd-space-4, 16px), env(safe-area-inset-bottom, 0px));
    }
}

.fd-modal__panel {
    max-height: min(90dvh, 760px);
    overflow-y: auto;
    overscroll-behavior: contain;
}

@media (max-width: 430px) {
    .fd-modal__panel {
        width: calc(100vw - 24px);
        max-width: calc(100vw - 24px);
    }
}
