/* Administrator's interface of the control center. One accent colour for
   everything that leads somewhere; green, orange and red only for states, and
   never without a word beside them. No inline styles anywhere: the page runs
   under style-src 'self'. */
:root {
  --bg: #f3f4f7; --surface: #fff; --side: #fafbfc; --sunk: #eef0f4; --line: #e3e6ec;
  --text: #14161a; --dim: #667085; --accent: #0071e3; --accent-soft: #e5f1fe;
  --ok: #16803c; --ok-soft: #e3f6e9; --warn: #b25e00; --warn-soft: #fdf0dc; --bad: #c8261a; --bad-soft: #fde8e6;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --lift: 0 8px 24px rgba(16, 24, 40, .12);
  --r: 14px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0c10; --surface: #17191f; --side: #111318; --sunk: #1f222a; --line: #282c36;
    --text: #f2f3f5; --dim: #98a1b0; --accent: #0a84ff; --accent-soft: #10294a;
    --ok: #3ccf6e; --ok-soft: #11301c; --warn: #ffa733; --warn-soft: #3a2a0c; --bad: #ff6257; --bad-soft: #3b1512;
    --shadow: 0 0 0 1px var(--line); --lift: 0 12px 32px rgba(0, 0, 0, .5);
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
[hidden] { display: none !important; }
h1 { overflow-wrap: anywhere; font-size: 1.6rem; line-height: 1.15; letter-spacing: -.02em; margin: 0; font-weight: 650; }
h2 { font-size: 1.05rem; margin: 0; font-weight: 650; }
h3 { font-size: .8rem; margin: 1rem 0 .4rem; color: var(--dim); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
p { margin: .5rem 0; }
a { color: var(--accent); text-decoration: none; }
.dim { color: var(--dim); }
.err { color: var(--bad); }
.pre { white-space: pre-line; }
.mono, code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: .8125rem; word-break: break-all; }
code.big { font-size: 1.3rem; letter-spacing: .05em; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- controls */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 2.25rem; padding: .4rem .95rem; border: 0; border-radius: 9px;
  background: var(--sunk); color: var(--text); font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; transition: transform .08s, filter .08s; }
.btn:hover { filter: brightness(.96); }
.btn:active { transform: scale(.97); filter: brightness(.9); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.warn { background: var(--warn-soft); color: var(--warn); }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn.primary.danger { background: var(--bad); color: #fff; }
.btn.primary.warn { background: var(--warn); color: #fff; }
.btn.small { min-height: 1.875rem; padding: .25rem .7rem; font-size: .8125rem; border-radius: 8px; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: .4rem .65rem; min-height: 2.25rem; max-width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { width: 100%; font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: .8125rem; resize: vertical; }
label { display: flex; flex-direction: column; gap: .25rem; font-size: .8125rem; color: var(--dim); margin: .6rem 0; }
label > input, label > select { color: var(--text); font-size: .9375rem; }
label.check { flex-direction: row; align-items: center; gap: .5rem; color: var(--text); font-size: .9375rem; min-height: 1.875rem; margin: .1rem 0; }
label.check input { min-height: 0; width: 1.05rem; height: 1.05rem; accent-color: var(--accent); }
input.code { font: 600 1.6rem ui-monospace, Menlo, monospace; letter-spacing: .3em; width: 11rem; text-align: center; }
fieldset.group { border: 1px solid var(--line); border-radius: 12px; margin: .8rem 0; padding: .3rem .9rem .7rem; display: grid; grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); gap: 0 1rem; }
fieldset.group legend { font-weight: 600; padding: 0 .4rem; }
.row { display: flex; align-items: center; justify-content: space-between; gap: .75rem; }
.row.left { justify-content: flex-start; align-items: flex-end; }
.row.end { justify-content: flex-end; margin-top: .9rem; }
.row.wrap { flex-wrap: wrap; }
.row label { margin: 0; }
.grow { flex: 1 1 12rem; }
.push { margin-right: auto; }
.acts { display: flex; gap: .4rem; flex-wrap: wrap; margin-left: auto; }

/* ---- the frame: a side for where one is, the rest for what is there */
#app { display: grid; grid-template-columns: 17rem minmax(0, 1fr); min-height: 100vh; }
#side { position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; gap: .25rem; padding: 1.1rem .8rem .8rem; background: var(--side); border-right: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: .65rem; padding: 0 .5rem .9rem; color: var(--text); font-weight: 650; letter-spacing: -.01em; }
.brand img { border-radius: 8px; }
#nav { display: flex; flex-direction: column; gap: 2px; }
#nav a { display: flex; align-items: center; gap: .7rem; padding: .5rem .6rem; border-radius: 9px; color: var(--text); font-weight: 550; position: relative; }
#nav a:hover { background: var(--sunk); }
#nav a[aria-current] { background: var(--accent-soft); color: var(--accent); }
#nav svg { width: 1.25rem; height: 1.25rem; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.mark { width: .5rem; height: .5rem; border-radius: 50%; background: var(--warn); margin-left: auto; }
.mark.bad { background: var(--bad); }
#treeBox { margin-top: .6rem; }
#treeBox > summary { display: none; }
.cap { font-size: .7rem; text-transform: uppercase; letter-spacing: .07em; color: var(--dim); font-weight: 600; margin: 1rem .6rem .3rem; }
.tree a { display: flex; align-items: center; gap: .5rem; padding: .3rem .6rem; border-radius: 8px; color: var(--text); font-size: .875rem; min-height: 1.875rem; cursor: pointer; }
.tree a:hover { background: var(--sunk); }
.tree a[aria-current] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.tree a.l1 { padding-left: 1.5rem; }
.tree a.l2 { padding-left: 2.4rem; }
.tree a span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree a i { font-style: normal; font-size: .75rem; color: var(--dim); font-variant-numeric: tabular-nums; }
#foot { margin-top: auto; padding: .8rem .4rem 0; border-top: 1px solid var(--line); display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
#whoami { flex: 1 1 100%; font-size: .8125rem; color: var(--dim); overflow: hidden; text-overflow: ellipsis; }
#lang { min-height: 1.875rem; padding: .15rem .4rem; font-size: .8125rem; }
#main { padding: 1.6rem 2rem 3rem; min-width: 0; max-width: 1500px; width: 100%; }
.head > div { min-width: 0; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.head p { margin: .2rem 0 0; }
.back { display: inline-flex; align-items: center; gap: .3rem; margin-bottom: .6rem; font-weight: 550; min-height: 1.875rem; }
.back::before { content: "‹"; font-size: 1.3em; line-height: 1; }
.bar { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
#find { flex: 1 1 14rem; max-width: 22rem; }
.seg { display: inline-flex; background: var(--sunk); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: none; color: var(--dim); font: inherit; font-weight: 550; font-size: .875rem; padding: .3rem .75rem; border-radius: 8px; cursor: pointer; min-height: 1.75rem; }
.seg button[aria-pressed=true] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.seg i { font-style: normal; color: var(--dim); font-variant-numeric: tabular-nums; margin-left: .15rem; }
.banner { padding: .6rem .9rem; border-radius: 10px; margin: 0 0 1rem; }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.bad { background: var(--bad-soft); color: var(--bad); }
.empty { text-align: center; color: var(--dim); padding: 3rem 1rem; border: 1px dashed var(--line); border-radius: var(--r); }

/* ---- cards */
.card { overflow-x: auto; background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow); padding: 1.1rem 1.25rem; margin-bottom: 1rem; }
.card > h2 { margin-bottom: .6rem; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(19rem, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.dev { min-width: 0; display: flex; flex-direction: column; gap: .55rem; background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow); padding: 1rem 1.1rem; color: var(--text); transition: transform .12s, box-shadow .12s; }
a.dev:hover { box-shadow: var(--lift); transform: translateY(-1px); }
a.dev:active { transform: scale(.99); }
.dev.off { box-shadow: none; border: 1px solid var(--line); background: none; }
.dev .top { display: flex; align-items: center; gap: .6rem; }
.dev b { font-size: 1.02rem; font-weight: 650; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dev .where { color: var(--dim); font-size: .8125rem; margin-top: -.35rem; }
.dev .facts { display: flex; flex-wrap: wrap; gap: .3rem .9rem; font-size: .8125rem; color: var(--dim); }
.dev .facts span { display: inline-flex; align-items: center; gap: .3rem; }
.dev .use { font-size: .8125rem; border-top: 1px solid var(--line); padding-top: .55rem; margin-top: auto; color: var(--dim); }
.dev .use.busy { color: var(--warn); font-weight: 550; }
/* the mark of a device that is connected right now: it breathes */
.dot { width: .65rem; height: .65rem; border-radius: 50%; background: var(--dim); flex: none; opacity: .5; }
.dot.on { opacity: 1; background: var(--ok); animation: pulse 2.4s infinite; }
.dot.busy { opacity: 1; background: var(--warn); }
.dot.pending { background: var(--accent); opacity: 1; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(34, 170, 85, .55); } 70%, 100% { box-shadow: 0 0 0 .5rem rgba(34, 170, 85, 0); } }
.pill, .badge { display: inline-flex; align-items: center; gap: .35rem; padding: .12rem .6rem; border-radius: 999px; font-size: .75rem; font-weight: 600; background: var(--sunk); color: var(--dim); white-space: nowrap; }
.pill.on, .pill.ok, .badge.done, .badge.active { background: var(--ok-soft); color: var(--ok); }
.pill.busy, .pill.warn, .badge.sent, .badge.queued { background: var(--warn-soft); color: var(--warn); }
.pill.pending { background: var(--accent-soft); color: var(--accent); }
.pill.revoked, .pill.failed, .badge.failed, .badge.expired { background: var(--bad-soft); color: var(--bad); }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.chips:empty { display: none; }
.chip { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; align-items: center; padding: .1rem .55rem; border-radius: 7px; font-size: .75rem; font-weight: 550; background: var(--sunk); color: var(--dim); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.acc { background: var(--accent-soft); color: var(--accent); }
#dChips { margin: -.4rem 0 1rem; }
/* signal: four bars, as many filled as the link is good */
.bars { display: inline-flex; align-items: flex-end; gap: 2px; height: .8rem; }
.bars i { width: 3px; background: var(--line); border-radius: 1px; }
.bars i:nth-child(1) { height: 25%; } .bars i:nth-child(2) { height: 50%; } .bars i:nth-child(3) { height: 75%; } .bars i:nth-child(4) { height: 100%; }
.bars.s1 i:nth-child(-n+1), .bars.s2 i:nth-child(-n+2), .bars.s3 i:nth-child(-n+3), .bars.s4 i { background: currentColor; }

.tabs { display: flex; gap: 1.4rem; border-bottom: 1px solid var(--line); margin-bottom: 1.1rem; overflow-x: auto; }
.tabs a { padding: .55rem 0; color: var(--dim); font-weight: 550; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; cursor: pointer; }
.tabs a[aria-current] { color: var(--text); border-color: var(--accent); }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(13.5rem, 1fr)); gap: .8rem; margin: 0 0 1rem; }
.tiles > div { background: var(--surface); border-radius: var(--r); box-shadow: var(--shadow); padding: .85rem 1rem; min-height: 5.6rem; }
.tiles dt { font-size: .75rem; color: var(--dim); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.tiles dd { margin: .25rem 0 0; font-size: 1.25rem; font-weight: 650; letter-spacing: -.01em; }
.tiles dd.text { font-size: 1.05rem; }
.tiles p { margin: .15rem 0 0; font-size: .8125rem; color: var(--dim); }
.tiles > div.attn { background: var(--warn-soft); }
.tiles > div.attn dd { color: var(--warn); }
.tiles > div.good dd { color: var(--ok); }

table { border-collapse: collapse; width: 100%; margin: .6rem 0; }
th { text-align: left; font-size: .75rem; color: var(--dim); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; padding: .4rem .6rem; border-bottom: 1px solid var(--line); }
td { padding: .5rem .6rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tr.grp td .acts { display: inline-flex; margin-left: 1rem; vertical-align: middle; text-transform: none; letter-spacing: 0; }
tr.grp td { background: var(--sunk); font-size: .75rem; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--dim); padding: .3rem .6rem; }
tr.failed td { color: var(--bad); }
td.acts { text-align: right; white-space: nowrap; display: table-cell; }
td.acts .btn { margin-left: .3rem; }
td pre { margin: 0; white-space: pre-wrap; word-break: break-word; font: .75rem ui-monospace, Menlo, monospace; max-height: 9rem; overflow: auto; }
table.kv th { width: 11rem; text-transform: none; letter-spacing: 0; font-size: .875rem; font-weight: 500; vertical-align: top; }
pre.code { background: var(--sunk); border-radius: 10px; padding: .8rem; max-height: 60vh; overflow: auto; font: .8125rem ui-monospace, Menlo, monospace; white-space: pre-wrap; word-break: break-word; }
.picks { display: flex; flex-direction: column; gap: .15rem; max-height: 18rem; overflow: auto; border: 1px solid var(--line); border-radius: 10px; padding: .4rem .6rem; }
.picks.flat { flex-direction: row; flex-wrap: wrap; gap: .2rem 1.2rem; border: 0; padding: 0; max-height: none; }
.picks .line { display: flex; align-items: center; justify-content: space-between; gap: .6rem; min-height: 2.1rem; }
.picks .line select { min-height: 1.8rem; padding: .1rem .4rem; font-size: .8125rem; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 1.2rem; }
.grpcard .people { font-size: .8125rem; color: var(--dim); }

#term { height: min(60vh, 34rem); background: #000; border-radius: 10px; padding: .4rem; margin: .6rem 0; overflow: hidden; }
#conState.wait { color: var(--warn); }
#conState.open { color: var(--ok); }

/* ---- dialogs */
dialog { border: 0; border-radius: 16px; padding: 1.3rem 1.4rem; width: min(30rem, calc(100vw - 2rem)); background: var(--surface); color: var(--text); box-shadow: var(--lift); }
dialog.wide { width: min(46rem, calc(100vw - 2rem)); }
dialog::backdrop { background: rgba(10, 12, 16, .45); }
dialog[open] { animation: rise .18s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(8px) scale(.98); } }
dialog h2 { margin-bottom: .6rem; font-size: 1.15rem; }
dialog canvas { display: block; margin: .6rem auto; border-radius: 8px; }
dialog ol, dialog ul { padding-left: 1.2rem; }
#toast { position: fixed; left: 50%; bottom: 1.6rem; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: .6rem 1rem; border-radius: 10px; box-shadow: var(--lift); z-index: 50; max-width: calc(100vw - 2rem); }

/* ---- signing in */
#login { max-width: 25rem; margin: 0 auto; padding: 8vh 1rem 3rem; }
.hero { text-align: center; margin-bottom: 1.4rem; }
.hero img { border-radius: 18px; box-shadow: var(--lift); }
.hero p { font-size: 1.35rem; font-weight: 650; letter-spacing: -.02em; margin: .8rem 0 0; }
#loginLang { display: flex; justify-content: flex-end; margin-bottom: 1rem; }
#login summary { cursor: pointer; font-weight: 550; min-height: 1.875rem; }
#login canvas { display: block; margin: .6rem auto; }

/* What an account may not do is not shown to it (app.js sets the classes). */
body:not(.admin) [data-admin], body:not(.can-manage) [data-manage] { display: none !important; }

/* ---- narrow: one column, the places as a bar under the thumb */
@media (max-width: 860px) {
  #app { display: block; padding-bottom: calc(4.2rem + env(safe-area-inset-bottom)); }
  #side { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: .7rem 1rem; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .brand { padding: 0; flex: 1; order: 1; min-width: 0; }
  .brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #foot { margin: 0; padding: 0; border: 0; flex: none; order: 2; flex-wrap: nowrap; }
  #whoami { display: none; }
  #nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; flex-direction: row; background: var(--side); border-top: 1px solid var(--line); padding: .3rem .4rem calc(.3rem + env(safe-area-inset-bottom)); }
  #nav a { flex: 1; flex-direction: column; gap: .1rem; font-size: .6875rem; padding: .3rem 0; min-height: 3.2rem; justify-content: center; }
  #nav a[aria-current] { background: none; }
  .mark { position: absolute; top: .35rem; right: 30%; }
  #treeBox { flex: 1 1 100%; margin: .3rem 0 0; order: 3; }
  .seg { flex-wrap: nowrap; overflow-x: auto; max-width: 100%; }
  .seg button { white-space: nowrap; }
  #find { max-width: none; flex-basis: 100%; }
  #treeBox > summary { display: block; line-height: 2.75rem; color: var(--accent); font-weight: 550; cursor: pointer; }
  body.one #treeBox { display: none; }
  #main { padding: 1rem 1rem 2rem; }
  h1 { font-size: 1.35rem; }
  .cards { grid-template-columns: minmax(0, 1fr); }
  .two { grid-template-columns: 1fr; }
  .btn, .btn.small, input, select, #lang, label.check, .seg button, .tree a, .back, .picks .line select { min-height: 2.75rem; }
  .tabs a { line-height: 1.9rem; }
  /* a table row becomes a block of its own, each cell with the name of its column */
  table.stack thead { display: none; }
  table.stack tr { display: block; padding: .5rem 0; border-bottom: 1px solid var(--line); }
  table.stack td { display: flex; gap: .6rem; border: 0; padding: .15rem 0; }
  table.stack td::before { content: attr(data-label); color: var(--dim); font-size: .8125rem; flex: 0 0 6.5rem; }
  table.stack td.acts { justify-content: flex-start; flex-wrap: wrap; padding-top: .4rem; }
  table.stack td.acts::before, table.stack tr.grp td::before, table.stack td.none { display: none; }
  table.stack td.acts .btn { margin: 0; }
  table.kv th { width: 7rem; }
  dialog { margin: auto 0 0; width: 100vw; max-width: 100vw; border-radius: 16px 16px 0 0; max-height: 92vh; }
  dialog.wide { width: 100vw; }
  dialog[open] { animation: up .22s ease-out; }
  #toast { bottom: calc(5rem + env(safe-area-inset-bottom)); }
}
@keyframes up { from { transform: translateY(100%); } }
@media (pointer: coarse) { .btn, .btn.small, input, select, #lang, label.check, .seg button, .tree a { min-height: 2.75rem; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
@media (prefers-reduced-transparency: reduce) { dialog::backdrop { background: rgba(10, 12, 16, .8); } }
@media (prefers-contrast: more) {
  :root { --line: #8a8f99; --dim: #3d434d; }
  .card, .dev, .tiles > div { border: 1px solid var(--line); }
}
@media (prefers-contrast: more) and (prefers-color-scheme: dark) { :root { --dim: #c9ced6; } }
