:root {
    --ink: #1d2733;
    --muted: #6b7785;
    --line: #e2e6ea;
    --bg: #f5f7f9;
    --card: #ffffff;
    --brand: #1f4e79;
    --brand-ink: #ffffff;
    --ok-bg: #e8f5ec; --ok-ink: #1d5c33;
    --err-bg: #fdecec; --err-ink: #8a1f1f;
    --warn-bg: #fff4dd; --warn-ink: #7a5200;
    color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }  /* author display rules must not un-hide elements */
/* Footer sits at the bottom even on short pages. */
body { display: flex; flex-direction: column; min-height: 100vh; }
main { flex: 1 0 auto; width: 100%; }
body { margin: 0; font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--brand); }
h1 { font-size: 1.5rem; margin: 0.5rem 0 1rem; }
h2 { font-size: 1.15rem; margin: 0 0 0.75rem; }
h3 { font-size: 1rem; margin: 1rem 0 0.5rem; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.muted { color: var(--muted); font-weight: normal; }
.nowrap { white-space: nowrap; }

.topbar { background: var(--brand); color: var(--brand-ink); display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 1rem; padding: 0.6rem 1rem; }
.topbar a, .topbar .link { color: var(--brand-ink); text-decoration: none; }
.brand { font-weight: 700; }
.topbar nav { display: flex; flex-wrap: wrap; align-items: center; gap: 0.25rem 1rem; }
.topbar nav a:hover, .topbar .link:hover { text-decoration: underline; }
.who { opacity: 0.8; }

main { max-width: 1200px; margin: 0 auto; padding: 1rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 1rem 1.25rem; margin-bottom: 1rem; }
.card.narrow { max-width: 440px; margin: 2rem auto; }
.card.danger { border-color: #f1c4c4; }
.crumbs { margin: 0; color: var(--muted); font-size: 0.9rem; }

.flash { padding: 0.65rem 0.9rem; border-radius: 6px; margin-bottom: 1rem; }
.flash.ok { background: var(--ok-bg); color: var(--ok-ink); }
.flash.error { background: var(--err-bg); color: var(--err-ink); }
.notice { background: var(--warn-bg); color: var(--warn-ink); padding: 0.5rem 0.75rem; border-radius: 6px; }

form.inline { display: inline; margin: 0; }
label { display: block; margin-bottom: 0.75rem; font-weight: 600; font-size: 0.9rem; }
label.check { display: flex; align-items: center; gap: 0.45rem; font-weight: normal; margin-bottom: 0.3rem; }
label.check.strong { font-weight: 600; }
input[type=text], input[type=email], input[type=password], input[type=search], select {
    display: block; width: 100%; margin-top: 0.25rem; padding: 0.5rem 0.6rem; font: inherit;
    border: 1px solid #c8d0d8; border-radius: 6px; background: #fff; color: var(--ink);
}
input:focus, select:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 1rem; align-items: end; }
.grid-form .wide { grid-column: 1 / -1; }
.grid-form button { justify-self: start; margin-bottom: 0.75rem; }
.inline-form { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; }
.inline-form label { margin: 0; }

button, .button {
    display: inline-block; padding: 0.5rem 1rem; font: inherit; font-weight: 600; border-radius: 6px;
    border: 1px solid var(--brand); background: var(--brand); color: #fff; cursor: pointer; text-decoration: none;
}
button.secondary, .button.secondary { background: #fff; color: var(--brand); }
/* Connect for a device that appears offline: outlined grey, still a working link. */
.button.offline { background: #fff; color: var(--muted); border-color: #c8d0d8; font-weight: normal; }
.button.offline:hover { color: var(--brand); border-color: var(--brand); }
button.danger { background: #b42318; border-color: #b42318; }
button.link { background: none; border: none; padding: 0; font-weight: normal; }
.button.small, button.small { padding: 0.25rem 0.7rem; font-size: 0.85rem; }
.list-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 1rem; margin: 0.5rem 0 0.75rem; }
.list-bar p { margin: 0; }
.button-row { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.button-row form { margin: 0; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 1rem; }
.search { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; flex: 1; max-width: 560px; }
.search input { flex: 1; min-width: 12rem; margin: 0; }

/* Devices page: collapsible customers and sites (<details>, no JavaScript). */
details.customer { margin-bottom: 0.6rem; background: var(--card); border: 1px solid var(--line); border-radius: 8px; }
details.customer > summary { font-size: 1.1rem; font-weight: 700; padding: 0.7rem 1rem; }
details.customer[open] > summary { border-bottom: 2px solid var(--brand); }
details.customer > details.site:first-of-type { margin-top: 0.75rem; }
details.site { margin: 0 0.75rem 0.75rem; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
details.site > summary { font-weight: 600; padding: 0.55rem 0.8rem; }
details.site[open] { background: var(--card); }
details.site > .table-wrap, details.site > p { padding: 0 0.8rem 0.6rem; margin: 0; }
summary { list-style: none; cursor: pointer; display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.25rem 0.6rem; border-radius: 8px; }
summary::-webkit-details-marker { display: none; }
/* Chevron: points right when closed, down when open. */
summary::before {
    content: ""; flex: none; align-self: center; width: 0.5em; height: 0.5em; margin: 0 0.45em 0 0.15em;
    border-right: 2.5px solid var(--brand); border-bottom: 2.5px solid var(--brand);
    transform: rotate(-45deg); transition: transform 0.15s;
}
details[open] > summary::before { transform: rotate(45deg) translate(-0.1em, -0.1em); }
summary:hover { background: #f0f4f8; }
summary .count { color: var(--muted); font-weight: normal; font-size: 0.85rem; }
summary a.edit { margin-left: auto; }
@media (prefers-reduced-motion: reduce) { summary::before { transition: none; } }

/* Same column widths in every site's table so they line up down the page. */
.site table { table-layout: fixed; min-width: 640px; }
.site th:nth-child(1) { width: 22%; }
.site th:nth-child(2) { width: 13%; }
.site th:nth-child(3) { width: 21%; }
.site th:nth-child(4) { width: 15%; }
.site th:nth-child(6) { width: 7rem; }
.site td { overflow-wrap: anywhere; }
/* Phones: each device becomes a compact card, Connect always visible on the right. */
@media (max-width: 700px) {
    .site table { min-width: 0; table-layout: auto; }
    .site thead { display: none; }
    .site tr { display: grid; grid-template-columns: 1fr auto; column-gap: 0.75rem; padding: 0.55rem 0; border-bottom: 1px solid var(--line); }
    .site td { border: 0; padding: 0; grid-column: 1; }
    .site td:empty { display: none; }
    .site td:nth-child(1) { font-weight: 600; }
    .site td:nth-child(4), .site td:nth-child(5) { color: var(--muted); font-size: 0.9rem; }
    .site td:nth-child(3) { font-size: 0.85rem; margin: 0.1rem 0; }
    .site td.actions { grid-column: 2; grid-row: 1 / span 5; align-self: center; }
}
/* RustDesk status: coloured dot + text (never colour alone). */
.status { display: inline-flex; align-items: center; gap: 0.4em; color: var(--muted); }
.status::before { content: ""; flex: none; width: 0.6em; height: 0.6em; border-radius: 50%; background: #b0b8c1; }
.status.online { color: var(--ok-ink); font-weight: 600; }
.status.online::before { background: #22a04b; box-shadow: 0 0 0 3px #22a04b22; }
.status.unknown::before { background: transparent; border: 1.5px dashed #9aa4ae; }
.online-count { color: var(--ok-ink); }
.online-count.none { color: var(--muted); }
a.edit { font-size: 0.8rem; font-weight: normal; margin-left: 0.5rem; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: var(--card); }
th, td { text-align: left; padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }
td.num, th.num { text-align: right; }
td.actions { text-align: right; white-space: nowrap; }
td.notes { color: var(--muted); max-width: 28rem; }
tr.inactive td { color: var(--muted); }
.tag { font-size: 0.8rem; padding: 0.1rem 0.4rem; border-radius: 4px; background: #eef2f6; }
.tag.warn { background: var(--warn-bg); color: var(--warn-ink); }

.qr { display: block; margin: 0.5rem auto 0.75rem; border: 1px solid var(--line); border-radius: 6px; max-width: 100%; height: auto; }
code.secret { word-break: break-all; background: #f0f3f6; padding: 0.1rem 0.35rem; border-radius: 4px; }

ul.tree, ul.tree ul { list-style: none; padding-left: 1.4rem; margin: 0.2rem 0; }
ul.tree { padding-left: 0; }
ul.tree > li { padding: 0.35rem 0; border-bottom: 1px solid var(--line); }

/* Footer on every page: copyright centred, developer credit on the right. */
.site-footer {
    display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 0.25rem 1rem;
    padding: 0.9rem 1rem calc(0.9rem + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--line); background: var(--card); color: var(--muted); font-size: 0.85rem;
}
.site-footer .footer-copy { grid-column: 2; text-align: center; }
.site-footer .footer-dev { grid-column: 3; text-align: right; }
.site-footer a { color: inherit; }
@media (max-width: 640px) {
    .site-footer { grid-template-columns: 1fr; text-align: center; }
    .site-footer .footer-copy, .site-footer .footer-dev { grid-column: 1; text-align: center; }
}

/* Audit log filters */
.filter-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0 1rem; }
.filter-form label { flex: 0 1 11rem; }
.filter-form label.grow { flex: 1 1 16rem; }
.filter-form input[type=date] { display: block; width: 100%; margin-top: 0.25rem; padding: 0.45rem 0.5rem; font: inherit; border: 1px solid #c8d0d8; border-radius: 6px; }
.filter-form .button-row { margin-bottom: 0.75rem; }
a.filter-link { color: inherit; text-decoration: none; border-bottom: 1px dotted #9aa4ae; }
a.filter-link:hover { color: var(--brand); border-bottom-color: var(--brand); }
a.tag { color: inherit; text-decoration: none; }
a.tag:hover { outline: 1px solid var(--brand); }
