:root {
  --bg: #0f1419;
  --card: #1a2332;
  --border: #2a3544;
  --text: #e8edf4;
  --text-muted: #8b9cb3;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --success: #22c55e;
  --danger: #ef4444;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.header {
  text-align: center;
  padding: 24px 16px 8px;
}

.header h1 {
  font-size: 1.5rem;
  font-weight: 600;
}

.header p {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 4px;
}

.container {
  max-width: 480px;
  margin: 0 auto;
  padding: 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.preview-area {
  width: 100%;
  aspect-ratio: 1;
  max-height: 280px;
  background: #0d1117;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  margin-bottom: 16px;
  cursor: pointer;
}

.file-input-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.preview-area img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.placeholder {
  text-align: center;
  color: var(--text-muted);
}

.placeholder .icon {
  font-size: 3rem;
  display: block;
  margin-bottom: 8px;
}

.decode-status {
  margin: -8px 0 12px;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.88rem;
}

.decode-status.info {
  background: rgba(59, 130, 246, 0.12);
  color: #93c5fd;
}

.decode-status.success {
  background: rgba(34, 197, 94, 0.12);
  color: #86efac;
}

.decode-status.error {
  background: rgba(239, 68, 68, 0.12);
  color: #fca5a5;
}

.actions {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 12px 20px;
  font-size: 0.95rem;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  flex: 1;
}

label.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  user-select: none;
}

.btn:active {
  transform: scale(0.98);
}

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

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

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

.btn-secondary {
  background: var(--border);
  color: var(--text);
}

.btn-submit {
  width: 100%;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  color: white;
  font-weight: 600;
  margin-top: 12px;
}

.btn-sm {
  padding: 8px 14px;
  font-size: 0.85rem;
  flex: none;
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.manual-input {
  margin-top: 8px;
}

.manual-input label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.manual-input input,
.form-row input {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #0d1117;
  color: var(--text);
  font-size: 1rem;
}

.result-card h2 {
  font-size: 1.1rem;
  margin-bottom: 12px;
}

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

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

.tips-card h3 {
  font-size: 1rem;
  margin-bottom: 8px;
}

.tips-card ul {
  list-style: none;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.tips-card li {
  padding: 4px 0;
  padding-left: 16px;
  position: relative;
}

.tips-card li::before {
  content: "•";
  position: absolute;
  left: 0;
  color: var(--primary);
}

/* Admin */
.admin-page {
  width: 100%;
  min-height: 100vh;
}

.admin-page .header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  width: 100%;
}

.admin-auth {
  display: flex;
  gap: 8px;
  align-items: center;
}

.admin-auth input {
  padding: 8px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #0d1117;
  color: var(--text);
}

.admin-layout {
  display: flex;
  min-height: calc(100vh - 70px);
  width: 100%;
}

.sidebar {
  width: 220px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  padding: 16px;
}

.nav-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 16px;
  margin-bottom: 4px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.nav-item.active,
.nav-item:hover {
  background: var(--card);
  color: var(--text);
}

.admin-content {
  flex: 1;
  min-width: 0;
  width: 100%;
  max-width: none;
  padding: 20px 28px 32px;
}

.panel {
  display: none;
}

.panel.active {
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: calc(100vh - 110px);
}

.panel h2 {
  margin-bottom: 16px;
}

#panel-cards tbody tr,
#panel-logs tbody tr {
  cursor: default;
}

.settings-form {
  width: 100%;
  max-width: 900px;
}

.card.form-card,
.panel .form-card {
  width: 100%;
}

.form-card .form-row {
  margin-bottom: 12px;
}

.form-card label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.hint {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 8px;
}

.hint-success {
  color: #22c55e;
}

.hint-error {
  color: #ef4444;
}

.captcha-block {
  margin: 12px 0;
  padding: 12px;
  background: #0d1117;
  border-radius: 8px;
}

.captcha-block img {
  max-height: 60px;
  margin-bottom: 8px;
}

.table-wrap {
  overflow-x: auto;
  margin-bottom: 16px;
  width: 100%;
  flex: 1;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  table-layout: auto;
}

.admin-page table th,
.admin-page table td {
  white-space: nowrap;
}

.admin-page table td.cell-code,
.admin-page table td.cell-batch,
.admin-page table .log-summary {
  white-space: normal;
  word-break: break-all;
}

.cell-code {
  min-width: 200px;
}

.cell-code code {
  margin-right: 8px;
}

.card-code-full {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.88rem;
  letter-spacing: 0.02em;
}

.cell-batch {
  max-width: 280px;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.82rem;
}

.cell-actions {
  white-space: nowrap;
}

.cell-action-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.btn-warn {
  background: rgba(245, 158, 11, 0.2);
  border-color: rgba(245, 158, 11, 0.45);
  color: #fbbf24;
}

.btn-warn:hover {
  background: rgba(245, 158, 11, 0.32);
}

.btn-copy-card {
  padding: 2px 8px;
  font-size: 0.75rem;
}

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

th {
  color: var(--text-muted);
  font-weight: 500;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover,
tbody tr.selected {
  background: rgba(59, 130, 246, 0.1);
}

.detail-card {
  margin-top: 16px;
}

.detail-card pre {
  background: #0d1117;
  padding: 12px;
  border-radius: 8px;
  overflow: auto;
  font-size: 0.8rem;
  max-height: 200px;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 12px 0;
}

.toolbar {
  margin-bottom: 12px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.panel-header h2 {
  margin: 0;
}

.panel-header .toolbar {
  margin-bottom: 0;
  margin-left: auto;
}

.modal-form-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-form-card .form-row {
  margin: 0;
}

.modal-form-card .captcha-block {
  margin: 0;
}

@media (min-width: 1600px) {
  .admin-content {
    padding: 24px 40px 40px;
  }

  .sidebar {
    width: 240px;
  }
}

@media (max-width: 768px) {
  .admin-layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    display: flex;
    gap: 8px;
    overflow-x: auto;
  }

  .nav-item {
    flex: 1;
    text-align: center;
    white-space: nowrap;
  }

  .modal {
    width: 95%;
    max-height: 90vh;
  }
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2500;
  padding: 16px;
}

.modal-overlay[hidden]:not(.is-open) {
  display: none !important;
}

.modal-overlay.is-open {
  display: flex !important;
}

body.modal-active {
  overflow: hidden;
}

.card-gen-panel {
  margin: 0 0 16px;
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
}

.card-gen-panel h3 {
  margin: 0 0 12px;
  font-size: 1rem;
}

.card-gen-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.card-gen-panel[hidden] {
  display: none !important;
}

.log-ip {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.82rem;
  color: #93c5fd;
}

.modal {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: min(640px, 100%);
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  margin: 0;
  font-size: 1.05rem;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}

.modal-close:hover {
  color: var(--text);
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

/* 详情字段网格 */
.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px 20px;
  margin-bottom: 20px;
}

.detail-item label {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.detail-item span {
  font-size: 0.9rem;
  word-break: break-all;
}

.detail-item.full {
  grid-column: 1 / -1;
}

.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.8rem;
}

.status-badge.active {
  background: rgba(34, 197, 94, 0.15);
  color: #22c55e;
}

.status-badge.error {
  background: rgba(239, 68, 68, 0.15);
  color: #ef4444;
}

.status-badge.online {
  background: rgba(59, 130, 246, 0.15);
  color: #3b82f6;
}

.status-badge.offline {
  background: rgba(148, 163, 184, 0.15);
  color: #94a3b8;
}

.status-badge.warn {
  background: rgba(245, 158, 11, 0.18);
  color: #fbbf24;
}

/* 设备列表 */
.device-section h4 {
  margin: 0 0 12px;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.device-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.device-card {
  background: #0d1117;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.device-info {
  flex: 1;
  min-width: 0;
}

.device-name {
  font-weight: 500;
  font-size: 0.9rem;
}

.device-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.device-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.device-empty {
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 16px;
  text-align: center;
  background: #0d1117;
  border-radius: 8px;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.modal-actions .form-row {
  flex: 1 1 100%;
  display: flex;
  gap: 8px;
  align-items: center;
}

.modal-actions .form-row input {
  flex: 1;
}

/* 支付链接弹窗 */
.pay-link-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.pay-link-item {
  background: #0d1117;
  border-radius: 8px;
  padding: 10px 12px;
}

.pay-link-item .name {
  font-weight: 500;
  margin-bottom: 4px;
}

.pay-link-item a {
  color: var(--primary);
  font-size: 0.82rem;
  word-break: break-all;
}

.pay-link-row {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.pay-link-row:first-of-type {
  border-top: none;
  padding-top: 0;
}

.pay-link-label {
  font-size: 0.82rem;
  font-weight: 500;
  margin-bottom: 4px;
}

.pay-link-url {
  font-size: 0.78rem;
  color: var(--text-muted);
  word-break: break-all;
  line-height: 1.4;
  margin-bottom: 6px;
}

.pay-link-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* 支付二维码弹窗 */
.pay-qr-card {
  text-align: center;
  padding: 8px 0;
}

.pay-qr-title {
  font-weight: 600;
  font-size: 1rem;
  margin-bottom: 6px;
}

.pay-qr-meta {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 8px;
}

.pay-qr-price {
  color: #ff6b6b;
  font-weight: 700;
  font-size: 1.1rem;
}

.pay-qr-original {
  text-decoration: line-through;
  opacity: 0.65;
  margin-left: 4px;
  font-size: 0.85rem;
}

.pay-qr-badge {
  display: inline-block;
  background: rgba(255, 107, 107, 0.15);
  color: #ff8a8a;
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 999px;
  margin-left: 6px;
  vertical-align: middle;
}

.pay-qr-renew {
  color: var(--text-muted);
  font-size: 0.78rem;
  margin: 0 0 12px;
}

.pay-qr-box {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  padding: 12px;
  background: #fff;
  border-radius: 12px;
  margin: 0 auto 12px;
}

.pay-qr-box img,
.pay-qr-box canvas {
  display: block;
}

.pay-qr-hint {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin: 0 0 8px;
}

.pay-qr-order {
  color: var(--text-muted);
  font-size: 0.78rem;
  margin: 0 0 12px;
}

.pay-qr-link-detail {
  text-align: left;
  margin-top: 12px;
  font-size: 0.82rem;
  color: var(--text-muted);
}

.pay-qr-link-detail summary {
  cursor: pointer;
  user-select: none;
  margin-bottom: 8px;
}

/* Toast */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 4000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  min-width: 240px;
  max-width: 360px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  pointer-events: auto;
  animation: toast-in 0.25s ease;
}

.toast.success { border-left: 3px solid #22c55e; }
.toast.error { border-left: 3px solid #ef4444; }
.toast.info { border-left: 3px solid #3b82f6; }

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

.input-sm {
  padding: 6px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 0.85rem;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  min-width: 220px;
}

.row-actions .btn-sm {
  padding: 4px 8px;
  font-size: 0.75rem;
}

.log-summary {
  max-width: 360px;
  font-size: 0.85rem;
  line-height: 1.4;
  word-break: break-word;
}

.log-row {
  cursor: pointer;
}

.log-row:hover td {
  background: rgba(255, 255, 255, 0.03);
}

.log-loading,
.log-empty {
  text-align: center;
  color: var(--muted, #9ca3af);
  padding: 24px 12px !important;
}

.log-time {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.log-action-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.82rem;
  line-height: 1.35;
  border: 1px solid transparent;
  white-space: nowrap;
}

.log-action-default {
  background: rgba(148, 163, 184, 0.12);
  color: #cbd5e1;
  border-color: rgba(148, 163, 184, 0.25);
}

.log-action-platform {
  background: rgba(59, 130, 246, 0.15);
  color: #93c5fd;
  border-color: rgba(59, 130, 246, 0.35);
}

.log-action-scan {
  background: rgba(16, 185, 129, 0.12);
  color: #6ee7b7;
  border-color: rgba(16, 185, 129, 0.3);
}

.log-action-device {
  background: rgba(245, 158, 11, 0.12);
  color: #fcd34d;
  border-color: rgba(245, 158, 11, 0.3);
}

.log-action-card {
  background: rgba(168, 85, 247, 0.12);
  color: #d8b4fe;
  border-color: rgba(168, 85, 247, 0.3);
}

.log-action-admin {
  background: rgba(239, 68, 68, 0.1);
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.25);
}

.log-pagination {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 12px;
  padding: 0 4px;
}

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

.log-detail-pre {
  background: rgba(0, 0, 0, 0.25);
  padding: 10px;
  border-radius: 6px;
  font-size: 0.78rem;
  overflow-x: auto;
  max-height: 240px;
  white-space: pre-wrap;
  word-break: break-all;
}

.login-page-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.admin-login-page {
  background: var(--bg);
}

.login-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 32px;
  width: min(400px, 92vw);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.45);
}

.login-card h2 {
  margin: 0 0 8px;
  font-size: 1.25rem;
}

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

.admin-user-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-right: 8px;
}

.settings-form h3 {
  margin: 20px 0 8px;
  font-size: 1rem;
}

.settings-form h3:first-child {
  margin-top: 0;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 12px 0;
  cursor: pointer;
}

.modal-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.modal-tab {
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.modal-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.modal-form-card textarea {
  width: 100%;
  min-height: 60px;
  padding: 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-family: monospace;
  font-size: 0.82rem;
}

.card-export-area {
  width: 100%;
  min-height: 200px;
  font-family: monospace;
  font-size: 0.85rem;
  margin: 8px 0;
  padding: 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.2);
  color: var(--text);
}

.platform-log-box {
  background: #1a1d23;
  color: #c8cdd6;
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 0.82rem;
  height: min(420px, 55vh);
  overflow-y: auto;
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  line-height: 1.55;
}

.platform-log-line {
  margin: 0 0 4px;
  white-space: pre-wrap;
  word-break: break-word;
}

.platform-log-line .ts {
  color: #6b7280;
  margin-right: 8px;
  user-select: none;
}

.platform-log-line.success {
  color: #6ee7a0;
}

.platform-log-line.error {
  color: #f87171;
}

.platform-log-line.running {
  color: #93c5fd;
}
