/* ============================================================
   MTH10203 Sources — Main Stylesheet
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@300;400;500;600;700&display=swap');

:root {
  --navy:        #1e3a5f;
  --navy-dark:   #152c48;
  --blue:        #2563eb;
  --blue-light:  #dbeafe;
  --amber:       #f59e0b;
  --amber-light: #fef3c7;
  --green:       #059669;
  --green-light: #d1fae5;
  --red:         #dc2626;
  --text:        #1e293b;
  --text-muted:  #64748b;
  --bg:          #f1f5f9;
  --card:        #ffffff;
  --border:      #e2e8f0;
  --shadow:      0 2px 8px rgba(0,0,0,0.08);
  --shadow-md:   0 4px 20px rgba(0,0,0,0.12);
  --radius:      12px;
  --radius-sm:   8px;
  --nav-h:       52px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: 'Sarabun', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.65;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Container ── */
.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 1rem;
}

/* ── Header ── */
.site-header {
  background: linear-gradient(135deg, var(--navy-dark) 0%, var(--navy) 60%, #2563eb 100%);
  color: white;
  padding: 2rem 0 1.75rem;
  text-align: center;
  box-shadow: 0 4px 24px rgba(0,0,0,0.25);
  position: relative;
  overflow: hidden;
}
.site-header::before {
  content: '';
  position: absolute;
  inset: 0;
  background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none'%3E%3Cg fill='%23ffffff' fill-opacity='0.04'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
}
.header-inner { position: relative; }
.site-header h1 {
  font-size: clamp(1.4rem, 5vw, 2rem);
  font-weight: 700;
  letter-spacing: -0.5px;
}
.site-header .badge {
  display: inline-block;
  background: rgba(255,255,255,0.18);
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 20px;
  padding: 0.2rem 0.85rem;
  font-size: 0.82rem;
  margin-bottom: 0.4rem;
  letter-spacing: 0.5px;
}
.site-header .subtitle {
  font-size: 0.9rem;
  opacity: 0.8;
  margin-top: 0.25rem;
}
.admin-link {
  position: absolute;
  top: 0.75rem;
  right: 1rem;
  color: rgba(255,255,255,0.5);
  font-size: 0.78rem;
  transition: color 0.2s;
}
.admin-link:hover { color: white; text-decoration: none; }

/* ── Announcements ── */
#announcements-section { padding: 1.25rem 0 0; }
.announcement-card {
  background: linear-gradient(135deg, #fffbeb, #fef3c7);
  border: 1px solid #fcd34d;
  border-left: 4px solid var(--amber);
  border-radius: var(--radius-sm);
  padding: 0.9rem 1rem;
  margin-bottom: 0.65rem;
  display: flex;
  gap: 0.65rem;
  align-items: flex-start;
}
.announcement-icon { font-size: 1.1rem; flex-shrink: 0; margin-top: 0.1rem; }
.announcement-title { font-weight: 600; font-size: 0.92rem; margin-bottom: 0.15rem; }
.announcement-content { font-size: 0.875rem; color: var(--text-muted); white-space: pre-wrap; }

/* ── Page Nav (replaces tabs) ── */
.nav-wrapper {
  background: var(--card);
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 1px solid var(--border);
}

.page-nav {
  display: flex;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  gap: 0;
}
.page-nav::-webkit-scrollbar { display: none; }

.nav-link {
  flex: 1;
  min-width: 130px;
  padding: 0 1rem;
  height: var(--nav-h);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-muted);
  text-decoration: none;
  position: relative;
  white-space: nowrap;
  transition: color 0.2s;
  border-bottom: 3px solid transparent;
}
.nav-link:hover { color: var(--navy); text-decoration: none; background: var(--bg); }
.nav-link.active { color: var(--navy); font-weight: 600; border-bottom-color: var(--amber); }

/* ── Content Sections ── */
main { padding-bottom: 3rem; }

.content-section {
  padding: 2rem 0 2.5rem;
  scroll-margin-top: calc(var(--nav-h) + 8px);
}

.section-divider {
  height: 1px;
  background: var(--border);
  margin: 0;
}

/* ── Section Heading ── */
.section-heading {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--navy);
  margin-bottom: 1.1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--blue-light);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* ── Quiz + Assignment Grid ── */
.qa-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

.qa-column-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--navy);
  margin-bottom: 0.65rem;
  padding: 0.45rem 0.75rem;
  background: var(--blue-light);
  border-radius: var(--radius-sm);
}

.qa-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.8rem 0.9rem;
  margin-bottom: 0.55rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  box-shadow: var(--shadow);
}
.qa-item-label {
  font-weight: 500;
  font-size: 0.92rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.qa-item-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--navy);
  color: white;
  border-radius: 50%;
  width: 1.5rem;
  height: 1.5rem;
  font-size: 0.72rem;
  font-weight: 700;
  flex-shrink: 0;
}

/* ── TA Exercise ── */
.exercise-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  margin-bottom: 0.65rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  box-shadow: var(--shadow);
}
.exercise-title {
  font-weight: 600;
  font-size: 0.97rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.exercise-actions { display: flex; gap: 0.5rem; flex-shrink: 0; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  min-height: 40px;
  padding: 0 0.9rem;
  border-radius: var(--radius-sm);
  font-family: 'Sarabun', sans-serif;
  font-size: 0.875rem;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  white-space: nowrap;
  -webkit-user-select: none;
  user-select: none;
}
.btn:hover { text-decoration: none; opacity: 0.88; }
.btn:active { transform: scale(0.97); }

.btn-primary  { background: var(--blue);  color: white; }
.btn-download { background: var(--green); color: white; }
.btn-solution { background: var(--amber); color: var(--navy); }
.btn-video    { background: #7c3aed; color: white; }
.btn-outline  { background: transparent; color: var(--blue); border: 1.5px solid var(--blue); }
.btn-sm       { min-height: 34px; padding: 0 0.7rem; font-size: 0.82rem; }

/* ── Badge ── */
.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-soon { background: #f1f5f9; color: var(--text-muted); border: 1px solid var(--border); }

/* ── TA Tutoring Accordion ── */
.tutoring-day {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.65rem;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.day-header {
  width: 100%;
  background: none;
  border: none;
  padding: 0.9rem 1.1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  font-family: 'Sarabun', sans-serif;
  text-align: left;
  transition: background 0.2s;
  min-height: 56px;
}
.day-header:hover { background: var(--bg); }
.tutoring-day.open .day-header { background: var(--blue-light); }

.day-header-left { display: flex; align-items: center; gap: 0.65rem; min-width: 0; }
.day-number-badge {
  background: var(--navy);
  color: white;
  border-radius: 8px;
  padding: 0.22rem 0.6rem;
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}
.day-info { min-width: 0; }
.day-title { font-weight: 600; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.day-date  { font-size: 0.82rem; color: var(--text-muted); }

.day-chevron {
  font-size: 0.85rem;
  color: var(--text-muted);
  transition: transform 0.2s;
  flex-shrink: 0;
  margin-left: 0.5rem;
}
.tutoring-day.open .day-chevron { transform: rotate(180deg); }

.day-body {
  display: none;
  padding: 0 1.1rem 1.1rem;
  border-top: 1px solid var(--border);
}
.tutoring-day.open .day-body { display: block; }

.day-source {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.7rem 0;
  border-bottom: 1px dashed var(--border);
  margin-bottom: 0.65rem;
  flex-wrap: wrap;
}
.day-source-label { font-weight: 500; font-size: 0.875rem; color: var(--text-muted); }

.topics-list { display: flex; flex-direction: column; gap: 0.45rem; }

.topic-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.8rem;
  background: var(--bg);
  border-radius: var(--radius-sm);
  gap: 0.65rem;
}
.topic-video-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}
.view-badge {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  min-width: 3rem;
}
.topic-title {
  font-size: 0.9rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
}
.topic-num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.35rem;
  height: 1.35rem;
  background: var(--blue-light);
  color: var(--blue);
  border-radius: 50%;
  font-size: 0.68rem;
  font-weight: 700;
  flex-shrink: 0;
}

/* ── Video Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.78);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-overlay.active { display: flex; }

.modal-box {
  background: var(--card);
  border-radius: var(--radius);
  width: 100%;
  max-width: 820px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
  overflow: hidden;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 1.1rem;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 0.95rem; font-weight: 600; }
.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  min-width: 36px;
  min-height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-close:hover { background: var(--bg); color: var(--text); }

.modal-video {
  position: relative;
  padding-bottom: 56.25%;
  background: #000;
}
.modal-video iframe,
.modal-video video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
}

/* ── Loading ── */
.loading {
  text-align: center;
  padding: 1.5rem;
  color: var(--text-muted);
  font-size: 0.88rem;
}
.spinner {
  display: inline-block;
  width: 1.25rem;
  height: 1.25rem;
  border: 2.5px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-bottom: 0.4rem;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--text-muted);
}
.empty-state .icon { font-size: 2rem; margin-bottom: 0.4rem; }

/* ── Footer ── */
.site-footer {
  background: var(--navy-dark);
  color: rgba(255,255,255,0.5);
  text-align: center;
  padding: 1.1rem;
  font-size: 0.8rem;
}
.site-footer a { color: rgba(255,255,255,0.6); }
.site-footer a:hover { color: white; }

/* ============================================================
   Mobile Responsive
   ============================================================ */

/* ≤ 640px: phone layout */
@media (max-width: 640px) {

  /* Header */
  .site-header { padding: 1.5rem 0 1.25rem; }
  .admin-link { top: 0.6rem; right: 0.75rem; }

  /* Nav */
  .nav-link { min-width: 110px; font-size: 0.82rem; padding: 0 0.75rem; }

  /* Quiz+Assignment: single column on phone */
  .qa-grid { grid-template-columns: 1fr; gap: 1rem; }

  .qa-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }
  .qa-item .btn { width: 100%; }

  /* Exercise: stack title + buttons */
  .exercise-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.65rem;
    padding: 0.9rem;
  }
  .exercise-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
  }
  .exercise-actions .btn,
  .exercise-actions .badge-soon {
    width: 100%;
    text-align: center;
  }

  /* Tutoring */
  .day-title { font-size: 0.9rem; }
  .topic-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }
  .topic-item .btn,
  .topic-item .badge-soon { width: 100%; }
  .topic-video-group { width: 100%; }
  .topic-video-group .btn { flex: 1; }

  /* Video modal: bottom sheet style */
  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }
  .modal-box {
    border-radius: var(--radius) var(--radius) 0 0;
    max-width: 100%;
  }

  /* Sections */
  .content-section { padding: 1.5rem 0 2rem; }
  .section-heading { font-size: 1.1rem; }
}

/* ≤ 380px: very small phones */
@media (max-width: 380px) {
  .nav-link { min-width: 95px; font-size: 0.78rem; }
  .section-heading { font-size: 1rem; }
}
