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

/* ---------- Theme ---------- */
:root {
  --bg1: #667eea;
  --bg2: #764ba2;
  --card: #ffffff;
  --muted: #7f8c8d;
  --ink: #2c3e50;
  --accent: #3498db;
  --accent-2: #4CAF50;
  --accent-2b: #45a049;
  --warning: #ffc107;
  --danger: #e74c3c;
  --chip: #f2f6ff;
  --chip-border: #e7eefc;
  --shadow: 0 10px 30px rgba(0, 0, 0, .10);
  --border: #e5e7eb;
  --surface: #fff;
  --panel: #fafafa;
  --brand: #f3f6ff;
  --brand-border: #e8ecf6;
}

.group-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px
}

.group-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  cursor: pointer;
  transition: box-shadow .2s, transform .05s
}

.group-card:hover {
  box-shadow: 0 6px 24px rgba(0, 0, 0, .06)
}

.group-title {
  font-weight: 600;
  font-size: 1.05rem;
  margin-bottom: 6px
}

.group-count {
  font-size: .9rem;
  color: var(--muted)
}

.subgroup-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px
}

.subgroup-chip {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 8px;
  font-size: .82rem;
  background: var(--panel);
  cursor: pointer
}

.breadcrumbs {
  font-size: .95rem;
  margin-bottom: 8px
}

.lo-description {
  margin: 8px 0
}

.empty {
  padding: 24px;
  text-align: center;
  color: var(--muted)
}

.pill {
  background: var(--panel);
  border: 1px solid var(--border)
}

.btn-mini {
  border: 1px solid var(--border)
}

.panel-actions .select {
  min-width: 200px
}

/* ---------- Base ---------- */
body {
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, "Helvetica Neue", Arial;
  line-height: 1.6;
  color: #333;
  background: linear-gradient(135deg, var(--bg1) 0%, var(--bg2) 100%);
  min-height: 100vh;
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
  padding-bottom: 60px;
}

/* ---------- Header (two rows) ---------- */
.header {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 18px;
}

/* Row 1: logo + title on light band */
.brand-bar {
  display: flex;
  justify-content: space-around;
  align-content: center;
  align-items: center;
  padding: 12px 14px;
  background: var(--brand);
  border: 1px solid var(--brand-border);
  border-radius: 12px;
  flex-wrap: wrap;
  text-align: center;
}

.site-logo {
  display: block;
  width: 280px;
  height: auto;
}

.help-logo {
  display: block;
  width: 220px;
  height: auto;
}

.roles-logo {
  display: block;
  width: 450px;
  height: auto;
}

.brand-bar h1 {
  margin: 0;
  font-size: 1.7rem;
  line-height: 1.2;
  color: var(--ink);
}

/* Row 2: subtitle left, actions right (aligned horizontally) */
.nav-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(10px);
  border-radius: 16px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
}

.nav-main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  max-width: 800px;
  gap: 20px;
}

.nav-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

.nav-secondary {
  display: flex;
  align-items: center;
  gap: 12px;
}

.help-header {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.subtitle {
  margin: 0;
  color: var(--card);
  font-size: 1rem;
}

/* Top actions */
.top-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap
}

/* Buttons */
.btn {
  appearance: none;
  border: none;
  border-radius: 9999px;
  padding: 10px 16px;
  font-weight: 600;
  cursor: pointer;
  background: rgb(255, 255, 255);
  color: var(--ink);
  backdrop-filter: blur(6px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, .10);
  transition: transform .18s ease, background .2s ease;
}

.btn.secondary:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.25);

}

.btn.primary:hover {
  transform: translateY(-1px);
  background: rgba(255, 255, 255, 0.849);

}

.btn.secondary {
  background: rgba(255, 255, 255, 0.12);
  font-weight: 600;
  padding: 10px 16px;
  color: white;
}

.btn-icon {
  appearance: none;
  border: none;
  background: rgba(255, 255, 255, 0.15);
  color: white;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-icon:hover {
  background: rgba(255, 255, 255, 0.25);
  transform: translateY(-1px);
}

.btn-text {
  appearance: none;
  border: none;
  background: none;
  color: rgba(255, 255, 255, 0.85);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: 8px;
  transition: all 0.2s ease;
}


.help-icon {
  font-weight: 700;
  font-size: 1.1rem;
}

.auth-menu {
  position: relative;
}

/* ---------- Stats ---------- */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin: 22px 0
}

.stat-card {
  background: rgba(255, 255, 255, .92);
  padding: 18px;
  border-radius: 12px;
  text-align: center;
  box-shadow: var(--shadow)
}

.stat-number {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--accent)
}

.stat-label {
  color: var(--muted);
  font-size: .9rem
}

/* ---------- Search & Filters ---------- */
.search-filter-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  margin-bottom: 14px
}

.search-box {
  padding: 12px 16px;
  font-size: 1rem;
  border: none;
  border-radius: 9999px;
  min-width: 300px;
  max-width: 100%;
  outline: none;
  box-shadow: 0 4px 15px rgba(0, 0, 0, .10)
}

.filter-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  margin: 10px 0 22px
}

.filter-btn {
  padding: 8px 14px;
  border: none;
  border-radius: 9999px;
  background: rgba(255, 255, 255, .2);
  color: #fff;
  cursor: pointer;
  transition: all .2s
}

.filter-btn:hover,
.filter-btn.active {
  background: rgba(255, 255, 255, .3);
  transform: translateY(-1px)
}

/* ---------- Sections & Books ---------- */
.section {
  background: var(--card);
  border-radius: 16px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
  overflow: hidden;
  transition: transform .25s
}

.section-header {
  background: linear-gradient(135deg, var(--accent-2), var(--accent-2b));
  color: #fff;
  padding: 18px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center
}

.section-header h2 {
  font-size: 1.2rem
}

.toggle-icon {
  transition: transform .25s
}

.section-header.collapsed .toggle-icon {
  transform: rotate(-90deg)
}

.books-grid {
  padding: 18px;
  display: grid;
  /* Reduced the minimum width from 380px to a more mobile-friendly 320px */
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 16px;
}

.book-card {
  border: 1px solid #edf0f4;
  border-radius: 12px;
  padding: 16px;
  background: #fafafa;
  transition: all .2s;
  /* Add this line to force long words to wrap */
  overflow-wrap: break-word;
}

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

.book-title {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--ink);
  margin-bottom: 0;
  /* This was already in a later rule, just confirming */
  /* Added to prevent long titles from overflowing the card */
  overflow-wrap: break-word;
}

.book-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 10px;
  font-size: .92rem
}

.meta-item {
  display: flex;
  flex-direction: column
}

.meta-label {
  font-weight: 700;
  color: var(--muted);
  font-size: .75rem;
  text-transform: uppercase
}

.pdf-badge {
  display: inline-block;
  background: #27ae60;
  color: #fff;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: .78rem
}

.no-pdf {
  background: var(--danger)
}

.chapters-section {
  margin-top: 10px
}

.chapters-title {
  font-weight: 800;
  color: var(--ink);
  margin-bottom: 6px
}

.chapter-list {
  background: #fff;
  padding: 10px;
  border-radius: 10px;
  border-left: 4px solid var(--accent)
}

.chapter-item {
  margin-bottom: 6px;
  font-size: .95rem;
  line-height: 1.45;
  /* Add this more aggressive rule to break any string */
  word-break: break-all;
}

.learning-objectives {
  color: #8e44ad;
  font-weight: 600
}

.optional-chapters {
  background: #fff8e1;
  border-left-color: var(--warning);
  margin-top: 8px
}

.rationale {
  background: #e8f5e8;
  padding: 10px;
  border-radius: 8px;
  margin-top: 10px;
  font-style: italic;
  color: #2d5a2d
}

.collapsed .books-grid {
  display: none
}

/* ---------- Slide-over Panel ---------- */
.panel-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .35);
  display: none;
  justify-content: flex-end;
  z-index: 50
}

.panel {
  width: min(600px, 90vw);
  height: 100vh;
  background: #fff;
  border-radius: 16px 0 0 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column
}

.panel-header {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid #eef1f4;
  background: #fbfbfd;
  position: sticky;
  top: 0
}

.panel-header-main {
  flex: 1;
  min-width: 0;
}

.panel-title {
  font-weight: 800;
  font-size: 1.05rem;
  color: var(--ink)
}

.panel-body {
  padding: 12px;
  overflow: auto
}

.panel-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--chip-border);
  background: var(--chip);
  padding: 6px 10px;
  border-radius: 9999px;
  font-size: .9rem
}

.select {
  padding: 8px 10px;
  border: 1px solid #e7e7ef;
  border-radius: 10px;
  background: #fff;
  max-width: 100%;
}

.input {
  padding: 9px 12px;
  border: 1px solid #e7e7ef;
  border-radius: 9999px;
  min-width: 240px
}

/* Group description block shown above subgroup chips */
.group-description {
  background: #eef1f4;
  padding: 14px;
  border-radius: 12px;
  margin-bottom: 16px;
  font-size: .95rem;
  line-height: 1.5;
  border-left: 5px solid var(--accent);
  display: none
}

.group-description h3 {
  margin: 0 0 8px;
  font-size: 1.1rem;
  color: var(--ink)
}

.group-description ul {
  list-style-position: inside;
  padding-left: 10px;
  margin-top: 8px;
  color: #555
}

/* ---------- Objectives list ---------- */
.lo-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 10px
}

details.lo {
  border: 1px solid #edf0f4;
  border-radius: 12px;
  overflow: hidden;
  background: #fff
}

details.lo summary {
  list-style: none;
  cursor: pointer;
  padding: 10px 12px;
  background: #f7f9ff;
  border-bottom: 1px solid #edf0f4;
  display: flex;
  align-items: center;
  justify-content: space-between
}

.lo-code {
  font-weight: 800;
  color: #4c3c8c
}

.lo-label {
  color: var(--muted);
  font-size: .9rem
}

.tag {
  font-size: .78rem;
  padding: 2px 8px;
  border-radius: 9999px;
  border: 1px solid #e9e9f2;
  background: #fff
}

.lo-description {
  padding: 12px;
  font-size: .9rem;
  color: var(--ink);
  background: #fdfdff;
  border-bottom: 1px solid #edf0f4
}

.lo-description ul {
  list-style-position: inside;
  padding-left: 1rem;
  margin-top: .5rem
}

.hit {
  padding: 10px 12px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  border-bottom: 1px dashed #f0f2f6
}

.hit:last-child {
  border-bottom: none
}

.hit .right {
  display: flex;
  align-items: center;
  gap: 6px
}

.pill {
  font-size: .72rem;
  border: 1px solid #e0e0ea;
  border-radius: 9999px;
  padding: 2px 8px
}

.btn-mini {
  border: 1px solid #e0e0ea;
  background: #fff;
  border-radius: 10px;
  padding: 6px 8px;
  cursor: pointer
}

.empty {
  padding: 24px;
  text-align: center;
  color: var(--muted)
}

/* Styling for new badges */
.book-title-wrapper {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 8px;
}

.book-title {
  margin-bottom: 0;
  /* Override existing margin */
}

.badges-container {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
  /* Removed 'flex-shrink: 0;' which was preventing this container from shrinking */
}

.badge {
  display: inline-block;
  padding: 3px 10px;
  font-size: .7rem;
  font-weight: 700;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #fff;
  line-height: 1.4;
}

.readearly-badge {
  background-color: #8e44ad;
  /* Purple */
}

.examinable-badge {
  background-color: #c65347;
  /* Red */
}

/* ---------- Tooltip Implementation ---------- */
.lo-code-tooltip {
  cursor: help;
  border-bottom: 1px dotted var(--accent);
  color: var(--accent);
  font-weight: 600;
}

#loTooltip {
  position: absolute;
  z-index: 1000;
  background: var(--ink, #2c3e50);
  color: #fff;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.9rem;
  max-width: 400px;
  pointer-events: none;
  /* Critical to prevent flicker */
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.25);
  line-height: 1.5;
  display: none;
  /* Initially hidden */
  border-left: 4px solid #58d68d;
}

#loTooltip h4 {
  margin: 0 0 6px 0;
  font-size: 1rem;
  color: #58d68d;
  /* A light green for contrast */
}

#loTooltip ul {
  margin-top: 8px;
  padding-left: 20px;
}

#closeObjectives {
  margin-top: -1rem;
}

/* ---------- Responsive ---------- */
@media (max-width:768px) {
  .brand-bar {
    gap: 10px
  }

  .brand-bar h1 {
    font-size: 1.35rem
  }

  .nav-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px
  }

  .top-actions {
    justify-content: flex-start
  }

  .books-grid {
    grid-template-columns: 1fr
  }

  .search-box {
    width: 100%;
    max-width: 300px
  }
}

li,
#helpPanelBody p {
  margin: 1rem;
}

footer {
  left: 0;
  bottom: 0;
  width: 100%;
  background-color: var(--ink);
  color: white;
  text-align: center;
  padding: 10px 0;
  font-size: 0.9rem;
  z-index: 100;
}

@media (hover: none) and (pointer: coarse) {
  #loTooltip {
    /* Change positioning to be relative to the viewport */
    position: fixed;

    /* Center it horizontally and place it at the bottom */
    inset-inline: 0;
    inset-block-end: calc(12px + env(safe-area-inset-bottom));
    margin-inline: auto;

    /* Set a responsive width */
    max-inline-size: min(92vw, 450px);

    /* Allow scrolling for long descriptions */
    max-block-size: 50vh;
    overflow: auto;

    /* Reset any positioning styles from JavaScript */
    left: auto;
    top: auto;
    right: auto;
    transform: none;

    /* Allow interaction (like scrolling) with the tooltip on mobile */
    pointer-events: auto;
  }
}

@media (max-width: 768px) {
  .nav-main {
    flex-direction: column;
    gap: 12px;
    text-align: center;
  }

  .nav-actions {
    order: 1;
  }

  .nav-secondary {
    order: 2;
  }
}

/* ---------- Login Form ---------- */
#login-section {
  background: var(--warning);
  padding: 12px 20px;
  color: var(--ink);
  position: sticky;
  top: 0;
  z-index: 200;
  box-shadow: 0 4px 12px rgba(0, 0, 0, .15);
}

#login-section .container {
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
}

#login-form {
  display: flex;
  gap: 10px;
  align-items: center;
}

#login-form label {
  font-weight: 600;
}

#login-form input {
  padding: 6px 10px;
  font-size: .9rem;
  border: 1px solid rgba(0, 0, 0, 0.2);
  border-radius: 8px;
  background: #fff;
}

#login-form button {
  appearance: none;
  border: 1px solid var(--ink);
  border-radius: 8px;
  padding: 6px 12px;
  font-weight: 600;
  cursor: pointer;
  background: var(--ink);
  color: #fff;
  transition: background .2s ease;
}

#login-form button:hover {
  background: #4a6582;
}

#login-error {
  color: var(--danger);
  font-weight: bold;
}

.hidden {
  display: none !important;
}

/* Style for clickable PDF badges */
.meta-value .pdf-link a {
  text-decoration: none;
  cursor: pointer;
}

.meta-value .pdf-link a .pdf-badge:hover {
  filter: brightness(1.1);
}

/* ---------- Announcement Bar ---------- */
.announcement-bar {
  background-color: var(--ink);
  color: white;
  text-align: center;
  padding: 8px 12px;
  font-size: 0.9rem;
  font-weight: 500;
}

.announcement-bar p {
  margin: 0;
}

.epa-tabs {
  display: flex;
  flex-wrap: wrap;
  border-bottom: 1px solid #ddd;
  margin-bottom: 1.5rem;
}

.epa-tab-btn {
  padding: 10px 15px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 1rem;
  border-bottom: 3px solid transparent;
  margin-bottom: -1px;
  color: #333;
}

.epa-tab-btn.active {
  border-bottom-color: #3498db;
  font-weight: 600;
  color: #000;
}

.epa-content h3 {
  margin-top: 0;
  font-size: 1.5rem;
  color: #2c3e50;
}

.epa-content-panel th,
.epa-content-panel td {
  border: 1px solid #ddd;
}

.epa-content-panel ul {
  padding-left: 20px;
}

#epaOverlay {
  justify-content: center;
  align-items: center;
}

#epaOverlay .panel {
  width: min(900px, 90vw);
  height: auto;
  max-height: 90vh;
  border-radius: 16px;
}

.epa-content-panel table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1.5em;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden; 
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.epa-content-panel th {
  background-color: var(--brand);
  padding: 12px 15px;
  text-align: left;
  font-weight: 600;
  font-size: 0.8rem; 
  color: var(--ink);
  letter-spacing: 0.05em;
  border-bottom: 2px solid var(--border);
}

/* Table body cells (td) */
.epa-content-panel td {
  padding: 12px 15px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle; 
}

.epa-content-panel tbody tr:last-child td {
  border-bottom: none;
}

.epa-content-panel tbody tr:nth-of-type(even) {
  background-color: var(--panel);
}


.epa-content-panel tbody tr:hover {
  background-color: var(--chip);
}

.epa-content-panel th:nth-child(n+4),
.epa-content-panel td:nth-child(n+4) {
  text-align: center;
  width: 7%; 
}

.epa-content-panel td:nth-child(n+4) {
    font-weight: bold;
    color: var(--accent);
}

.epa-content-panel p{
  padding: 0.7rem 0rem;
}