:root {
  --blue: #2563eb;
  --blue-dark: #1d4ed8;
  --sky: #38bdf8;
  --sky-light: #e0f2fe;
  --white: #ffffff;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-900: #111827;
  --lime: #a3e635;
  --lime-light: #ecfccb;
  --green: #16a34a;
  --green-light: #dcfce7;
  --red: #ef4444;
  --radius: 0.9rem;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
}

button { font-family: inherit; cursor: pointer; }

#app { min-height: 100vh; display: flex; flex-direction: column; }

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-box { max-width: 360px; width: 100%; }
.login-logo {
  height: 48px; width: auto; max-width: 220px;
  object-fit: contain; display: block; margin-bottom: 16px;
}
.login-box h1 { font-size: 20px; margin: 0 0 4px; }
.login-box p { color: var(--gray-500); font-size: 14px; margin: 0 0 24px; }

/* ---------- Layout ---------- */
.header {
  height: 56px; background: var(--blue); color: #fff;
  display: flex; align-items: center; gap: 10px; padding: 0 12px;
  position: sticky; top: 0; z-index: 20; box-shadow: 0 1px 4px rgba(0,0,0,.08);
}
.header .avatar {
  width: 32px; height: 32px; border-radius: 10px; object-fit: cover; flex-shrink:0;
}
.header .titles { flex: 1; min-width: 0; }
.header .titles .app-name { font-weight: 600; line-height: 1.2; }
.header .titles .user-line { font-size: 12px; color: #dbeafe; line-height: 1.2; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.header button.icon-btn { background: transparent; border: none; color: #fff; padding: 8px; border-radius: 10px; }
.header button.icon-btn:active { background: var(--blue-dark); }

.tabs { display: flex; background: #fff; border-bottom: 1px solid var(--gray-200); position: sticky; top: 56px; z-index: 10; }
.tabs button {
  flex: 1; border: none; background: transparent; padding: 12px 0; font-size: 14px; font-weight: 500;
  color: var(--gray-400); border-bottom: 2px solid transparent;
}
.tabs button.active { color: var(--blue); border-color: var(--blue); }

.subtabs { display: flex; background: var(--gray-100); margin: 12px 12px 0; border-radius: 12px; padding: 4px; }
.subtabs button {
  flex: 1; border: none; background: transparent; padding: 8px 0; font-size: 13px; font-weight: 600;
  color: var(--gray-500); border-radius: 8px;
}
.subtabs button.active { background: #fff; color: var(--blue); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.main { flex: 1; padding: 12px; padding-bottom: 90px; }

/* ---------- Students list ---------- */
.list-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.sort-toggle { display: inline-flex; background: var(--gray-100); border-radius: 10px; padding: 3px; }
.sort-toggle button {
  border: none; background: transparent; padding: 5px 10px; font-size: 12px; font-weight: 600;
  color: var(--gray-500); border-radius: 7px; white-space: nowrap;
}
.sort-toggle button.active { background: #fff; color: var(--blue); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.btn-primary {
  background: var(--blue); color: #fff; border: none; border-radius: 12px; padding: 0 16px;
  display: flex; align-items: center; justify-content: center; font-size: 20px; font-weight: 600;
}
.btn-primary:active { background: var(--blue-dark); }

.student-row {
  width: 100%; background: #fff; border: 1px solid var(--gray-200); border-radius: var(--radius);
  padding: 12px; display: flex; align-items: center; gap: 12px; text-align: left; margin-bottom: 8px;
}
.student-row:active { background: var(--gray-50); }
.student-row .initial {
  width: 40px; height: 40px; border-radius: 50%; background: var(--sky-light); color: #0284c7;
  display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0;
}
.student-row .info { flex: 1; min-width: 0; }
.student-row .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.student-row .year { font-size: 12px; color: var(--gray-400); }
.student-row .progress { text-align: right; flex-shrink: 0; }
.student-row .count { font-weight: 700; color: var(--green); font-size: 14px; }
.progress-bar { width: 56px; height: 6px; background: var(--gray-100); border-radius: 4px; overflow: hidden; margin-top: 4px; }
.progress-bar > div { height: 100%; background: var(--lime); }

.empty-state { text-align: center; color: var(--gray-400); font-size: 14px; padding: 40px 0; border: 1px dashed var(--gray-200); border-radius: var(--radius); }

/* ---------- Student card ---------- */
.card { background: #fff; border: 1px solid var(--gray-200); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; }
.card-head h2 { margin: 0; font-size: 18px; }
.card-head .year { color: var(--gray-400); font-size: 14px; }
.icon-btn-gray { background: var(--gray-100); border: none; color: var(--gray-500); padding: 8px; border-radius: 10px; }
.progress-full { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.progress-full .count { font-weight: 700; color: var(--green); font-size: 14px; white-space: nowrap; }
.progress-full .bar { flex: 1; height: 8px; background: var(--gray-100); border-radius: 8px; overflow: hidden; }
.progress-full .bar > div { height: 100%; background: linear-gradient(90deg, var(--sky), var(--lime)); }

.lessons-title { font-size: 14px; font-weight: 600; color: var(--gray-500); margin-bottom: 10px; }
.lessons-title-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.lessons-title-row .lessons-title { margin-bottom: 0; }
.btn-link { background: none; border: none; color: var(--blue); font-size: 13px; font-weight: 600; padding: 0; }
.lessons-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.lesson-box {
  aspect-ratio: 1; border-radius: 10px; display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; border: 1px solid var(--gray-100); background: var(--gray-50); color: var(--gray-400);
}
.lesson-box.next { background: var(--sky-light); border-color: var(--sky); color: #0284c7; }
.lesson-box.done { background: var(--green); border-color: var(--green); color: #fff; }
.lesson-box.planned { background: var(--lime-light); border-color: var(--lime); color: #3f6212; }
.lesson-box.locked { opacity: .6; }
.lessons-hint { font-size: 12px; color: var(--gray-400); margin-top: 12px; line-height: 1.4; }

.lesson-row {
  width: 100%; background: #fff; border: 1px solid var(--gray-200); border-radius: var(--radius);
  padding: 12px; display: flex; align-items: center; gap: 12px; text-align: left; margin-bottom: 8px;
}
.lesson-row:active { background: var(--gray-50); }
.lesson-row .info { flex: 1; min-width: 0; }
.lesson-row .name { font-weight: 600; font-size: 14px; }
.lesson-row .meta { font-size: 12px; color: var(--gray-400); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-badge { font-size: 11px; font-weight: 700; padding: 4px 10px; border-radius: 999px; flex-shrink: 0; white-space: nowrap; }
.status-badge.done { background: var(--green-light); color: var(--green); }
.status-badge.planned { background: var(--lime-light); color: #65a30d; }

/* ---------- Users ---------- */
.user-row {
  background: #fff; border: 1px solid var(--gray-200); border-radius: var(--radius);
  padding: 12px; display: flex; align-items: center; gap: 12px; margin-bottom: 8px;
}
.user-row .avatar-round { width: 40px; height: 40px; border-radius: 50%; background: #eff6ff; color: var(--blue); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.user-row .info { flex: 1; min-width: 0; }
.user-row .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-row .phone { font-size: 12px; color: var(--gray-400); }
.role-badge { font-size: 11px; font-weight: 700; padding: 4px 10px; border-radius: 999px; background: var(--sky-light); color: #0284c7; flex-shrink: 0; }

/* ---------- Forms / Modal ---------- */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--gray-500); margin-bottom: 4px; }
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--gray-200); border-radius: 12px; padding: 10px 12px; font-size: 14px;
  font-family: inherit; outline: none; background: #fff; color: var(--gray-900);
}
.field input:focus, .field select:focus, .field textarea:focus { box-shadow: 0 0 0 2px var(--sky); border-color: var(--sky); }
.field input:disabled { background: var(--gray-50); color: var(--gray-400); }
.hint { font-size: 12px; color: var(--gray-400); margin-top: 4px; line-height: 1.4; }
.form-error { color: var(--red); font-size: 13px; margin-bottom: 10px; }
.btn-danger {
  width: 100%; background: #fff; color: var(--red); border: 1px solid var(--red); border-radius: 12px;
  padding: 12px 0; font-size: 14px; font-weight: 600;
}
.btn-danger:active { background: #fef2f2; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal-box {
  background: #fff; width: 100%; max-width: 420px; border-radius: 18px 18px 0 0;
  padding: 16px 16px 24px; max-height: 85vh; overflow-y: auto;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.modal-head h3 { margin: 0; font-size: 16px; }
.modal-close { background: none; border: none; font-size: 22px; color: var(--gray-400); line-height: 1; }

@media (min-width: 640px) {
  .modal-overlay { align-items: center; }
  .modal-box { border-radius: 18px; }
}
