:root {
  --bg: #f6f7f9;
  --card: #fff;
  --text: #1d2330;
  --muted: #667085;
  --line: #e2e5ea;
  --accent: #2557d6;
  --ok: #1f9d55;
  --warn: #c98a04;
  --bad: #d23c3c;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #15181e; --card: #1e232b; --text: #e6e8eb; --muted: #98a1b0; --line: #313844; --accent: #7aa2ff; }
}
body { margin: 0; }
header {
  display: flex; align-items: center; gap: 1rem;
  padding: .75rem 1.5rem; background: var(--card); border-bottom: 1px solid var(--line);
}
header .brand { font-weight: 700; color: var(--text); text-decoration: none; margin-right: auto; }
header .who { color: var(--muted); }
main { max-width: 960px; margin: 0 auto; padding: 1.5rem; }
h1 { margin-top: 0; }
a { color: var(--accent); }
.muted, small { color: var(--muted); }
small { display: block; margin-top: .25rem; }
code, pre { font-family: ui-monospace, Menlo, monospace; font-size: .9em; }
pre { background: var(--bg); padding: .75rem; border-radius: 6px; overflow-x: auto; user-select: all; }

.card, fieldset {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 1rem 1.25rem; margin: 0 0 1.25rem;
}
.card.narrow { max-width: 380px; margin: 3rem auto; }
.card.highlight { border-color: var(--warn); }
.card.danger { border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
legend { font-weight: 600; padding: 0 .4rem; }
.card h2 { margin-top: 0; font-size: 1.1rem; }

label { display: block; margin: .6rem 0; font-weight: 500; }
label.check { font-weight: 400; display: flex; gap: .4rem; align-items: center; margin-top: -.2rem; }
input:not([type=checkbox]) {
  display: block; width: 100%; box-sizing: border-box; margin-top: .25rem;
  padding: .5rem .6rem; border: 1px solid var(--line); border-radius: 6px;
  background: var(--card); color: var(--text); font: inherit;
}
input.short { max-width: 9rem; }
button {
  padding: .5rem 1rem; border: 0; border-radius: 6px; background: var(--accent); color: #fff;
  font: inherit; cursor: pointer;
}
button.secondary { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
button.danger { background: var(--bad); }
button.link { background: none; color: var(--accent); padding: 0; }
form.inline { display: inline; }
form.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin: .5rem 0; }
form.row input { width: auto; flex: 1; margin: 0; }
form.row small { flex-basis: 100%; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0 1rem; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .45rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 600; color: var(--muted); font-size: .9em; }
table.devices { background: var(--card); border: 1px solid var(--line); border-radius: 10px; margin-bottom: 1.5rem; }
table.messages td:first-child { white-space: nowrap; }

.dot { display: inline-block; width: .6rem; height: .6rem; border-radius: 50%; margin-right: .45rem; background: var(--muted); }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--warn); }
.dot.bad { background: var(--bad); }
.status p { margin: .3rem 0; }
.status dl { display: grid; grid-template-columns: max-content 1fr; gap: .2rem 1rem; margin: .75rem 0 0; }
.status dt { color: var(--muted); }
.status dd { margin: 0; }

.flash { padding: .6rem .9rem; border-radius: 6px; background: color-mix(in srgb, var(--ok) 15%, var(--card)); }
.flash.error { background: color-mix(in srgb, var(--bad) 15%, var(--card)); }
.flash.warn { background: color-mix(in srgb, var(--warn) 18%, var(--card)); }
.flash ul { margin: .3rem 0 0; }
.warn-text { color: var(--warn); font-size: .92em; }
.event-rolled_back td, .event-rejected td { color: var(--bad); }
.event-applied td:nth-child(3) { color: var(--ok); }
tr.by-admin td { background: color-mix(in srgb, var(--accent) 4%, transparent); }
td.actions { white-space: nowrap; }
td.actions form + form { margin-left: .6rem; }
button.link.danger-link { color: var(--bad); }

/* ---------- Compact device page: collapsible sections ---------- */
h2.group { font-size: .85rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 1.5rem 0 .5rem; }
.back { margin: 0 0 .25rem; }
.status { padding: .75rem 1.25rem; }
.status .state { display: flex; flex-wrap: wrap; gap: .4rem 1.5rem; align-items: center; }
.status dl { display: flex; flex-wrap: wrap; gap: .25rem 2rem; margin: .6rem 0 0; font-size: .9em; }
.status dl div { display: flex; gap: .4rem; }

details.section {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; margin: 0 0 .5rem;
}
details.section > summary {
  display: flex; align-items: baseline; gap: .75rem; padding: .7rem 1rem; cursor: pointer; list-style: none;
}
details.section > summary::-webkit-details-marker { display: none; }
details.section > summary::before {
  content: "▸"; color: var(--muted); width: .8rem; flex: none; transition: transform .15s;
}
details.section[open] > summary::before { transform: rotate(90deg); }
details.section[open] > summary { border-bottom: 1px solid var(--line); }
details.section > summary:hover { background: color-mix(in srgb, var(--accent) 5%, transparent); border-radius: 10px; }
details.section .title { font-weight: 600; min-width: 8.5rem; }
details.section .sum { color: var(--muted); font-size: .92em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
details.section .body { padding: .25rem 1rem 1rem; }
details.section.danger { border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }

.badge {
  flex: none; font-size: .75em; padding: .1rem .45rem; border-radius: 999px;
  background: var(--bg); color: var(--muted); border: 1px solid var(--line);
}
.badge.custom { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }

/* Save bar: at the top of the config, stays in view while scrolling. */
.savebar {
  display: flex; gap: .5rem; align-items: center;
  position: sticky; top: 0; z-index: 5; margin: 0 0 .5rem;
  padding: .6rem .75rem; background: var(--card);
  border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--line)); border-radius: 10px;
  box-shadow: 0 4px 14px rgb(0 0 0 / 8%);
}
.savebar[hidden] { display: none; }
.savebar input { margin: 0; flex: 1; }
.savebar button { flex: none; }
.hint { font-size: .88em; margin: 0 0 .6rem; }
button.small { padding: .25rem .6rem; font-size: .9em; }

@media (max-width: 640px) {
  details.section > summary { flex-wrap: wrap; }
  details.section .sum { flex-basis: 100%; padding-left: 1.55rem; white-space: normal; }
  .savebar { flex-direction: column; }
}

/* Navigation and WhatsApp */
header nav { display: flex; gap: 1rem; margin-right: auto; }
header .brand { margin-right: 0; }
header nav a { color: var(--muted); text-decoration: none; }
header nav a:hover { color: var(--accent); }
select {
  display: block; width: 100%; box-sizing: border-box; margin-top: .25rem; padding: .5rem .6rem;
  border: 1px solid var(--line); border-radius: 6px; background: var(--card); color: var(--text); font: inherit;
}
.paircode { font: 700 2rem ui-monospace, Menlo, monospace; letter-spacing: .15em; margin: .5rem 0; user-select: all; }
.section .highlight { border-left: 3px solid var(--warn); padding: .25rem 0 .25rem 1rem; margin-bottom: .5rem; }
.highlight.qr { display: flex; gap: 1.5rem; align-items: flex-start; flex-wrap: wrap; }
.highlight.qr img { background: #fff; border-radius: 6px; image-rendering: pixelated; }
