:root {
    --bg: #f8fafc;
    --card: #ffffff;
    --ink: #0f172a;
    --ink-soft: #475569;
    --ink-muted: #94a3b8;
    --border: #e2e8f0;
    --brand: #4f46e5;
    --brand-dark: #4338ca;
    --brand-soft: #eef2ff;
    --danger: #dc2626;
    --radius: 12px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .04);
    --shadow-md: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 14px rgba(15, 23, 42, .05);
    --shadow-brand: 0 1px 2px rgba(79, 70, 229, .25), 0 6px 18px rgba(79, 70, 229, .18);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Inter, Roboto, system-ui, sans-serif;
    background: var(--bg);
    color: var(--ink);
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); }

.tqforms-page {
    max-width: 760px;
    margin: 2.5rem auto;
    padding: 0 1rem 4rem;
}

.tqforms-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

/* Form header */
.tqforms-header { margin: 0 0 1rem; }
.tqforms-hero {
    display: block;
    width: 100%;
    height: auto;
    max-height: 360px;
    object-fit: cover;
    border-radius: var(--radius);
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow-md);
}
.tqforms-title {
    font-size: 1.85rem;
    font-weight: 700;
    margin: 0 0 .4rem;
    letter-spacing: -0.02em;
}
.tqforms-description {
    color: var(--ink-soft);
    margin: 0;
    font-size: 1rem;
}

/* Page header (after pageBreak) */
.tqforms-page-header { margin: .25rem 0 .25rem; }
.tqforms-page-header h2 {
    font-size: 1.3rem;
    margin: 0 0 .4rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

/* Section — visually distinct from regular fields */
.tqforms-section {
    background: var(--brand-soft);
    border-left: 4px solid var(--brand);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
}
.tqforms-section h2 {
    font-size: 1.05rem;
    margin: 0 0 .35rem;
    font-weight: 600;
    color: var(--brand-dark);
}
.tqforms-section .tqforms-help {
    color: var(--ink-soft);
    margin: 0;
}

/* Field card */
.tqforms-field {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    box-shadow: var(--shadow-sm);
}

.tqforms-label {
    font-weight: 600;
    font-size: .95rem;
    margin-bottom: .35rem;
}
.tqforms-required { color: var(--danger); }

.tqforms-error {
    color: var(--danger);
    font-size: .875rem;
    margin-top: .5rem;
    font-weight: 500;
}
.tqforms-field-invalid {
    border-color: var(--danger);
    box-shadow: 0 0 0 3px rgba(220, 38, 38, .08);
}

.tqforms-submit-errors {
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-left: 4px solid var(--danger);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    color: #7f1d1d;
}
.tqforms-submit-errors strong { color: var(--danger); }
.tqforms-submit-errors ul {
    margin: .5rem 0 0;
    padding-left: 1.25rem;
}
.tqforms-submit-errors li { margin: .2rem 0; }

.tqforms-success {
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
    border-left: 4px solid #059669;
    border-radius: var(--radius);
    padding: 2rem 1.5rem;
    text-align: center;
}
.tqforms-success h1 { color: #065f46; margin: 0 0 .5rem; }
.tqforms-success p { margin: 0; color: #047857; }

.tqforms-help {
    color: var(--ink-soft);
    font-size: .875rem;
    margin-bottom: .75rem;
}
.tqforms-help > div:empty { min-height: .5em; }

/* Text-like inputs (the :not() excludes the inline "Inne:" text input, which is a flex child) */
.tqforms-field input[type=text]:not(.tqforms-other-input),
.tqforms-field input[type=email],
.tqforms-field input[type=tel],
.tqforms-field input[type=url],
.tqforms-field input[type=date],
.tqforms-field input[type=number],
.tqforms-field textarea,
.tqforms-field select {
    width: 100%;
    padding: .7rem .9rem;
    font-size: 1rem;
    font-family: inherit;
    color: var(--ink);
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    transition: border-color .12s, box-shadow .12s;
}

.tqforms-field input:focus,
.tqforms-field textarea:focus,
.tqforms-field select:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, .15);
}

.tqforms-field textarea {
    resize: vertical;
    min-height: 5.5rem;
}

.tqforms-field select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%23475569'%3E%3Cpath d='M5.23 7.21a.75.75 0 0 1 1.06.02L10 11.17l3.71-3.94a.75.75 0 1 1 1.08 1.04l-4.25 4.5a.75.75 0 0 1-1.08 0l-4.25-4.5a.75.75 0 0 1 .02-1.06z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right .75rem center;
    background-size: 1.25rem;
    padding-right: 2.5rem;
}

/* Choice pills (radio + checkbox) */
.tqforms-choices {
    display: flex;
    flex-direction: column;
    gap: .5rem;
}

.tqforms-choice {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .75rem 1rem;
    background: #fff;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    user-select: none;
    transition: border-color .12s, background .12s, box-shadow .12s;
}
.tqforms-choice:hover {
    border-color: var(--brand);
}
.tqforms-choice:has(input:checked) {
    border-color: var(--brand);
    background: var(--brand-soft);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, .1);
}
.tqforms-choice input[type=radio],
.tqforms-choice input[type=checkbox] {
    width: 18px;
    height: 18px;
    margin: 0;
    flex: 0 0 auto;
    accent-color: var(--brand);
    cursor: pointer;
}
.tqforms-choice span { flex: 1; }

/* "Other" choice with inline free-text input */
.tqforms-choice-other span { flex: 0 0 auto; color: var(--ink-soft); }
.tqforms-other-input {
    flex: 1;
    min-width: 0;
    padding: .35rem .6rem;
    font: inherit;
    font-size: .95rem;
    color: var(--ink);
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 6px;
    transition: border-color .12s, box-shadow .12s;
}
.tqforms-other-input:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, .15);
}

/* Scale — pill-style numeric buttons */
.tqforms-scale {
    display: flex;
    align-items: center;
    gap: .75rem;
    flex-wrap: wrap;
}
.tqforms-scale-label {
    color: var(--ink-soft);
    font-size: .875rem;
}
.tqforms-scale-options {
    display: flex;
    gap: .5rem;
    flex-wrap: wrap;
}
.tqforms-scale-option {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.5rem;
    height: 2.5rem;
    padding: 0 .75rem;
    background: #fff;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
    transition: background .12s, color .12s, border-color .12s;
}
.tqforms-scale-option input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}
.tqforms-scale-option:hover { border-color: var(--brand); }
.tqforms-scale-option:has(input:checked) {
    background: var(--brand);
    border-color: var(--brand);
    color: #fff;
}

/* Boolean (single checkbox) */
.tqforms-field-boolean {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    box-shadow: var(--shadow-sm);
}
.tqforms-boolean {
    display: flex;
    align-items: center;
    gap: .75rem;
    cursor: pointer;
    font-weight: 500;
}
.tqforms-boolean input {
    width: 20px;
    height: 20px;
    accent-color: var(--brand);
    cursor: pointer;
}

/* Repeat groups — collapsible per-instance cards + optional add/remove controls */
.tqforms-repeat-group {
    display: flex;
    flex-direction: column;
    gap: .75rem;
}
.tqforms-repeat-instance {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fafafe;
    overflow: hidden;
}
.tqforms-repeat-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    padding: .75rem 1rem;
    cursor: pointer;
    user-select: none;
    list-style: none;
    font-weight: 600;
    color: var(--brand-dark);
}
.tqforms-repeat-summary::-webkit-details-marker { display: none; }
.tqforms-repeat-summary::before {
    content: '';
    width: 10px; height: 10px; flex: 0 0 auto;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(-45deg);
    transition: transform .15s;
    margin-right: .25rem;
}
details[open] > .tqforms-repeat-summary::before { transform: rotate(45deg); }
.tqforms-repeat-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.tqforms-repeat-body {
    padding: 0 1rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    border-top: 1px solid var(--border);
    padding-top: 1rem;
    background: #fff;
}
.tqforms-repeat-remove {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    color: var(--ink-muted);
    cursor: pointer;
    transition: color .12s, background .12s, border-color .12s;
}
.tqforms-repeat-remove:hover {
    color: var(--danger);
    background: #fef2f2;
    border-color: #fecaca;
}
.tqforms-repeat-add {
    align-self: flex-start;
    padding: .55rem 1rem;
    font: inherit;
    font-weight: 600;
    font-size: .95rem;
    color: var(--brand);
    background: #fff;
    border: 1.5px dashed var(--brand);
    border-radius: 10px;
    cursor: pointer;
    transition: background .12s, color .12s;
}
.tqforms-repeat-add:hover {
    background: var(--brand-soft);
}
.tqforms-repeat-empty {
    color: var(--ink-muted);
    font-style: italic;
    margin: 0;
}

/* Collapsed instance with invalid descendants — flag it so the user knows
   where to look. Field-level errors are hidden inside a closed <details>,
   so the summary itself needs to carry the signal. */
.tqforms-repeat-instance:not([open]):has(.tqforms-field-invalid) {
    border-color: var(--danger);
    background: #fef2f2;
}
.tqforms-repeat-instance:not([open]):has(.tqforms-field-invalid) > .tqforms-repeat-summary {
    color: var(--danger);
}

/* Nav bar */
.tqforms-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-top: 1rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border);
}
.tqforms-page-indicator {
    color: var(--ink-muted);
    font-size: .875rem;
    font-variant-numeric: tabular-nums;
}

.tqforms-nav button {
    padding: .75rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    font-family: inherit;
    border-radius: 10px;
    cursor: pointer;
    border: 1.5px solid transparent;
    transition: background .12s, border-color .12s, box-shadow .12s, transform .06s;
}
.tqforms-nav button:active { transform: translateY(1px); }

.tqforms-next {
    background: var(--brand);
    color: #fff;
    box-shadow: var(--shadow-brand);
}
.tqforms-next:hover { background: var(--brand-dark); }

.tqforms-prev {
    background: #fff;
    color: var(--ink);
    border-color: var(--border);
}
.tqforms-prev:hover {
    border-color: var(--ink-muted);
    background: #f8fafc;
}

/* Language switcher (dropdown) */
.lang-switcher {
    position: relative;
    display: flex;
    justify-content: flex-end;
    margin-bottom: 1.25rem;
}
.lang-switcher__btn {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    padding: .5rem .85rem;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 999px;
    font: inherit;
    font-size: .9rem;
    color: var(--ink);
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: border-color .12s, background .12s;
}
.lang-switcher__btn:hover { border-color: var(--brand); }
.lang-switcher__btn[aria-expanded="true"] { border-color: var(--brand); background: var(--brand-soft); }
.lang-switcher__flag {
    display: inline-block;
    width: 22px;
    height: 15px;
    border-radius: 3px;
    object-fit: cover;
    box-shadow: 0 0 0 1px rgba(15, 23, 42, .1), 0 1px 2px rgba(15, 23, 42, .08);
    flex: 0 0 auto;
}
.lang-switcher__chevron {
    color: var(--ink-muted);
    transition: transform .15s;
}
.lang-switcher__btn[aria-expanded="true"] .lang-switcher__chevron { transform: rotate(180deg); }

.lang-switcher__menu {
    position: absolute;
    top: calc(100% + .35rem);
    right: 0;
    min-width: 160px;
    margin: 0;
    padding: .35rem;
    list-style: none;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: var(--shadow-md);
    z-index: 10;
}
.lang-switcher__menu li { margin: 0; }
.lang-switcher__menu a {
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .5rem .75rem;
    border-radius: 7px;
    color: var(--ink);
    text-decoration: none;
    font-size: .9rem;
    transition: background .1s;
}
.lang-switcher__menu a:hover { background: var(--brand-soft); }
.lang-switcher__menu a[aria-selected="true"] {
    background: var(--brand-soft);
    color: var(--brand-dark);
    font-weight: 600;
}

/* Unknown type fallback */
.tqforms-unknown {
    color: var(--danger);
    padding: .5rem;
    border: 1px dashed var(--danger);
    border-radius: 6px;
}

/* Small-screen tweaks */
@media (max-width: 560px) {
    #tqforms-root { margin: 1rem auto; padding: 0 .75rem 3rem; }
    .tqforms-title { font-size: 1.5rem; }
    .tqforms-field, .tqforms-section, .tqforms-field-boolean { padding: .85rem 1rem; }
    .tqforms-nav button { padding: .65rem 1.1rem; }
}
