:root {
    --bg: #f5f7fb;
    --surface: #ffffff;
    --surface-soft: #eef3f8;
    --text: #1f2937;
    --muted: #667085;
    --border: #d8e0ea;
    --primary: #1666c5;
    --primary-hover: #0f55a8;
    --danger: #b42318;
    --danger-bg: #fff1f0;
    --success: #147a48;
    --success-bg: #e9f7ef;
    --shadow: 0 14px 34px rgba(17, 24, 39, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    min-height: 100vh;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Arial, Helvetica, sans-serif;
    line-height: 1.5;
}

a {
    color: inherit;
}

h1,
h2,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 0;
    font-size: clamp(28px, 4vw, 40px);
    line-height: 1.15;
}

h2 {
    margin-bottom: 6px;
    font-size: 20px;
}

input,
textarea,
button {
    font: inherit;
}

input,
textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 14px;
    color: var(--text);
    background: #ffffff;
}

textarea {
    resize: vertical;
}

input:focus,
textarea:focus {
    border-color: var(--primary);
    outline: 3px solid rgba(22, 102, 197, 0.14);
}

.auth-page {
    display: grid;
    place-items: center;
    padding: 24px;
}

.auth-shell,
.container {
    width: min(1120px, calc(100% - 32px));
    margin: 0 auto;
}

.container {
    padding: 28px 0 48px;
}

.container.narrow {
    width: min(720px, calc(100% - 32px));
}

.auth-card,
.form-panel,
.link-panel,
.message-panel,
.empty-state,
.client-card {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    box-shadow: var(--shadow);
}

.auth-card {
    width: min(440px, 100%);
    margin: 0 auto;
    padding: 32px;
}

.auth-card__link {
    margin: 18px 0 0;
    text-align: center;
}

.auth-card__link a {
    color: var(--primary);
    font-weight: 700;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 24px max(16px, calc((100vw - 1120px) / 2)) 18px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}

.page-kicker {
    margin-bottom: 8px;
    color: var(--primary);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: uppercase;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: flex-end;
    margin-bottom: 22px;
}

.token-generator {
    display: grid;
    width: min(620px, 100%);
    gap: 12px;
    justify-items: end;
}

.inline-token {
    display: grid;
    width: 100%;
    gap: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px;
    background: var(--surface);
    box-shadow: 0 8px 22px rgba(17, 24, 39, 0.06);
}

.inline-token[hidden] {
    display: none !important;
}

.inline-token label {
    display: grid;
    gap: 7px;
    width: 100%;
    font-weight: 700;
}

.inline-token label span:first-child {
    font-size: 13px;
    color: var(--muted);
}

.inline-token__actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
}

.client-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 18px;
}

.client-card {
    display: flex;
    flex-direction: column;
    gap: 18px;
    padding: 22px;
}

.client-card__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
}

.status-stack {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
}

.client-card__header p,
.muted {
    color: var(--muted);
}

.status {
    flex: 0 0 auto;
    border-radius: 999px;
    padding: 5px 10px;
    font-size: 13px;
    font-weight: 700;
    white-space: nowrap;
}

.status-ready {
    color: var(--success);
    background: var(--success-bg);
}

.status-pending {
    color: #7a4a00;
    background: #fff5df;
}

.error-text {
    color: var(--danger);
}

.details-list {
    display: grid;
    gap: 12px;
    margin: 0;
}

.details-list div {
    display: grid;
    gap: 3px;
}

.details-list dt {
    color: var(--muted);
    font-size: 13px;
}

.details-list dd {
    margin: 0;
    overflow-wrap: anywhere;
}

.empty-state,
.form-panel,
.link-panel,
.message-panel {
    padding: 28px;
}

.empty-state {
    min-height: 180px;
    display: grid;
    place-items: center;
    text-align: center;
}

.empty-state h2,
.message-panel h1 {
    margin-bottom: 0;
}

.public-form {
    padding-top: 48px;
}

.form-stack {
    display: grid;
    gap: 16px;
    margin-top: 24px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.form-stack label,
.link-panel label {
    display: grid;
    gap: 7px;
    font-weight: 700;
}

.form-stack label span {
    font-size: 14px;
}

.copy-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 12px;
    margin-top: 8px;
}

.client-actions {
    display: grid;
    gap: 10px;
    margin-top: auto;
}

.client-actions form {
    margin: 0;
}

.client-actions .button {
    width: 100%;
}

.button {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 10px 16px;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}

.button-primary {
    color: #ffffff;
    background: var(--primary);
}

.button-primary:hover {
    background: var(--primary-hover);
}

.button-secondary {
    color: var(--text);
    border-color: var(--border);
    background: var(--surface);
}

.button-secondary:hover {
    background: var(--surface-soft);
}

.button-danger {
    color: #ffffff;
    background: var(--danger);
}

.button-danger:hover {
    background: #8f1d14;
}

.alert {
    border-radius: 8px;
    padding: 12px 14px;
    margin-top: 18px;
}

.alert p {
    margin: 0;
}

.alert p + p {
    margin-top: 6px;
}

.alert-error {
    color: var(--danger);
    border: 1px solid rgba(180, 35, 24, 0.2);
    background: var(--danger-bg);
}

.alert-success {
    color: var(--success);
    border: 1px solid rgba(20, 122, 72, 0.2);
    background: var(--success-bg);
}

.teen-test {
    width: min(980px, calc(100% - 32px));
}

.teen-test__panel {
    overflow: visible;
}

.teen-test-header,
.teen-step-heading,
.teen-priority-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
}

.teen-step-counter,
.priority-counter {
    flex: 0 0 auto;
    min-width: 150px;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    color: var(--muted);
    background: var(--surface-soft);
    font-size: 13px;
    text-align: right;
}

.teen-step-counter strong,
.priority-counter strong {
    display: block;
    color: var(--text);
    font-size: 16px;
}

.teen-progress {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 8px;
    margin: 24px 0;
    padding: 0;
    list-style: none;
}

.teen-progress li {
    min-height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 7px 8px;
    color: var(--muted);
    background: var(--surface-soft);
    font-size: 13px;
    font-weight: 700;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.16s ease, background-color 0.16s ease, color 0.16s ease, box-shadow 0.16s ease;
}

.teen-progress li.is-active {
    color: #ffffff;
    border-color: var(--primary);
    background: var(--primary);
}

.teen-progress li.is-complete:not(.is-active) {
    color: var(--success);
    border-color: rgba(20, 122, 72, 0.28);
    background: var(--success-bg);
}

.teen-progress li.is-disabled:not(.is-active) {
    cursor: not-allowed;
    opacity: 0.58;
}

.teen-progress li:focus-visible {
    outline: 3px solid rgba(22, 102, 197, 0.14);
    outline-offset: 2px;
}

.teen-step {
    display: grid;
    gap: 18px;
}

.teen-test-form.is-enhanced .teen-step[hidden] {
    display: none;
}

.teen-test-form {
    padding-bottom: 102px;
}

.question-list {
    display: grid;
    gap: 14px;
}

.question-block {
    min-width: 0;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    margin: 0;
    background: #ffffff;
    transition: border-color 0.16s ease, box-shadow 0.16s ease, background-color 0.16s ease;
}

.question-block.is-invalid,
.priority-final.is-invalid,
.teen-step.is-invalid {
    border-color: var(--danger);
    background: #fffafa;
    box-shadow: 0 0 0 3px rgba(180, 35, 24, 0.12);
}

.teen-step.is-invalid {
    border: 1px solid var(--danger);
    border-radius: 8px;
    padding: 14px;
}

.teen-test label.is-invalid {
    border: 1px solid var(--danger);
    border-radius: 8px;
    padding: 10px;
    background: #fffafa;
    box-shadow: 0 0 0 3px rgba(180, 35, 24, 0.12);
}

.question-block legend {
    display: block;
    width: 100%;
    margin-bottom: 12px;
    padding: 0;
    font-weight: 700;
}

.question-number {
    display: inline-flex;
    min-width: 28px;
    height: 28px;
    align-items: center;
    justify-content: center;
    margin-right: 8px;
    border-radius: 50%;
    color: #ffffff;
    background: var(--primary);
    font-size: 13px;
}

.choice-list {
    display: grid;
    gap: 10px;
}

.choice-list-inline {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.choice-option {
    position: relative;
    display: flex !important;
    min-width: 0;
    align-items: flex-start;
    gap: 10px !important;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 42px 12px 12px;
    background: var(--surface);
    font-weight: 600 !important;
    cursor: pointer;
    transition: border-color 0.16s ease, background-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

.choice-option:hover {
    border-color: rgba(20, 122, 72, 0.35);
    background: #fbfffc;
}

.choice-option input[type="radio"] {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: 0;
    opacity: 0;
    pointer-events: none;
}

.choice-option.is-selected {
    border-color: rgba(20, 122, 72, 0.48);
    background: var(--success-bg);
    box-shadow: 0 0 0 3px rgba(20, 122, 72, 0.12);
}

.choice-option.is-selected::after {
    content: "✓";
    position: absolute;
    top: 10px;
    right: 10px;
    display: inline-flex;
    width: 22px;
    height: 22px;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: #ffffff;
    background: var(--success);
    font-size: 13px;
    font-weight: 800;
}

.choice-option input[type="radio"]:focus-visible + span {
    outline: 3px solid rgba(20, 122, 72, 0.16);
    outline-offset: 3px;
}

.choice-label {
    color: var(--primary);
    font-weight: 800;
}

.scale-control {
    width: fit-content;
    max-width: 100%;
}

.scale-labels {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    margin: -2px 0 10px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    width: 100%;
}

.rating-scale {
    display: flex;
    flex-wrap: wrap;
    gap: 10px 12px;
    align-items: center;
    width: fit-content;
    max-width: 100%;
}

.rating-scale label {
    position: relative;
    display: block !important;
    flex: 0 0 44px;
    font-weight: 800 !important;
}

.rating-scale-ten label {
    flex-basis: 38px;
}

.rating-scale input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.rating-scale span {
    display: flex;
    min-height: 38px;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text);
    background: var(--surface);
    box-shadow: 0 5px 14px rgba(31, 41, 55, 0.04);
    transition: transform 0.14s ease, border-color 0.14s ease, background-color 0.14s ease, box-shadow 0.14s ease;
}

.rating-scale label:hover span {
    border-color: rgba(20, 122, 72, 0.42);
    background: #fbfffc;
    transform: translateY(-1px);
}

.rating-scale input:checked + span {
    color: #0f5132;
    border-color: rgba(20, 122, 72, 0.48);
    background: var(--success-bg);
    box-shadow: 0 8px 18px rgba(20, 122, 72, 0.14);
}

.rating-scale input:focus-visible + span {
    outline: 3px solid rgba(20, 122, 72, 0.16);
}

.priority-flow {
    display: grid;
    gap: 16px;
}

.priority-final {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 24px;
    background: #ffffff;
}

.priority-final[hidden] {
    display: none;
}

.priority-final h3 {
    margin: 0 0 6px;
    font-size: 18px;
    line-height: 1.3;
}

.priority-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 12px;
}

.priority-card {
    position: relative;
    display: grid !important;
    grid-template-columns: auto 1fr;
    gap: 10px !important;
    align-items: flex-start;
    min-height: 96px;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px;
    background: var(--surface);
    cursor: pointer;
    transition: border-color 0.16s ease, background-color 0.16s ease, box-shadow 0.16s ease, opacity 0.16s ease;
}

.priority-card input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.priority-card__number {
    display: inline-flex;
    width: 30px;
    height: 30px;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: var(--primary);
    background: var(--surface-soft);
    font-size: 13px;
    font-weight: 800;
}

.priority-card__text {
    display: block;
    min-width: 0;
    color: var(--text);
    font-size: 14px;
    font-weight: 700;
    line-height: 1.4;
}

.priority-card__body {
    display: grid;
    min-width: 0;
    gap: 8px;
}

.priority-card__badge {
    width: fit-content;
    border-radius: 999px;
    padding: 4px 8px;
    color: var(--muted);
    background: var(--surface-soft);
    font-size: 12px;
    font-weight: 800;
}

.priority-card__badge[data-score-level="top"] {
    color: #0f5132;
    background: #e8f6ef;
}

.priority-card__badge[data-score-level="high"] {
    color: #155e75;
    background: #e9f7fb;
}

.priority-card__badge[data-score-level="mid"] {
    color: #7a4b00;
    background: #fff5dc;
}

.priority-card__badge[data-score-level="low"] {
    color: #7f1d1d;
    background: #fff1f1;
}

.priority-card.is-selected {
    border-color: rgba(20, 122, 72, 0.48);
    background: var(--success-bg);
    box-shadow: 0 0 0 3px rgba(20, 122, 72, 0.12);
}

.priority-card.is-selected .priority-card__number {
    color: #ffffff;
    background: var(--success);
}

.priority-card.is-disabled {
    cursor: not-allowed;
    opacity: 0.58;
}

.priority-card.is-disabled .priority-card__badge {
    opacity: 0.75;
}

.teen-nav {
    position: fixed;
    z-index: 40;
    left: 50%;
    bottom: 16px;
    width: min(980px, calc(100% - 32px));
    transform: translateX(-50%);
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 12px 28px rgba(17, 24, 39, 0.14);
    backdrop-filter: blur(8px);
}

.teen-nav .button[hidden],
.button[hidden] {
    display: none !important;
}

@media (max-width: 680px) {
    .topbar {
        align-items: stretch;
        flex-direction: column;
    }

    .toolbar {
        justify-content: stretch;
    }

    .toolbar form,
    .toolbar .button,
    .topbar .button,
    .copy-row .button {
        width: 100%;
    }

    .copy-row {
        grid-template-columns: 1fr;
    }

    .client-card__header {
        flex-direction: column;
    }

    .status-stack {
        align-items: flex-start;
    }

    .auth-card,
    .form-panel,
    .link-panel,
    .message-panel,
    .empty-state,
    .client-card {
        padding: 20px;
    }

    .form-grid,
    .choice-list-inline {
        grid-template-columns: 1fr;
    }

    .teen-progress {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .rating-scale {
        gap: 9px;
    }

    .rating-scale label,
    .rating-scale-ten label {
        flex-basis: 42px;
    }

    .scale-labels {
        font-size: 11px;
    }

    .teen-nav {
        right: 12px;
        left: 12px;
        bottom: 10px;
        width: auto;
        transform: none;
        flex-direction: row;
    }

    .teen-nav .button {
        flex: 1 1 0;
        width: auto;
        padding-right: 10px;
        padding-left: 10px;
    }

    .teen-test-header,
    .teen-step-heading,
    .teen-priority-head {
        flex-direction: column;
    }

    .teen-step-counter,
    .priority-counter {
        width: 100%;
        text-align: left;
    }

    .priority-grid {
        grid-template-columns: 1fr;
    }

    .token-generator {
        justify-items: stretch;
    }

    .inline-token__actions {
        align-items: stretch;
        flex-direction: column;
    }

    .inline-token__actions .button {
        width: 100%;
    }
}
