:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #172033;
  --muted: #667085;
  --border: #dbe1e8;
  --primary: #1668dc;
  --primary-hover: #0f56bb;
  --match: #e11d48;
  --match-bg: rgba(225, 29, 72, 0.14);
  --normal: #10b981;
  --unknown: #f59e0b;
  --danger: #be123c;
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans JP", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .5; }
.hidden { display: none !important; }

.app-shell {
  width: min(100%, 1080px);
  margin: 0 auto;
  padding: 20px 18px 32px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}
.eyebrow { margin: 0 0 2px; color: var(--muted); font-size: 12px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
h1 { margin: 0; font-size: clamp(24px, 4vw, 34px); line-height: 1.25; }
h2 { margin: 0; font-size: 20px; }
h3 { margin: 0 0 14px; font-size: 17px; }
p { line-height: 1.7; }
.status-pill, .count-badge {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 6px 10px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}
.status-pill.ok { color: #067647; border-color: #a6f4c5; background: #ecfdf3; }
.status-pill.error { color: #b42318; border-color: #fecdca; background: #fef3f2; }

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 5px;
  margin-bottom: 16px;
  background: #e9edf2;
  border-radius: 12px;
}
.tab-button {
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 10px 14px;
  border-radius: 9px;
  font-weight: 700;
}
.tab-button.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(16,24,40,.08); }

.panel { display: none; }
.panel.active { display: block; }
.search-row, .list-toolbar, .admin-toolbar, .camera-controls, .section-heading-row, .button-row {
  display: flex;
  align-items: end;
  gap: 10px;
}
.admin-toolbar, .section-heading-row { align-items: center; justify-content: space-between; }
.admin-toolbar { margin-bottom: 14px; }
.admin-toolbar p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { color: #344054; font-size: 13px; font-weight: 700; }
.field.grow { flex: 1; }
.field.full { grid-column: 1 / -1; }
input, textarea {
  width: 100%;
  border: 1px solid #cfd6df;
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  padding: 11px 12px;
  outline: none;
}
input:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(22,104,220,.12); }
textarea { resize: vertical; }

.primary-button, .secondary-button, .danger-button {
  border-radius: 10px;
  padding: 10px 15px;
  font-weight: 700;
  border: 1px solid transparent;
  min-height: 43px;
}
.primary-button { background: var(--primary); color: white; }
.primary-button:hover:not(:disabled) { background: var(--primary-hover); }
.secondary-button { background: var(--surface); border-color: #cfd6df; color: #344054; }
.secondary-button:hover:not(:disabled) { background: #f8fafc; }
.danger-button { background: #fff1f2; border-color: #fecdd3; color: var(--danger); }
.compact { white-space: nowrap; }

.finder-summary { min-height: 28px; margin: 8px 0; color: var(--muted); font-size: 13px; }
.camera-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  border-radius: var(--radius);
  background: #111827;
  border: 1px solid #222b3a;
}
#cameraVideo, #overlayCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
#cameraVideo { object-fit: contain; background: #000; }
#overlayCanvas { pointer-events: none; }
.camera-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  color: #e5e7eb;
  text-align: center;
  background: radial-gradient(circle at 50% 35%, #273449 0, #111827 65%);
}
.camera-placeholder p { max-width: 520px; margin: 0; font-size: 14px; }
.camera-icon { font-size: 44px; line-height: 1; }
.camera-message {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  padding: 9px 12px;
  border-radius: 9px;
  background: rgba(17,24,39,.84);
  color: #fff;
  font-size: 13px;
  backdrop-filter: blur(6px);
}
.camera-controls { align-items: center; margin-top: 10px; flex-wrap: wrap; }
.scanner-status { color: var(--muted); font-size: 12px; margin-left: auto; }

.seen-section { margin-top: 22px; }
.section-heading-row { margin-bottom: 10px; }
.seen-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 9px; }
.seen-item {
  border: 1px solid var(--border);
  border-left: 4px solid var(--normal);
  background: var(--surface);
  border-radius: 10px;
  padding: 10px 12px;
}
.seen-item.match { border-left-color: var(--match); background: #fff7f8; }
.seen-item.unknown { border-left-color: var(--unknown); }
.seen-item-title { font-weight: 700; }
.seen-item-meta { color: var(--muted); font-size: 12px; margin-top: 3px; word-break: break-all; }
.empty-state { color: var(--muted); font-size: 14px; padding: 16px 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
}
.login-card { max-width: 520px; margin: 10px auto; }
.login-card p { color: var(--muted); font-size: 13px; }
.login-card .button-row { margin-top: 12px; }
.editor-card { margin-bottom: 16px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.editor-card .button-row { margin-top: 14px; }
.form-message { min-height: 20px; margin: 8px 0 0; color: var(--muted); font-size: 13px; }
.form-message.error { color: #b42318; }
.form-message.success { color: #067647; }
.list-toolbar { margin: 16px 0 10px; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.item-table { width: 100%; border-collapse: collapse; min-width: 650px; }
.item-table th, .item-table td { padding: 11px 12px; border-bottom: 1px solid #eef1f4; text-align: left; vertical-align: middle; }
.item-table th { color: var(--muted); font-size: 12px; background: var(--surface-2); }
.item-table td { font-size: 13px; }
.item-table tr:last-child td { border-bottom: 0; }
.table-actions { display: flex; gap: 6px; }
.table-actions button { min-height: auto; padding: 6px 9px; font-size: 12px; }

.footer-note { margin-top: 24px; text-align: center; color: var(--muted); font-size: 11px; }

@media (max-width: 640px) {
  .app-shell { padding: 14px 12px 28px; }
  .topbar { align-items: flex-start; }
  .status-pill { max-width: 46%; white-space: normal; text-align: center; justify-content: center; }
  .search-row, .list-toolbar { align-items: stretch; }
  .search-row .compact, .list-toolbar .compact { align-self: end; }
  .form-grid { grid-template-columns: 1fr; }
  .field.full { grid-column: auto; }
  .camera-stage { border-radius: 11px; }
  .scanner-status { width: 100%; margin-left: 0; }
  .admin-toolbar { align-items: flex-start; }
}
