@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700&display=swap');

:root {
  --bg: #f6f7f8;
  --surface: #ffffff;
  --surface-soft: #f2f4f5;
  --surface-2: #eef2f3;
  --text: #1b2428;
  --text-soft: #5d6a71;
  --line: #dbe2e6;
  --line-strong: #c7d1d8;
  --brand: #136f63;
  --brand-hover: #0d5a50;
  --accent: #1f8f82;
  --danger: #c83f3f;
  --danger-hover: #a93535;
  --ok: #198754;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --shadow-sm: 0 6px 20px rgba(17, 27, 31, 0.05);
  --shadow-md: 0 16px 36px rgba(17, 27, 31, 0.08);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  font-family: 'Manrope', 'Segoe UI', sans-serif;
  background:
    radial-gradient(circle at 12% 4%, #ffffff 0%, #f4f6f7 44%, transparent 62%),
    radial-gradient(circle at 90% -20%, #e8f4f2 0%, transparent 52%),
    var(--bg);
  color: var(--text);
  line-height: 1.55;
}

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

.header {
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(9px);
  background: rgba(246, 247, 248, 0.86);
  border-bottom: 1px solid var(--line);
}

.header-content {
  max-width: 1320px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.header h1 {
  font-size: 1.22rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--text);
  white-space: nowrap;
}

.tabs {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.tab-btn {
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-soft);
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: 0.2s ease;
}

.tab-btn:hover {
  border-color: var(--line);
  background: var(--surface-2);
  color: var(--text);
}

.tab-btn.active {
  border-color: rgba(19, 111, 99, 0.22);
  background: #e7f4f2;
  color: var(--brand);
}

.auth-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.user-name {
  padding: 7px 11px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text-soft);
  font-size: 0.82rem;
}

.btn-logout,
.btn-primary,
.btn-small,
.btn-tiny {
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: 0.18s ease;
  font-weight: 600;
  font-family: inherit;
}

.btn-logout,
.btn-primary {
  background: var(--brand);
  color: #fff;
}

.btn-logout:hover,
.btn-primary:hover {
  background: var(--brand-hover);
}

.btn-logout,
.btn-secondary,
.btn-primary {
  padding: 10px 14px;
  font-size: 0.88rem;
}

.btn-secondary {
  background: var(--surface-soft);
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: 0.18s ease;
  font-weight: 600;
}

.btn-secondary:hover {
  background: #e8ecef;
}

.btn-small {
  padding: 8px 11px;
  background: var(--brand);
  color: #fff;
  font-size: 0.8rem;
}

.btn-small:hover {
  background: var(--brand-hover);
}

.btn-small:disabled {
  background: #9ab0b7;
  cursor: not-allowed;
}

.btn-large {
  width: 100%;
  padding: 12px 20px;
  font-size: 0.95rem;
}

.btn-tiny {
  padding: 6px 10px;
  background: var(--surface);
  color: var(--text-soft);
  border: 1px solid var(--line-strong);
  font-size: 0.75rem;
}

.btn-tiny:hover {
  background: var(--surface-soft);
  color: var(--text);
}

.btn-danger {
  background: var(--danger) !important;
  color: #fff !important;
  border-color: transparent !important;
}

.btn-danger:hover {
  background: var(--danger-hover) !important;
}

.main {
  flex: 1;
  max-width: 1320px;
  width: 100%;
  margin: 0 auto;
  padding: 20px;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

.container {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 22px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.section-header h2 {
  color: var(--text);
  font-size: 1.24rem;
  letter-spacing: 0.01em;
}

.courses-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 14px;
}

.course-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  overflow: hidden;
  cursor: pointer;
  transition: 0.22s ease;
  position: relative;
}

.course-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: #bfd0d8;
}

.course-card-image {
  width: 100%;
  height: 148px;
  background: linear-gradient(130deg, #cfe8e3 0%, #e8f2ef 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #48746b;
  font-size: 2.5rem;
}

.course-card-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.course-card-content {
  padding: 14px;
}

.course-card-content h3 {
  color: var(--text);
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 5px;
}

.course-card-content .badge {
  display: inline-block;
  margin-top: 6px;
  padding: 4px 8px;
  background: #edf4f3;
  color: #3f6a62;
  border: 1px solid #d5e6e3;
  border-radius: 999px;
  font-size: 0.72rem;
}

.course-card-actions {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
}

.course-detail {
  display: grid;
  grid-template-columns: minmax(250px, 300px) minmax(0, 1fr);
  gap: 14px;
  height: min(72vh, 680px);
}

.left-panel,
.right-panel {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #fff 0%, #fbfcfc 100%);
  border-radius: var(--radius-md);
  padding: 12px;
  overflow-y: auto;
}

.right-panel {
  display: grid;
  grid-template-rows: auto 1fr auto 1fr;
  gap: 10px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
  margin-bottom: 10px;
}

.panel-header h4 {
  margin: 0;
  color: var(--text);
  font-size: 0.94rem;
}

.sections-list,
.blocks-list,
.enrollment-list,
.progress-list {
  overflow-y: auto;
}

.section-item,
.block-item,
.enrollment-item,
.progress-item {
  padding: 10px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  cursor: pointer;
  transition: 0.18s ease;
}

.section-item:hover,
.block-item:hover,
.enrollment-item:hover,
.progress-item:hover {
  border-color: #bfd0d8;
  background: #eef3f4;
}

.section-item.selected {
  background: #e7f4f2;
  border-color: #a6cfc8;
}

.section-item-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.section-item-actions {
  flex-shrink: 0;
  display: flex;
  gap: 6px;
}

.item-title {
  color: var(--text);
  font-weight: 600;
  font-size: 0.88rem;
  margin-bottom: 3px;
}

.item-meta {
  color: var(--text-soft);
  font-size: 0.76rem;
}

.progress-bar {
  width: 100%;
  margin-top: 7px;
  height: 8px;
  border-radius: 999px;
  background: #dde6ea;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #158f7d 0%, #58b8ac 100%);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(17, 27, 31, 0.42);
  padding: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal.hidden {
  display: none;
}

.modal-content {
  width: min(760px, 100%);
  max-height: 100%;
  overflow-y: auto;
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-md);
  padding: 20px;
}

.modal-content.modal-wide {
  width: min(1160px, 100%);
}

.modal-header {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.modal-header h3 {
  margin-right: auto;
  color: var(--text);
  font-size: 1.1rem;
}

.modal-close {
  width: 30px;
  height: 30px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-soft);
  font-size: 1rem;
  cursor: pointer;
}

.modal-close:hover {
  background: var(--surface-soft);
  color: var(--text);
}

.form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 600;
}

.form-group input,
.form-group select,
.form-group textarea,
.filter-group select {
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--text);
  padding: 9px 11px;
  font-size: 0.88rem;
  font-family: inherit;
  transition: 0.18s ease;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus,
.filter-group select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 143, 130, 0.15);
}

.form-group input[type='checkbox'] {
  width: auto;
}

.form-group label:has(input[type='checkbox']) {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.json-textarea {
  min-height: 112px;
  resize: vertical;
  font-family: 'Cascadia Mono', 'Consolas', 'Courier New', monospace;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 2px;
}

.block-student-view {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.test-question,
.test-admin-item {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px;
  background: var(--surface-soft);
}

.test-question.read-only.correct {
  border-color: #b8dbc5;
  background: #edf8f1;
}

.test-question.read-only.wrong {
  border-color: #e8c4c4;
  background: #fbf1f1;
}

.test-question h5 {
  color: var(--text);
  font-size: 0.9rem;
  margin-bottom: 6px;
}

.test-options {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 6px;
}

.test-result,
.test-answer-line {
  color: var(--text-soft);
  font-size: 0.82rem;
}

.test-admin-controls {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.test-admin-list {
  display: grid;
  gap: 8px;
}

.admin-controls {
  margin-bottom: 14px;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.filter-group label {
  color: var(--text);
  font-size: 0.84rem;
  font-weight: 600;
}

.users-table {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}

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

thead {
  background: #f0f4f5;
}

th,
td {
  padding: 11px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 0.84rem;
}

th {
  color: var(--text);
  font-weight: 700;
}

td {
  color: var(--text-soft);
}

tbody tr:hover {
  background: #f5f8f9;
}

.user-role {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 0.74rem;
  font-weight: 700;
}

.user-role.admin {
  background: #fce8e8;
  color: #af2f2f;
}

.user-role.reviewer {
  background: #e6f4f1;
  color: #15695f;
}

.user-role.student {
  background: #e7f1fb;
  color: #2a5878;
}

.table-actions {
  display: flex;
  gap: 6px;
}

.profile-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.profile-card + .profile-card {
  margin-top: 10px;
}

.profile-content {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.profile-avatar {
  width: 90px;
  height: 90px;
  border-radius: 999px;
  flex-shrink: 0;
  overflow: hidden;
  color: #29564e;
  background: linear-gradient(140deg, #cae7e1 0%, #eef7f5 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
}

.profile-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.profile-info {
  flex: 1;
}

.profile-info h3 {
  margin-bottom: 4px;
  color: var(--text);
}

.profile-info p {
  margin-bottom: 4px;
  color: var(--text-soft);
  font-size: 0.87rem;
}

.profile-role {
  display: inline-block;
  margin-top: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  background: #e6f4f1;
  color: #15695f;
  font-weight: 700;
  font-size: 0.75rem;
}

.login-screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  background:
    radial-gradient(circle at 80% -10%, #d8efea 0%, transparent 52%),
    radial-gradient(circle at 0% 100%, #edf3f5 0%, transparent 56%),
    #f2f5f6;
}

.login-screen.hidden {
  display: none;
}

.login-card {
  width: min(420px, calc(100vw - 32px));
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  text-align: center;
  padding: 28px;
}

.login-card h1 {
  color: var(--text);
  margin-bottom: 8px;
  font-size: 1.62rem;
}

.login-card p {
  color: var(--text-soft);
  margin-bottom: 20px;
  font-size: 0.92rem;
}

@media (max-width: 1024px) {
  .header-content {
    align-items: flex-start;
    flex-direction: column;
  }

  .tabs {
    width: 100%;
  }

  .main {
    padding: 14px;
  }

  .container {
    padding: 16px;
  }

  .course-detail {
    grid-template-columns: 1fr;
    height: auto;
  }

  .right-panel {
    grid-template-rows: auto minmax(180px, auto) auto minmax(180px, auto);
  }
}

@media (max-width: 640px) {
  .main,
  .modal {
    padding: 10px;
  }

  .header-content {
    padding: 10px;
  }

  .auth-controls {
    width: 100%;
    justify-content: space-between;
  }

  .user-name {
    max-width: 56vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .section-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .courses-grid {
    grid-template-columns: 1fr;
  }

  .modal-content,
  .modal-content.modal-wide {
    width: 100%;
    max-height: calc(100vh - 20px);
    padding: 14px;
    border-radius: 14px;
  }

  .modal-header {
    gap: 6px;
  }

  .form-actions {
    justify-content: stretch;
  }

  .form-actions .btn-primary,
  .form-actions .btn-secondary,
  .form-actions .btn-small {
    flex: 1;
  }

  .table-actions {
    flex-wrap: wrap;
  }

  .profile-content {
    flex-direction: column;
    align-items: center;
    text-align: center;
  }

  .profile-info {
    width: 100%;
  }
}
