:root {
  --container: 980px;
  --pad: 16px;
  --radius: 12px;
  --bg: #f5f5f5;
  --card: #fff;
  --text: #1a1a1a;
  --muted: #666;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --error: #dc2626;
  --border: #e5e7eb;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.35;
}

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

.container {
  max-width: var(--container);
  margin: 0 auto;
  padding: var(--pad);
}

/* Header: не ломаться на мобиле */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px var(--pad);
  border-bottom: 1px solid #eee;
  background: var(--card);
}
.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.header-right {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.header a, .header span {
  white-space: nowrap;
}
.logo { font-weight: 700; font-size: 1.25rem; flex-shrink: 0; }
.header .user { color: var(--muted); }

/* Длинные строки: только там, где нужен перенос (не глобально для .card/.table) */
.text-wrap { overflow-wrap: anywhere; word-break: break-word; }

.alert { padding: 0.75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; }
.alert-error { background: #fef2f2; color: var(--error); }
.alert-warning { background: #fef3c7; color: #92400e; }

.course-section-title { font-size: 1rem; margin: 1rem 0 0.25rem; }
.course-section-title:first-of-type { margin-top: 0; }

/* Auth */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: var(--pad); }
.auth-card {
  background: var(--card);
  padding: 2rem;
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
  width: 100%; max-width: 360px;
}
.auth-card h1 { margin: 0 0 1.5rem; font-size: 1.5rem; }
.auth-form label { display: block; margin-bottom: 1rem; }
.auth-form input {
  display: block;
  width: 100%;
  max-width: 100%;
  margin-top: 0.25rem;
  padding: 12px 14px;
  border: 1px solid #d7d7d7;
  border-radius: var(--radius);
  font-size: 16px;
}
.auth-form button {
  width: 100%;
  padding: 12px 16px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 0.5rem;
}
.auth-form button:hover { background: var(--accent-hover); }

/* Cards */
.card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}
.card h2 { margin: 0 0 0.5rem; font-size: 1.125rem; }
.card .meta { color: var(--muted); font-size: 0.875rem; }
.progress-bar { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; margin-top: 0.5rem; }
.progress-bar span { display: block; height: 100%; background: var(--accent); }

/* Forms: поля под мобилку, font-size 16px для iOS */
input, select, textarea {
  width: 100%;
  max-width: 100%;
  padding: 12px 14px;
  border: 1px solid #d7d7d7;
  border-radius: var(--radius);
  font-size: 16px;
}
textarea {
  min-height: 120px;
  resize: vertical;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 16px;
  border-radius: 10px;
  border: 0;
  text-decoration: none;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.9375rem;
  background: var(--accent);
  color: #fff;
}
.btn:hover { background: var(--accent-hover); text-decoration: none; }
.btn-secondary { background: var(--muted); }
.btn-secondary:hover { background: #555; }
.btn-danger { background: var(--error); color: #fff; }
.btn-danger:hover { background: #b91c1c; color: #fff; text-decoration: none; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-small { padding: 0.25rem 0.5rem; font-size: 0.75rem; }
.btn-block { width: 100%; }
.btn-link { background: none; border: none; cursor: pointer; font: inherit; padding: 0; text-decoration: underline; }

.actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
@media (max-width: 640px) {
  .actions { flex-direction: column; }
  .actions .btn { width: 100%; }
}

.badge { display: inline-block; padding: 0.15rem 0.4rem; border-radius: 4px; font-size: 0.7rem; margin-right: 0.35rem; }
.badge-position { background: #dbeafe; color: #1d4ed8; }
.badge-manual { background: #e0e7ff; color: #3730a3; }

.course-checkbox-list { list-style: none; padding: 0; margin: 0; }
.course-checkbox-list .course-row { display: flex; align-items: center; flex-wrap: wrap; gap: 0.5rem; padding: 0.5rem 0; border-bottom: 1px solid var(--border); }
.course-checkbox-list .course-row label { flex: 1; margin: 0; cursor: pointer; min-width: 0; }
.course-checkbox-list .course-row input[type=checkbox] { margin-right: 0.35rem; flex-shrink: 0; }

/* Lists */
.lesson-list { list-style: none; padding: 0; margin: 0; }
.lesson-list li { display: flex; align-items: center; justify-content: space-between; padding: 0.75rem; border-bottom: 1px solid var(--border); gap: 0.5rem; flex-wrap: wrap; }
.lesson-list li:last-child { border-bottom: none; }
.lesson-list .lesson-thumb { flex-shrink: 0; }
.lesson-list .lesson-thumb img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; display: block; }
.lesson-list .locked { color: var(--muted); }
.lesson-list .done { color: #16a34a; }

/* Quiz */
.quiz-question { margin-bottom: 1.5rem; padding: 1rem; background: var(--card); border-radius: var(--radius); border: 1px solid var(--border); }
.quiz-question label { display: block; padding: 0.5rem 0; cursor: pointer; }
.quiz-question input[type=radio] { margin-right: 0.5rem; }

/* Admin: таблицы с горизонтальным скроллом на мобиле */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 1rem;
}
.table {
  width: 100%;
  border-collapse: collapse;
  min-width: 640px;
}
.table th, .table td { padding: 0.5rem 0.75rem; text-align: left; border-bottom: 1px solid var(--border); }
.table th { background: var(--bg); font-weight: 600; }

/* Админка: ровные отступы, контейнер по центру */
.page-admin { padding: 24px var(--pad); }
.page-admin h1 { margin: 0 0 1rem; font-size: 1.5rem; }
.page-admin .actions { margin-bottom: 1.5rem; display: flex; flex-wrap: wrap; gap: 0.75rem; }
.page-admin h2 { margin: 2rem 0 0.75rem; font-size: 1.25rem; }
.page-admin h2:first-of-type { margin-top: 1rem; }
.page-admin .table-wrap { margin-bottom: 1.5rem; }
.page-admin .table-wrap + h2 { margin-top: 2rem; }
.page-admin p { margin: 0.5rem 0 1rem; }

.form-group { margin-bottom: 1rem; }
.form-group label { display: block; margin-bottom: 0.25rem; font-weight: 500; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  max-width: 100%;
  padding: 12px 14px;
  border: 1px solid #d7d7d7;
  border-radius: var(--radius);
  font-size: 16px;
}

/* ========== Стили только внутри урока (не влияют на админку/кабинет) ========== */
.lesson-content.longread {
  max-width: 900px;
  margin: 0 auto;
  padding: 16px;
  font-size: 17px;
  line-height: 1.7;
  word-break: break-word;
  overflow-wrap: anywhere;
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.lesson-content h1 { font-size: 1.5rem; margin: 1.25rem 0 0.5rem; }
.lesson-content h2 { font-size: 1.25rem; margin: 1.5rem 0 0.5rem; }
.lesson-content h3 { font-size: 1.1rem; margin: 1rem 0 0.35rem; }
.lesson-content p { margin: 0.5rem 0; }
.lesson-content ul { margin: 0.5rem 0; padding-left: 1.5rem; }
.lesson-content li { margin: 0.25rem 0; }
.lesson-content a { color: var(--accent); text-decoration: none; }
.lesson-content a:hover { text-decoration: underline; }
.lesson-content img { max-width: 100%; height: auto; display: block; margin: 0.75rem 0; }
.lesson-content table { width: 100%; border-collapse: collapse; margin: 0.75rem 0; font-size: 0.95em; }
.lesson-content th, .lesson-content td { border: 1px solid var(--border); padding: 0.5rem 0.75rem; text-align: left; }
.lesson-content .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0.75rem 0; }

.lesson-content .lesson-figure {
  margin: 1.25rem 0;
}
.lesson-content .lesson-figure img {
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.lesson-content .lesson-figure figcaption {
  margin-top: 0.5rem;
  font-size: 0.9em;
  color: var(--muted);
  line-height: 1.4;
}

.lesson-content .block-important,
.lesson-content .block-example,
.lesson-content .block-error,
.lesson-content .block-wow,
.lesson-content .block-fu {
  margin: 1rem 0;
  padding: 1rem 1.25rem;
  border-radius: var(--radius);
  border-left: 4px solid;
}
.lesson-content .block-important { background: #eff6ff; border-color: #2563eb; }
.lesson-content .block-example { background: #f0fdf4; border-color: #16a34a; }
.lesson-content .block-error { background: #fef2f2; border-color: #dc2626; }
.lesson-content .block-wow { background: #fefce8; border-color: #eab308; }
.lesson-content .block-fu { background: #fef2f2; border-color: #dc2626; }

.lesson-content .toc { margin: 1rem 0 1.5rem; padding: 1rem 1.25rem; background: var(--bg); border-radius: var(--radius); }
.lesson-content .toc ol { list-style: decimal; padding-left: 1.5rem; }
.lesson-content .toc li { margin: 0.35rem 0; }
.lesson-content section { margin-bottom: 1.5rem; }

@media (max-width: 640px) {
  .lesson-content.longread {
    padding: 12px;
    font-size: 16px;
    line-height: 1.65;
  }
  .lesson-content h1 { font-size: 1.35rem; margin: 1rem 0 0.4rem; }
  .lesson-content h2 { font-size: 1.15rem; margin: 1.25rem 0 0.4rem; }
  .lesson-content h3 { font-size: 1.05rem; }
}
