/**
 * WP Medical Directory v2.0 — Search Shell & Discovery Styles
 *
 * Styles for the Session 6 patient discovery layer:
 *   - Search shell (form, primary input, geolocation toggle)
 *   - "More filters" progressive disclosure (HTML <details>)
 *   - ABC alphabetical filter strip
 *   - AI interpretation panel
 *   - Sub-network filter
 *   - Completeness metabox (admin)
 *   - NAP mismatch admin notice
 *
 * Inherits the design tokens from frontend.css. WCAG 2.1 Level AA
 * compliant per the same standards Session 5 established. Respects
 * prefers-reduced-motion.
 *
 * @package WP Medical Directory
 * @since 2.0.0
 */

/* ─── Search Shell Container ──────────────────────────────────────── */

.wpmd-search-shell {
    background: var(--wpmd-color-bg-section);  /* #f1f5f9 — clearly distinct from page white */
    border: 1px solid var(--wpmd-color-border);
    border-radius: 8px;
    padding: var(--wpmd-space-md) var(--wpmd-space-md) var(--wpmd-space-md);
    margin-bottom: var(--wpmd-space-lg);
    /* Ensure shell expands to contain all child flex rows */
    display: flex;
    flex-direction: column;
    gap: 0;
}

.wpmd-search-shell__form {
    display: contents;  /* form is transparent to layout — shell is the flex container */
}

/* ─── Primary search input row ────────────────────────────────────── */

.wpmd-search-shell__primary {
    display: flex;
    gap: var(--wpmd-space-sm);
    flex-wrap: wrap;
    margin-bottom: var(--wpmd-space-sm);
}

.wpmd-search-shell__input {
    flex: 1 1 280px;
    min-height: 44px; /* WCAG touch target */
    padding: 0 var(--wpmd-space-md);
    font-size: 1.0625rem;
    border: 2px solid var(--wpmd-color-border-strong);
    border-radius: 4px;
    background: var(--wpmd-color-bg);
    color: var(--wpmd-color-text);
}

.wpmd-search-shell__input:focus {
    outline: 3px solid var(--wpmd-color-focus);
    outline-offset: 2px;
    border-color: var(--wpmd-color-focus);
}

.wpmd-search-shell__submit {
    min-height: 44px;
    min-width: 44px;
    padding: 0 var(--wpmd-space-lg);
    font-size: 1rem;
    font-weight: 600;
    color: var(--wpmd-color-bg);
    background: var(--wpmd-color-link);
    border: 2px solid var(--wpmd-color-link);
    border-radius: 4px;
    cursor: pointer;
}

.wpmd-search-shell__submit:hover {
    background: var(--wpmd-color-link-hover);
    border-color: var(--wpmd-color-link-hover);
}

.wpmd-search-shell__submit:focus-visible {
    outline: 3px solid var(--wpmd-color-focus);
    outline-offset: 2px;
}

/* ─── Geolocation row ─────────────────────────────────────────────── */

.wpmd-search-shell__geo {
    display: flex;
    gap: var(--wpmd-space-md);
    flex-wrap: wrap;
    align-items: center;
}

.wpmd-search-shell__geo-toggle,
.wpmd-search-shell__radius {
    display: inline-flex;
    align-items: center;
    gap: var(--wpmd-space-sm);
    font-size: 0.9375rem;
    color: var(--wpmd-color-text);
    cursor: pointer;
    min-height: 44px;
}

/* Hide radius selector when geolocation is not active.
   :has() handles modern browsers; JS adds .geo-inactive as fallback. */
.wpmd-search-shell__geo:not(:has(input[data-wpmd-geolocation]:checked)) .wpmd-search-shell__radius,
.wpmd-search-shell__geo.geo-inactive .wpmd-search-shell__radius {
    display: none;
}

.wpmd-search-shell__geo-toggle input[type="checkbox"] {
    width: 1.125rem;
    height: 1.125rem;
}

.wpmd-search-shell__radius select {
    min-height: 36px;
    padding: 0 var(--wpmd-space-sm);
    border: 1px solid var(--wpmd-color-border-strong);
    border-radius: 4px;
    background: var(--wpmd-color-bg);
}

.wpmd-search-shell__radius select:focus {
    outline: 3px solid var(--wpmd-color-focus);
    outline-offset: 2px;
}

/* ─── Pill filter strip ───────────────────────────────────────────── */

.wpmd-search-shell__filters {
    display: flex;
    flex-wrap: wrap;
    gap: var(--wpmd-space-sm);
    align-items: center;
    padding-top: var(--wpmd-space-xs);
    border-top: 1px solid var(--wpmd-color-border);
    margin-top: var(--wpmd-space-xs);
}

/* Base pill — shared by both select and checkbox-label variants */
.wpmd-filter-pill {
    display: inline-flex;
    align-items: center;
    height: 36px;
    padding: 0 var(--wpmd-space-md);
    border: 1.5px solid var(--wpmd-color-border-strong);
    border-radius: 100px;
    font-size: var(--wpmd-text-sm);
    font-weight: 500;
    color: var(--wpmd-color-text);
    background: var(--wpmd-color-bg);
    cursor: pointer;
    white-space: nowrap;
    transition: border-color 0.15s, background 0.15s, color 0.15s;
    font-family: inherit;
}

.wpmd-filter-pill:hover {
    border-color: var(--wpmd-color-primary);
    background: var(--wpmd-color-primary-bg);
    color: var(--wpmd-color-primary-dark);
}

.wpmd-filter-pill.is-active {
    border-color: var(--wpmd-color-primary);
    background: var(--wpmd-color-primary-bg);
    color: var(--wpmd-color-primary-dark);
    font-weight: 600;
}

/* Select pill — dropdown arrow via appearance override */



/* Checkbox pill — visually hidden checkbox, pill acts as the toggle */
.wpmd-filter-pill--check {
    gap: 0.375rem;
    user-select: none;
}

/* Checkmark prefix when active */
.wpmd-filter-pill--check.is-active::before {
    content: "✓";
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--wpmd-color-primary-dark);
    margin-right: 0.125rem;
}

.wpmd-filter-pill--check:focus-within {
    outline: 3px solid var(--wpmd-color-focus);
    outline-offset: 2px;
    border-radius: 100px;
}

/* Modern browsers: toggle active class via :has() */
.wpmd-filter-pill--check:has(input:checked) {
    border-color: var(--wpmd-color-primary);
    background: var(--wpmd-color-primary-bg);
    color: var(--wpmd-color-primary-dark);
    font-weight: 600;
}

/* ── Pill select wrapper ─────────────────────────────────────────── */
/* The wrapper div is the visible pill. The native <select> sits on top
   as an absolutely-positioned, fully transparent overlay — it handles
   click/keyboard but renders nothing visible. The selected option text
   is shown via ::before reading data-label, updated by JS on change.
   This is the only cross-browser-reliable way to suppress the native
   select arrow widget on Windows Chrome/Edge without losing OS picker
   accessibility. */

.wpmd-pill-wrap {
    position: relative;
    /* No overflow:hidden — it clips ::before label text.
       The native select's focus ring is suppressed via outline:none below. */
    padding-right: 1.75rem;
    min-width: 140px;
    max-width: 280px;
    /* Full background shorthand so no cascade from .wpmd-filter-pill
       shorthand can reset background-repeat back to 'repeat' */
    background: var(--wpmd-color-bg)
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='11' height='11' viewBox='0 0 24 24' fill='none' stroke='%23475569' stroke-width='2.5'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E")
        no-repeat right 0.5rem center / 11px;
}

/* Label text from data-label attribute set by JS */
.wpmd-pill-wrap::before {
    content: attr(data-label);
    pointer-events: none;
    white-space: nowrap;
    /* No truncation — wrapper max-width handles overflow */
}

.wpmd-pill-wrap:hover {
    border-color: var(--wpmd-color-primary);
    color: var(--wpmd-color-primary-dark);
    background: var(--wpmd-color-primary-bg)
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='11' height='11' viewBox='0 0 24 24' fill='none' stroke='%23475569' stroke-width='2.5'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E")
        no-repeat right 0.5rem center / 11px;
}

.wpmd-pill-wrap.is-active {
    border-color: var(--wpmd-color-primary);
    color: var(--wpmd-color-primary-dark);
    font-weight: 600;
    /* Full shorthand — prevents background-repeat defaulting to repeat */
    background: var(--wpmd-color-primary-bg)
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='11' height='11' viewBox='0 0 24 24' fill='none' stroke='%230e3650' stroke-width='2.5'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E")
        no-repeat right 0.5rem center / 11px;
}

/* Keyboard focus ring on wrapper when select is focused */
.wpmd-pill-wrap:focus-within {
    outline: 2px solid var(--wpmd-color-focus);
    outline-offset: 2px;
}

/* The native <select> — invisible overlay covering the wrapper.
   appearance:none kills the OS arrow widget.
   color/background transparent makes it visually invisible.
   No border, outline, or shadow — the wrapper provides all chrome.
   z-index keeps it above the ::before pseudo-element so it intercepts clicks. */
.wpmd-pill-wrap__select {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    cursor: pointer;
    /* appearance:none kills the native dropdown arrow widget */
    appearance: none !important;
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    /* opacity:0 makes the element invisible in the CSS compositing layer.
       The OS-native picker renders in its own layer above CSS opacity,
       so options remain fully readable when the dropdown opens. */
    opacity: 0 !important;
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    margin: 0 !important;
}

/* Suppress frontend.css .wpmd-directory select:focus-visible on the inner select */
.wpmd-directory .wpmd-pill-wrap__select:focus,
.wpmd-directory .wpmd-pill-wrap__select:focus-visible {
    outline: none !important;
    box-shadow: none !important;
}

@media (prefers-reduced-motion: reduce) {
    .wpmd-filter-pill { transition: none; }
}

/* ─── Loading state (applied by JS during filter submit) ─────────── */

.wpmd-search-shell.is-loading {
    opacity: 0.55;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

.wpmd-search-shell.is-loading .wpmd-search-shell__submit {
    cursor: wait;
}

@media (prefers-reduced-motion: reduce) {
    .wpmd-search-shell.is-loading { transition: none; }
}

/* ─── ABC alphabetical strip ──────────────────────────────────────── */

.wpmd-abc-strip {
    display: flex;
    flex-wrap: wrap;
    gap: var(--wpmd-space-xs);
    margin-top: var(--wpmd-space-md);
    padding-top: var(--wpmd-space-md);
    border-top: 1px solid var(--wpmd-color-border);
}

.wpmd-abc-strip__letter {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: var(--wpmd-touch-min);
    height: var(--wpmd-touch-min);
    padding: 0 var(--wpmd-space-sm);
    font-weight: 600;
    font-size: 0.9375rem;
    color: var(--wpmd-color-link);
    background: var(--wpmd-color-bg);
    border: 1px solid var(--wpmd-color-border);
    border-radius: 4px;
    text-decoration: none;
}

.wpmd-abc-strip__letter:hover {
    background: var(--wpmd-color-bg-subtle);
    border-color: var(--wpmd-color-link);
}

.wpmd-abc-strip__letter:focus-visible {
    outline: 3px solid var(--wpmd-color-focus);
    outline-offset: 2px;
}

.wpmd-abc-strip__letter.is-current {
    background: var(--wpmd-color-link);
    color: var(--wpmd-color-bg);
    border-color: var(--wpmd-color-link);
}

.wpmd-abc-strip__letter--all {
    min-width: 56px;
}

.wpmd-abc-strip__letter--disabled {
    color: var(--wpmd-color-text-muted);
    background: var(--wpmd-color-bg-subtle);
    border-style: dashed;
    cursor: not-allowed;
    opacity: 0.6;
}

/* ─── AI interpretation panel ─────────────────────────────────────── */

.wpmd-search-shell__interpretation {
    margin-top: var(--wpmd-space-md);
    padding: var(--wpmd-space-sm) var(--wpmd-space-md);
    background: var(--wpmd-color-bg);
    border-left: 4px solid var(--wpmd-color-link);
    border-radius: 4px;
    font-size: 0.9375rem;
}

.wpmd-search-shell__interpretation-label {
    font-weight: 600;
    color: var(--wpmd-color-text-muted);
    margin-right: var(--wpmd-space-sm);
}

.wpmd-search-shell__interpretation-text {
    color: var(--wpmd-color-text);
}

/* ─── Completeness metabox (admin) ────────────────────────────────── */

.wpmd-completeness-metabox {
    font-size: 13px;
}

.wpmd-completeness-metabox__badge {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px;
    margin-bottom: 12px;
    border-radius: 6px;
    border: 2px solid currentColor;
}

.wpmd-completeness-metabox__badge--high {
    color: #1b5e20;
    background: #e8f5e9;
}

.wpmd-completeness-metabox__badge--medium {
    color: #664d03;
    background: #fff3cd;
}

.wpmd-completeness-metabox__badge--low {
    color: #b3261e;
    background: #fce4e4;
}

.wpmd-completeness-metabox__percent {
    font-size: 28px;
    font-weight: 700;
    line-height: 1;
}

.wpmd-completeness-metabox__label {
    font-size: 12px;
    text-transform: uppercase;
    margin-top: 4px;
}

.wpmd-completeness-metabox__tier1-warning {
    padding: 8px 10px;
    background: #fce4e4;
    border-left: 4px solid #b3261e;
    color: #4a1310;
    font-size: 12px;
    margin: 0 0 12px 0;
    line-height: 1.4;
}

.wpmd-completeness-metabox__suggestions-heading {
    font-size: 13px;
    font-weight: 600;
    margin: 12px 0 8px 0;
}

.wpmd-completeness-metabox__suggestions {
    list-style: none;
    margin: 0;
    padding: 0;
}

.wpmd-completeness-metabox__suggestion {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 6px 0;
    border-bottom: 1px solid #e5e5e5;
    counter-increment: none;
}

.wpmd-completeness-metabox__suggestion:last-child {
    border-bottom: none;
}

.wpmd-completeness-metabox__tier-tag {
    display: inline-block;
    padding: 2px 6px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    border-radius: 3px;
    flex-shrink: 0;
}

.wpmd-completeness-metabox__suggestion--tier-1 .wpmd-completeness-metabox__tier-tag {
    background: #b3261e;
    color: #ffffff;
}

.wpmd-completeness-metabox__suggestion--tier-2 .wpmd-completeness-metabox__tier-tag {
    background: #664d03;
    color: #ffffff;
}

.wpmd-completeness-metabox__suggestion--tier-3 .wpmd-completeness-metabox__tier-tag {
    background: #4a4a4a;
    color: #ffffff;
}

.wpmd-completeness-metabox__field-label {
    flex: 1 1 auto;
    color: #1a1a1a;
}

.wpmd-completeness-metabox__hint-button {
    flex-shrink: 0;
    font-size: 11px !important;
}

.wpmd-completeness-metabox__more {
    margin: 12px 0 0 0;
    padding-top: 8px;
    border-top: 1px solid #e5e5e5;
    color: #4a4a4a;
    font-size: 12px;
    font-style: italic;
}

.wpmd-completeness-metabox__complete {
    padding: 12px;
    background: #e8f5e9;
    color: #1b5e20;
    border-radius: 4px;
    text-align: center;
    font-weight: 600;
    margin: 0;
}

/* ─── Distance display on search result cards ─────────────────────── */

.wpmd-card__distance {
    display: inline-flex;
    align-items: center;
    gap: var(--wpmd-space-xs);
    font-size: 0.875rem;
    color: var(--wpmd-color-text-muted);
    margin-top: var(--wpmd-space-xs);
}

.wpmd-card__distance::before {
    content: "📍";
    font-style: normal;
}

