/* ========== Reset & Base ========== */
, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: #f0f4f8;
  color: #1e293b;
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
}
a { color: inherit; text-decoration: none; }
button { cursor: pointer; border: none; background: none; font-family: inherit; font-size: inherit; }
input, textarea, select { font-family: inherit; font-size: inherit; }

/* ========== App Shell ========== */
#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  background: #f0f4f8;
  position: relative;
}

/* ========== Header ========== */
#app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%);
  color: #fff;
  min-height: 56px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
#header-title {
  flex: 1;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.5px;
}
.header-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  color: #fff;
  transition: background 0.2s;
}
.header-btn:active { background: rgba(255,255,255,0.2); }

/* ========== Views ========== */
.view { display: none; padding: 0 0 24px; }
.view.active { display: block; }
.view-header { padding: 16px 16px 12px; }
.view-subtitle { font-size: 14px; color: #64748b; }

/* ========== Collection Grid (Home) ========== */
.collection-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 0 16px;
}
.collection-card {
  background: #fff;
  border-radius: 12px;
  padding: 20px 16px;
  text-align: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  transition: transform 0.15s, box-shadow 0.15s;
  cursor: pointer;
  border: 2px solid transparent;
}
.collection-card:active {
  transform: scale(0.97);
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}
.collection-card .icon {
  font-size: 32px;
  margin-bottom: 8px;
}
.collection-card .name {
  font-size: 15px;
  font-weight: 600;
  color: #1e293b;
}
.collection-card .count {
  font-size: 12px;
  color: #94a3b8;
  margin-top: 4px;
}
.collection-card .status-dots {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-top: 10px;
}
.collection-card .status-dots span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}
.dot-normal { background: #22c55e; }
.dot-repair { background: #ef4444; }
.dot-outgoing { background: #f59e0b; }

/* ========== Status Summary ========== */
.status-summary {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.status-summary .badge {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 20px;
  font-weight: 500;
}
.badge-normal { background: #dcfce7; color: #166534; }
.badge-repair { background: #fee2e2; color: #991b1b; }
.badge-outgoing { background: #fef3c7; color: #92400e; }

/* ========== Device List ========== */
.device-list { padding: 0 16px; display: flex; flex-direction: column; gap: 10px; }
.device-item {
  display: flex;
  align-items: center;
  gap: 14px;
  background: #fff;
  border-radius: 10px;
  padding: 14px 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  cursor: pointer;
  transition: transform 0.15s;
  border-left: 4px solid #e2e8f0;
}
.device-item:active { transform: scale(0.98); }
.device-item.status-normal { border-left-color: #22c55e; }
.device-item.status-repair { border-left-color: #ef4444; }
.device-item.status-outgoing { border-left-color: #f59e0b; }
.device-item .status-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
}
.device-item.status-normal .status-icon { background: #dcfce7; color: #22c55e; }
.device-item.status-repair .status-icon { background: #fee2e2; color: #ef4444; }
.device-item.status-outgoing .status-icon { background: #fef3c7; color: #f59e0b; }
.device-item .info { flex: 1; min-width: 0; }
.device-item .info .name { font-size: 15px; font-weight: 600; color: #1e293b; }
.device-item .info .meta { font-size: 12px; color: #94a3b8; margin-top: 2px; }
.device-item .status-label {
  font-size: 12px;
  font-weight: 500;
  padding: 4px 8px;
  border-radius: 6px;
  white-space: nowrap;
}
.device-item.status-normal .status-label { background: #dcfce7; color: #166534; }
.device-item.status-repair .status-label { background: #fee2e2; color: #991b1b; }
.device-item.status-outgoing .status-label { background: #fef3c7; color: #92400e; }

/* ========== Device Detail ========== */
.device-detail { padding: 0 16px; }

/* Info Card */
.detail-info-card {
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  margin-bottom: 16px;
}
.detail-info-card .device-name {
  font-size: 20px;
  font-weight: 700;
  color: #0f172a;
  margin-bottom: 4px;
}
.detail-info-card .device-model {
  font-size: 14px;
  color: #64748b;
  margin-bottom: 12px;
}
.detail-info-card .status-badge {
  display: inline-block;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 20px;
  margin-bottom: 12px;
}
.status-badge-normal { background: #dcfce7; color: #166534; }
.status-badge-repair { background: #fee2e2; color: #991b1b; }
.status-badge-outgoing { background: #fef3c7; color: #92400e; }

.detail-info-card .meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid #f1f5f9;
}
.detail-info-card .meta-item label {
  font-size: 11px;
  color: #94a3b8;
  display: block;
}
.detail-info-card .meta-item span {
  font-size: 14px;
  color: #334155;
  font-weight: 500;
}

/* Action Buttons */
.detail-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}
.action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 18px 12px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 14px;
  transition: transform 0.15s, box-shadow 0.15s;
  border: 2px solid transparent;
}
.action-btn:active { transform: scale(0.96); }
.action-btn .btn-icon { font-size: 24px; }
.action-btn .btn-label { font-size: 13px; }

.action-btn.btn-check {
  background: #dcfce7;
  color: #166534;
  border-color: #bbf7d0;
}
.action-btn.btn-check:active { background: #bbf7d0; }

.action-btn.btn-repair {
  background: #fee2e2;
  color: #991b1b;
  border-color: #fecaca;
}
.action-btn.btn-repair:active { background: #fecaca; }

.action-btn.btn-outgoing {
  background: #fef3c7;
  color: #92400e;
  border-color: #fde68a;
}
.action-btn.btn-outgoing:active { background: #fde68a; }

.action-btn.btn-edit {
  background: #e0e7ff;
  color: #3730a3;
  border-color: #c7d2fe;
}
.action-btn.btn-edit:active { background: #c7d2fe; }

.action-btn.btn-return {
  background: #e0f2fe;
  color: #075985;
  border-color: #bae6fd;
}
.action-btn.btn-return:active { background: #bae6fd; }

.action-btn.btn-scrap {
  background: #f1f5f9;
  color: #475569;
  border-color: #e2e8f0;
}
.action-btn.btn-scrap:active { background: #e2e8f0; }

/* Extra buttons row (3-column) */
.detail-actions-extra {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}
.detail-actions-extra .action-btn { padding: 14px 8px; }

/* QR Code Section */
.detail-qr-section {
  background: #fff;
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  margin-bottom: 16px;
  text-align: center;
}
.detail-qr-section .qr-preview {
  display: inline-block;
  width: 120px;
  height: 120px;
  background: #fff;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid #e2e8f0;
}
.detail-qr-section .qr-preview canvas, .detail-qr-section .qr-preview img {
  width: 100% !important;
  height: 100% !important;
}
.detail-qr-section .qr-label {
  font-size: 12px;
  color: #94a3b8;
  margin-top: 8px;
}
.detail-qr-section .btn-show-qr {
  margin-top: 8px;
  padding: 8px 20px;
  background: #2563eb;
  color: #fff;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.2s;
}
.detail-qr-section .btn-show-qr:active { background: #1d4ed8; }

/* Operation Records */
.detail-records {
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  margin-bottom: 16px;
  overflow: hidden;
}
.detail-records .records-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid #f1f5f9;
}
.detail-records .records-header h3 {
  font-size: 15px;
  font-weight: 600;
  color: #0f172a;
}
.detail-records .records-header .count {
  font-size: 12px;
  color: #94a3b8;
  background: #f1f5f9;
  padding: 2px 8px;
  border-radius: 12px;
}
.records-list { max-height: 400px; overflow-y: auto; }
.record-item {
  display: flex;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid #f8fafc;
}
.record-item:last-child { border-bottom: none; }
.record-item .record-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}
.record-item .record-icon.type-check { background: #dcfce7; color: #22c55e; }
.record-item .record-icon.type-repair { background: #fee2e2; color: #ef4444; }
.record-item .record-icon.type-outgoing { background: #fef3c7; color: #f59e0b; }
.record-item .record-icon.type-return { background: #e0f2fe; color: #0ea5e9; }
.record-item .record-icon.type-edit { background: #e0e7ff; color: #6366f1; }
.record-item .record-icon.type-scrap { background: #f1f5f9; color: #64748b; }
.record-item .record-body { flex: 1; min-width: 0; }
.record-item .record-body .record-detail { font-size: 14px; color: #334155; }
.record-item .record-body .record-meta {
  display: flex;
  gap: 8px;
  font-size: 12px;
  color: #94a3b8;
  margin-top: 2px;
}
.record-empty {
  text-align: center;
  padding: 32px 16px;
  color: #94a3b8;
  font-size: 14px;
}

/* ========== Edit Form ========== */
.edit-form { padding: 0 16px; }
.edit-form .form-card {
  background: #fff;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.form-group { margin-bottom: 16px; }
.form-group:last-child { margin-bottom: 0; }
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: #475569;
  margin-bottom: 6px;
}
.form-group input, .form-group textarea, .form-group select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  font-size: 15px;
  color: #1e293b;
  background: #fff;
  transition: border-color 0.2s;
}
.form-group input:focus, .form-group textarea:focus, .form-group select:focus {
  outline: none;
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.form-group textarea { resize: vertical; min-height: 60px; }
.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}
.form-actions button {
  flex: 1;
  padding: 12px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 15px;
  transition: opacity 0.2s;
}
.form-actions .btn-save { background: #2563eb; color: #fff; }
.form-actions .btn-save:active { opacity: 0.85; }
.form-actions .btn-cancel { background: #f1f5f9; color: #475569; }
.form-actions .btn-cancel:active { opacity: 0.85; }

/* ========== Modal ========== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15,23,42,0.5);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  backdrop-filter: blur(2px);
}
.modal-content {
  background: #fff;
  border-radius: 16px;
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.modal-sm { max-width: 360px; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #f1f5f9;
}
.modal-header h2 { font-size: 17px; font-weight: 600; }
.modal-close {
  font-size: 24px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #94a3b8;
  border-radius: 6px;
}
.modal-close:active { background: #f1f5f9; }
.modal-body { padding: 20px; }

/* QR Scanner */
#qr-reader { width: 100%; min-height: 240px; }
#qr-reader video { border-radius: 8px; }
#qr-reader__dashboard_section_csr button {
  background: #2563eb !important;
  color: #fff !important;
  border-radius: 8px !important;
  padding: 8px 20px !important;
  font-size: 14px !important;
  border: none !important;
  cursor: pointer !important;
}
#qr-reader__dashboard_section_csr span { display: none !important; }
.scan-hint { text-align: center; font-size: 13px; color: #94a3b8; margin-top: 12px; }
.scan-error { text-align: center; font-size: 13px; color: #ef4444; margin-top: 8px; padding: 8px; background: #fee2e2; border-radius: 8px; }

/* ========== Toast ========== */
.toast {
  position: fixed;
  top: 72px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 24px;
  border-radius: 10px;
  font-weight: 500;
  font-size: 14px;
  z-index: 2000;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  animation: toast-in 0.25s ease-out;
  max-width: 90%;
  text-align: center;
}
.toast-success { background: #22c55e; color: #fff; }
.toast-error { background: #ef4444; color: #fff; }
.toast-info { background: #2563eb; color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateX(-50%) translateY(-12px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }

/* ========== Responsive ========== */
@media (min-width: 768px) {
  #app { max-width: 640px; border-left: 1px solid #e2e8f0; border-right: 1px solid #e2e8f0; min-height: 100vh; box-shadow: 0 0 20px rgba(0,0,0,0.05); }
  .collection-grid { grid-template-columns: 1fr 1fr 1fr; }
}
@media (max-width: 360px) {
  .collection-grid { grid-template-columns: 1fr; }
  .detail-actions { grid-template-columns: 1fr; }
  .detail-actions-extra { grid-template-columns: 1fr 1fr; }
}

/* ========== Scrollbar ========== */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }

/* ========== Export Button ========== */
.btn-export-records {
  padding: 6px 14px;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
  line-height: 1.4;
}
.btn-export-records:active { background: #1d4ed8; }
.records-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}


/* ========== Home Header ========== */
.view-header-home {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.view-header-home .view-subtitle {
  flex: 1;
}
.view-header-home .btn-batch-export {
  margin-top: 0;
  flex-shrink: 0;
}

/* ========== Batch Export ========== */
.batch-checkbox-list { max-height: 280px; overflow-y: auto; }
.batch-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  margin-bottom: 4px;
  background: #f8fafc;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
  border: 1px solid #e2e8f0;
  user-select: none;
}
.batch-checkbox:hover { background: #f1f5f9; }
.batch-checkbox input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: #2563eb;
  cursor: pointer;
}
.batch-checkbox-icon { font-size: 20px; }
.batch-checkbox-name { flex: 1; font-size: 14px; font-weight: 500; color: #1e293b; }
.batch-checkbox-count { font-size: 12px; color: #94a3b8; background: #e2e8f0; padding: 2px 8px; border-radius: 10px; }
.btn-batch-export {
  margin-top: 8px;
  padding: 8px 16px;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-batch-export:active { background: #1d4ed8; }

/* ========== Utilities ========== */
.mt-8 { margin-top: 8px; }
.text-center { text-align: center; }
