* {
    box-sizing: border-box;
}

body {
    font-family: system-ui, -apple-system, sans-serif;
    margin: 0;
    padding: 1rem;
    background: #e5e7eb;
    color: #222;
}

/* Задний фон с GIF только на странице 404 */
body.page-404 {
    min-height: 100vh;
    background: #e5e7eb url(/static/bg.gif) center center fixed no-repeat;
    background-size: cover;
    position: relative;
}

body.page-404::before {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(229, 231, 235, 0);
    pointer-events: none;
    z-index: 0;
}

body.page-404 > * {
    position: relative;
    z-index: 1;
}

.container {
    max-width: 720px;
    margin: 0 auto;
}

.card {
    background: #fff;
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 1rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.card h1, .card h2 {
    margin-top: 0;
}

.error {
    color: #c00;
    margin: 0.5rem 0;
}

.success {
    color: #166534;
    margin: 0.5rem 0;
}

.form label {
    display: block;
    margin: 0.75rem 0;
}

.form input[type="text"],
.form input[type="password"],
.form textarea {
    width: 100%;
    padding: 0.5rem;
    margin-top: 0.25rem;
    border: 1px solid #ccc;
    border-radius: 4px;
}

.form textarea {
    min-height: 80px;
    resize: vertical;
}

.form button:not(.btn-remove-option),
button[type="submit"]:not(.nav-btn):not(.btn-delete):not(.filter-btn) {
    padding: 0.5rem 1rem;
    background: #2563eb;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    margin-top: 0.5rem;
}

.form button:not(.btn-remove-option):hover,
button[type="submit"]:not(.nav-btn):not(.btn-delete):not(.filter-btn):hover {
    background: #1d4ed8;
}

.auth-card {
    max-width: 360px;
    margin: 2rem auto;
}

.not-found-card {
    max-width: 420px;
    margin: 2rem auto;
    text-align: center;
    animation: not-found-slide-up 0.5s ease-out forwards;
}

.not-found-card h1 {
    font-size: 3rem;
    color: #6b7280;
    margin-bottom: 0.25rem;
}

@keyframes not-found-slide-up {
    from {
        opacity: 0;
        transform: translateY(2rem);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}


.not-found-text {
    font-size: 1.25rem;
    font-weight: 500;
    color: #374151;
}

.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1rem;
}

.admin-header nav {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.nav-btn-wrap {
    display: inline-block;
    margin: 0;
    padding: 0;
    border: none;
    background: none;
}

.nav-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-sizing: border-box;
    height: 2.5rem;
    padding: 0 1rem;
    font-family: inherit;
    font-size: 1rem;
    line-height: 1.5;
    color: #2d3748;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 20px;
    text-decoration: none;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    white-space: nowrap;
}

a.nav-btn:hover,
button.nav-btn:hover {
    background: #f9fafb;
    color: #2d3748;
    text-decoration: none;
}

.form-inline {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.form-inline input {
    padding: 0.5rem;
    border: 1px solid #ccc;
    border-radius: 4px;
}

.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -0.5rem;
    padding: 0 0.5rem;
}

.table {
    width: 100%;
    border-collapse: collapse;
    min-width: 320px;
}

.table th,
.table td {
    padding: 0.5rem;
    text-align: left;
    border-bottom: 1px solid #eee;
}

.table th {
    font-weight: 600;
}

.table th:last-child,
.table td:last-child {
    padding-left: 1.5rem;
}

.table form {
    display: inline;
}

.table form button {
    padding: 0.35rem 0.75rem;
    font-size: 0.875rem;
    min-width: 5.5rem;
    text-align: center;
    background: #dc2626;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.table form button:hover {
    background: #b91c1c;
}

.btn-edit {
    display: inline-block;
    padding: 0.35rem 0.75rem;
    font-size: 0.875rem;
    min-width: 5.5rem;
    text-align: center;
    box-sizing: border-box;
    background: #2563eb;
    color: #fff;
    border: none;
    border-radius: 4px;
    text-decoration: none;
    cursor: pointer;
}

/* Внутри блока вопроса отступы между кнопками управляются через flex-gap */
.admin-question-block .question-row .btn-edit {
    margin-right: 0;
}

.btn-edit:hover {
    background: #1d4ed8;
    color: #fff;
}

.test-url-cell {
    vertical-align: middle;
    white-space: nowrap;
}

.test-url-cell a {
    white-space: nowrap;
    display: inline-block;
    margin-right: 0.5rem;
    vertical-align: middle;
    max-width: 10ch;
    overflow: hidden;
    text-overflow: ellipsis;
}

.test-url-cell .btn-copy {
    vertical-align: middle;
}

.btn-copy {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    background: #64748b;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    white-space: nowrap;
}

.btn-copy:hover {
    background: #475569;
}

/* Колонка «Действия» в таблице тестов */
.table th:last-child {
    text-align: center;
}

.actions-cell {
    vertical-align: middle;
    text-align: center;
}

.actions-buttons {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    width: 8rem;
    margin-left: auto;
    margin-right: auto;
}

.actions-buttons .btn-edit {
    display: block;
    width: 100%;
    margin-right: 0;
    text-align: center;
    box-sizing: border-box;
}

.actions-buttons form {
    margin: 0;
}

.actions-buttons form .btn-delete {
    display: block;
    width: 100%;
    box-sizing: border-box;
}

.actions-buttons .btn-detail {
    display: block;
    width: 100%;
    margin-right: 0;
    text-align: center;
    box-sizing: border-box;
}

/* В колонке действий кнопки одного размера */
.actions-buttons .btn-detail,
.actions-buttons form .btn-delete {
    padding: 0.35rem 0.5rem;
    font-size: 0.875rem;
}

@media (max-width: 640px) {
    .admin-header {
        flex-direction: column;
        text-align: center;
    }
    .admin-header h1 {
        width: 100%;
        text-align: center;
        margin: 0 0 0.25rem 0;
    }
    .admin-header nav {
        justify-content: center;
    }
    body {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }
    .card {
        padding: 1rem;
    }
    .table-responsive {
        margin-left: -0.5rem;
        margin-right: -0.5rem;
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }
    .actions-buttons {
        width: 7rem;
        min-width: 6rem;
    }
    .actions-buttons .btn-edit,
    .actions-buttons form .btn-delete {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
        font-size: 0.8125rem;
    }
    .table th:last-child,
    .table td:last-child {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }
}

.actions-cell .inline-form {
    display: inline;
    margin-left: 0.5rem;
}

.actions-cell .inline-form button {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    background: #dc2626;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.actions-cell .inline-form button:hover {
    background: #b91c1c;
}

.btn-delete {
    padding: 0.35rem 0.75rem;
    background: #dc2626;
    color: #fff;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.875rem;
}

.btn-delete:hover {
    background: #b91c1c;
}

/* Иконки вместо текста на кнопках редактирования/удаления вопросов */
.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.8rem;
    height: 1.8rem;
    padding: 0;
    min-width: 1.8rem;
    box-sizing: border-box;
    border-radius: 4px;
}

.btn-icon img {
    width: 1rem;
    height: 1rem;
    display: block;
}

/* Кнопка «Подробнее» на странице результатов — размер как у «Удалить», цвет как у «Создать» */
.btn-detail {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    color: #fff;
    background: #2563eb;
    border: none;
    border-radius: 4px;
    text-decoration: none;
    cursor: pointer;
}

.btn-detail:hover {
    background: #1d4ed8;
    color: #fff;
    text-decoration: none;
}

/* iOS-style toggle (ползунок) */
.toggle-form {
    display: inline-block;
}

.ios-toggle {
    cursor: pointer;
    display: inline-block;
    user-select: none;
}

.ios-toggle-track {
    display: inline-flex;
    align-items: center;
    width: 50px;
    height: 28px;
    padding: 2px;
    background: #cbd5e1;
    border-radius: 14px;
    transition: background 0.2s ease;
}

.ios-toggle-track.on {
    background: #22c55e;
}

.ios-toggle-thumb {
    width: 24px;
    height: 24px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
    transition: transform 0.2s ease;
}

.ios-toggle-track.on .ios-toggle-thumb {
    transform: translateX(22px);
}

.filters {
    margin-bottom: 1rem;
}

/* Фильтр: поля и кнопка в одну линию */
.form-filters {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
}

.form-filters .filter-input {
    width: 10rem;
    max-width: 100%;
    height: 2.25rem;
    padding: 0 0.6rem;
    box-sizing: border-box;
    font-size: 1rem;
    color: #000;
    background: #e9e9eb;
    border: none;
    border-radius: 20px;
    outline: none;
}

.form-filters .filter-input::placeholder {
    color: #8e8e93;
}

.form-filters .filter-input:focus {
    background: #e0e0e2;
}

.form-filters .filter-btn {
    width: auto;
    height: 2.25rem;
    padding: 0 1rem;
    margin: 0;
    box-sizing: border-box;
    font-size: 1rem;
    font-family: inherit;
    line-height: 1;
    color: #2d3748;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 20px;
    cursor: pointer;
}

.form-filters .filter-btn:hover {
    background: #f9fafb;
}

.question {
    margin: 1.5rem 0;
    padding-bottom: 1rem;
    border-bottom: 1px solid #eee;
}

.question-progress {
    margin: 0 0 1rem;
    font-size: 0.95rem;
    color: #64748b;
}

.questions-steps {
    min-height: 120px;
}

.question-step {
    display: none;
}

.question-step.active {
    display: block;
}

.test-step-nav {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    margin-top: 1.25rem;
    flex-wrap: wrap;
}

.question-unanswered {
    padding: 0.75rem;
    margin-left: -0.75rem;
    margin-right: -0.75rem;
    border-radius: 6px;
    background: #fef2f2;
    border-left: 3px solid #dc2626;
}

.question-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0.5rem 0;
}

.question-text {
    font-weight: 500;
    margin-bottom: 0;
    flex: 1;
}

.question-actions {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.admin-question-block {
    padding: 0.75rem 0.75rem;
    margin: 0.25rem -0.25rem;
    border-radius: 6px;
    border: 1px solid transparent;
    transition: background-color 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.admin-question-block.dragging {
    opacity: 0.92;
    transition: none;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.btn-drag-question {
    cursor: grab;
    background: #2563eb;
    border: none;
    color: #fff;
}

.admin-question-block-placeholder {
    border-radius: 6px;
    border: 1px dashed #d1d5db;
}

.question-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.question-progress-bar {
    flex: 1;
    height: 4px;
    background: #e5e7eb;
    border-radius: 2px;
    overflow: hidden;
}

.question-progress-fill {
    height: 100%;
    background: #4f46e5;
    border-radius: 2px;
    transition: width 0.2s ease;
}

.question-num {
    font-size: 0.8125rem;
    color: #6b7280;
    white-space: nowrap;
}

.admin-question-block:hover {
    background: #f9fafb;
    border-color: #e5e7eb;
}

.admin-question-block.admin-question-selected {
    background: #eef2ff;
    border-color: #4f46e5;
    box-shadow: 0 0 0 1px #4f46e5 inset;
}

/* Контейнер формы вопроса */
.add-question-section {
    margin-top: 0.75rem;
}

/* Подсветка блока «Добавить вопрос», как у выбранного вопроса */
#addQuestionFormPlaceholder.add-question-active {
    margin-top: 0.5rem;
    padding: 0.75rem 0.75rem;
    border-radius: 6px;
    border: 1px solid #4f46e5;
    background: #eef2ff;
    box-shadow: 0 0 0 1px #4f46e5 inset;
}

.btn-add-question-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.5rem 0.75rem;
    font-size: 0.9375rem;
    color: #4f46e5;
    background: transparent;
    border: 1px dashed #a5b4fc;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.btn-add-question-toggle:hover {
    background: #eef2ff;
    border-color: #4f46e5;
}

.btn-add-question-toggle.add-question-btn-hidden {
    display: none;
}

.add-question-form-hidden {
    display: none;
}

#questionFormContainer {
    margin-top: 0.5rem;
}

.form-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.btn-cancel-question {
    padding: 0.4rem 0.75rem;
    font-size: 0.9375rem;
    color: #6b7280;
    background: transparent;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    cursor: pointer;
}

.btn-cancel-question:hover {
    background: #f9fafb;
    color: #374151;
}

.admin-options-list {
    list-style: none;
    margin: 0.35rem 0 0;
    padding-left: 0;
}

.admin-option {
    display: flex;
    align-items: flex-start;
    gap: 0.35rem;
    margin: 0.15rem 0;
    font-size: 0.95rem;
    color: #111827;
}

.admin-option-mark {
    width: 1rem;
    text-align: center;
    color: #9ca3af;
    flex-shrink: 0;
}

.admin-option-correct .admin-option-mark {
    color: #16a34a;
    font-weight: 600;
}

.admin-option-correct .admin-option-text {
    font-weight: 500;
}

.question-delete-form {
    display: inline;
}

.question-move-form {
    display: inline;
    margin: 0;
}

.btn-move {
    font-size: 1rem;
    padding: 0;
    line-height: 1;
}

.btn-move-up {
    transform: translateY(-4px);
}

.btn-move-down {
    transform: translateY(-4px);
}

.btn-move[disabled] {
    opacity: 0.3;
    cursor: default;
}

/* Кнопки управления вопросом показываем только при наведении на вопрос */
.admin-question-block .question-row .btn-edit,
.admin-question-block .question-row .btn-delete,
.admin-question-block .question-row .btn-move,
.admin-question-block .question-row .btn-drag-question {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

.admin-question-block:hover .question-row .btn-edit,
.admin-question-block:hover .question-row .btn-delete,
.admin-question-block:hover .question-row .btn-move,
.admin-question-block:hover .question-row .btn-drag-question,
.admin-question-block.admin-question-actions-visible .question-row .btn-edit,
.admin-question-block.admin-question-actions-visible .question-row .btn-delete,
.admin-question-block.admin-question-actions-visible .question-row .btn-move,
.admin-question-block.admin-question-actions-visible .question-row .btn-drag-question {
    opacity: 1;
    pointer-events: auto;
}

.option {
    display: block;
    margin: 0.25rem 0;
    cursor: pointer;
}

.option input {
    margin-right: 0.5rem;
}

.thankyou {
    text-align: center;
    padding: 2rem;
}

.thankyou h1 {
    color: #16a34a;
}

.description {
    color: #555;
    margin: 0.5rem 0;
}

.answer-block {
    margin: 1rem 0;
    padding: 0.75rem;
    background: #f8fafc;
    border-radius: 4px;
}

.answer-block.answer-correct {
    background: #dcfce7;
    border-left: 4px solid #166534;
}

.answer-block.answer-incorrect {
    background: #fee2e2;
    border-left: 4px solid #b91c1c;
}

.answer-block.answer-correct .answer-value {
    color: #166534;
    font-weight: 500;
}

.answer-block.answer-incorrect .answer-value {
    color: #b91c1c;
    font-weight: 500;
}

.answer-block .answer-row {
    margin: 0.25rem 0;
}

.answer-block .answer-label {
    font-weight: 600;
    margin-right: 0.5rem;
    margin-top: 0.75rem;
}

.answer-block .answer-correct-row {
    margin-top: 0.5rem;
}

.answer-block .answer-correct-value {
    color: #166534;
    font-weight: 500;
}

.answer-value {
    margin: 0.25rem 0 0;
    color: #334155;
}

.answer-match-pairs {
    margin: 0.5rem 0 0;
    padding-left: 1.25rem;
    list-style: none;
}

.answer-match-pairs li {
    display: block;
    margin: 0.25rem 0;
    padding: 0.25rem 0;
    border-bottom: 1px solid rgba(0,0,0,0.06);
    white-space: normal;
    word-break: break-word;
}

.answer-match-pairs li:last-child {
    border-bottom: none;
}

.answer-match-pairs.answer-correct-pairs li {
    color: #166534;
    font-weight: 500;
}

.question-options-block {
    margin: 0.75rem 0;
}

.match-pairs-list {
    margin-top: 0.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.match-pair-row {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.match-pair-row input {
    flex: 1;
}

.options-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.option-list {
    margin-bottom: 0.5rem;
}

.option-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.option-row .option-num {
    flex-shrink: 0;
    width: 1.5rem;
    color: #64748b;
    font-size: 0.9rem;
}

.option-row .option-input {
    flex: 1;
    max-width: 220px;
    padding: 0.35rem 0.5rem;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: 0.9rem;
}

.option-row .option-input:focus {
    outline: none;
    border-color: #2563eb;
}

.option-correct-label {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    cursor: pointer;
    user-select: none;
    font-size: 0.85rem;
    color: #64748b;
}

.option-row .option-correct-toggle .ios-toggle-track {
    width: 40px;
    height: 24px;
    border-radius: 12px;
}

.option-row .option-correct-toggle .ios-toggle-thumb {
    width: 18px;
    height: 18px;
}

.option-row .option-correct-toggle .ios-toggle-track.on .ios-toggle-thumb {
    transform: translateX(18px);
}

.option-actions {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.35rem;
}

.btn-remove-option {
    flex-shrink: 0;
    width: 2rem;
    height: 24px;
    padding: 0;
    border: none;
    border-radius: 4px;
    background: #dc2626;
    color: #fff;
    font-size: 1.15rem;
    line-height: 1;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-remove-option:hover {
    background: #b91c1c;
    color: #fff;
}

.btn-add-option {
    padding: 0.4rem 0.75rem;
    border: 1px dashed #d1d5db;
    border-radius: 4px;
    background: #f9fafb;
    color: #2563eb;
    font-size: 0.95rem;
    cursor: pointer;
}

.btn-add-option:hover {
    background: #eff6ff;
    border-color: #2563eb;
}

.match-question {
    margin-top: 0.5rem;
}

.match-hint {
    font-size: 0.9rem;
    color: #64748b;
    margin-bottom: 0.5rem;
}

.match-table {
    width: 100%;
    border-collapse: collapse;
}

.match-table td {
    padding: 0.35rem 0.5rem;
    vertical-align: middle;
}

.match-left {
    width: 40%;
    font-weight: 500;
}

.match-arrow {
    width: 2rem;
    text-align: center;
    color: #94a3b8;
}

.match-right select {
    width: 100%;
    padding: 0.35rem 0.5rem;
    border: 1px solid #ccc;
    border-radius: 4px;
}

.hint {
    font-size: 0.85rem;
    color: #64748b;
    margin: 0.25rem 0;
}

.score-result {
    margin-top: 0.75rem;
    padding: 0.5rem;
    background: #f0fdf4;
    border-radius: 4px;
    color: #166534;
}
