:root {
  color-scheme: dark;
  --bg: #0c0f12;
  --panel: #12171d;
  --line: #273240;
  --text: #d8e0e8;
  --muted: #9ca9b7;
  --accent: #35b66f;
}

* {
  box-sizing: border-box;
}

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

input,
select,
textarea,
button {
  font-size: 16px;
}

.app {
  max-width: 860px;
  margin: 0 auto;
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 16px;
  padding: 20px;
}

.classroom-layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 16px;
  min-height: 100vh;
  padding: 16px;
}

.top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.top h1 {
  margin: 0;
  font-size: 1.4rem;
}

.chat {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 12px;
  padding: 16px;
  overflow: auto;
}

.study {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 12px;
  padding: 12px;
}

.study-controls {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.study-controls input,
.study-controls select,
.exam-panel input {
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #0f141a;
  color: var(--text);
  padding: 8px;
  min-height: 44px;
}

.study-meta {
  color: var(--muted);
  font-size: 0.95rem;
  margin-bottom: 10px;
}

.chapters {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 10px;
}

.chapter-btn {
  font-size: 0.9rem;
  min-height: 42px;
  padding: 8px 6px;
}

.chapter-btn.done {
  background: #35b66f;
  color: #062311;
  border: none;
}

.chapter-btn.exam {
  border-color: #c89f37;
}

.exam-panel {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.lesson-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 10px;
  background: #0f141a;
}

.lesson-card textarea {
  width: 100%;
  margin-top: 8px;
  margin-bottom: 8px;
}

.lesson-card input {
  width: 100%;
  margin-bottom: 8px;
}

#adminUsers {
  display: grid;
  gap: 6px;
}

.admin-user-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.danger {
  background: #5c1f1f;
  border-color: #8a2c2c;
}

.admin-layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 16px;
  min-height: 100vh;
  padding: 16px;
}

.admin-sidebar {
  position: sticky;
  top: 16px;
  align-self: start;
  display: grid;
  gap: 10px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 12px;
  padding: 12px;
}

.admin-content {
  display: grid;
  gap: 12px;
}

.admin-section {
  scroll-margin-top: 16px;
}

.nav-btn {
  width: 100%;
  text-align: left;
}

.msg {
  padding: 12px;
  border-radius: 10px;
  margin-bottom: 10px;
  white-space: pre-wrap;
  line-height: 1.45;
}

.msg.user {
  background: #1b2430;
}

.msg.assistant {
  background: #112019;
  border: 1px solid #1e3b2c;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

textarea,
button {
  border-radius: 10px;
  border: 1px solid var(--line);
  font: inherit;
}

textarea {
  width: 100%;
  resize: vertical;
  min-height: 58px;
  background: #0f141a;
  color: var(--text);
  padding: 10px;
}

button {
  background: #1b2430;
  color: var(--text);
  padding: 11px 14px;
  cursor: pointer;
  min-height: 44px;
}

#sendBtn {
  background: var(--accent);
  color: #062311;
  border: none;
  font-weight: 700;
}

@media (max-width: 980px) {
  .classroom-layout {
    grid-template-columns: 1fr;
    padding: 10px;
    gap: 10px;
  }

  .study {
    padding: 10px;
  }

  .chapters {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .top {
    gap: 8px;
    align-items: flex-start;
    flex-direction: column;
  }

  .top h1 {
    font-size: 1.2rem;
  }

  .lesson-card h3 {
    margin-top: 0;
  }

  .exam-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .exam-panel > * {
    width: 100%;
  }

  .admin-layout {
    grid-template-columns: 1fr;
    padding: 10px;
    gap: 10px;
  }

  .admin-sidebar {
    position: static;
    grid-auto-flow: column;
    grid-auto-columns: minmax(150px, 1fr);
    overflow-x: auto;
    white-space: nowrap;
  }

  .nav-btn,
  .admin-sidebar a {
    text-align: center;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 8px;
    text-decoration: none;
    color: var(--text);
    background: #1b2430;
  }
}

@media (max-width: 560px) {
  .chapters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .exam-panel {
    grid-template-columns: 1fr;
  }
}
