/* Core UI: editor, history, diff, search. Layout CSS is in the content repo. */
.lw-button { display: inline-block; padding: .35em .9em; border: 1px solid #b9b2a4; border-radius: 4px; background: #fbfaf6; color: #222 !important; font: inherit; cursor: pointer; text-decoration: none !important; }
.lw-button:hover { background: #fff; border-color: #8a8173; }
.lw-primary { background: #660000; border-color: #660000; color: #fff !important; }
.lw-primary:hover { background: #800; border-color: #800; }
.lw-link { background: none; border: 0; padding: 0; color: inherit; font: inherit; cursor: pointer; text-decoration: underline; }
.lw-inline { display: inline; margin: 0; }
.lw-quiet { color: #777; font-size: .92em; }
.lw-error { color: #a00; font-weight: bold; }
.lw-note { padding: .6em 1em; margin: 0 0 1em; border-left: 4px solid #c90; background: #fff8e1; }

.lw-form label { display: block; margin: .6em 0; }
.lw-form input { display: block; width: 100%; max-width: 22em; padding: .4em; font: inherit; border: 1px solid #b9b2a4; border-radius: 4px; box-sizing: border-box; }
.lw-searchform input { display: inline-block; max-width: 30em; }
.lw-login { max-width: 22em; }

/* Editor */
.lw-editor-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .5em; }
.lw-editor-head h1 { margin: 0 0 .4em; }
.lw-editor-tabs { display: flex; gap: .25em; align-items: center; }
.lw-tab { padding: .3em .8em; border: 1px solid #ccc5b6; border-radius: 4px 4px 0 0; background: #eeeadf; font: inherit; cursor: pointer; }
.lw-tab.lw-active { background: #fff; border-bottom-color: #fff; font-weight: bold; }
.lw-help { margin-left: .8em; font-size: .9em; }
.lw-editor-panes { display: grid; gap: 1em; }
.lw-mode-write { grid-template-columns: 1fr; } .lw-mode-write .lw-preview { display: none; }
.lw-mode-preview { grid-template-columns: 1fr; } .lw-mode-preview .lw-text { display: none; }
.lw-mode-split { grid-template-columns: 1fr 1fr; }
.lw-text { width: 100%; min-height: 65vh; box-sizing: border-box; padding: .7em; font: 14px/1.5 ui-monospace, Consolas, monospace; border: 1px solid #b9b2a4; border-radius: 0 4px 4px 4px; resize: vertical; tab-size: 4; }
.lw-preview { --page-pad: 1em; min-height: 65vh; max-height: 80vh; overflow: auto; padding: 0 var(--page-pad); border: 1px dashed #b9b2a4; border-radius: 4px; background: rgba(255,255,255,.5); }
.lw-editor-foot { display: flex; flex-wrap: wrap; gap: .5em; align-items: center; margin-top: .7em; }
.lw-summary { flex: 1 1 20em; padding: .4em; font: inherit; border: 1px solid #b9b2a4; border-radius: 4px; }
.lw-hint { color: #777; font-size: .85em; }
.lw-conflict { padding: .5em 1em; margin-bottom: 1em; border: 2px solid #c60; background: #fff4e5; }
.lw-conflict textarea { width: 100%; box-sizing: border-box; font: 13px/1.4 ui-monospace, Consolas, monospace; }
@media (max-width: 800px) { .lw-mode-split { grid-template-columns: 1fr; } }

/* History and diff */
table.lw-history { border-collapse: collapse; width: 100%; }
table.lw-history th, table.lw-history td { text-align: left; padding: .3em .6em; border-bottom: 1px solid #ddd6c8; vertical-align: top; }
.lw-actions { white-space: nowrap; }
table.lw-history td:first-child { white-space: nowrap; }
pre.lw-diff { white-space: pre-wrap; word-break: break-word; font: 13px/1.45 ui-monospace, Consolas, monospace; background: #fff; border: 1px solid #ddd6c8; padding: .5em; }
pre.lw-diff span { display: block; padding: 0 .4em; min-height: 1.45em; }
.lw-add { background: #e6ffec; } .lw-add::before { content: "+ "; color: #1a7f37; }
.lw-del { background: #ffebe9; } .lw-del::before { content: "− "; color: #cf222e; }
.lw-ctx::before { content: "  "; }
.lw-hunk { color: #888; background: #f3f1ea; margin: .4em 0; }

/* Lists of things */
.lw-recent li, .lw-hits li { margin: .35em 0; }
.lw-snippet { color: #555; font-size: .92em; }
.lw-index ul { list-style: none; padding-left: 1.2em; }
.lw-index summary { cursor: pointer; }


/* Widgets */
.widget { margin: 1em 0; }

/* Fallback layout when a namespace has none */
.lw-default { max-width: 60em; margin: 0 auto; padding: 0 1em; font: 15px/1.5 Georgia, serif; }
.lw-bar { display: flex; flex-wrap: wrap; gap: 1em; align-items: center; padding: .6em 0; border-bottom: 1px solid #ccc; }
.lw-site { font-weight: bold; font-size: 1.3em; text-decoration: none; }
.lw-tools { display: flex; gap: .8em; flex-wrap: wrap; margin-left: auto; }
.lw-pageinfo { margin: 2em 0; color: #777; font-size: .85em; border-top: 1px solid #ddd; padding-top: .5em; }

/* Image picker */
.lw-media { border: 1px solid #ccc5b6; border-radius: 4px; background: rgba(255,255,255,.7); padding: .5em; margin-bottom: .6em; }
.lw-media-bar { display: flex; flex-wrap: wrap; gap: .6em; align-items: center; margin-bottom: .5em; }
.lw-media-ns { font: inherit; padding: .2em .4em; }
.lw-media-list { display: flex; flex-wrap: wrap; gap: .4em; max-height: 18em; overflow: auto; }
.lw-media-folder { font: inherit; padding: .3em .6em; border: 1px solid #ccc5b6; background: #f6f4ee; border-radius: 4px; cursor: pointer; }
.lw-media-item { width: 120px; padding: 4px; border: 1px solid #ddd6c8; background: #fff; border-radius: 4px; cursor: pointer; display: flex; flex-direction: column; align-items: center; font-size: 11px; }
.lw-media-item:hover { border-color: #660000; }
.lw-media-item img { width: 110px; height: 80px; object-fit: cover; }
.lw-media-item span { width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lw-media-icon { font-size: 40px; line-height: 80px; }

/* Media in the Files view */
.lw-upload { display: flex; flex-wrap: wrap; gap: .6em; align-items: center; margin-bottom: 1em; }
.lw-upload input[type=file] { display: inline-block; width: auto; border: 0; }
.lw-mediagrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: .7em; }
.lw-mediacell { border: 1px solid #ddd6c8; border-radius: 4px; background: rgba(255,255,255,.6); padding: 5px; display: flex; flex-direction: column; font-size: .85em; }
.lw-thumb { display: flex; align-items: center; justify-content: center; height: 110px; background: #eeeadf; border-radius: 3px; overflow: hidden; text-decoration: none !important; }
.lw-thumb img { max-width: 100%; max-height: 110px; object-fit: contain; }
.lw-thumb-folder { font-size: 48px; }
.lw-mediainfo { display: flex; flex-direction: column; gap: .15em; margin-top: .3em; min-width: 0; }
.lw-medianame { font-weight: bold; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lw-mediaactions { font-size: .95em; }
.lw-check { display: flex !important; gap: .4em; align-items: center; }
.lw-check input { width: auto !important; display: inline !important; }

/* Code editor (CodeMirror) */
.lw-editor .CodeMirror { height: 65vh; border: 1px solid #b9b2a4; border-radius: 0 4px 4px 4px; font: 14px/1.5 ui-monospace, Consolas, monospace; background: #fff; }
.lw-editor .CodeMirror-gutters { background: #f6f4ee; border-right-color: #e2ddd0; }
.lw-mode-preview .CodeMirror { display: none; }
.lw-editor-panes > .CodeMirror { min-width: 0; }
.lw-editor .cm-s-default .cm-header { color: #660000; }
.lw-editor .cm-header-1 { font-size: 1.25em; }
.lw-editor .cm-header-2 { font-size: 1.12em; }
.lw-editor .cm-s-default .cm-link, .lw-editor .cm-s-default .cm-url { color: #0b5394; }
.lw-editor .cm-s-default .cm-quote { color: #6a737d; font-style: italic; }
.lw-editor .CodeMirror-activeline-background { background: #fbf8ef; }
.lw-editor .CodeMirror-matchingbracket { background: #e6f0d8; color: inherit !important; }

/* Files maintained by the server */
.lw-warning { padding: .6em 1em; margin: 0 0 .8em; border-left: 4px solid #c60; background: #fff4e5; }
.lw-badge { display: inline-block; font-size: .8em; padding: 0 .5em; border-radius: 3px; background: #f3e3c3; color: #6b4a10; }

/* ---------- Page images (docs/guide.md, "Images and other files") ----------
   The renderer marks an image alone in its paragraph (p.pic), an image
   with a caption (figure), images side by side (p.gallery), and the
   presets from the address (#small, #medium, #full, #left, #right).
   Zero specificity (:where), so layouts can restyle any of it. */
:where(.page) :where(p.pic) { text-align: center; }
:where(.page) :where(p.pic, figure) img, :where(.page) img:where(.center):where(:not([width])) { width: auto; max-height: 32rem; }
:where(.page) img:where(.left, .right):where(:not(.small, .medium, [width])) { max-width: 40%; }
:where(.page) img:where(.small) { width: 200px; }
:where(.page) img:where(.medium) { width: 400px; }
:where(.page) img:where(.full) { width: 100%; max-height: none; }
:where(.page) img:where(.right) { float: right; margin: .3rem 0 1rem 1.25rem; }
:where(.page) img:where(.left) { float: left; margin: .3rem 1.25rem 1rem 0; }
:where(.page) figure { margin: 0 0 1.1rem; text-align: center; }
:where(.page) figcaption { font-size: .9em; font-style: italic; margin-top: .3rem; opacity: .85; }
:where(.page) figure:where(:has(img.right)) { float: right; max-width: 40%; margin: .3rem 0 1rem 1.25rem; }
:where(.page) figure:where(:has(img.left)) { float: left; max-width: 40%; margin: .3rem 1.25rem 1rem 0; }
:where(.page) figure:where(:has(img.left, img.right)) img { float: none; margin: 0; max-width: 100%; }
:where(.page) :where(p.gallery) { display: grid; grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr)); gap: .5rem; }
:where(.page) :where(p.gallery) img { display: block; width: 100%; height: 12rem; max-height: none; object-fit: cover; }
@media (max-width: 600px) {
  :where(.page) img:where(.left, .right), :where(.page) figure:where(:has(img.left, img.right)) {
    float: none; display: block; max-width: 100%; margin: 0 auto 1rem;
  }
  :where(.page) :where(p.gallery) { grid-template-columns: repeat(auto-fill, minmax(7rem, 1fr)); }
  :where(.page) :where(p.gallery) img { height: 8rem; }
}

/* ---------- Page finder ("/" or Ctrl+K; "[[" in the editor) ---------- */
.lw-finder { position: fixed; inset: 0; z-index: 100; background: rgba(0, 0, 0, .3); }
.lw-finder-box {
  width: min(36rem, 92vw); margin: 12vh auto 0; padding: .75rem;
  background: var(--paper, #fff); color: var(--text, #222);
  border-radius: 8px; box-shadow: 0 8px 30px rgba(0, 0, 0, .3);
  font: 15px/1.4 var(--body-font, system-ui, sans-serif);
}
.lw-finder-box input {
  width: 100%; box-sizing: border-box; padding: .5rem .6rem; font: inherit; font-size: 1.05rem;
  border: 1px solid var(--rule, #ccc); border-radius: 5px; background: #fff; color: #222;
}
.lw-finder-box ul { list-style: none; margin: .5rem 0 0; padding: 0; max-height: 55vh; overflow-y: auto; }
.lw-finder-box li { padding: .35rem .5rem; border-radius: 4px; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lw-finder-box li .lw-quiet { font-size: .85em; margin-left: .4rem; }
.lw-finder-box li.lw-sel { background: var(--link, #335); color: #fff; }
.lw-finder-box li.lw-sel .lw-quiet { color: rgba(255, 255, 255, .8); }
.lw-finder-box li.lw-finder-extra { font-style: italic; }
.lw-finder-box > p { margin: .5rem 0 0; font-size: .8rem; text-align: right; }
