:root {
  --primary: #319795;
  --primary-dark: #234e52;
  --accent: #3182ce;
  --bg: #f7fafc;
  --card: #ffffff;
  --text: #1a202c;
  --text-sub: #718096;
  --border: #e2e8f0;
  --danger: #e53e3e;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Noto Sans JP', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.app-container {
  max-width: 500px;
  margin: 0 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-header {
  height: 56px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-title { font-size: 17px; font-weight: 700; }
.count-badge {
  background: #e6fffa;
  color: #234e52;
  font-size: 13px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid #b2f5ea;
}

.icon-btn {
  background: none;
  border: none;
  font-size: 22px;
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  display: flex;
  align-items: center;
}

.nav-tabs {
  display: flex;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  flex: 1;
  padding: 12px 0;
  border: none;
  background: none;
  font-size: 14px;
  font-weight: 500;
  color: var(--text-sub);
  border-bottom: 3px solid transparent;
  cursor: pointer;
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 700;
}

.app-main { flex: 1; padding: 16px; position: relative; }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* Camera View Box */
.camera-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 4/3;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

#video-preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.scan-overlay {
  position: absolute;
  border: 2px solid #38b2ac;
  border-radius: 8px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
  transition: all 0.3s ease;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.scan-area--narrow { width: 85%; height: 25%; }
.scan-area--medium { width: 85%; height: 50%; }
.scan-area--full { width: 92%; height: 85%; }

.scan-overlay.success {
  border-color: #48bb78;
  background: rgba(72, 187, 120, 0.15);
}

.scan-laser {
  height: 2px;
  background: #e53e3e;
  box-shadow: 0 0 8px #e53e3e;
  animation: laser 1.8s infinite ease-in-out;
}

@keyframes laser {
  0% { transform: translateY(0); }
  50% { transform: translateY(50px); }
  100% { transform: translateY(0); }
}

.scan-hint {
  position: absolute;
  bottom: -32px;
  width: 100%;
  text-align: center;
  color: #fff;
  font-size: 12px;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}

.torch-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  border: none;
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 13px;
}

.scan-controls { margin-top: 20px; }

.btn {
  width: 100%;
  padding: 14px;
  border-radius: 10px;
  border: none;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-secondary { background: #edf2f7; color: #2d3748; }
.btn-accent { background: var(--accent); color: #fff; }
.btn-outline-danger { background: #fff5f5; color: var(--danger); border: 1px solid #feb2b2; }

.recent-toast {
  margin-top: 16px;
  background: #c6f6d5;
  color: #22543d;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* List Tab UI */
.panel-box {
  background: #ebf8ff;
  border: 1px solid #bee3f8;
  padding: 16px;
  border-radius: 10px;
  margin-bottom: 16px;
}

.panel-header { font-weight: 700; color: #2b6cb0; font-size: 15px; margin-bottom: 4px; }
.panel-desc { font-size: 12px; color: #4a5568; margin-bottom: 12px; }

.progress-wrap { margin-top: 12px; }
.progress-bar { height: 8px; background: #e2e8f0; border-radius: 4px; overflow: hidden; }
.progress-inner { height: 100%; width: 0%; background: var(--accent); transition: width 0.3s; }
.progress-text { font-size: 12px; text-align: right; color: var(--text-sub); margin-top: 4px; }

.action-tools {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}

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

.list-item {
  background: var(--card);
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.item-main { flex: 1; min-width: 0; }
.item-code { font-family: monospace; font-size: 15px; font-weight: 700; }
.item-meta { font-size: 12px; color: var(--text-sub); display: flex; gap: 8px; margin-top: 2px; }
.item-title { font-size: 13px; font-weight: 700; color: #2d3748; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.badge-type {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 4px;
  background: #edf2f7;
  color: #4a5568;
}

.badge-type.isbn { background: #e6fffa; color: #234e52; }

.delete-item-btn {
  background: none;
  border: none;
  color: #a0aec0;
  font-size: 18px;
  padding: 6px;
  cursor: pointer;
}

/* Settings Tab UI */
.settings-group {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 16px;
}

.settings-group h2 { font-size: 14px; color: var(--text-sub); margin-bottom: 12px; border-bottom: 1px solid #f0f0f0; padding-bottom: 6px; }

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  font-size: 14px;
}

.setting-row select {
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #fff;
  font-size: 14px;
}

input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--primary); }

.scan-overlay.warning {
  border-color: #dd6b20;
  background: rgba(221, 107, 32, 0.2);
}

.recent-toast.success {
  background: #c6f6d5;
  color: #22543d;
}

.recent-toast.warning {
  background: #feebc8;
  color: #744210;
}

/* Data Storage Notice */
.storage-notice {
  background: #f7fafc;
  border: 1px solid #e2e8f0;
  border-left: 4px solid var(--primary);
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 12px;
  color: #4a5568;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  margin-bottom: 12px;
  line-height: 1.4;
}

.storage-notice i {
  font-size: 18px;
  color: var(--primary);
  margin-top: 2px;
  flex-shrink: 0;
}

/* List Table View */
.items-list-container {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.scan-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.scan-table th {
  background: #edf2f7;
  color: #4a5568;
  font-weight: 700;
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}

.scan-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #edf2f7;
  vertical-align: middle;
}

.scan-table tr:last-child td {
  border-bottom: none;
}

.scan-table tr:nth-child(even) {
  background: #fcfcfc;
}

.col-no {
  color: #a0aec0;
  font-weight: 700;
  font-size: 12px;
  text-align: center;
}

.code-val {
  font-family: monospace;
  font-size: 14px;
  font-weight: 700;
  color: #2d3748;
}

.time-val {
  font-size: 11px;
  color: #a0aec0;
  margin-top: 1px;
}

.title-val {
  font-size: 12px;
  font-weight: 700;
  color: #2b6cb0;
  margin-top: 2px;
}
