:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --border: #e4e8ef;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --danger: #dc2626;
  --success: #059669;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, "Segoe UI", "Microsoft JhengHei", "PingFang TC", sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

.topbar {
  position: sticky; top: 0; z-index: 10;
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: 12px 16px; display: flex; align-items: center; gap: 12px;
  box-shadow: var(--shadow);
}
.topbar h1 { font-size: 18px; margin: 0; flex: 1; }
.topbar a { text-decoration: none; color: var(--primary); font-weight: 500; font-size: 14px; }
.topbar .stat { color: var(--muted); font-size: 13px; }
.user-chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--muted);
  padding: 4px 10px; border-radius: 999px; border: 1px solid var(--border);
}
.user-chip .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--success); }

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

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow); }
.card h2 { margin: 0 0 12px; font-size: 16px; }

button, .btn {
  font: inherit; cursor: pointer;
  background: var(--primary); color: white; border: none;
  padding: 10px 16px; border-radius: var(--radius); font-weight: 500;
  transition: background .15s;
}
button:hover, .btn:hover { background: var(--primary-hover); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
button.secondary:hover { background: #f3f4f6; }
button.danger { background: var(--danger); }
button.danger:hover { background: #b91c1c; }
button.small { padding: 6px 12px; font-size: 13px; }

input, textarea, select {
  font: inherit; width: 100%;
  padding: 9px 12px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--surface); color: var(--text);
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }
textarea { resize: vertical; min-height: 80px; font-family: inherit; }

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.grid { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
.grid .full { grid-column: 1 / -1; }
@media (max-width: 480px) { .grid { grid-template-columns: 1fr; } }

.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 0; }
.row.tight { gap: 4px; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; align-items: center; }
.toolbar input { flex: 1; min-width: 180px; }

.address-block { display: flex; gap: 6px; align-items: center; }
.address-block .addr-primary {
  display: inline-flex; gap: 4px; align-items: center;
  font-size: 12px; color: var(--muted); margin: 0;
  flex: 0 0 auto; width: 70px; cursor: pointer;
}
.address-block .addr-primary input { width: auto; padding: 0; }
.address-block .postal-input { flex: 0 0 110px; }
@media (max-width: 480px) {
  .address-block { flex-wrap: wrap; }
  .address-block .addr-primary { width: 60px; }
  .address-block .postal-input { flex: 1 1 90px; }
}

.capture-area {
  border: 2px dashed var(--border); border-radius: var(--radius);
  padding: 32px 16px; text-align: center;
  background: #fafbfd; cursor: pointer; transition: border-color .15s, background .15s;
}
.capture-area:hover { border-color: var(--primary); background: #f0f7ff; }
.capture-area svg { width: 48px; height: 48px; color: var(--muted); margin-bottom: 8px; }
.capture-area p { margin: 4px 0; color: var(--muted); }
.capture-area input { display: none; }

.preview-img {
  width: 100%; max-height: 320px; object-fit: contain;
  background: #000; border-radius: var(--radius); display: block;
}
.preview-pair { display: grid; grid-template-columns: 1fr; gap: 8px; }
@media (min-width: 600px) { .preview-pair { grid-template-columns: 1fr 1fr; } }
.preview-slot { position: relative; }
.preview-label {
  position: absolute; top: 6px; left: 6px;
  background: rgba(0,0,0,.55); color: #fff;
  padding: 2px 8px; border-radius: 999px;
  font-size: 12px; pointer-events: none;
}
.preview-img { cursor: zoom-in; }

.lightbox {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,.92);
  display: none; align-items: center; justify-content: center;
  cursor: zoom-out; padding: 20px;
}
.lightbox.show { display: flex; }
.lightbox img {
  max-width: 100%; max-height: 100%;
  object-fit: contain; box-shadow: 0 4px 24px rgba(0,0,0,.5);
}
.lightbox-close {
  position: absolute; top: 16px; right: 20px;
  color: #fff; font-size: 32px; line-height: 1;
  background: none; border: none; cursor: pointer; padding: 4px 12px;
}
.lightbox-close:hover { color: #ccc; background: none; }

.dup-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px; border: 1px solid var(--border); border-radius: 8px;
  margin-bottom: 8px;
}
.dup-item:hover { background: #f8fafc; }

.status {
  padding: 10px 14px; border-radius: 8px; font-size: 14px;
  display: none; margin-bottom: 12px;
}
.status.show { display: block; }
.status.info { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }
.status.error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.status.success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }

.spinner {
  display: inline-block; width: 16px; height: 16px;
  border: 2px solid currentColor; border-top-color: transparent;
  border-radius: 50%; animation: spin .8s linear infinite;
  vertical-align: -3px; margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.list { display: grid; gap: 12px; }
.list-item {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; display: flex; gap: 12px; box-shadow: var(--shadow);
}
.list-item .thumb {
  width: 64px; height: 64px; border-radius: 8px; background: #f1f5f9;
  flex-shrink: 0; overflow: hidden; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 11px;
}
.list-item .thumb img { width: 100%; height: 100%; object-fit: cover; }
.list-item .info { flex: 1; min-width: 0; }
.list-item .info .name { font-weight: 600; font-size: 15px; }
.list-item .info .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.list-item .info .contact { font-size: 13px; margin-top: 4px; }
.list-item .actions { display: flex; flex-direction: column; gap: 4px; }
.list-item .check { align-self: flex-start; margin-top: 4px; }
.list-item .check input { width: auto; }

.tag {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  background: #e0e7ff; color: #3730a3; font-size: 11px; margin-right: 4px; margin-top: 4px;
}

.empty { text-align: center; color: var(--muted); padding: 48px 16px; }

.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.5); display: none; align-items: center; justify-content: center; z-index: 100; padding: 16px; }
.modal-bg.show { display: flex; }
.modal { background: var(--surface); border-radius: var(--radius); max-width: 560px; width: 100%; max-height: 90vh; overflow-y: auto; padding: 20px; }
.modal h2 { margin-top: 0; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; flex-wrap: wrap; }

.bulk-bar {
  position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--border);
  padding: 12px 16px; margin: 16px -16px -16px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}
.bulk-bar .count { font-weight: 600; }
