/* ==========================================================================
   Examnotes Instapaper Exact 3-Pane Interface Stylesheet
   Extreme Left Nav | Middle Feed | Right Reader
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Typography & Colors (Exact Instapaper Specs)
   -------------------------------------------------------------------------- */
html, body {
  margin: 0 !important;
  padding: 0 !important;
}

:root {
  --ip-serif: Charter, "Bitstream Charter", "Sitka Text", Cambria, Georgia, serif;
  --ip-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  
  --ip-bg-left: #f6f6f5;
  --ip-bg-middle: #ffffff;
  --ip-bg-right: #ffffff;
  --ip-border: #e8e8e7;
  --ip-border-light: #f1f1f0;
  
  --ip-text-title: #1a1a1a;
  --ip-text-body: #222222;
  --ip-text-meta: #8c8c8b;
  --ip-text-glimpse: #555555;
  
  --ip-active-blue: #2563eb;
  --ip-hover-gray: #ebebea;
  --ip-active-pill: #ebebea;
}

[data-md-color-scheme="slate"] {
  --ip-bg-left: #18181b;
  --ip-bg-middle: #1e1e24;
  --ip-bg-right: #18181b;
  --ip-border: #27272a;
  --ip-border-light: #222226;
  
  --ip-text-title: #f4f4f5;
  --ip-text-body: #e4e4e7;
  --ip-text-meta: #a1a1aa;
  --ip-text-glimpse: #d4d4d8;
  
  --ip-active-blue: #3b82f6;
  --ip-hover-gray: rgba(255, 255, 255, 0.06);
  --ip-active-pill: #27272a;
}

/* --------------------------------------------------------------------------
   2. Desktop Layout: Seamless Full-Height 3-Pane Window
   -------------------------------------------------------------------------- */
@media (min-width: 960px) {
  .md-header {
    display: none !important;
  }

  .md-container {
    margin: 0 !important;
    padding: 0 !important;
  }

  .md-main {
    margin: 0 !important;
    padding: 0 !important;
  }

  .md-main__inner {
    margin: 0 !important;
    max-width: 100% !important;
    padding: 0 !important;
    display: flex !important;
  }

  .md-sidebar--secondary {
    display: none !important;
  }

  /* Extreme Left Panel (.md-sidebar--primary) */
  .md-sidebar--primary {
    position: sticky !important;
    top: 0 !important;
    align-self: flex-start !important;
    width: 240px !important;
    min-width: 240px !important;
    max-width: 240px !important;
    height: 100vh !important;
    background-color: var(--ip-bg-left) !important;
    border-right: 1px solid var(--ip-border) !important;
    display: flex !important;
    flex-direction: column !important;
    overflow-y: hidden !important;
    z-index: 20 !important;
  }

  .md-sidebar--primary .md-sidebar__scrollwrap {
    height: 100% !important;
    margin: 0 !important;
  }

  .md-sidebar--primary .md-sidebar__inner {
    height: 100% !important;
    padding: 0 !important;
    margin: 0 !important;
    display: flex !important;
    flex-direction: column !important;
  }

  /* Main Content Area */
  .md-content {
    flex: 1 !important;
    min-width: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
  }

  .md-content__inner {
    margin: 0 !important;
    padding: 0 !important;
    max-width: 100% !important;
  }

  /* Question pages only: lock to the viewport and let each pane scroll on its own.
     Every other page (home, overview) scrolls normally. */
  .md-main__inner:has(.instapaper-container, .instapaper-app),
  .md-content:has(.instapaper-container, .instapaper-app) {
    height: 100vh !important;
    overflow: hidden !important;
  }

  .md-content__inner:has(.instapaper-container, .instapaper-app) {
    height: 100% !important;
  }

  /* Normal pages: keep the text off the screen edges */
  .md-content__inner:not(:has(.instapaper-container, .instapaper-app)) {
    padding: 24px clamp(20px, 4vw, 56px) 64px !important;
  }

  .instapaper-app {
    display: flex !important;
    width: 100% !important;
    height: 100vh !important;
    overflow: hidden !important;
  }
}

/* --------------------------------------------------------------------------
   3. Extreme Left Panel: Clean Instapaper Sidebar Structure
   -------------------------------------------------------------------------- */
.ip-sidebar-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
}

.ip-brand-header {
  padding: 24px 20px 18px;
  font-family: var(--ip-serif);
  font-size: 24px;
  font-weight: 700;
  color: var(--ip-text-title);
  letter-spacing: -0.02em;
}

.ip-nav-list {
  flex: 1;
  padding: 4px 10px;
  overflow-y: auto;
}

.ip-nav-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 7px 12px;
  margin-bottom: 3px;
  border-radius: 8px;
  text-decoration: none !important;
  font-family: var(--ip-sans);
  font-size: 13.5px;
  color: var(--ip-text-body) !important;
  transition: background 0.12s ease;
  cursor: pointer;
  user-select: none;
}

.ip-nav-row:hover {
  background-color: var(--ip-hover-gray);
  color: var(--ip-text-title) !important;
}

.ip-nav-row.is-active {
  background-color: var(--ip-active-pill) !important;
  color: var(--ip-text-title) !important;
  font-weight: 600 !important;
}

.ip-row-icon {
  color: #555555;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
}

[data-md-color-scheme="slate"] .ip-row-icon {
  color: #a1a1aa;
}

.ip-nav-row.is-active .ip-row-icon {
  color: var(--ip-text-title);
}

.ip-row-label {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ip-row-badge {
  font-size: 12px;
  color: var(--ip-text-meta);
  font-weight: 400;
}

.ip-section-heading {
  padding: 16px 12px 6px;
  font-family: var(--ip-sans);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ip-text-meta);
  letter-spacing: 0.02em;
}

/* User Profile Footer */
.ip-user-footer {
  margin-top: auto;
  padding: 14px 18px;
  border-top: 1px solid var(--ip-border);
  background-color: var(--ip-bg-left);
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--ip-sans);
  font-size: 13px;
  font-weight: 600;
  color: var(--ip-text-title);
}

.ip-user-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  overflow: hidden;
  background-color: #3b82f6;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}

.ip-user-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ip-user-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ip-user-more {
  color: var(--ip-text-meta);
  cursor: pointer;
}

/* --------------------------------------------------------------------------
   4. Middle Section: Question Feed (.instapaper-feed)
   -------------------------------------------------------------------------- */
.instapaper-feed {
  width: 370px;
  min-width: 350px;
  max-width: 390px;
  height: 100%;
  background-color: var(--ip-bg-middle);
  border-right: 1px solid var(--ip-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.instapaper-feed-header {
  height: 52px;
  min-height: 52px;
  padding: 0 16px;
  border-bottom: 1px solid var(--ip-border);
  background-color: var(--ip-bg-middle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.feed-header-left {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--ip-sans);
}

.feed-home-icon {
  font-size: 17px;
  color: var(--ip-text-title);
}

.feed-home-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--ip-text-title);
}

.feed-count {
  font-size: 13px;
  color: var(--ip-text-meta);
  margin-left: 2px;
}

.feed-header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.feed-icon-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--ip-text-meta);
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.15s ease;
}

.feed-icon-btn:hover {
  color: var(--ip-text-title);
}

.feed-search-drawer {
  padding: 8px 16px;
  border-bottom: 1px solid var(--ip-border);
  background-color: var(--ip-bg-left);
}

.feed-search-input {
  width: 100%;
  padding: 6px 10px;
  font-size: 13px;
  font-family: var(--ip-sans);
  border: 1px solid var(--ip-border);
  border-radius: 6px;
  outline: none;
  background-color: var(--ip-bg-middle);
  color: var(--ip-text-title);
}

.instapaper-card-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.instapaper-card {
  display: flex;
  gap: 12px;
  justify-content: space-between;
  align-items: flex-start;
  padding: 12px 14px;
  margin-bottom: 6px;
  border-radius: 8px;
  border: 1.5px solid transparent;
  background-color: var(--ip-bg-middle);
  cursor: pointer;
  transition: all 0.12s ease;
  user-select: none;
}

.instapaper-card:hover {
  background-color: #fafaf9;
}

[data-md-color-scheme="slate"] .instapaper-card:hover {
  background-color: rgba(255, 255, 255, 0.04);
}

.instapaper-card.is-active {
  border-color: var(--ip-active-blue) !important;
  background-color: var(--ip-bg-middle) !important;
  box-shadow: 0 1px 4px rgba(37, 99, 235, 0.08);
}

.card-body {
  flex: 1;
  min-width: 0;
}

.card-title {
  font-family: var(--ip-sans) !important;
  font-size: 14.5px !important;
  font-weight: 700 !important;
  color: var(--ip-text-title) !important;
  line-height: 1.32 !important;
  margin: 0 0 4px 0 !important;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-meta {
  font-family: var(--ip-sans);
  font-size: 11.5px;
  color: var(--ip-text-meta);
  margin-bottom: 5px;
  font-weight: 400;
}

.card-glimpse {
  font-family: var(--ip-sans);
  font-size: 12.5px;
  color: var(--ip-text-glimpse);
  line-height: 1.42;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.card-thumb {
  width: 64px;
  height: 64px;
  min-width: 64px;
  border-radius: 6px;
  border: 1px solid var(--ip-border);
  overflow: hidden;
  background-color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* --------------------------------------------------------------------------
   5. Right Section: Whole Answer Reader Pane (.instapaper-reader)
   -------------------------------------------------------------------------- */
.instapaper-reader {
  flex: 1;
  height: 100%;
  overflow-y: auto;
  background-color: var(--ip-bg-right);
  display: flex;
  flex-direction: column;
}

.instapaper-toolbar {
  height: 52px;
  min-height: 52px;
  padding: 0 28px;
  border-bottom: 1px solid var(--ip-border);
  background-color: var(--ip-bg-right);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}

.toolbar-left,
.toolbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.toolbar-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--ip-text-meta);
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--ip-sans);
  transition: color 0.15s ease;
}

.toolbar-btn:hover {
  color: var(--ip-text-title);
}

.toolbar-btn.fav-btn.is-favorited svg {
  fill: #ef4444;
  stroke: #ef4444;
}

.toolbar-btn.type-settings-btn {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.05em;
}

.mobile-back-btn {
  display: none;
  font-size: 13.5px;
  font-weight: 700;
  color: var(--ip-active-blue);
}

.typography-dropdown-wrap {
  position: relative;
}

.type-settings-menu {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 10px;
  width: 180px;
  background: var(--ip-bg-middle);
  border: 1px solid var(--ip-border);
  border-radius: 8px;
  padding: 10px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.12);
  z-index: 100;
}

.type-settings-menu.is-visible {
  display: block;
}

.type-menu-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.type-menu-row:last-child {
  margin-bottom: 0;
}

.type-menu-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--ip-text-meta);
  font-family: var(--ip-sans);
}

.type-pill-group {
  display: flex;
  border: 1px solid var(--ip-border);
  border-radius: 6px;
  overflow: hidden;
}

.font-pill, .size-pill {
  background: none;
  border: none;
  padding: 3px 8px;
  font-size: 12px;
  cursor: pointer;
  color: var(--ip-text-meta);
  font-family: var(--ip-sans);
}

.font-pill.is-selected {
  background-color: var(--ip-active-blue);
  color: #ffffff;
  font-weight: 700;
}

/* Article Reading Viewport */
.instapaper-article {
  max-width: 740px;
  width: 100%;
  margin: 0 auto;
  padding: 40px 36px 90px;
  font-family: var(--ip-serif);
  font-size: 19px;
  line-height: 1.72;
  color: var(--ip-text-body);
}

.instapaper-article.font-sans {
  font-family: var(--ip-sans) !important;
}

.reader-header {
  margin-bottom: 24px;
}

.reader-title {
  font-family: inherit !important;
  font-size: 32px !important;
  font-weight: 700 !important;
  line-height: 1.25 !important;
  letter-spacing: -0.015em;
  color: var(--ip-text-title) !important;
  margin: 0 0 10px 0 !important;
}

.reader-byline {
  font-family: var(--ip-sans);
  font-size: 13px;
  color: var(--ip-text-meta);
  font-weight: 400;
}

.article-lead {
  font-size: 19.5px;
  line-height: 1.58;
  color: #333333;
  margin-bottom: 28px;
  font-family: inherit;
}

[data-md-color-scheme="slate"] .article-lead {
  color: #d4d4d8;
}

.article-illustration {
  margin: 28px 0;
  text-align: center;
}

.article-illustration img {
  max-width: 100%;
  border-radius: 8px;
  border: 1.5px solid #1a1a1a;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.05);
  background: #ffffff;
}

[data-md-color-scheme="slate"] .article-illustration img {
  border-color: #3f3f46;
}

.article-illustration figcaption {
  font-family: var(--ip-sans);
  font-size: 13px;
  color: var(--ip-text-meta);
  font-style: italic;
  margin-top: 10px;
  margin-bottom: 24px;
  text-align: left;
}

.reader-content h3 {
  font-family: inherit !important;
  font-size: 22px !important;
  font-weight: 700 !important;
  margin: 36px 0 14px 0 !important;
  color: var(--ip-text-title) !important;
}

.reader-content p, .reader-content li {
  margin-bottom: 1.2em;
}

.instapaper-app.is-reader-expanded .instapaper-feed {
  display: none !important;
}

/* --------------------------------------------------------------------------
   6. Mobile Responsiveness (< 960px)
   -------------------------------------------------------------------------- */
@media (max-width: 959px) {
  .instapaper-app {
    display: flex;
    flex-direction: column;
    width: 100%;
  }

  .instapaper-feed {
    width: 100%;
    max-width: 100%;
    border-right: none;
    height: auto;
  }

  .instapaper-reader {
    display: none;
    width: 100%;
  }

  .instapaper-app.mobile-reader-open .instapaper-feed {
    display: none;
  }

  .instapaper-app.mobile-reader-open .instapaper-reader {
    display: flex;
  }

  .mobile-back-btn {
    display: inline-block;
  }

  .instapaper-article {
    padding: 24px 18px 60px;
    font-size: 17.5px;
  }

  .reader-title {
    font-size: 26px !important;
  }
}


/* --------------------------------------------------------------------------
   7. Behaviour fixes (scrolling / focus)
   -------------------------------------------------------------------------- */
/* The page title is redundant on question pages (the list header shows it); hide it at every width */
.instapaper-subject-title,
.md-content__inner:has(.instapaper-app) > h1 {
  display: none !important;
}

/* Scrolling inside the list or the answer must never drag the page behind it */
.instapaper-card-list,
.instapaper-reader {
  overscroll-behavior: contain;
}

.instapaper-card:focus-visible {
  outline: 2px solid #3b82f6;
  outline-offset: -2px;
}

/* Question pages on desktop: the panes already fill the screen, so the theme footer and its
   8px top spacer would only create a second, page-level scrollbar behind the panes. */
.md-content__inner:has(.instapaper-app)::before,
.md-content__inner:has(.instapaper-app)::after {
  display: none !important;
}

@media (min-width: 960px) {
  .md-container:has(.instapaper-app) > .md-footer {
    display: none !important;
  }
}

/* KaTeX adds an invisible position:absolute copy of every equation. With no positioned ancestor those
   copies escaped the reader pane and stretched the whole page, creating a second page-level scrollbar
   behind the panes. A positioned reader keeps them inside its own scroll area. */
.instapaper-reader,
.instapaper-feed {
  position: relative;
}
