:root {
    --brand: #1f5fbf;
    --brand-dark: #154a99;
    --brand-bg: #eaf2ff;
    --text: #1a2233;
    --muted: #6b7280;
    --line: #e5e7eb;
    --bg: #f7f9fc;
    --ok: #16a34a;
    --ok-bg: #e8f7ee;
    --fail: #dc2626;
    --fail-bg: #fdecec;
    --card: #ffffff;
    --shadow: 0 1px 2px rgba(20, 40, 80, .06), 0 4px 14px rgba(20, 40, 80, .06);
    --radius: 10px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    color: var(--text);
    background: var(--bg);
    line-height: 1.5;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}
.container { flex: 1 0 auto; }
.admin-layout { flex: 1 0 auto; }
.footer { flex-shrink: 0; }

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
    background: #fff;
    border-bottom: 1px solid var(--line);
    padding: 14px 28px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 10;
}
.brand {
    font-weight: 700;
    color: var(--text);
    display: inline-flex;
    align-items: center;
    font-size: 17px;
    letter-spacing: -.01em;
}
.brand:hover { color: var(--brand); text-decoration: none; }
.nav { display: flex; gap: 18px; align-items: center; }
.nav a { color: var(--text); font-weight: 500; }
.nav a:hover { color: var(--brand); text-decoration: none; }
.inline-form { display: inline; margin: 0; }

.container {
    max-width: 1080px;
    margin: 32px auto;
    padding: 0 24px;
}

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 28px;
    box-shadow: var(--shadow);
    margin-bottom: 18px;
}
.card.narrow { max-width: 460px; margin: 32px auto; }
.card.center { text-align: center; }

h1 { margin: 0 0 18px; font-size: 28px; }
h2 { margin: 0 0 8px; font-size: 18px; }

.page-centered {
    text-align: center;
    margin: 8px auto 28px;
    max-width: 640px;
}
.page-centered h1 { margin-bottom: 8px; }
.page-subtitle { font-size: 15px; margin: 0; }

.page-head {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 18px;
}

form label {
    display: block;
    margin-bottom: 14px;
}
form label > span {
    display: block;
    font-size: 13px;
    margin-bottom: 6px;
    color: var(--muted);
}
input[type=text], input[type=email], input[type=password], input[type=number], input[type=url], textarea, select {
    width: 100%;
    padding: 10px 12px;
    height: 40px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-size: 14.5px;
    font-family: inherit;
    background: #fff;
    color: var(--text);
    transition: border-color .15s, box-shadow .15s;
}
textarea { height: auto; min-height: 80px; }
input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-bg);
}

select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'><path d='M1 1.5L6 6.5L11 1.5' stroke='%231f5fbf' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/></svg>");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 36px;
    cursor: pointer;
}

.btn, button.btn {
    display: inline-block;
    padding: 11px 18px;
    background: var(--brand);
    color: #fff;
    border: 0;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s;
}
.btn:hover { background: var(--brand-dark); text-decoration: none; }
.btn-ghost {
    background: #fff;
    color: var(--brand);
    border: 1px solid var(--brand);
}
.btn-ghost:hover { background: var(--brand-bg); }
.btn-ghost-danger {
    background: #fff;
    color: var(--fail);
    border: 1px solid var(--fail);
    padding: 10px 17px; /* компенсация border */
}
.btn-ghost-danger:hover { background: var(--fail-bg); text-decoration: none; }
.btn-sm {
    padding: 7px 14px;
    font-size: 13px;
    font-weight: 500;
}
.btn-sm.btn-ghost, .btn-sm.btn-ghost-danger { padding: 6px 13px; }
.link-btn {
    background: none; border: 0; color: var(--text);
    cursor: pointer; font: inherit; padding: 0;
}
.link-btn:hover { color: var(--brand); }

.muted { color: var(--muted); font-size: 14px; }

.auth-links {
    margin-top: 18px;
    padding-top: 18px;
    border-top: 1px solid var(--line);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    font-size: 14px;
}
.auth-link-secondary { color: var(--muted); }
.auth-link-secondary:hover { color: var(--brand); text-decoration: none; }
.auth-link-primary {
    font-weight: 600;
    color: var(--brand);
    transition: transform .15s;
}
.auth-link-primary:hover { transform: translateX(2px); text-decoration: none; }

.flash {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 18px;
    border: 1px solid transparent;
}
.flash-ok  { background: var(--ok-bg);   color: #14532d; border-color: #bbf7d0; }
.flash-err { background: var(--fail-bg); color: #7f1d1d; border-color: #fecaca; }

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

/* Карточки курсов */
.course-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 22px;
    margin-top: 8px;
}
.course-card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 14px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: transform .15s ease, box-shadow .15s ease;
    box-shadow: var(--shadow);
}
.course-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 4px 8px rgba(20, 40, 80, .08), 0 12px 28px rgba(20, 40, 80, .10);
}
.course-cover {
    aspect-ratio: 16 / 9;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}
.course-cover::after {
    content: "";
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at 20% 20%, rgba(255,255,255,.18), transparent 40%),
        radial-gradient(circle at 80% 80%, rgba(0,0,0,.10), transparent 40%);
}
.course-letter {
    font-size: 72px;
    font-weight: 800;
    color: #fff;
    text-shadow: 0 4px 16px rgba(0,0,0,.20);
    z-index: 1;
    letter-spacing: -2px;
}
.course-img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    z-index: 0;
}
.cover-preview {
    margin: -8px 0 14px;
    border: 1px solid var(--line);
    border-radius: 10px;
    overflow: hidden;
    max-width: 320px;
    background: var(--bg);
}
.cover-preview img { display: block; width: 100%; height: auto; max-height: 180px; object-fit: cover; }

.course-pin {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 2;
    background: rgba(255,255,255,.94);
    color: #b45309;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .02em;
    backdrop-filter: blur(4px);
    box-shadow: 0 2px 6px rgba(0,0,0,.12);
}

/* Обратная связь */
.feedback-item { padding: 18px 22px; }
.feedback-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    margin-bottom: 6px;
}
.feedback-meta { margin-bottom: 10px; }
.feedback-msg {
    background: var(--bg);
    padding: 12px 14px;
    border-radius: 8px;
    border: 1px solid var(--line);
    margin-bottom: 12px;
    white-space: pre-wrap;
    font-size: 14px;
}
.feedback-actions {
    display: flex;
    gap: 14px;
    align-items: center;
}
.feedback-actions select { width: auto; min-width: 160px; }

.form-meta {
    margin: 6px 0 14px;
    padding: 10px 14px;
    background: var(--bg);
    border-radius: 8px;
    display: grid;
    gap: 2px;
}

.filter-bar {
    display: flex;
    gap: 8px;
    margin: 0 0 18px;
    flex-wrap: wrap;
}
.filter-bar a {
    padding: 6px 14px;
    border-radius: 999px;
    background: #fff;
    border: 1px solid var(--line);
    color: var(--text);
    font-size: 13px;
    font-weight: 500;
}
.filter-bar a:hover { background: var(--brand-bg); border-color: var(--brand); text-decoration: none; }
.filter-bar a.active { background: var(--brand); border-color: var(--brand); color: #fff; }

.badge-warn { background: #fef3c7; color: #92400e; }
.badge-info { background: #dbeafe; color: #1e3a8a; }

/* Назначения сотрудникам */
.assignees {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 14px 16px 4px;
    margin: 14px 0;
}
.assignees legend { padding: 0 8px; font-size: 13px; color: var(--muted); font-weight: 500; }
.assignee-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 6px;
    max-height: 280px;
    overflow-y: auto;
    margin-top: 10px;
    padding-right: 4px;
}
.assignee-row {
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    margin: 0;
    transition: background .12s;
}
.assignee-row:hover { background: var(--brand-bg); }
.assignee-row span span { display: block; }
.course-body {
    padding: 20px 22px 22px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    flex: 1;
}
.course-body h2 {
    margin: 0;
    font-size: 17px;
    line-height: 1.3;
}
.course-desc {
    margin: 0;
    font-size: 13.5px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.course-meta {
    margin: 4px 0 0;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    font-size: 13px;
}
.course-meta li { list-style: none; }
.course-cta {
    margin-top: auto;
    padding-top: 6px;
}
.course-cta button { width: 100%; }
.course-cta button:disabled {
    background: var(--line);
    color: var(--muted);
    cursor: not-allowed;
}

ul.meta { list-style: none; padding: 0; margin: 12px 0; color: var(--muted); font-size: 13px; }
ul.meta li { margin-bottom: 2px; }

.q { border: 1px solid var(--line); border-radius: 8px; padding: 18px; margin-bottom: 14px; }
.q legend { padding: 0 8px; color: var(--muted); font-size: 13px; }
.q-text { font-weight: 500; margin: 4px 0 12px; }
.opt {
    display: flex; gap: 10px; align-items: flex-start;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 6px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: background .12s, border-color .12s;
}
.opt:hover { background: var(--brand-bg); border-color: var(--brand); }
.opt input { margin-top: 3px; }

.timer {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--brand-bg);
    color: var(--brand-dark);
    padding: 4px 10px 4px 9px;
    border-radius: 999px;
    font-variant-numeric: tabular-nums;
    font-size: 13px;
    font-weight: 600;
    line-height: 1;
    transition: background .2s, color .2s, transform .2s;
}
.timer-icon { flex-shrink: 0; opacity: .85; }
.timer-value { letter-spacing: .02em; }
.timer.timer-warn {
    background: var(--fail-bg);
    color: var(--fail);
    animation: pulse 1s ease-in-out infinite;
}
@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50%      { transform: scale(1.05); }
}

/* Прохождение теста — пошагово */
.quiz { max-width: 720px; margin: 0 auto; }

.quiz-progress {
    margin-bottom: 18px;
}
.quiz-progress-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
}
.quiz-progress-text {
    font-size: 13px;
    color: var(--muted);
}
.quiz-progress-text span { color: var(--brand); font-weight: 700; }
.quiz-head h1 { margin-bottom: 18px; }
.quiz-progress-bar {
    height: 6px;
    background: var(--line);
    border-radius: 999px;
    overflow: hidden;
}
.quiz-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--brand), #7c3aed);
    border-radius: 999px;
    transition: width .35s ease;
}

.quiz-step {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 28px;
    box-shadow: var(--shadow);
    animation: stepIn .3s ease;
}
@keyframes stepIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
.quiz-step .q-text {
    font-size: 19px;
    font-weight: 600;
    margin: 0 0 20px;
    line-height: 1.4;
}
.quiz-step-hint {
    margin-top: 14px;
    font-size: 13px;
    color: var(--fail);
}

.quiz-nav {
    display: flex;
    gap: 12px;
    justify-content: space-between;
    margin-top: 18px;
}
.quiz-nav button[hidden] { display: none; }
.quiz-nav [data-step-prev] { margin-right: auto; }
.quiz-nav [data-step-next], .quiz-nav [data-step-submit] { margin-left: auto; }

.result-badge {
    text-align: center;
    padding: 14px;
    border-radius: 8px;
    font-weight: 700;
    margin: 14px 0;
}
.result-badge.ok   { background: var(--ok-bg);   color: #14532d; }
.result-badge.fail { background: var(--fail-bg); color: #7f1d1d; }

.actions { display: flex; gap: 10px; margin-top: 12px; align-items: center; }
.actions .inline-form { display: inline-flex; }

.summary {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
    margin: 0 auto 26px;
    max-width: 720px;
}
.stat {
    background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
    padding: 18px; text-align: center;
}
.stat-num { display: block; font-size: 28px; font-weight: 700; color: var(--brand); }
.stat-lbl { color: var(--muted); font-size: 13px; }

.table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
    padding: 12px 14px;
    text-align: left;
    border-bottom: 1px solid var(--line);
    font-size: 14px;
    vertical-align: middle;
}
.table th { background: #fafbfd; font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.table tr:last-child td { border-bottom: 0; }
.table .select-compact {
    height: 32px;
    padding: 4px 30px 4px 10px;
    font-size: 13px;
    background-position: right 10px center;
    min-width: 130px;
}

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    background: #eef1f6;
    color: var(--muted);
    white-space: nowrap;
}
.badge.ok   { background: var(--ok-bg);   color: #14532d; }
.badge.fail { background: var(--fail-bg); color: #7f1d1d; }

.kv { display: grid; grid-template-columns: 200px 1fr; gap: 8px 16px; margin: 0; }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd { margin: 0; font-weight: 500; }

.footer {
    text-align: center;
    padding: 18px 24px;
    color: var(--muted);
    border-top: 1px solid var(--line);
    background: #fff;
    font-size: 13px;
}

@media (max-width: 640px) {
    .topbar { padding: 12px 16px; }
    .nav { gap: 12px; flex-wrap: wrap; }
    .container { padding: 0 16px; }
    .summary { grid-template-columns: 1fr; }
    .kv { grid-template-columns: 1fr; }
}

/* --- Админка --- */

.admin-layout {
    display: grid;
    grid-template-columns: 220px 1fr;
    min-height: calc(100vh - 70px);
}
.sidebar {
    background: #fff;
    border-right: 1px solid var(--line);
    padding: 24px 0;
}
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a {
    color: var(--text);
    padding: 10px 22px;
    border-left: 3px solid transparent;
    font-weight: 500;
}
.sidebar nav a:hover {
    background: var(--brand-bg);
    color: var(--brand-dark);
    text-decoration: none;
}
.sidebar nav a.active {
    background: var(--brand-bg);
    color: var(--brand-dark);
    border-left-color: var(--brand);
}
.sidebar-badge {
    display: inline-block;
    background: var(--fail);
    color: #fff;
    border-radius: 999px;
    padding: 1px 7px;
    font-size: 11px;
    font-weight: 700;
    margin-left: 6px;
    vertical-align: middle;
}
.admin-main {
    padding: 28px 32px;
    max-width: 1100px;
}
.admin-stats {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    max-width: none;
    margin: 0 0 26px;
}

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

label.check {
    display: flex;
    gap: 10px;
    align-items: center;
    margin: 12px 0;
}
label.check.inline { margin: 0; }
label.check input { width: auto; }

.opts { border: 1px solid var(--line); border-radius: 8px; padding: 14px; }
.opts legend { padding: 0 6px; font-size: 13px; color: var(--muted); }
.opt-row {
    display: grid;
    grid-template-columns: 40px 1fr;
    gap: 8px;
    align-items: center;
    margin-bottom: 8px;
}

.btn.small, .btn-ghost.small {
    padding: 7px 12px;
    font-size: 13px;
}

.actions-cell { white-space: nowrap; font-size: 13px; }
.actions-cell a, .actions-cell .link-btn { font-size: 13px; }
.danger { color: var(--fail); }
.danger:hover { color: #991b1b; }

.opt-list { list-style: none; padding: 0; margin: 8px 0 0; }
.opt-list li { padding: 6px 8px; border-bottom: 1px dashed var(--line); font-size: 14px; }
.opt-list li.correct { color: #14532d; font-weight: 500; }
.opt-list li:last-child { border-bottom: 0; }

.small { font-size: 12px; }
textarea { font-family: inherit; resize: vertical; }

@media (max-width: 900px) {
    .admin-layout { grid-template-columns: 1fr; }
    .sidebar { border-right: 0; border-bottom: 1px solid var(--line); padding: 12px 0; }
    .sidebar nav { flex-direction: row; flex-wrap: wrap; gap: 0; }
    .sidebar nav a { border-left: 0; border-bottom: 3px solid transparent; }
    .sidebar nav a.active { border-bottom-color: var(--brand); border-left-color: transparent; }
    .admin-main { padding: 18px; }
    .admin-stats { grid-template-columns: repeat(2, 1fr); }
    .row { grid-template-columns: 1fr; }
}
