:root {
  color-scheme: light;
  --background: #ffffff;
  --panel: #ffffff;
  --ink: #131821;
  --muted: #627080;
  --border: #dde3ea;
  --accent: #1769e8;
  --accent-dark: #0e51bd;
  --danger: #ca3446;
  --success: #15815a;
  --warning: #a65f00;
  --radius: 8px;
}

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--background);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", Arial, sans-serif;
}

.admin-layout {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 24px 18px;
  border-right: 1px solid var(--border);
  background: #fbfcfe;
}

.brand-block {
  padding: 4px 6px 18px;
  border-bottom: 1px solid var(--border);
}

.brand-block h1 {
  font-size: 26px;
}

.brand-block span {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.side-nav {
  display: grid;
  gap: 6px;
  margin-top: 18px;
}

.side-nav button {
  width: 100%;
  justify-content: start;
  height: 42px;
  padding: 0 12px;
  border-color: transparent;
  background: transparent;
  color: #334052;
  text-align: left;
}

.side-nav button:hover {
  background: #f2f6fb;
}

.side-nav button.active {
  color: var(--accent);
  border-color: #cfe0ff;
  background: #eef5ff;
}

.sidebar-status {
  display: grid;
  gap: 10px;
  margin-top: auto;
}

.sidebar-status .status,
.sidebar-status .icon-button {
  width: 100%;
}

.admin-main {
  min-width: 0;
  padding: 34px 28px 42px;
}

.shell {
  width: min(1280px, calc(100% - 48px));
  margin: 0 auto;
  padding: 38px 0 42px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 12px;
  margin-bottom: 24px;
}

.topbar h2 {
  margin-bottom: 0;
  font-size: 28px;
}

.topbar-copy {
  max-width: 420px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}

.toast-stack {
  position: fixed;
  top: 18px;
  left: 50%;
  z-index: 100;
  display: grid;
  gap: 10px;
  width: min(520px, calc(100% - 32px));
  pointer-events: none;
  transform: translateX(-50%);
}

.toast {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  gap: 10px;
  align-items: center;
  min-height: 46px;
  padding: 12px 14px;
  border: 1px solid rgba(23, 105, 232, 0.18);
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 18px 42px rgba(19, 24, 33, 0.16);
  color: var(--ink);
  font-size: 14px;
  font-weight: 650;
  pointer-events: auto;
  backdrop-filter: blur(10px);
  animation: toast-in 180ms ease-out;
}

.toast::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
}

.toast.success::before {
  background: var(--success);
}

.toast.error::before {
  background: var(--danger);
}

.toast.warning::before {
  background: var(--warning);
}

.toast button {
  width: 26px;
  height: 26px;
  padding: 0;
  border-color: transparent;
  color: var(--muted);
  background: transparent;
  font-size: 18px;
  line-height: 1;
}

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

.label {
  margin: 0 0 5px;
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: 30px;
  line-height: 1.15;
}

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 18px;
  color: var(--muted);
  font-size: 13px;
  background: var(--panel);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #aeb7c0;
}

.status.online .dot {
  background: var(--success);
}

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

.login-panel {
  width: min(420px, 100%);
  padding: 28px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.login-copy {
  margin: 10px 0 22px;
  color: var(--muted);
  font-size: 14px;
}

.login-panel button {
  width: 100%;
}

.panel {
  margin-bottom: 14px;
  padding: 22px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.overview-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 14px;
}

.overview-card {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #f8fafc;
}

.overview-card span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.overview-card strong {
  display: block;
  color: var(--ink);
  font-size: 30px;
  line-height: 1;
}

.overview-card small {
  margin-top: 9px;
}

.section-heading {
  margin-bottom: 19px;
}

h2 {
  margin: 0 0 5px;
  font-size: 18px;
}

.section-heading p,
.notice {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

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

.field > span {
  display: block;
  margin-bottom: 7px;
  color: #334052;
  font-size: 13px;
  font-weight: 600;
}

input,
select {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: 1px solid #c9d2dd;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-size: 15px;
}

input:focus,
select:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 28%, transparent);
  border-color: var(--accent);
}

.key-row {
  display: flex;
  gap: 8px;
}

.key-row input {
  flex: 1;
}

small {
  display: block;
  margin-top: 7px;
  color: var(--muted);
}

.hidden {
  display: none !important;
}

button {
  height: 42px;
  padding: 0 17px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.actions {
  display: flex;
  gap: 10px;
  padding-top: 3px;
}

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

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

.danger {
  color: var(--danger);
  border-color: #eed3d8;
}

.icon-button {
  color: var(--muted);
  border-color: var(--border);
}

.rules {
  display: grid;
  gap: 10px;
}

.rules div {
  display: grid;
  grid-template-columns: 118px 1fr;
  gap: 14px;
  align-items: baseline;
  padding: 10px 12px;
  border-radius: 6px;
  background: #f7f9fb;
  font-size: 13px;
}

.rules span {
  color: var(--muted);
}

.license-form {
  display: grid;
  grid-template-columns: 180px 150px 1fr auto;
  gap: 12px;
  align-items: end;
}

.license-form .field {
  margin-bottom: 0;
}

.generated-license {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 10px;
  align-items: center;
  margin-top: 16px;
  padding: 12px;
  border: 1px solid #b9d2ff;
  border-radius: 7px;
  background: #f4f8ff;
}

.generated-license span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.generated-license code {
  overflow-wrap: anywhere;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 13px;
  font-weight: 700;
}

.table-wrap {
  margin-top: 16px;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

table {
  width: 100%;
  min-width: 1120px;
  border-collapse: collapse;
  font-size: 12px;
}

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

th {
  color: var(--muted);
  font-weight: 700;
  background: #f8fafc;
}

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

td small {
  margin-top: 4px;
}

.serial-cell {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 280px;
  width: 280px;
}

.serial-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.serial-summary strong,
.serial-summary small {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.serial-summary strong {
  flex: 0 1 auto;
}

.serial-summary small {
  flex: 1 1 auto;
  margin-top: 0;
  color: var(--muted);
}

.serial-cell button {
  flex: 0 0 auto;
  height: 28px;
  padding: 0 10px;
  border-color: var(--border);
  font-size: 12px;
}

.serial-cell button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.pill {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 9px;
  border-radius: 12px;
  font-weight: 700;
}

.pill.active {
  color: #0f6b4c;
  background: #e5f6ef;
}

.pill.disabled {
  color: #8d3440;
  background: #fbecef;
}

.table-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 280px;
}

.table-actions button {
  height: 30px;
  padding: 0 12px;
  border-color: var(--border);
  font-size: 12px;
}

.identity-cell {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 11px;
}

.identity-cell:hover {
  color: var(--accent);
}

.password-form {
  max-width: 520px;
}

.sample-metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.sample-metrics div {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #f8fafc;
}

.sample-metrics span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.sample-metrics strong {
  font-size: 18px;
  font-weight: 800;
}

.sample-table-wrap table {
  min-width: 980px;
}

.test-input {
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 14px;
  margin-bottom: 14px;
}

.upload-area {
  display: grid;
  place-content: center;
  gap: 7px;
  min-height: 190px;
  padding: 18px;
  border: 1px dashed #bbc7d4;
  border-radius: 7px;
  color: var(--muted);
  text-align: center;
  cursor: pointer;
}

.upload-area:hover {
  border-color: var(--accent);
  background: #f5f9ff;
}

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

.upload-title {
  color: var(--accent);
  font-size: 15px;
  font-weight: 700;
}

.upload-detail {
  font-size: 12px;
}

.photo-preview {
  display: grid;
  place-content: center;
  height: 190px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #eef2f5;
  color: var(--muted);
  font-size: 13px;
}

.photo-preview img {
  display: block;
  width: 100%;
  height: 190px;
  object-fit: contain;
}

.photo-preview.empty img {
  display: none;
}

.recognize-actions {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.recognition-state {
  color: var(--muted);
  font-size: 13px;
}

.recognition-state.busy {
  color: var(--accent);
}

.recognition-state.failed {
  color: var(--danger);
}

.recognition-result {
  border-top: 1px solid var(--border);
  padding-top: 18px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 17px;
}

.metrics div {
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

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

.metrics strong {
  font-size: 14px;
}

.road-preview {
  margin-bottom: 14px;
}

.road-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

h3 {
  margin: 0;
  font-size: 15px;
}

.road-heading p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

#road-canvas {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--border);
  background: #fff;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(13, 18, 27, 0.45);
}

.road-modal-panel {
  width: min(1180px, 100%);
  max-height: min(860px, calc(100vh - 48px));
  overflow: auto;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 28px 80px rgba(19, 24, 33, 0.26);
}

.road-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 16px;
  margin-bottom: 16px;
}

.road-modal-header h2 {
  margin-bottom: 4px;
}

.road-modal-header p:last-child {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.road-board-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.road-board {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfcfe;
}

.road-board.wide {
  grid-column: 1 / -1;
}

.road-board h3 {
  margin-bottom: 8px;
}

.road-board canvas {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid #d9e0e7;
  background: #fff;
}

.warning-list {
  display: grid;
  gap: 6px;
  color: #945414;
  font-size: 12px;
}

.warning-list p {
  margin: 0;
  padding: 8px 10px;
  border-radius: 5px;
  background: #fff7eb;
}

.notice {
  min-height: 22px;
  padding: 4px 2px 0;
  font-size: 12px;
}

.notice.success {
  color: var(--success);
}

.notice.error {
  color: var(--danger);
}

@media (max-width: 600px) {
  .admin-layout {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 18px 14px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .brand-block {
    padding-bottom: 12px;
  }

  .side-nav {
    grid-template-columns: repeat(2, 1fr);
  }

  .sidebar-status {
    grid-template-columns: 1fr 1fr;
    margin-top: 14px;
  }

  .admin-main {
    padding: 22px 14px 30px;
  }

  .shell {
    width: calc(100% - 28px);
    padding-top: 22px;
  }

  .topbar {
    align-items: start;
    flex-direction: column;
    gap: 16px;
  }

  .topbar-copy {
    text-align: left;
  }

  .rules div {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .test-input,
  .license-form,
  .metrics,
  .sample-metrics,
  .overview-grid {
    grid-template-columns: 1fr;
  }

  .generated-license {
    grid-template-columns: 1fr;
  }

  .modal-backdrop {
    padding: 10px;
  }

  .road-modal-panel {
    max-height: calc(100vh - 20px);
    padding: 14px;
  }

  .road-modal-header {
    flex-direction: column;
  }

  .road-board-grid {
    grid-template-columns: 1fr;
  }
}
