:root {
  color-scheme: dark;
  --canvas: #090a0c;
  --surface: #111214;
  --surface-raised: #1b1c1e;
  --ink: #ffffff;
  --muted: #9c9c9d;
  --line: #363739;
  --selected: #452324;
  --hover: #191a1d;
  --accent: #ff6363;
  --ease: cubic-bezier(.22, 1, .36, 1);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--canvas);
  color: var(--ink);
}

html { scrollbar-gutter: stable; }
* { box-sizing: border-box; }

body {
  min-height: 100vh;
  margin: 0;
  background: var(--canvas);
}

button,
select { font: inherit; }
button { color: inherit; }

main {
  width: 100%;
  max-width: 1680px;
  margin: 0 auto;
  padding: 14px 24px 52px;
}

header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  align-items: center;
  min-height: 58px;
  border: 1px solid var(--line);
  border-bottom: 0;
  background: rgba(17, 18, 20, .94);
  padding: 9px 14px;
  box-shadow: inset 0 1px rgba(255, 255, 255, .05), inset 0 -1px rgba(0, 0, 0, .25);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
}

.brand {
  display: flex;
  min-width: 0;
  gap: 12px;
  align-items: center;
}

.eyebrow {
  color: var(--accent);
  font-size: 12px;
  font-weight: 750;
  letter-spacing: .08em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1;
  letter-spacing: -.015em;
}

.meta {
  overflow: hidden;
  border-left: 1px solid var(--line);
  padding-left: 12px;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.toolbar { display: flex; align-items: center; }

.select-wrap {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 5px;
}

select {
  appearance: none;
  min-width: 132px;
  border: 0;
  outline: 0;
  background: transparent;
  padding: 8px 34px 8px 11px;
  color: var(--ink);
  cursor: pointer;
}

.select-wrap::after {
  content: "⌄";
  position: absolute;
  right: 12px;
  top: 6px;
  color: var(--ink);
  pointer-events: none;
}

.select-wrap:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }

.operations {
  border: 1px solid var(--line);
  background: var(--surface);
}

.operations-head {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: center;
  padding: 16px 18px;
}

.operations-head h2 { margin: 0; font-size: 16px; line-height: 1.2; letter-spacing: -.015em; }
.operations-head p { margin: 5px 0 0; color: var(--muted); font-size: 11px; }

.operations-metrics { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 7px; }
.metric { border-radius: 999px; background: var(--surface-raised); padding: 6px 9px; color: var(--muted); font-size: 11px; white-space: nowrap; }
.metric strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.metric--running strong { color: #7ddba4; }
.metric--queued strong { color: #8bb9ff; }
.metric--stale strong { color: #ffb86b; }
.metric--completed strong { color: #c7c7c8; }
.metric--failed strong { color: #ff9696; }
.metric--timed-out strong { color: #ffc17d; }

.operations-content { border-top: 1px solid var(--line); }
.operations-table-wrap { max-height: 310px; overflow: auto; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
.operations-table { width: 100%; min-width: 760px; border-collapse: collapse; table-layout: fixed; }
.operations-table th { position: sticky; top: 0; z-index: 1; background: var(--surface-raised); padding: 9px 12px; color: var(--muted); font-size: 10px; font-weight: 680; text-align: left; }
.operations-table th:first-child { width: 21%; }
.operations-table th:nth-child(2) { width: 20%; }
.operations-table th:nth-child(3) { width: auto; }
.operations-table th:nth-child(4) { width: 112px; }
.operations-table th:last-child { width: 90px; text-align: right; }
.operations-table td { border-top: 1px solid var(--line); padding: 10px 12px; color: #d1d1d2; font-size: 12px; vertical-align: middle; }
.operations-table tbody tr { transition: background .14s ease; }
.operations-table tbody tr:hover { background: var(--hover); }
.operations-table .row-stale { background: rgba(255, 184, 107, .055); }
.operation-user { overflow: hidden; color: var(--ink) !important; font-weight: 680; text-overflow: ellipsis; white-space: nowrap; }
.operation-task { color: var(--ink) !important; }
.operation-time { color: var(--muted) !important; text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

.status { display: inline-flex; align-items: center; border-radius: 999px; padding: 5px 8px; font-size: 10px; font-weight: 700; white-space: nowrap; }
.status.is-running { background: rgba(73, 187, 119, .14); color: #8ee0ad; }
.status.is-queued { background: rgba(92, 151, 238, .15); color: #9cc5ff; }
.status.is-completed { background: rgba(198, 198, 200, .12); color: #dededf; }
.status.is-failed { background: rgba(255, 99, 99, .14); color: #ff9696; }
.status.is-stale { background: rgba(255, 169, 77, .15); color: #ffc17d; }
.status.is-timed-out { background: rgba(255, 169, 77, .15); color: #ffc17d; }
.status.is-cancelled { background: var(--surface-raised); color: var(--muted); }

.operations-empty,
.operations-error { padding: 18px; color: var(--muted); font-size: 12px; }
.operations-error { color: #ffb1b1; }
.operations-loading { display: flex; gap: 7px; padding: 19px; }
.operations-loading span { width: 54px; height: 10px; background: var(--surface-raised); }

.grid,
.skeleton {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0;
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
}

.department {
  display: flex;
  flex-direction: column;
  aspect-ratio: 1;
  min-width: 0;
  overflow: hidden;
  border: 0;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: var(--surface);
  padding: 17px;
  cursor: pointer;
  outline: none;
  caret-color: transparent;
  user-select: none;
  -webkit-user-select: none;
  box-shadow: inset 0 1px rgba(255, 255, 255, .045), inset 0 -1px rgba(0, 0, 0, .22);
  transition: background .16s ease, box-shadow .16s ease;
}

.department:hover { background: var(--hover); }

.department:focus-visible {
  position: relative;
  z-index: 1;
  outline: 2px solid var(--accent);
  outline-offset: -3px;
}

.department.is-selected {
  background: var(--selected);
  box-shadow: inset 0 1px rgba(255, 99, 99, .13), inset 0 -1px rgba(0, 0, 0, .24);
}

.department.is-selected .total { color: var(--accent); }

.department-title {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  margin-bottom: 15px;
}

.department-title h2 {
  margin: 0;
  max-width: 17ch;
  font-size: 15px;
  line-height: 1.25;
  font-weight: 700;
  text-wrap: balance;
}

.total {
  color: var(--ink);
  font-size: 31px;
  line-height: .9;
  font-weight: 760;
  font-variant-numeric: tabular-nums;
}

.active-label,
.detail-label,
.dialog-label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 680;
}

.names-preview {
  display: grid;
  gap: 3px;
  min-height: 0;
  margin-top: 8px;
  overflow: auto;
  scrollbar-width: none;
}

.names-preview::-webkit-scrollbar { display: none; }

.active-user {
  border-bottom: 1px solid rgba(255, 255, 255, .10);
  padding: 5px 0;
  font-size: 12px;
}

.active-user-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.active-user-head > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.active-user-head > strong { font-variant-numeric: tabular-nums; }

.active-user-rubrics {
  display: none;
  gap: 4px 10px;
  margin-top: 6px;
  color: #9c9c9d;
  font-size: 10px;
  line-height: 1.25;
}

.active-user-rubrics span { display: flex; justify-content: space-between; gap: 8px; }
.active-user-rubrics strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.department:hover .active-user-rubrics,
.department.is-selected .active-user-rubrics { display: grid; }
.no-active { margin-top: 8px; color: var(--muted); font-size: 12px; }

.name-chip {
  display: block;
  overflow: hidden;
  border-bottom: 1px solid rgba(255, 255, 255, .10);
  padding: 5px 0;
  color: var(--ink);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.name-chip.is-zero { color: var(--muted); }
.details-panel { display: none; }

.card-footer {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  margin-top: auto;
  padding-top: 12px;
}

.card-chevron {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 1px solid transparent;
  border-radius: 0;
  color: var(--ink);
  font-size: 15px;
  transition: border-color .16s ease, background .16s ease, transform .16s var(--ease);
}

.department:hover .card-chevron,
.department.is-selected .card-chevron {
  border-color: var(--line);
  background: var(--surface-raised);
  transform: translate(1px, -1px);
}

.inactive-button {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-raised);
  padding: 6px 9px;
  color: var(--ink);
  font-size: 11px;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

.inactive-button:hover { background: #e6e6e6; color: #454647; }
.inactive-button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.inactive-button:disabled { opacity: .36; cursor: default; }

.department-detail {
  border: 1px solid var(--line);
  border-top: 0;
  background: var(--surface);
  padding: 24px;
}

.department-detail:empty { display: none; }

.detail-head {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: end;
  margin-bottom: 16px;
}

.detail-head h2,
.dialog-head h2 {
  margin: 5px 0 0;
  font-size: 22px;
  line-height: 1.2;
  letter-spacing: -.015em;
}

.detail-total { display: flex; align-items: baseline; gap: 7px; color: var(--muted); font-size: 12px; }
.detail-total strong { color: var(--ink); font-size: 27px; font-variant-numeric: tabular-nums; }

.detail-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--surface);
  scrollbar-width: none;
}

.detail-table-wrap::-webkit-scrollbar { display: none; }

.detail-table {
  width: 100%;
  min-width: 620px;
  border-collapse: collapse;
  table-layout: fixed;
}

.detail-table th {
  padding: 10px 14px;
  background: var(--surface-raised);
  color: var(--ink);
  font-size: 11px;
  font-weight: 680;
  text-align: left;
}

.detail-table th:first-child { width: 27%; }
.detail-table th:nth-child(2) { width: 110px; text-align: center; }

.detail-table td {
  border-top: 1px solid var(--line);
  padding: 11px 14px;
  color: #d1d1d2;
  font-size: 12px;
  vertical-align: middle;
}

.detail-table tbody tr { transition: background .14s ease; }
.detail-table tbody tr:hover { background: var(--hover); }
.table-user { overflow: hidden; color: var(--ink) !important; font-size: 13px !important; font-weight: 680; text-overflow: ellipsis; white-space: nowrap; }
.table-count { color: var(--ink) !important; text-align: center; font-weight: 760; font-variant-numeric: tabular-nums; }
.table-rubrics { display: flex; flex-wrap: wrap; gap: 5px 12px; }
.table-rubrics span { color: var(--muted); white-space: nowrap; }
.table-rubrics strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.no-detail { color: var(--muted); font-size: 13px; }

.inactive-dialog {
  width: min(460px, calc(100vw - 28px));
  max-height: min(620px, calc(100vh - 40px));
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--selected);
  padding: 20px;
  color: var(--ink);
  box-shadow: 8px 8px 0 rgba(18, 18, 20, .34);
}

.inactive-dialog::backdrop { background: rgba(18, 18, 20, .72); }
.dialog-head { display: flex; justify-content: space-between; gap: 16px; align-items: start; }

.icon-button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 0;
  background: var(--surface);
  font-size: 22px;
  cursor: pointer;
}

.icon-button:hover { background: #e6e6e6; color: #454647; }

.inactive-users {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0;
  margin-top: 18px;
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
  overflow: auto;
}

.inactive-user {
  overflow: hidden;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  padding: 10px;
  color: var(--ink);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.empty {
  grid-column: 1 / -1;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  padding: 28px;
  color: var(--muted);
}

.skeleton .department { min-height: 230px; }
.pulse { height: 16px; border-radius: 0; background: var(--surface-raised); margin: 10px 0; }

@media (max-width: 1080px) {
  .grid,
  .skeleton { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  main { padding: 8px 12px 32px; }
  header { grid-template-columns: minmax(0, 1fr) auto; min-height: 54px; padding: 8px 10px; }
  .brand { gap: 8px; }
  .eyebrow { font-size: 10px; }
  h1 { font-size: 16px; }
  .meta { display: none; }
  .toolbar, .select-wrap, select { width: auto; }
  select { min-width: 112px; }
  .operations-head { display: block; padding: 14px; }
  .operations-metrics { justify-content: flex-start; margin-top: 12px; }
  .operations-table-wrap { max-height: 360px; }
  .grid,
  .skeleton { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .department { padding: 13px; }
  .department-title { gap: 6px; margin-bottom: 9px; }
  .department-title h2 { font-size: 13px; }
  .total { font-size: 24px; }
  .active-user { padding: 3px 0; font-size: 11px; }
  .department-detail { padding: 18px; }
  .detail-head { align-items: start; }
}

@media (max-width: 420px) {
  .grid,
  .skeleton { grid-template-columns: 1fr; }
  .department { aspect-ratio: auto; min-height: 280px; }
  .inactive-users { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
  }
}
