html {
  font-size: 14px;
}

@media (min-width: 768px) {
  html {
    font-size: 16px;
  }
}

.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
  box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb;
}

html {
  position: relative;
  min-height: 100%;
}

body {
  margin-bottom: 60px;
}

:root {
  --ai-surface: #f7f8fb;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  width: 240px;
  background: #ffffff;
  border-right: 1px solid #e6e6e6;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.sidebar-brand .navbar-brand {
  font-weight: 600;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.sidebar-nav .nav-link {
  color: #111;
  border-radius: 10px;
  padding: 8px 10px;
}

.sidebar-nav .nav-link:hover {
  background: #f4f5f7;
}

.sidebar-footer {
  margin-top: auto;
}

.sidebar-user {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.main-content {
  flex: 1;
  padding: 20px;
}

.mobile-topbar {
  display: none;
}

/* AI Tutor chat page */
.ai-tutor-page {
  min-height: calc(100vh - 120px);
  background: transparent;
  border-radius: 0;
  padding: 0;
}

.ai-tutor-grid {
  display: grid;
  grid-template-columns: minmax(260px, 0.95fr) minmax(320px, 1.4fr);
  gap: 24px;
  align-items: start;
}

.ai-tutor-panel {
  background: var(--ai-surface);
  border: 1px solid #e1e6ef;
  border-radius: 18px;
  padding: 20px;
  box-shadow: 0 12px 30px rgba(20, 35, 60, 0.08);
}

.login-panel {
  max-width: 520px;
  margin: 0 auto;
}

.login-page {
  display: block;
}

.modal-content {
  background: var(--ai-surface);
}

.ai-panel-header {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.ai-panel-title {
  font-size: 1.4rem;
  font-weight: 600;
  margin: 0;
}

.ai-panel-subtitle {
  font-size: 0.95rem;
  color: #5c6677;
}

.ai-config-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ai-config-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: #2a3242;
}

.ai-config-textarea,
.ai-config-input {
  border-radius: 14px;
  border: 1px solid #d6dbe6;
  background: #fff;
}

.ai-config-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.ai-config-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.ai-config-hint {
  font-size: 0.8rem;
  color: #6b7280;
}

.ai-chat-shell {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: #ffffff;
  border: 1px solid #e6e6e6;
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
}

.ai-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #eee;
  padding-bottom: 12px;
}

.ai-chat-title {
  font-size: 1.35rem;
  font-weight: 600;
  margin: 0;
}

.ai-chat-subtitle {
  color: #666;
  font-size: 0.9rem;
}

.ai-chat-thread {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 8px 4px;
  overflow-y: visible;
}

.ai-chat-bubble {
  max-width: 80%;
  padding: 12px 14px;
  border-radius: 14px;
  line-height: 1.4;
  white-space: pre-wrap;
}

.ai-chat-bubble.user {
  margin-left: auto;
  background: #0d6efd;
  color: #fff;
  border-bottom-right-radius: 4px;
}

.ai-chat-bubble.assistant {
  margin-right: auto;
  background: transparent;
  color: #111;
  border-bottom-left-radius: 4px;
}

.ai-chat-bubble.assistant > * {
  margin-top: 0;
  margin-bottom: 0.5rem;
}

.ai-chat-bubble.assistant > *:last-child {
  margin-bottom: 0;
}

.ai-chat-bubble.assistant p,
.ai-chat-bubble.assistant ul,
.ai-chat-bubble.assistant ol,
.ai-chat-bubble.assistant blockquote,
.ai-chat-bubble.assistant pre,
.ai-chat-bubble.assistant h1,
.ai-chat-bubble.assistant h2,
.ai-chat-bubble.assistant h3,
.ai-chat-bubble.assistant h4,
.ai-chat-bubble.assistant h5,
.ai-chat-bubble.assistant h6 {
  margin-top: 0;
  margin-bottom: 0.5rem;
}

.ai-chat-bubble.assistant li {
  margin-bottom: 0.25rem;
}

.ai-chat-bubble.pending {
  opacity: 0.7;
  font-style: italic;
}

.ai-chat-input {
  display: flex;
  gap: 10px;
  align-items: center;
  border-top: 1px solid #eee;
  padding-top: 12px;
}

.ai-chat-input textarea {
  resize: none;
  min-height: 52px;
  border-radius: 16px;
}

.ai-chat-send {
  white-space: nowrap;
}

@media (max-width: 768px) {
  .mobile-topbar {
    position: sticky;
    top: 0;
    z-index: 1001;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: #ffffff;
    border-bottom: 1px solid #e6e6e6;
  }

  .mobile-brand {
    font-weight: 600;
  }

  .layout-shell {
    flex-direction: column;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 240px;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    z-index: 1000;
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  body.sidebar-open::before {
    content: "";
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.2);
    z-index: 999;
  }

  .sidebar-nav {
    flex-direction: column;
    flex-wrap: nowrap;
    gap: 8px;
  }

  .sidebar-nav .nav-link {
    padding: 6px 8px;
    font-size: 0.9rem;
  }

  .main-content {
    padding: 12px;
    margin-top: 6px;
  }

  .ai-chat-shell {
    border-radius: 12px;
    padding: 12px;
  }

  .ai-chat-bubble {
    max-width: 100%;
  }

  .ai-chat-input {
    flex-direction: column;
    align-items: stretch;
  }

  .ai-chat-send {
    width: 100%;
  }

  .ai-tutor-grid {
    grid-template-columns: 1fr;
  }

  .ai-chat-thread {
    max-height: none;
  }
}
  .login-panel {
    max-width: 640px;
    width: 92%;
    margin: 0 auto;
    padding: 24px;
  }

  .login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 120px);
    padding: 24px 0;
  }
