/* SOR browser - light/dark aware, no framework. */

:root {
    --bg: #f7f8fa;
    --surface: #ffffff;
    --border: #dfe3e8;
    --text: #1b1f24;
    --muted: #6b7480;
    --accent: #2f6fd0;
    --accent-soft: #e8f0fc;
    --closed: #a4562a;
    --closed-soft: #fdf1e7;
    --owner: #6d3fbf;
    --institution: #1c7a63;
    --unit: #40566d;
    --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    --tree-w: 30rem;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #14171c;
        --surface: #1b1f26;
        --border: #2c333d;
        --text: #e4e7ec;
        --muted: #98a2b0;
        --accent: #6aa5f0;
        --accent-soft: #1d2b40;
        --closed: #e0a878;
        --closed-soft: #2e2318;
        --owner: #b795f0;
        --institution: #5fc9ac;
        --unit: #93a7bd;
    }
}

* { box-sizing: border-box; }

html, body {
    height: 100%;
    margin: 0;
}

body {
    display: flex;
    flex-direction: column;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.muted { color: var(--muted); }
.warn  { color: var(--closed); }

/* ---------- top bar ---------- */

.topbar {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: .6rem 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex: none;
}

.brand { display: flex; align-items: baseline; gap: .5rem; }
.brand strong { letter-spacing: .06em; }
.brand .muted { font-size: .85em; }

.search { flex: 1; display: flex; align-items: center; gap: .4rem; max-width: 40rem; }

.search input {
    flex: 1;
    min-width: 0;
    padding: .45rem .7rem;
    font: inherit;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
}
.search input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* Leaving a search is the one action in the top bar the user has to find, so it is an outlined
   accent button with a word on it rather than a muted × floating in the input. */
.search .clear-search {
    flex: none;
    padding: .4rem .65rem;
    font: inherit;
    line-height: 1.2;
    white-space: nowrap;
    color: var(--accent);
    background: var(--accent-soft);
    border: 1px solid var(--accent);
    border-radius: 6px;
    cursor: pointer;
}
.search .clear-search:hover { color: var(--surface); background: var(--accent); }
.search .clear-search:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* Kept explicit: the button is toggled with the hidden attribute, and any author `display` added
   to the rule above -- inline-flex for an icon, say -- would silently beat the UA sheet's
   [hidden] { display: none } and leave it on screen. */
.search .clear-search[hidden] { display: none; }

.counts { font-size: .85em; white-space: nowrap; }

/* ---------- layout ---------- */

.split { display: flex; flex: 1; min-height: 0; }

.pane {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    background: var(--surface);
}

.pane-tree { flex: 0 0 var(--tree-w); border-right: 1px solid var(--border); }
.pane-detail { flex: 1; }

.pane-head {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: .5rem .9rem;
    border-bottom: 1px solid var(--border);
    font-size: .85em;
    font-weight: 600;
    flex: none;
}
/* margin-left:auto beats justify-content, so the count keeps to the right edge and the toggle sits
   next to the title rather than being spread across the whole head. */
.pane-head .muted { font-weight: 400; margin-left: auto; }

.toggle {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    font-weight: 400;
    color: var(--muted);
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
}
.toggle:hover { color: var(--text); }
.toggle input { margin: 0; accent-color: var(--accent); cursor: pointer; }

/* ---------- header chips, buttons and panels ---------- */

.chip {
    flex: none;
    font: inherit;
    font-size: .85em;
    padding: .25rem .6rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg);
    color: var(--text);
    cursor: pointer;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
button.primary {
    background: var(--accent);
    color: var(--surface);
    border-color: var(--accent);
    font-weight: 600;
}

/* The download panel: one block per generated archive. */
.op {
    margin: 1rem 0;
    padding: .8rem 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
}
.op-head { display: flex; align-items: baseline; gap: .5rem; margin-bottom: .5rem; flex-wrap: wrap; }
.op-actions { display: flex; gap: .5rem; margin-top: .6rem; }
.op-actions .download {
    font: inherit;
    padding: .4rem .8rem;
    border: 1px solid var(--accent);
    border-radius: 5px;
    color: var(--surface);
    background: var(--accent);
    text-decoration: none;
    font-weight: 600;
}
.op-actions .download:hover { filter: brightness(1.08); }

.pane-body { overflow: auto; flex: 1; padding: .5rem 0; }
.pane-detail .pane-body { padding: 1.25rem 1.5rem 3rem; }

.gutter {
    flex: none;
    width: 5px;
    cursor: col-resize;
    background: transparent;
}
.gutter:hover, .gutter:focus-visible { background: var(--accent); outline: none; }

/* ---------- tree ---------- */

.tree, .tree ul { list-style: none; margin: 0; padding: 0; }
.tree ul { padding-left: 1.05rem; border-left: 1px solid var(--border); margin-left: .75rem; }

.row {
    display: flex;
    align-items: center;
    gap: .35rem;
    padding: .18rem .9rem .18rem .25rem;
    cursor: default;
    border-radius: 4px;
}
.row:hover { background: var(--bg); }
.row.selected { background: var(--accent-soft); }

.twisty {
    flex: none;
    width: 1.15rem; height: 1.15rem;
    display: grid; place-items: center;
    border: 0; background: none; padding: 0;
    color: var(--muted);
    cursor: pointer;
    font-size: .7rem;
    transition: transform .12s ease;
}
.twisty[hidden] { visibility: hidden; display: grid; }
.twisty.open { transform: rotate(90deg); }
.twisty.busy { animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.label {
    flex: 1;
    min-width: 0;
    text-align: left;
    border: 0; background: none; padding: 0;
    font: inherit; color: inherit;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.label:focus-visible { outline: 2px solid var(--accent); border-radius: 3px; }

.row.closed .label { color: var(--muted); text-decoration: line-through solid; text-decoration-thickness: 1px; }
/* Not started yet is not the same as closed: dotted underline rather than struck through, so the
   two read differently at a glance when "Vis inaktive" is ticked. */
.row.pending .label { color: var(--muted); text-decoration: underline dotted; text-underline-offset: 3px; }
.badge.pending { color: var(--accent); background: var(--accent-soft); border-color: currentColor; }

/* inline-block, not inline: in the search hits a .dot is a plain inline child of the button,
   where width/height on an inline box would be ignored. */
.dot { flex: none; display: inline-block; width: .5rem; height: .5rem; border-radius: 50%; }
.dot.owner { background: var(--owner); }
.dot.institution { background: var(--institution); }
.dot.unit { background: var(--unit); }

.n { flex: none; font-size: .78em; color: var(--muted); font-variant-numeric: tabular-nums; }

.tree-foot { padding: .5rem 1rem; }

.more {
    font: inherit;
    color: var(--accent);
    background: none;
    border: 1px dashed var(--border);
    border-radius: 5px;
    padding: .35rem .7rem;
    cursor: pointer;
    width: 100%;
}
.more:hover { border-color: var(--accent); }
.more[disabled] { color: var(--muted); cursor: default; }

/* ---------- search results in tree pane ---------- */

.hits { list-style: none; margin: 0; padding: 0 .5rem; }
.hit { padding: .35rem .4rem; border-radius: 5px; }
.hit:hover { background: var(--bg); }
.hit button {
    display: block; width: 100%; text-align: left;
    border: 0; background: none; padding: 0; font: inherit; color: inherit; cursor: pointer;
}
.hit .where { font-size: .8em; color: var(--muted); }
/* Which of the three organisations the hit is in. Coloured rather than just worded, because the same
   identifier occurs in two of them once a branch has been copied. */
.region {
    font-size: .72em; padding: .05rem .35rem; border-radius: 9px; white-space: nowrap;
    border: 1px solid transparent; vertical-align: .1em;
}
.r-ost { background: #e7f3ea; border-color: #bfdcc7; color: #276b3a; }
.r-hov { background: #e8f0fc; border-color: #c2d6f2; color: #24568f; }
.r-sja { background: #fdf0e3; border-color: #eed6b8; color: #8a5a1a; }
.r-other { background: var(--bg); border-color: var(--line); color: var(--muted); }
@media (prefers-color-scheme: dark) {
    .r-ost { background: #16301f; border-color: #2c5236; color: #8fd0a2; }
    .r-hov { background: #17263a; border-color: #2b4667; color: #93bdf0; }
    .r-sja { background: #33260f; border-color: #5b4520; color: #e0b878; }
}
.hit mark { background: var(--accent-soft); color: inherit; border-radius: 2px; }

/* ---------- detail pane ---------- */

.empty { color: var(--muted); padding: 2rem 0; max-width: 34rem; }

.crumbs { font-size: .82em; margin-bottom: .5rem; }
.crumbs button {
    border: 0; background: none; padding: 0; font: inherit;
    color: var(--accent); cursor: pointer; text-decoration: underline;
}
.crumbs .sep { color: var(--muted); margin: 0 .35rem; }

.detail-head h1 { font-size: 1.35rem; margin: 0 0 .35rem; line-height: 1.25; }

.badges { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: 1.1rem; }
.badge {
    font-size: .76em;
    padding: .15rem .5rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    color: var(--muted);
}
.badge.kind-owner { color: var(--owner); border-color: currentColor; }
.badge.kind-institution { color: var(--institution); border-color: currentColor; }
.badge.kind-unit { color: var(--unit); border-color: currentColor; }
.badge.closed { color: var(--closed); background: var(--closed-soft); border-color: currentColor; }
.badge.id { font-family: var(--mono); color: var(--text); }

/* Even column counts only. The dt/dd pairs are flat children of one grid, so an odd number of
   columns puts a label above the wrong value -- which auto-fit happily does at some pane widths.
   Sized against the pane, not the viewport, because the gutter can be dragged anywhere. */
.pane-detail { container-type: inline-size; }

.facts {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .1rem 1rem;
    margin: 0 0 1.5rem;
    padding: .75rem 0;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}
@container (min-width: 34rem) { .facts { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@container (min-width: 54rem) { .facts { grid-template-columns: repeat(6, minmax(0, 1fr)); } }

.facts dt { font-size: .76em; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.facts dd { margin: 0 0 .5rem; font-variant-numeric: tabular-nums; }

.fields { margin: 0; }
.fields .grp { margin: 0 0 1rem; }
.fields .grp > h3 {
    font-size: .82em;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--muted);
    margin: 1.2rem 0 .4rem;
    padding-bottom: .2rem;
    border-bottom: 1px solid var(--border);
}
.fields .grp .grp { margin-left: 1rem; }

.kv { display: grid; grid-template-columns: minmax(11rem, 16rem) 1fr; gap: .1rem 1rem; }
.kv > dt { color: var(--muted); padding: .15rem 0; }
.kv > dd { margin: 0; padding: .15rem 0; overflow-wrap: anywhere; }
.kv > dd .resolved, .facts > dd .resolved { color: var(--muted); }
.kv > dd .resolved::before, .facts > dd .resolved::before { content: " - "; }
.kv > dd a { color: var(--accent); }
.kv > dd.mono { font-family: var(--mono); font-size: .92em; }

.kids { margin-top: 1.5rem; display: flex; gap: .5rem; flex-wrap: wrap; }
.kids button, .op-actions button {
    font: inherit; color: var(--accent); background: none;
    border: 1px solid var(--border); border-radius: 5px;
    padding: .4rem .8rem; cursor: pointer;
}
.kids button:hover, .op-actions button:hover { border-color: var(--accent); }
.kids button:disabled, .op-actions button:disabled {
    opacity: .5; cursor: default;
}

.spinner { color: var(--muted); padding: 1rem 0; }
.error { color: var(--closed); background: var(--closed-soft); padding: .75rem 1rem; border-radius: 6px; }

.fatal { margin: 3rem auto; max-width: 40rem; }
.fatal pre, .fatal code {
    font-family: var(--mono);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 5px;
    padding: .75rem;
    display: block;
    overflow-x: auto;
}

/* ---------- login ---------- */

.login-body {
    display: grid;
    place-items: center;
    min-height: 100%;
    background: var(--bg);
}

.login {
    width: min(22rem, calc(100vw - 2rem));
    display: flex;
    flex-direction: column;
    gap: .5rem;
    padding: 1.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
}
.login h1 { margin: 0; font-size: 1.25rem; letter-spacing: .04em; }
.login > .muted { margin: 0 0 .75rem; font-size: .85em; }
.login label { font-size: .85em; color: var(--muted); }
.login input {
    font: inherit;
    padding: .5rem .7rem;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
}
.login input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.login button {
    margin-top: .5rem;
    font: inherit;
    padding: .5rem .8rem;
    border-radius: 6px;
    cursor: pointer;
}
.login .error { margin: 0; font-size: .9em; }
.login .small { margin: .25rem 0 0; font-size: .78em; }

/* The header logout sits next to the download chip; it is a link, not a button. */
a.chip { text-decoration: none; }

/* ---------- the notice shown after a login ---------- */

/* A native <dialog>, so the backdrop, the focus trap and Esc are the browser's job. Only the box
   itself is styled; showModal() centres it. */
#welcome {
    width: min(34rem, calc(100vw - 2rem));
    padding: 1.5rem 1.6rem;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 10px 40px rgb(0 0 0 / .25);
}
#welcome::backdrop { background: rgb(0 0 0 / .45); }
#welcome p { margin: 0 0 .8rem; }
#welcome p:last-of-type { margin-bottom: 1.2rem; }
#welcome p:has(+ ul) { margin-bottom: .5rem; }
#welcome ul { margin: 0 0 1.2rem; padding-left: 1.3rem; }
#welcome ul ul { margin: .3rem 0 0; }
#welcome li { margin-bottom: .35rem; }
#welcome form { display: flex; justify-content: flex-end; }
#welcome button {
    font: inherit;
    padding: .5rem 1.2rem;
    border: 1px solid var(--accent);
    border-radius: 6px;
    cursor: pointer;
}
