/* ---------- Study: folder tree + note list (left), note detail (right) ---------- */

.study-layout {
  display: flex;
  align-items: flex-start;
  gap: var(--space-4);
}

.study-sidebar {
  width: 300px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4);
  max-height: calc(100vh - var(--topbar-height) - var(--pageheader-height) - var(--space-6));
  overflow-y: auto;
}

.study-sidebar__top {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

/* ---------- sidebar icon bar ---------- */
/* Obsidian-style: New note / New folder / Import / Collapse-all as a slim
   row of small icon buttons instead of three stacked full-width text
   buttons — same ids as before (js/pages/study.js's shellHtml), just a
   different visual treatment. */
.study-icon-bar {
  display: flex;
  align-items: center;
  gap: 2px;
}

.study-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.study-icon-btn:hover {
  color: var(--text);
  background: rgba(245, 245, 245, 0.08);
}

/* Delete keeps the app-wide .row-delete-btn class (red-on-hover danger
   convention, used the same way elsewhere) but sized/flattened to match
   the icon-button language instead of its default bordered-pill look. */
.study-icon-btn--delete.row-delete-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: none;
  background: transparent;
}

.study-icon-btn--delete.row-delete-btn:hover {
  background: rgba(244, 80, 106, 0.12);
}

/* ---------- search ---------- */
.study-search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.study-search-icon {
  position: absolute;
  left: var(--space-2);
  display: flex;
  color: var(--muted);
  pointer-events: none;
}

/* A small uppercase eyebrow above the folder tree and note list — the only
   thing that previously separated them was a single border line, which
   didn't say what was on either side of it. */
.study-sidebar__label {
  margin: 0;
  padding-top: var(--space-3);
  border-top: 1px solid var(--border);
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.study-search-input {
  width: 100%;
  background: var(--bg);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 6px var(--space-2) 6px 27px;
  font-size: 0.82rem;
  color: var(--text);
}

.study-search-input:focus {
  border-color: var(--border);
}

.study-search-input::placeholder {
  color: var(--muted);
}

.study-folder-tree,
.study-folder-children {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.study-folder-children {
  margin-top: var(--space-1);
}

/* Same fix as .study-color-popover[hidden] elsewhere in this file: an
   author display value (display:flex above) always beats the UA
   stylesheet's [hidden] rule, so a collapsed folder's children would stay
   visually shown despite the hidden attribute without this override. */
.study-folder-children[hidden] {
  display: none;
}

.study-folder-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  width: 100%;
  min-width: 0;
  text-align: left;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  padding: 5px var(--space-1);
  color: var(--muted);
  font-size: 0.82rem;
  cursor: pointer;
}

.study-folder-btn__name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Every row (real folder, "All notes", "Unfiled") is a chevron/spacer +
   name button + delete button, all sharing one flex row so names line up
   regardless of nesting depth or whether a row has a delete control. */
.study-folder-row {
  display: flex;
  align-items: center;
  gap: 2px;
}

.study-folder-row .study-folder-btn {
  width: auto;
  flex: 1;
  min-width: 0;
}

/* Fixed-width slot every row reserves, whether it holds a real rotating
   chevron (a folder with children) or an inert spacer (a leaf folder, or
   "All notes"/"Unfiled") — keeps every name starting at the same x
   regardless of what's to its left. */
.study-folder-chevron {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
}

.study-folder-chevron svg {
  transition: transform var(--transition-fast);
}

.study-folder-chevron.is-expanded svg {
  transform: rotate(90deg);
}

.study-folder-chevron:hover {
  color: var(--text);
  background: rgba(245, 245, 245, 0.08);
}

.study-folder-chevron--spacer {
  cursor: default;
}

/* Hidden until the row is hovered (or the button itself has keyboard
   focus) — a minimal icon instead of an always-visible control. */
.study-folder-delete-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  padding: 0;
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--transition-fast), color var(--transition-fast), background var(--transition-fast);
}

.study-folder-row:hover .study-folder-delete-btn,
.study-folder-delete-btn:focus-visible {
  opacity: 1;
}

.study-folder-delete-btn:hover {
  color: var(--red);
  background: rgba(244, 80, 106, 0.12);
}

.study-folder-btn:hover {
  color: var(--text);
  background: rgba(245, 245, 245, 0.05);
}

.study-folder-btn.is-selected {
  color: var(--text);
  background: rgba(245, 245, 245, 0.08);
  font-weight: 600;
}

.study-folder-count {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--muted);
  opacity: 0.75;
  flex-shrink: 0;
}

.study-note-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.study-note-list__empty {
  padding: var(--space-2);
}

.study-note-row {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  text-align: left;
  background: transparent;
  border: none;
  border-left: 2px solid transparent;
  border-radius: var(--radius-sm);
  padding: var(--space-2);
  cursor: pointer;
}

.study-note-row:hover {
  background: rgba(245, 245, 245, 0.05);
}

.study-note-row.is-active {
  background: rgba(52, 211, 153, 0.08);
  border-left-color: var(--green);
}

.study-note-row__title {
  font-size: 0.9rem;
  color: var(--text);
  font-weight: 500;
}

.study-note-row__folder,
.study-note-row__date {
  font-size: 0.72rem;
  color: var(--muted);
}

.study-note-row__date {
  font-family: var(--font-mono);
}

/* ---------- detail pane ---------- */

/* Matches .study-sidebar's own height cap + internal scroll (below) — the
   two panes now scroll independently within a fixed-height split view
   instead of the whole page (and the sidebar along with it) scrolling
   together. */
.study-detail {
  flex: 1;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-6) var(--space-6) var(--space-5);
  max-height: calc(100vh - var(--topbar-height) - var(--pageheader-height) - var(--space-6));
  overflow-y: auto;
}

.study-detail__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
  flex-wrap: wrap;
}

.study-detail__titles h2 {
  font-size: 1.7rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin-bottom: var(--space-1);
  word-break: break-word;
}

/* Breadcrumb-style folder path underneath the title — note.folder itself
   stays a plain "/"-joined string (see folderBreadcrumbHtml in
   js/pages/study.js); only the separator between segments is styled. */
.study-detail__folder {
  font-size: 0.78rem;
}

.study-breadcrumb-sep {
  margin: 0 2px;
  opacity: 0.6;
}

.study-detail__actions {
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
}

/* Full-page writing mode toggle (js/pages/study.js) — same icon-button
   treatment as the chart full-screen viewer's expand/close buttons
   (chart-fullscreen.css) for a consistent interaction pattern, and reuses
   its exact expand/close icon paths. */
.study-focus-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  cursor: pointer;
  flex: none;
}

.study-focus-toggle-btn:hover {
  color: var(--text);
  border-color: var(--green);
}

.study-focus-toggle-btn.is-active {
  color: var(--green);
  border-color: var(--green);
}

/* Shared by the note's rendered view (#study-note-body) and the live
   editor body (#study-body-editor carries this class too) — capping and
   centering both here, in one place, is what gives either mode the
   "reading a document" column instead of text running edge-to-edge. The
   toolbar and header above stay full width, same as Word/Docs/Notion. */
.study-rendered-body {
  line-height: 1.6;
  max-width: 720px;
  margin: 0 auto;
}

.study-rendered-body h1,
.study-rendered-body h2,
.study-rendered-body h3,
.study-rendered-body h4,
.study-rendered-body h5,
.study-rendered-body h6 {
  margin: var(--space-5) 0 var(--space-2);
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.25;
}

/* Deliberate, clearly-stepped sizes — headings previously fell back to the
   browser's own UA-stylesheet defaults, which happen to shrink but were
   never actually chosen for this app. */
.study-rendered-body h1 {
  font-size: 1.65rem;
}

.study-rendered-body h2 {
  font-size: 1.35rem;
}

.study-rendered-body h3 {
  font-size: 1.12rem;
}

.study-rendered-body h4,
.study-rendered-body h5,
.study-rendered-body h6 {
  font-size: 1rem;
}

.study-rendered-body p {
  margin: var(--space-3) 0;
}

.study-rendered-body ul,
.study-rendered-body ol {
  padding-left: 1.4em;
  margin: var(--space-3) 0;
}

.study-rendered-body blockquote {
  border-left: 3px solid var(--border);
  padding-left: var(--space-3);
  color: var(--muted);
  margin: var(--space-3) 0;
}

.study-rendered-body hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: var(--space-5) 0;
}

/* Checklist: a plain <ul> whose <li>s each hold a live/disabled checkbox +
   a trailing <span> of text (see study-editor.js's applyChecklist). Styled
   structurally off that shape rather than the study-checklist(-item)
   classes the editor also adds — those classes only survive on the live
   editing DOM and get stripped by study-markdown.js's sanitizer on
   save/reload (UL/LI keep no class), so relying on structure instead keeps
   the checklist look identical before and after a save. */
.study-rendered-body ul:has(> li > input[type="checkbox"]) {
  list-style: none;
  padding-left: 0;
}

.study-rendered-body li:has(> input[type="checkbox"]) {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  list-style: none;
}

.study-rendered-body li > input[type="checkbox"] {
  margin-top: 4px;
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  accent-color: var(--green);
  cursor: pointer;
}

.study-rendered-body li > input[type="checkbox"]:checked ~ span {
  text-decoration: line-through;
  opacity: 0.6;
  color: var(--muted);
}

.study-rendered-body mark {
  background: var(--amber);
  color: #0a0a0a;
  padding: 1px 4px;
  border-radius: 4px;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

.study-rendered-body code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
}

.study-rendered-body pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  overflow-x: auto;
}

.study-rendered-body pre code {
  border: none;
  padding: 0;
}

.study-note-img {
  max-width: 100%;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  display: block;
  margin: var(--space-3) 0;
  cursor: pointer;
}

.study-note-missing-img {
  color: var(--muted);
  font-style: italic;
}

.study-rendered-body a {
  color: var(--green);
  text-decoration: underline;
}

/* Not a real href (JS-driven navigation to another note — see wireLinks in
   study-markdown.js), so it needs an explicit pointer cursor a real <a
   href> already gets from the browser by default. */
.study-rendered-body a.study-note-link {
  cursor: pointer;
}

/* ---------- editor ---------- */

.study-editor {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.study-editor .form-actions,
.study-editor .study-image-gallery {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
}

/* ---------- editor toolbar ---------- */
/* A slim, borderless icon row — Obsidian/Notion style: no boxed container,
   no per-group chip background, just small icon buttons with a hairline
   divider between clusters (emphasis / headings / lists / alignment /
   block inserts / highlight / history) and tooltips carrying the labels
   that used to be printed on the buttons themselves. */
.study-editor__format-toolbar {
  display: flex;
  align-items: center;
  gap: 2px var(--space-2);
  flex-wrap: wrap;
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--border);
}

.study-format-group {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 1px;
  position: relative;
  padding-right: var(--space-2);
}

.study-format-group:not(:last-child)::after {
  content: "";
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 1px;
  height: 16px;
  background: var(--border);
}

.study-format-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.study-format-btn:hover {
  color: var(--text);
  background: rgba(245, 245, 245, 0.08);
}

/* A quiet permanent tint on the Highlight toggle so it still reads as
   "this one paints color" at rest, not just on hover. */
.study-format-btn--highlight {
  color: var(--amber);
}

.study-format-btn--highlight:hover {
  background: rgba(245, 196, 81, 0.16);
}

/* Add image's upload status (or an error) — collapses to nothing when
   empty instead of reserving a blank line under the toolbar at rest. */
.study-editor #study-editor-message:empty {
  display: none;
}

/* Shared toggle+popover shell for both the Highlight and Text color
   pickers (see colorPickerHtml in study-editor.js) — one set of rules for
   both instead of near-duplicate highlight-only ones. */
.study-color-picker-group {
  position: relative;
  display: flex;
}

.study-color-popover {
  position: absolute;
  top: calc(100% + var(--space-2));
  left: 0;
  z-index: 20;
  display: flex;
  gap: var(--space-2);
  padding: var(--space-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
}

/* An author display value always beats the UA stylesheet's [hidden] rule,
   so display:flex above would otherwise keep the popover visible even
   while its hidden attribute is set (the toggle open/close logic in
   study-editor.js relies entirely on that attribute) — this restores it,
   at higher specificity than the bare class. */
.study-color-popover[hidden] {
  display: none;
}

.study-color-swatch {
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  cursor: pointer;
}

.study-color-swatch:hover {
  border-color: var(--text);
}

/* The live (WYSIWYG) contentEditable body — also carries
   .study-rendered-body (same class the read-only note view uses), so
   headings/lists/marks/images inside it are styled identically whether
   editing or just viewing; this block only adds what's specific to being
   an editable surface. */
.study-body-editor {
  width: 100%;
  min-height: 360px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  color: var(--text);
  outline: none;
  overflow-y: auto;
}

.study-body-editor:focus {
  border-color: var(--green);
}

.study-body-editor:empty::before {
  content: attr(data-placeholder);
  color: var(--muted);
}

.study-image-gallery {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.study-image-gallery__item {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  overflow: hidden;
}

.study-image-gallery__item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.study-image-gallery__remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: none;
  background: rgba(10, 10, 10, 0.75);
  color: var(--text);
  cursor: pointer;
  line-height: 1;
  font-size: 0.75rem;
}

/* ---------- full-page writing mode (js/pages/study.js) ---------- */
/* Toggled by adding/removing this class on the page's own root container —
   never by re-rendering the note (that would tear down and rebuild the
   contentEditable body, losing the cursor position, scroll position, and
   any typed-but-unsaved text). .study-detail stays the exact same DOM node,
   just repositioned to cover the full viewport. */
.study-focus-active .study-sidebar {
  display: none;
}

.study-focus-active .study-detail {
  position: fixed;
  inset: 0;
  z-index: 1000;
  max-height: none;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border: none;
  border-radius: 0;
}

.study-focus-active .study-editor {
  flex: 1;
  min-height: 0;
}

/* The editor body is the one thing that actually scrolls in focus mode —
   header and toolbar stay put, matching how a dedicated writing surface
   behaves rather than scrolling the whole panel. */
.study-focus-active .study-body-editor {
  flex: 1;
  min-height: 0;
}

/* Belt-and-suspenders: the fixed, full-viewport .study-detail already
   blocks pointer access to everything behind it, but this also stops the
   page itself from scrolling underneath while focus mode is open. */
body.study-focus-scroll-lock {
  overflow: hidden;
}

@media (max-width: 899px) {
  .study-layout {
    flex-direction: column;
  }

  .study-sidebar {
    width: 100%;
    max-height: none;
  }

  .study-detail {
    max-height: none;
    padding: var(--space-4);
  }

  .study-detail__titles h2 {
    font-size: 1.4rem;
  }
}
