:root {
  --bg: #0b0d12;
  --surface: #141820;
  --surface-2: #1c2230;
  --border: #2a3344;
  --text: #e8ecf4;
  --muted: #8b95a8;
  --accent: #6c8cff;
  --accent-glow: rgba(108, 140, 255, 0.35);
  --bot: #1a2235;
  --user: linear-gradient(135deg, #4f6ef7, #7b5cf0);
  --radius: 16px;
  --font: "Inter", system-ui, sans-serif;
}

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

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
}

.bg-glow {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(ellipse 60% 40% at 20% 0%, var(--accent-glow), transparent 55%),
    radial-gradient(ellipse 50% 30% at 90% 80%, rgba(123, 92, 240, 0.15), transparent 50%);
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  max-width: 720px;
  margin: 0 auto;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 1rem 1rem 0.75rem;
}

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 0.75rem;
  animation: fadeIn 0.5s ease;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.logo-icon {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--accent);
  font-size: 1.1rem;
}

.logo h1 {
  font-size: 1.1rem;
  font-weight: 600;
}

.logo p {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 2px;
}

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--muted);
  transition: background 0.3s, box-shadow 0.3s;
}

.status-dot.warming {
  background: #e8b84a;
  box-shadow: 0 0 10px rgba(232, 184, 74, 0.5);
  animation: status-pulse 1.2s ease-in-out infinite;
}

.status-dot.online {
  background: #3dd68c;
  box-shadow: 0 0 12px rgba(61, 214, 140, 0.6);
}

@keyframes status-pulse {
  50% { opacity: 0.55; }
}

.chat {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding: 0.5rem 0 1rem;
  scroll-behavior: smooth;
}

.chat::-webkit-scrollbar {
  width: 6px;
}

.chat::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.message {
  display: flex;
  gap: 0.65rem;
  max-width: 92%;
  animation: slideUp 0.35s ease;
}

.message.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.avatar {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 0.65rem;
  font-weight: 600;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--accent);
}

.message.user .avatar {
  background: var(--user);
  border: none;
  color: #fff;
}

.bubble {
  padding: 0.85rem 1rem;
  border-radius: var(--radius);
  line-height: 1.55;
  font-size: 0.92rem;
}

.message.bot .bubble {
  background: var(--bot);
  border: 1px solid var(--border);
  border-top-left-radius: 4px;
}

.message.user .bubble {
  background: var(--user);
  color: #fff;
  border-top-right-radius: 4px;
}

.meta {
  margin-top: 0.5rem;
  font-size: 0.7rem;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.meta .tag {
  background: var(--surface);
  padding: 0.15rem 0.45rem;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.typing .bubble {
  display: flex;
  gap: 4px;
  padding: 1rem 1.2rem;
}

.typing span {
  width: 6px;
  height: 6px;
  background: var(--muted);
  border-radius: 50%;
  animation: bounce 1.2s infinite;
}

.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }

.composer {
  padding-top: 0.5rem;
  animation: fadeIn 0.6s ease 0.2s both;
}

.composer form {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0.5rem 0.5rem 1rem;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.composer form:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.composer textarea {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  resize: none;
  min-height: calc(1.4em * 2 + 0.5rem);
  max-height: 140px;
  outline: none;
  line-height: 1.4;
  overflow-y: auto;
}

.composer button {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 12px;
  background: var(--user);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: transform 0.15s, opacity 0.2s;
}

.composer button:hover:not(:disabled) {
  transform: scale(1.05);
}

.composer button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.hint {
  text-align: center;
  font-size: 0.68rem;
  color: var(--muted);
  margin-top: 0.5rem;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-5px); }
}

/* === School landing === */
.school-page {
  position: relative;
  z-index: 1;
  max-width: 960px;
  margin: 0 auto;
  padding: 1.25rem 1.5rem 6rem;
}

.school-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 0 1.5rem;
  animation: fadeIn 0.5s ease;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 600;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--user);
  display: grid;
  place-items: center;
  font-weight: 700;
  color: #fff;
}

.nav-links {
  display: flex;
  gap: 1.25rem;
}

.nav-links a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  transition: color 0.2s;
}

.nav-links a:hover { color: var(--text); }

.nav-cta {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem 1rem;
  border-radius: 10px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.85rem;
}

.hero {
  padding: 2rem 0 2.5rem;
  animation: slideUp 0.6s ease;
}

.hero-badge {
  display: inline-block;
  font-size: 0.75rem;
  color: var(--accent);
  background: rgba(108, 140, 255, 0.12);
  border: 1px solid rgba(108, 140, 255, 0.3);
  padding: 0.35rem 0.75rem;
  border-radius: 999px;
  margin-bottom: 1rem;
}

.hero h1 {
  font-size: clamp(1.75rem, 5vw, 2.75rem);
  line-height: 1.15;
  font-weight: 700;
}

.hero h1 span {
  background: linear-gradient(90deg, #8aa4ff, #b08cff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.hero-lead {
  margin-top: 1rem;
  max-width: 540px;
  color: var(--muted);
  line-height: 1.6;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

.btn-primary, .btn-ghost {
  font-family: inherit;
  padding: 0.7rem 1.25rem;
  border-radius: 12px;
  cursor: pointer;
  font-size: 0.9rem;
  border: none;
  transition: transform 0.15s;
}

.btn-primary {
  background: var(--user);
  color: #fff;
}

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-primary:hover, .btn-ghost:hover { transform: translateY(-1px); }

a.btn-primary,
a.btn-ghost,
a.nav-cta {
  text-decoration: none;
  display: inline-block;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
  margin-bottom: 2.5rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
}

.stat-card strong {
  display: block;
  font-size: 1.5rem;
  color: var(--accent);
}

.stat-card span { font-size: 0.8rem; color: var(--muted); }

.modules-section h2, .format-section h2 {
  font-size: 1.25rem;
  margin-bottom: 1rem;
}

.modules-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: 2rem;
}

.module-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem;
  transition: border-color 0.2s, transform 0.2s;
}

.module-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.module-num {
  font-size: 0.7rem;
  color: var(--accent);
  font-weight: 600;
}

.module-card h3 { margin: 0.4rem 0; font-size: 1rem; }
.module-card p { font-size: 0.85rem; color: var(--muted); }

.format-list {
  list-style: none;
  display: grid;
  gap: 0.5rem;
  color: var(--muted);
}

.format-list li::before {
  content: "✦ ";
  color: var(--accent);
}

.school-footer {
  text-align: center;
  padding: 2rem 0;
  color: var(--muted);
  font-size: 0.8rem;
}

/* === Chat widget === */
.chat-fab {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 1000;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  border: none;
  background: var(--user);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 8px 32px rgba(79, 110, 247, 0.45);
  display: grid;
  place-items: center;
  transition: transform 0.25s, box-shadow 0.25s;
}

.chat-fab:hover { transform: scale(1.06); }

.chat-fab .fab-icon-close { display: none; }
.chat-fab.is-open .fab-icon-open { display: none; }
.chat-fab.is-open .fab-icon-close { display: block; }

.fab-pulse {
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid rgba(108, 140, 255, 0.5);
  animation: fabPulse 2s ease-out infinite;
  pointer-events: none;
}

.chat-fab.is-open .fab-pulse { display: none; }

@keyframes fabPulse {
  0% { transform: scale(1); opacity: 0.8; }
  100% { transform: scale(1.35); opacity: 0; }
}

.chat-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 1001;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

.chat-backdrop.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.chat-panel {
  position: fixed;
  right: 1.25rem;
  bottom: 5.5rem;
  z-index: 1002;
  width: min(400px, calc(100vw - 2rem));
  height: min(520px, calc(100dvh - 7rem));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(0.96);
  pointer-events: none;
  transition: opacity 0.3s, transform 0.3s;
}

.chat-panel.is-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.chat-header-info h2 { font-size: 0.95rem; font-weight: 600; }
.chat-header-info p { font-size: 0.7rem; color: var(--muted); }

.chat-panel .chat {
  flex: 1;
  padding: 0.75rem 1rem;
  min-height: 0;
}

.chat-panel .composer {
  padding: 0.5rem 0.75rem 0.75rem;
  flex-shrink: 0;
}

@media (max-width: 640px) {
  .nav-links { display: none; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .modules-grid { grid-template-columns: 1fr; }
  .chat-panel {
    right: 0.5rem;
    left: 0.5rem;
    width: auto;
    bottom: 5rem;
  }
}

/* Analytics dashboard (учебный пример) */
.analytics-page {
  position: relative;
  z-index: 1;
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.25rem 1.5rem 3rem;
}

.nav-brand-link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: inherit;
  text-decoration: none;
}

.nav-links a.nav-active {
  color: var(--accent);
}

.analytics-header {
  margin: 1.5rem 0 1.25rem;
}

.analytics-header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 0.35rem;
}

.analytics-subtitle {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
}

.analytics-subtitle code {
  font-size: 0.85em;
  color: var(--text);
}

.analytics-refresh { margin-top: 0.25rem; }

.analytics-error {
  color: #f87171;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.analytics-kpi { margin-bottom: 1.5rem; }

.analytics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}

.analytics-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}

.analytics-panel-wide { margin-bottom: 1rem; }

.analytics-panel h2 {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
}

.analytics-empty {
  color: var(--muted);
  font-size: 0.85rem;
}

.bar-chart { display: flex; flex-direction: column; gap: 0.5rem; }

.bar-row {
  display: grid;
  grid-template-columns: 7rem 1fr 2rem;
  gap: 0.5rem;
  align-items: center;
  font-size: 0.8rem;
}

.bar-label {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-track {
  height: 8px;
  background: var(--surface-2);
  border-radius: 4px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #7b5cf0);
  border-radius: 4px;
  min-width: 4px;
}

.bar-value {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.analytics-table-wrap {
  overflow-x: auto;
  max-height: 320px;
  overflow-y: auto;
}

.analytics-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.analytics-table th,
.analytics-table td {
  text-align: left;
  padding: 0.45rem 0.5rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.analytics-table th {
  color: var(--muted);
  font-weight: 500;
  position: sticky;
  top: 0;
  background: var(--surface);
}

.analytics-table .num { text-align: right; white-space: nowrap; }
.analytics-table .nowrap { white-space: nowrap; }
.analytics-table .q-cell { max-width: 280px; word-break: break-word; }

@media (max-width: 768px) {
  .analytics-grid { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 5rem 1fr 1.5rem; }
}
