:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-light: #eef2ff;
  --danger: #e11d48;
  --danger-light: #fef1f3;
  --warn: #b45309;
  --warn-light: #fffbeb;
  --warn-border: #fde68a;
  --bg: #f4f5f8;
  --surface: #ffffff;
  --border: #e6e7ec;
  --text: #1c1f2b;
  --text-muted: #6b7280;
  --radius-lg: 18px;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
  --shadow-lg: 0 12px 28px rgba(16, 24, 40, 0.12);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Kaku Gothic ProN",
    "Noto Sans JP", Meiryo, sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(24px + var(--safe-bottom));
}

a { color: inherit; text-decoration: none; }

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

/* ---------- App bar ---------- */
.appbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  padding-top: calc(14px + env(safe-area-inset-top, 0px));
  background: rgba(244, 245, 248, 0.88);
  backdrop-filter: saturate(180%) blur(10px);
  -webkit-backdrop-filter: saturate(180%) blur(10px);
  border-bottom: 1px solid var(--border);
  margin-bottom: 18px;
}
.appbar-back {
  display: flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--surface); box-shadow: var(--shadow);
  font-size: 20px; flex-shrink: 0;
}
.appbar h1 {
  flex: 1; min-width: 0;
  font-size: 19px; margin: 0; font-weight: 700; letter-spacing: 0.01em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.appbar .sub { font-size: 13px; color: var(--text-muted); margin-top: 1px; }
.appbar-edit {
  display: flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--surface); box-shadow: var(--shadow);
  font-size: 16px; flex-shrink: 0;
}
.appbar-user {
  display: flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0; overflow: hidden;
  background: var(--primary); box-shadow: var(--shadow);
}
.appbar-user img { width: 100%; height: 100%; object-fit: cover; }
.appbar-user span { color: #fff; font-size: 15px; font-weight: 700; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 12px 18px; border-radius: var(--radius-sm); border: none;
  font-size: 15.5px; font-weight: 600; cursor: pointer;
  text-decoration: none; transition: transform .08s ease, opacity .15s ease, box-shadow .15s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 4px 12px rgba(79, 70, 229, 0.28); }
.btn-primary:disabled { background: #b7b3f5; box-shadow: none; }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-outline { background: var(--surface); color: var(--primary); border: 1.5px solid var(--primary); }
.btn-block { width: 100%; }

.fab {
  position: fixed; right: 20px; bottom: calc(20px + var(--safe-bottom));
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--primary); color: #fff; font-size: 26px; font-weight: 400;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-lg); z-index: 30; line-height: 1;
}
.fab:active { transform: scale(0.95); }

/* ---------- Search ---------- */
.search-row { display: flex; gap: 8px; margin-bottom: 16px; }
.search-row input[type=text], .search-row input[type=search] {
  flex: 1; padding: 12px 16px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); font-size: 16px; box-shadow: var(--shadow); -webkit-appearance: none;
}
.search-row input[type=text]:focus, .search-row input[type=search]:focus { outline: none; border-color: var(--primary); }

/* ---------- Card list (index) ---------- */
.card-list { display: flex; flex-direction: column; gap: 14px; }
.card-item {
  position: relative; display: flex; align-items: center; gap: 14px;
  background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow);
  padding: 16px; padding-right: 66px;
}
.card-item .card-link { display: flex; align-items: center; gap: 14px; flex: 1; min-width: 0; }
.card-thumb {
  width: 112px; height: 68px; border-radius: 10px; object-fit: cover;
  background: var(--primary-light); flex-shrink: 0; border: 1px solid var(--border);
}
.card-thumb.placeholder { display: flex; align-items: center; justify-content: center; font-size: 32px; color: var(--primary); }
.card-body { min-width: 0; flex: 1; }
.card-title { font-weight: 700; font-size: 20px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-id { font-weight: 600; font-size: 14px; color: var(--text-muted); }
.card-sub { font-size: 16px; color: var(--text-muted); margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-meta { font-size: 15px; color: var(--text-muted); margin-top: 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-hint { font-size: 13px; color: var(--text-muted); margin: -6px 0 12px; padding: 0 2px; }
.card-side {
  position: absolute; right: 12px; top: 12px; bottom: 12px;
  display: flex; flex-direction: column; align-items: flex-end; justify-content: space-between; gap: 8px;
}
.card-side .icon-btn:only-child { margin-top: auto; margin-bottom: auto; }
.history-badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  background: var(--primary-light); color: var(--primary); font-size: 13px; font-weight: 700; white-space: nowrap;
}
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: var(--bg); color: var(--text-muted); font-size: 19px; flex-shrink: 0; border: none; cursor: pointer;
  padding: 0; font-family: inherit;
}
/* CSRF対策でリンクからbutton(form属性でform外から送信)に変更した削除操作を、
   元のリンクと同じ見た目にするためのリセット */
.link-btn {
  background: none; border: none; padding: 0; margin: 0; font: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.icon-btn.danger { color: var(--danger); }
.icon-btn:active { transform: scale(0.92); }

.empty { color: var(--text-muted); padding: 60px 16px; text-align: center; font-size: 16px; }
.empty .emoji { font-size: 40px; display: block; margin-bottom: 10px; }

/* ---------- Form ---------- */
.form-section {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 14px;
}
.form-section h2 {
  font-size: 14px; font-weight: 700; color: var(--text-muted); margin: 0 0 12px;
  text-transform: uppercase; letter-spacing: 0.04em;
}
.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field label { display: block; font-size: 14px; color: var(--text-muted); margin-bottom: 5px; font-weight: 600; }
.field input[type=text], .field input[type=email], .field input[type=date], .field textarea {
  width: 100%; padding: 11px 13px; border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  font-size: 16px; background: #fbfbfd; color: var(--text); font-family: inherit;
}
.field input:focus, .field textarea:focus {
  outline: none; border-color: var(--primary); background: #fff;
  box-shadow: 0 0 0 3px var(--primary-light);
}
.field-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 12px; }
textarea { resize: vertical; min-height: 64px; }

/* ---------- Multi-candidate choice chips (address/tel/fax/mobile) ---------- */
.field-choices { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.field-choices:empty { margin-top: 0; }
.chip {
  max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  padding: 6px 12px; border-radius: 999px; border: 1.5px solid var(--border);
  background: var(--surface); color: var(--text-muted); font-size: 13.5px; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.chip.selected { border-color: var(--primary); background: var(--primary-light); color: var(--primary-dark); font-weight: 600; }

/* ---------- Photo capture ---------- */
.photo-preview-wrap { margin-bottom: 10px; }
.preview {
  max-width: 100%; width: 100%; max-height: 220px; object-fit: contain;
  display: block; border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--bg); margin-bottom: 10px;
}
.photo-row { display: flex; gap: 8px; margin-bottom: 4px; }
.photo-row label {
  flex: 1; text-align: center; padding: 13px 8px; font-size: 14px; font-weight: 600;
  border: 1.5px solid var(--primary); border-radius: var(--radius-sm); color: var(--primary);
  cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent;
  transition: background .1s ease;
}
.photo-row label:active { background: var(--primary-light); }
input[type=file] { display: none; }
.photo-status { font-size: 14px; color: var(--primary); margin-top: 8px; display: none; }
.photo-status.active { display: flex; align-items: center; gap: 6px; }
.photo-status.active::before {
  content: ''; width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid var(--primary-light); border-top-color: var(--primary);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.photo-warning { font-size: 13.5px; color: var(--danger); margin-top: 8px; display: none; line-height: 1.5; }
.photo-warning.active { display: block; }

/* ---------- Duplicate person banners ---------- */
.dup-banner {
  display: none; background: var(--warn-light); border: 1px solid var(--warn-border); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 14px; font-size: 14px;
}
.dup-banner.active { display: block; }
.dup-banner .dup-title { font-weight: 700; margin-bottom: 8px; color: var(--warn); }
.dup-candidate {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 8px 0; border-top: 1px solid var(--warn-border);
}
.dup-candidate:first-of-type { border-top: none; }
.dup-candidate .dup-info { line-height: 1.5; }
.dup-candidate .dup-info .sub { color: var(--text-muted); font-size: 13px; }
.dup-candidate button {
  flex-shrink: 0; padding: 7px 12px; font-size: 13px; font-weight: 600; border-radius: var(--radius-sm);
  border: 1.5px solid var(--primary); background: #fff; color: var(--primary); cursor: pointer;
}
.dup-linked {
  display: none; background: var(--primary-light); border: 1px solid var(--primary); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 14px; font-size: 13px; align-items: center;
  justify-content: space-between; gap: 10px; color: var(--primary-dark); font-weight: 600;
}
.dup-linked.active { display: flex; }
.dup-linked button {
  flex-shrink: 0; padding: 7px 12px; font-size: 13px; font-weight: 600; border-radius: var(--radius-sm);
  border: 1.5px solid #b9b4f0; background: #fff; color: var(--text-muted); cursor: pointer;
}

/* ---------- Sticky bottom action bar ---------- */
.bottom-bar {
  position: sticky; bottom: 0; left: 0; right: 0;
  display: flex; gap: 10px; padding: 12px 16px; padding-bottom: calc(12px + var(--safe-bottom));
  background: rgba(244, 245, 248, 0.9); backdrop-filter: saturate(180%) blur(10px);
  -webkit-backdrop-filter: saturate(180%) blur(10px);
  border-top: 1px solid var(--border); margin: 20px -16px 0;
}
.bottom-bar .btn { flex: 1; }

/* ---------- Timeline (history) ---------- */
.timeline { position: relative; padding-left: 22px; }
.timeline::before {
  content: ''; position: absolute; left: 5px; top: 6px; bottom: 6px; width: 2px; background: var(--border);
}
.entry { position: relative; margin-bottom: 16px; }
.entry::before {
  content: ''; position: absolute; left: -22px; top: 5px; width: 12px; height: 12px;
  border-radius: 50%; background: var(--primary); border: 3px solid var(--bg);
}
.entry .date { font-size: 13.5px; color: var(--primary); font-weight: 700; margin-bottom: 6px; }
.entry .card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px; display: flex; gap: 12px;
}
.entry .thumb {
  width: 68px; height: 46px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); flex-shrink: 0;
}
.entry .info { font-size: 15px; line-height: 1.6; flex: 1; min-width: 0; }
.entry .info .company { font-weight: 700; }
.entry .info .meta { color: var(--text-muted); font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry .actions { margin-top: 6px; display: flex; gap: 14px; }
.entry .actions a, .entry .actions .link-btn { font-size: 13.5px; color: var(--primary); font-weight: 600; }
.entry .actions a.danger, .entry .actions .link-btn.danger { color: var(--danger); }

.top-actions { display: flex; gap: 10px; margin-bottom: 18px; }
.top-actions .btn { flex: 1; }

/* ---------- Detail view (view.php) ---------- */
.detail-photos { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 18px; }
.detail-photo-card {
  flex: 0 0 auto; width: 160px; cursor: zoom-in; -webkit-tap-highlight-color: transparent;
}
.detail-photo-frame {
  position: relative; width: 160px; height: 104px; border-radius: var(--radius);
  overflow: hidden; background: var(--surface); box-shadow: var(--shadow); border: 1px solid var(--border);
  transition: transform .12s ease, box-shadow .12s ease;
}
.detail-photo-card:active .detail-photo-frame { transform: scale(0.97); }
.detail-photo-frame img { width: 100%; height: 100%; object-fit: cover; display: block; }
.detail-photo-frame .zoom-hint {
  position: absolute; right: 6px; bottom: 6px; width: 22px; height: 22px; border-radius: 50%;
  background: rgba(0, 0, 0, 0.55); color: #fff; font-size: 12px;
  display: flex; align-items: center; justify-content: center;
}
.detail-photo-label { text-align: center; font-size: 12.5px; color: var(--text-muted); margin-top: 6px; font-weight: 600; }
.detail-header {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px 16px; margin-bottom: 14px; text-align: center;
}
.detail-name { font-size: 23px; font-weight: 700; display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap; }
.detail-kana { font-size: 14px; color: var(--text-muted); margin-top: 2px; }
.detail-company { font-size: 16px; margin-top: 10px; font-weight: 600; }
.detail-position { font-size: 14px; color: var(--text-muted); font-weight: 400; margin-top: 2px; }

.info-list {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden; margin-bottom: 14px;
}
.info-row {
  display: flex; align-items: flex-start; gap: 12px; padding: 13px 16px;
  border-bottom: 1px solid var(--border); font-size: 16px; color: var(--text);
}
.info-row:last-child { border-bottom: none; }
.info-row .icon { font-size: 18px; flex-shrink: 0; line-height: 1.4; }
.info-row .value { flex: 1; min-width: 0; line-height: 1.5; word-break: break-word; }
.info-row .value.memo { white-space: pre-line; }
.info-row .label { display: block; font-size: 12.5px; color: var(--text-muted); margin-top: 2px; font-weight: 600; }
.info-row.static { color: var(--text); }
a.info-row:active { background: var(--primary-light); }

/* ---------- Fullscreen image lightbox ---------- */
.lightbox {
  display: none; position: fixed; inset: 0; z-index: 50;
  background: rgba(0, 0, 0, 0.92); align-items: center; justify-content: center; padding: 24px;
}
.lightbox.active { display: flex; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }

/* ---------- Login page ---------- */
.login-wrap {
  min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px;
}
.login-card {
  width: 100%; max-width: 340px; background: var(--surface); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); padding: 36px 28px; text-align: center;
}
.login-logo { font-size: 44px; margin-bottom: 8px; }
.login-card h1 { font-size: 22px; margin: 0 0 6px; }
.login-desc { font-size: 14.5px; color: var(--text-muted); margin: 0 0 24px; }
.login-error { font-size: 14px; color: var(--danger); background: var(--danger-light); border-radius: var(--radius-sm); padding: 8px 12px; margin-bottom: 16px; }
.btn-google {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; padding: 12px 16px; border-radius: var(--radius-sm); border: 1.5px solid var(--border);
  background: #fff; color: #1f2330; font-size: 15.5px; font-weight: 600; text-decoration: none;
  box-shadow: var(--shadow); transition: transform .08s ease;
}
.btn-google:active { transform: scale(0.98); }
