:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --panel: #ffffff;
  --line: #dfe3e8;
  --line-strong: #cbd2da;
  --text: #1f2937;
  --muted: #667085;
  --primary: #2563eb;
  --primary-soft: #eff6ff;
  --green: #15803d;
  --green-soft: #ecfdf3;
  --amber: #a16207;
  --amber-soft: #fffbeb;
  --red: #b42318;
  --red-soft: #fff1f0;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 860px;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.5 "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
}

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

button,
a { -webkit-tap-highlight-color: transparent; }

.page { min-height: 100vh; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.mono { font-family: Consolas, "SFMono-Regular", monospace; }

.topbar {
  height: 58px;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--panel);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  text-decoration: none;
}

.brand > span {
  width: 34px;
  height: 34px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  background: var(--primary);
  color: #fff;
  font-weight: 800;
}

.brand strong {
  display: block;
  font-size: 15px;
}

.brand small {
  display: block;
  margin-top: 1px;
  color: var(--muted);
  font-size: 11px;
}

.top-actions,
.tools,
.form-actions,
.card-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

button,
.ghost,
.small-button {
  min-height: 34px;
  border: 1px solid var(--primary);
  border-radius: 6px;
  padding: 7px 13px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  font-weight: 600;
  text-decoration: none;
  white-space: nowrap;
}

button:hover { background: #1d4ed8; }
button:disabled { opacity: .55; cursor: not-allowed; }

.ghost,
.small-button {
  border-color: var(--line-strong);
  background: #fff;
  color: #344054;
}

.ghost:hover,
.small-button:hover {
  border-color: #98a2b3;
  background: #f9fafb;
}

.login-card {
  width: 380px;
  margin: 11vh auto 0;
  padding: 28px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.login-copy {
  padding-bottom: 20px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 20px;
}

.login-copy h1 {
  margin: 0 0 6px;
  font-size: 23px;
}

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

.login-card form {
  display: grid;
  gap: 15px;
}

label {
  display: grid;
  gap: 6px;
  color: #344054;
  font-weight: 600;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line-strong);
  background: #fff;
  color: var(--text);
  border-radius: 6px;
  padding: 8px 10px;
  outline: none;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, .12);
}

textarea {
  resize: vertical;
  font-family: Consolas, "SFMono-Regular", monospace;
  font-size: 12px;
}

.error {
  min-height: 20px;
  margin: 0;
  color: var(--red);
}

.app {
  display: grid;
  grid-template-columns: 184px minmax(0, 1fr);
  min-height: calc(100vh - 58px);
}

.sidebar {
  padding: 14px 10px;
  border-right: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar button {
  width: 100%;
  min-height: 38px;
  border: 0;
  border-left: 3px solid transparent;
  border-radius: 4px;
  padding: 8px 11px;
  background: transparent;
  color: #475467;
  text-align: left;
  font-weight: 600;
}

.sidebar button:hover {
  background: #f2f4f7;
  color: var(--text);
}

.sidebar button.active {
  border-left-color: var(--primary);
  background: var(--primary-soft);
  color: #1d4ed8;
}

.side-note {
  margin-top: auto;
  padding: 11px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
}

.workspace {
  min-width: 0;
  padding: 18px;
}

.panel {
  max-width: 1500px;
  margin: 0 auto;
}

.panel-head {
  min-height: 50px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.panel-head h2 {
  margin: 0;
  font-size: 20px;
}

.panel-head p {
  margin: 4px 0 0;
  color: var(--muted);
}

.setup-card,
.card,
.notice {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 7px;
}

.setup-card {
  margin-bottom: 12px;
  padding: 15px;
}

.setup-card h3,
.card h3 {
  margin: 0;
  font-size: 15px;
}

.setup-list {
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
  border-top: 1px solid var(--line);
}

.setup-list li {
  min-height: 62px;
  display: grid;
  grid-template-columns: 30px minmax(260px, 1fr) auto auto;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
}

.setup-list li:last-child { border-bottom: 0; }

.step-number {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: #eef2f6;
  color: #475467;
  font-weight: 700;
}

.setup-list li.done .step-number {
  background: var(--green-soft);
  color: var(--green);
}

.step-copy strong { display: block; }
.step-copy p { margin: 2px 0 0; color: var(--muted); }

.step-status {
  min-width: 82px;
  color: var(--muted);
  text-align: right;
}

.setup-list li.done .step-status {
  color: var(--green);
  font-weight: 600;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.stat {
  padding: 12px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 7px;
}

.stat b {
  display: block;
  margin-top: 3px;
  font-size: 22px;
  line-height: 1.2;
}

.stat small { color: var(--muted); }

.card { padding: 14px; }
.card.no-pad { padding: 0; overflow: hidden; }
.card-head { justify-content: space-between; }
.card-head.pad { padding: 11px 13px; border-bottom: 1px solid var(--line); }

.notice {
  margin-bottom: 12px;
  padding: 9px 12px;
  background: #f9fafb;
  color: #475467;
}

.split {
  display: grid;
  grid-template-columns: minmax(300px, 420px) minmax(520px, 1fr);
  gap: 12px;
}

.form-card {
  align-self: start;
  display: grid;
  gap: 13px;
}

.compact-form {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) 110px 110px minmax(180px, 1.2fr) auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 10px;
}

.compact-form > .muted {
  grid-column: 1 / -1;
  min-height: 18px;
}

.form-actions { flex-wrap: wrap; }

.import-form {
  display: grid;
  gap: 10px;
  margin-bottom: 10px;
}

.file-picker {
  position: relative;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  width: fit-content;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 7px 12px;
  background: #fff;
  color: #344054;
  cursor: pointer;
  font-weight: 600;
  white-space: nowrap;
}

.file-picker:hover { border-color: #98a2b3; background: #f9fafb; }

.file-picker input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.danger-outline {
  border-color: #efb5af;
  color: var(--red);
}

.danger-outline:hover { border-color: #dc8178; background: var(--red-soft); }

.table-wrap {
  width: 100%;
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  white-space: nowrap;
}

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

th {
  background: #f8fafc;
  color: #475467;
  font-size: 12px;
  font-weight: 700;
}

tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fafbfc; }

.sub {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.sub.warn {
  color: #96631a;
}

.empty {
  height: 76px;
  color: var(--muted);
  text-align: center;
}

.badge {
  display: inline-block;
  min-width: 52px;
  padding: 2px 7px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: #f8fafc;
  color: #475467;
  text-align: center;
  font-size: 11px;
  font-weight: 700;
}

.badge.active,
.badge.approved,
.badge.available,
.badge.delivered,
.badge.unused {
  border-color: #a6e3bd;
  background: var(--green-soft);
  color: var(--green);
}

.badge.pending {
  border-color: #f2d58a;
  background: var(--amber-soft);
  color: var(--amber);
}

.badge.rejected,
.badge.revoked,
.badge.suspended,
.badge.disabled {
  border-color: #f5b4ae;
  background: var(--red-soft);
  color: var(--red);
}

.badge.allocated,
.badge.used {
  border-color: #b6cef7;
  background: var(--primary-soft);
  color: #1d4ed8;
}

.badge.expired {
  border-color: #e2c795;
  background: #fdf4e3;
  color: #96631a;
}

.pill {
  padding: 2px 7px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f8fafc;
  color: var(--muted);
  font-size: 11px;
}

.copy {
  min-height: auto;
  border: 0;
  padding: 2px 5px;
  background: transparent;
  color: var(--primary);
  font-weight: 600;
}

.copy:hover { background: var(--primary-soft); }

.tiny {
  min-height: 27px;
  padding: 3px 8px;
  border-color: var(--line-strong);
  background: #fff;
  color: #344054;
  font-size: 11px;
}

.tiny:hover { border-color: #98a2b3; background: #f9fafb; }

.tiny.danger {
  border-color: #efb5af;
  color: var(--red);
}

.tiny.danger:hover { background: var(--red-soft); }

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 30;
  max-width: 420px;
  padding: 10px 14px;
  border: 1px solid #a6e3bd;
  border-radius: 7px;
  background: #fff;
  color: var(--text);
}

.list-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px 12px;
}

.list-head h3 { margin-right: auto; }

.list-filters {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 6px;
}

.list-filters input,
.list-filters select,
.list-filters button {
  min-height: 31px;
  padding: 5px 8px;
  font-size: 12px;
}

.list-filters input[type="search"] { width: 210px; }
.list-filters input[type="date"] { width: 132px; }
.list-filters select { width: auto; min-width: 104px; }
.range-separator { color: var(--muted); font-size: 12px; }
.filter-reset { padding-inline: 10px; }

.import-dialog {
  width: min(680px, calc(100vw - 28px));
  max-height: calc(100vh - 36px);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 0;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 18px 55px rgba(15, 23, 42, .22);
}

.import-dialog::backdrop { background: rgba(15, 23, 42, .46); }

.import-dialog form {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line);
}

.dialog-head h2 { margin: 0; font-size: 18px; }
.import-dialog textarea { min-height: 230px; max-height: 48vh; }
.import-dialog .form-actions { justify-content: flex-end; }
.import-dialog #tokenImportMessage { min-height: 18px; }

@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2, minmax(130px, 1fr)); }
  .split { grid-template-columns: 1fr; }
  .compact-form { grid-template-columns: repeat(2, minmax(150px, 1fr)); }
  .compact-form button { align-self: end; }
  .list-head { align-items: flex-start; }
  .list-head h3 { width: 100%; }
  .list-filters { justify-content: flex-start; }
}

@media (max-width: 900px) {
  body { min-width: 0; }
  .topbar { position: static; }
  .brand small, #dealerIdentity { display: none; }
  .app { display: block; }
  .sidebar {
    position: sticky;
    top: 0;
    z-index: 8;
    flex-direction: row;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .sidebar button {
    width: auto;
    min-width: max-content;
    border-left: 0;
    border-bottom: 3px solid transparent;
  }
  .sidebar button.active { border-left: 0; border-bottom-color: var(--primary); }
  .side-note { display: none; }
  .workspace { padding: 12px; }
  .setup-list li { grid-template-columns: 30px minmax(210px, 1fr) auto; }
  .step-status { display: none; }
}

@media (max-width: 620px) {
  .topbar { padding: 0 12px; }
  .brand > div { display: none; }
  .login-card { width: calc(100% - 24px); margin-top: 28px; padding: 22px; }
  .panel-head { align-items: center; }
  .panel-head p { display: none; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .setup-list li { grid-template-columns: 28px 1fr; }
  .setup-list li .small-button { grid-column: 2; width: fit-content; }
  .compact-form { grid-template-columns: 1fr; }
  .top-actions .ghost:first-of-type { display: none; }
  .list-filters { width: 100%; }
  .list-filters input[type="search"] { width: 100%; }
  .list-filters input[type="date"] { width: calc(50% - 18px); }
  .list-filters select { flex: 1; }
  .import-dialog form { padding: 12px; }
  .dialog-head { align-items: flex-start; }
}

/* Login verification */
.login-card { width: 420px; }
/* Slider puzzle */
.captcha-block { display: grid; gap: 8px; }
.captcha-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 13px; color: var(--muted); }
.captcha-refresh-text {
  padding: 2px 8px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #f8fafc;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}
.captcha-refresh-text:hover { border-color: var(--primary); color: var(--primary); background: #fff; }
.captcha-board {
  position: relative;
  /* aspect-ratio and --board-width come from the widget, using the server geometry.
     Board and piece scale together and the widget converts the reported offset back
     to board coordinates, so a narrow screen no longer breaks verification. */
  width: 100%;
  max-width: var(--board-width, 300px);
  aspect-ratio: 300 / 160;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #f1f5f9;
  user-select: none;
  touch-action: none;
}
.captcha-board > img { display: block; width: 100%; height: 100%; }
.captcha-piece {
  position: absolute;
  left: 0;
  width: 17.333%;
  height: 32.5%;
  cursor: grab;
  filter: drop-shadow(0 1px 3px rgba(15, 23, 42, .45));
  will-change: transform;
}
.captcha-piece:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.captcha-piece.dragging { cursor: grabbing; filter: drop-shadow(0 2px 6px rgba(15, 23, 42, .55)); }
.captcha-track {
  position: relative;
  width: 100%;
  max-width: var(--board-width, 300px);
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #f8fafc;
}
.captcha-track-fill { position: absolute; inset: 0 auto 0 0; width: 0; background: var(--primary-soft); transition: width .05s linear; }
.captcha-hint { position: relative; font-size: 12px; color: var(--muted); }
/* Reserved height so the card does not jump when a message appears. */
.captcha-status { min-height: 16px; margin: 0; font-size: 12px; color: var(--muted); }
.captcha-status.ok { color: #047857; }
.captcha-status.warn { color: #b45309; }
.login-submit { width: 100%; }
@media (max-width: 620px) {
  .login-card { width: min(340px, 100%); }
}
