:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --ink: #18202a;
  --muted: #637083;
  --line: #d8dee7;
  --panel: #ffffff;
  --accent: #0f766e;
  --accent-dark: #115e59;
  --warn: #b45309;
  --bad: #b91c1c;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

[hidden] {
  display: none !important;
}

.visually-hidden {
  clip: rect(0, 0, 0, 0) !important;
  clip-path: inset(50%) !important;
  height: 1px !important;
  overflow: hidden !important;
  position: absolute !important;
  white-space: nowrap !important;
  width: 1px !important;
}

button,
input,
select {
  font: inherit;
}

.topbar {
  align-items: center;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 24px;
  justify-content: space-between;
  min-height: 72px;
  padding: 14px 18px;
}

h1 {
  font-size: 20px;
  line-height: 1.1;
  margin: 0 0 5px;
}

p {
  color: var(--muted);
  margin: 0;
}

.message {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
  max-width: 520px;
}

.message[data-tone="warn"] {
  color: var(--warn);
}

.message[data-tone="error"] {
  color: var(--bad);
}

.poll-status {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.poll-status[data-tone="error"] {
  color: var(--bad);
}

.actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.pin-form {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
}

.pin-form .form-control {
  min-width: 120px;
}

.btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  display: inline-block;
  font-weight: 600;
  line-height: 1.5;
  min-height: 36px;
  padding: 6px 12px;
  text-align: center;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.btn-primary:hover {
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.btn-secondary {
  background: #e6fffb;
  border-color: var(--accent);
  color: var(--accent-dark);
}

.btn-sm {
  font-size: 12px;
  min-height: 30px;
  padding: 3px 8px;
}

.btn:disabled {
  background: #a8b4c2;
  border-color: #a8b4c2;
  color: white;
  cursor: not-allowed;
}

.form-control,
.form-select {
  background-color: white;
  border: 1px solid var(--line);
  border-radius: 6px;
  border-color: var(--line);
  color: var(--ink);
  min-height: 36px;
  padding: 6px 9px;
}

.form-control-sm,
.form-select-sm {
  font-size: 12px;
  min-height: 30px;
  padding: 4px 7px;
}

.form-check-input {
  accent-color: var(--accent);
  height: 16px;
  width: 16px;
}

main {
  display: grid;
  gap: 14px;
  padding: 14px;
}

.metrics {
  display: grid;
  gap: 1px;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  overflow: hidden;
}

.metrics > div {
  background: var(--panel);
  min-width: 0;
  padding: 12px;
}

.metrics span {
  color: var(--muted);
  display: block;
  font-size: 12px;
  margin-bottom: 5px;
}

.metrics strong {
  display: block;
  font-size: 18px;
  font-weight: 650;
  overflow-wrap: anywhere;
}

.speed-settings {
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(220px, 1.2fr) repeat(2, minmax(240px, 1fr));
  padding: 14px;
}

.speed-settings h2 {
  font-size: 16px;
  margin: 0 0 4px;
}

.speed-settings p,
.setting-toggle small {
  color: var(--muted);
  font-size: 12px;
}

.setting-toggle {
  align-items: flex-start;
  cursor: pointer;
  display: flex;
  gap: 10px;
  margin: 0;
}

.setting-toggle input {
  flex: 0 0 auto;
  margin-top: 3px;
}

.setting-toggle span,
.setting-toggle small {
  display: block;
}

.table-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.table-responsive {
  overflow-x: auto;
}

.table {
  --bs-table-bg: var(--panel);
  --bs-table-color: var(--ink);
  --bs-table-border-color: var(--line);
  border-collapse: collapse;
  margin: 0;
  min-width: 1040px;
  width: 100%;
}

.table th,
.table td {
  border-bottom: 1px solid var(--line);
  padding: 10px;
  text-align: left;
  vertical-align: middle;
}

.table th {
  background: #edf1f5;
  color: #344054;
  font-size: 12px;
  font-weight: 650;
  position: sticky;
  top: 0;
  z-index: 1;
}

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

.slot {
  color: var(--muted);
  font-weight: 650;
  white-space: nowrap;
}

.checkline {
  align-items: center;
  display: flex;
  gap: 8px;
  margin-bottom: 6px;
}

.checkline input {
  min-height: auto;
}

.type {
  font-weight: 650;
  text-transform: uppercase;
}

.source,
.fore,
.side {
  width: 100%;
}

.position {
  display: grid;
  gap: 6px;
  min-width: 150px;
}

.raw,
.corrected,
.weight {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.fresh {
  color: var(--accent-dark);
}

.stale {
  color: var(--bad);
}

.stepper {
  display: grid;
  gap: 4px;
  grid-template-columns: 34px 88px 34px;
}

.stepper button {
  padding: 0;
}

.angleOffset,
.speedScale {
  font-variant-numeric: tabular-nums;
  width: 100%;
}

@media (max-width: 780px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .actions {
    justify-content: stretch;
    width: 100%;
  }

  .actions input,
  .actions button {
    flex: 1 1 120px;
  }

  .pin-form {
    flex: 1 1 auto;
  }

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

  .speed-settings {
    align-items: stretch;
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  main {
    padding: 10px;
  }

  .table-responsive {
    overflow-x: visible;
  }

  .table-wrap {
    background: transparent;
    border: 0;
  }

  .table {
    border-collapse: separate;
    border-spacing: 0 12px;
    min-width: 0;
  }

  .table thead {
    display: none;
  }

  .table tbody,
  .table tr,
  .table td {
    display: block;
    width: 100%;
  }

  .table tbody tr {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: 0 1px 2px rgb(16 24 40 / 8%);
    margin-bottom: 12px;
    overflow: hidden;
    padding: 8px 10px;
  }

  .table td {
    align-items: center;
    border-bottom: 1px solid var(--line);
    display: grid;
    gap: 10px;
    grid-template-columns: minmax(92px, 32%) minmax(0, 1fr);
    padding: 8px 2px;
  }

  .table td::before {
    color: var(--muted);
    content: attr(data-label);
    font-size: 12px;
    font-weight: 650;
    text-transform: uppercase;
  }

  .table td:last-child {
    border-bottom: 0;
  }

  .table .slot {
    background: #edf1f5;
    display: block;
    margin: -8px -10px 8px;
    padding: 10px;
  }

  .table .slot::before {
    content: none;
  }

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

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

  .raw,
  .corrected,
  .weight {
    white-space: normal;
  }
}

@media (max-width: 480px) {
  body {
    font-size: 13px;
  }

  .metrics {
    grid-template-columns: 1fr;
  }

  .actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .actions input,
  .actions button {
    width: 100%;
  }

  .pin-form {
    display: grid;
    grid-template-columns: 1fr;
    width: 100%;
  }

  .table td {
    align-items: stretch;
    grid-template-columns: 1fr;
  }
}
