/* interface/docs.css
   Books (interface/docs/docs-view.js): the floating button bar, the two-column index, the
   document and notebook layouts, the editor, and the permissions box. A document's page itself is the Rules
   page's (rules.css); a notebook's notes are the Notes modal's (modal.css). Load after both. */

/* ---------------------------------------------------------------- */
/* In the sheet's place                                               */
/* ---------------------------------------------------------------- */
/* While the Books button says Sheets, the sheet and its "no character" terminal stay in the page (so they keep
   their layout and their live connection) but take no room and are not seen. */
.docs-mode #sheet-main,
.docs-mode #no-character {
  visibility: hidden;
  height: 0;
  margin: 0;
  padding: 0;
  overflow: hidden;
}

.docs-main {
  padding-bottom: 90px; /* clear of the floating bar */
}

.docs-main[hidden] {
  display: none;
}

/* The floating bar of buttons near the bottom of the screen: Back, then an entry's Edit / Permissions / Delete.
   The buttons are the top bar's (.edit-toggle-btn). Room is kept under the content so the bar never covers it. */
.docs-float {
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  z-index: 15;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  max-width: calc(100% - 32px);
  box-sizing: border-box;
  padding: 8px;
  background: rgba(17, 12, 23, 0.92);
  backdrop-filter: blur(6px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.45);
}

/* Narrow screens (where a page has its Contents button): no bar until the Options button, which sits beside
   Contents (docs-view.js places it), is pressed. Then the bar spans the screen, above the buttons, on one row. */
@media (max-width: 860px) {
  .docs-float {
    left: 8px;
    right: 8px;
    bottom: 68px;
    transform: none;
    max-width: none;
    flex-wrap: nowrap;
    gap: 6px;
    padding: 6px;
  }

  .docs-float:not(.is-open) {
    display: none;
  }

  .docs-float .edit-toggle-btn {
    flex: 1 1 auto;
    min-width: 0;
    padding: 9px 4px;
    font-size: 13px;
    letter-spacing: 0;
    white-space: nowrap;
  }
}

.docs-loading {
  margin: 40px auto;
  text-align: center;
  color: var(--text-dim);
}

.docs-error {
  color: var(--accent);
}

/* ---------------------------------------------------------------- */
/* The index                                                          */
/* ---------------------------------------------------------------- */
/* Two columns: the game's own documents (left, the wider) and the system's reference pages (right). They stack on a
   narrow screen, the game's first. */
.docs-index-wrap {
  max-width: 1280px;
  margin: 0 auto;
  padding: 16px 24px 0;
  box-sizing: border-box;
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  gap: 18px;
  align-items: start;
}

@media (max-width: 760px) {
  .docs-index-wrap {
    grid-template-columns: minmax(0, 1fr);
  }
}

.docs-index .panel-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.docs-index .panel-header h2 {
  flex: 1 1 auto;
  min-width: 0;
}

.docs-new {
  flex: 0 0 auto;
}

.docs-list {
  list-style: none;
  margin: 0;
  padding: 6px 0 10px;
}

.docs-item + .docs-item {
  border-top: 1px solid var(--border);
}

.docs-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
  box-sizing: border-box;
  padding: 11px 18px;
  font: inherit;
  text-align: left;
  color: var(--text);
  background: transparent;
  border: none;
  cursor: pointer;
}

.docs-row:hover,
.docs-row:focus-visible {
  background: rgba(56, 230, 207, 0.07);
  outline: none;
}

.docs-row-main {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.docs-row-name {
  font-family: var(--font-ui);
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.05em;
  overflow-wrap: anywhere;
}

.docs-row-note {
  font-size: 12px;
  color: var(--text-dim);
}

.docs-row-kind {
  flex: 0 0 auto;
  font-family: var(--font-data);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.docs-empty {
  padding: 16px 18px;
  color: var(--text-dim);
}

/* ---------------------------------------------------------------- */
/* An entry                                                           */
/* ---------------------------------------------------------------- */
.docs-notebook-wrap {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 24px;
  box-sizing: border-box;
}

.docs-notebook {
  margin-top: 12px;
}

/* One inset for everything inside a notebook: the header's own text padding (16px, core.css). The description, the
   search box, the compose box, the index and the notes all start and end that far from the panel's edges, so
   the edges line up all the way down. (Selectors are as specific as the modal's, which they override.) */
.docs-notebook {
  --docs-inset: 16px;
}

.docs-notebook .rules-content.docs-description {
  padding: 4px var(--docs-inset) 10px;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
}

.docs-notebook .rules-search,
.docs-notebook .notes-compose,
.docs-notebook .notes-index {
  padding-left: var(--docs-inset);
  padding-right: var(--docs-inset);
}

.docs-notebook .modal-list {
  padding-left: var(--docs-inset);
  padding-right: var(--docs-inset);
}

/* In a notebook the notes sit in the page, not in a scrolling box of their own. */
.docs-notes .modal-list {
  overflow: visible;
  flex: none;
}

.docs-notes .notes-index {
  max-height: none;
  overflow: visible;
}

.docs-danger:hover {
  color: var(--danger);
  border-color: var(--danger);
}

/* ---------------------------------------------------------------- */
/* The editors                                                        */
/* ---------------------------------------------------------------- */
.docs-editor {
  width: calc(100% - 48px);
  max-width: 1280px;
  margin: 12px auto 0;
}

.docs-notebook-wrap .docs-editor {
  width: auto;
  max-width: none;
}

.docs-editor-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px 16px 16px;
}

.docs-field-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-family: var(--font-data);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-faint);
}

.docs-field-label .notes-title-input {
  font-size: 15px;
  text-transform: none;
}

.docs-editor-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.docs-description-input {
  min-height: 120px;
}

/* The document editor: toolbar, then the source and the preview side by side. */
.md-editor {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.md-editor-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.md-editor-bar .md-toolbar {
  flex: 1 1 auto;
}

.md-editor-tabs {
  display: none; /* narrow screens only */
  gap: 4px;
}

.md-editor-tab {
  padding: 4px 12px;
  font-family: var(--font-ui);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-dim);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
}

.md-editor-tab.active {
  color: var(--accent);
  border-color: var(--accent);
}

.md-editor-panes {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 14px;
  align-items: stretch;
}

.md-editor-source {
  display: block;
  box-sizing: border-box;
  width: 100%;
  height: 62vh;
  min-height: 320px;
  padding: 10px 12px;
  font-family: var(--font-data, monospace);
  font-size: 13.5px;
  line-height: 1.55;
  color: var(--text);
  background: var(--panel-bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  resize: vertical;
  tab-size: 2;
}

.md-editor-source:focus {
  border-color: var(--cyan);
}

.md-editor-preview {
  box-sizing: border-box;
  height: 62vh;
  min-height: 320px;
  overflow-y: auto;
  padding: 4px 16px 12px;
  background: var(--panel-bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.md-editor-status {
  font-family: var(--font-data);
  font-size: 11px;
  letter-spacing: 0.08em;
  color: var(--text-faint);
}

@media (max-width: 860px) {
  .md-editor-tabs {
    display: flex;
  }

  .md-editor-panes {
    grid-template-columns: minmax(0, 1fr);
  }

  .md-editor[data-mode='write'] .md-editor-preview,
  .md-editor[data-mode='preview'] .md-editor-source {
    display: none;
  }

  .docs-editor {
    width: calc(100% - 32px);
  }

  .docs-index-wrap,
  .docs-notebook-wrap {
    padding-left: 16px;
    padding-right: 16px;
  }
}

/* ---------------------------------------------------------------- */
/* Permissions box                                                    */
/* ---------------------------------------------------------------- */
.modal-box.docs-perm-modal {
  max-width: 520px;
}

.docs-perm-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 8px 18px 4px;
}

.docs-perm-hint {
  margin: 6px 0 12px;
  font-size: 13px;
  color: var(--text-dim);
}

.docs-perm-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 0;
  border-top: 1px solid var(--border);
}

.docs-perm-all {
  border-top: none;
  padding-bottom: 10px;
  font-weight: 700;
}

.docs-perm-name {
  min-width: 0;
  overflow-wrap: anywhere;
}

.docs-perm-select {
  flex: 0 0 150px;
}

.docs-perm-actions {
  flex-shrink: 0;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 18px 16px;
  border-top: 1px solid var(--border);
}
