/* Workspace panels.
 *
 * The design system owns colours, typography and panel chrome. These rules place the
 * wiki's own pieces inside a panel and keep the document readable while scrolling. */

.wiki-explorer {
  display: flex;
  flex-direction: column;
  flex: 1 1 0;
  min-height: 0;
  padding: var(--sui-space-1) 0;
  overflow-y: auto;
}

.wiki-explorer__filters {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 0 var(--sui-space-2) var(--sui-space-1);
  border-bottom: 1px solid var(--sui-border);
  margin-bottom: var(--sui-space-1);
}

.wiki-filter {
  padding: 1px 7px;
  border: 1px solid var(--sui-border);
  border-radius: 999px;
  background: transparent;
  color: var(--sui-text-faint);
  font-family: var(--sui-font-mono);
  font-size: var(--sui-text-xs);
  cursor: pointer;
}

.wiki-filter:hover {
  color: var(--sui-text);
  border-color: var(--sui-text-faint);
}

.wiki-filter--on {
  border-color: var(--sui-accent);
  background: var(--sui-accent-soft);
  color: var(--sui-accent);
}

.wiki-explorer__views {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: 0 var(--sui-space-2) var(--sui-space-1);
  margin-bottom: var(--sui-space-1);
}

.wiki-explorer__views select,
.wiki-explorer__views button {
  font-family: var(--sui-font-mono);
  font-size: var(--sui-text-xs);
  padding: 2px 6px;
  border: 1px solid var(--sui-border);
  border-radius: 4px;
  background: transparent;
  color: var(--sui-text-faint);
}

.wiki-explorer__views button {
  cursor: pointer;
}

.wiki-explorer__views button:disabled {
  opacity: 0.5;
  cursor: default;
}

.wiki-explorer__empty {
  margin: 0;
  padding: var(--sui-space-2);
  color: var(--sui-text-faint);
  font-size: var(--sui-text-sm);
}

.wiki-document-panel {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
}

.wiki-source {
  position: sticky;
  top: 0;
  margin: 0;
  background: var(--sui-surface);
  padding: var(--sui-space-1) var(--sui-space-6);
  border-bottom: 1px solid var(--sui-border);
  color: var(--sui-text-faint);
  font-family: var(--sui-font-mono);
  font-size: var(--sui-text-xs);
}

.wiki-document-panel .sui-markdown {
  padding-top: var(--sui-space-4);
}

.wiki-outline,
.wiki-backlinks {
  flex: 1 1 0;
  min-height: 0;
  list-style: none;
  margin: 0;
  padding: 0 var(--sui-space-2) var(--sui-space-2);
  overflow-y: auto;
}

.wiki-outline li {
  padding: 2px var(--sui-space-2);
}

.wiki-backlinks li {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--sui-space-1) var(--sui-space-2);
}

.wiki-depth-3 {
  padding-left: var(--sui-space-4);
}

.wiki-depth-4,
.wiki-depth-5,
.wiki-depth-6 {
  padding-left: var(--sui-space-6);
}

.wiki-link-button {
  padding: 0;
  border: none;
  background: none;
  color: var(--sui-accent);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.wiki-link-button:hover {
  text-decoration: underline;
}

.wiki-path {
  color: var(--sui-text-faint);
  font-size: var(--sui-text-xs);
  font-family: var(--sui-font-mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sui-statusbar__user {
  color: var(--sui-text-muted);
  font-size: var(--sui-text-xs);
}

/* Pages outside the workspace: the tag listing and errors. */

.wiki-content {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: var(--sui-space-6);
}

.wiki-index {
  max-width: 820px;
  margin: 0 auto;
  background: var(--sui-surface);
  border: 1px solid var(--sui-border);
  border-radius: var(--sui-radius-lg);
  padding: var(--sui-space-6) var(--sui-space-8);
}

.wiki-index h1 {
  margin-top: 0;
  font-size: var(--sui-text-2xl);
}

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

.wiki-list li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--sui-space-4);
  padding: var(--sui-space-2) 0;
  border-bottom: 1px solid var(--sui-border);
}

.wiki-list li:last-child {
  border-bottom: none;
}

/* The gallery. */

.design-page {
  max-width: 1180px;
  margin: 0 auto;
  padding: var(--sui-space-8) var(--sui-space-6) calc(var(--sui-space-8) * 2);
}

.design-header {
  margin-bottom: var(--sui-space-8);
}

.design-header h1 {
  margin: 0 0 var(--sui-space-2);
  font-size: var(--sui-text-2xl);
}

.design-header p {
  color: var(--sui-text-muted);
  margin: var(--sui-space-1) 0;
}

.design-theme {
  margin-bottom: var(--sui-space-8);
  border: 1px solid var(--sui-border);
  border-radius: var(--sui-radius-lg);
  overflow: hidden;
  background: var(--sui-bg);
}

.design-theme > h3 {
  margin: 0;
  padding: var(--sui-space-2) var(--sui-space-4);
  font-size: var(--sui-text-sm);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--sui-text-muted);
  border-bottom: 1px solid var(--sui-border);
  background: var(--sui-bg-subtle);
}

.design-theme__body {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  min-height: 320px;
}

.design-theme__body .sui-panel {
  border-right: 1px solid var(--sui-border);
}

.design-theme__doc {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.design-theme__doc .sui-markdown {
  flex: 1 1 auto;
  margin: 0;
  max-width: none;
  padding: var(--sui-space-4) var(--sui-space-5);
}

.design-theme__bar {
  display: flex;
  align-items: center;
  gap: var(--sui-space-2);
  padding: var(--sui-space-3) var(--sui-space-4);
  border-top: 1px solid var(--sui-border);
  background: var(--sui-bg-subtle);
  flex-wrap: wrap;
}

.design-section {
  margin-bottom: var(--sui-space-8);
}

.design-section h2 {
  font-size: var(--sui-text-lg);
  margin: 0 0 var(--sui-space-3);
  padding-bottom: var(--sui-space-2);
  border-bottom: 1px solid var(--sui-border);
}

.design-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sui-space-3);
}

.design-inputs {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--sui-space-4);
  width: 100%;
  max-width: 820px;
}

.design-swatches {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--sui-space-3);
  width: 100%;
}

.design-swatch {
  display: flex;
  align-items: center;
  gap: var(--sui-space-2);
  font-size: var(--sui-text-xs);
  color: var(--sui-text-muted);
}

.design-swatch__chip {
  width: 28px;
  height: 28px;
  border-radius: var(--sui-radius-sm);
  border: 1px solid var(--sui-border-strong);
}

/* Sign-in and invitation pages. */

.wiki-auth {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: var(--sui-space-6);
  background: var(--sui-bg-subtle);
}

.wiki-auth__card {
  display: flex;
  flex-direction: column;
  gap: var(--sui-space-4);
  width: min(420px, 100%);
  background: var(--sui-surface);
  border: 1px solid var(--sui-border);
  border-radius: var(--sui-radius-lg);
  padding: var(--sui-space-8) var(--sui-space-6);
}

.wiki-auth__brand {
  color: var(--sui-text-muted);
  font-size: var(--sui-text-sm);
  text-decoration: none;
}

.wiki-auth__brand:hover {
  color: var(--sui-text);
}

.wiki-auth__title {
  margin: 0;
  font-size: var(--sui-text-2xl);
}

.wiki-auth__form {
  display: flex;
  flex-direction: column;
  gap: var(--sui-space-4);
}

.wiki-auth__error {
  margin: 0;
  padding: var(--sui-space-2) var(--sui-space-3);
  border: 1px solid var(--sui-danger);
  border-radius: var(--sui-radius-md);
  color: var(--sui-danger);
  font-size: var(--sui-text-sm);
}

.wiki-auth__notice {
  margin: 0;
  color: var(--sui-text-muted);
  font-size: var(--sui-text-sm);
}

.wiki-auth__telegram {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sui-space-3);
}

.wiki-auth__divider {
  width: 100%;
  margin: 0;
  padding-top: var(--sui-space-3);
  border-top: 1px solid var(--sui-border);
  color: var(--sui-text-faint);
  font-size: var(--sui-text-xs);
  text-align: center;
}

.wiki-auth__links {
  margin: 0;
  color: var(--sui-text-muted);
  font-size: var(--sui-text-sm);
}

.wiki-signout {
  display: inline-flex;
  margin: 0;
}

/* Mobile reader: one document pane, drawers for files/outline/links.
 *
 * The desktop workspace tree is not rendered below 900px; the app-shell passes a
 * single-pane document layout instead. These rules give that pane the full height and
 * make the three secondary panels full-screen overlays. */

.wiki-mobile-nav,
.wiki-mobile-panel {
  display: none;
}

@media (max-width: 900px) {
  .sui-shell {
    grid-template-rows: var(--sui-topbar-height) minmax(0, 1fr) 52px;
  }

  .sui-topbar {
    gap: var(--sui-space-1);
    padding: 0 var(--sui-space-2);
  }

  .sui-topbar__title {
    max-width: 55%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .sui-statusbar,
  .sui-statusbar__user {
    display: none;
  }

  .sui-workspace,
  .sui-view,
  .sui-panel {
    min-height: 0;
  }

  .sui-workspace {
    grid-row: 2;
  }

  .sui-panel {
    height: 100%;
  }

  .sui-tabs {
    display: none;
  }

  .wiki-source {
    padding: var(--sui-space-1) var(--sui-space-3);
  }

  .wiki-document-panel {
    padding-bottom: var(--sui-space-6);
  }

  .wiki-document-panel .sui-markdown {
    padding-left: var(--sui-space-3);
    padding-right: var(--sui-space-3);
  }

  .wiki-mobile-nav {
    display: grid;
    grid-row: 3;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    align-items: stretch;
    border-top: 1px solid var(--sui-border);
    background: var(--sui-bg-subtle);
  }

  .wiki-mobile-nav button {
    min-height: 52px;
    border: 0;
    border-right: 1px solid var(--sui-border);
    background: transparent;
    color: var(--sui-text-muted);
    font: inherit;
    font-size: var(--sui-text-xs);
    cursor: pointer;
  }

  .wiki-mobile-nav button:last-child {
    border-right: 0;
  }

  .wiki-mobile-nav button[aria-pressed='true'] {
    color: var(--sui-accent);
    background: var(--sui-accent-soft);
  }

  .wiki-mobile-nav button:disabled {
    opacity: 0.4;
    cursor: default;
  }

  .wiki-mobile-panel {
    position: fixed;
    inset: var(--sui-topbar-height) 0 52px;
    z-index: 30;
    display: flex;
    flex-direction: column;
    background: var(--sui-bg);
    border-top: 1px solid var(--sui-border);
  }

  .wiki-mobile-panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 44px;
    padding: 0 var(--sui-space-2) 0 var(--sui-space-3);
    border-bottom: 1px solid var(--sui-border);
    background: var(--sui-bg-subtle);
    font-weight: 600;
  }

  .wiki-mobile-panel__body {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }

  .wiki-mobile-panel__body .wiki-explorer {
    padding: var(--sui-space-2);
  }

  .wiki-mobile-panel__body .wiki-explorer__filters,
  .wiki-mobile-panel__body .wiki-explorer__views {
    padding: 0 0 var(--sui-space-2);
  }

  .wiki-mobile-panel__body .wiki-outline,
  .wiki-mobile-panel__body .wiki-backlinks {
    padding: var(--sui-space-2);
  }

  .wiki-mobile-panel__body .wiki-outline li {
    padding: 8px var(--sui-space-2);
  }

  .wiki-mobile-panel__body .wiki-backlinks li {
    padding: var(--sui-space-2);
  }
}

/* Editor: the same panel, two views. */
.wiki-document-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.wiki-document-modes {
  display: flex;
  gap: 0.25rem;
}

.wiki-editor {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  min-height: 0;
}

.wiki-editor__text {
  width: 100%;
  min-height: 60vh;
  padding: 0.75rem;
  border: 1px solid var(--sui-border);
  border-radius: 6px;
  background: var(--sui-surface);
  color: inherit;
  font-family: var(--sui-font-mono, ui-monospace, monospace);
  font-size: 0.9rem;
  line-height: 1.5;
  resize: vertical;
}

.wiki-editor__actions {
  display: flex;
  gap: 0.5rem;
}

/* The editor is the page: same font, same measure, no box. */
.wiki-codemirror {
  min-height: 0;
  flex: 1 1 auto;
}

.wiki-codemirror .cm-editor {
  height: 100%;
  background: transparent;
  color: inherit;
  font-family: inherit;
  font-size: inherit;
  line-height: 1.6;
}

.wiki-codemirror .cm-editor.cm-focused {
  outline: none;
}

.wiki-codemirror .cm-scroller {
  font-family: inherit;
  line-height: 1.6;
}

.wiki-codemirror .cm-content {
  padding: 0;
  caret-color: var(--sui-accent);
}

.wiki-codemirror .cm-line {
  padding: 0;
}

/* Live preview: the source stays in the document, the reading view is built
   from it. Only the block under the cursor keeps its markers. */
.cm-lp-strong {
  font-weight: 700;
}
.cm-lp-em {
  font-style: italic;
}
.cm-lp-strike {
  text-decoration: line-through;
  opacity: 0.65;
}
.cm-lp-link {
  color: var(--sui-accent);
  text-decoration: underline;
  text-decoration-color: var(--sui-accent-soft);
  text-underline-offset: 2px;
}
.cm-lp-image {
  color: var(--sui-text-faint);
  font-style: italic;
}
.cm-lp-math {
  font-family: var(--sui-font-mono);
  color: var(--sui-accent);
}
.cm-lp-ordinal {
  color: var(--sui-text-faint);
}

.cm-lp-code-inline {
  font-family: var(--sui-font-mono);
  font-size: 0.92em;
  background: var(--sui-accent-soft);
  border-radius: 4px;
  padding: 0.05em 0.28em;
}

.cm-lp-bullet {
  display: inline-block;
  width: 1.05em;
  color: var(--sui-text-faint);
}

.cm-lp-checkbox {
  margin: 0 0.4em 0 0;
  vertical-align: middle;
  accent-color: var(--sui-accent);
}

.wiki-codemirror .cm-line.cm-lp-heading {
  font-weight: 700;
  line-height: 1.3;
  padding: 0.35em 0 0.1em;
}
.cm-lp-h1 {
  font-size: 1.9em;
}
.cm-lp-h2 {
  font-size: 1.55em;
}
.cm-lp-h3 {
  font-size: 1.3em;
}
.cm-lp-h4 {
  font-size: 1.12em;
}
.cm-lp-h5 {
  font-size: 1em;
}
.cm-lp-h6 {
  font-size: 0.92em;
  color: var(--sui-text-faint);
}

.wiki-codemirror .cm-line.cm-lp-quote {
  border-left: 3px solid var(--sui-border);
  padding-left: 0.9em;
  color: var(--sui-text-faint);
}

/* A code block is replaced whole, so its fences never reach the page. */
.cm-lp-code-widget {
  margin: 0.4em 0;
  padding: 0.65em 0.9em;
  background: var(--sui-bg-sunken);
  border-radius: var(--sui-radius-md);
  overflow-x: auto;
  font-family: var(--sui-font-mono);
  font-size: 0.9em;
  line-height: 1.5;
}

.cm-lp-code-widget code {
  background: transparent;
  padding: 0;
  font-family: inherit;
  font-size: inherit;
}

/* Syntax colours come from the theme, so dark and light stay legible. */
.hljs-comment,
.hljs-quote {
  color: var(--sui-text-faint);
  font-style: italic;
}

.hljs-keyword,
.hljs-selector-tag,
.hljs-built_in,
.hljs-name {
  color: var(--sui-accent);
}

.hljs-string,
.hljs-attr,
.hljs-attribute,
.hljs-symbol {
  color: var(--sui-success);
}

.hljs-number,
.hljs-literal,
.hljs-variable,
.hljs-template-variable {
  color: var(--sui-warning);
}

.hljs-title,
.hljs-section {
  color: var(--sui-accent-hover);
}

.hljs-type,
.hljs-meta {
  color: var(--sui-text-muted);
}

.cm-lp-math-block {
  padding: 0.4em 0;
  overflow-x: auto;
  text-align: center;
}

.cm-lp-math-inline {
  display: inline-block;
  vertical-align: baseline;
}

.wiki-codemirror .cm-line.cm-lp-table {
  font-family: var(--sui-font-mono);
  font-size: 0.9em;
}

.wiki-codemirror .cm-line.cm-lp-table-rule {
  opacity: 0.3;
}

.wiki-codemirror .cm-line.cm-lp-hr {
  border-bottom: 1px solid var(--sui-border);
}

/* A rendered table replaces its block, so it carries the page's own table look
   rather than the editor's. */
.cm-lp-table-widget {
  padding: 0.5em 0;
  overflow-x: auto;
}

.cm-lp-table-widget table {
  border-collapse: collapse;
  font-size: 0.95em;
}

.cm-lp-table-widget th,
.cm-lp-table-widget td {
  border: 1px solid var(--sui-border);
  padding: 0.3em 0.75em;
  text-align: left;
}

.cm-lp-table-widget th {
  background: var(--sui-accent-soft);
  font-weight: 600;
}

/* A draft is a state of the note, not a warning: it says the tab holds text that
   the vault does not yet have. */
.wiki-draft-badge {
  display: inline-flex;
  align-items: center;
  padding: 0 0.5em;
  border: 1px solid var(--sui-warning);
  border-radius: var(--sui-radius-pill);
  color: var(--sui-warning);
  background: var(--sui-warning-soft);
  font-size: var(--sui-text-xs);
  line-height: 1.6;
}

.wiki-changes {
  max-height: 38vh;
  overflow: auto;
  border-bottom: 1px solid var(--sui-border);
  background: var(--sui-bg-subtle);
  padding: var(--sui-space-2) 0;
  font-family: var(--sui-font-mono);
  font-size: var(--sui-text-xs);
}

.wiki-changes__line {
  display: flex;
  gap: 0.5em;
  padding: 0 var(--sui-space-6);
  white-space: pre-wrap;
  word-break: break-word;
}

.wiki-changes__line--add {
  background: var(--sui-success-soft);
  color: var(--sui-success);
}

.wiki-changes__line--remove {
  background: var(--sui-danger-soft);
  color: var(--sui-danger);
}

.wiki-changes__sign {
  flex: none;
  width: 1ch;
  text-align: center;
  opacity: 0.7;
}

.wiki-changes__text {
  flex: 1 1 auto;
}

/* Unsaved text has to be findable from the tree, not only by reopening the note. */
.wiki-drafts {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 30vh;
  overflow-y: auto;
  padding: var(--sui-space-1) var(--sui-space-2);
  border-bottom: 1px solid var(--sui-border);
}

.wiki-drafts__title {
  margin: 0 0 2px;
  color: var(--sui-warning);
  font-size: var(--sui-text-xs);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.wiki-drafts__item {
  display: flex;
  justify-content: space-between;
  gap: 0.5em;
  padding: 2px var(--sui-space-1);
  border: 0;
  border-radius: var(--sui-radius-sm);
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.wiki-drafts__item:hover {
  background: var(--sui-surface-hover);
}

.wiki-drafts__path {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wiki-drafts__time {
  flex: none;
  color: var(--sui-text-faint);
  font-size: var(--sui-text-xs);
}

/* The save target is part of the note's identity while editing: main, or a
   changelist that will be merged. */
.wiki-target {
  max-width: 14em;
  padding: 2px var(--sui-space-1);
  border: 1px solid var(--sui-border);
  border-radius: var(--sui-radius-sm);
  background: var(--sui-surface);
  color: inherit;
  font: inherit;
  font-size: var(--sui-text-xs);
}

.wiki-notice {
  margin: 0;
  padding: var(--sui-space-1) var(--sui-space-6);
  border-bottom: 1px solid var(--sui-border);
  background: var(--sui-success-soft);
  color: var(--sui-success);
  font-size: var(--sui-text-xs);
}

.wiki-draft-stale {
  margin: 0;
  padding: var(--sui-space-1) var(--sui-space-6);
  border-bottom: 1px solid var(--sui-border);
  background: var(--sui-warning-soft);
  color: var(--sui-warning);
  font-size: var(--sui-text-xs);
}

/* A changelist is reviewable before it becomes history: what it touches, and
   the one action that turns it into the note's past. */
.wiki-changelists {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 40vh;
  overflow-y: auto;
  padding: var(--sui-space-1) var(--sui-space-2);
  border-bottom: 1px solid var(--sui-border);
}

.wiki-changelists__title {
  margin: 0 0 2px;
  color: var(--sui-accent);
  font-size: var(--sui-text-xs);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.wiki-changelists__name {
  padding: 2px var(--sui-space-1);
  border: 0;
  border-radius: var(--sui-radius-sm);
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.wiki-changelists__name:hover {
  background: var(--sui-surface-hover);
}

.wiki-changelists__files {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding-left: var(--sui-space-3);
}

.wiki-changelists__file {
  display: flex;
  justify-content: space-between;
  gap: 0.5em;
  padding: 2px var(--sui-space-1);
  border: 0;
  border-radius: var(--sui-radius-sm);
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: var(--sui-text-xs);
  text-align: left;
  cursor: pointer;
}

.wiki-changelists__file:hover {
  background: var(--sui-surface-hover);
}

.wiki-changelists__path {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wiki-changelists__stat {
  flex: none;
  color: var(--sui-text-faint);
}

.wiki-changelists__merge {
  align-self: flex-start;
  margin-top: 4px;
}
