:root {
  color-scheme: light;
  --bg: #fdf8f4;
  --bg-elevated: #ffffff;
  --bg-elevated-2: #fff2e6;
  --border: #f0dfd0;
  --border-strong: #e3c9b4;
  --text: #2b1d14;
  --text-dim: #7a6656;
  --text-faint: #7f6a58;
  --accent: #c2410c;
  --accent-hover: #9a3412;
  --accent-contrast: #ffffff;
  --accent-glow: #f97316;
  --ok: #0b7a44;
  --danger: #dc2626;
  --warn: #b45309;
  --tint-accent: rgba(194, 65, 12, 0.1);
  --tint-ok: rgba(11, 122, 68, 0.12);
  --tint-danger: rgba(220, 38, 38, 0.1);
  --tint-warn: rgba(180, 83, 9, 0.1);
  --tint-muted: rgba(122, 102, 86, 0.1);
  --hover-surface: rgba(194, 65, 12, 0.06);
  --surface-veil: rgba(255, 255, 255, 0.72);
  --backdrop: rgba(43, 29, 20, 0.42);
  --ring: rgba(194, 65, 12, 0.22);
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 18px 40px -20px rgba(120, 72, 32, 0.28);
  --glow: radial-gradient(1200px 600px at 15% -10%, #ffe3cc 0%, transparent 60%);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code", Menlo, monospace;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #14100d;
  --bg-elevated: #1c1713;
  --bg-elevated-2: #261f19;
  --border: #33291f;
  --border-strong: #4a3a2c;
  --text: #f6ece4;
  --text-dim: #b8a695;
  --text-faint: #8a7a6b;
  --accent: #fb923c;
  --accent-hover: #fdba74;
  --accent-contrast: #1a120b;
  --accent-glow: #fbbf24;
  --ok: #34d399;
  --danger: #fb7185;
  --warn: #fbbf24;
  --tint-accent: rgba(251, 146, 60, 0.16);
  --tint-ok: rgba(52, 211, 153, 0.14);
  --tint-danger: rgba(251, 113, 133, 0.14);
  --tint-warn: rgba(251, 191, 36, 0.14);
  --tint-muted: rgba(184, 166, 149, 0.14);
  --hover-surface: rgba(251, 146, 60, 0.1);
  --surface-veil: rgba(20, 16, 13, 0.72);
  --backdrop: rgba(10, 7, 5, 0.68);
  --ring: rgba(251, 146, 60, 0.24);
  --shadow: 0 18px 40px -18px rgba(0, 0, 0, 0.8);
  --glow: radial-gradient(1200px 600px at 15% -10%, #3a2416 0%, transparent 60%);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--glow), var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

h1,
h2 {
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* Boot ----------------------------------------------------------------- */
.boot {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  height: 100vh;
  color: var(--text-dim);
}

.boot__spinner {
  width: 28px;
  height: 28px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Login ---------------------------------------------------------------- */
.login {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
}

.login__card {
  width: 100%;
  max-width: 380px;
  padding: 32px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.login__title {
  font-size: 22px;
  letter-spacing: -0.02em;
}

.login__title span {
  color: var(--accent);
}

.login__subtitle {
  margin: 4px 0 24px;
  color: var(--text-dim);
}

.login__hint {
  margin: 16px 0 0;
  color: var(--text-faint);
  font-size: 12px;
  text-align: center;
}

.field {
  display: block;
  margin-bottom: 14px;
}

.field__label {
  display: block;
  margin-bottom: 6px;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

input,
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--ring);
}

textarea {
  min-height: 84px;
  resize: vertical;
}

.form-error {
  margin: 12px 0 0;
  padding: 10px 12px;
  background: var(--tint-danger);
  border: 1px solid color-mix(in srgb, var(--danger) 35%, transparent);
  border-radius: var(--radius-sm);
  color: var(--danger);
  font-size: 13px;
}

/* Buttons -------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  background: var(--bg-elevated-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}

.btn:hover:not(:disabled) {
  background: var(--hover-surface);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
  font-weight: 600;
}

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

.btn--ghost {
  background: transparent;
}

.btn--danger {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 40%, transparent);
}

.btn--danger:hover:not(:disabled) {
  background: var(--tint-danger);
}

.btn--sm {
  padding: 5px 10px;
  font-size: 12px;
}

.btn--block {
  width: 100%;
  margin-top: 8px;
}

/* Layout --------------------------------------------------------------- */
.app {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 22px 16px;
  background: var(--surface-veil);
  border-right: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 6px;
}

.brand__mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  background: linear-gradient(140deg, var(--accent), var(--accent-glow));
  border-radius: 9px;
  color: var(--accent-contrast);
  font-weight: 800;
  font-size: 12px;
  letter-spacing: 0.02em;
}

.brand__text {
  font-size: 15px;
  letter-spacing: -0.01em;
}

.brand__text strong {
  color: var(--accent);
  font-weight: 600;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav__item {
  padding: 9px 12px;
  background: transparent;
  color: var(--text-dim);
  border: none;
  border-radius: var(--radius-sm);
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.nav__item:hover {
  background: var(--hover-surface);
  color: var(--text);
}

.nav__item.is-active {
  background: var(--tint-accent);
  color: var(--accent);
  font-weight: 600;
}

.sidebar__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: auto;
  padding: 12px 6px 0;
  border-top: 1px solid var(--border);
}

.sidebar__actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.btn--icon {
  padding: 5px 8px;
  font-size: 14px;
  line-height: 1;
}

.login__theme {
  display: flex;
  width: 100%;
  margin-top: 14px;
  color: var(--text-dim);
  font-size: 12px;
}

.sidebar__admin {
  color: var(--text-dim);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.content {
  padding: 28px 32px 64px;
  min-width: 0;
}

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

.page-head h1 {
  font-size: 24px;
}

.page-head__sub {
  margin: 4px 0 0;
  color: var(--text-dim);
}

/* Stats ---------------------------------------------------------------- */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 26px;
}

.stat {
  padding: 16px 18px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.stat__label {
  display: block;
  color: var(--text-dim);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stat__value {
  display: block;
  margin-top: 6px;
  font-size: 28px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.stat--ok .stat__value {
  color: var(--ok);
}

.stat--danger .stat__value {
  color: var(--danger);
}

/* Panels and tables ---------------------------------------------------- */
.panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
}

.panel__head h2 {
  font-size: 15px;
}

.table-wrap {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
}

.panel .table-wrap {
  border: none;
  border-radius: 0;
}

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

.table th {
  padding: 11px 16px;
  background: var(--hover-surface);
  color: var(--text-faint);
  font-size: 11px;
  font-weight: 600;
  text-align: left;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  white-space: nowrap;
}

.table td {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  vertical-align: middle;
}

.table tbody tr:hover td {
  background: var(--hover-surface);
}

.table__actions {
  text-align: right;
}

.table td.table__actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.table__empty {
  padding: 32px 16px !important;
  color: var(--text-faint);
  text-align: center;
}

.table__sub {
  display: block;
  color: var(--text-faint);
  font-size: 12px;
}

.mono {
  font-family: var(--mono);
  font-size: 12px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.toolbar .input {
  max-width: 340px;
}

.input--select {
  max-width: 180px;
}

.toolbar__field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.toolbar__label {
  color: var(--text-faint);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.toolbar__spacer {
  flex: 1 1 auto;
}

.input--date {
  max-width: 160px;
}

.input--search {
  min-width: 200px;
}

/* Pagination ----------------------------------------------------------- */
.pager {
  color: var(--text-faint);
  font-size: 12px;
}

.pager__inner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 12px 2px 0;
}

.pager__summary {
  flex: 1 1 auto;
}

.pager__buttons {
  display: flex;
  align-items: center;
  gap: 4px;
}

.pager__btn {
  min-width: 32px;
  padding: 5px 9px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--bg-elevated);
  color: var(--text-dim);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.12s ease, color 0.12s ease, background 0.12s ease;
}

.pager__btn:hover:not(:disabled):not(.is-current) {
  border-color: var(--accent);
  color: var(--accent);
}

.pager__btn.is-current {
  border-color: var(--accent);
  background: var(--tint-accent);
  color: var(--accent);
}

.pager__btn:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.pager__gap {
  padding: 0 2px;
  color: var(--text-faint);
}

/* Rows ---------------------------------------------------------------- */
/* Inactive products, revoked licenses and other retired records sink to the
   bottom of their table and read as secondary information. */
.row--inactive td {
  opacity: 0.62;
}

.row--inactive:hover td {
  opacity: 0.85;
}

.clamp {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  max-width: 320px;
  color: var(--text-dim);
  font-size: 12px;
  line-height: 1.45;
}

/* License key cell ---------------------------------------------------- */
.keycell {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
}

.keycell__value {
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.keycell__value--shown {
  color: var(--accent);
  font-weight: 600;
}

.badge--used {
  background: var(--tint-ok);
  color: var(--ok);
}

/* Runtimes ------------------------------------------------------------ */
.runtime-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 220px;
  margin: 4px 0 14px;
  overflow-y: auto;
}

.runtime-list__item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elevated-2);
  font-size: 13px;
}

/* Customers table column sizing --------------------------------------- */
.table .col-name {
  width: 30%;
}

.table .col-discord {
  width: 22%;
  white-space: nowrap;
}

.table .col-count {
  width: 90px;
  text-align: center;
}

.table .col-notes {
  width: 38%;
}

.table .col-actions {
  width: 96px;
  white-space: nowrap;
}

.table td.col-count,
.table th.col-count {
  text-align: center;
}

/* Badges --------------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.badge--active {
  background: var(--tint-ok);
  color: var(--ok);
}

.badge--revoked {
  background: var(--tint-danger);
  color: var(--danger);
}

.badge--muted {
  background: var(--tint-muted);
  color: var(--text-dim);
}

.badge--bound {
  background: var(--tint-accent);
  color: var(--accent);
}

/* Modal ---------------------------------------------------------------- */
.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 50;
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: var(--backdrop);
  backdrop-filter: blur(3px);
}

.modal__panel {
  position: relative;
  width: 100%;
  max-width: 460px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

.modal__head h2 {
  font-size: 16px;
}

.modal__close {
  padding: 0;
  width: 28px;
  height: 28px;
  background: transparent;
  color: var(--text-dim);
  border: none;
  border-radius: 6px;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.modal__close:hover {
  background: var(--hover-surface);
  color: var(--text);
}

.modal__body {
  padding: 20px;
}

.modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

/* One-time key reveal -------------------------------------------------- */
.keybox {
  margin: 16px 0 0;
  padding: 14px;
  background: var(--bg);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
}

.keybox__value {
  display: block;
  font-family: var(--mono);
  font-size: 16px;
  letter-spacing: 0.06em;
  word-break: break-all;
  color: var(--accent-hover);
}

.keybox__actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.notice {
  margin: 14px 0 0;
  padding: 10px 12px;
  background: var(--tint-warn);
  border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent);
  border-radius: var(--radius-sm);
  color: var(--warn);
  font-size: 12px;
}

.notice--danger {
  background: var(--tint-danger);
  border-color: color-mix(in srgb, var(--danger) 35%, transparent);
  color: var(--danger);
}

/* Toasts --------------------------------------------------------------- */
.toasts {
  position: fixed;
  right: 20px;
  bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 60;
}

.toast {
  min-width: 220px;
  max-width: 360px;
  padding: 11px 14px;
  background: var(--bg-elevated-2);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  font-size: 13px;
  animation: toast-in 0.18s ease-out;
}

.toast--error {
  border-left-color: var(--danger);
}

.toast--success {
  border-left-color: var(--ok);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

/* Responsive ----------------------------------------------------------- */
@media (max-width: 820px) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .nav {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 4px;
  }

  .sidebar__footer {
    margin-top: 0;
    margin-left: auto;
    border-top: none;
    padding-top: 0;
  }

  .content {
    padding: 20px 16px 48px;
  }

  .page-head {
    flex-direction: column;
    align-items: flex-start;
  }
}
