:root {
  color-scheme: light;
  --bg: #e9edf1;
  --surface: #ffffff;
  --surface-2: #f4f6f8;
  --ink: #17212b;
  --muted: #5a6876;
  --line: #c9d2db;
  --accent: #1d5aa6;
  --accent-hover: #174a8a;
  --accent-ink: #ffffff;
  --ok: #2c7349;
  --warn: #8a5f00;
  --danger: #b42318;
  --focus: #e0a100;
  --radius-s: 4px;
  --radius-m: 8px;
  --font: "Segoe UI", "Helvetica Neue", system-ui, -apple-system, Roboto, Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "Liberation Mono", monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #10161d;
    --surface: #18212a;
    --surface-2: #1f2a35;
    --ink: #e3e9ef;
    --muted: #97a6b5;
    --line: #2f3c49;
    --accent: #6fa6ec;
    --accent-hover: #8db9f1;
    --accent-ink: #0c1623;
    --ok: #6cc28f;
    --warn: #e0b45a;
    --danger: #f07c70;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { font-size: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 1rem/1.5 var(--font);
}
h1, h2, h3 { line-height: 1.2; margin: 0; }
h1 { font-size: 1.75rem; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 1.25rem; font-weight: 650; }
h3 { font-size: 1.0625rem; font-weight: 650; }
p { margin: 0; }
a { color: var(--accent); }
code { font-family: var(--mono); font-size: 0.8125rem; word-break: break-all; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* Top bar */
.topbar {
  display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap;
  padding: 0.75rem clamp(1rem, 4vw, 2.5rem);
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 1.0625rem; color: var(--ink); text-decoration: none; }
.tabs { display: flex; gap: 0.25rem; flex-wrap: wrap; }
.tabs a {
  padding: 0.4rem 0.75rem; border-radius: var(--radius-s);
  color: var(--muted); text-decoration: none; font-weight: 550;
}
.tabs a:hover { color: var(--ink); background: var(--surface-2); }
.tabs a[aria-current="page"] { color: var(--ink); background: var(--surface-2); box-shadow: inset 0 -2px 0 var(--accent); }
.account { margin-left: auto; display: flex; align-items: center; gap: 0.75rem; color: var(--muted); }

main { max-width: 64rem; margin: 0 auto; padding: 2rem clamp(1rem, 4vw, 2.5rem) 4rem; }
.view > * + * { margin-top: 1.5rem; }
.page-head { display: flex; align-items: end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.muted { color: var(--muted); }
.spaced { margin-top: 1rem; }
input.search { max-width: 18rem; margin-top: 0; }
.error { color: var(--danger); }

/* Buttons and inputs */
.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem;
  font: inherit; font-weight: 600; font-size: 0.9375rem;
  padding: 0.5rem 1rem; border-radius: var(--radius-s);
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.button:hover { background: var(--surface-2); }
.button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.button.quiet { border-color: transparent; background: transparent; padding-inline: 0.5rem; }
.button.danger { color: var(--danger); }
.button:disabled { opacity: 0.55; cursor: not-allowed; }

label { display: block; font-weight: 600; font-size: 0.9375rem; }
.hint { display: block; font-weight: 400; color: var(--muted); font-size: 0.875rem; }
input[type="text"], input[type="search"], input[type="date"], input[type="number"], select, textarea {
  display: block; width: 100%; margin-top: 0.35rem;
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-s); padding: 0.5rem 0.65rem;
}
textarea { min-height: 7rem; resize: vertical; }
input[type="file"] { margin-top: 0.35rem; font: inherit; max-width: 100%; }
.form { display: grid; gap: 1rem; max-width: 36rem; }
.form-row { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 1.25rem; }
.panel > * + * { margin-top: 1rem; }

/* Products and the version timeline */
.product { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); padding: 1.5rem; }
.product-desc { color: var(--muted); margin-top: 0.35rem; max-width: 70ch; }
.timeline { list-style: none; margin: 1.25rem 0 0; padding: 0 0 0 1.5rem; position: relative; }
.timeline::before {
  content: ""; position: absolute; left: 0.4rem; top: 0.6rem; bottom: 0.6rem;
  width: 2px; background: var(--line);
}
.version { position: relative; display: flex; gap: 1rem; align-items: flex-start; padding: 0.75rem 0; }
.version + .version { border-top: 1px solid var(--line); }
.version::before {
  content: ""; position: absolute; left: -1.5rem; top: 1rem;
  width: 0.85rem; height: 0.85rem; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--line);
}
.version.is-latest::before { background: var(--accent); border-color: var(--accent); }
.version-main { flex: 1; min-width: 0; }
.version-title { display: flex; gap: 0.5rem; align-items: baseline; flex-wrap: wrap; }
.version.is-latest .version-title h3 { font-size: 1.1875rem; }
.version-meta { color: var(--muted); font-size: 0.9375rem; margin-top: 0.15rem; overflow-wrap: anywhere; }
.tag { font-size: 0.8125rem; font-weight: 600; padding: 0.05rem 0.45rem; border-radius: var(--radius-s); background: var(--surface-2); color: var(--muted); }
.tag.latest { color: var(--accent); }
.tag.processing, .tag.uploading { color: var(--warn); }
.tag.failed { color: var(--danger); }
details { margin-top: 0.5rem; }
summary { cursor: pointer; color: var(--accent); font-weight: 550; font-size: 0.9375rem; }
.notes { white-space: pre-wrap; margin-top: 0.4rem; max-width: 72ch; }
.internal-notes { margin-top: 0.6rem; padding: 0.5rem 0.75rem; max-width: 72ch; background: var(--surface-2); border-left: 3px solid var(--warn); border-radius: var(--radius-s); }
.internal-notes.empty-note { padding: 0.25rem 0.5rem; background: none; border-left-color: var(--line); }
.internal-notes .notes { margin-top: 0.25rem; }
.internal-notes-head { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; }
.internal-notes-label { font-size: 0.8125rem; font-weight: 600; color: var(--warn); }
.checksum { margin-top: 0.5rem; font-size: 0.8125rem; color: var(--muted); }
.empty { padding: 2.5rem 1.5rem; text-align: center; background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius-m); }
.empty p { color: var(--muted); margin-top: 0.4rem; }

/* Upload progress */
.progress { height: 0.6rem; background: var(--surface-2); border-radius: 999px; overflow: hidden; border: 1px solid var(--line); }
.progress > div { height: 100%; width: 0; background: var(--accent); transition: width 0.2s linear; }
.progress-text { font-variant-numeric: tabular-nums; color: var(--muted); }

/* Tables */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-m); }
table { width: 100%; border-collapse: collapse; font-size: 0.9375rem; }
th, td { text-align: left; padding: 0.6rem 0.85rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-weight: 600; color: var(--muted); background: var(--surface-2); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }

.row-actions { display: flex; gap: 0.25rem; flex-wrap: wrap; align-items: center; }

/* Admin product list */
.admin-products > * + * { margin-top: 1rem; }
.admin-product-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; }
.admin-product-title { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; min-width: 0; }
.chips { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.tag.group { color: var(--accent); border: 1px solid var(--line); }
.tag.group.failed { color: var(--danger); }
.product details { margin-top: 1rem; }
.product details .table-wrap { margin-top: 0.6rem; }

/* Group picker */
.group-picker { border: 1px solid var(--line); border-radius: var(--radius-s); padding: 0.75rem 1rem 1rem; margin: 0; min-width: 0; }
.group-picker legend { font-weight: 600; font-size: 0.9375rem; padding: 0 0.25rem; }
.group-picker .hint + input, .group-picker legend + .hint { margin-top: 0.35rem; }
.check-list {
  display: flex; flex-direction: column; gap: 0.15rem;
  margin-top: 0.6rem; max-height: 14rem; overflow-y: auto;
  border: 1px solid var(--line); border-radius: var(--radius-s); background: var(--surface-2);
  padding: 0.4rem 0.6rem;
}
.check-list label.check { padding: 0.2rem 0; }

/* Two-column form: fields on the left, group picker on the right */
.form.wide { max-width: 56rem; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(14rem, 20rem); gap: 1.25rem; align-items: start; }
.split-main { display: grid; gap: 1rem; }
@media (max-width: 40rem) {
  .split { grid-template-columns: minmax(0, 1fr); }
}
label.check { display: flex; align-items: center; gap: 0.45rem; font-weight: 450; overflow-wrap: anywhere; }
label.check input { margin: 0; width: 1rem; height: 1rem; flex: none; accent-color: var(--accent); }

/* Edit dialog */
.edit-dialog {
  width: min(36rem, calc(100% - 2rem)); max-height: calc(100% - 2rem);
  padding: 1.5rem; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-m);
}
.edit-dialog.wide { width: min(56rem, calc(100% - 2rem)); }
.edit-dialog::backdrop { background: rgb(0 0 0 / 0.45); }
.edit-dialog .form { max-width: none; }

/* Sign-in */
.signin { max-width: 28rem; margin: 12vh auto 0; text-align: center; }
.signin > * + * { margin-top: 1rem; }
.signin p { color: var(--muted); }

/* Notice */
.notice {
  position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%);
  max-width: min(36rem, calc(100% - 2rem));
  background: var(--ink); color: var(--bg);
  padding: 0.7rem 1.1rem; border-radius: var(--radius-m); font-weight: 550;
}
.notice.error { background: var(--danger); color: #fff; }

@media (max-width: 40rem) {
  .version { flex-direction: column; }
  .account span { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  .progress > div { transition: none; }
}
/* License keys stay together; machine identifiers can wrap in narrow tables. */
.license-key code { white-space: nowrap; word-break: normal; }
.license-expiry { display: grid; justify-items: start; gap: 0.35rem; }
.license-machines { padding-left: 1.2rem; }
.license-machines code { overflow-wrap: anywhere; }
.license-machines li { margin-block: .75rem; }
