/* DynamicForm public form styling.
   Hand-authored rather than Tailwind-from-CDN: the old app pulls the Tailwind CDN build on
   every page load (a large render-blocking script that also JIT-compiles classes in the
   browser). One small stylesheet keeps the embedded form fast and works offline/in iframes.
   Values mirror the current design so the rewrite looks like the live site. */

:root {
    --ink: #1e293b;          /* slate-800 */
    --ink-strong: #0f172a;   /* slate-900 */
    --muted: #64748b;        /* slate-500 */
    --line: #e2e8f0;         /* slate-200 */
    --line-input: #cbd5e1;   /* slate-300 */
    --surface: #ffffff;
    --surface-sunken: #f8fafc; /* slate-50 */
    --primary: #2563eb;      /* blue-600 */
    --primary-light: #3b82f6;/* blue-500 */
    --primary-soft: #eff6ff; /* blue-50 */
    --danger: #ef4444;
    --radius: 0.75rem;
    --radius-lg: 1rem;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    font-size: 1rem;
    line-height: 1.6;
    color: var(--ink);
    background: linear-gradient(160deg, var(--surface-sunken) 0%, #ffffff 45%, #eff6ff80 100%);
    min-height: 100vh;
}

/* ---------- page chrome ---------- */

.site-header {
    position: sticky;
    top: 0;
    z-index: 40;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--line);
}

.site-header__inner,
.site-footer__inner {
    max-width: 64rem;
    margin: 0 auto;
    padding: 0 1.25rem;
    min-height: 4rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.brand {
    display: inline-flex;
    align-items: center;
    gap: 0.625rem;
    font-weight: 600;
    color: var(--ink-strong);
    text-decoration: none;
}

.brand__mark {
    width: 2.25rem;
    height: 2.25rem;
    border-radius: var(--radius);
    background: linear-gradient(135deg, var(--primary-light), var(--primary));
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}

.brand img { max-height: 2.75rem; width: auto; display: block; }

.header-link {
    color: var(--muted);
    text-decoration: none;
    font-size: 0.9rem;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
}
.header-link:hover { color: var(--primary); background: var(--primary-soft); }

.page-main { padding: 2rem 1rem 3rem; }

.form-card {
    max-width: 46rem;
    margin: 0 auto;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: 0 10px 30px -12px rgba(15, 23, 42, 0.15);
    padding: clamp(1.25rem, 4vw, 2.5rem);
}

.form-title {
    margin: 0 0 1.75rem;
    font-size: clamp(1.4rem, 3vw, 1.75rem);
    font-weight: 700;
    color: var(--ink-strong);
    text-align: center;
}

.site-footer {
    border-top: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.7);
    color: var(--muted);
    font-size: 0.85rem;
}
.site-footer__inner { min-height: 3.5rem; }
.site-footer a { color: var(--muted); }

/* ---------- layout grid (maps the stored col-md-* widths) ---------- */

.grid {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: 1.5rem 1rem;
}

.col { grid-column: span 12 / span 12; }

@media (min-width: 48rem) {
    .col-3 { grid-column: span 3 / span 3; }
    .col-4 { grid-column: span 4 / span 4; }
    .col-6 { grid-column: span 6 / span 6; }
    .col-8 { grid-column: span 8 / span 8; }
}

.form-step + .form-step { margin-top: 2rem; }

.step-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--ink-strong);
    margin: 0 0 1rem;
}

/* ---------- fields ---------- */

.field-label {
    display: block;
    font-size: 1rem;
    font-weight: 600;
    color: var(--ink);
    margin-bottom: 0.5rem;
}

.field-letter { color: var(--primary-light); margin-right: 0.35rem; font-weight: 600; }
.required { color: var(--danger); margin-left: 0.25rem; }

.field-help {
    margin: 0.4rem 0 0;
    font-size: 0.85rem;
    color: var(--muted);
}

.input {
    width: 100%;
    padding: 0.75rem 1rem;
    font: inherit;
    font-size: 1rem;            /* 16px keeps iOS from zooming on focus */
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--line-input);
    border-radius: var(--radius);
    transition: border-color .15s, box-shadow .15s;
}

.input::placeholder { color: #94a3b8; }

.input:focus {
    outline: none;
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.18);
}

textarea.input { min-height: 8.75rem; resize: vertical; }
select.input { cursor: pointer; }

/* choice cards (radio / checkbox) */
.choices { display: flex; flex-direction: column; gap: 0.75rem; }

.choice {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    background: var(--surface);
    border: 2px solid var(--line);
    border-radius: var(--radius);
    cursor: pointer;
    transition: border-color .15s, background .15s;
}
.choice:hover { border-color: #93c5fd; background: #eff6ff4d; }
.choice:has(input:checked) { border-color: var(--primary-light); background: var(--primary-soft); }
.choice input { width: 1.15rem; height: 1.15rem; accent-color: var(--primary); flex: none; }
.choice span { font-size: 0.95rem; font-weight: 500; }

.upload {
    padding: 2rem 1rem;
    text-align: center;
    color: var(--muted);
    background: var(--surface-sunken);
    border: 2px dashed var(--line-input);
    border-radius: var(--radius);
}

/* ---------- repeatable group ---------- */

.group-block {
    margin: 2rem 0;
    padding-top: 1.5rem;
    border-top: 1px solid var(--line);
}
.group-block > h3 { font-size: 1.1rem; font-weight: 700; color: var(--ink-strong); margin: 0 0 1rem; }

.group-row {
    background: var(--surface-sunken);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1.25rem;
}

/* ---------- read-only submission view ---------- */

.submitted-banner {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
    padding: 0.75rem 1rem;
    background: var(--primary-soft);
    border: 1px solid #bfdbfe;
    border-radius: var(--radius);
    color: #1e40af;
    font-size: 0.9rem;
}

.answer {
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--line);
}
.answer:last-child { border-bottom: 0; }

.answer__label {
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 0.2rem;
}

.answer__value { color: var(--ink-strong); overflow-wrap: anywhere; white-space: pre-wrap; }
.answer__value--empty { color: #94a3b8; font-style: italic; }
.answer__list { margin: 0; padding-left: 1.25rem; color: var(--ink-strong); }

.answer-group > h4 {
    margin: 0 0 0.5rem;
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--ink-strong);
}
.answer-group + .answer-group { margin-top: 1rem; }

/* ---------- closed / not-found panels ---------- */

.closed-panel {
    text-align: center;
    padding: 2rem 1rem;
}
.closed-panel h2 { color: var(--ink-strong); margin: 0 0 0.5rem; }
.closed-panel p { color: var(--muted); max-width: 32rem; margin: 0 auto; }

.muted { color: var(--muted); }

/* ---------- actions ---------- */

.form-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 1rem;
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--line);
}

.btn-submit {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.875rem 2rem;
    font: inherit;
    font-size: 1rem;
    font-weight: 600;
    color: #fff;
    background: linear-gradient(135deg, var(--primary-light), var(--primary));
    border: 0;
    border-radius: var(--radius);
    box-shadow: 0 10px 20px -10px rgba(37, 99, 235, 0.7);
    cursor: pointer;
}
.btn-submit:hover:not(:disabled) { filter: brightness(1.05); }
.btn-submit:disabled { opacity: 0.55; cursor: not-allowed; box-shadow: none; }

.phase-note {
    font-size: 0.8rem;
    color: var(--muted);
}

/* HTML blocks are admin-authored; keep their content readable without fighting it. */
.html-block :where(h1, h2, h3, h4) { color: var(--ink-strong); }
.html-block img { max-width: 100%; height: auto; }
.html-block { overflow-wrap: anywhere; }

.form-errors {
    margin-bottom: 1.5rem;
    padding: 1rem 1.25rem;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: var(--radius);
    color: #991b1b;
}
.form-errors ul { margin: 0.5rem 0 0; padding-left: 1.25rem; }

/* ---------- admin ---------- */

.admin-shell { display: flex; min-height: 100vh; align-items: stretch; }

.admin-sidebar {
    flex: 0 0 15rem;
    background: var(--surface);
    border-right: 1px solid var(--line);
    padding: 1rem 0;
    position: sticky;
    top: 0;
    align-self: flex-start;
    height: 100vh;
    overflow-y: auto;
}

.admin-brand {
    display: block;
    padding: 0 1.25rem 1rem;
    font-weight: 700;
    color: var(--ink-strong);
    text-decoration: none;
    border-bottom: 1px solid var(--line);
}
.admin-brand span { color: var(--primary); font-weight: 500; }

.admin-menu { display: flex; flex-direction: column; padding-top: 0.5rem; }

.admin-menu__group {
    padding: 1rem 1.25rem 0.35rem;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #94a3b8;
}

.admin-menu__item {
    padding: 0.5rem 1.25rem;
    color: var(--ink);
    text-decoration: none;
    font-size: 0.9rem;
    border-left: 3px solid transparent;
}
.admin-menu__item:hover { background: var(--surface-sunken); color: var(--primary); }
.admin-menu__item--sub { padding-left: 1.75rem; font-size: 0.85rem; color: var(--muted); }
.admin-menu__item.active {
    background: var(--primary-soft);
    color: var(--primary);
    border-left-color: var(--primary);
    font-weight: 600;
}

.admin-content { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

.admin-header {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 0.75rem 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}

.admin-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.85rem;
    color: var(--muted);
}

.admin-main { padding: 1.5rem; min-width: 0; }

@media (max-width: 60rem) {
    .admin-shell { display: block; }
    .admin-sidebar { position: static; height: auto; flex: none; width: 100%; border-right: 0; border-bottom: 1px solid var(--line); }
    .admin-menu { flex-direction: row; flex-wrap: wrap; }
    .admin-menu__group { width: 100%; padding-top: 0.5rem; }
}

.admin-page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
}
.admin-page-head h1 { margin: 0; font-size: 1.5rem; color: var(--ink-strong); }
.admin-page-head p { margin: 0.25rem 0 0; }

.admin-search { max-width: 20rem; }

.admin-card {
    max-width: 40rem;
    margin: 3rem auto;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 2rem;
}

.admin-section { margin-bottom: 2.5rem; }
.admin-section > h2 {
    font-size: 1.05rem;
    color: var(--ink-strong);
    margin: 0 0 0.75rem;
}

/* Wide grids scroll inside their own box; the page itself must never scroll sideways. */
.table-scroll {
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
}

.admin-table { border-collapse: collapse; width: 100%; font-size: 0.875rem; }
.admin-table th,
.admin-table td {
    padding: 0.6rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
    white-space: nowrap;
}
.admin-table th {
    background: var(--surface-sunken);
    font-weight: 600;
    color: var(--ink-strong);
    position: sticky;
    top: 0;
}
.admin-table tr:last-child td { border-bottom: 0; }
.admin-table tbody tr:hover { background: var(--surface-sunken); }
.admin-table td.group-col { background: #f8fafc80; }
.admin-table th.group-col { color: var(--primary); }

.small { font-size: 0.8rem; }

.badge {
    display: inline-block;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}
.badge-open { background: #dcfce7; color: #166534; }
.badge-scheduled { background: #fef3c7; color: #92400e; }
.badge-closed { background: #fee2e2; color: #991b1b; }

.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.45rem 0.85rem;
    font: inherit;
    font-size: 0.85rem;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--line-input);
    border-radius: var(--radius);
    cursor: pointer;
    text-decoration: none;
}
.btn:hover { border-color: var(--primary-light); color: var(--primary); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-small { padding: 0.3rem 0.6rem; font-size: 0.8rem; }
.btn-link { border: 0; background: none; color: var(--primary); padding: 0; }

.row-actions { display: flex; gap: 0.35rem; flex-wrap: wrap; }

.pager {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-top: 1rem;
    font-size: 0.85rem;
}

.filter-bar {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
}
.filter-bar .input { max-width: 16rem; font-size: 0.875rem; padding: 0.5rem 0.75rem; }

.login-divider {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin: 1.5rem 0 1rem;
    color: var(--muted);
    font-size: 0.8rem;
}
.login-divider::before,
.login-divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--line);
}

.btn-provider {
    width: 100%;
    justify-content: center;
    margin-bottom: 0.6rem;
    padding: 0.7rem 1rem;
    font-size: 0.9rem;
    font-weight: 600;
}

.checkbox-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
    gap: 0.6rem;
}

.confirm-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
    padding: 0.85rem 1rem;
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-radius: var(--radius);
    color: #92400e;
    font-size: 0.9rem;
}

.form-warnings {
    margin-bottom: 1.25rem;
    padding: 0.85rem 1.1rem;
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-radius: var(--radius);
    color: #92400e;
}
.form-warnings ul { margin: 0; padding-left: 1.25rem; }

.btn-danger { color: #b91c1c; border-color: #fecaca; }
.btn-danger:hover { color: #fff; background: #dc2626; border-color: #dc2626; }

.input.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.85rem; }

/* ---------- file upload & signature ---------- */

.input-file {
    padding: 0.6rem 0.75rem;
    background: var(--surface-sunken);
    cursor: pointer;
}
.input-file::file-selector-button {
    margin-right: 0.75rem;
    padding: 0.4rem 0.9rem;
    font: inherit;
    font-size: 0.85rem;
    color: var(--ink);
    background: var(--surface);
    border: 1px solid var(--line-input);
    border-radius: var(--radius);
    cursor: pointer;
}

.signature { display: flex; flex-direction: column; align-items: flex-start; gap: 0.5rem; }
.signature__pad {
    width: 100%;
    max-width: 100%;
    height: auto;
    aspect-ratio: 3 / 1;
    background: var(--surface);
    border: 2px dashed var(--line-input);
    border-radius: var(--radius);
    touch-action: none;         /* let the pad capture touch drawing instead of scrolling */
    cursor: crosshair;
}

.answer__signature {
    max-width: 20rem;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: #fff;
}

/* ---------- repeatable group add/remove ---------- */

.group-rows > .group-row + .group-row { margin-top: 1rem; }
.group-row__actions { display: flex; justify-content: flex-end; padding-top: 0.25rem; }
.group-row__remove { color: #b91c1c; border-color: #fecaca; }
.group-row__remove:hover { color: #fff; background: #dc2626; border-color: #dc2626; }
.group-add { margin-top: 1rem; }

/* ---------- multi-step wizard ---------- */

.wizard-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--line);
}
.wizard-status { color: var(--muted); font-size: 0.9rem; font-weight: 600; }
.wizard-next { margin-left: auto; }

/* ---------- admin structure editor ---------- */

.structure-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.25rem;
    padding: 1rem;
    background: var(--surface-sunken);
    border: 1px solid var(--line);
    border-radius: var(--radius);
}
.structure-toolbar > div { display: flex; gap: 0.4rem; align-items: center; }

/* screen-reader-only text (accessible names for icon/asterisk controls) */
.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;
}

.signature__row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    width: 100%;
}
.signature__row .field-help { margin: 0; }

/* ---------- payment ---------- */

.pay-panel { text-align: center; padding: 1rem 0 0.5rem; }
.pay-panel h2 { color: var(--ink-strong); margin: 0 0 0.5rem; }
.pay-panel p { color: var(--muted); max-width: 32rem; margin: 0 auto 0.75rem; }
.pay-panel .form-actions { justify-content: center; }

.pay-amount {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--ink-strong) !important;
    margin: 0.5rem 0 1rem !important;
}

.pay-panel--paid h2 { color: #166534; }

.badge-paid { background: #dcfce7; color: #166534; }
.badge-unpaid { background: #fef3c7; color: #92400e; }
.badge-refunded { background: #e0e7ff; color: #3730a3; }

/* A public read-only form: the fields show, nothing can be changed. */
.form-view-only { border: 0; margin: 0; padding: 0; min-width: 0; }

.step-description { margin-top: 0; }
