:root {
  --bg: #0b0f14;
  --panel: #131a24;
  --panel2: #1a2332;
  --fg: #e4ecf5;
  --muted: #7e8fa3;
  --line: #1e2d3d;
  --ok: #34d399;
  --ok-bg: rgba(52, 211, 153, 0.1);
  --off: #64748b;
  --err: #f87171;
  --err-bg: rgba(248, 113, 113, 0.08);
  --accent: #3b82f6;
  --accent2: #2563eb;
  --accent-bg: rgba(59, 130, 246, 0.08);
  --focus: #60a5fa;
  --r: 12px;
  --r-sm: 8px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35), 0 1px 3px rgba(0, 0, 0, 0.2);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5);
  --transition: 150ms ease;
  font-family: "Inter", "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--fg);
  background:
    radial-gradient(ellipse 1400px 700px at 5% -15%, rgba(59, 130, 246, 0.08) 0%, transparent 60%),
    radial-gradient(ellipse 1000px 500px at 95% -5%, rgba(52, 211, 153, 0.05) 0%, transparent 50%),
    var(--bg);
  background-attachment: fixed;
  display: flow-root;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--focus); text-decoration: none; }
a:hover { color: #93c5fd; text-decoration: underline; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* ---- Header --------------------------------------------------------------- */
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem clamp(1rem, 2.5vw, 2.5rem);
  border-bottom: 1px solid var(--line);
  background: rgba(11, 15, 20, 0.75);
  backdrop-filter: blur(12px) saturate(1.2);
  position: sticky;
  top: 0;
  z-index: 50;
  flex-wrap: wrap;
}
.brand {
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.01em;
  background: linear-gradient(135deg, var(--fg) 0%, var(--muted) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.header-right {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  color: var(--muted);
  font-size: 0.85rem;
  min-width: 0;
  margin-left: auto;
}

/* ---- Shell layout --------------------------------------------------------- */
.shell {
  display: grid;
  grid-template-columns: 12rem minmax(0, 1fr);
  gap: clamp(1rem, 2vw, 1.75rem);
  margin: 1.5rem auto;
  padding: 0 clamp(1rem, 2.5vw, 2.5rem);
  align-items: start;
}
.side {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  position: sticky;
  top: 4.5rem;
}
.nav-item {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-radius: var(--r-sm);
  font-size: 0.9rem;
  transition: all var(--transition);
  font-weight: 500;
}
.nav-item:hover { background: rgba(255, 255, 255, 0.04); color: var(--fg); }
.nav-item.active {
  background: var(--accent-bg);
  border-color: rgba(59, 130, 246, 0.2);
  color: var(--accent);
  font-weight: 600;
}
.shell:has(> .side.hidden) {
  grid-template-columns: minmax(0, 32rem);
  justify-content: center;
}

main {
  min-width: 0;
  max-width: 40rem;
  margin: 2rem auto;
  padding: 0 1rem;
}
.shell > main { max-width: none; margin: 0; padding: 0; }

/* ---- Panel ---------------------------------------------------------------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: clamp(1.25rem, 2vw, 2rem);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
}
.hidden { display: none !important; }
h1 { margin: 0; font-size: 1.3rem; font-weight: 700; letter-spacing: -0.01em; }
.hint { color: var(--muted); margin: 0 0 1.25rem; max-width: 72ch; line-height: 1.6; font-size: 0.88rem; }
.muted { color: var(--muted); }
.err { color: var(--err); margin-top: 0.75rem; font-size: 0.88rem; }

/* ---- Forms ---------------------------------------------------------------- */
label { display: flex; flex-direction: column; gap: 0.35rem; margin-bottom: 0.9rem; font-size: 0.88rem; color: var(--muted); }
input, select {
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--line);
  color: var(--fg);
  border-radius: var(--r-sm);
  padding: 0.5rem 0.7rem;
  font-size: 0.9rem;
  font-family: inherit;
  transition: border-color var(--transition), box-shadow var(--transition);
}
input:hover, select:hover { border-color: #3a4756; }
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15); }
button {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: var(--r-sm);
  padding: 0.45rem 0.9rem;
  font-size: 0.85rem;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition);
}
button:hover { background: var(--accent2); transform: translateY(-1px); box-shadow: 0 2px 8px rgba(59, 130, 246, 0.25); }
button:active { transform: translateY(0); }
button:disabled { opacity: 0.4; cursor: not-allowed; transform: none; box-shadow: none; }
button.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--fg);
}
button.ghost:hover { border-color: var(--muted); background: rgba(255, 255, 255, 0.04); transform: translateY(-1px); box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2); }
button.ghost.danger { color: var(--err); }
button.ghost.danger:hover { border-color: var(--err); background: var(--err-bg); }
button.ghost:disabled:hover { border-color: var(--line); background: transparent; transform: none; box-shadow: none; }

/* ---- Row header ----------------------------------------------------------- */
.row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}
.row > h1 { margin-right: auto; }
.inline { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem; align-items: center; }
.inline input, .inline select { min-width: 10rem; }

.count {
  color: var(--muted);
  font-size: 0.82rem;
  white-space: nowrap;
  font-weight: 500;
}
.count strong { color: var(--ok); font-weight: 600; }

/* ---- Tables --------------------------------------------------------------- */
.table-wrap { width: 100%; }
table {
  width: 100%;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 0.88rem;
}
th, td {
  text-align: left;
  padding: 0.65rem 0.6rem;
  border-bottom: 1px solid var(--line);
}
th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
  position: sticky;
  top: 3.2rem;
  z-index: 3;
  background: var(--panel);
}
td {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
}
td .hint { margin: 0; font-size: 0.78rem; }
tbody tr:not(.detail) { transition: background var(--transition); }
tbody tr:not(.detail):hover { background: rgba(255, 255, 255, 0.03); }
tbody tr:last-child > td { border-bottom: 0; }
td code { font-size: 0.8rem; color: var(--muted); font-family: "JetBrains Mono", "Fira Code", monospace; }

/* Column widths */
th.expander { width: 5rem; }
th.nameCol { width: 18%; }
th.idCol { width: 11%; }
th.statusCol { width: 13%; }
th.viewersCol { width: 16%; }
th.assignedCol { width: 19%; }
th.buildCol { width: 7%; }
th.actions { width: 9.5rem; }

/* ---- Status badge --------------------------------------------------------- */
.statusbox {
  display: inline-flex;
  align-items: baseline;
  gap: 0.4rem;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.statusbox .hint {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge::before {
  content: "";
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}
.badge.on { color: var(--ok); }
.badge.on::before { box-shadow: 0 0 6px var(--ok); }
.badge.off { color: var(--off); }

/* ---- Row actions / menus -------------------------------------------------- */
td.actions {
  white-space: nowrap;
  overflow: visible;
  position: relative;
  text-align: right;
}
td.actions:has(.rowmenu[open]) { z-index: 41; }
td.actions > * + * { margin-left: 0.35rem; }
.rowmenu { display: inline-block; position: relative; }
.rowmenu > summary {
  list-style: none;
  cursor: pointer;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--fg);
  padding: 0.4rem 0.55rem;
  line-height: 1;
  user-select: none;
  transition: all var(--transition);
}
.rowmenu > summary::-webkit-details-marker { display: none; }
.rowmenu > summary:hover { border-color: var(--muted); background: rgba(255, 255, 255, 0.04); }
.rowmenu[open] > summary { border-color: var(--accent); background: var(--accent-bg); }
.rowmenu-items {
  position: absolute;
  right: 0;
  top: calc(100% + 0.35rem);
  z-index: 40;
  min-width: 12rem;
  display: flex;
  flex-direction: column;
  padding: 0.3rem;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow-lg);
  animation: menuIn 120ms ease-out;
}
@keyframes menuIn {
  from { opacity: 0; transform: translateY(-4px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.menu-item {
  background: transparent;
  border: 0;
  color: var(--fg);
  text-align: left;
  padding: 0.5rem 0.7rem;
  border-radius: var(--r-sm);
  font-size: 0.85rem;
  white-space: nowrap;
  transition: background var(--transition);
}
.menu-item:hover { background: rgba(255, 255, 255, 0.06); transform: none; box-shadow: none; }
.menu-item.danger { color: var(--err); }
.menu-item.danger:hover { background: var(--err-bg); }

/* ---- PC picker (dropdown checklist) --------------------------------------- */
.rowmenu-items.picker {
  width: 24rem;
  max-width: min(24rem, 90vw);
  padding: 0.75rem;
  gap: 0.5rem;
  text-align: left;
  white-space: normal;
}
.picker-note {
  margin: 0;
  padding: 0.6rem 0.75rem;
  border-radius: var(--r-sm);
  border-left: 3px solid var(--accent);
  background: var(--accent-bg);
  color: var(--fg);
  font-size: 0.82rem;
  line-height: 1.5;
}
.picker-tools { margin: 0; gap: 0.35rem; }
.picker-tools input[type="search"] { flex: 1 1 8rem; min-width: 0; font-size: 0.85rem; padding: 0.35rem 0.5rem; }
.picker-tools .hint { flex-basis: 100%; margin: 0; font-size: 0.75rem; }
.picker-list {
  grid-template-columns: minmax(0, 1fr);
  max-height: 15rem;
  margin: 0;
}
.picker-foot { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.picker-foot .err { margin: 0; font-size: 0.82rem; }

/* ---- Narrow screens ------------------------------------------------------- */
@media (max-width: 1100px) {
  .listing, .listing tbody, .listing tr, .listing td { display: block; width: auto; }
  .listing thead { display: none; }
  .listing tbody tr:not(.detail) {
    background: var(--panel2);
    border: 1px solid var(--line);
    border-radius: var(--r);
    margin-bottom: 0.6rem;
    padding: 0.5rem 0.85rem;
    position: relative;
    transition: border-color var(--transition);
  }
  .listing tbody tr:not(.detail):hover { border-color: rgba(59, 130, 246, 0.3); background: var(--panel2); }
  .listing td {
    border-bottom: 0;
    padding: 0.3rem 0;
    display: grid;
    grid-template-columns: 7.5rem minmax(0, 1fr);
    gap: 0.5rem;
    align-items: center;
    white-space: normal;
    overflow: visible;
    overflow-wrap: anywhere;
  }
  .listing td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
  }
  .listing td.expander, .listing td.actions { display: flex; justify-content: flex-start; }
  .listing td.actions { justify-content: flex-end; padding-top: 0.5rem; flex-wrap: wrap; gap: 0.4rem; }
  .listing td.expander::before, .listing td.actions::before { content: none; }
  .shell { grid-template-columns: minmax(0, 1fr); gap: 0.75rem; margin-top: 1rem; }
  .side { flex-direction: row; position: static; gap: 0.3rem; }
  .nav-item { flex: 1; text-align: center; padding: 0.5rem 0.4rem; font-size: 0.82rem; }
  th { position: static; }
  #hostsTable .statusbox { flex-wrap: wrap; white-space: normal; overflow: visible; }
  .listing .chips { flex-wrap: wrap; }
  .listing .chip { flex: none; max-width: 100%; }
  .listing .pcs-line { flex-wrap: wrap; }
  .listing td.actions > * + * { margin-left: 0; }
}

#who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 14rem; }
#langSelect { padding: 0.3rem 0.4rem; font-size: 0.82rem; }

/* ---- Checkbox rows -------------------------------------------------------- */
label.check {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
  padding: 0.4rem 0.6rem;
  border-radius: var(--r-sm);
  font-size: 0.88rem;
  color: var(--muted);
  cursor: pointer;
  transition: all var(--transition);
}
label.check:hover { background: rgba(255, 255, 255, 0.04); color: var(--fg); }
label.check input { width: auto; margin: 0; accent-color: var(--accent); }
label.check .hint { margin: 0; }
.check-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- Checklist grid ------------------------------------------------------- */
.checklist {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(18rem, 1fr));
  gap: 0.1rem 0.75rem;
  margin-bottom: 1.25rem;
  max-height: 28rem;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 0.25rem;
}
.checklist > p.hint { grid-column: 1 / -1; margin: 0.5rem 0 0; }
#hostUsersList {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  max-width: 48rem;
}
#hostUsersList label.check { width: 100%; min-width: 0; }

/* ---- Users table ---------------------------------------------------------- */
#usersTable th.userNameCol { width: 18%; }
#usersTable th.emailCol { width: 25%; }
#usersTable th.roleCol { width: 12%; }
#usersTable th.pcsCol { width: 28%; }
#usersTable th.actions { width: 15rem; }
#usersTable input.user-name { width: 100%; min-width: 0; }
#usersTable td.roleCol > .muted { display: inline-flex; align-items: center; min-height: 2.45rem; }
td.pcsCol { overflow: hidden; }

/* Activity. The detail column takes the slack: it is free text of very
   variable length, and the three fixed columns either side are what the eye
   scans down. .table-wrap already scrolls the table rather than the page. */
#auditTable th.auditTimeCol { width: 15rem; }
#auditTable th.emailCol { width: 22%; }
#auditTable th.auditActionCol { width: 14rem; }
#auditTable td { vertical-align: top; }
.pcs-line { display: flex; align-items: center; gap: 0.4rem; min-width: 0; }
.pcs-line > .hint { flex: none; }
.pcs-line > .chips { min-width: 0; }

#accessSaved { margin-left: 0.75rem; }

/* ---- Sign-in button (anchor) ---------------------------------------------- */
a.button {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--accent);
  color: #fff;
  border-radius: var(--r-sm);
  padding: 0.6rem 1.2rem;
  font-size: 0.95rem;
  font-weight: 500;
  text-decoration: none;
  transition: all var(--transition);
}
a.button:hover { background: var(--accent2); text-decoration: none; transform: translateY(-1px); box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3); }

/* ---- Detail panel --------------------------------------------------------- */
th.expander, td.expander { white-space: nowrap; padding-right: 0; overflow: visible; }
button.tiny { padding: 0.3rem 0.45rem; font-size: 0.72rem; line-height: 1; min-width: 3.9rem; }

th.buildCol, td.buildCol { white-space: nowrap; }
#hostsTable.hideBuild th.buildCol,
#hostsTable.hideBuild td.buildCol { display: none; }

#hostsTable.hideAssigned th.assignedCol,
#hostsTable.hideAssigned td.assignedCol { display: none; }
td.assignedCol { overflow: hidden; }

/* ---- Chips ---------------------------------------------------------------- */
.chips { display: flex; flex-wrap: nowrap; gap: 0.25rem; min-width: 0; }
.chip {
  display: inline-block;
  flex: 0 1 auto;
  min-width: 3rem;
  max-width: 8.5rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  line-height: 1.5;
  font-weight: 500;
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid rgba(59, 130, 246, 0.2);
  color: #93c5fd;
}
.chip.more { color: var(--muted); border-color: var(--line); border-style: dashed; background: transparent; cursor: help; flex: none; min-width: 0; }

tr.detail > td {
  background: rgba(0, 0, 0, 0.2);
  padding: 1rem 1.25rem 1.25rem;
  white-space: normal;
  overflow: visible;
  border-left: 2px solid var(--accent);
}
tr.detail h2 {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  font-weight: 700;
  margin: 0 0 0.5rem;
}
tr.detail h2 + * { margin-top: 0; }
tr.detail h2:not(:first-child) { margin-top: 1.1rem; }
tr.detail h3 { font-size: 0.88rem; font-weight: 600; margin: 0.6rem 0 0.3rem; }

dl.facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(24rem, 100%), 1fr));
  gap: 0.3rem 2rem;
  margin: 0;
  font-size: 0.88rem;
}
dl.facts > div { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 0.3rem 1rem; }
dl.facts dt { color: var(--muted); font-weight: 500; }
dl.facts dd { margin: 0; word-break: break-all; }

@media (max-width: 640px) {
  dl.facts > div { grid-template-columns: 1fr; gap: 0.1rem; }
  dl.facts dd { margin-bottom: 0.4rem; }
}

/* ---- Scrollbar styling ---------------------------------------------------- */
.checklist::-webkit-scrollbar,
.picker-list::-webkit-scrollbar { width: 6px; }
.checklist::-webkit-scrollbar-track,
.picker-list::-webkit-scrollbar-track { background: transparent; }
.checklist::-webkit-scrollbar-thumb,
.picker-list::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }
.checklist::-webkit-scrollbar-thumb:hover,
.picker-list::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ---- Login card centering ------------------------------------------------- */
#loginView {
  text-align: center;
  padding: clamp(2rem, 4vw, 3.5rem);
}
#loginView h1 { font-size: 1.6rem; margin-bottom: 0.75rem; }
#loginView .hint { margin: 0 auto 1.5rem; text-align: center; }
