/* shelf: layout and widgets on top of x11.css. No transitions beyond
   x11's colour flips; the only motion is the busy marker. */

[hidden] { display: none !important; }

/* ---- page frame: top bar, app, status bar ---- */
html, body { height: 100%; }
body { display: flex; flex-direction: column; overflow: hidden; }
#topbar, .statusbar { flex: none; }
#topbar #who button { padding: 1px 6px; font-size: 11px; }
#topbar .lang-pick { padding: 1px 2px; font-size: 11px; margin-right: 6px; }
/* six sections and longer words (fr, hu) on a phone: a second row */
#topbar nav { flex-wrap: wrap; }
#app { flex: 1; min-height: 0; overflow: auto; padding: 10px; }
#app.fill { overflow: hidden; display: flex; flex-direction: column; }
#app.fill > * { flex: 1; min-height: 0; }
.statusbar { white-space: nowrap; overflow: hidden; min-height: 22px; }
#status { overflow: hidden; text-overflow: ellipsis; }
#up-status { color: var(--accent); }
p { margin: 0 0 8px; }

.stack { display: flex; flex-direction: column; gap: 10px; max-width: 1100px; margin: 0 auto; }
.win.narrow { max-width: 520px; margin: 40px auto; }

/* titlebars carry names: keep their case */
.titlebar .crumbs, .titlebar .dirty, .titlebar .tag { text-transform: none; letter-spacing: 0; }
.titlebar .crumbs { font-size: 12px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crumbs a { color: var(--fg-dim); text-decoration: none; }
.crumbs a:hover { color: var(--accent); text-decoration: underline; }
.crumbs .here { color: var(--accent); }
.titlebar button, .titlebar .btn-link, .titlebar select { padding: 1px 6px; font-size: 11px; flex: none; }
.titlebar .dirty { color: var(--warn); font-size: 11px; }

/* ---- busy marker, a stepped spinner ---- */
#busy { color: var(--accent); }
#busy i { font-style: normal; display: inline-block; width: 1ch; }
#busy i::after { content: "|"; animation: busy-spin .6s steps(1) infinite; }
@keyframes busy-spin { 0% { content: "|"; } 25% { content: "/"; } 50% { content: "-"; } 75% { content: "\\"; } }

/* ---- forms ---- */
.field { display: flex; flex-direction: column; gap: 3px; min-width: 0; margin-bottom: 8px; }
.field input, .field select, .field textarea { width: 100%; }
.form2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.form3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 12px; max-width: 760px; }
.span2 { grid-column: 1 / -1; }
.chk { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; white-space: nowrap; text-transform: none; }
.row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; }
.row-end { display: flex; justify-content: flex-end; gap: 6px; }
.lbl.gap { display: block; margin-top: 14px; margin-bottom: 4px; }
input.num { width: 80px; }
input.wide { width: 100%; }
textarea.key { font-size: 11px; resize: vertical; }
pre.secret { background: var(--bg); border: 1px solid var(--border); padding: 8px 10px; margin: 8px 0 0; user-select: all; white-space: pre-wrap; word-break: break-all; }
.note { padding: 4px 10px; border-bottom: 1px solid var(--border); background: var(--panel-2); }

/* ---- tables on the admin / shared / links pages ---- */
table.x11 td.act { white-space: nowrap; text-align: right; }
table.x11 td.act button, table.x11 td.act .btn-link { padding: 1px 6px; font-size: 11px; }
table.x11 td.num, table.x11 th.num { text-align: right; white-space: nowrap; }
table.x11 td.url a { word-break: break-all; }
table.x11 td.msg { max-width: 420px; word-break: break-word; }
table.x11 tr.off td { opacity: .6; }
.small { font-size: 11px; }
.tag { font-size: 10px; border: 1px solid var(--border); color: var(--fg-dim); padding: 0 4px; margin-left: 6px; text-transform: lowercase; }
.titlebar .tag { color: var(--warn); border-color: var(--warn); }

/* ---- login ---- */
.login-page { display: flex; justify-content: center; padding-top: 12vh; }
.login { width: 340px; max-width: 100%; }
.login .body { padding: 12px 14px; }
.login-msg { min-height: 1.4em; margin-bottom: 6px; }

/* ---- files: places + list ---- */
.files-layout { display: grid; grid-template-columns: 200px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); gap: 10px; min-height: 0; }
.places { overflow: auto; min-height: 0; }
.places > .body { display: flex; flex-direction: column; gap: 1px; padding: 6px; }
.places .lbl { margin: 10px 0 2px 6px; }
.place { color: var(--fg); text-decoration: none; padding: 2px 6px; border: 1px solid transparent; overflow: hidden; white-space: nowrap; display: flex; gap: 6px; align-items: baseline; }
.place .pn { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.space { flex: none; font-size: 10px; color: var(--fg-dim); letter-spacing: 0; }
.space.full { color: inherit; font-weight: bold; }
.place.on .space { color: inherit; opacity: .7; }
.place.on .space.full { opacity: 1; }
.place:hover { color: var(--accent); border-color: var(--border); }
.place.on { color: var(--bg); background: var(--accent); border-color: var(--accent); }
/* folded: the titlebar alone, as a strip over the window beside it */
.places > .titlebar { cursor: pointer; user-select: none; }
.places .fold { color: var(--fg-dim); letter-spacing: 0; }
.places > .titlebar:hover .fold { color: var(--accent); }
.places .place-here { display: none; color: var(--fg); }
.places.shaded > .body { display: none; }
.places.shaded .place-here { display: inline; }
.files-layout:has(> .places.shaded) { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); }

.filewin, .viewwin, .editwin { display: flex; flex-direction: column; min-height: 0; min-width: 0; position: relative; }
.toolbar { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; padding: 5px 6px; border-bottom: 1px solid var(--border); background: var(--panel); flex: none; }
.toolbar .sep { width: 1px; align-self: stretch; background: var(--border); margin: 0 3px; }
.toolbar .spacer { flex: 1; }
.toolbar .lbl { margin: 0 2px 0 4px; }
.toolbar button.on { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.toolbar .filter { width: 170px; }
.seg { display: inline-flex; }
.seg button + button { margin-left: -1px; }

.listwrap { flex: 1; min-height: 0; overflow: auto; outline: none; }
table.files { table-layout: fixed; }
table.files th.nm { width: auto; }
table.files th.sz { width: 90px; text-align: right; }
table.files th.tm { width: 150px; }
table.files th:nth-child(4) { width: 110px; }
table.files thead th { position: sticky; top: 0; z-index: 1; background: var(--panel); cursor: pointer; user-select: none; white-space: nowrap; }
table.files th.sorted { color: var(--accent); }
table.files th.sorted::after { content: " \25B4"; }
table.files th.sorted.desc::after { content: " \25BE"; }
table.files td { padding: 3px 7px; vertical-align: middle; border-bottom-color: color-mix(in srgb, var(--border) 45%, transparent); }
table.files td.nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.files td.sz { text-align: right; color: var(--fg-dim); white-space: nowrap; }
table.files td.tm { color: var(--fg-dim); white-space: nowrap; overflow: hidden; }
table.files td.nm a { text-decoration: none; color: var(--fg); }
table.files tr.d td.nm a, table.files tr.up td.nm a { color: var(--accent); }
table.files td.nm a:hover { text-decoration: underline; }
table.files tr.sel td, table.files tr.sel:hover td { background: var(--accent-soft); }
table.files tr.cur td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
/* offline: not on this device */
table.files tr.gone td, table.files tr.gone td.nm a { color: var(--fg-dim); }
table.files tr.gone td.nm a { text-decoration: line-through; text-decoration-color: var(--border); }
.listwrap:focus table.files tr.cur td { border-bottom-color: var(--accent); }
.empty { padding: 24px; text-align: center; }
.dropnote { position: absolute; inset: 0; z-index: 5; display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--bg) 75%, transparent); border: 2px dashed var(--accent); color: var(--accent); font-size: 16px; }
.dropnote span { pointer-events: none; }


/* ---- uploads ---- */
.uploads { position: fixed; right: 10px; bottom: 30px; z-index: 50; width: 440px; max-width: calc(100vw - 20px); }
.uploads .titlebar button { padding: 0 6px; }
.up-list { max-height: 40vh; overflow: auto; padding: 4px 8px; }
.up-row { display: grid; grid-template-columns: minmax(0, 1fr) 90px 70px auto; gap: 6px; align-items: center; padding: 2px 0; }
.up-row button { padding: 0 5px; font-size: 11px; }
.up-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up-st { font-size: 11px; text-align: right; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.up-bar { display: block; height: 8px; border: 1px solid var(--border); background: var(--bg); }
.up-bar > i { display: block; height: 100%; width: 0; background: var(--accent); }

/* ---- dialogs and toast ---- */
.dlg-back { position: fixed; inset: 0; z-index: 100; background: rgba(0, 0, 0, .45); display: flex; align-items: flex-start; justify-content: center; padding: 12vh 10px 10px; }
.dlg { width: 440px; max-width: 100%; max-height: 80vh; display: flex; flex-direction: column; }
.dlg.wide { width: 760px; }
.dlg > .body { overflow: auto; min-height: 0; }
.dlg > .body > .lbl { display: block; margin-bottom: 3px; }
.dlg-buttons { display: flex; justify-content: flex-end; gap: 6px; padding: 8px 10px; border-top: 1px solid var(--border); }
.dlg-x { padding: 0 6px; font-size: 11px; }
.dlg-text { white-space: pre-wrap; word-break: break-word; }
.dlg.busy { cursor: progress; }
.dlg.busy .dlg-buttons button { pointer-events: none; opacity: .5; }
#toast { position: fixed; right: 10px; top: 44px; z-index: 200; min-width: 220px; max-width: 440px; }
#toast .body { white-space: pre-wrap; word-break: break-word; }
#toast .titlebar.bad { color: var(--danger); }

/* ---- folder picker, share dialog ---- */
.pick-path { color: var(--accent); margin: 3px 0 6px; word-break: break-all; }
.pick-list { border: 1px solid var(--border); background: var(--bg); height: 260px; overflow: auto; display: flex; flex-direction: column; }
.pick-list > div { padding: 3px 8px; }
.pick-item { text-align: left; border: 0; background: transparent; padding: 3px 8px; text-transform: none; }
.pick-item:hover { background: var(--panel-2); }
.share table.x11 { margin-bottom: 4px; }
.share select { min-width: 160px; }
.tag.warn { color: var(--warn); border-color: var(--warn); }
.mono { font-family: monospace; font-size: 12px; }
pre.mono { white-space: pre-wrap; word-break: break-all; background: var(--panel-2); border: 1px solid var(--border); padding: 4px 6px; }

/* ---- viewer ---- */
.viewer { flex: 1; min-height: 0; overflow: auto; background: var(--bg); display: flex; align-items: center; justify-content: center; }
.viewer video { max-width: 100%; max-height: 100%; background: #000; }
.viewer audio { width: min(640px, 90%); }
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; cursor: zoom-in; }
.viewer.actual { display: block; }
.viewer.actual img { max-width: none; max-height: none; cursor: zoom-out; }
.viewer-pdf { align-items: stretch; }
.viewer-pdf iframe { flex: 1; border: 0; background: #fff; }
.viewer-md, .viewer-text, .viewer-other { display: block; }
.viewer-csv, .viewer-sheet, .viewer-rtf, .viewer-doc, .viewer-slides, .viewer-mail, .viewer-pub,
.viewer-archive, .viewer-img, .viewer-book, .viewer-cal, .viewer-font, .viewer-iwork { flex-direction: column; align-items: stretch; justify-content: stretch; overflow: hidden; }
.viewer-csv > .csv-host, .viewer-sheet > .csv-host, .viewer > .rich-view, .viewer > .slides-view, .viewer > .mail-view, .viewer > .part-view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.viewer-md .md-body { max-width: 880px; margin: 0 auto; padding: 16px 22px; }
.text-view { margin: 0; padding: 10px 12px; white-space: pre-wrap; word-break: break-word; font-size: 12px; tab-size: 4; }
.viewer-note { padding: 20px; text-align: center; }

/* ---- rendered markdown ---- */
.md-body { line-height: 1.55; overflow-wrap: break-word; }
.md-body h1, .md-body h2, .md-body h3, .md-body h4, .md-body h5, .md-body h6 { color: var(--accent); margin: 1.1em 0 .5em; line-height: 1.25; }
.md-body h1 { font-size: 1.6em; border-bottom: 1px solid var(--border); padding-bottom: .2em; }
.md-body h2 { font-size: 1.3em; border-bottom: 1px solid var(--border); padding-bottom: .15em; }
.md-body h3 { font-size: 1.12em; }
.md-body h4, .md-body h5, .md-body h6 { font-size: 1em; }
.md-body > :first-child { margin-top: 0; }
.md-body p, .md-body ul, .md-body ol, .md-body pre, .md-body table, .md-body blockquote { margin: 0 0 .8em; }
.md-body ul, .md-body ol { padding-left: 2em; }
.md-body li > input[type="checkbox"] { margin: 0 .4em 0 -1.4em; vertical-align: middle; }
.md-body li:has(> input[type="checkbox"]) { list-style: none; }
.md-body code { background: var(--panel-2); border: 1px solid var(--border); padding: 0 3px; font-size: .95em; }
.md-body pre { background: var(--panel-2); border: 1px solid var(--border); padding: 8px 10px; overflow: auto; }
.md-body pre code { background: none; border: 0; padding: 0; }
.md-body blockquote { border-left: 3px solid var(--accent); margin-left: 0; padding: 0 0 0 12px; color: var(--fg-dim); }
.md-body table { border-collapse: collapse; }
.md-body th, .md-body td { border: 1px solid var(--border); padding: 3px 8px; }
.md-body th { background: var(--panel-2); }
.md-body img { max-width: 100%; }
.md-body hr { border: 0; border-top: 1px solid var(--border); margin: 1.2em 0; }

.pop-back { position: fixed; inset: 0; z-index: 90; }
.win.pop { position: fixed; display: flex; flex-direction: column; max-height: calc(100vh - 8px); box-shadow: 3px 3px 0 rgba(0, 0, 0, .35); }

/* ---- narrow screens ---- */
@media (max-width: 760px) {
  #app { padding: 4px; }
  .files-layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr); gap: 4px; }
  .places { max-height: 110px; }
  .form2, .form3 { grid-template-columns: minmax(0, 1fr); }
  table.files th.tm, table.files td.tm { display: none; }
  .toolbar .filter { width: 110px; }
}

/* references to wiki articles: the accent, and its opposite for those yet to be written */
:root { --accent-opp: #8a3b87; }
@supports (color: hsl(from red h s l)) {
  :root { --accent-opp: hsl(from var(--accent) calc(h + 180) s l); }
}
a.wiki-ref, .wiki-ref { color: var(--accent); }
a.wiki-ref.missing, .wiki-ref.missing { color: var(--accent-opp); text-decoration-style: dashed; }
.ref-list { max-height: 50vh; overflow: auto; margin-top: 8px; border: 1px solid var(--border); }
.ref-list tr { cursor: pointer; }
.ref-list tr.cur td { background: var(--accent-soft); }

/* shelf at home does not answer (util.js) */
.offline-bar { flex: none; padding: 2px 10px; background: var(--titlebar); color: var(--warn); border-bottom: 1px solid var(--warn); font-size: 12px; }

/* multivac: pm14's apps in a frame (app.js multivacPage) */
.mv-win { min-height: 0; }
.mv-frame { flex: 1; min-height: 0; width: 100%; border: 0; background: var(--bg); }
/* on a phone the page around the frame scrolls up and away, the frame one screen tall and nothing below
   it, so scrolled to the end pm14 has the whole screen; pulling down at pm14's top brings shelf's bars back */
@media (max-width: 760px), (pointer: coarse) {
  html:has(#app.mv), html:has(#app.mv) body { height: auto; }
  body:has(#app.mv) { overflow: visible; }
  body:has(#app.mv) .statusbar { display: none; }
  #app.mv { flex: none; overflow: visible; padding-bottom: 0; }
  #app.mv .mv-win { border-bottom: 0; }
  #app.mv .mv-frame { flex: none; height: 100vh; height: 100dvh; }
}
/* inside shelf 0.2: the shared header (portal, apps; admin and the user at the right) */
#topbar #nav a.portal { font-weight: bold; }
/* inside shelf 0.2 the header stays one line: what does not fit is on the portal */
body:not(.anon) #topbar #nav:has(a.portal) { flex-wrap: nowrap; white-space: nowrap; min-width: 0; }
#topbar #nav a.admin { margin-left: 6px; }
#topbar #who a.navlink { padding: 0 6px; }
