:root{
  --bg:#f6f7f8;
  --panel:#ffffff;
  --text:#1f2937;
  --muted:#6b7280;
  --border:#e5e7eb;
  --radius:12px;
  --chat-width: 900px;
}

/* Global */
*{ box-sizing:border-box }
html, body { height: 100% }

html {
  overflow-x: hidden; /* prevent horizontal scroll */
}

body{
  overflow: hidden; /* lock page scroll */
  margin: 0;
  font: 16px/1.45 system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  position: relative;
  width: 100%;
}

/* Course background image on body for full viewport coverage */
body::before{
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image: var(--course-bg-image);
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  filter: blur(80px);
  opacity: 0.24;
  z-index: 0;
  pointer-events: none;
}

/* Course page headers - extends navbar.css */
.course-header {
  /* Desktop navbar - inherits from navbar.css */
  position: fixed;
  width: 100%;
  top: 0;
  left: 0;
  z-index: 100;
}

.topbar{
  display:none;
  /* Mobile navbar - inherits from navbar.css */
  z-index: 100;
}

/* Main split layout */
.layout{
  display:grid; grid-template-columns:1fr; gap:0;
  height:100vh;
  overflow:hidden;           /* Prevent page scroll */
  padding-top: 92px;         /* Space for fixed navbar */
  position: relative;
}

/* Allow scroll areas to shrink properly */
.layout { min-height: 0; }
.sidebar { min-height: 0; }
.chat    { min-height: 0; }
.chat-thread { flex: 1; overflow: auto; }

.sidebar{
  background:var(--panel); border-left:1px solid var(--border);
  padding:16px; overflow:auto;
  padding-top: 32px;         /* Extra top padding for breathing room from navbar */
  position: fixed;
  top: 92px;
  right: 0;
  bottom: 0;
  width: 320px;
  transform: translateX(100%);
  transition: transform 0.3s ease;
  z-index: 30;
}

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

/* Overlay backdrop for desktop sidebar */
.sidebar-overlay{
  position: fixed;
  top: 92px;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.3);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  z-index: 29;
}

.sidebar-overlay.active{
  opacity: 1;
  visibility: visible;
}

/* Sidebar is solid white via background on the element */
.course-title{
  margin:0 0 16px 0; 
  font-size:18px;
  font-weight: 700;
  color: var(--text);
}

/* Chapters */
.chapters-heading{margin:6px 0 8px; font-weight:700; font-size:14px; color:var(--muted)}
.chapters{list-style:none; padding:0; margin:0}
.chapter{
  padding:10px 12px; border:1px solid var(--border); border-radius:10px;
  margin-bottom:8px; background:#fafafa;
  color: var(--muted);
}
.chapter.active{background:#e9f0ff; border-color:#d7e6ff; font-weight:700; color:#1f2937}
.chapter.locked{opacity:.55}

/* Course sidebar buttons - inherit from navbar.css */
/* All styling now from navbar.css (.btn, .btn-outline) */

/* Only course-specific overrides */
.btn-danger{
  color: #b91c1c;
  border-color: #fecaca;
  background: #fef2f2;
}

.btn-danger:hover{
  border-color: #fca5a5;
  background: #fee2e2;
}

/* Give the red reset button some space from whatever is above it */
.sidebar .btn-danger { 
  margin-top: 8px;
}

/* Chat area */
.chat{
  display:flex; flex-direction:column;
  height:100%;              /* Fill grid cell */
  position: relative;
  z-index: 1;
  /* No margin-top - background extends to navbar */
}

/* Chat blur overlay - matches sidebar blur */
.chat::before{
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg);
  backdrop-filter: blur(60px);
  -webkit-backdrop-filter: blur(60px);
  opacity: 0.2;
  z-index: -1;
  pointer-events: none;
}

.chat-thread{
  flex:1;
  overflow:auto;            /* ONLY this scrolls */
  padding:28px 16px 100px 16px;   /* Add horizontal padding here */
  position: relative;       /* Above background */
  z-index: 1;
}

.bubble .text h1{ font-size:20px; margin:8px 0 6px; }
.bubble .text h2{ font-size:18px; margin:8px 0 6px; }
.bubble .text h3{ font-size:16px; margin:8px 0 6px; }
.bubble .text h4{ font-size:15px; margin:6px 0 4px; }
.bubble .text h5{ font-size:14px; margin:6px 0 4px; }
.bubble .text h6{ font-size:13px; margin:6px 0 4px; }
.bubble .text code{ background:#f3f4f6; padding:2px 6px; border-radius:6px; font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; }

.meta{font-size:12px; color:var(--muted); margin-bottom:4px}

/* Composer */
.composer{
  position:sticky; bottom:0; left:0; right:0; z-index:20;
  background:linear-gradient(180deg, rgba(246,247,248,0) 0%, rgba(246,247,248,0.95) 24%);
  padding:10px 16px 12px 16px;
}
.composer-inner{
  display:flex; gap:8px; align-items:center;
  background:var(--panel); border:1px solid var(--border); border-radius:999px;
  padding:8px 10px;
}

/* Ensure forms in composer don't interfere with flex layout */
.composer-inner form{
  display: contents;
}

#chatInput {
  flex: 1;
  min-width: 0;
  border: none;
  outline: none;
  font-size: 16px;
  height: 44px;
  background: transparent;
}

/* Chat composer emoji buttons (different from navbar .btn-outline) */
.composer .btn-outline{
  border: 1px solid var(--border);
  background: transparent;
  border-radius: 50px;
  padding: 0.4rem 1rem;
  min-height: 44px;
  min-width: 44px;
  width: 44px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 28px;
  line-height: 1;
  transition: all 0.2s;
  color: var(--text);
  font-weight: 500;
}
.composer .btn-outline:hover:not([disabled]){
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.1);
  border-color: var(--text);
}
.composer .btn-outline[disabled]{opacity:.6; cursor:not-allowed}
.composer .btn-send:hover:not([disabled]){border-color:#93c5fd}
.composer .btn-understood:hover:not([disabled]){border-color:#86efac}
.composer .btn-congrats{border-color:#fde68a !important; color:#aa7a00}

/* Mobile / small screens */
@media (max-width: 900px){
  .course-header {
    display: none; /* Hide desktop navbar on mobile */
  }
  
  /* Hide desktop sidebar overlay on mobile */
  .sidebar-overlay{
    display: none;
  }
  
  .layout{
    grid-template-columns:1fr;
    height:100dvh; /* dynamic viewport height */
    overflow:hidden;            /* keep page locked */
    padding-top: 75px;          /* Space for fixed mobile navbar */
    width: 100%;
    max-width: 100vw;
  }
  
  /* Mobile background still covers entire viewport */
  .topbar{
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100vw;
    margin-left: calc(50% - 50vw);
    padding: 0.75rem 16px;
    padding-left:  max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }
  
  /* Match dashboard/settings navbar layout on mobile */
  .topbar .logo {
    z-index: 2;
  }
  
  .topbar .page-title {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1;
  }
  
  .topbar .hamburger-course {
    z-index: 2;
  }

  /* Sidebar as overlay on mobile - slides from top */
  .sidebar{
    position:fixed; 
    inset:75px 0 auto 0; 
    width:100%;
    top: 75px;
    right: auto;
    bottom: auto;
    left: 0;
    max-height:calc(100dvh - 75px);
    transform:translateY(-110%);
    transition:transform .18s ease;
    border-left:none; 
    border-right:none; 
    border-bottom:1px solid var(--border);
    border-radius:0 0 16px 16px; 
    padding:14px 16px; 
    z-index:25;
    overflow:auto;
    background:var(--panel);
  }
  
  .sidebar.open{
    transform:translateY(0);
  }

  .chat{
    padding:0;
    width: 100%;
    max-width: 100vw;
    overflow-x: hidden;
  }
  
  .chat-thread{
    padding:12px 12px 100px 12px;
    width: 100%;
  }
  
  .composer{
    padding:10px 0 12px 0;
    width: 100%;
    max-width: 100vw;
  }
  
  .composer-inner{
    margin:0 12px;
    width: calc(100% - 24px);
  }

  /* Mobile: tutor messages centered with equal spacing */
  .bubble.assistant{ margin-right:auto; }
  .bubble.user{ margin-left:10%; margin-right:auto; }
}

/* Desktop: unify background across the full content area to match chat */
@media (min-width: 901px){
  .layout::before{
    content: '';
    position: absolute;
    inset: 0;
    background: var(--bg);
    backdrop-filter: blur(60px);
    -webkit-backdrop-filter: blur(60px);
    opacity: 0.2;
    z-index: 0;
    pointer-events: none;
  }

  /* Remove chat-only overlay on desktop to avoid double layering */
  .chat::before{ content: none; }

  /* Unify bottom background: remove composer gradient on desktop */
  .composer{ background: transparent; }
}

/* Narrow, centered chat on wide screens */
@media (min-width: 1200px) {
  /* center and cap width of the chat column pieces */
  .chat,
  .chat-thread,
  .composer {
    width: 100%;
    max-width: var(--chat-width);
    margin-left: auto;
    margin-right: auto;
  }
}

/* Message bubble look */
.bubble{
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 14px;
  margin: 8px 0;
  max-width: 100%;
  box-shadow: 0 1px 0 rgba(0,0,0,.02);
}
.bubble.assistant{ margin-right: auto; }  /* left-side */

.bubble.user {
  margin-right: auto;
  margin-left: 10%;
  background: #e9f0ff;
  border-color: #d7e6ff;
}
/* Quota Modal Styles */
.modal {
  display: none;
  position: fixed;
  z-index: 9999;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}

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

.modal-content {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 0;
  max-width: 500px;
  width: 90%;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  animation: slideUp 0.3s ease;
  overflow: hidden;
}

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

.modal-header {
  padding: 24px 24px 16px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  margin: 0;
  font-size: 24px;
  font-weight: 600;
  color: var(--text);
}

.modal-body {
  padding: 24px;
  color: var(--text);
  line-height: 1.6;
}

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

.modal-body p:first-child {
  font-size: 16px;
  margin-bottom: 20px;
}

.modal-body strong {
  color: var(--text);
  font-weight: 600;
}

.modal-actions {
  padding: 16px 24px 24px 24px;
  display: flex;
  gap: 12px;
  flex-direction: column;
}

.modal-actions .btn {
  width: 100%;
  text-align: center;
  justify-content: center;
  padding: 12px 24px;
  font-size: 16px;
  font-weight: 600;
}

.modal-actions .btn-primary {
  background: var(--accent);
  color: white;
  border: none;
}

.modal-actions .btn-primary:hover {
  background: var(--accent-hover);
}

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

.modal-actions .btn-outline:hover {
  background: var(--hover);
}

@media (min-width: 600px) {
  .modal-actions {
    flex-direction: row;
  }
  
  .modal-actions .btn {
    flex: 1;
  }
}

/* Quota Exceeded Modal */
.quota-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  z-index: 10000;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  animation: fadeIn 0.2s ease-out;
}

.quota-modal.show {
  display: flex;
}

.quota-modal-content {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 2rem;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  text-align: center;
  animation: slideUp 0.3s ease-out;
}

.quota-modal-icon {
  font-size: 3.5rem;
  margin-bottom: 1rem;
  animation: bounce 0.6s ease-out;
}

.quota-modal-title {
  font-size: 1.5rem;
  font-weight: 600;
  margin: 0 0 1rem 0;
  color: var(--text);
}

.quota-modal-text {
  font-size: 1rem;
  margin: 0 0 0.75rem 0;
  color: var(--text);
  line-height: 1.6;
}

.quota-modal-text strong {
  color: var(--text);
  font-weight: 600;
}

.quota-modal-subtext {
  font-size: 0.95rem;
  margin: 0 0 1.75rem 0;
  color: var(--muted);
  line-height: 1.6;
}

.quota-modal-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.quota-modal-actions .btn {
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  border: none;
  font-size: 1rem;
}

.quota-modal-actions .btn-primary {
  background: var(--text);
  color: white;
}

.quota-modal-actions .btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.quota-modal-actions .btn-secondary {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.quota-modal-actions .btn-secondary:hover {
  background: var(--bg);
  color: var(--text);
}

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

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

@keyframes bounce {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.1);
  }
}

/* Confirmation Modal */
.confirm-modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  z-index: 10000;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  animation: fadeIn 0.2s ease-out;
}

.confirm-modal.show {
  display: flex;
}

.confirm-modal-content {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 2rem;
  max-width: 480px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  text-align: center;
  animation: slideUp 0.3s ease-out;
}

.confirm-modal-icon {
  font-size: 3.5rem;
  margin-bottom: 1rem;
  animation: bounce 0.6s ease-out;
}

.confirm-modal-message {
  font-size: 1rem;
  margin: 0 0 1.75rem 0;
  color: var(--text);
  line-height: 1.6;
  white-space: pre-line;
}

.confirm-modal-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.confirm-modal-actions .btn {
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  border: none;
  font-size: 1rem;
}

.confirm-modal-actions .btn-primary {
  background: var(--text);
  color: white;
}

.confirm-modal-actions .btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.confirm-modal-actions .btn-secondary {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.confirm-modal-actions .btn-secondary:hover {
  background: var(--bg);
  color: var(--text);
}
