/* CSS custom property defaults — overridden per-tenant via theme.css */
:root {
    /* Primary must keep ≥ 4.5:1 contrast with --color-primary-text (WCAG AA) */
    --color-primary: #1d4ed8;
    --color-primary-dark: #1e40af;
    --color-primary-text: #ffffff;
    --color-secondary: #64748b;
    --color-bg: #ffffff;
    --color-bg-alt: #f8fafc;
    --color-surface: #f1f5f9;
    --color-border: #e2e8f0;
    --color-text: #0f172a;
    --color-text-muted: #64748b;
    --color-error: #dc2626;
    --color-success: #16a34a;
    --color-warning: #ca8a04;
    --color-warning-bg: #fef9c3;

    --font-sans: system-ui, -apple-system, sans-serif;
    --radius: 6px;
    --shadow-sm: 0 1px 2px rgb(0 0 0 / 0.05);
    --shadow: 0 1px 3px rgb(0 0 0 / 0.1), 0 1px 2px rgb(0 0 0 / 0.06);
}

/* Reset & base */
*, *::before, *::after { box-sizing: border-box; }

body {
    font-family: var(--font-sans);
    background-color: var(--color-bg);
    color: var(--color-text);
    margin: 0;
    line-height: 1.6;
}

/* Layout */
.flow-container {
    max-width: 640px;
    margin: 2rem auto;
    padding: 0 1rem;
}

.char-counter {
    display: block;
    margin-top: 0.25rem;
    text-align: right;
    font-size: 0.8125rem;
    color: var(--color-text-muted);
    font-variant-numeric: tabular-nums;
}

.char-counter.is-invalid { color: var(--color-error); }

/* Language choice: full-width tappable rows */
.locale-option {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-bg);
    font-weight: 500;
    cursor: pointer;
}

.locale-option:hover { border-color: var(--color-primary); }

.locale-option:has(input:checked) {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 1px var(--color-primary);
}

.flow-progress {
    margin-bottom: 1.25rem;
}

.flow-progress-text {
    display: block;
    font-size: 0.8125rem;
    color: var(--color-text-muted);
    margin-bottom: 0.375rem;
}

.flow-progress-bar {
    height: 4px;
    border-radius: 9999px;
    background: var(--color-surface);
    overflow: hidden;
}

.flow-progress-bar span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: var(--color-primary);
    transition: width 0.3s;
}

.flow-header {
    margin-bottom: 2rem;
}

.flow-header h1 {
    margin: 0 0 0.5rem;
    font-size: 1.5rem;
}

.flow-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 2rem;
    align-items: center;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.625rem 1.25rem;
    border-radius: var(--radius);
    font-size: 0.9375rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    border: none;
    transition: background-color 0.15s;
}

.btn-primary {
    background-color: var(--color-primary);
    color: var(--color-primary-text);
}

.btn-primary:hover { background-color: var(--color-primary-dark); }

.btn-secondary {
    background-color: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-border);
}

.btn-danger {
    background-color: var(--color-error);
    color: #fff;
}

.btn-small {
    padding: 0.375rem 0.75rem;
    font-size: 0.875rem;
}

/* Forms */
/* Question groups: a soft card instead of the browser's default frame */
fieldset {
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-bg-alt);
    padding: 1.25rem;
    margin: 0 0 1.5rem;
    min-width: 0;
}

legend {
    /* Floating pulls the legend inside the card instead of straddling the
       border, which breaks with long questions that wrap. */
    float: left;
    width: 100%;
    padding: 0;
    margin: 0 0 1rem;
    font-size: 1.0625rem;
    font-weight: 600;
    line-height: 1.4;
}

legend + * { clear: both; }

fieldset > :last-child { margin-bottom: 0; }

.form-group {
    margin-bottom: 1.25rem;
}

label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.375rem;
    font-size: 0.9375rem;
}

.form-control {
    display: block;
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-family: inherit; /* textareas default to monospace otherwise */
    font-size: 1rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background-color: var(--color-bg);
    color: var(--color-text);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.form-control:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgb(37 99 235 / 0.15);
}

textarea.form-control { resize: vertical; }

.form-check {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.form-check-input {
    margin-top: 0.2rem;
    flex-shrink: 0;
}

.form-help, small.form-help {
    display: block;
    font-size: 0.8125rem;
    color: var(--color-text-muted);
    margin-top: 0.25rem;
}

.has-error .form-control { border-color: var(--color-error); }

.form-errors {
    list-style: none;
    padding: 0;
    margin: 0.375rem 0 0;
}

.form-errors li {
    font-size: 0.8125rem;
    color: var(--color-error);
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2364748b' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2.25rem;
    cursor: pointer;
}

.choice-expanded {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.25rem;
}

.choice-item {
    display: flex;
    align-items: center;
    gap: 0.625rem;
}

.choice-item input[type="checkbox"],
.choice-item input[type="radio"] {
    width: 1rem;
    height: 1rem;
    margin: 0;
    flex-shrink: 0;
    accent-color: var(--color-primary);
    cursor: pointer;
}

.choice-item label {
    font-weight: 400;
    margin-bottom: 0;
    cursor: pointer;
}

/* Alerts */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.9375rem;
}

.alert-error {
    background-color: #fef2f2;
    border: 1px solid #fca5a5;
    color: var(--color-error);
}

/* Badges */
.badge {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-pending_review   { background: #fef3c7; color: #92400e; }
.badge-returned_to_submitter { background: #fce7f3; color: #9d174d; }
.badge-published        { background: #d1fae5; color: #065f46; }
.badge-rejected         { background: #fee2e2; color: #991b1b; }
.badge-withdrawn        { background: #f1f5f9; color: #475569; }

/* Admin layout */
.admin-layout {
    display: flex;
    min-height: 100vh;
}

.admin-sidebar {
    width: 220px;
    background: var(--color-bg-alt);
    border-right: 1px solid var(--color-border);
    padding: 1.5rem 1rem;
    flex-shrink: 0;
}

.admin-main {
    flex: 1;
    padding: 2rem;
    overflow: auto;
}

.admin-nav a {
    display: block;
    padding: 0.5rem 0.75rem;
    color: var(--color-text);
    text-decoration: none;
    border-radius: var(--radius);
    font-size: 0.9375rem;
}

.admin-nav a:hover { background: var(--color-surface); }
.admin-nav a.active { background: var(--color-primary); color: white; }

/* Tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.625rem 0.75rem; border-bottom: 1px solid var(--color-border); font-size: 0.9375rem; }
th { font-weight: 600; background: var(--color-bg-alt); }

/* Reformulation / translation review */
.reformulation-field, .translation-field { margin-bottom: 2rem; border: 1px solid var(--color-border); border-radius: var(--radius); padding: 1rem; }
.reformulation-options .option { margin-bottom: 1rem; }
.text-preview { padding: 0.75rem; background: var(--color-bg-alt); border-radius: var(--radius); font-size: 0.9375rem; margin-top: 0.25rem; white-space: pre-wrap; }

/* Consent */
.consent-text { padding: 1rem; background: var(--color-bg-alt); border: 1px solid var(--color-border); border-radius: var(--radius); margin-bottom: 1.5rem; font-size: 0.9375rem; }
.consent-check { margin: 1rem 0; }

/* Submissions list */
.submissions-list { list-style: none; padding: 0; }
.submission-item { display: flex; justify-content: space-between; align-items: center; padding: 0.75rem 0; border-bottom: 1px solid var(--color-border); }

/* Review page */
.review-card {
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 2rem;
    background: var(--color-bg);
}

.review-row {
    display: grid;
    grid-template-columns: 10rem 1fr;
    gap: 1rem;
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--color-border);
    align-items: baseline;
}

.review-row:last-child { border-bottom: none; }

.review-label {
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--color-text-muted);
}

.review-value {
    font-size: 0.9375rem;
    color: var(--color-text);
    white-space: pre-wrap;
    word-break: break-word;
}

.review-photo-note {
    display: flex;
    align-items: center;
    font-size: 0.875rem;
    color: var(--color-success);
}

.review-photo-preview {
    display: block;
    max-width: 160px;
    max-height: 160px;
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
}

/* Done / success page */
.done-card {
    text-align: center;
    padding: 4rem 1rem 3rem;
}

.done-icon {
    width: 4rem;
    height: 4rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1.5rem;
}

.done-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0 0 1rem;
    color: var(--color-text);
}

.done-body {
    font-size: 1rem;
    color: var(--color-text-muted);
    margin: 0 auto 0.625rem;
    max-width: 26rem;
    line-height: 1.6;
}

.done-hint {
    font-size: 0.875rem;
    margin-top: 1rem;
}

/* Honeypot */
.hp-field { position: absolute; left: -9999px; top: -9999px; }

/* Locale bar */
.locale-bar {
    display: flex;
    justify-content: flex-end;
    gap: 0.25rem;
    padding: 0.375rem 1rem;
    background: var(--color-bg-alt);
    border-bottom: 1px solid var(--color-border);
    font-size: 0.8125rem;
}
.locale-bar-btn {
    padding: 0.1875rem 0.625rem;
    border-radius: 9999px;
    text-decoration: none;
    color: var(--color-text-muted);
    border: 1px solid transparent;
    transition: background 0.15s;
}
.locale-bar-btn:hover { background: var(--color-surface); color: var(--color-text); }
.locale-bar-btn.active { color: var(--color-text); border-color: var(--color-border); font-weight: 500; }

/* Photo step */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

.photo-dropzone {
    border: 2px dashed var(--color-border);
    border-radius: var(--radius);
    padding: 2.5rem 1.5rem;
    text-align: center;
    background-color: var(--color-bg-alt);
    transition: border-color 0.15s, background-color 0.15s;
}

.photo-dropzone.is-dragover {
    border-color: var(--color-primary);
    background-color: rgb(37 99 235 / 0.06);
}

.photo-dropzone-hint {
    margin: 0 0 1rem;
    color: var(--color-text-muted);
    font-size: 0.9375rem;
}

.photo-dropzone-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    flex-wrap: wrap;
}

.photo-examples {
    margin-top: 1.5rem;
    padding-top: 1.25rem;
    border-top: 1px dashed var(--color-border);
}

.photo-examples-title {
    margin: 0 0 0.75rem;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--color-text-muted);
}

.photo-examples-row {
    display: flex;
    gap: 1rem;
    justify-content: center;
    flex-wrap: wrap;
}

.photo-example {
    margin: 0;
    max-width: 140px;
}

.photo-example img {
    display: block;
    width: 100%;
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
}

.photo-example figcaption {
    margin-top: 0.375rem;
    font-size: 0.75rem;
    color: var(--color-text-muted);
    line-height: 1.4;
}

.photo-camera {
    margin-top: 1rem;
}

.photo-camera video {
    display: block;
    width: 100%;
    max-height: 60vh;
    border-radius: var(--radius);
    background: #000;
}

.photo-camera-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
    flex-wrap: wrap;
    margin-top: 0.75rem;
}

/* The photo step is skippable, and this line is what stops someone abandoning
   the whole submission there, so it carries a little more weight than the size
   constraints listed beneath it. Theme variables so tenants keep their palette. */
.photo-optional-hint {
    color: var(--color-text);
    font-weight: 600;
}

.photo-editor {
    margin-top: 1.25rem;
}

.photo-editor-canvas {
    max-width: 600px;
}

.photo-editor-canvas img {
    display: block;
    max-width: 100%;
}

/* Cropper v2 swaps the <img> for a <cropper-canvas>, which has no intrinsic
   height of its own, so the editor viewport has to be sized here. */
.photo-editor-canvas cropper-canvas {
    display: block;
    width: 100%;
    height: 420px;
    max-width: 600px;
}

@media (max-width: 640px) {
    .photo-editor-canvas cropper-canvas { height: 300px; }
}

.recrop-canvas cropper-canvas {
    display: block;
    width: 100%;
    height: 400px;
}

@media (max-width: 640px) {
    .recrop-canvas cropper-canvas { height: 280px; }
}

.photo-editor-toolbar {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 0.75rem;
}

.photo-editor-toolbar .btn-small {
    /* 44px minimum touch target */
    min-width: 2.75rem;
    min-height: 2.75rem;
    line-height: 1;
}

.photo-replace[hidden] { display: none; }

.photo-replace {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    flex-wrap: wrap;
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-bg-alt);
}

.photo-replace-label {
    font-size: 0.875rem;
    color: var(--color-text-muted);
    margin-right: auto;
}

.photo-size-readout {
    margin-left: auto;
    font-size: 0.8125rem;
    color: var(--color-text-muted);
    font-variant-numeric: tabular-nums;
}

.photo-size-readout.is-warning {
    color: var(--color-error);
    font-weight: 600;
}

.btn:disabled {
    opacity: 0.6;
    cursor: wait;
}
