/* ── Reset & base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #f0f4f8;
  color: #1a202c;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Navbar ── */
.navbar {
  background: #1e3a5f;
  padding: 0 2rem;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand {
  color: #fff;
  font-size: 1.15rem;
  font-weight: 700;
  text-decoration: none;
  letter-spacing: -.01em;
}

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

.nav-link {
  color: rgba(255,255,255,.75);
  text-decoration: none;
  padding: 0.35rem 0.85rem;
  border-radius: 6px;
  font-size: 0.9rem;
  transition: background .15s, color .15s;
}
.nav-link:hover { background: rgba(255,255,255,.12); color: #fff; }
.nav-link.active { background: rgba(255,255,255,.2); color: #fff; font-weight: 600; }

/* ── Main content ── */
.main-content {
  flex: 1;
  padding: 2rem;
  max-width: 960px;
  margin: 0 auto;
  width: 100%;
}

/* ── Page header ── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}
.page-header h1 { font-size: 1.6rem; font-weight: 700; color: #1e3a5f; }

/* ── Buttons ── */
.btn {
  padding: 0.45rem 1rem;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  transition: opacity .15s, transform .1s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary { background: #1e3a5f; color: #fff; }
.btn-primary:hover:not(:disabled) { opacity: .88; }
.btn-secondary { background: #e2e8f0; color: #2d3748; }
.btn-secondary:hover:not(:disabled) { background: #cbd5e0; }
.btn-ghost { background: transparent; color: #718096; border: 1px solid #e2e8f0; }
.btn-ghost:hover { background: #f7fafc; }
.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.8rem; }

/* ── Student card ── */
.student-card {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.04);
  margin-bottom: 1.5rem;
  overflow: hidden;
}

.student-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid #e8edf3;
  background: #f7fafc;
}

.student-name { font-size: 1.2rem; font-weight: 700; color: #1e3a5f; }
.student-school { font-size: 0.85rem; color: #718096; margin-top: 2px; }

/* ── Course rows ── */
.course-list { padding: 0.5rem 0; }

.course-row {
  padding: 0.7rem 1.5rem;
  border-bottom: 1px solid #f0f4f8;
  transition: background .1s;
}
.course-row:last-child { border-bottom: none; }
.course-row:hover { background: #f7fafc; }
.course-row.has-missing { border-left: 3px solid #f6ad55; }

.course-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  justify-content: space-between;
  flex-wrap: wrap;
}

.course-right { display: flex; align-items: center; gap: 0.5rem; }

.period {
  font-size: 0.75rem;
  font-weight: 700;
  color: #a0aec0;
  min-width: 28px;
}

.course-title { font-weight: 500; flex: 1; }
.teacher { font-size: 0.8rem; color: #a0aec0; }
.score { font-size: 0.8rem; color: #718096; }

/* ── Grade badges ── */
.grade-badge {
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.2rem 0.55rem;
  border-radius: 6px;
  min-width: 36px;
  text-align: center;
  display: inline-block;
}
.grade-a  { background: #c6f6d5; color: #22543d; }
.grade-b  { background: #bee3f8; color: #1a365d; }
.grade-c  { background: #fefcbf; color: #744210; }
.grade-d  { background: #fbd38d; color: #7b341e; }
.grade-f  { background: #fed7d7; color: #742a2a; }
.grade-na { background: #e2e8f0; color: #4a5568; }

/* ── Missing assignments ── */
.missing-list { margin-top: 0.4rem; padding-left: calc(28px + 0.75rem); }
.missing-item {
  font-size: 0.8rem;
  color: #c05621;
  padding: 0.15rem 0;
}
.due { color: #a0aec0; font-size: 0.75rem; }

/* ── Badges ── */
.badge {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
}
.badge-warn { background: #feebc8; color: #c05621; }
.badge-ok   { background: #c6f6d5; color: #276749; }

/* ── Loading & error ── */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4rem 2rem;
  color: #718096;
  gap: 1rem;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid #e2e8f0;
  border-top-color: #1e3a5f;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-card {
  background: #fff5f5;
  border: 1px solid #fed7d7;
  border-radius: 10px;
  padding: 1.5rem;
  color: #c53030;
}

/* ── Chat layout ── */
.main-content:has(.chat-layout) {
  max-width: 100%;
  padding: 0;
}

.chat-layout {
  display: flex;
  height: calc(100vh - 56px);
}

.chat-sidebar {
  width: 240px;
  flex-shrink: 0;
  background: #fff;
  border-right: 1px solid #e2e8f0;
  padding: 1.5rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.chat-sidebar h3 { font-size: 0.95rem; font-weight: 700; color: #1e3a5f; }
.sidebar-desc { font-size: 0.8rem; color: #718096; line-height: 1.5; }
.sidebar-tips { font-size: 0.8rem; color: #4a5568; line-height: 1.6; }
.sidebar-tips ul { padding-left: 1.1rem; margin-top: 0.3rem; }
.sidebar-tips li { margin-bottom: 0.2rem; }

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Messages ── */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.message { display: flex; }
.message.user { justify-content: flex-end; }
.message.assistant { justify-content: flex-start; }

.bubble {
  max-width: 72%;
  padding: 0.75rem 1rem;
  border-radius: 16px;
  line-height: 1.55;
  font-size: 0.9rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.message.user .bubble {
  background: #1e3a5f;
  color: #fff;
  border-bottom-right-radius: 4px;
}

.message.assistant .bubble {
  background: #fff;
  color: #1a202c;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08);
}

.bubble.streaming::after {
  content: '▌';
  animation: blink .7s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.file-attached {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  opacity: .8;
  margin-bottom: 0.3rem;
}

/* ── Chat input ── */
.chat-input-area {
  border-top: 1px solid #e2e8f0;
  background: #fff;
  padding: 0.75rem 1rem;
}

.file-preview {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: #ebf8ff;
  border-radius: 8px;
  padding: 0.4rem 0.75rem;
  margin-bottom: 0.5rem;
  font-size: 0.8rem;
  color: #2b6cb0;
}

.remove-file {
  background: none;
  border: none;
  cursor: pointer;
  color: #718096;
  font-size: 0.85rem;
  margin-left: auto;
  padding: 0;
  line-height: 1;
}
.remove-file:hover { color: #e53e3e; }

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
}

.upload-btn {
  cursor: pointer;
  font-size: 1.3rem;
  padding: 0.4rem;
  border-radius: 8px;
  line-height: 1;
  color: #718096;
  transition: background .15s;
  flex-shrink: 0;
}
.upload-btn:hover { background: #f0f4f8; }

.message-textarea {
  flex: 1;
  resize: none;
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 0.6rem 0.85rem;
  font-size: 0.9rem;
  font-family: inherit;
  line-height: 1.5;
  max-height: 140px;
  overflow-y: auto;
  outline: none;
  transition: border-color .15s;
}
.message-textarea:focus { border-color: #1e3a5f; }

.send-btn {
  background: #1e3a5f;
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 0.6rem 1.1rem;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity .15s;
}
.send-btn:hover:not(:disabled) { opacity: .85; }
.send-btn:disabled { opacity: .45; cursor: not-allowed; }

/* ── Google Classroom section ── */
.section-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: #1e3a5f;
  margin: 1.5rem 0 0.5rem;
  padding-left: 0.25rem;
}

.gc-list { display: flex; flex-direction: column; gap: 0.5rem; }

.gc-row {
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.gc-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  flex-wrap: wrap;
}

.gc-status {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.2rem 0.5rem;
  border-radius: 99px;
  text-transform: uppercase;
  white-space: nowrap;
}
.gc-assigned { background: #dbeafe; color: #1e40af; }
.gc-missing  { background: #fee2e2; color: #991b1b; }
.gc-done     { background: #dcfce7; color: #166534; }

.gc-course {
  font-size: 0.8rem;
  color: #64748b;
  white-space: nowrap;
}
.gc-title { font-weight: 500; font-size: 0.9rem; }

.gc-actions { margin-left: auto; }

.doc-link {
  font-size: 0.82rem;
  font-weight: 600;
  color: #1e3a5f;
  text-decoration: none;
  background: #e0e7ff;
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  white-space: nowrap;
}
.doc-link:hover { background: #c7d2fe; }
.review-link { background: #d1fae5; color: #065f46; margin-left: 0.35rem; }
.review-link:hover { background: #a7f3d0; }

.teacher-comment {
  width: 100%;
  font-size: 0.82rem;
  color: #92400e;
  background: #fef3c7;
  border-radius: 6px;
  padding: 0.35rem 0.6rem;
  margin-top: 0.25rem;
}

/* ── Responsive ── */
@media (max-width: 600px) {
  .chat-sidebar { display: none; }
  .main-content { padding: 1rem; }
  .bubble { max-width: 88%; }
}
