:root {
  --bg: #f6f5f2; --surface: #fff; --text: #1d1f21; --muted: #6a6f75; --line: #e2e0da;
  --accent: #2f5d50; --accent-text: #fff; --ok: #1f7a4d; --ok-bg: #e0f2e8; --off: #7a5a1f; --off-bg: #f4ead3;
  --fact: #274f8a; --fact-bg: #dfe9f7; --proc: #5b3a8a; --proc-bg: #ece3f6;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 4px 14px rgb(0 0 0 / .05);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161716; --surface: #202221; --text: #ecebe7; --muted: #9a9d9a; --line: #333634;
    --accent: #7fb8a3; --accent-text: #0e1512; --ok: #8fd6b0; --ok-bg: #1d3328; --off: #e0c07a; --off-bg: #382f1a;
    --fact: #9fc2f2; --fact-bg: #1d2c44; --proc: #cfb4ee; --proc-bg: #2f2340;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--accent); }
main { max-width: 1280px; margin: 0 auto; padding: 16px; }

.top { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 14px; color: var(--text); text-decoration: none; min-width: 0; }
.brand img { display: block; height: 12px; width: auto; flex: none; }
.brand-text { font-weight: 600; font-size: 1rem; color: var(--muted); padding-left: 14px; border-left: 1px solid var(--line); line-height: 22px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-text > span { position: relative; top: -1px; } /* optical centring: capitals sit on the logo's centre line */
@media (max-width: 520px) { .brand-text { display: none; } }
@media (prefers-color-scheme: dark) { .brand img { filter: invert(1); } }
.lang a { color: var(--muted); text-decoration: none; padding: 4px 8px; border-radius: 6px; font-size: .9rem; }
.lang a[aria-current] { color: var(--accent-text); background: var(--accent); }

.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; align-items: end; background: var(--surface); padding: 16px; border-radius: 12px; box-shadow: var(--shadow); }
.filters input[type=search] { grid-column: 1 / -1; }
.filters label { min-width: 0; display: grid; gap: 4px; font-size: .8rem; color: var(--muted); }
input[type=search], select, .dropdown summary { width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background-color: var(--bg); color: var(--text); font: inherit; font-size: 1rem; line-height: 1.3; min-height: 42px; }
select, .dropdown summary { appearance: none; -webkit-appearance: none; padding-right: 34px; background-repeat: no-repeat; background-position: right 12px center; background-size: 12px 8px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%238a8f94' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); }
.actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px; }
button, .btn { white-space: nowrap; padding: 9px 16px; border: 0; border-radius: 8px; background: var(--accent); color: var(--accent-text); font: inherit; cursor: pointer; text-decoration: none; }
.btn.secondary { background: transparent; color: var(--text); border: 1px solid var(--line); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.count { color: var(--muted); margin: 16px 0 8px; }
.notice { background: var(--surface); padding: 16px; border-radius: 12px; border: 1px solid var(--line); }
.notice.error pre { white-space: pre-wrap; color: var(--muted); }

.grid { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.card { background: var(--surface); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow); }
.card a { display: block; color: inherit; text-decoration: none; height: 100%; }
.card:hover { outline: 2px solid var(--accent); }
.thumb { position: relative; aspect-ratio: 4/3; background: var(--line); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.nophoto { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: .9rem; }
.pill { position: absolute; padding: 2px 10px; border-radius: 999px; font-size: .75rem; font-weight: 600; }
.status { top: 8px; left: 8px; } .status.ok { background: var(--ok-bg); color: var(--ok); } .status.off, .status.cust { background: var(--off-bg); color: var(--off); }
.status.fact { background: var(--fact-bg); color: var(--fact); }
.status.proc { background: var(--proc-bg); color: var(--proc); }
.count-pill { right: 8px; bottom: 8px; background: rgb(0 0 0 / .6); color: #fff; }
.body { padding: 12px 14px 14px; }
.body h2 { margin: 0; font-size: 1.1rem; }
.body p { margin: 2px 0; }
.mat { color: var(--muted); font-size: .9rem; }
.meta { font-size: .9rem; font-variant-numeric: tabular-nums; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 !important; }
.tag { padding: 1px 8px; border-radius: 6px; font-size: .78rem; font-weight: 600; background: var(--accent); color: var(--accent-text); }
.tag.soft { background: var(--bg); color: var(--text); border: 1px solid var(--line); font-weight: 500; }

.pager { display: flex; flex-wrap: wrap; gap: 6px; justify-content: center; margin: 24px 0; }
.pager a, .pager span { padding: 6px 12px; border-radius: 8px; text-decoration: none; }
.pager a { background: var(--surface); border: 1px solid var(--line); }
.pager a[aria-current] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

.detail-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.detail-head h1 { margin: 0; }
.detail-head .pill { position: static; }
.detail { display: grid; gap: 24px; grid-template-columns: 1fr; margin-top: 16px; }
@media (min-width: 900px) { .detail { grid-template-columns: 2fr 1fr; align-items: start; } }
.gallery { list-style: none; margin: 0; padding: 0; columns: 2 220px; column-gap: 10px; }
.gallery li { break-inside: avoid; margin: 0 0 10px; }
.gallery a { display: block; border-radius: 10px; overflow: hidden; background: var(--line); }
.gallery img { width: 100%; height: auto; display: block; }
.facts { margin: 0; background: var(--surface); border-radius: 12px; box-shadow: var(--shadow); }
.facts div { display: flex; justify-content: space-between; gap: 16px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.facts div:last-child { border: 0; }
.facts dt { color: var(--muted); } .facts dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

dialog { border: 0; padding: 0; background: transparent; max-width: 100vw; max-height: 100vh; width: 100vw; height: 100vh; color: #fff; }
dialog::backdrop { background: rgb(0 0 0 / .92); }
dialog[open] { display: grid; place-items: center; }
dialog img { max-width: 92vw; max-height: 88vh; object-fit: contain; }
.lb-close, .lb-nav { position: fixed; background: rgb(255 255 255 / .15); color: #fff; font-size: 2rem; line-height: 1; width: 48px; height: 48px; padding: 0; border-radius: 50%; }
.lb-close { top: 16px; right: 16px; }
.lb-nav { top: 50%; transform: translateY(-50%); } .lb-nav.prev { left: 16px; } .lb-nav.next { right: 16px; }
.lb-count { position: fixed; bottom: 12px; margin: 0; font-size: .9rem; opacity: .8; }

/* "Options" dropdown with checkboxes */
.field { min-width: 0; display: grid; gap: 4px; }
.field .lbl { font-size: .8rem; color: var(--muted); }
.dropdown { position: relative; }
.dropdown summary { list-style: none; cursor: pointer; user-select: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dropdown summary::-webkit-details-marker { display: none; }
.dropdown summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.dropdown[open] summary { border-color: var(--accent); }
.dropdown .menu { position: absolute; z-index: 20; top: calc(100% + 4px); left: 0; min-width: 100%; width: max-content; max-width: min(320px, 90vw); padding: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgb(0 0 0 / .18); }
.dropdown .menu label { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 6px; font-size: .95rem; color: var(--text); cursor: pointer; }
.dropdown .menu label:hover { background: var(--bg); }
.dropdown .menu input { width: 18px; height: 18px; accent-color: var(--accent); flex: none; }

/* Filters + totals side by side */
.toolbar { display: grid; gap: 16px; grid-template-columns: 1fr; align-items: stretch; }
@media (min-width: 1000px) { .toolbar { grid-template-columns: minmax(0, 1fr) 260px; } }
.stats { background: var(--surface); padding: 16px; border-radius: 12px; box-shadow: var(--shadow); }
.stats h2 { margin: 0 0 8px; font-size: .8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stats dl { margin: 0; display: grid; gap: 0; }
.stats dl div { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.stats dl div:last-child { border-bottom: 0; padding-bottom: 0; }
.stats dt { color: var(--muted); font-size: .9rem; }
.stats dd { margin: 0; font-size: 1.25rem; font-weight: 650; font-variant-numeric: tabular-nums; text-align: right; }
.stats small { font-size: .8rem; font-weight: 500; color: var(--muted); }
@media (max-width: 999px) { .stats dl { grid-template-columns: repeat(3, 1fr); gap: 12px; } .stats dl div { display: block; border: 0; padding: 0; } .stats dd { text-align: left; font-size: 1.1rem; } }

/* Selection */
.listbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; margin: 16px 0 8px; }
.listbar .count { margin: 0; }
.selbar { display: flex; flex-wrap: wrap; gap: 8px; }
.btn.sm, .selbar button { padding: 6px 12px; font-size: .85rem; }
button.btn.secondary { background: transparent; color: var(--text); border: 1px solid var(--line); }
.card { position: relative; }
.pick { position: absolute; z-index: 2; top: 8px; right: 8px; width: 34px; height: 34px; display: grid; place-items: center; border-radius: 8px; background: rgb(255 255 255 / .92); box-shadow: 0 1px 4px rgb(0 0 0 / .25); cursor: pointer; }
.pick input { width: 20px; height: 20px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.card.selected { outline: 3px solid var(--accent); }
.stats-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.stats-head h2 { margin: 0; }
.stats-head [hidden], .selbar [hidden] { display: none; }
button.link { background: none; border: 0; padding: 0; color: var(--accent); font-size: .85rem; text-decoration: underline; cursor: pointer; }
.stats-sub { margin: 10px 0 0; padding-top: 8px; border-top: 1px dashed var(--line); font-size: .8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.stats.has-selection { outline: 2px solid var(--accent); }

.stats form[hidden] { display: none; }
.export { margin-top: 12px; }
.export .btn { display: block; width: 100%; text-align: center; margin-top: 8px; }
.export .btn:first-of-type { margin-top: 0; }
.export .btn:disabled { opacity: .5; cursor: not-allowed; }
.export-note { margin: 6px 0 0; font-size: .8rem; color: var(--off); }

/* ---- sign-in, account and user management ---- */
.top-right { display: flex; align-items: center; gap: 12px; }
.usermenu { position: relative; }
.usermenu summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 8px; padding: 3px 8px 3px 3px; border: 1px solid var(--line); border-radius: 999px; user-select: none; }
.usermenu summary::-webkit-details-marker { display: none; }
.usermenu[open] summary { border-color: var(--accent); }
.avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: var(--accent-text); display: grid; place-items: center; font-size: .8rem; font-weight: 700; }
.uname { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: .9rem; }
.usermenu .menu { position: absolute; right: 0; z-index: 30; top: calc(100% + 6px); min-width: 210px; padding: 6px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgb(0 0 0 / .18); display: grid; }
.usermenu .who { margin: 0; padding: 8px 10px 6px; font-size: .8rem; color: var(--muted); border-bottom: 1px solid var(--line); margin-bottom: 4px; overflow-wrap: anywhere; }
.usermenu .menu a, .usermenu .menu button { display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; border-radius: 6px; background: none; color: var(--text); font: inherit; font-size: .95rem; text-decoration: none; cursor: pointer; }
.usermenu .menu a:hover, .usermenu .menu button:hover { background: var(--bg); }
@media (max-width: 520px) { .uname { display: none; } .usermenu summary { padding: 3px; } }

.muted { color: var(--muted); }
.authbox { max-width: 400px; margin: 48px auto; background: var(--surface); padding: 28px; border-radius: 14px; box-shadow: var(--shadow); }
.authbox.wide-box { max-width: 520px; }
.authbox h1 { margin: 0 0 6px; font-size: 1.4rem; }
.authbox h2 { font-size: 1.05rem; margin: 22px 0 10px; }
.stack { display: grid; gap: 14px; }
.stack label, .row-form label { display: grid; gap: 4px; font-size: .85rem; color: var(--muted); min-width: 0; }
.stack input[type=text], .stack input[type=password], .row-form input[type=text], .row-form input[type=password] { width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--text); font: inherit; font-size: 1rem; min-height: 42px; }
.stack small { color: var(--muted); }
.btn.wide { width: 100%; text-align: center; }
.btn.danger { background: transparent; color: #b3261e; border: 1px solid #b3261e55; }
@media (prefers-color-scheme: dark) { .btn.danger { color: #f2a8a2; border-color: #f2a8a255; } }
.notice.error { border-color: #b3261e66; color: #b3261e; }
@media (prefers-color-scheme: dark) { .notice.error { color: #f2a8a2; } }
.notice.flash { margin: 0 0 16px; }
.notice.flash.ok { border-color: var(--ok); color: var(--ok); }
.notice.flash.error { border-color: #b3261e66; color: #b3261e; }
.authbox .facts div:first-child { border-top: 0; }

.panel { background: var(--surface); padding: 16px; border-radius: 12px; box-shadow: var(--shadow); margin: 16px 0; }
.panel h2 { margin: 0 0 12px; font-size: 1rem; }
.row-form { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); align-items: end; }
.row-form .check, .stack .check { display: flex; align-items: center; gap: 8px; font-size: .9rem; color: var(--text); }
.inline { display: flex; gap: 6px; align-items: center; }
.inline input { flex: 1; min-width: 0; }
.tablewrap { overflow-x: auto; }
table.users { width: 100%; border-collapse: collapse; }
table.users th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.users td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.users tr.is-disabled td { opacity: .6; }
.pill-s { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: .75rem; font-weight: 600; margin-right: 4px; }
.pill-s.ok { background: var(--ok-bg); color: var(--ok); }
.pill-s.off { background: var(--off-bg); color: var(--off); }
.pill-s.warn { background: var(--proc-bg); color: var(--proc); }
.actions-cell { display: flex; flex-wrap: wrap; gap: 6px; align-items: flex-start; }
.inline-form { margin: 0; }
details.rowform { position: relative; }
details.rowform summary { list-style: none; cursor: pointer; display: inline-block; }
details.rowform summary::-webkit-details-marker { display: none; }
details.rowform .stack { position: absolute; z-index: 15; left: 0; top: calc(100% + 6px); width: 300px; max-width: 80vw; padding: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgb(0 0 0 / .18); }
@media (max-width: 760px) {
  table.users thead { display: none; }
  table.users tr { display: block; padding: 8px 0; border-bottom: 1px solid var(--line); }
  table.users td { display: flex; justify-content: space-between; gap: 12px; border: 0; padding: 4px 10px; }
  table.users td::before { content: attr(data-label); color: var(--muted); font-size: .8rem; }
  table.users td.actions-cell { justify-content: flex-start; }
  table.users td.actions-cell::before { display: none; }
}
