/* ── Reader layout ────────────────────────────────────────────────────────── */

body.reader-mode {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

body.reader-mode .layout-main {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
}

.reader-screen {
  display: flex;
  flex: 1;
  min-height: 0;
  min-width: 0;
  --widget-pane-width: 440px;
}

/* ── Widget pane (left, resizable) ────────────────────────────────────────── */

.reader-widget-pane {
  flex: 0 0 var(--widget-pane-width);
  display: flex;
  min-height: 0;
}

/* ── Resize handle ────────────────────────────────────────────────────────── */

.reader-resize-handle {
  width: 6px;
  margin-left: -3px;
  margin-right: -3px;
  cursor: col-resize;
  z-index: 5;
  position: relative;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.reader-resize-handle > .-bar {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 2px;
  width: 2px;
  background: transparent;
  transition: background var(--dur-fast) var(--ease-out);
}

.reader-resize-handle:hover > .-bar,
.reader-resize-handle.-dragging > .-bar {
  background: var(--slate-300);
}

.reader-resize-handle > .-pill {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 4px;
  height: 36px;
  border-radius: 999px;
  background: var(--slate-400);
  box-shadow: 0 0 0 3px rgba(85, 124, 153, 0.18);
  opacity: 0;
  transition: opacity var(--dur-fast) var(--ease-out);
}

.reader-resize-handle:hover > .-pill,
.reader-resize-handle.-dragging > .-pill {
  opacity: 1;
}

/* ── PDF pane (right, flex 1) ─────────────────────────────────────────────── */

.reader-pdf-pane {
  flex: 1;
  min-width: 0;
  background: var(--paper-2);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

/* Protection gradient below toolbar */
.reader-pdf-pane::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 53px;
  height: 18px;
  background: linear-gradient(var(--paper-2), transparent);
  pointer-events: none;
  z-index: 1;
}

.reader-pdf-pane.-search-open::after {
  top: 93px;
}

.reader-pdf-pane.-search-open .pdf-loading {
  inset: 93px 0 0;
}

/* ── Mobile reader layout ─────────────────────────────────────────────────── */

@media (max-width: 767px) {
  body.reader-mode .top-bar { display: none; }

  body.reader-mode .layout-main {
    height: 100dvh;
  }

  .reader-widget-pane,
  .reader-resize-handle {
    display: none;
  }

  /* Binder tabs never needed on mobile — bottom nav handles switching */
  .reader-widget-pane > .-tabs {
    display: none;
  }

  /* Widget pane full-screen when a non-PDF tab is active */
  .reader-screen.-mobile-widget-visible .reader-widget-pane {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: calc(60px + env(safe-area-inset-bottom, 0px));
    z-index: 50;
    flex: none;
    width: 100%;
    background: var(--bg-surface);
  }

  .reader-screen.-mobile-widget-visible .reader-widget-pane > .-body {
    margin: 0;
    border-radius: 0;
    border-top: none;
    border-bottom: none;
    border-left: none;
    border-right: none;
  }

  .reader-pdf-pane::after {
    top: 52px;
  }

  .reader-pdf-pane.-search-open::after {
    top: 92px;
  }

  .reader-pdf-pane.-search-open .pdf-loading {
    inset: 92px 0 0;
  }
}

/* ── reader-mobile-header ─────────────────────────────────────────────────── */

.reader-mobile-header {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: rgba(250, 247, 242, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
  z-index: 2;
  min-height: 52px;
}

@media (max-width: 767px) {
  .reader-mobile-header { display: flex; }
}

.reader-mobile-header > .-back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  color: var(--slate-500);
  border-radius: var(--radius-sm);
  text-decoration: none;
  border-bottom: none;
  transition: background var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out);
}

.reader-mobile-header > .-back:hover {
  background: var(--slate-50);
  color: var(--slate-700);
  border-bottom: none;
}

.reader-mobile-header > .-info {
  flex: 1;
  min-width: 0;
}

.reader-mobile-header > .-info > .-title {
  font-family: var(--font-serif);
  font-size: var(--fs-14);
  font-weight: 600;
  color: var(--slate-800);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reader-mobile-header > .-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

.reader-mobile-header > .-actions > .-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--slate-600);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out);
}

.reader-mobile-header > .-actions > .-btn:hover,
.reader-mobile-header > .-actions > .-btn.-active,
.reader-mobile-header > .-actions > .-btn.-search-active {
  background: var(--slate-50);
  color: var(--slate-800);
}

.reader-mobile-header > .-actions > .-btn.-zoom-btn {
  font-size: 20px;
  font-weight: 400;
  line-height: 1;
  width: 30px;
  color: var(--slate-500);
}

/* ── reader-mobile-nav ────────────────────────────────────────────────────── */

.reader-mobile-nav {
  display: none;
}

@media (max-width: 767px) {
  .reader-mobile-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(60px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    background: rgba(250, 247, 242, 0.96);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--border-soft);
    align-items: stretch;
    z-index: 100;
  }
}

.reader-mobile-nav__tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--slate-400);
  padding: 0 4px;
  transition: color var(--dur-fast) var(--ease-out);
}

.reader-mobile-nav__tab:hover {
  color: var(--slate-600);
}

.reader-mobile-nav__tab.-active {
  color: var(--slate-700);
}

.reader-mobile-nav__tab > .-icon-wrap {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.reader-mobile-nav__tab > .-icon-wrap > .-dot {
  position: absolute;
  bottom: -1px;
  right: -3px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--slate-500);
  opacity: 0;
  transition: opacity var(--dur-fast) var(--ease-out);
}

.reader-mobile-nav__tab.-active > .-icon-wrap > .-dot {
  opacity: 1;
}

.reader-mobile-nav__tab > .-label {
  font-family: var(--font-sans);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.01em;
  line-height: 1;
}

/* ── reader-sheet-backdrop ────────────────────────────────────────────────── */

.reader-sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(30, 44, 55, 0.35);
  z-index: 9;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-slow) var(--ease-out);
}

.reader-sheet-backdrop.-open {
  opacity: 1;
  pointer-events: auto;
}

/* ── reader-mobile-sheet (highlights) ────────────────────────────────────── */

.reader-mobile-sheet {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 85vh;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-soft);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  box-shadow: 0 -8px 40px -4px rgba(10, 15, 18, 0.18);
  z-index: 10;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: translateY(105%);
  transition: transform var(--dur-slow) var(--ease-out);
}

.reader-mobile-sheet.-open {
  transform: translateY(0);
}

.reader-mobile-sheet > .-drag-handle {
  display: flex;
  justify-content: center;
  padding: 10px 0 4px;
  flex-shrink: 0;
}

.reader-mobile-sheet > .-drag-handle > .-pill {
  width: 36px;
  height: 4px;
  border-radius: var(--radius-pill);
  background: var(--slate-200);
}

.reader-mobile-sheet > .-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 20px 14px;
  border-bottom: 1px solid var(--border-soft);
  flex-shrink: 0;
}

.reader-mobile-sheet > .-header > .-title {
  font-family: var(--font-sans);
  font-size: var(--fs-18);
  font-weight: var(--fw-semibold);
  color: var(--fg-1);
}

.reader-mobile-sheet > .-header > .-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--fg-3);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out),
              color var(--dur-fast) var(--ease-out);
}

.reader-mobile-sheet > .-header > .-close:hover {
  background: var(--slate-50);
  color: var(--fg-2);
}

.reader-mobile-sheet > .-body {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
  padding-bottom: 24px;
}

/* ── Empty state (no PDF attached) ────────────────────────────────────────── */

.reader-pdf-pane.-empty {
  align-items: center;
  justify-content: center;
}

.pdf-no-attachment {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: var(--fg-3);
  text-align: center;
}

.pdf-no-attachment > .-icon {
  color: var(--slate-300);
}
