:root {
  --bg: #f5f5f0;
  --surface: #ffffff;
  --primary: #1a1a2e;
  --accent: #c9a84c;
  --text: #2d2d2d;
  --muted: #777;
  --border: #e0e0d8;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
}

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

body {
  font-family: 'Hiragino Sans', 'Noto Sans JP', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

header {
  background: var(--primary);
  color: white;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

header h1 { font-size: 1.1rem; font-weight: 600; letter-spacing: 0.05em; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  font-family: inherit;
  transition: opacity 0.15s;
}
.btn:hover { opacity: 0.85; }
.btn-primary { background: var(--accent); color: var(--primary); font-weight: 600; }
.btn-ghost { background: transparent; color: white; border: 1px solid rgba(255,255,255,0.3); }
.btn-danger { background: #e74c3c; color: white; }
.btn-sm { padding: 5px 10px; font-size: 0.8rem; }

main { padding: 20px; max-width: 900px; margin: 0 auto; }

.search-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}

.toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.toolbar-btn {
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--border);
  font-size: 0.8rem;
}

.search-bar input {
  flex: 1;
  padding: 10px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  background: var(--surface);
}

.search-bar input:focus { outline: 2px solid var(--accent); border-color: transparent; }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
  border: 1px solid var(--border);
  position: relative;
}

.card:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,0,0,0.12); }

.card-accent { width: 3px; height: 40px; background: var(--accent); position: absolute; left: 0; top: 18px; border-radius: 0 2px 2px 0; }

.card-company { font-size: 0.75rem; color: var(--muted); margin-bottom: 2px; padding-left: 12px; }
.card-name { font-size: 1.05rem; font-weight: 700; padding-left: 12px; margin-bottom: 2px; }
.card-furigana { font-size: 0.7rem; color: var(--muted); padding-left: 12px; margin-bottom: 8px; }
.card-title { font-size: 0.8rem; color: var(--muted); padding-left: 12px; margin-bottom: 10px; }
.card-contact { font-size: 0.8rem; color: var(--text); display: flex; flex-direction: column; gap: 3px; }
.card-contact span::before { margin-right: 5px; }

.card-photo-thumb {
  width: 100%;
  height: 100px;
  object-fit: cover;
  object-position: top;
  border-radius: 8px;
  margin-bottom: 12px;
}

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 28px;
  position: relative;
}

.modal h2 { font-size: 1.1rem; margin-bottom: 20px; color: var(--primary); }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group.full { grid-column: 1 / -1; }

label { font-size: 0.8rem; color: var(--muted); font-weight: 500; }

input[type="text"],
input[type="email"],
input[type="url"],
input[type="date"],
textarea {
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: inherit;
  background: var(--bg);
  width: 100%;
}

input:focus, textarea:focus { outline: 2px solid var(--accent); border-color: transparent; background: white; }
input[readonly] { background: var(--bg); color: #888; cursor: default; }

textarea { resize: vertical; min-height: 70px; }

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.photo-section {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.photo-preview {
  width: 100%;
  max-height: 200px;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid var(--border);
  display: none;
}

.photo-buttons { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.ocr-provider-select {
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.8rem;
  font-family: inherit;
  background: var(--bg);
  cursor: pointer;
}

.ocr-status {
  font-size: 0.8rem;
  color: var(--accent);
  min-height: 1.2em;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}

.empty-state h2 { font-size: 1.1rem; margin-bottom: 8px; }

.toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--primary);
  color: white;
  padding: 12px 16px 12px 20px;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 500;
  z-index: 999;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
  max-width: 90vw;
  box-shadow: 0 4px 20px rgba(0,0,0,0.25);
  display: flex;
  align-items: center;
  gap: 12px;
}
.toast.show { opacity: 1; pointer-events: auto; }
.toast.toast-error { background: #c0392b; font-size: 1.05rem; }
.toast-close {
  background: none;
  border: none;
  color: white;
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0;
  opacity: 0.75;
  flex-shrink: 0;
  line-height: 1;
}
.toast-close:hover { opacity: 1; }

/* Sort select in toolbar */
.sort-select {
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.8rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  margin-left: auto;
}

/* Photo label above each photo section */
.photo-label {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Detail view */
.detail-modal-inner { max-width: 600px; position: relative; padding-top: 48px; }

.detail-edit-btn, .detail-close-btn {
  position: absolute;
  top: 16px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background 0.15s;
}
.detail-edit-btn:hover, .detail-close-btn:hover { background: var(--border); }
.detail-edit-btn  { right: 48px; }
.detail-close-btn { right: 12px; color: var(--muted); }

.detail-photo {
  display: block;
  width: 100%;
  height: 160px;
  object-fit: contain;
  background: var(--bg);
  border-radius: 8px;
  border: 1px solid var(--border);
  margin-bottom: 16px;
  cursor: zoom-in;
}

.detail-header { margin-bottom: 4px; }
.detail-company { font-size: 0.8rem; color: var(--muted); }
.detail-dept    { font-size: 0.8rem; color: var(--muted); }
.detail-name    { font-size: 1.4rem; font-weight: 700; color: var(--primary); margin: 6px 0 2px; }
.detail-furigana { font-size: 0.75rem; color: var(--muted); margin-bottom: 16px; }

.detail-rows { display: flex; flex-direction: column; gap: 2px; margin-top: 12px; }

.detail-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.detail-row:last-child { border-bottom: none; }

.detail-label {
  font-size: 0.75rem;
  color: var(--muted);
  min-width: 80px;
  flex-shrink: 0;
}

.detail-value {
  flex: 1;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  gap: 8px;
  word-break: break-all;
}

.detail-value a { color: var(--primary); text-decoration: underline; }

.copy-btn {
  flex-shrink: 0;
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.8rem;
  padding: 1px 5px;
  color: var(--muted);
  transition: background 0.15s;
}
.copy-btn:hover { background: var(--border); }

/* Card scanner */
.scan-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 300;
  flex-direction: column;
}
.scan-modal.open { display: flex; }

.scan-viewport {
  flex: 1;
  position: relative;
  overflow: hidden;
}

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

#scan-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.scan-hint {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  color: white;
  background: rgba(0,0,0,0.55);
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 0.85rem;
  white-space: nowrap;
}

.scan-bar {
  padding: 20px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(0,0,0,0.85);
}

.scan-shutter { padding: 12px 32px; font-size: 1rem; }

.scan-loading {
  display: none;
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.75);
  color: white;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 1rem;
  line-height: 1.8;
}
.scan-loading.show { display: flex; }

/* Lightbox */
.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.9);
  z-index: 500;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
}
.lightbox.open { display: flex; }
.lightbox img {
  max-width: 95vw;
  max-height: 95vh;
  object-fit: contain;
  border-radius: 4px;
}

/* Detail top layout: image left, info right */
.detail-top {
  display: flex;
  gap: 16px;
  margin-bottom: 16px;
  align-items: flex-start;
}

.detail-img-col {
  flex: 0 0 42%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.detail-info-col {
  flex: 1;
  min-width: 0;
}

.detail-photo {
  display: block;
  width: 100%;
  object-fit: contain;
  background: var(--bg);
  border-radius: 8px;
  border: 1px solid var(--border);
  cursor: zoom-in;
}

.detail-photo-label {
  font-size: 0.7rem;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 2px;
}

.img-download-btn {
  display: inline-block;
  font-size: 0.75rem;
  color: var(--muted);
  text-decoration: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 8px;
  text-align: center;
}
.img-download-btn:hover { background: var(--border); }

.detail-updated {
  font-size: 0.72rem;
  color: var(--muted);
  margin-top: 10px;
}

@media (max-width: 540px) {
  .detail-top { flex-direction: column; }
  .detail-img-col { flex: none; width: 100%; flex-direction: row; flex-wrap: wrap; gap: 8px; align-items: flex-start; }
  .detail-img-col .detail-photo { width: 48%; }
}

@media (max-width: 480px) {
  .form-grid { grid-template-columns: 1fr; }
  .modal { padding: 20px; }
}
