:root {
  --bg: #f5f7f8;
  --panel: #ffffff;
  --ink: #1c2b2d;
  --muted: #6a7b7d;
  --line: #e2e8e9;
  --brand: #0d5c63;
  --brand-dark: #094248;
  --accent: #d97706;
  --danger: #c0392b;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.6;
}
button { font-family: inherit; cursor: pointer; }
a { color: var(--brand); }
input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(13,92,99,.25); border-color: var(--brand); }
textarea { resize: vertical; min-height: 60px; }
label { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }

.btn {
  border: 1px solid var(--brand);
  background: var(--brand);
  color: #fff;
  padding: 8px 16px;
  border-radius: 8px;
  font-weight: 600;
}
.btn:hover { background: var(--brand-dark); }
.btn.ghost { background: #fff; color: var(--brand); }
.btn.ghost:hover { background: #eef4f4; }
.btn.danger { background: #fff; color: var(--danger); border-color: #e6c3bf; }
.btn.danger:hover { background: #fdeeec; }
.btn.sm { padding: 4px 10px; font-size: 12px; }

/* ログイン画面 */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card {
  background: var(--panel); padding: 32px; border-radius: var(--radius);
  box-shadow: var(--shadow); width: 100%; max-width: 360px;
}
.login-card h1 { font-size: 20px; margin: 0 0 4px; color: var(--brand); }
.login-card .sub { color: var(--muted); font-size: 13px; margin: 0 0 20px; }
.err { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 8px; }
.login-help { font-size: 12px; color: var(--muted); margin: 14px 0 0; line-height: 1.7; }

/* ヘッダ */
.topbar {
  display: flex; align-items: center; gap: 12px;
  background: var(--brand); color: #fff; padding: 10px 18px;
}
.topbar .logo { font-weight: 700; font-size: 16px; }
.topbar .spacer { flex: 1; }
.topbar .who { font-size: 13px; opacity: .9; }
.topbar a, .topbar button.link {
  color: #fff; background: none; border: none; font-size: 13px;
  text-decoration: underline; cursor: pointer;
}
.impersonate-banner {
  background: var(--accent); color: #fff; text-align: center;
  padding: 6px; font-size: 13px;
}

/* レイアウト */
.layout { display: grid; grid-template-columns: 340px 1fr; height: calc(100vh - 44px); }
.sidebar { border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; overflow: hidden; }
.detail { overflow-y: auto; padding: 20px 24px; }
.back-btn {
  display: none; background: none; border: none; color: var(--brand);
  font-size: 14px; font-weight: 600; padding: 4px 0 10px; cursor: pointer;
}
/* スマホ: 一覧と詳細を一画面ずつ切り替える（迷子防止） */
@media (max-width: 780px) {
  .layout { grid-template-columns: 1fr; height: calc(100vh - 44px); }
  .sidebar { height: 100%; }
  .detail { display: none; padding: 14px 16px; }
  .layout.show-detail .sidebar { display: none; }
  .layout.show-detail .detail { display: block; }
  .back-btn { display: inline-flex; }
}

.filters { padding: 12px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
.filters .row { display: flex; gap: 8px; }
.add-btn { width: 100%; font-size: 15px; padding: 10px; }
.search-box { position: relative; }
.search-box .search-ico { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); font-size: 13px; opacity: .6; pointer-events: none; }
.search-box input { padding-left: 30px; }
.filter-group { display: flex; flex-direction: column; gap: 5px; }
.filter-label { font-size: 11px; font-weight: 600; color: var(--muted); }
.tag-filter { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; padding: 2px 10px; border-radius: 999px;
  background: #eef4f4; color: var(--brand-dark); border: 1px solid transparent; cursor: pointer;
}
.chip.active { background: var(--brand); color: #fff; }
.chip.cat { background: #f0ede8; color: #6b5d43; }

.org-list { overflow-y: auto; flex: 1; }
.org-item { padding: 12px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.org-item:hover { background: #f7fafa; }
.org-item.active { background: #eef4f4; border-left: 3px solid var(--brand); padding-left: 11px; }
.org-item .name { font-weight: 600; font-size: 15px; }
.org-item .meta { font-size: 12px; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; align-items: center; }
.org-item .count { color: var(--muted); }
.org-item .tagmini { color: var(--brand-dark); }
.cat-badge { font-size: 11px; padding: 2px 9px; border-radius: 999px; background: #e7f0f0; color: var(--brand-dark); font-weight: 600; white-space: nowrap; }

.detail-head { display: flex; align-items: center; gap: 10px; }
.empty-state.sm { padding: 28px 18px; }
.empty-state.first-run .big-ico { font-size: 40px; }
.empty-state.first-run .big-msg { font-weight: 700; font-size: 15px; color: var(--ink); margin-top: 6px; }
.empty-state.first-run p { font-size: 13px; margin: 6px 0 14px; }
.link-btn { background: none; border: none; color: var(--brand); text-decoration: underline; cursor: pointer; font-size: 13px; }

/* 名刺モーダルのステップ表示 */
.photo-step { background: #f6faf9; border: 1px solid var(--line); border-radius: 8px; padding: 12px; }
.step-head { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 13px; color: var(--brand-dark); }
.step-no { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 999px; background: var(--brand); color: #fff; font-size: 12px; }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; margin-bottom: 16px; box-shadow: var(--shadow);
}
.card h2 { font-size: 16px; margin: 0 0 12px; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; }
.field-grid .full { grid-column: 1 / -1; }
@media (max-width: 560px) { .field-grid { grid-template-columns: 1fr; } }

.contact {
  border: 1px solid var(--line); border-radius: 8px; padding: 12px;
  margin-bottom: 10px; display: flex; gap: 12px;
}
.contact.former { opacity: .72; background: #fafafa; }
.contact .thumb {
  width: 72px; height: 46px; object-fit: cover; border-radius: 6px;
  border: 1px solid var(--line); background: #f0f0f0; flex-shrink: 0; cursor: pointer;
}
.contact .thumb.empty { display: grid; place-items: center; color: #b8c2c3; font-size: 11px; }
.contact .info { flex: 1; min-width: 0; }
.contact .cname { font-weight: 600; }
.contact .ctitle { font-size: 12px; color: var(--muted); }
.contact .clines { font-size: 12px; margin-top: 4px; }
.contact .clines a { word-break: break-all; }
.status-pill { font-size: 11px; padding: 1px 8px; border-radius: 999px; }
.status-pill.current { background: #dcf1e4; color: #1c6b3f; }
.status-pill.former { background: #ececec; color: #777; }

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

.modal-bg {
  position: fixed; inset: 0; background: rgba(20,30,32,.5);
  display: none; align-items: flex-start; justify-content: center; padding: 30px 16px; overflow-y: auto; z-index: 50;
}
.modal-bg.open { display: flex; }
.modal {
  background: #fff; border-radius: var(--radius); padding: 20px 22px;
  width: 100%; max-width: 520px; box-shadow: 0 10px 40px rgba(0,0,0,.2);
}
.modal h3 { margin: 0 0 12px; font-size: 16px; }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

.card-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.card-row input[type=file] { flex: 1; min-width: 0; }
.ocr-result { margin-top: 8px; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fbfdfd; }
.ocr-note { font-size: 12px; color: var(--ink); }
.ocr-note b { color: var(--accent); }
.ocr-found { font-size: 13px; margin-top: 6px; color: var(--brand-dark); }
.ocr-raw { margin-top: 6px; }
.ocr-raw summary { font-size: 12px; color: var(--muted); cursor: pointer; }
.ocr-raw pre { white-space: pre-wrap; word-break: break-word; font-size: 12px; margin: 6px 0 0; padding: 8px; background: #f2f6f6; border-radius: 6px; max-height: 160px; overflow-y: auto; }

.img-viewer-bg { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: none; place-items: center; z-index: 60; }
.img-viewer-bg.open { display: grid; }
.img-viewer-bg img { max-width: 92vw; max-height: 92vh; border-radius: 8px; }

table.acct { width: 100%; border-collapse: collapse; }
table.acct th, table.acct td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); font-size: 13px; }
table.acct th { color: var(--muted); font-weight: 600; }
