/* Persistent, low-profile access to study tools without obstructing the current page. */
.floating-tools {
  position: fixed;
  z-index: 88;
  right: 22px;
  bottom: 22px;
  display: grid;
  gap: 9px;
  transition: opacity .18s ease, transform .18s ease;
}

/* Dialog elements sit above page-level fixed tools, so the reader has its own pair. */
.reader-quick-tools {
  position: fixed;
  z-index: 2;
  right: 22px;
  bottom: 22px;
  display: grid;
  gap: 9px;
}

/* The panel is moved inside the full-screen reader dialog while a material is open. */
#materialDialog .right-panel {
  position: absolute;
  z-index: 4;
  top: auto;
  right: 18px;
  bottom: 18px;
  left: auto;
  width: min(430px, calc(100vw - 36px));
  height: min(610px, calc(100dvh - 36px));
  box-sizing: border-box;
}

#materialDialog .right-panel[data-panel-kind="chat"] {
  height: min(570px, calc(100dvh - 36px));
}

#materialDialog .right-panel #chatPanel:not([hidden]),
#materialDialog .right-panel #chatEnabledContent:not([hidden]) {
  min-height: 0;
  height: 100%;
}

#materialDialog .right-panel .online-list {
  max-height: 58px;
}

.floating-tools.panel-open {
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
}

.floating-tool {
  width: 48px;
  height: 48px;
  border: 1px solid rgba(212, 224, 231, .42);
  border-radius: 50%;
  background: rgba(7, 14, 18, .58);
  color: #f8fbfd;
  display: grid;
  place-items: center;
  font-size: 1.18rem;
  cursor: pointer;
  backdrop-filter: blur(10px);
  box-shadow: 0 7px 20px rgba(0, 0, 0, .26), 0 0 18px rgba(0, 217, 255, .06);
  opacity: .76;
  transition: opacity .18s ease, transform .18s ease, border-color .18s ease, background .18s ease, box-shadow .18s ease;
}

.floating-tool:hover,
.floating-tool:focus-visible {
  opacity: 1;
  transform: translateY(-2px);
  border-color: rgba(111, 220, 255, .8);
  background: rgba(7, 25, 32, .9);
  box-shadow: 0 10px 26px rgba(0, 0, 0, .32), 0 0 20px rgba(0, 217, 255, .18);
}

.floating-tool.notebook:hover,
.floating-tool.notebook:focus-visible {
  border-color: rgba(121, 255, 185, .72);
  background: rgba(5, 29, 19, .9);
}

.right-panel-scrim {
  display: none !important;
}

.right-panel {
  position: fixed;
  z-index: 96;
  top: auto;
  right: 22px;
  bottom: 22px;
  width: min(430px, calc(100vw - 44px));
  height: min(610px, calc(100dvh - 44px));
  padding: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
  border: 1px solid rgba(137, 159, 171, .46);
  border-radius: 20px;
  background: linear-gradient(155deg, rgba(13, 24, 30, .985), rgba(2, 5, 7, .99) 66%);
  box-shadow: 0 22px 76px rgba(0, 0, 0, .64), 0 0 36px rgba(0, 217, 255, .08);
  transform: translateY(calc(100% + 42px));
  transition: transform .24s ease;
}

.right-panel.open {
  transform: translateY(0);
}

.right-panel[data-panel-kind="notebook"] {
  width: min(530px, calc(100vw - 44px));
  height: min(700px, calc(100dvh - 44px));
}

.right-panel-head {
  align-items: center;
  padding: 13px 14px;
  border-bottom-color: rgba(133, 153, 165, .25);
  background: rgba(255, 255, 255, .015);
}

.right-panel-head h3 {
  margin: 2px 0 0;
  font-size: 1.05rem;
}

.right-panel-actions {
  display: flex;
  gap: 6px;
}

.right-panel-actions .icon-btn {
  width: 34px;
  min-width: 34px;
  height: 34px;
  min-height: 34px;
  padding: 0;
  border-radius: 10px;
}

.right-panel-section {
  min-height: 0;
  padding: 13px 14px 14px;
  overflow: auto;
}

.right-panel-section[hidden],
#chatEnabledContent[hidden] {
  display: none !important;
}

#chatPanel:not([hidden]) {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

#chatEnabledContent:not([hidden]) {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(130px, 1fr) auto auto;
  gap: 9px;
}

.chat-access-state {
  margin-bottom: 0;
  padding: 10px 11px;
  font-size: .78rem;
}

.chat-access-state.ok,
#chatEnabledContent > .panel-label {
  display: none;
}

.online-list {
  max-height: 48px;
  display: flex;
  gap: 6px;
  overflow: auto;
  padding-bottom: 2px;
}

.online-person {
  flex: 0 0 min(220px, 80%);
  padding: 5px 8px;
}

.online-person span {
  font-size: .67rem;
}

.chat-messages {
  min-height: 0;
  max-height: none;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  padding: 2px 3px 2px 0;
}

.chat-message {
  padding: 8px 9px;
  font-size: .79rem;
}

.chat-message-head {
  font-size: .68rem;
}

.chat-message small {
  font-size: .64rem;
}

.chat-compose {
  grid-template-columns: minmax(0, 1fr) auto;
}

.chat-compose textarea {
  min-height: 58px;
  max-height: 110px;
}

#notebookPanel:not([hidden]) {
  display: grid;
  align-content: start;
}

.notebook-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: end;
}

.notebook-toolbar label {
  display: grid;
  gap: 5px;
  min-width: 0;
  font-size: .75rem;
  font-weight: 800;
}

.notebook-toolbar select {
  width: 100%;
}

.notebook-saved-list {
  max-height: 132px;
  overflow-y: auto;
  padding-right: 2px;
}

.notebook-body {
  min-height: 185px;
  resize: vertical;
}

.notebook-history {
  border-top: 1px solid rgba(133, 153, 165, .22);
  padding-top: 9px;
}

.notebook-history summary {
  cursor: pointer;
  color: var(--muted);
  font-size: .73rem;
  font-weight: 800;
}

.notebook-history .notebook-list {
  max-height: 150px;
  margin-top: 9px;
  overflow-y: auto;
}

.notebook-library {
  display: grid;
  gap: 15px;
}

.notebook-library-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.notebook-library-list {
  display: grid;
  gap: 10px;
}

.notebook-library-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 14px;
  border: 1px solid #29343d;
  border-radius: 14px;
  background: linear-gradient(155deg, #0a0d10, #050607);
}

.notebook-library-row > div {
  min-width: 0;
}

.notebook-library-row h4 {
  margin: 5px 0 4px;
}

.notebook-library-row p,
.notebook-library-row small {
  margin: 0;
  color: var(--muted);
  overflow-wrap: anywhere;
}

/* Keep the sidebar compact enough for account controls on short desktop screens. */
.sidebar {
  padding: 12px;
  gap: 10px;
}

.sidebar-top {
  min-height: 40px;
}

#nav {
  flex: 1 1 auto;
  min-height: 0;
  align-content: start;
  gap: 4px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 2px;
}

.nav-btn {
  min-height: 44px;
  padding: 9px 12px;
  border-radius: 15px;
}

.sidebar-foot {
  flex: 0 0 auto;
  gap: 7px;
}

.user-chip {
  padding: 10px 12px;
  border-radius: 15px;
}

.topbar {
  min-height: 58px;
  padding: 8px 16px;
}

.header-logo {
  width: 29px;
  height: 29px;
}

.topbar h2 {
  font-size: 1.25rem;
}

.content {
  max-width: 1640px;
  padding: 16px;
}

.app-shell.sidebar-collapsed .sidebar {
  padding: 12px 10px;
}

.app-shell.sidebar-collapsed .sidebar-top {
  justify-content: center;
}

.app-shell.sidebar-collapsed .sidebar-foot .btn {
  width: 100%;
  padding: 9px 4px;
  font-size: .72rem;
}

.app-shell.sidebar-collapsed .sidebar-foot .btn::after {
  content: none;
}

.notebook-library-row p {
  line-height: 1.5;
}

.notebook-library-row small {
  display: block;
  margin-top: 7px;
  font-size: .74rem;
}

.light .floating-tool {
  border-color: rgba(45, 70, 84, .38);
  background: rgba(255, 255, 255, .7);
  color: #10202a;
  box-shadow: 0 7px 20px rgba(20, 40, 52, .16);
}

.light .right-panel,
.light .notebook-library-row {
  background: #fff;
  border-color: #bdc8d0;
}

@media (max-width: 760px) {
  .floating-tools {
    right: 12px;
    bottom: calc(81px + env(safe-area-inset-bottom));
    grid-auto-flow: column;
    gap: 7px;
  }

  .reader-quick-tools {
    right: 12px;
    bottom: calc(18px + env(safe-area-inset-bottom));
    grid-auto-flow: column;
    gap: 7px;
  }

  #materialDialog .right-panel,
  #materialDialog .right-panel[data-panel-kind="chat"] {
    right: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    width: calc(100vw - 20px);
    height: min(68dvh, 560px);
    border-radius: 18px;
  }

  #materialDialog .right-panel[data-panel-kind="notebook"] {
    height: min(76dvh, 680px);
  }

  .floating-tool {
    width: 42px;
    height: 42px;
    font-size: 1rem;
    opacity: .7;
  }

  .right-panel,
  .right-panel[data-panel-kind="notebook"] {
    right: 10px;
    bottom: calc(78px + env(safe-area-inset-bottom));
    width: calc(100vw - 20px);
    height: min(72dvh, 620px);
    border-radius: 18px;
  }

  .right-panel[data-panel-kind="notebook"] {
    height: min(78dvh, 680px);
  }

  .right-panel-head {
    padding: 10px 12px;
  }

  .right-panel-section {
    padding: 11px 12px 12px;
  }

  .topbar {
    min-height: 56px;
    padding: 8px 10px;
  }

  .chat-compose textarea {
    min-height: 48px;
  }

  .notebook-library-row {
    flex-direction: column;
  }

  .notebook-library-row .btn {
    width: 100%;
  }
}
