@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap");

:root {
  --navy: #0f3f63;
  --light-blue: #e6f0fb;
  --text-dark: #0c2f4f;
  --border: #d7dce3;
  --card-shadow: 0 10px 20px rgba(13, 33, 61, 0.08);

  --sidebar-width: 280px;
  --divider-width: 5px;
  --scrollbar-size: 6px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Inter", sans-serif;
  background: #f4f6fb;
  color: var(--text-dark);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  overflow-y: auto;

  scrollbar-width: thin;
  scrollbar-color: rgba(15, 63, 99, 0.4) transparent;
}

body::-webkit-scrollbar {
  width: var(--scrollbar-size);
  height: var(--scrollbar-size);
}

body::-webkit-scrollbar-track {
  background: transparent;
}

body::-webkit-scrollbar-thumb {
  background: rgba(15, 63, 99, 0.35);
  border-radius: 999px;
}

/* ===== Desktop-like layout for ALL screen sizes ===== */
.page {
  flex: 1;
  display: grid;
  grid-template-columns: var(--sidebar-width) var(--divider-width) 1fr;
  gap: 0;
  padding: 24px 32px 40px;
  position: relative;
  min-height: 100vh;
  overflow: visible;
  transition: grid-template-columns 0.5s ease;
}

/* ===== Sidebar ===== */
.sidebar {
  background: var(--light-blue);
  border-radius: 18px;
  padding: 32px 22px;
  box-shadow: var(--card-shadow);
  display: flex;
  flex-direction: column;
  gap: 24px;
  font-size: 0.65rem;
  transition: width 0.5s ease, opacity 0.5s ease, padding 0.5s ease, margin 0.5s ease;

  position: sticky;
  top: 24px;
  align-self: start;
  height: calc(100vh - 64px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(15, 63, 99, 0.4) transparent;
}

.sidebar-title {
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 1px;
  text-align: center;
  color: var(--navy);
}

.course-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.menu {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.course-card {
  display: block;
  background: #fff;
  border: 1px solid #e1e4ea;
  border-radius: 16px;
  padding: 14px 16px;
  font-weight: 60;
  color: var(--navy);
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  box-shadow: var(--card-shadow);
}

.menu a {
  display: block;
  background: #fff;
  border: 1px solid #e1e4ea;
  border-radius: 5px;
  padding: 9px 9px;
  font-weight: 20;
  color: var(--navy);
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  box-shadow: var(--card-shadow);
}

.course-card.active {
  outline: 2px solid rgba(15, 63, 99, 0.45);
}

.menu a.active {
  outline: 2px solid rgba(15, 63, 99, 0.45);
}

/* Sidebar scrollbar */
.sidebar::-webkit-scrollbar {
  width: var(--scrollbar-size);
}

.sidebar::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
  background: rgba(15, 63, 99, 0.35);
  border-radius: 999px;
}

/* ===== Divider ===== */
.divider {
  background: var(--navy);
  border-radius: 10px;
  display: flex;
  justify-content: center;
  position: sticky;
  top: 24px;
  height: calc(100vh - 64px);
  transition: width 0.5s ease, opacity 0.5s ease;
}

.divider-pill {
  width: 1px;
  height: 55vh;
  background: #d6e5f5;
  border-radius: 999px;
  align-self: center;
  box-shadow: inset 0 0 0 2px rgba(15, 63, 99, 0.15);
}

/* ===== Content ===== */
.content {
  padding-left: 24px;
  display: flex;
  height: auto;
  overflow-y: visible;
  scrollbar-width: thin;
  scrollbar-color: rgba(15, 63, 99, 0.4) transparent;
  transition: padding-left 0.5s ease;
}

.content::-webkit-scrollbar {
  width: var(--scrollbar-size);
}

.content::-webkit-scrollbar-track {
  background: transparent;
}

.content::-webkit-scrollbar-thumb {
  background: rgba(15, 63, 99, 0.35);
  border-radius: 999px;
}

.content-card {
  background: #fff;
  border-radius: 18px;
  padding: 36px 42px;
  box-shadow: var(--card-shadow);
  border: 1px solid var(--border);
  width: 100%;
  max-width: 980px;

  /* ✅ NEW: ensure child scrollbars are not clipped */
  overflow: visible;
}

.back-link {
  display: inline-block;
  color: var(--navy);
  font-weight: 600;
  text-decoration: underline;
  margin-bottom: 28px;
}

h1 {
  text-align: center;
  color: var(--navy);
  font-size: 25px;
  margin-bottom: 18px;
}

.intro {
  color: #2a3e55;
  font-size: 14px;
  line-height: 1.7;
  margin-bottom: 28px;
}

.about h2 {
  color: var(--navy);
  font-size: 18px;
  margin-bottom: 14px;
}

.about h3 {
  color: var(--navy);
  font-size: 15px;
  margin: 18px 0 10px;
}

.about p {
  line-height: 1.8;
  font-size: 14px;
  margin-bottom: 18px;
  color: #2a3e55;
}

.about-list {
  margin: 0 0 18px 20px;
  color: #2a3e55;
  font-size: 14px;
  line-height: 1.8;
}

.about-list li {
  margin-bottom: 8px;
}

/* ===============================
   CODE BLOCKS: Horizontal scroll
   (Desktop + Mobile) - natural overflow only
================================= */
pre,
.code-block {
  background: #f8fafc;
  border: 1px solid #e1e4ea;
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 18px;
  font-size: 13px;
  line-height: 1.6;
  color: #1a2b3c;

  display: block;
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 100%;

  /* ✅ Keep code in one line; show scrollbar only if needed */
  white-space: pre;
  -webkit-overflow-scrolling: touch;
  scrollbar-gutter: stable;

  /* ✅ NEW: helps prevent layout blowouts in rare cases */
  contain: content;
}

.code-block code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

/* ✅ NEW: Make horizontal scrollbar visible on WebKit */
pre::-webkit-scrollbar,
.code-block::-webkit-scrollbar {
  height: 8px;
}

pre::-webkit-scrollbar-thumb,
.code-block::-webkit-scrollbar-thumb {
  background: rgba(15, 63, 99, 0.45);
  border-radius: 999px;
}

pre::-webkit-scrollbar-track,
.code-block::-webkit-scrollbar-track {
  background: transparent;
}

/* ===============================
   TABLES: Horizontal scroll
   (Desktop + Mobile)
   Use: <div class="table-wrap"><table>...</table></div>
================================= */
.table-wrap,
.table-wrapper {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  margin-bottom: 18px;
  -webkit-overflow-scrolling: touch;
  scrollbar-gutter: stable;
}

/* Allow table to exceed container width when needed */
.table-wrap table,
.table-wrapper table,
.about table,
.content-card table {
  width: max-content; /* natural width -> enables overflow */
  min-width: 100%;   /* still fills container when small */
  border-collapse: collapse;
  margin-bottom: 18px;
  font-size: 14px;
  color: #2a3e55;
}

.about th,
.about td,
.content-card th,
.content-card td {
  border: 1px solid #d7dce3;
  padding: 10px 12px;
  text-align: left;
  white-space: nowrap; /* force horizontal overflow -> scroll */
}

.about th,
.content-card th {
  background: #f5f8fd;
  color: var(--navy);
  font-weight: 600;
}

.last-updated {
  font-weight: 600;
  color: var(--navy);
}

/* ===== Toggle Button ===== */
.sidebar-toggle {
  position: fixed;
  top: 24px;
  left: calc(var(--sidebar-width) + (var(--divider-width) / 2));
  transform: translateX(-50%);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: #fff;
  color: var(--navy);
  box-shadow: 0 10px 20px rgba(13, 33, 61, 0.15);
  cursor: pointer;
  display: grid;
  place-items: center;
  z-index: 5;
  transition: left 0.5s ease, transform 0.5s ease;
}

.sidebar-toggle span {
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
  animation: sidebar-toggle-flash 1.4s ease-in-out infinite;
}

.sidebar-toggle:hover {
  background: #f5f8fd;
}

@keyframes sidebar-toggle-flash {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.4;
    transform: scale(1.08);
  }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar-toggle span {
    animation: none;
  }
}

/* ===== To Top Button ===== */
.to-top {
  position: fixed;
  left: calc(var(--sidebar-width) + var(--divider-width) + 24px);
  bottom: 24px;
  padding: 10px 16px;
  border-radius: 999px;
  border: none;
  background: var(--navy);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 10px 20px rgba(13, 33, 61, 0.2);
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 0.2s ease, transform 0.2s ease, left 0.5s ease;
  z-index: 6;
}

.page--collapsed .to-top {
  left: 24px;
}

.to-top:hover {
  background: #14507f;
}

.to-top:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

.to-top--visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateY(0);
}

/* ===== Collapsed: NOTHING from left should be visible ===== */
.page--collapsed {
  grid-template-columns: 0 0 1fr;
}

.page--collapsed .sidebar {
  padding: 0;
  margin: 0;
  width: 0;
  opacity: 0;
  overflow: hidden;
  pointer-events: none;
  box-shadow: none;
  border: none;
}

.page--collapsed .divider {
  width: 0;
  background: transparent;
}

.page--collapsed .divider-pill {
  display: none;
}

.page--collapsed .content {
  padding-left: 0;
}

.page--collapsed .sidebar-toggle {
  left: 12px;
  transform: none;
}

/* ===== Footer ===== */
footer {
  background: #fff;
  border-top: 1px solid #e1e4ea;
  padding: 14px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: #41556f;
}

footer nav {
  display: flex;
  gap: 24px;
}

footer a {
  color: #41556f;
  text-decoration: none;
}

/* ===== Make smaller screens still use same layout (desktop-like) ===== */
@media (max-width: 900px) {
  .page {
    padding: 16px;
  }

  .content-card {
    padding: 28px 24px;
  }

  footer {
    flex-direction: column;
    gap: 8px;
  }
}

@media (max-width: 600px) {
  :root {
    --sidebar-width: 200px;
    --divider-width: 5px;
  }

  .content {
    padding-left: 16px;
  }

  .content-card {
    padding: 22px 16px;
    max-width: none;
  }

  h1 {
    font-size: 22px;
  }

  footer {
    padding: 14px 16px;
  }
}

/* ✅ Prevent any page-level horizontal extension */
html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

/* ✅ Make grid columns shrink instead of forcing overflow */
.page {
  grid-template-columns: minmax(0, var(--sidebar-width)) minmax(0, var(--divider-width)) minmax(0, 1fr);
  max-width: 100%;
  overflow-x: hidden;
}

/* Ensure collapsed state overrides the base grid columns */
.page--collapsed {
  grid-template-columns: 0 0 1fr;
}

/* ✅ Critical for grid/flex children to allow shrinking */
.sidebar,
.content,
.content-card {
  min-width: 0;
}

/* ✅ Code blocks must also be shrinkable inside flex/grid */
pre,
.code-block {
  min-width: 0;
  max-width: 100%;
}

/* ✅ If any inline element causes overflow, this prevents it */
.about,
.content-card {
  overflow-wrap: anywhere;
  word-break: break-word;
}
/* =========================================================
   FIX: Collapsed layout should not leave a big left gap
   (Add at END of style.css)
========================================================= */

/* Grid/flex children must be allowed to shrink */
.page,
.sidebar,
.content,
.content-card {
  min-width: 0;
}

/* Make the content column actually expand */
.content {
  flex: 1;
  width: 100%;
  justify-content: flex-start; /* avoid centered/narrow look */
}

/* Normal: keep your max width */
.content-card {
  width: 100%;
  max-width: 980px;
}

/* Collapsed: make card fill the whole available space */
.page--collapsed .content {
  padding-left: 0;
  width: 100%;
  flex: 1;
}

.page--collapsed .content-card {
  max-width: 100%;
  width: 100%;
  margin: 0;
}

/* Move toggle button to a consistent left position when collapsed */
.page--collapsed .sidebar-toggle {
  left: 12px;
  transform: none;
}
