/* STA2016 - สถิติธุรกิจและวิเคราะห์เชิงปริมาณ
   Responsive Design for Desktop & Mobile
   Ramkhamhaeng University */

:root {
  --primary: #1a365d;
  --primary-light: #2c5282;
  --secondary: #ed8936;
  --accent: #38a169;
  --bg: #f7fafc;
  --card: #ffffff;
  --text: #2d3748;
  --text-light: #718096;
  --border: #e2e8f0;
  --danger: #e53e3e;
  --success: #38a169;
  --warning: #d69e2e;
  --shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
  --radius: 12px;
  --font: 'Sarabun', 'Kanit', system-ui, -apple-system, sans-serif;
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ===== Header ===== */
.header {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
  color: white;
  padding: 0.75rem 1rem;
  position: sticky;
  top: 0;
  z-index: 1000;
  box-shadow: var(--shadow);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: white;
  font-weight: 700;
  font-size: 1.15rem;
}

.logo img, .logo svg {
  width: 40px;
  height: 40px;
  flex-shrink: 0;
}

.logo-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.logo-text span:first-child {
  font-size: 0.95rem;
}

.logo-text span:last-child {
  font-size: 0.7rem;
  opacity: 0.85;
  font-weight: 400;
}

/* Hamburger */
.menu-toggle {
  display: none;
  background: none;
  border: none;
  color: white;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.25rem;
}

/* Navigation */
.nav {
  display: flex;
  gap: 0.25rem;
  align-items: center;
}

.nav a {
  color: rgba(255,255,255,0.9);
  text-decoration: none;
  padding: 0.5rem 0.85rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.2s;
  white-space: nowrap;
}

.nav a:hover, .nav a.active {
  background: rgba(255,255,255,0.15);
  color: white;
}

/* ===== Main Content ===== */
.main {
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}

/* Hero */
.hero {
  background: linear-gradient(135deg, #1a365d 0%, #2b6cb0 100%);
  color: white;
  border-radius: var(--radius);
  padding: 2rem 1.5rem;
  margin-bottom: 2rem;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.hero h1 {
  font-size: 1.75rem;
  margin-bottom: 0.5rem;
  font-weight: 700;
}

.hero p {
  opacity: 0.9;
  font-size: 1rem;
  max-width: 600px;
  margin: 0 auto 1.25rem;
}

.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: center;
}

/* Cards Grid */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1.25rem;
  margin-bottom: 2rem;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  transition: transform 0.2s, box-shadow 0.2s;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
}

.card:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1);
}

.card-icon {
  width: 48px;
  height: 48px;
  margin-bottom: 1rem;
  color: var(--primary);
}

.card h3 {
  font-size: 1.1rem;
  margin-bottom: 0.5rem;
  color: var(--primary);
}

.card p {
  font-size: 0.9rem;
  color: var(--text-light);
  flex: 1;
  margin-bottom: 1rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1.25rem;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.95rem;
  text-decoration: none;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}

.btn-primary {
  background: var(--secondary);
  color: white;
}

.btn-primary:hover {
  background: #dd6b20;
  transform: translateY(-1px);
}

.btn-outline {
  background: transparent;
  border: 2px solid white;
  color: white;
}

.btn-outline:hover {
  background: rgba(255,255,255,0.15);
}

.btn-secondary {
  background: var(--primary);
  color: white;
}

.btn-secondary:hover {
  background: var(--primary-light);
}

.btn-success {
  background: var(--accent);
  color: white;
}

.btn-block {
  width: 100%;
}

/* Section Title */
.section-title {
  font-size: 1.35rem;
  color: var(--primary);
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 3px solid var(--secondary);
  display: inline-block;
}

/* Chapter List */
.chapter-list {
  list-style: none;
}

.chapter-list li {
  background: var(--card);
  border-radius: 10px;
  margin-bottom: 0.75rem;
  border: 1px solid var(--border);
  overflow: hidden;
}

.chapter-list a {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  text-decoration: none;
  color: var(--text);
  transition: background 0.2s;
}

.chapter-list a:hover {
  background: #edf2f7;
}

.chapter-num {
  background: var(--primary);
  color: white;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  flex-shrink: 0;
}

.chapter-info h4 {
  font-size: 1rem;
  margin-bottom: 0.15rem;
}

.chapter-info p {
  font-size: 0.8rem;
  color: var(--text-light);
}

/* Progress Badge */
.progress-badge {
  margin-left: auto;
  background: #e6fffa;
  color: var(--accent);
  font-size: 0.75rem;
  padding: 0.25rem 0.6rem;
  border-radius: 20px;
  font-weight: 600;
}

/* Content Page */
.content-page {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.75rem;
  border: 1px solid var(--border);
}

.content-page h1 {
  color: var(--primary);
  font-size: 1.6rem;
  margin-bottom: 0.5rem;
}

.content-page h2 {
  color: var(--primary-light);
  font-size: 1.25rem;
  margin: 1.75rem 0 0.75rem;
  padding-bottom: 0.35rem;
  border-bottom: 2px solid var(--border);
}

.content-page h3 {
  font-size: 1.1rem;
  margin: 1.25rem 0 0.5rem;
  color: var(--text);
}

.content-page p, .content-page li {
  margin-bottom: 0.75rem;
}

.content-page ul, .content-page ol {
  padding-left: 1.5rem;
  margin-bottom: 1rem;
}

.highlight-box {
  background: #ebf8ff;
  border-left: 4px solid var(--primary-light);
  padding: 1rem 1.25rem;
  border-radius: 0 8px 8px 0;
  margin: 1.25rem 0;
}

.important-box {
  background: #fffaf0;
  border-left: 4px solid var(--secondary);
  padding: 1rem 1.25rem;
  border-radius: 0 8px 8px 0;
  margin: 1.25rem 0;
}

.formula {
  background: #f0fff4;
  border: 1px solid #c6f6d5;
  padding: 1rem;
  border-radius: 8px;
  text-align: center;
  font-family: 'Courier New', monospace;
  margin: 1rem 0;
  overflow-x: auto;
}

/* Notes Sidebar style */
.notes-grid {
  display: grid;
  gap: 1rem;
}

.note-card {
  background: #fffbeb;
  border: 1px solid #f6e05e;
  border-radius: 10px;
  padding: 1.25rem;
}

.note-card h4 {
  color: #975a16;
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Footer */
.footer {
  background: var(--primary);
  color: rgba(255,255,255,0.85);
  text-align: center;
  padding: 1.25rem;
  font-size: 0.85rem;
}

.footer a {
  color: white;
  text-decoration: underline;
}

/* ===== Rest Reminder Modal ===== */
.rest-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 9999;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

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

.rest-content {
  background: white;
  border-radius: 16px;
  padding: 2rem;
  max-width: 400px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 25px -5px rgba(0,0,0,0.2);
}

.rest-content h2 {
  color: var(--primary);
  margin-bottom: 0.75rem;
  font-size: 1.4rem;
}

.rest-content p {
  color: var(--text-light);
  margin-bottom: 1.5rem;
}

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

.rest-actions .btn {
  width: 100%;
}

/* ===== Stats ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

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

.stat-card .value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--primary);
}

.stat-card .label {
  font-size: 0.8rem;
  color: var(--text-light);
  margin-top: 0.25rem;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
  .menu-toggle {
    display: block;
  }

  .nav {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--primary);
    flex-direction: column;
    padding: 0.75rem;
    gap: 0.25rem;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
  }

  .nav.open {
    display: flex;
  }

  .nav a {
    padding: 0.75rem 1rem;
    width: 100%;
  }

  .hero h1 {
    font-size: 1.4rem;
  }

  .logo-text span:last-child {
    display: none;
  }

  .main {
    padding: 1rem 0.75rem 2rem;
  }

  .content-page {
    padding: 1.25rem;
  }

  .cards {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .hero {
    padding: 1.5rem 1rem;
  }

  .hero-actions {
    flex-direction: column;
  }

  .btn {
    width: 100%;
  }
}

/* Utility */
.text-center { text-align: center; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-2 { margin-bottom: 1rem; }
.hidden { display: none !important; }

/* Loading */
.loading {
  text-align: center;
  padding: 2rem;
  color: var(--text-light);
}
/* ===== PWA Install ===== */
.install-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(135deg, #1a365d, #2c5282);
  color: white;
  padding: 0.85rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  z-index: 9000;
  box-shadow: 0 -4px 12px rgba(0,0,0,0.15);
  flex-wrap: wrap;
}
.install-banner.hidden { display: none !important; }
.install-banner p { font-size: 0.9rem; margin: 0; flex: 1; min-width: 180px; }
.install-banner .banner-actions { display: flex; gap: 0.5rem; flex-shrink: 0; }
.install-banner .btn-sm {
  padding: 0.45rem 0.9rem;
  font-size: 0.85rem;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
}
.install-banner .btn-install-main {
  background: #ed8936;
  color: white;
}
.install-banner .btn-install-dismiss {
  background: transparent;
  color: rgba(255,255,255,0.85);
  border: 1px solid rgba(255,255,255,0.4);
}
#btn-install {
  background: #ed8936;
  color: white;
  border: none;
  padding: 0.4rem 0.85rem;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}
#btn-install.hidden { display: none !important; }
