/* =============================================================================
   Phones and tablets.

   The captured pages were laid out for a desktop browser. Everything in this
   file sits inside a max-width media query, so the desktop layout is
   untouched; it only takes over below 1024px.

   Loaded after the page's own styles (build.py puts it at the end of <head>),
   so equal-specificity rules here win. !important is used only where the page
   sets the value inline, which nothing else can override.
   ========================================================================== */

/* ---- Drawer backdrop and menu button (built by mobile.js) ---------------- */
.m-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
  z-index: 45;
}
.m-backdrop.is-open {
  opacity: 1;
  visibility: visible;
}
.m-menu-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  margin-left: -6px;
  margin-right: 4px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #334155;
  cursor: pointer;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.m-menu-btn:hover,
.m-menu-btn:focus-visible {
  background: #f1f5f9;
  outline: none;
}
.m-menu-btn svg {
  width: 22px;
  height: 22px;
}
body.m-locked {
  overflow: hidden;
}

/* Built by mobile.js; only shown inside the drawers below 1024px. */
.m-drawer-head,
.m-module-meta {
  display: none;
}
.m-drawer-head {
  align-items: center;
  justify-content: space-between;
  padding: 4px 12px 12px 20px;
  margin-bottom: 4px;
  border-bottom: 1px solid #e2e8f0;
}
.m-drawer-head img {
  height: 22px;
  width: auto;
}
.m-drawer-head .m-menu-btn {
  margin: 0;
}
/* The drawer built for the course page has no desktop place to live. */
.lms-sidebar.m-built {
  position: fixed;
  left: -290px;
}

/* Swipeable wrapper mobile.js puts round wide lesson tables. */
.m-table-scroll {
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  margin: 1rem 0;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
}
.m-table-scroll > * {
  margin: 0 !important;
}
@media (max-width: 768px) {
  .m-empty-strip {
    display: none !important;
  }
}
.m-table-hint {
  display: none;
}

/* =============================================================================
   Tablet and below: the sidebars become drawers
   ========================================================================== */
@media (max-width: 1024px) {
  .m-menu-btn {
    display: inline-flex;
  }
  /* Bell + avatar always sit at the right edge. Most pages have a title
     that fills the middle; the course page has none, so without this they
     drifted left beside the logo. */
  .lms-header .header-actions {
    margin-left: auto !important;
  }

  /* Main app sidebar — already off-canvas in the page CSS; make it a proper
     drawer: above the backdrop, full height, with a shadow when open. */
  .lms-sidebar {
    top: 0 !important;
    height: 100vh !important;
    height: 100dvh !important;
    width: 280px !important;
    left: -290px !important;
    z-index: 60 !important;
    padding-top: 12px;
    transition: left 0.25s ease, box-shadow 0.25s ease !important;
  }
  .lms-sidebar.open {
    left: 0 !important;
    box-shadow: 0 20px 60px rgba(15, 23, 42, 0.25);
  }
  .lms-sidebar .m-drawer-head {
    display: flex;
  }
  .lms-sidebar .m-drawer-head + .sidebar-nav {
    padding-top: 12px;
  }

  /* The course page's desktop icon rail: replaced by the same drawer. */
  .m-rail {
    display: none !important;
  }

  /* ---- Lesson player ---------------------------------------------------- */
  /* Course outline (left) and AI assistant (right) slide over the lesson
     instead of squeezing it. Hidden completely when closed — at width 0 their
     contents used to spill into view at the screen edge. */
  .lesson-sidebar,
  .lesson-assistant {
    position: fixed !important;
    top: 0;
    bottom: 0;
    height: 100vh;
    height: 100dvh;
    z-index: 60 !important;
    background: #fff;
    overflow-y: auto;
    transition: transform 0.25s ease, visibility 0.25s ease !important;
  }
  .lesson-sidebar {
    left: 0;
    width: min(320px, 86vw) !important;
    transform: translateX(-105%) !important;
    visibility: hidden;
  }
  .lesson-sidebar.m-open {
    transform: translateX(0) !important;
    visibility: visible;
    box-shadow: 0 20px 60px rgba(15, 23, 42, 0.25);
  }
  .lesson-assistant {
    right: 0;
    width: min(380px, 100vw) !important;
    transform: translateX(105%) !important;
    visibility: hidden;
  }
  .lesson-assistant.m-open {
    transform: translateX(0) !important;
    visibility: visible;
    box-shadow: 0 20px 60px rgba(15, 23, 42, 0.25);
  }
}

/* Below Tailwind's lg breakpoint the dashboard columns stack. The stats
   column's top padding lines it up with the heading beside it on desktop;
   stacked, it is only an empty gap. */
@media (max-width: 1023.98px) {
  .lms-content .pt-\[3\.25rem\] {
    padding-top: 0 !important;
  }
}

/* =============================================================================
   Phones
   ========================================================================== */
@media (max-width: 768px) {
  /* ---- Header ----------------------------------------------------------- */
  .lms-header {
    padding-left: 12px !important;
    padding-right: 12px !important;
    gap: 4px;
  }
  .header-logo-section {
    padding: 0 !important;
    min-width: 0;
  }
  .header-logo img {
    height: 20px !important;
  }
  .header-title-section {
    margin-left: 12px !important;
  }
  .header-title-section h1 {
    font-size: 16px !important;
  }
  /* "Welcome, <name>" repeats on every page; the space goes to the title. */
  .header-title-section p {
    display: none !important;
  }
  .header-actions {
    gap: 4px !important;
    margin-left: 4px;
  }

  /* ---- Page body -------------------------------------------------------- */
  .lms-content {
    padding: 1.25rem 1rem 1.5rem !important;
    min-width: 0;
  }
  .lms-content h1.text-3xl,
  .lms-content h1.text-4xl {
    font-size: 1.625rem !important;
    line-height: 1.25;
  }
  .lms-content .gap-8 {
    gap: 1.25rem !important;
  }
  .lms-content .space-y-8 > * + * {
    margin-top: 1.5rem !important;
  }
  /* Long words, URLs and hashes wrap instead of pushing the layout wide. */
  .lms-content,
  .lesson-content-html {
    overflow-wrap: anywhere;
  }

  /* Footer: copyright on one line, links on the next. */
  .m-footer {
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 12px;
    margin-top: 2rem !important;
  }
  .m-footer > div:last-child {
    gap: 20px !important;
  }

  /* ---- Lists of cards --------------------------------------------------- */
  /* Session/recording titles wrap rather than being cut to "Web3 in Prac…". */
  .lms-content .card h3.truncate {
    white-space: normal !important;
    overflow: visible !important;
    text-overflow: clip !important;
  }
  /* Session / recording rows: date tile on the left, and the text with its
     badge or button stacked beside it — the badge no longer orphans itself
     under the tile. */
  .lms-content .card > .p-5.flex.items-center {
    display: grid !important;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: start !important;
    column-gap: 14px;
    row-gap: 10px;
    padding: 16px !important;
  }
  .lms-content .card > .p-5.flex.items-center > :nth-child(n + 3) {
    grid-column: 2;
    justify-self: start;
  }

  /* Dashboard quick actions: equal, full-width buttons rather than three
     ragged widths. */
  .lms-content .bg-slate-50.rounded-xl.py-5.px-8 {
    padding: 1.25rem !important;
  }
  .lms-content .bg-slate-50.rounded-xl .flex-wrap.gap-1 {
    width: 100%;
    flex-direction: column;
    align-items: stretch !important;
    gap: 8px !important;
  }
  .lms-content .bg-slate-50.rounded-xl .flex-wrap.gap-1 > a,
  .lms-content .bg-slate-50.rounded-xl .flex-wrap.gap-1 .btn {
    width: 100%;
    justify-content: flex-start;
  }

  /* Wide lesson tables: readable column widths inside the swipe box. */
  .m-table-scroll table {
    min-width: 0 !important;
    width: max-content !important;
    max-width: none !important;
  }
  .m-table-scroll th,
  .m-table-scroll td {
    white-space: normal !important;
    min-width: 8.5rem;
    max-width: 15rem;
    font-size: 14px;
    line-height: 1.5;
  }
  /* The first column is usually short labels; keep it narrow so more of the
     description shows before the reader has to swipe. */
  .m-table-scroll th:first-child,
  .m-table-scroll td:first-child {
    min-width: 7rem;
    max-width: 9.5rem;
  }

  /* ---- Course page: module rows ---------------------------------------- */
  /* Title gets the full width; "11 lessons · 4 subsections" sits beneath it. */
  .m-module-row {
    align-items: flex-start !important;
    padding: 14px !important;
    gap: 10px;
  }
  .m-module-row > div:first-child {
    gap: 12px !important;
    min-width: 0;
    flex: 1;
  }
  .m-module-row > div:last-child {
    flex-shrink: 0;
    padding-top: 6px;
  }
  .m-module-row > div:last-child > span:first-child {
    display: none;
  }
  .m-module-meta {
    display: block !important;
    margin-top: 4px;
    font-size: 12px;
    color: #64748b;
    font-weight: 500;
  }

  /* ---- Lesson player ---------------------------------------------------- */
  .m-lesson-body {
    padding: 1.25rem 1.125rem 7rem !important;
  }
  .m-lesson-body h1 {
    font-size: 1.5rem !important;
    line-height: 1.3 !important;
  }
  .lesson-content-html {
    font-size: 15px;
    line-height: 1.7;
  }
  /* Justified text makes rivers of white space in a narrow column. */
  .lesson-content-html p,
  .lesson-content-html li,
  .lesson-content-html div {
    text-align: left !important;
  }
  .lesson-content-html img,
  .lesson-content-html video,
  .lesson-content-html iframe {
    max-width: 100% !important;
    height: auto;
  }
  .lesson-content-html iframe {
    aspect-ratio: 16 / 9;
    width: 100% !important;
  }
  .lesson-content-html pre {
    max-width: 100%;
    overflow-x: auto;
  }
  .m-table-hint {
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 1rem 0 -0.5rem;
    font-size: 12px;
    color: #64748b;
  }
  .m-table-hint svg {
    width: 14px;
    height: 14px;
  }

  /* Player header: tighter padding so the controls fit. */
  .m-player-header {
    padding-left: 12px !important;
    padding-right: 12px !important;
  }

  /* Bottom bar: Previous / Complete / Next must always fit on one line. */
  .m-lesson-nav {
    padding: 10px 12px !important;
    padding-bottom: calc(10px + env(safe-area-inset-bottom)) !important;
    gap: 8px;
  }
  .m-lesson-nav .btn {
    padding: 0.55rem 0.8rem !important;
    font-size: 13px !important;
    white-space: nowrap;
    gap: 6px !important;
    min-height: 40px;
  }
}

@media (max-width: 640px) {
  /* A sliver of lesson beside the assistant is no use; take the screen. */
  .lesson-assistant {
    width: 100vw !important;
  }

  /* Notifications: a 384px dropdown pinned to the bell hung off the left
     edge of a phone, hiding the heading and "View all". Here it is a sheet
     under the header with even margins; the page behind is dimmed (a spread
     shadow, so tapping it still closes the panel through Alpine's
     click.away). Display is left alone — Alpine shows and hides it. */
  .notification-dropdown {
    position: fixed !important;
    top: calc(var(--header-height, 64px) + 8px) !important;
    left: 12px !important;
    right: 12px !important;
    width: auto !important;
    max-width: none !important;
    border-radius: 16px !important;
    box-shadow: 0 18px 50px rgba(15, 23, 42, 0.22), 0 0 0 100vmax rgba(15, 23, 42, 0.35) !important;
    z-index: 70 !important;
  }
  .notification-dropdown-header {
    padding: 14px 16px !important;
  }
  .notification-dropdown-header h3 {
    font-size: 15px !important;
  }
  .notification-dropdown-content {
    /* Header (64) + gap + panel header + footer, so the panel never runs
       past the bottom of the screen; the list scrolls inside it. */
    max-height: calc(100vh - 64px - 150px) !important;
    max-height: calc(100dvh - 64px - 150px) !important;
    overscroll-behavior: contain;
  }
  .notification-item {
    padding: 14px 16px !important;
    gap: 12px;
  }
  .notification-dropdown-footer {
    padding: 12px 16px !important;
    flex-wrap: wrap;
    gap: 10px;
  }
  .notification-dropdown-footer button,
  .notification-dropdown-footer a {
    font-size: 13px !important;
    padding: 4px 0 !important;
  }
}

@media (max-width: 360px) {
  /* Smallest phones (320px): the last lesson's "Course Completed" must still fit. */
  .m-lesson-nav {
    padding-left: 8px !important;
    padding-right: 8px !important;
    gap: 6px;
  }
  .m-lesson-nav .btn {
    font-size: 12px !important;
    padding: 0.5rem 0.6rem !important;
    gap: 4px !important;
  }
}

@media (max-width: 430px) {
  /* "Previous" becomes its chevron; the label is kept for screen readers. */
  .m-lesson-nav .m-prev span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }
  .m-lesson-nav .m-prev {
    padding-left: 0.6rem !important;
    padding-right: 0.6rem !important;
  }
  .lms-content {
    padding-left: 0.875rem !important;
    padding-right: 0.875rem !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  .m-backdrop,
  .lms-sidebar,
  .lesson-sidebar,
  .lesson-assistant {
    transition: none !important;
  }
}
