:root {
  --primary: #1a5276;
  --primary-light: #eaf2f8;
  --accent: #e67e22;
  --bg: #f4f6f7;
  --card: #ffffff;
  --text: #2c3e50;
  --text-sub: #7f8c8d;
  --border: #dce4e8;
  --danger: #c0392b;
  --radius: 10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ---- ヘッダー ---- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  background: var(--primary);
  color: #fff;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
}
.app-header h1 { font-size: 17px; font-weight: 600; flex: 1; text-align: center; }
.header-back {
  position: absolute;
  left: 8px;
  background: none;
  border: none;
  color: #fff;
  font-size: 22px;
  padding: 4px 10px;
  cursor: pointer;
}

/* ---- メイン ---- */
main {
  max-width: 640px;
  margin: 0 auto;
  padding: 12px 12px calc(env(safe-area-inset-bottom) + 84px);
}

/* ---- ボトムナビ ---- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  justify-content: space-around;
  align-items: center;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  height: calc(60px + env(safe-area-inset-bottom));
}
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  text-decoration: none;
  color: var(--text-sub);
  font-size: 11px;
  flex: 1;
  padding: 8px 0;
}
.nav-item.active { color: var(--primary); font-weight: 600; }
.nav-icon { font-size: 20px; }
.nav-scan-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  margin-top: -26px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 30px;
  font-weight: 300;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.25);
}

/* ---- 検索・絞り込み ---- */
.search-box {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 15px;
  background: var(--card);
}
.filter-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 10px 0 4px;
  -webkit-overflow-scrolling: touch;
}
.filter-row select, .filter-row input[type="date"] {
  flex-shrink: 0;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card);
  font-size: 13px;
  color: var(--text);
}
.filter-row select.active-filter { border-color: var(--primary); background: var(--primary-light); }
.list-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 2px;
  font-size: 13px;
  color: var(--text-sub);
}
.list-toolbar button {
  background: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
}

/* ---- カード型リスト ---- */
.contact-card {
  display: block;
  background: var(--card);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
  text-decoration: none;
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}
.contact-card .row1 {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.contact-card .name { font-size: 16px; font-weight: 600; }
.contact-card .last-met { font-size: 12px; color: var(--text-sub); }
.contact-card .company { font-size: 13px; color: var(--text-sub); margin-top: 2px; }
.tag-chips { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 4px; }
.tag-chip {
  font-size: 11px;
  background: var(--primary-light);
  color: var(--primary);
  border-radius: 999px;
  padding: 2px 8px;
}
.empty-note { text-align: center; color: var(--text-sub); padding: 40px 0; }

/* ---- 会社一覧 ---- */
.company-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--card);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 8px;
  text-decoration: none;
  color: var(--text);
}
.company-card .count {
  background: var(--primary);
  color: #fff;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
}

/* ---- フォーム ---- */
.form-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.form-card h2 { font-size: 14px; color: var(--primary); margin-bottom: 12px; }
.field { margin-bottom: 10px; }
.field label {
  display: block;
  font-size: 12px;
  color: var(--text-sub);
  margin-bottom: 3px;
}
.field input, .field select, .field textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  background: #fff;
  color: var(--text);
}
.field textarea { min-height: 64px; resize: vertical; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }

.btn {
  display: block;
  width: 100%;
  padding: 13px;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
}
.btn.primary { background: var(--primary); color: #fff; }
.btn.accent { background: var(--accent); color: #fff; }
.btn.ghost { background: none; border: 1px solid var(--border); color: var(--text); }
.btn.danger-ghost { background: none; border: 1px solid var(--danger); color: var(--danger); }
.btn + .btn { margin-top: 8px; }
.btn:disabled { opacity: 0.5; }

/* ---- 撮影 ---- */
.scan-drop {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--card);
  padding: 36px 16px;
  text-align: center;
  color: var(--text-sub);
  cursor: pointer;
}
.scan-drop .big { font-size: 40px; }
.scan-queue { margin-top: 10px; font-size: 13px; color: var(--text-sub); }
.card-preview {
  width: 100%;
  border-radius: var(--radius);
  margin-bottom: 12px;
  border: 1px solid var(--border);
}

/* ---- タグ入力 ---- */
.tag-select { display: flex; flex-wrap: wrap; gap: 6px; }
.tag-option {
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}
.tag-option.selected {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.tag-add-input { margin-top: 8px; display: flex; gap: 6px; }
.tag-add-input input { flex: 1; }
.tag-add-input button {
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}

/* ---- 詳細 ---- */
.detail-header { text-align: left; }
.detail-header .name { font-size: 20px; font-weight: 700; }
.detail-header .kana { font-size: 12px; color: var(--text-sub); }
.detail-header .company { margin-top: 4px; color: var(--text); }
.detail-fields dt { font-size: 11px; color: var(--text-sub); margin-top: 10px; }
.detail-fields dd { font-size: 15px; word-break: break-all; }
.detail-fields a { color: var(--primary); }

.timeline { list-style: none; }
.timeline li {
  border-left: 2px solid var(--primary-light);
  padding: 0 0 14px 14px;
  margin-left: 6px;
  position: relative;
}
.timeline li::before {
  content: "";
  position: absolute;
  left: -6px;
  top: 4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--primary);
}
.timeline .enc-date { font-weight: 600; font-size: 14px; }
.timeline .enc-context { font-size: 13px; }
.timeline .enc-meta { font-size: 12px; color: var(--text-sub); }
.timeline .enc-memo { font-size: 13px; margin-top: 2px; white-space: pre-wrap; }
.context-badge {
  display: inline-block;
  font-size: 11px;
  border-radius: 4px;
  padding: 1px 6px;
  margin-right: 4px;
  background: var(--primary-light);
  color: var(--primary);
}

/* ---- ダイアログ ---- */
.dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.dialog {
  background: var(--card);
  border-radius: var(--radius);
  padding: 20px;
  width: 100%;
  max-width: 420px;
  max-height: 80vh;
  overflow-y: auto;
}
.dialog h3 { font-size: 16px; margin-bottom: 10px; }
.dialog p { font-size: 13px; color: var(--text-sub); margin-bottom: 14px; }
.dup-info {
  background: var(--primary-light);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 14px;
}

/* ---- トースト ---- */
.toast {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom) + 76px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  border-radius: 999px;
  padding: 10px 20px;
  font-size: 13px;
  z-index: 100;
  opacity: 0;
  transition: opacity 0.25s;
  pointer-events: none;
  white-space: nowrap;
}
.toast.show { opacity: 1; }

.loading { text-align: center; color: var(--text-sub); padding: 30px 0; }

/* ---- 連続スキャンのキュー ---- */
.btn-sm {
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #fff;
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
}
.btn-sm.ghost { background: none; color: var(--text-sub); border-color: var(--border); padding: 5px 9px; }
.scan-done {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #eafaf1;
  border: 1px solid #abebc6;
  color: #1e8449;
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 8px;
}
.queue-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 8px 10px;
  margin-bottom: 6px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}
.queue-thumb {
  width: 52px;
  height: 34px;
  border-radius: 5px;
  background: var(--primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
  font-size: 18px;
}
.queue-thumb img { width: 100%; height: 100%; object-fit: cover; }
.queue-body { flex: 1; min-width: 0; }
.queue-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.queue-status { font-size: 11px; color: var(--text-sub); }
.queue-item.qs-scanning .queue-status { color: var(--accent); }
.queue-item.qs-error .queue-status { color: var(--danger); }
.queue-item.qs-saved { opacity: 0.65; }
.queue-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.saved-check { color: #1e8449; font-weight: 700; padding: 0 6px; }

/* ---- 最近見た人 ---- */
.recent-label { font-size: 12px; color: var(--text-sub); margin: 4px 2px; }
.recent-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 8px;
  margin-bottom: 6px;
  -webkit-overflow-scrolling: touch;
}
.recent-chip {
  flex-shrink: 0;
  width: 130px;
  background: var(--card);
  border-radius: var(--radius);
  padding: 10px 12px;
  text-decoration: none;
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}
.recent-chip .rc-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.recent-chip .rc-co { font-size: 11px; color: var(--text-sub); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---- 詳細のアクション ---- */
.detail-actions { display: flex; gap: 8px; margin-top: 14px; }
.detail-actions .btn { margin-top: 0; }
