/* Layout principal */
.page-container {
  display: flex;
  height: 100vh;
  width: 100%;
  overflow: hidden;
}

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: all 0.3s ease-in-out;
  width: 100%;
}

.main-content.sidebar-open {
  margin-right: 280px;
}

.main-content.chat-open {
  margin-right: 380px;
}

/* Sidebar */
.sidebar-container {
  width: 280px;
  border-left: 1px solid var(--ntabs-border);
  background: var(--ntabs-bg-primary);
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease-in-out, background-color 0.2s ease;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  transform: translateX(100%);
}

.sidebar-container.open {
  transform: translateX(0);
}

.sidebar {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
}

.sidebar ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.sidebar li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem;
  color: var(--ntabs-text-secondary);
  border-radius: 0.375rem;
  margin-bottom: 0.25rem;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.sidebar li:hover {
  background: var(--ntabs-bg-secondary);
  color: var(--ntabs-text-primary);
}

.sidebar li.back {
  color: var(--ntabs-text-secondary);
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--ntabs-border);
  padding-bottom: 1rem;
}

.sidebar li a {
  color: inherit;
  text-decoration: none;
  font-size: 0.875rem;
  flex: 1;
}

/* Header - main page header with logo, breadcrumbs, and actions */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--ntabs-border);
  background: var(--ntabs-header-bg);
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.page-header-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.page-header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-left: auto;
}

.back-button {
  display: flex;
  align-items: center;
  color: var(--ntabs-text-secondary);
  text-decoration: none;
  font-size: 0.875rem;
  transition: color 0.2s ease;
}

.back-button:hover {
  color: var(--ntabs-text-primary);
}

/* Conteúdo */
.page-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Turbo-frame styling - layout rules are in empty_state.css for consistency */
.page-content > turbo-frame {
  background-color: var(--ntabs-bg-secondary);
  transition: background-color 0.2s ease;
}

.lesson-navigation {
  padding: 1.5rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--ntabs-bg-primary);
  border-bottom: 1px solid var(--ntabs-border);
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.lesson-count {
  color: var(--ntabs-text-secondary);
  font-size: 0.875rem;
}

.lesson-title {
  font-size: 2rem;
  font-weight: 600;
  color: var(--ntabs-text-primary);
  margin-bottom: 1.5rem;
}

.lesson-navigation .sidebar-actions {
  display: flex;
  align-items: center;
}

/* Editor Content - layout rules in empty_state.css, styling here */
.content {
  padding: 2rem;
  background-color: var(--ntabs-bg-secondary);
  transition: background-color 0.2s ease;
}

/* Mark editor container
   !important needed to override Mark.js library defaults for ntabs integration */
.mark-container {
  background: var(--ntabs-bg-primary) !important;
  padding: 0 !important;
  border: none !important;
  border-radius: 0 !important;
  min-height: 400px;
  transition: background-color 0.2s ease;
}

.mark-container.mark-dark {
  background: var(--mark-bg-primary, #0d1117) !important;
}

/* DocMap positioning fix for delegateScroll mode
   Layout: [content + scrollbar] [DocMap at viewport edge]

   We need to:
   1. Add padding-right to page-content to make room for DocMap
   2. Position DocMap fixed to the viewport right edge
   3. Remove the mark-panels margin since DocMap is now outside the scroll container */

/* Add right padding to page-content to reserve space for DocMap */
.page-content {
  transition: padding-right 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Collapsed state (default when visible) = 24px */
.page-content:has(.mark-container.mark-delegate-scroll.mark-docmap-visible) {
  padding-right: 24px;
}

/* Preview state (on hover) = 60px */
.page-content:has(.mark-container.mark-delegate-scroll.mark-docmap-visible[data-docmap-state="preview"]) {
  padding-right: 60px;
}

/* Expanded state (on click) = 280px */
.page-content:has(.mark-container.mark-delegate-scroll.mark-docmap-visible[data-docmap-state="expanded"]) {
  padding-right: 280px;
}

/* Position DocMap fixed to viewport right edge */
.mark-container.mark-delegate-scroll .mark-docmap {
  position: fixed;
  right: 0;
  top: 60px; /* Height of .page-header (0.75rem padding * 2 + line-height) */
  bottom: 0;
  height: auto;
  z-index: 50;
}

/* Remove mark-panels margin when DocMap is fixed (DocMap is now outside content flow) */
.mark-container.mark-delegate-scroll.mark-docmap-visible .mark-panels {
  margin-right: 0;
}

/* Bottom breathing room for the Mark editor form */
div[data-controller="mark"] > form {
  padding-bottom: 2rem;
}

.trix-content {
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  font-size: 1.125rem;
  line-height: 1.75;
  padding: 0 1rem;
}

/* Trix editor - !important needed to override trix defaults */
trix-editor {
  width: 100% !important;
  max-width: 900px !important;
  margin: 0 auto !important;
  padding: 2rem !important;
  background: var(--ntabs-bg-primary) !important;
  border: none !important;
  outline: none !important;
}

.trix-content .attachment-gallery > .attachment,
.trix-content .attachment-gallery > * {
  flex: 1 0 33%;
  padding: 0 0.5em;
  max-width: 33%;
}

.trix-content .attachment-gallery.attachment-gallery--2 > .attachment,
.trix-content .attachment-gallery.attachment-gallery--2 > * {
  flex-basis: 50%;
  max-width: 50%;
}

.trix-content .attachment-gallery.attachment-gallery--4 > .attachment,
.trix-content .attachment-gallery.attachment-gallery--4 > * {
  flex-basis: 25%;
  max-width: 25%;
}

/* Trix Toolbar - !important needed to override trix defaults */
.trix-toolbar {
  position: sticky !important;
  top: 0 !important;
  z-index: 10 !important;
  background: var(--ntabs-bg-primary) !important;
  border-bottom: 1px solid var(--ntabs-border) !important;
  padding: 0.5rem 0 !important;
  margin-bottom: 1rem !important;
}

.trix-toolbar .trix-button-group {
  border-color: var(--ntabs-border) !important;
  margin-bottom: 0 !important;
}

.trix-toolbar .trix-button {
  border-color: var(--ntabs-border) !important;
}

.trix-toolbar .trix-button:hover {
  background: var(--ntabs-bg-secondary) !important;
}

.trix-toolbar .trix-button.trix-active {
  background: var(--ntabs-bg-secondary) !important;
}

/* Trix Editor Container */
.trix-editor-container {
  flex: 1;
  overflow-y: auto;
  padding: 0 2rem;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Chat Sidebar */
.chat-sidebar {
  width: 380px;
  border-left: 1px solid var(--ntabs-border);
  background: var(--ntabs-bg-primary);
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease-in-out, background-color 0.2s ease, border-color 0.2s ease;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
}

.chat-header {
  padding: 1rem;
  border-bottom: 1px solid var(--ntabs-border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: border-color 0.2s ease;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
}

.chat-message {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.chat-avatar {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 9999px;
  overflow: hidden;
}

.chat-message-content {
  flex: 1;
}

.chat-message-header {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.25rem;
}

.chat-author {
  font-weight: 500;
  color: var(--ntabs-text-primary);
}

.chat-time {
  font-size: 0.75rem;
  color: var(--ntabs-text-secondary);
}

.chat-text {
  color: var(--ntabs-text-primary);
  font-size: 0.875rem;
  line-height: 1.5;
}

.chat-actions {
  display: flex;
  gap: 1rem;
  margin-top: 0.5rem;
}

.chat-action-button {
  color: var(--ntabs-text-secondary);
  font-size: 0.75rem;
  text-decoration: none;
  transition: color 0.2s ease;
}

.chat-action-button:hover {
  color: var(--ntabs-text-primary);
}

.chat-input-container {
  padding: 1rem;
  border-top: 1px solid var(--ntabs-border);
  transition: border-color 0.2s ease;
}

.chat-input-wrapper {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  background: var(--ntabs-bg-secondary);
  border: 1px solid var(--ntabs-border);
  border-radius: 0.5rem;
  padding: 0.5rem;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.chat-input {
  flex: 1;
  border: none;
  background: transparent;
  min-height: 1.5rem;
  resize: none;
  padding: 0;
  font-size: 0.875rem;
  line-height: 1.5;
}

.chat-input:focus {
  outline: none;
}

.chat-toolbar {
  display: flex;
  gap: 0.5rem;
}

.chat-toolbar-button {
  padding: 0.25rem;
  color: var(--ntabs-text-secondary);
  border-radius: 0.25rem;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.chat-toolbar-button:hover {
  background: var(--ntabs-bg-secondary);
  color: var(--ntabs-text-primary);
}

/* Utilitários */
.icon {
  width: 1.25rem;
  height: 1.25rem;
}

/* Chat Visibility */
.chat-sidebar.hidden {
  transform: translateX(100%);
}

/* Ajustes de navegação */
.nav-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  color: var(--ntabs-text-secondary);
  border-radius: 0.375rem;
  transition: all 0.2s;
}

.nav-button:hover {
  background-color: var(--ntabs-bg-secondary);
  color: var(--ntabs-text-primary);
}

.nav-button + .nav-button {
  margin-left: 0.5rem;
}

/* Ajustes do header */
.page-header h1 {
  font-size: 1.25rem;
  font-weight: 500;
  color: var(--ntabs-text-primary);
  margin: 0;
}

.page-header .icon {
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 0.375rem;
  transition: all 0.2s;
  color: var(--ntabs-text-secondary);
}

.page-header .icon:hover {
  background-color: var(--ntabs-bg-secondary);
  color: var(--ntabs-text-primary);
}

/* Ícones de ação */
.action-icon {
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 0.375rem;
  color: var(--ntabs-text-secondary);
  transition: all 0.2s ease-in-out;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.action-icon:hover {
  background-color: var(--ntabs-bg-secondary);
  color: var(--ntabs-text-primary);
}

.action-icon.active {
  color: var(--ntabs-text-primary);
  background-color: var(--ntabs-bg-secondary);
}

.action-icon svg {
  width: 1.25rem;
  height: 1.25rem;
}

/* Indicadores de estado */
.chat-toggle.active,
.folder-toggle.active {
  color: var(--ntabs-text-primary);
  background-color: var(--ntabs-bg-secondary);
}

/* Chat toggle */
.chat-toggle {
  position: relative;
}

.chat-toggle::after {
  content: '';
  position: absolute;
  width: 6px;
  height: 6px;
  background-color: #10b981;
  border-radius: 50%;
  top: 6px;
  right: 6px;
  display: none;
}

.chat-toggle.has-unread::after {
  display: block;
}

/* Responsividade */
@media (max-width: 768px) {
  .main-content.chat-open {
    margin-right: 0;
  }

  .sidebar-container {
    width: 100%;
    max-width: 280px;
  }

  .chat-sidebar {
    width: 100%;
    max-width: 380px;
  }

  .content {
    padding: 1rem;
  }

  .trix-content,
  trix-editor {
    max-width: 100% !important;
    padding: 1rem !important;
  }

  .trix-editor-container {
    padding: 0 1rem;
  }
}

/* Sidebar Header */
.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  border-bottom: 1px solid var(--ntabs-border);
  transition: border-color 0.2s ease;
}

.sidebar-header h2 {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--ntabs-text-primary);
  margin: 0;
}

.sidebar-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--ntabs-text-secondary);
  padding: 0.25rem;
  border-radius: 0.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.sidebar-close:hover {
  background-color: var(--ntabs-bg-secondary);
  color: var(--ntabs-text-primary);
}

.sidebar-close svg {
  width: 1.25rem;
  height: 1.25rem;
}

/* Tags - visibility indicators */
.tag {
  background: var(--ntabs-bg-secondary);
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  color: var(--ntabs-text-secondary);
  border: 1px solid var(--ntabs-border);
  transition: background-color 0.2s ease, border-color 0.2s ease;
}

.tag--public {
  background-color: rgba(16, 185, 129, 0.1);
  border-color: rgba(16, 185, 129, 0.3);
}

.tag--private {
  background-color: rgba(59, 130, 246, 0.1);
  border-color: rgba(59, 130, 246, 0.3);
}

.lock-icon {
  color: #3b82f6;
}

.globe-icon {
  color: #10b981;
}


.page-header .left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.page-header .menu-toggle {
  background: none;
  border: none;
  padding: 4px;
  cursor: pointer;
  color: var(--ntabs-text-secondary);
}

.page-header .logo {
  font-weight: bold;
  color: var(--ntabs-text-primary);
  text-decoration: none;
}

.page-header .breadcrumb {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  overflow-x: auto;
  font-size: 0.95rem;
}

.breadcrumb-link {
  color: var(--ntabs-text-secondary);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.2s ease;
}

.breadcrumb-link:hover {
  color: var(--ntabs-text-primary);
}

.breadcrumb-separator {
  color: var(--ntabs-text-secondary);
  opacity: 0.6;
}

.page-header .right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.page-link-wrapper {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.page-children {
  padding-left: 16px;
}

/* Share Actions */
.share-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.share-button {
  position: relative;
}

.share-button svg {
  width: 18px;
  height: 18px;
}

.share-button.copied {
  color: #10b981;
}

.share-button .hidden {
  display: none;
}

/* Utility classes */
.hidden {
  display: none !important;
}

/* Claim banner (visitantes anônimos) */
.claim-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  padding: 0.5rem 1rem;
  background: rgba(247, 181, 0, 0.12);
  border-bottom: 1px solid rgba(247, 181, 0, 0.35);
  font-size: 0.875rem;
  color: #1a1a1a;
}

.claim-banner-cta {
  font-weight: 600;
  color: #1a1a1a;
  background: #f7b500;
  padding: 0.25rem 0.75rem;
  border-radius: 0.375rem;
  text-decoration: none;
  white-space: nowrap;
}

.claim-banner-cta:hover {
  background: #e5a800;
}

/* PHONE HEADER. The full trail is hidden and the compact one takes over — see
 * the note in shared/_breadcrumb.html.erb for why the path has to stay on
 * screen at all. */
.breadcrumb-compact { display: none; }

@media (max-width: 768px) {
  .page-header .breadcrumb { display: none !important; }

  .page-header .breadcrumb-compact {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: baseline;
    gap: 4px;
    font-size: 0.9rem;
    overflow: hidden;
    white-space: nowrap;
  }

  .page-header .breadcrumb-compact .breadcrumb-link {
    flex: none;
    max-width: 9rem;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .page-header .breadcrumb-compact .breadcrumb-current {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 600;
    color: var(--ntabs-text-primary);
  }
}

/* A finger is not a mouse pointer. Every control in this header was a 32px
 * box, measured — under the 44px that every touch guideline asks for, and they
 * sat 4px apart in the corner of the screen. Keyed on the POINTER, not on
 * width, so a small window on a laptop keeps the compact header and a large
 * tablet gets the comfortable one.
 *
 * Growing them is not free: at 44px the right-hand group came to 253px and the
 * header overflowed the screen by 20px, measured. The two sides have to be
 * told which one gives way — the path can be shortened, a button cannot. */
@media (pointer: coarse) {
  .page-header {
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
  }

  .page-header-left {
    flex: 1;
    min-width: 0;
    gap: 0.6rem;
  }

  .page-header-right {
    flex: none;
    gap: 0.35rem;
  }

  .page-header .nav-button {
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 0.5rem;
  }

  .page-header .share-actions { gap: 0.15rem; }
  .page-header .nav-button + .nav-button { margin-left: 0; }

  /* The visibility tag is a word plus an icon, and on a phone the word is the
   * widest thing in the header after the path. The icon carries the same
   * meaning and the label is still read out, so the text stays for a screen
   * reader and leaves the layout. */
  .page-header .visibility-tag-link {
    display: inline-flex;
    align-items: center;
    min-width: 2.75rem;
    min-height: 2.75rem;
    justify-content: center;
  }

  /* The logo is a text link 24px tall. It is the way back to the space and to
   * the tilde, and it was the smallest target in the header. */
  .page-header .logo {
    display: inline-flex;
    align-items: center;
    min-height: 2.75rem;
  }

  .page-header .visibility-tag-link .tag {
    padding-left: 0.55rem;
    padding-right: 0.55rem;
    min-height: 2.25rem;
  }

  /* Visually hidden, not removed: the word still reaches a screen reader. */
  .page-header .visibility-tag-link .tag-label {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }

  .claim-banner-cta { padding: 0.55rem 0.9rem; }
}

/* The visitor banner is 121px of a 844px screen, above the fold, on every page
 * a guest opens. The first sentence is the news; the rest is the argument, and
 * it can wait for a screen with room for it. */
@media (max-width: 700px) {
  .claim-banner { padding: 0.5rem 0.9rem; font-size: 0.82rem; gap: 0.5rem; }
  .claim-banner-rest { display: none; }
}

/* ============================================================ document flow
 * `.page-container.nt-flow` turns the app shell into a document: the PAGE
 * scrolls, the way an article does, instead of a viewport-tall frame with a
 * scrolling box inside it.
 *
 * Set by the server for a readonly page, and toggled by the mark controller
 * when the editor mode changes — preview is a document, code and divided are
 * not, because the toolbar and both panes have to stay put while you type.
 *
 * Why it matters beyond taste: a nested scroller loses the browser's own
 * scroll restoration on back, breaks find-in-page's ability to bring a match
 * into view, and stops a phone from collapsing its address bar. Measured
 * before: the document was exactly the viewport (900px of 900px) and
 * `.mark-preview` was the only thing that moved.
 *
 * Every step of the chain has to be undone, not just the last one: the box
 * exists because `.page-container` is `100vh` and every wrapper down to the
 * frame is `overflow: hidden`. */
.page-container.nt-flow {
  height: auto;
  min-height: 100vh;
  overflow: visible;
}

.page-container.nt-flow .main-content,
.page-container.nt-flow .page-content,
.page-container.nt-flow .page-content > turbo-frame,
.page-container.nt-flow .content,
.page-container.nt-flow .mark-editor-wrapper,
.page-container.nt-flow .mark-container,
.page-container.nt-flow .mark-panels,
.page-container.nt-flow .mark-preview-panel,
.page-container.nt-flow .mark-preview {
  overflow: visible;
  height: auto;
  max-height: none;
}

/* The header keeps its place while the page moves under it. It carries the
 * things a theme may not remove (ADR 017) — the visibility tag and sign-in —
 * so it has to stay reachable, and a document that scrolls its own header
 * away would put them out of reach for the length of a long page. */
.page-container.nt-flow .page-header {
  position: sticky;
  top: 0;
  z-index: 20;
}

/* The sidebar is a panel beside the document, not part of its flow: it stays
 * put while the page scrolls. Only signed-in people ever see it. */
.page-container.nt-flow .sidebar {
  position: sticky;
  top: 0;
  align-self: flex-start;
  max-height: 100vh;
}

/* A short page must not leave the ground of the page ending halfway down. */
.page-container.nt-flow .page-content,
.page-container.nt-flow .page-content > turbo-frame {
  min-height: 0;
  flex: 1 0 auto;
}

/* SIDE MARGINS ON A PHONE.
 *
 * Measured on a 390px screen: 16px from `.content` plus 40px from the mark
 * library's `.mark-preview` came to 56px a side — 29% of the screen spent on
 * empty margin, leaving 278px for the text. That is a desktop measure applied
 * to a phone, where the bezel already provides the breathing room a wide
 * window has to draw for itself.
 *
 * The library's value is right for a wide window and cannot be changed from
 * here, so it is overridden rather than edited. */
@media (max-width: 700px) {
  .content {
    padding: 1rem 0.5rem;
  }

  .content .mark-preview,
  .content .mark-container .mark-preview {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }
}

/* THE HIDDEN TEXTAREA STAYS IN THE LAYOUT.
 *
 * In preview mode mark hides the source panel with `width: 0; opacity: 0`,
 * which keeps the textarea in the layout tree: 32 KB of markdown is a
 * 662,014px-tall textarea nobody can see. Every keystroke in the preview sets
 * `editor.value`, the whole textarea is laid out again (1,575 of 4,071 layout
 * objects dirty), and the first geometry read pays for it — traced at
 * 1,207 ms of layout across 11 keys, against 38 ms with the panel actually
 * gone. This is why typing in a long page felt slow.
 *
 * `display: none` takes it out of layout. Nothing in preview mode reads the
 * textarea's geometry: scroll metrics use the preview, scroll sync only runs
 * in divided mode, and `.value` works on an element that is not displayed.
 * This belongs in mark's own stylesheet eventually; it lives here so the
 * vendored build stays untouched. */
.page-content .mark-mode-preview .mark-editor-panel {
  display: none;
}
