/* QSORT participant UI styling.
   Follows STRATEGIOS design tokens (B&W, Inter) from shared strategios.css. */

#qsort-root {
    --card-bg: var(--color-surface, #fff);
    --card-fg: var(--color-text, #111);
    --card-border: var(--color-border, #d9d9d9);
    --card-selected: var(--color-accent, #111);
    --cell-empty-bg: var(--color-surface-alt, #f4f4f4);
    --cell-droppable-bg: #fffbe6;
    --flash-bg: #ffe3e3;
}

.qsort-state {
    padding: 1.5rem 0;
}

.qsort-state[hidden] {
    display: none;
}

.qsort-header h2 {
    margin-bottom: 0.25rem;
}

.qsort-header .instruction {
    color: var(--muted);
    margin-top: 0;
}

.consent-label {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 1rem;
    border: 1px solid var(--card-border);
    border-radius: 4px;
    cursor: pointer;
}

.consent-label input {
    margin-top: 0.2rem;
    flex-shrink: 0;
}

.nav-buttons {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

/* -- Presort (one-at-a-time triage) -- */

.presort-card-wrap {
    display: flex;
    justify-content: center;
    margin: 2rem 0 1.5rem;
}

.presort-card {
    width: 100%;
    max-width: 520px;
    min-height: 9rem;
    padding: 1.5rem;
    background: var(--card-bg);
    color: var(--card-fg);
    border: 2px solid var(--card-border);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-size: 1.1rem;
    line-height: 1.4;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}

.presort-card-text {
    font-weight: 400;
}

.presort-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.button-presort {
    flex: 1 1 120px;
    max-width: 180px;
    min-height: 3rem;
    font-size: 0.95rem;
}

@media (max-width: 480px) {
    .presort-card {
        min-height: 7rem;
        padding: 1rem;
        font-size: 1rem;
    }
    .presort-actions {
        flex-direction: column;
    }
    .button-presort {
        max-width: none;
    }
}

/* -- Unplaced cards tray -- */

.qsort-unplaced {
    margin: 1rem 0 1.5rem;
    padding: 1rem;
    border: 1px solid var(--card-border);
    border-radius: 4px;
}

.qsort-unplaced-heading {
    font-size: 0.9rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin: 0 0 0.75rem;
}

.qsort-count {
    margin-left: 0.25rem;
    padding: 0.1rem 0.5rem;
    background: var(--color-text, #111);
    color: var(--color-surface, #fff);
    border-radius: 10px;
    font-size: 0.8rem;
}

.qsort-unplaced-cards {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    min-height: 3rem;
}

/* -- Sort grid -- */

.qsort-grid-labels {
    display: flex;
    justify-content: space-between;
    margin: 0.5rem 0;
    font-size: 0.85rem;
    color: var(--muted);
}

.qsort-grid {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(0, 1fr);
    gap: 0.25rem;
    margin-bottom: 1.5rem;
}

.qsort-col {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.qsort-col-flash {
    animation: col-flash 0.4s ease;
}

@keyframes col-flash {
    0%, 100% { background: transparent; }
    50% { background: var(--flash-bg); }
}

.qsort-col-header {
    text-align: center;
    font-weight: 600;
    padding: 0.4rem 0.25rem;
    border-bottom: 2px solid var(--card-border);
    font-size: 0.9rem;
}

.qsort-col-label {
    font-size: 0.7rem;
    font-weight: 400;
    color: var(--muted);
    margin-top: 0.1rem;
    line-height: 1.2;
}

.qsort-cell {
    min-height: 4.5rem;
    padding: 0.25rem;
    border: 1px dashed var(--card-border);
    border-radius: 4px;
    display: flex;
    align-items: stretch;
}

.qsort-cell-empty {
    background: var(--cell-empty-bg);
}

.qsort-cell-droppable {
    background: var(--cell-droppable-bg);
    border-style: solid;
    cursor: pointer;
}

.qsort-cell-droppable:hover {
    background: #fff5b3;
}

/* -- Cards -- */

.qsort-card {
    display: block;
    width: 100%;
    min-height: 3rem;
    padding: 0.5rem 0.6rem;
    background: var(--card-bg);
    color: var(--card-fg);
    border: 1px solid var(--card-border);
    border-radius: 4px;
    font-family: inherit;
    font-size: 0.85rem;
    line-height: 1.3;
    text-align: left;
    cursor: pointer;
    transition: border-color 0.15s, transform 0.1s, box-shadow 0.15s;
}

.qsort-card:hover {
    border-color: var(--card-selected);
}

.qsort-card-selected {
    border-color: var(--card-selected);
    border-width: 2px;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.qsort-card-placed {
    font-size: 0.78rem;
    min-height: auto;
    padding: 0.4rem 0.5rem;
}

.qsort-unplaced-cards .qsort-card {
    flex: 0 1 calc(50% - 0.25rem);
    max-width: 320px;
}

@media (min-width: 720px) {
    .qsort-unplaced-cards .qsort-card {
        flex: 0 1 calc(33% - 0.4rem);
    }
}

/* -- Footer / progress -- */

.qsort-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--card-border);
}

.qsort-progress {
    font-family: var(--font-mono, ui-monospace, SFMono-Regular, monospace);
    font-size: 0.95rem;
    color: var(--muted);
}

/* -- Comments step -- */

.qsort-comments {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin: 1rem 0;
}

.qsort-comments-section-heading {
    margin: 1.5rem 0 0.25rem;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
}

.qsort-comments-section-heading:first-child {
    margin-top: 0;
}

.qsort-comment-item {
    padding: 0.75rem 1rem;
    border: 1px solid var(--card-border);
    border-radius: 4px;
    background: var(--card-bg);
    color: var(--card-fg);
}

.qsort-comment-statement {
    margin: 0 0 0.5rem;
    font-weight: 500;
    line-height: 1.35;
}

.qsort-comment-input {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--card-border);
    border-radius: 3px;
    font-family: inherit;
    font-size: 0.9rem;
    line-height: 1.35;
    resize: vertical;
}

/* -- Demographics form -- */

.qsort-demographics {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    margin: 1rem 0;
}

.demographics-field {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.demographics-label {
    font-weight: 500;
    font-size: 0.95rem;
}

.demographics-field input[type="text"],
.demographics-field select,
.demographics-field textarea {
    padding: 0.5rem;
    border: 1px solid var(--card-border);
    border-radius: 3px;
    font-family: inherit;
    font-size: 0.95rem;
    background: var(--card-bg);
    color: var(--card-fg);
}

.demographics-field textarea {
    resize: vertical;
}

.demographics-radio-group,
.demographics-checkbox-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.demographics-radio-option,
.demographics-checkbox-option {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.3rem 0;
    cursor: pointer;
}

.demographics-error {
    margin-top: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: var(--flash-bg);
    border: 1px solid #c33;
    border-radius: 3px;
    font-size: 0.9rem;
}

/* -- Drag-and-drop helpers -- */

.qsort-card-ghost {
    opacity: 0.35;
    background: var(--cell-droppable-bg);
    border-style: dashed;
}

/* -- Screen reader only -- */

.qsort-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* -- Error state -- */

.error-message {
    padding: 1rem;
    background: var(--flash-bg);
    border: 1px solid #c33;
    border-radius: 4px;
    font-family: var(--font-mono, ui-monospace, SFMono-Regular, monospace);
    font-size: 0.9rem;
    word-break: break-word;
}

/* -- Mobile adjustments -- */

@media (max-width: 480px) {
    .qsort-grid {
        gap: 0.15rem;
    }
    .qsort-col-header {
        font-size: 0.75rem;
        padding: 0.3rem 0.1rem;
    }
    .qsort-col-label {
        display: none;
    }
    .qsort-cell {
        min-height: 3.5rem;
        padding: 0.1rem;
    }
    .qsort-card-placed {
        font-size: 0.65rem;
        padding: 0.25rem;
    }
}
