/* ============================================================
   БАЗА (перенесено из hygiene_v1_0.html)
   ============================================================ */
:root {
    --bg: #f7f9fc;
    --panel: #ffffff;
    --text: #1a1a1a;
    --text-muted: #555555;
    --border: #d0d7e2;
    --border-soft: #e6e6e6;
    --btn-bg: #ffffff;
    --btn-hover: #eef4ff;
    --btn-border: #c9d4e3;
    --btn-primary: #1976d2;
    --btn-primary-hover: #1565c0;
    --btn-secondary: #78909c;
    --btn-secondary-hover: #546e7a;
    --btn-back: #f0f0f0;
    --input-section-bg: #fff4f4;
    --input-section-border: #e4bcbc;
    --output-section-bg: #f3f7ff;
    --output-section-border: #bdcce5;
    --answer-bg: #ffffff;
    --answer-hover: #f0f6ff;
    --answer-correct-bg: #e8f5e9;
    --answer-correct-border: #66bb6a;
    --answer-correct-text: #1b5e20;
    --answer-incorrect-bg: #ffebee;
    --answer-incorrect-border: #ef5350;
    --answer-incorrect-text: #b71c1c;
    --progress-bg: #e0e0e0;
    --progress-fill: #4caf50;
    --qlist-bg: #fafafa;
    --qlist-current-bg: #e8f5e9;
    --shadow: 0 2px 10px rgba(0,0,0,.06);
    --shadow-header: 0 2px 6px rgba(0,0,0,.08);
    --img-bg: #ffffff;
    --accent-1: #6a4c93;
    --accent-2: #2a9d8f;
    --grade-5: #2e7d32;
    --grade-4: #558b2f;
    --grade-3: #ef6c00;
    --grade-2: #c62828;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #121417;
        --panel: #1c1f24;
        --text: #f1f3f5;
        --text-muted: #b0b6bd;
        --border: #3a4048;
        --border-soft: #2b3037;
        --btn-bg: #262b31;
        --btn-hover: #313842;
        --btn-border: #3a4048;
        --btn-primary: #2b8ae0;
        --btn-primary-hover: #3d9bef;
        --btn-secondary: #4b555f;
        --btn-secondary-hover: #5a6570;
        --btn-back: #262b31;
        --input-section-bg: #2a2224;
        --input-section-border: #5a3f3f;
        --output-section-bg: #1f2530;
        --output-section-border: #3a4a63;
        --answer-bg: #23272d;
        --answer-hover: #2b323a;
        --answer-correct-bg: #1e3a22;
        --answer-correct-border: #4caf50;
        --answer-correct-text: #a5e0a8;
        --answer-incorrect-bg: #3a1f22;
        --answer-incorrect-border: #ef5350;
        --answer-incorrect-text: #ffb3b3;
        --progress-bg: #2b3037;
        --progress-fill: #4caf50;
        --qlist-bg: #23272d;
        --qlist-current-bg: #1e3a22;
        --shadow: 0 2px 12px rgba(0,0,0,.5);
        --shadow-header: 0 2px 8px rgba(0,0,0,.5);
        --img-bg: #1c1f24;
        --accent-1: #b39ddb;
        --accent-2: #80cbc4;
        --grade-5: #81c784;
        --grade-4: #aed581;
        --grade-3: #ffb74d;
        --grade-2: #ef9a9a;
    }
}

* { box-sizing: border-box; }

html, body {
    background: var(--bg);
    color: var(--text);
    color-scheme: light dark;
}

body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding-top: 70px;
    transition: background .2s, color .2s;
}

.hidden { display: none !important; }

#header {
    position: fixed;
    top: 0; left: 0; right: 0;
    background: var(--panel);
    color: var(--text);
    z-index: 1000;
    box-shadow: var(--shadow-header);
    padding: 12px 0;
    text-align: center;
}
#header h1 { margin: 0; font-size: 1.5em; color: var(--text); }

/* ============================================================
   ЭКРАНЫ (новые классы)
   ============================================================ */
.screen {
    max-width: 900px;
    margin: 20px auto;
    padding: 20px;
    background: var(--panel);
    color: var(--text);
    border-radius: 12px;
    box-shadow: var(--shadow);
}
.screen > h2 { margin-top: 0; }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.topbar-user { font-weight: bold; }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.banner {
    background: var(--output-section-bg);
    border: 1px solid var(--output-section-border);
    border-radius: 8px;
    padding: 12px 14px;
    margin-bottom: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.banner-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 12px;
    margin-top: 12px;
}

.card {
    background: var(--btn-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: var(--shadow);
}
.card h3 { margin-top: 0; }

.node-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin: 12px 0 16px;
}

/* Тумблер «выдавать чекбоксами» */
.switch-row {
    margin: 0 0 16px;
    padding: 12px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 8px;
}
.mode-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
}
.mode-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.mode-switch {
    flex: none;
    width: 40px;
    height: 22px;
    border-radius: 11px;
    background: var(--btn-secondary);
    position: relative;
    transition: background .15s;
}
.mode-switch::after {
    content: "";
    position: absolute;
    top: 2px; left: 2px;
    width: 18px; height: 18px;
    border-radius: 50%;
    background: #fff;
    transition: transform .15s;
}
.mode-toggle input:checked + .mode-switch { background: var(--btn-primary); }
.mode-toggle input:checked + .mode-switch::after { transform: translateX(18px); }
.mode-toggle input:focus-visible + .mode-switch { outline: 2px solid var(--btn-primary); outline-offset: 2px; }

/* Формы */
.form-row { margin-bottom: 12px; display: flex; flex-direction: column; gap: 4px; }
.form-row label { font-weight: bold; font-size: .95em; }
.form-row input {
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--panel);
    color: var(--text);
    font-size: 1em;
}
.form-row input:focus { outline: 2px solid var(--btn-primary); outline-offset: 1px; }
.form-hint { font-size: .9em; color: var(--text-muted); margin-top: 8px; }
.form-hint a { color: var(--btn-primary); }

.readonly {
    padding: 8px 10px;
    background: var(--qlist-bg);
    border-radius: 6px;
    border: 1px dashed var(--border);
}

/* Кнопки */
button {
    padding: 10px 16px;
    cursor: pointer;
    border: none;
    border-radius: 6px;
    background: var(--btn-primary);
    color: #fff;
    font-size: .95em;
    transition: .15s;
    font-family: inherit;
}
button:hover:not(:disabled) { background: var(--btn-primary-hover); }
button:disabled { background: #b0bec5; cursor: default; color: #444; }

.btn-primary { background: var(--btn-primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--btn-primary-hover); }
.btn-ghost {
    background: var(--btn-back);
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-ghost:hover:not(:disabled) { background: var(--btn-hover); }
.btn-danger {
    background: var(--answer-incorrect-border);
    color: #fff;
}

.master-btn {
    padding: 16px 14px;
    font-size: 1.02em;
    font-weight: 700;
    text-align: left;
    border-radius: 10px;
    border: 1px solid var(--btn-border);
    background: var(--btn-bg);
    color: var(--text);
    cursor: pointer;
    transition: .15s;
}
.master-btn.all-questions {
    background: linear-gradient(135deg, var(--input-section-bg) 0%, var(--btn-bg) 100%);
    border-color: var(--input-section-border);
    border-left: 5px solid var(--accent-1);
}
.master-btn.all-questions:hover { background: var(--btn-hover); border-color: var(--accent-1); }
.master-btn.random-test {
    background: linear-gradient(135deg, var(--output-section-bg) 0%, var(--btn-bg) 100%);
    border-color: var(--output-section-border);
    border-left: 5px solid var(--accent-2);
}
.master-btn.random-test:hover { background: var(--btn-hover); border-color: var(--accent-2); }

/* Карточки узлов и вопросов (аналог старых #menu button) */
.card-btn {
    padding: 12px 14px;
    font-size: .95em;
    cursor: pointer;
    border: 1px solid var(--btn-border);
    border-radius: 8px;
    background: var(--btn-bg);
    color: var(--text);
    text-align: left;
    transition: .15s;
    display: flex;
    align-items: baseline;
    gap: 4px;
    min-width: 0;
    overflow: hidden;
}
.card-btn.input-section {
    background: var(--input-section-bg);
    border-color: var(--input-section-border);
}
.card-btn.output-section {
    background: var(--output-section-bg);
    border-color: var(--output-section-border);
}
.card-btn:hover:not(:disabled) { background: var(--btn-hover); border-color: var(--btn-primary); }
.card-btn .q-num { flex-shrink: 0; }
.card-btn .q-preview {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-muted);
    font-size: 0.85em;
}

/* ============================================================
   ПРОХОЖДЕНИЕ ТЕСТА (перенесено, адаптировано под id)
   ============================================================ */
.quiz-topbar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.quiz-progress-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 160px;
}
#progress-bar-container {
    flex: 1;
    background: var(--progress-bg);
    border-radius: 5px;
    height: 10px;
    overflow: hidden;
}
#progress-bar {
    height: 100%;
    width: 0%;
    background: var(--progress-fill);
    border-radius: 5px;
    transition: width .3s;
}
#progress-text { font-weight: bold; }

#question-jump { margin: 0 0 15px; }
#question-jump summary { cursor: pointer; font-weight: bold; font-size: 1.05em; }
#question-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 10px;
    padding: 15px 0;
}
#question-list button {
    padding: 8px 4px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--qlist-bg);
    color: var(--text);
    cursor: pointer;
    display: flex;
    align-items: baseline;
    gap: 4px;
    text-align: left;
    min-width: 0;
}
#question-list button .q-num { flex-shrink: 0; }
#question-list button .q-preview {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-muted);
    font-size: 0.85em;
}
#question-list button:hover { background: var(--btn-hover); }
#question-list button.current-question {
    outline: 2px solid var(--progress-fill);
    font-weight: bold;
    background: var(--qlist-current-bg);
}
#question-list button.answered-correct {
    color: var(--answer-correct-text);
    background: var(--answer-correct-bg);
    border-color: var(--answer-correct-border);
}
#question-list button.answered-incorrect {
    color: var(--answer-incorrect-text);
    background: var(--answer-incorrect-bg);
    border-color: var(--answer-incorrect-border);
}
#question-list button.answered-correct .q-preview,
#question-list button.answered-incorrect .q-preview { color: inherit; }

.question-text { margin-bottom: 12px; font-size: 1.05em; }

.question-image { margin: 14px 0; text-align: center; }
.question-image img {
    max-width: 100%;
    height: auto;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--img-bg);
}

.answers { list-style: none; padding: 0; margin: 0; }
.answers li {
    margin: 8px 0;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    transition: .12s;
    background: var(--answer-bg);
    color: var(--text);
}
.answers li:hover { background: var(--answer-hover); }
.answers li label { cursor: pointer; color: inherit; flex: 1; }
.answers li.correct {
    color: var(--answer-correct-text);
    background: var(--answer-correct-bg);
    border-color: var(--answer-correct-border);
    font-weight: bold;
}
.answers li.incorrect {
    color: var(--answer-incorrect-text);
    background: var(--answer-incorrect-bg);
    border-color: var(--answer-incorrect-border);
    font-weight: bold;
}
.answers input[type="radio"],
.answers input[type="checkbox"] { margin-right: 6px; }

.quiz-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 16px; }

#feedback { margin-top: 12px; font-weight: bold; min-height: 1.4em; }
#feedback .fb-hint {
    display: block;
    margin-top: 6px;
    font-weight: normal;
    color: var(--text-muted);
}

/* ============================================================
   РЕЗУЛЬТАТ
   ============================================================ */
#result-score {
    font-size: 1.2em;
    font-weight: bold;
    margin-bottom: 10px;
}
#result-grade {
    text-align: center;
    font-size: 1.35em;
    font-weight: bold;
    margin-top: 16px;
    padding: 14px;
    border-radius: 10px;
    background: var(--btn-hover);
    border: 1px solid var(--border);
}
#result-grade .grade-num { display: inline-block; font-size: 1.5em; margin-right: 8px; }
#result-grade.grade-5 { color: var(--grade-5); border-color: var(--grade-5); }
#result-grade.grade-4 { color: var(--grade-4); border-color: var(--grade-4); }
#result-grade.grade-3 { color: var(--grade-3); border-color: var(--grade-3); }
#result-grade.grade-2 { color: var(--grade-2); border-color: var(--grade-2); }

/* ============================================================
   СТАТИСТИКА
   ============================================================ */
#stats-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.stat-item {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--qlist-bg);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.stat-item .stat-title { font-weight: bold; }
.stat-item .stat-meta { color: var(--text-muted); font-size: .9em; }
.stat-item .stat-score { font-weight: bold; }
.stat-item.forced .stat-title::after {
    content: " (досрочно)";
    color: var(--text-muted);
    font-weight: normal;
    font-size: .85em;
}

/* ============================================================
   СПИННЕР И ТОСТ
   ============================================================ */
.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--btn-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--text);
    color: var(--bg);
    padding: 10px 18px;
    border-radius: 8px;
    box-shadow: var(--shadow);
    z-index: 2000;
    max-width: calc(100vw - 40px);
    font-size: .95em;
}

.muted { color: var(--text-muted); }

/* ============================================================
   МОБИЛЬНАЯ АДАПТАЦИЯ
   ============================================================ */
@media (max-width: 600px) {
    #header { display: none; }
    body { padding-top: 0; }
    .screen { margin: 8px; padding: 14px; border-radius: 8px; }
    .cards-grid { grid-template-columns: 1fr; }
    #question-list { grid-template-columns: repeat(4, 1fr); }
    #question-list button { justify-content: center; }
/*    #question-list button .q-preview { display: none; }
    .card-btn .q-preview { display: none; }                        - удаление превью (первые 3 слова вопроса) на мобилках*/ 
    .topbar { flex-direction: column; align-items: stretch; }
    .topbar-actions { justify-content: stretch; }
    .topbar-actions button { flex: 1; }
    .quiz-actions { flex-direction: column; }
    .quiz-actions button { width: 100%; }
    .banner { flex-direction: column; align-items: stretch; }
}

/* ============================================================
   АДМИН-ПАНЕЛЬ
   ============================================================ */
.admin-tabs { display: flex; gap: 8px; margin-bottom: 16px; border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.tab-btn { background: var(--panel); border: 1px solid var(--border); padding: 8px 16px; border-radius: 6px; cursor: pointer; color: var(--text); font-weight: bold; }
.tab-btn.active { background: var(--btn-primary); color: #fff; border-color: var(--btn-primary); }
.tab-btn:hover:not(.active) { background: var(--btn-hover); }

.admin-user-row { display: flex; justify-content: space-between; align-items: center; padding: 12px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px; background: var(--panel); flex-wrap: wrap; gap: 8px; }
.admin-user-info { flex: 1; min-width: 200px; }
.admin-user-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.form-select { width: 100%; padding: 10px; border-radius: 6px; border: 1px solid var(--border); background: var(--panel); color: var(--text); font-size: 1em; margin-bottom: 12px; }
.access-node-item { display: flex; align-items: center; gap: 8px; padding: 6px 0; }

/* Таблицы админки */
.table-wrap { overflow-x: auto; background: var(--panel); border-radius: 8px; border: 1px solid var(--border); }
.admin-table { width: 100%; border-collapse: collapse; text-align: left; }
.admin-table th, .admin-table td { padding: 10px; border-bottom: 1px solid var(--border); }
.admin-table th { background: var(--qlist-bg); font-weight: bold; }
.admin-table tr:last-child td { border-bottom: none; }
.btn-sm { padding: 4px 8px; font-size: 0.85em; }
.btn-danger { background: var(--answer-incorrect-border); color: white; border: none; }
.btn-danger:hover { background: #c62828; }

/* Модальное окно */
.modal { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; z-index: 2000; }
.modal.hidden { display: none !important; }
.modal-content { background: var(--panel); padding: 20px; border-radius: 12px; max-width: 800px; width: 90%; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow); }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.copy-ip { cursor: pointer; border-bottom: 1px dashed var(--text-muted); }
.copy-ip:hover { color: var(--btn-primary); }
.flag-icon { display: inline-block; width: 20px; height: 14px; background-size: cover; margin-right: 6px; border-radius: 2px; vertical-align: middle; background-color: #ccc; }

/* Убираем обводку фокуса внутри модальных окон */
.modal-content *:focus {
  outline: none !important;
  box-shadow: none !important;
}
.modal-content button:focus-visible,
.modal-content input:focus-visible,
.modal-content select:focus-visible {
  outline: 2px solid var(--btn-primary) !important;
  outline-offset: 2px;
}