*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  min-height: 100vh;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: linear-gradient(to bottom right, #7d2fc0 0%, #ffffff 100%);
  background-repeat: no-repeat;
  background-attachment: fixed;
  color: #ffffff;
}

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

.sidebar {
  width: clamp(240px, 22.5vw, 326px);
  flex-shrink: 0;
  padding: 30px 18px 18px;
  display: flex;
  flex-direction: column;
}

.brand {
  display: flex;
  justify-content: center;
  margin-bottom: 28px;
}

.brand-logo {
  width: 150px;
  max-width: 100%;
  height: auto;
  display: block;
  user-select: none;
}

.lessons-nav {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.lesson-item {
  width: 100%;
  padding: 10px 14px;
  border: none;
  border-radius: 0;
  background: rgba(0, 0, 0, 0.35);
  color: #ffffff;
  font-family: inherit;
  font-size: 16px;
  font-weight: 400;
  line-height: 1.3;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.lesson-item:hover {
  background: rgba(0, 0, 0, 0.45);
}

.lesson-item.is-active {
  background: rgba(0, 0, 0, 0.56);
}

.main-area {
  flex: 1;
  min-width: 0;
  margin: 8px 12px 12px 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.top-nav {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
}

.top-btn {
  width: 100%;
  padding: 8px 10px;
  border: none;
  border-radius: 0;
  background: rgba(0, 0, 0, 0.38);
  color: #ffffff;
  font-family: inherit;
  font-size: 14px;
  font-weight: 400;
  line-height: 1.2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.top-btn:hover {
  background: rgba(0, 0, 0, 0.48);
}

.top-btn.is-active {
  background: rgba(0, 0, 0, 0.58);
}

.content-panel {
  flex: 1;
  background: rgba(0, 0, 0, 0.38);
  padding: 28px 32px;
  overflow-y: auto;
}

/* Reader view */
.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.14);
}

.panel-breadcrumb {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.72);
}

.lesson-body {
  max-width: 820px;
  line-height: 1.7;
  font-size: 16px;
  color: rgba(255, 255, 255, 0.94);
}

.lesson-body h1 {
  margin: 0 0 14px;
  font-size: 28px;
  line-height: 1.25;
}

.lesson-body h2 {
  margin: 20px 0 10px;
  font-size: 21px;
  line-height: 1.3;
}

.lesson-body p {
  margin: 0 0 12px;
}

.lesson-body ul {
  margin: 0 0 14px;
  padding-left: 22px;
}

.lesson-body li + li {
  margin-top: 4px;
}

.empty-note {
  color: rgba(255, 255, 255, 0.68);
  font-style: italic;
}

/* Profile & Admin */
.profile-box {
  max-width: 920px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.auth-card,
.admin-section {
  background: rgba(0, 0, 0, 0.26);
  border: 1px solid rgba(255, 255, 255, 0.14);
  padding: 20px;
}

.auth-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.user-name {
  font-weight: 600;
  font-size: 16px;
}

.user-sub {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.72);
}

.role-pill {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 600;
  background: rgba(125, 47, 192, 0.8);
  color: #ffffff;
}

.admin-grid {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 18px;
}

.admin-section h2,
.auth-card h2 {
  margin: 0 0 12px;
  font-size: 18px;
}

.admin-section p,
.auth-card p {
  margin: 0 0 12px;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.8);
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.field span {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.78);
}

.input,
.select,
.textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(0, 0, 0, 0.34);
  color: #ffffff;
  font-family: inherit;
  font-size: 14px;
}

.select option {
  background: #271a38;
  color: #ffffff;
}

.textarea {
  min-height: 240px;
  resize: vertical;
  line-height: 1.55;
}

.format-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.tool-btn,
.ui-btn {
  padding: 7px 12px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  background: rgba(0, 0, 0, 0.35);
  color: #ffffff;
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.tool-btn:hover,
.ui-btn:hover {
  background: rgba(0, 0, 0, 0.55);
}

.ui-btn-primary {
  background: #7d2fc0;
  border-color: rgba(255, 255, 255, 0.3);
  font-weight: 600;
}

.ui-btn-primary:hover {
  background: #8f3fd4;
}

.ui-btn-danger {
  background: rgba(185, 35, 55, 0.55);
}

.ui-btn-danger:hover {
  background: rgba(185, 35, 55, 0.8);
}

.ui-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.list-editor {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.list-editor-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.tabs-editor {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 14px;
}

.save-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}

.status-msg {
  font-size: 13px;
  color: #d8b4fe;
}

.setup-code {
  display: block;
  padding: 10px 12px;
  background: rgba(0, 0, 0, 0.42);
  border: 1px solid rgba(255, 255, 255, 0.15);
  font-family: Consolas, monospace;
  font-size: 12px;
  white-space: pre-wrap;
  color: rgba(255, 255, 255, 0.9);
  margin-bottom: 12px;
}

.telegram-widget-wrap {
  margin: 12px 0;
}

@media (max-width: 900px) {
  .admin-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .app-shell {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    padding-bottom: 12px;
  }

  .main-area {
    margin: 0 12px 12px;
    flex: 1;
  }

  .top-nav {
    grid-template-columns: repeat(3, 1fr);
  }

  .content-panel {
    padding: 20px;
    min-height: 55vh;
  }

  .field-row {
    grid-template-columns: 1fr;
  }
}
