:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #6f6d68;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --wash: rgba(11, 11, 11, 0.05);
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --danger: #b92f2f;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #6250d6;
  --series-other: #898781;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --muted: #a09e96;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --wash: rgba(255, 255, 255, 0.06);
    --accent: #3987e5;
    --accent-ink: #86b6ef;
    --danger: #e66767;
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-other: #898781;
  }
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --ink: #f0efec;
  --ink-2: #c3c2b7;
  --muted: #a09e96;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --wash: rgba(255, 255, 255, 0.06);
  --accent: #3987e5;
  --accent-ink: #86b6ef;
  --danger: #e66767;
  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-other: #898781;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.55 system-ui, -apple-system, 'Segoe UI', 'Leelawadee UI', 'Noto Sans Thai', sans-serif;
}

h1,
h2,
h3,
p {
  margin: 0;
}

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

a {
  color: var(--accent-ink);
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Header */

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  display: flex;
  align-items: center;
  gap: 24px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
  min-height: 56px;
}

.brand {
  font-weight: 650;
  letter-spacing: -0.01em;
}

.nav {
  display: flex;
  gap: 4px;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.nav a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 8px;
  color: var(--ink-2);
  text-decoration: none;
  white-space: nowrap;
}

.nav a:hover {
  background: var(--wash);
}

.nav a[aria-current='page'] {
  background: var(--wash);
  color: var(--ink);
  font-weight: 600;
}

.count {
  min-width: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--wash);
  font-size: 12px;
  line-height: 20px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* Layout */

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}

.page-head {
  margin-bottom: 16px;
}

.page-head h1 {
  font-size: 22px;
  line-height: 1.3;
  font-weight: 650;
}

.lede {
  margin-top: 4px;
  color: var(--ink-2);
  max-width: 68ch;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}

.card h2 {
  font-size: 15px;
  font-weight: 600;
}

.card-note {
  color: var(--muted);
  font-size: 13px;
}

.stack {
  display: grid;
  gap: 16px;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

/* Controls */

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}

.field {
  display: grid;
  gap: 2px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
}

select,
input[type='text'],
input[type='password'] {
  height: 36px;
  max-width: 100%;
  padding: 0 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--ink);
  font-size: 14px;
}

.button {
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  font-size: 14px;
  white-space: nowrap;
  cursor: pointer;
}

.button:hover {
  background: var(--wash);
}

.button:disabled {
  opacity: 0.55;
  cursor: default;
}

.button.primary {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
}

.button.primary:hover {
  filter: brightness(1.08);
}

.button.quiet {
  border-color: transparent;
  background: none;
  color: var(--ink-2);
}

.button.quiet:hover {
  background: var(--wash);
}

.button.danger {
  color: var(--danger);
}

.error {
  color: var(--danger);
  font-size: 14px;
}

/* Stat tiles */

.tiles {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  min-width: 0;
}

.tile-label {
  color: var(--ink-2);
  font-size: 13px;
}

.tile-value {
  font-size: 24px;
  line-height: 1.3;
  font-weight: 620;
  letter-spacing: -0.01em;
}

/* Charts */

.chart-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 16px;
  margin-bottom: 8px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  color: var(--ink-2);
  font-size: 13px;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

.share {
  display: grid;
  grid-template-columns: 170px minmax(0, 1fr);
  align-items: center;
  gap: 20px;
}

.share:has(> :only-child) {
  grid-template-columns: minmax(0, 1fr);
}

.share-list {
  display: grid;
  gap: 8px;
  min-width: 0;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 14px;
}

.share-list li {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) auto 52px;
  align-items: center;
  gap: 8px;
}

.share-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.share-percent,
.share-value {
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.share-value {
  color: var(--ink-2);
}

.slice {
  stroke: var(--surface);
  stroke-width: 2;
}

.chart .donut-total {
  fill: var(--ink);
  font-size: 20px;
  font-weight: 600;
}

.heat-legend {
  display: flex;
  align-items: center;
  gap: 3px;
  color: var(--ink-2);
  font-size: 13px;
}

.heat-legend .swatch:first-of-type {
  margin-left: 4px;
}

.heat-legend .swatch:last-of-type {
  margin-right: 4px;
}

.chart {
  position: relative;
  width: 100%;
}

.chart svg {
  display: block;
  width: 100%;
}

.chart text {
  fill: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.gridline {
  stroke: var(--grid);
  stroke-width: 1;
}

.baseline {
  stroke: var(--axis);
  stroke-width: 1;
}

.crosshair {
  fill: var(--wash);
}

.table-toggle {
  margin-top: 8px;
  color: var(--ink-2);
  font-size: 13px;
}

.table-toggle summary {
  cursor: pointer;
}

.table-toggle .table-wrap {
  max-height: 320px;
  margin-top: 8px;
}

.tooltip {
  position: fixed;
  z-index: 20;
  min-width: 170px;
  padding: 8px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.14);
  font-size: 13px;
  pointer-events: none;
}

.tooltip-title {
  color: var(--ink-2);
  margin-bottom: 2px;
}

.tooltip-row {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--ink-2);
}

.tooltip-row strong {
  margin-left: auto;
  padding-left: 12px;
  color: var(--ink);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.line-key {
  width: 12px;
  height: 2px;
  border-radius: 1px;
}

/* Ranked bars */

.ranks {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.rank-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 14px;
}

.rank-name {
  min-width: 0;
  overflow-wrap: anywhere;
}

.rank-name.none {
  color: var(--muted);
}

.rank-value {
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.rank-track {
  height: 6px;
  margin-top: 3px;
}

.rank-bar {
  height: 100%;
  min-width: 2px;
  border-radius: 0 3px 3px 0;
  background: var(--series-1);
}

/* Tables */

.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface);
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  white-space: nowrap;
}

th,
td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.nowrap {
  white-space: nowrap;
}

.path {
  min-width: 300px;
  max-width: 420px;
  overflow-wrap: anywhere;
}

.sub {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.assign select {
  width: 170px;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
  color: var(--ink-2);
  font-size: 14px;
}

.pager div {
  display: flex;
  gap: 8px;
}

/* Lists of projects and groups */

.rows {
  display: grid;
  gap: 12px;
}

.group {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px 20px;
}

.group-pick,
.select-all {
  display: flex;
  gap: 12px;
  min-width: 0;
  cursor: pointer;
}

.group-pick input,
.select-all input {
  flex: none;
  width: 18px;
  height: 18px;
  margin: 2px 0 0;
}

.select-all {
  width: fit-content;
  margin-bottom: 12px;
  color: var(--ink-2);
  font-size: 14px;
}

.bulk-bar {
  position: sticky;
  bottom: 12px;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 20px;
  margin-top: 16px;
  padding: 12px 20px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.14);
}

.bulk-bar[hidden] {
  display: none;
}

.bulk-count {
  font-weight: 550;
}

.group-name {
  font-weight: 550;
  overflow-wrap: anywhere;
}

.group-facts {
  color: var(--ink-2);
  font-size: 13px;
}

.inline-form {
  display: flex;
  gap: 8px;
  min-width: 0;
}

.inline-form input {
  width: 200px;
  min-width: 0;
}

.project-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.project-head h2 {
  font-size: 16px;
  overflow-wrap: anywhere;
  min-width: 0;
}

.rule-list {
  display: grid;
  gap: 4px;
  margin: 10px 0 12px;
  padding: 0;
  list-style: none;
}

.rule-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 14px;
}

.rule-list code {
  font: 13px ui-monospace, Consolas, monospace;
  overflow-wrap: anywhere;
  min-width: 0;
}

.rule-kind {
  color: var(--muted);
  font-size: 12px;
  margin-right: 6px;
}

.rule-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.rule-form input {
  flex: 1 1 240px;
  min-width: 0;
}

.empty {
  padding: 32px 16px;
  color: var(--ink-2);
  text-align: center;
}

/* Login */

.command code {
  display: block;
  margin-top: 6px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--wash);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.command h3 {
  font-size: 14px;
  font-weight: 600;
}

.machines {
  margin-top: 16px;
}

.settings-form {
  display: grid;
  gap: 12px;
  max-width: 420px;
}

.settings-form input {
  width: 100%;
}

.settings-form .button {
  justify-self: start;
}

.profile {
  position: relative;
  flex: none;
}

.profile summary {
  list-style: none;
  cursor: pointer;
}

.profile summary::-webkit-details-marker {
  display: none;
}

.profile summary::after {
  content: ' ▾';
}

.profile-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 6;
  display: grid;
  min-width: 150px;
  padding: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.14);
}

.profile-menu a,
.profile-menu button {
  padding: 7px 10px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.profile-menu a:hover,
.profile-menu button:hover,
.profile-menu a[aria-current='page'] {
  background: var(--wash);
}

.theme-switch {
  display: inline-flex;
  flex: none;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.theme-switch button {
  padding: 3px 8px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--ink-2);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.theme-switch button:hover {
  background: var(--wash);
}

.theme-switch button[aria-pressed='true'] {
  background: var(--wash);
  color: var(--ink);
  font-weight: 600;
}

.login .theme-switch {
  justify-self: center;
}

.login {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 16px;
}

.login form {
  display: grid;
  gap: 12px;
  width: min(340px, 100%);
}

.login h1 {
  font-size: 20px;
  font-weight: 650;
}

.login input {
  width: 100%;
}

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

@media (max-width: 640px) {
  .topbar-inner {
    flex-wrap: wrap;
    gap: 0 12px;
    padding: 6px 16px;
  }

  .nav {
    order: 3;
    flex-basis: 100%;
    margin: 0 -8px;
  }

  .brand {
    display: none;
  }

  .topbar .theme-switch {
    margin-right: auto;
  }

  main {
    padding: 16px;
  }

  .tiles {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .grid-2,
  .share {
    grid-template-columns: minmax(0, 1fr);
  }

  .donut {
    max-width: 170px;
    margin: 0 auto;
  }

  .tile-value {
    font-size: 20px;
  }

  .card {
    padding: 16px;
  }

  .group {
    grid-template-columns: minmax(0, 1fr);
  }

  .inline-form input {
    flex: 1;
    width: auto;
  }

  .bulk-bar .inline-form {
    flex: 1 1 100%;
  }

  .filters .field {
    flex: 1 1 140px;
  }

  .filters select {
    width: 100%;
  }
}
