:root {
  --bg: #f5f6fa;
  --card: #fff;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --secondary: #64748b;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,.1);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.app {
  max-width: 900px;
  margin: 0 auto;
  padding: 1rem;
}

header {
  text-align: center;
  margin-bottom: 1.5rem;
}
header h1 { margin: 0; font-size: 1.75rem; }
.subtitle { margin: 0.25rem 0 0; color: var(--text-muted); font-size: 0.95rem; }

.notice {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.notice-warning { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }
.notice code { background: rgba(0,0,0,.08); padding: 0.15rem 0.4rem; border-radius: 4px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}
.card h2 { margin: 0 0 1rem; font-size: 1.1rem; }

.form-row {
  margin-bottom: 0.75rem;
}
.form-row label { display: block; margin-bottom: 0.25rem; font-weight: 500; font-size: 0.9rem; }
.form-row input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
}
.form-row input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}
.required { color: var(--danger); }
.hint { font-size: 0.8rem; color: var(--text-muted); display: block; margin-top: 0.25rem; }
.form-row-checkbox label { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; }
.form-row-checkbox input[type="checkbox"] { width: auto; }

.btn {
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--secondary); color: #fff; }
.btn-secondary:hover { opacity: 0.9; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-sm { padding: 0.35rem 0.6rem; font-size: 0.85rem; }
.scan-hint { font-size: 0.85rem; color: var(--text-muted); margin: 0.5rem 0 0; }
.actions { display: flex; gap: 0.5rem; margin-top: 1rem; }

.scanner-wrap {
  margin: 1rem 0;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  max-width: 100%;
}
#scanner {
  display: block;
  width: 100%;
  max-height: 320px;
  object-fit: cover;
}
.hidden { display: none !important; }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.5);
}
.modal-content {
  position: relative;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 1.5rem;
  width: 100%;
  max-width: 360px;
}
.modal-content h3 { margin: 0 0 0.75rem; }
.barcode-display { margin-bottom: 1rem; }
.modal-actions { display: flex; gap: 0.5rem; margin-top: 1rem; }

/* Record list by FileName */
.file-group {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.75rem;
  overflow: hidden;
}
.file-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  background: #f8fafc;
  cursor: pointer;
  user-select: none;
}
.file-header:hover { background: #f1f5f9; }
.file-name { font-weight: 600; }
.file-count { color: var(--text-muted); font-size: 0.9rem; }
.file-latest-time { color: var(--text-muted); font-size: 0.85rem; white-space: nowrap; }
.file-actions { display: flex; gap: 0.35rem; }
.file-actions .btn { flex-shrink: 0; }
.file-body {
  border-top: 1px solid var(--border);
  overflow: hidden;
}
.file-body.collapsed { display: none; }

.records-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.records-table th,
.records-table td { padding: 0.5rem 0.75rem; text-align: left; border-bottom: 1px solid var(--border); }
.records-table th { background: #f8fafc; font-weight: 500; }
.records-table input { width: 100%; padding: 0.35rem 0.5rem; border: 1px solid var(--border); border-radius: 4px; }
.record-actions { display: flex; gap: 0.25rem; }

.empty-state { color: var(--text-muted); padding: 1.5rem; text-align: center; }
.error-msg { color: var(--danger); font-size: 0.9rem; margin-top: 0.25rem; }

.url-check {
  margin-top: 1.5rem;
  padding: 0.75rem 1rem;
  background: #f8fafc;
  border-radius: var(--radius);
  font-size: 0.85rem;
  word-break: break-all;
}
.url-check .url-label { color: var(--text-muted); margin-right: 0.35rem; }
.url-check #currentUrl { color: var(--primary); }
.url-check .url-protocol {
  display: inline-block;
  margin-left: 0.5rem;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-size: 0.8rem;
}
.url-check .url-protocol.https { background: #d1fae5; color: #065f46; }
.url-check .url-protocol.http { background: #fee2e2; color: #991b1b; }

@media (max-width: 640px) {
  .records-table { font-size: 0.8rem; }
  .records-table th:nth-child(4), .records-table td:nth-child(4) { display: none; }
  .file-header { flex-direction: column; align-items: flex-start; }
  .file-latest-time { display: block; margin-top: 0.25rem; }
}
