/* ======================================================
   PYQApp Common CSS - Mobile-First Responsive Design
   ====================================================== */

:root {
  --c-primary: #1d4ed8;
  --c-primary-hover: #1e40af;
  --c-primary-light: #dbeafe;
  --c-primary-dark: #1e3a8a;
  --c-text: #0f172a;
  --c-text-sec: #334155;
  --c-text-muted: #64748b;
  --c-bg: #ffffff;
  --c-bg-alt: #f8fafc;
  --c-bg-subtle: #f1f5f9;
  --c-border: #e2e8f0;
  --c-success: #15803d;
  --c-warning: #b45309;
  --c-danger: #b91c1c;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  --shadow-xs: 0 1px 2px rgba(0,0,0,0.04);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.08), 0 2px 4px -2px rgba(0,0,0,0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.04);
  --radius: 8px;
  --radius-sm: 6px;
  --radius-lg: 12px;
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
}

/* Reset */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  font-family: var(--font);
  color: var(--c-text);
  background: var(--c-bg-alt);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
a { color: inherit; text-decoration: none; }
a:not(.btn):not(.card):not(.site-logo):not(.header-cta):not(.bc-link):not(.sub-item):not(.course-row):not(.paper-item a):not(.footer-brand) {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}
img { max-width: 100%; height: auto; display: block; }
button { font-family: inherit; cursor: pointer; }

/* Page Layout */
.page-wrap {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--c-bg);
}
.main-content { flex: 1; }
.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px;
}

/* ---- Site Header ---- */
.site-header {
  background: var(--c-bg);
  border-bottom: 1px solid var(--c-border);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  background: rgba(255,255,255,0.95);
}
.site-header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
}
.site-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1.125rem;
  color: var(--c-text);
}
.site-logo img {
  width: 28px;
  height: 28px;
  border-radius: 6px;
}
.header-cta {
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 6px 14px;
  background: var(--c-primary);
  color: #fff;
  border-radius: var(--radius-sm);
  transition: background 0.2s var(--ease);
}
.header-cta:hover { background: var(--c-primary-hover); }

/* ---- Breadcrumbs ---- */
.breadcrumbs-wrap {
  background: var(--c-bg);
  border-bottom: 1px solid var(--c-border);
  padding: 10px 0;
}
.breadcrumbs {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  font-size: 0.8125rem;
  color: var(--c-text-sec);
  overflow: hidden;
}
.bc-link {
  color: var(--c-primary);
  white-space: nowrap;
  transition: color 0.15s;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}
.bc-link:hover { color: var(--c-primary-hover); text-decoration: underline; }
.bc-sep { color: var(--c-text-muted); margin: 0 2px; user-select: none; }
.bc-current {
  color: var(--c-text);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 300px;
}

/* ---- Page Hero ---- */
.page-hero {
  padding: 24px 0 20px;
  border-bottom: 1px solid var(--c-border);
  background: var(--c-bg);
}
.page-hero h1 {
  font-size: clamp(1.25rem, 4vw, 2rem);
  font-weight: 700;
  color: var(--c-text);
  letter-spacing: -0.02em;
  line-height: 1.3;
  margin-bottom: 4px;
}
.page-hero .subtitle {
  font-size: 0.9375rem;
  color: var(--c-text-sec);
}
.page-hero .stats {
  display: flex;
  gap: 16px;
  margin-top: 12px;
  flex-wrap: wrap;
}
.stat-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  background: var(--c-bg-subtle);
  color: var(--c-text-sec);
}

/* ---- Cards ---- */
.card {
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 14px 16px;
  transition: border-color 0.2s var(--ease), box-shadow 0.2s var(--ease);
  display: block;
  contain: layout style;
}
.card:hover {
  border-color: var(--c-primary);
  box-shadow: var(--shadow-sm);
}
.card-title {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--c-text);
  line-height: 1.45;
}
.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  margin-top: 8px;
  font-size: 0.8125rem;
  color: var(--c-text-sec);
}
.card-meta span { display: inline-flex; align-items: center; gap: 3px; }

/* Card accent variants */
.card--accent {
  background: var(--c-primary-light);
  border-color: #bfdbfe;
}
.card--accent:hover { border-color: var(--c-primary); }
.card--accent .card-title { color: var(--c-primary-dark); font-weight: 600; }

/* ---- Grid ---- */
.grid {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  border: none;
  transition: all 0.2s var(--ease);
  cursor: pointer;
  text-align: center;
  min-height: 44px; /* touch target */
}
.btn-primary {
  background: var(--c-primary);
  color: #fff;
}
.btn-primary:hover { background: var(--c-primary-hover); }
.btn-outline {
  background: transparent;
  color: var(--c-primary);
  border: 1px solid var(--c-primary);
}
.btn-outline:hover { background: var(--c-primary-light); }
.btn-sm {
  font-size: 0.8125rem;
  padding: 6px 14px;
  min-height: 36px;
}

/* ---- Section Groups ---- */
.section-group { margin-bottom: 24px; }
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--c-bg-alt);
  border-radius: var(--radius);
  cursor: pointer;
  user-select: none;
  margin-bottom: 12px;
  transition: background 0.15s;
  min-height: 48px;
}
.section-header:hover { background: var(--c-bg-subtle); }
.section-header h2 {
  font-size: 1.0625rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}
.section-header .count {
  font-size: 0.8125rem;
  font-weight: 400;
  color: var(--c-text-sec);
}
.section-toggle {
  font-size: 1.125rem;
  color: var(--c-text-muted);
  transition: transform 0.2s var(--ease);
  line-height: 1;
}
.section-group.collapsed .section-toggle { transform: rotate(-90deg); }
.section-body {
  max-height: 5000px;
  overflow: hidden;
  transition: max-height 0.3s var(--ease);
  content-visibility: auto;
  contain-intrinsic-size: 0 500px;
}
.section-group.collapsed .section-body { max-height: 0; }

/* ---- Search ---- */
.search-wrap {
  position: sticky;
  top: 56px;
  z-index: 50;
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--c-border);
  padding: 12px 0;
}
.search-inner {
  max-width: 640px;
  margin: 0 auto;
  position: relative;
}
.search-input {
  width: 100%;
  padding: 10px 44px 10px 16px;
  font-size: 0.9375rem;
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  outline: none;
  background: var(--c-bg);
  color: var(--c-text);
  transition: border-color 0.2s, box-shadow 0.2s;
  min-height: 44px;
}
.search-input:focus {
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.search-input::placeholder { color: var(--c-text-muted); font-style: italic; }
.search-icon-right {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--c-text-muted);
  font-size: 1.125rem;
  pointer-events: none;
}
.search-stats {
  text-align: center;
  margin-top: 8px;
  font-size: 0.8125rem;
  color: var(--c-text-sec);
}

/* ---- Loading Skeletons ---- */
.skeleton-group { display: grid; gap: 12px; grid-template-columns: 1fr; }
.skeleton {
  background: linear-gradient(90deg, var(--c-bg-subtle) 25%, var(--c-bg-alt) 50%, var(--c-bg-subtle) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius);
}
.skeleton-card { height: 72px; }
.skeleton-text { height: 18px; width: 60%; margin-bottom: 8px; border-radius: 4px; }
.skeleton-text.short { width: 35%; }
.skeleton-hero { height: 100px; margin-bottom: 16px; }
@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ---- Empty / Error states ---- */
.empty-state, .error-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--c-text-sec);
}
.empty-state .icon, .error-state .icon {
  font-size: 3rem;
  margin-bottom: 12px;
  opacity: 0.4;
}
.empty-state h3, .error-state h3 {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--c-text);
  margin-bottom: 6px;
}
.error-state .btn { margin-top: 16px; }

/* ---- Sub-items ---- */
.sub-list {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.sub-item {
  display: block;
  padding: 10px 12px;
  background: var(--c-bg-alt);
  border-left: 2px solid var(--c-border);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.875rem;
  color: var(--c-text);
  transition: all 0.15s var(--ease);
  min-height: 44px;
  display: flex;
  align-items: center;
}
.sub-item:hover {
  background: var(--c-bg-subtle);
  border-left-color: var(--c-primary);
  transform: translateX(2px);
}

/* ---- Highlight ---- */
.hl {
  background: #fef08a;
  padding: 1px 3px;
  border-radius: 3px;
  font-weight: 500;
}

/* ---- Paper Row ---- */
.paper-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  transition: border-color 0.2s, box-shadow 0.2s;
  min-height: 52px;
}
.paper-row:hover {
  border-color: var(--c-primary);
  box-shadow: var(--shadow-xs);
}
.paper-row .paper-name {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--c-text);
  flex: 1;
}

/* ---- PDF Viewer ---- */
.pdf-wrap {
  width: 100%;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px;
  gap: 16px;
}
.pdf-frame {
  width: 100%;
  height: 70vh;
  border: none;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  background: var(--c-bg-subtle);
}

/* ---- Site Footer ---- */
.site-footer {
  background: var(--c-bg);
  border-top: 1px solid var(--c-border);
  padding: 24px 0;
  margin-top: auto;
}
.footer-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
}
.footer-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1rem;
}
.footer-brand img { width: 24px; height: 24px; border-radius: 4px; }
.footer-links {
  display: flex;
  gap: 8px;
  font-size: 0.8125rem;
  color: var(--c-text-sec);
  flex-wrap: wrap;
  justify-content: center;
}
.footer-links a {
  color: var(--c-text-sec);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}
.footer-links a:hover { color: var(--c-primary); }
.footer-links .dot { color: var(--c-text-muted); }
.footer-copy {
  font-size: 0.75rem;
  color: var(--c-text-sec);
}

/* ---- Scroll to Top ---- */
.scroll-top {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--c-primary);
  color: #fff;
  border: none;
  font-size: 1.25rem;
  display: none;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-md);
  z-index: 90;
  transition: opacity 0.2s, transform 0.2s;
}
.scroll-top.visible { display: flex; }
.scroll-top:hover { transform: translateY(-2px); }

/* ---- Exam Date Badge ---- */
.exam-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 12px;
  background: #fef3c7;
  color: #78350f;
  white-space: nowrap;
}

/* ---- Year/Semester Headers ---- */
.year-header {
  font-size: 1.0625rem;
  font-weight: 700;
  color: var(--c-text);
  padding: 16px 0 8px;
  border-bottom: 2px solid var(--c-primary-light);
  margin-bottom: 12px;
}
.sem-header {
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--c-text-sec);
  padding: 8px 0;
  margin-bottom: 8px;
}

/* ======================================================
   RESPONSIVE BREAKPOINTS
   ====================================================== */

/* Tablet - 768px+ */
@media (min-width: 768px) {
  .container { padding: 0 24px; }
  .grid { grid-template-columns: repeat(2, 1fr); gap: 16px; }
  .page-hero { padding: 32px 0 24px; }
  .page-hero h1 { font-size: 1.75rem; }
  .skeleton-group { grid-template-columns: repeat(2, 1fr); }
  .pdf-frame { height: 80vh; }
  .site-header .container { height: 60px; }
  .footer-inner { flex-direction: row; justify-content: space-between; text-align: left; }
}

/* Desktop - 1024px+ */
@media (min-width: 1024px) {
  .grid { grid-template-columns: repeat(3, 1fr); }
  .skeleton-group { grid-template-columns: repeat(3, 1fr); }
  .container { padding: 0 32px; }
}

/* Large Desktop - 1280px+ */
@media (min-width: 1280px) {
  .grid.grid-4 { grid-template-columns: repeat(4, 1fr); }
}

/* Small mobile */
@media (max-width: 480px) {
  .page-hero h1 { font-size: 1.25rem; }
  .search-input { font-size: 16px; } /* prevents iOS zoom */
  .card { padding: 12px; }
  .bc-current { max-width: 180px; }
  .paper-row { flex-direction: column; align-items: flex-start; gap: 8px; }
}

/* ---- Print ---- */
@media print {
  .site-header, .site-footer, .search-wrap, .scroll-top, .breadcrumbs-wrap { display: none !important; }
  .page-wrap { min-height: auto; }
  .card { break-inside: avoid; }
}

/* ---- Reduced Motion ---- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
  html { scroll-behavior: auto; }
}

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--c-border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--c-text-muted); }

/* ---- Accessibility ---- */
:focus-visible {
  outline: 2px solid var(--c-primary);
  outline-offset: 2px;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}
