/* Riviu Manager look: neutral ground, white cards, brand blue. No external origin (CSP). */
:root {
  color-scheme: light;
  --blue: #0b68d8;
  --blue-hover: #0a5cc0;
  --blue-soft: #eaf2fd;
  --blue-line: #b9d3f5;
  --bg: #f7f7f8;
  --card: #ffffff;
  --line: #e5e7eb;
  --line-strong: #d1d5db;
  --text: #111827;
  --muted: #6b7280;
  --hover: #f3f4f6;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --bad: #b91c1c;
  --bad-soft: #fee2e2;
  --off-soft: #f3f4f6;
  --radius: 8px;
  --control: 6px;
  --shadow: 0 1px 2px rgba(17, 24, 39, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --blue: #3b8cf0;
    --blue-hover: #5a9ff3;
    --blue-soft: #16273d;
    --blue-line: #27476f;
    --bg: #18181b;
    --card: #222226;
    --line: #34343a;
    --line-strong: #46464d;
    --text: #f4f4f5;
    --muted: #a1a1aa;
    --hover: #2c2c31;
    --ok: #4ade80;
    --ok-soft: #173424;
    --warn: #fbbf24;
    --warn-soft: #3a2e12;
    --bad: #f87171;
    --bad-soft: #3b1a1a;
    --off-soft: #2c2c31;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--blue); }

h2 { font-size: 15px; font-weight: 600; margin: 0 0 12px; }

/* ---- Top bar ---- */

header.top {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 52px;
  padding: 0 20px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand img { width: 28px; height: 28px; border-radius: 6px; flex: none; }
.brand-name { font-size: 15px; font-weight: 600; white-space: nowrap; }
.brand-tag {
  font-size: 12px;
  color: var(--muted);
  padding: 2px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  white-space: nowrap;
}

.who { display: flex; align-items: center; gap: 12px; min-width: 0; }
.who-name {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

main { max-width: 1080px; margin: 0 auto; padding: 24px 20px 48px; }

/* ---- Cards ---- */

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.card-head h2 { margin: 0; }

/* Login and enrolment: a centred card. */
.auth {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}
.auth .card { width: 100%; max-width: 380px; margin: 0; padding: 28px 24px 24px; }
.auth-head { text-align: center; margin-bottom: 20px; }
.auth-head img { width: 56px; height: 56px; border-radius: 12px; display: block; margin: 0 auto 12px; }
.auth-head h1 { font-size: 18px; font-weight: 600; margin: 0; }
.auth-head p { margin: 4px 0 0; color: var(--muted); }

/* ---- Form controls ---- */

label { display: block; margin: 12px 0 6px; font-size: 13px; font-weight: 500; }
form > label:first-child, .field:first-child label { margin-top: 0; }

input[type="text"], input[type="password"], input:not([type]) {
  width: 100%;
  height: 32px;
  padding: 0 10px;
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line-strong);
  border-radius: var(--control);
}

input::placeholder { color: var(--muted); }

input:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 1px;
}
input:focus { border-color: var(--blue); }

input[type="checkbox"] { width: 15px; height: 15px; margin: 0; accent-color: var(--blue); }

button {
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  height: 32px;
  padding: 0 14px;
  border-radius: var(--control);
  border: 1px solid var(--blue);
  background: var(--blue);
  color: #fff;
  cursor: pointer;
  white-space: nowrap;
}
button:hover { background: var(--blue-hover); border-color: var(--blue-hover); }
button:disabled { opacity: 0.55; cursor: default; }

button.secondary { background: var(--card); color: var(--text); border-color: var(--line-strong); }
button.secondary:hover { background: var(--hover); }
button.danger { background: var(--card); color: var(--bad); border-color: var(--line-strong); }
button.danger:hover { background: var(--bad-soft); border-color: var(--bad); }
button.small { height: 28px; padding: 0 10px; font-size: 12px; }
button.block { width: 100%; margin-top: 4px; }

.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.check { display: inline-flex; align-items: center; gap: 6px; margin: 0; font-weight: 400; white-space: nowrap; }

.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; }
.inline-form input:not([type="checkbox"]) { flex: 1 1 200px; width: auto; }

.muted { color: var(--muted); }
.small-text { font-size: 12px; }
.error { color: var(--bad); min-height: 1.4em; margin: 8px 0; font-size: 13px; }
.error:empty { margin: 4px 0; }
.page-error:empty { display: none; }
.page-error { margin: 0 0 12px; }
.ok { color: var(--ok); }

/* ---- Status pills ---- */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 22px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  background: var(--off-soft);
  color: var(--muted);
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.on { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.plain::before { display: none; }

/* ---- PC list ---- */

.page-head { margin-bottom: 16px; }
.page-head h2 { font-size: 18px; margin: 0; }

.pcs { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }

.pc {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  height: auto;
  min-height: 180px;
  padding: 18px;
  text-align: left;
  font-weight: 400;
  white-space: normal;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.pc:hover { background: var(--card); border-color: var(--blue); }
.pc:disabled { opacity: 1; background: var(--bg); }
.pc:disabled:hover { border-color: var(--line); }
.pc:disabled .pc-title, .pc:disabled .pc-facts { color: var(--muted); }

.pc-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.pc-title { font-size: 17px; font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }
.pc-id { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.pc-facts { display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
.pc-busy { color: var(--warn); font-weight: 500; }
.pc-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}
.pc-open {
  display: inline-flex;
  align-items: center;
  height: 32px;
  padding: 0 18px;
  border-radius: var(--control);
  background: var(--blue);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
}
.pc:hover .pc-open { background: var(--blue-hover); }
.pc:disabled .pc-open { background: var(--off-soft); color: var(--muted); }

.empty {
  grid-column: 1 / -1;
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
  background: var(--card);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
}
.empty strong { display: block; color: var(--text); font-size: 15px; margin-bottom: 4px; }

/* ---- Tables ---- */

.scroll { overflow-x: auto; margin: 0 -20px; padding: 0 20px; }
table {
  width: 100%;
  font-size: 13px;
  border: 1px solid var(--line);
  border-radius: var(--control);
  border-collapse: separate;
  border-spacing: 0;
  overflow: hidden;
}
th, td {
  height: 36px;
  padding: 6px 10px;
  text-align: left;
  vertical-align: middle;
  border-bottom: 1px solid var(--line);
}
th {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  background: var(--bg);
  white-space: nowrap;
}
th:first-child, td:first-child { padding-left: 12px; }
tr:last-child td { border-bottom: 0; }
tr:hover td { background: var(--hover); }
td.actions { white-space: nowrap; }
td.actions .row { flex-wrap: nowrap; justify-content: flex-end; gap: 6px; }
td.empty-cell { text-align: center; color: var(--muted); height: 48px; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 12px; white-space: nowrap; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 26px;
  padding: 0 10px;
  margin: 0;
  font-size: 12px;
  font-weight: 400;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}
.chip:has(input:checked) { background: var(--blue-soft); border-color: var(--blue-line); color: var(--blue); }
.chip input { width: 13px; height: 13px; }

/* ---- Shown-once box ---- */

.once { background: var(--blue-soft); border-color: var(--blue-line); }
.secret {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 14px;
  background: var(--card);
  border: 1px solid var(--blue-line);
  border-radius: var(--control);
  padding: 8px 10px;
  margin: 0 0 10px;
  word-break: break-all;
  user-select: all;
}
.once-note { margin: 0 0 12px; font-size: 13px; }
.once-note strong { color: var(--warn); }

.qr { display: flex; justify-content: center; margin: 4px 0 8px; }
.qr svg { width: 200px; height: 200px; display: block; background: #fff; padding: 8px; border-radius: var(--control); }
.enrol-totp p { margin: 0 0 8px; }

.done-mark { text-align: center; }
.done-mark h2 { font-size: 17px; margin-bottom: 8px; }
.done-mark p { margin: 0 0 16px; color: var(--muted); }

.hidden { display: none !important; }

@media (max-width: 600px) {
  header.top { padding: 0 12px; height: 48px; }
  .brand-tag { display: none; }
  main { padding: 16px 12px 32px; }
  .card { padding: 16px; }
  .scroll { margin: 0 -16px; padding: 0 16px; }
  .pcs { grid-template-columns: 1fr; gap: 12px; }
  .pc { min-height: 0; }
  .inline-form input:not([type="checkbox"]) { flex-basis: 100%; }

  /* Admin tables: one small card per row, each cell labelled from its column. */
  .scroll { overflow: visible; margin: 0; padding: 0; }
  table, tbody, tr, td { display: block; width: 100%; }
  table { border: 0; }
  tr:first-child:has(th) { display: none; }
  tr {
    border: 1px solid var(--line);
    border-radius: var(--control);
    padding: 6px 12px;
    margin-bottom: 8px;
  }
  tr:hover td { background: transparent; }
  td, td:first-child {
    position: relative;
    height: auto;
    min-height: 32px;
    padding: 6px 0;
    border-bottom: 0;
    overflow-wrap: anywhere;
  }
  td[data-label] { padding-left: 108px; }
  td[data-label]::before {
    content: attr(data-label);
    position: absolute;
    left: 0;
    top: 7px;
    width: 96px;
    color: var(--muted);
    font-size: 12px;
  }
  td.actions { padding-top: 8px; }
  td.actions .row { flex-wrap: wrap; justify-content: flex-start; }
  td.empty-cell { padding: 14px 0; }
}

/* The relay runs with the 6-digit code off (RELAY_REQUIRE_TOTP=false): hide its fields. */
[data-totp="off"] .totp-only { display: none; }
