:root {
  --bg: #f5f6f8; --card: #fff; --text: #1c2230; --muted: #6b7385; --line: #e3e6ec;
  --accent: #2f6fde; --good: #1f9d55; --mid: #d08a00; --bad: #d64545;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #12151b; --card: #1b2029; --text: #e6e9ef; --muted: #8b93a5; --line: #2b313d; color-scheme: dark; }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
header { display: flex; align-items: baseline; gap: 16px; padding: 14px 20px; border-bottom: 1px solid var(--line); background: var(--card); }
h1 { font-size: 18px; margin: 0; }
h1 a { color: inherit; text-decoration: none; }
h2 { font-size: 16px; margin: 0 0 10px; }
h3 { font-size: 14px; margin: 0 0 10px; display: flex; align-items: center; gap: 8px; }
main { display: grid; grid-template-columns: 340px 1fr; gap: 16px; padding: 16px; }
main > * { min-width: 0; }
@media (max-width: 900px) { main { grid-template-columns: minmax(0, 1fr); } }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin-bottom: 16px; min-width: 0; }
.muted { color: var(--muted); }
.err { color: var(--bad); min-height: 1em; }
.hint { color: var(--muted); font-size: 12px; }
label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); margin-bottom: 8px; }
input, select, textarea { font: inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--text); min-width: 0; }
input.inline { font-size: 12px; padding: 3px 6px; margin-left: auto; width: 180px; }
button { font: inherit; padding: 7px 12px; border-radius: 6px; border: 1px solid var(--accent); background: var(--accent); color: #fff; cursor: pointer; }
button.ghost { background: transparent; color: var(--text); border-color: var(--line); }
button.danger { color: var(--bad); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; margin-top: 10px; }
details summary { cursor: pointer; color: var(--accent); margin-bottom: 6px; }
#searches ul { list-style: none; margin: 0; padding: 0 0 0 10px; }
#searches li { padding: 8px 10px; border-radius: 6px; cursor: pointer; border: 1px solid transparent; }
#searches li:hover { background: var(--bg); }
#searches li.sel { border-color: var(--accent); }
#searches li small { display: block; color: var(--muted); }
.head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.head a { font-size: 12px; word-break: break-all; color: var(--accent); }
.actions { display: flex; gap: 8px; align-items: flex-start; flex-wrap: wrap; }
.filters { display: flex; gap: 12px; flex-wrap: wrap; }
.filters label { margin: 0; }
.verdict { display: flex; gap: 20px; align-items: center; }
.score { font-size: 44px; font-weight: 700; min-width: 110px; text-align: center; }
.score small { font-size: 14px; color: var(--muted); }
.pill { font-size: 11px; font-weight: 500; padding: 2px 8px; border-radius: 99px; background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.kpi b { display: block; font-size: 20px; }
.kpi span { font-size: 12px; color: var(--muted); }
.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(380px, 100%), 1fr)); gap: 0 16px; }
@media (max-width: 500px) { .charts { grid-template-columns: 1fr; } }
.charts canvas { max-height: 260px; }
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.tabs button { background: transparent; color: var(--text); border-color: var(--line); padding: 4px 10px; font-size: 12px; }
.tabs button.on { border-color: var(--accent); color: var(--accent); }
.scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; cursor: pointer; user-select: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.click { cursor: pointer; }
tr.click:hover { background: var(--bg); }
.st { padding: 1px 7px; border-radius: 99px; font-size: 11px; border: 1px solid currentColor; }
.st-a { color: var(--accent); } .st-s { color: var(--good); } .st-r { color: var(--mid); } .st-h { color: var(--muted); }
.down { color: var(--good); } .up { color: var(--bad); }
.g { color: var(--good); } .m { color: var(--mid); } .b { color: var(--bad); }
dialog { border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--text); width: min(640px, 92vw); }
dialog::backdrop { background: rgba(0,0,0,.4); }

td.ph { padding: 3px 6px; }
td.ph img { width: 72px; height: 54px; object-fit: cover; border-radius: 4px; display: block; background: var(--bg); }
tr.excl td { opacity: .45; }
tr.excl td.ph, tr.excl td:last-child { opacity: 1; }
label.check { flex-direction: row; align-items: center; gap: 4px; margin: 0 0 0 auto; font-weight: 400; }
label.check + input.inline { margin-left: 8px; }
.gallery { position: relative; display: flex; align-items: center; justify-content: center; background: #000; border-radius: 8px; min-height: 200px; }
.gallery img { max-width: 100%; max-height: 62vh; display: block; }
.gallery .nav { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(0,0,0,.5); border: 0; font-size: 28px; line-height: 1; padding: 6px 12px; }
#g-prev { left: 6px; } #g-next { right: 6px; }
.dlg-actions { display: flex; justify-content: space-between; margin-top: 12px; }
dialog { width: min(900px, 94vw); }
.vf-ok { color: var(--good); } .vf-bad { color: var(--bad); } .vf-mix { color: var(--mid); } .vf-none { color: var(--muted); }

#t-now { padding: 10px 12px; border-radius: 8px; background: var(--bg); margin-bottom: 12px; }
.busy::before { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--good); margin-right: 6px; animation: pulse 1s infinite alternate; }
@keyframes pulse { to { opacity: .2; } }

details.grp > summary { list-style: none; cursor: pointer; padding: 6px 8px; border-radius: 6px; display: flex; align-items: baseline; gap: 6px; font-weight: 600; }
details.grp > summary::-webkit-details-marker { display: none; }
details.grp > summary::before { content: "▸"; color: var(--muted); width: 10px; transition: transform .15s; }
details.grp[open] > summary::before { transform: rotate(90deg); }
details.grp > summary:hover { background: var(--bg); }
details.grp > summary small { margin-left: auto; font-weight: 400; color: var(--muted); font-size: 11px; white-space: nowrap; }
details.grp.sub { margin-left: 12px; }
details.grp.sub > summary { font-weight: 500; }
#searches li { margin-left: 14px; }
#t-now { font-size: 13px; }
.tstats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; margin-bottom: 10px; font-size: 12px; }
.tstats div { display: flex; flex-direction: column; }
.tstats b { font-size: 16px; }
.tstats span { color: var(--muted); }
#t-list { list-style: none; margin: 0 0 8px; padding: 0; font-size: 12px; }
#t-list li { display: flex; align-items: center; gap: 6px; padding: 5px 0; border-top: 1px solid var(--line); }
#t-list li .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#t-list li .mt { color: var(--muted); white-space: nowrap; }
#t-list li button { padding: 2px 7px; font-size: 12px; }
#t-list li.err .nm { color: var(--bad); }
#searches li .yr { font-size: 11px; color: var(--accent); white-space: nowrap; margin-left: 4px; }
.thumbs { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 10px; }
.thumbs img { width: 96px; height: 72px; object-fit: cover; border-radius: 4px; cursor: pointer; opacity: .7; border: 2px solid transparent; }
.thumbs img:hover, .thumbs img.on { opacity: 1; border-color: var(--accent); }
.thumb-ph { width: 96px; height: 72px; border-radius: 4px; background: var(--bg); border: 1px dashed var(--line); display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 22px; }
.thumb-ph span { font-size: 10px; color: var(--muted); }

/* since the last visit */
.changes { border-color: var(--accent); }
.chg-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.chg-head h3 { margin: 0 0 2px; }
.chg-head p { margin: 0; }
.chg-head button { padding: 2px 9px; }
.changes .plus { color: var(--accent); font-weight: 600; } .changes .minus { color: var(--mid); font-weight: 600; }
.chg-s { border-top: 1px solid var(--line); margin-top: 12px; padding-top: 10px; }
.chg-s > h4 { margin: 0 0 6px; cursor: pointer; color: var(--accent); }
.chg-s > h4 small { color: var(--muted); font-weight: 400; margin-left: 8px; }
.chg-s > p { margin: 0; }
.chg-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 8px 20px; }
.chg h4 { margin: 4px 0; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.chg h4 span { color: var(--text); }
.chg ul { margin: 0; padding-left: 16px; }
.chg li { margin: 2px 0; }
.chg li a { color: var(--text); }
.c-new h4 { color: var(--accent); } .c-gone h4 { color: var(--mid); } .c-cut h4 { color: var(--good); } .c-rise h4 { color: var(--bad); }
@media (max-width: 600px) { .chg-grid { grid-template-columns: 1fr; } }
.changes.quiet { border-color: var(--line); padding: 10px 14px; }
.changes.quiet p { margin: 0; }

/* ---------- login / roles ---------- */
body.anon > header, body.anon > main { display: none; }
#login-screen { display: none; max-width: 340px; margin: 12vh auto 0; }
body.anon #login-screen { display: block; }
#login-screen h1 { margin-bottom: 14px; }
#login-screen form > button { width: 100%; }
.me { margin-left: auto; display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.me button { padding: 4px 10px; font-size: 12px; }
.role-user .admin-only { display: none !important; }
dialog.small { width: min(380px, 92vw); }
.grp.hid > summary { color: var(--muted); }
@media (max-width: 600px) { header { flex-wrap: wrap; } .me { margin-left: 0; } }

/* ---------- mobile (body.m is set by app.js: narrow screen, or a touch screen up to phone-landscape width) ---------- */
.m-only, #mnav { display: none; }
body.m .desk { display: none !important; }
body.m .m-only { display: revert; }
body.m #mnav.m-only, body.m #mnav { display: flex; }
body.m.anon #mnav { display: none; }

body.m { font-size: 15px; padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
body.m input, body.m select, body.m textarea { font-size: 16px; }  /* below 16px iOS zooms in on focus */
body.m button { min-height: 38px; }
body.m header { padding: 10px 12px; gap: 8px; position: sticky; top: 0; z-index: 5; flex-wrap: nowrap; align-items: center; }
body.m header h1 { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
body.m #worker { display: none; }
body.m .me { margin-left: auto; gap: 6px; }
body.m .me button { min-height: 32px; padding: 3px 9px; }
body.m main { display: block; padding: 10px; }
body.m .card { padding: 12px; margin-bottom: 10px; border-radius: 12px; }

/* one screen at a time, switched by the bottom bar */
body.m[data-view="home"] aside, body.m[data-view="detail"] aside { display: none; }
body.m[data-view="list"] #detail, body.m[data-view="tasks"] #detail { display: none; }
body.m[data-view="list"] #tasks { display: none; }
body.m[data-view="tasks"] #searches-card, body.m[data-view="tasks"] #add-card { display: none; }
#mnav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; background: var(--card); border-top: 1px solid var(--line);
  padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); justify-content: space-around; }
#mnav button { flex: 1; background: transparent; border: 0; color: var(--muted); display: flex; flex-direction: column;
  align-items: center; gap: 1px; padding: 6px 0; font-size: 11px; }
#mnav button b { font-size: 19px; line-height: 1; font-weight: 400; }
#mnav button.on { color: var(--accent); }

/* searches list: bigger touch targets */
body.m #searches li { padding: 10px; margin-left: 6px; }
body.m details.grp > summary { padding: 10px 8px; }
body.m details.grp.sub { margin-left: 6px; }

/* detail */
body.m .head { flex-direction: column; gap: 8px; }
body.m .head a { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; word-break: normal; }
body.m .actions { gap: 6px; }
body.m .actions button { flex: 1 1 auto; }
body.m .verdict { gap: 12px; }
body.m .score { font-size: 34px; min-width: 64px; }
body.m .kpis { grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
body.m .kpi { padding: 10px; }
body.m .kpi b { font-size: 17px; }
body.m .charts { grid-template-columns: minmax(0, 1fr); }
body.m .charts canvas { max-height: 220px; }
body.m .filters { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
body.m .filters > label { display: none; }
body.m .filters.open > label { display: flex; }
body.m #f-toggle { grid-column: 1 / -1; }
body.m .tabs { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; }
body.m .tabs button { white-space: nowrap; min-height: 32px; }
body.m #seg th:first-child, body.m #seg td:first-child { position: sticky; left: 0; background: var(--card); z-index: 1; }
body.m h3 { flex-wrap: wrap; }
body.m label.check { margin-left: 0; }
body.m input.inline { width: 100%; margin-left: 0; }
body.m label.check + input.inline { margin-left: 0; }
.l-sort { display: none; }
body.m .l-sort { display: flex; gap: 8px; align-items: flex-end; margin-bottom: 8px; }
body.m .l-sort label { flex: 1; margin: 0; }

/* cards replacing the wide tables */
body.m .cards { display: flex; flex-direction: column; gap: 8px; }
.lcard { display: flex; gap: 10px; padding: 8px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.lcard.excl { opacity: .5; }
.lcard img, .lcard .noimg { width: 96px; height: 72px; flex: none; object-fit: cover; border-radius: 6px; background: var(--bg); }
.lcard .lc { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.lcard .lc-t { font-weight: 600; font-size: 14px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.lcard .lc-p { font-size: 15px; }
.lcard .lc-m { font-size: 12px; color: var(--muted); }
.ocard { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
.ocard .oc-top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.ocard .oc-top b:last-child { font-size: 20px; }
.ocard .oc-g { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px 8px; margin-top: 6px; font-size: 12px; }
.ocard .oc-g div { display: flex; flex-direction: column; }
.ocard .oc-g span { color: var(--muted); font-size: 11px; }

/* dialogs full screen */
body.m dialog { width: 100vw; max-width: 100vw; height: 100dvh; max-height: 100dvh; margin: 0; border: 0; border-radius: 0; padding: 12px; }
body.m dialog.small { height: auto; margin: auto; border-radius: 12px; width: min(380px, 94vw); }
body.m .gallery { min-height: 160px; }
body.m .gallery img { max-height: 42vh; }
body.m .thumbs img, body.m .thumb-ph { width: 64px; height: 48px; }
body.m .dlg-actions { position: sticky; bottom: 0; background: var(--card); padding-top: 8px; gap: 8px; }
body.m .dlg-actions > * { flex: 1; }
body.m .dlg-actions button { width: 100%; }
body.m .chg-head button { min-height: 30px; }

/* password field with a show/hide (eye) button */
.pw-wrap { position: relative; display: flex; }
.pw-wrap input { flex: 1; padding-right: 42px; }
.pw-eye, body.m .pw-eye { position: absolute; right: 2px; top: 50%; transform: translateY(-50%); min-height: 0; padding: 4px 8px;
  background: transparent; border: 0; color: var(--muted); display: flex; align-items: center; }
.pw-eye:hover { color: var(--text); }
