/* ===== リセット & ベース ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #0078d4;
  --primary-dark: #005a9e;
  --primary-light: #deecf9;
  --accent: #00b0f0;
  --bg: #f3f5f7;
  --card-bg: #ffffff;
  --text: #323130;
  --text-light: #605e5c;
  --border: #e1dfdd;
  --danger: #d13438;
  --success: #107c10;
  --radius: 12px;
  --shadow: 0 2px 8px rgba(0,0,0,.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.12);
  --header-h: 40px;
  --nav-h: 60px;
  --bottom-bar-h: 110px;
}

html { font-size: 16px; }
body {
  font-family: 'Segoe UI', 'Hiragino Sans', 'Noto Sans JP', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-tap-highlight-color: transparent;
}

/* ===== ログイン画面 ===== */
.login-screen {
  position: fixed; inset: 0; z-index: 500;
  background: linear-gradient(135deg, #0078d4 0%, #005a9e 100%);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.login-card {
  background: #fff; border-radius: 20px;
  padding: 36px 28px; width: 100%; max-width: 380px;
  box-shadow: 0 12px 40px rgba(0,0,0,.2);
  text-align: center;
}
.login-logo { font-size: 3rem; margin-bottom: 8px; }
.login-title {
  font-size: 1.4rem; font-weight: 700; color: var(--text);
  margin-bottom: 4px;
}
.login-subtitle {
  font-size: .85rem; color: var(--text-light); margin-bottom: 24px;
}
.login-field {
  text-align: left; margin-bottom: 16px;
}
.login-field label {
  display: block; font-size: .8rem; font-weight: 600;
  color: var(--text-light); margin-bottom: 4px;
}
.login-field input {
  width: 100%; padding: 12px 14px;
  border: 1.5px solid var(--border); border-radius: 10px;
  font-size: .95rem; font-family: inherit;
  transition: border-color .2s;
}
.login-field input:focus { outline: none; border-color: var(--primary); }
.login-error {
  color: var(--danger); font-size: .82rem;
  margin-bottom: 12px; text-align: left;
}
.login-btn {
  width: 100%; padding: 14px;
  background: var(--primary); color: #fff; border: none;
  border-radius: 12px; font-size: 1rem; font-weight: 700;
  cursor: pointer; transition: background .2s;
}
.login-btn:hover { background: var(--primary-dark); }
.login-btn:active { transform: scale(.98); }
.login-link-btn {
  background: none; border: none; color: var(--primary);
  font-size: .8rem; cursor: pointer; padding: 4px;
  text-decoration: underline;
}

/* ===== ヘッダー ===== */
.header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--header-h);
  background: var(--primary);
  color: #fff;
  display: flex; align-items: center; padding: 0 16px;
  box-shadow: var(--shadow);
}
.header h1 { font-size: .85rem; font-weight: 600; flex: 1; }

.header-user {
  display: flex; align-items: center; gap: 6px;
  margin-left: auto;
}
.header-user-name {
  font-size: .72rem; color: rgba(255,255,255,.9);
  white-space: nowrap; max-width: 100px;
  overflow: hidden; text-overflow: ellipsis;
}
.header-admin-btn {
  background: rgba(255,255,255,.15); border: none;
  border-radius: 50%; width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: background .2s;
}
.header-admin-btn:hover { background: rgba(255,255,255,.3); }
.header-logout-btn {
  background: rgba(255,255,255,.15); border: none;
  border-radius: 50%; width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: background .2s;
}
.header-logout-btn:hover { background: rgba(255,255,255,.3); }

/* ユーザーカード */
.user-card {
  background: var(--card-bg); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 8px; box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 12px;
}
.user-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: .9rem; font-weight: 700; flex-shrink: 0; color: #fff;
}
.user-avatar-admin { background: #e65100; }
.user-avatar-user { background: var(--primary); }
.user-info { flex: 1; min-width: 0; }
.user-info-name { font-weight: 600; font-size: .9rem; }
.user-info-email { font-size: .75rem; color: var(--text-light); }
.user-info-role {
  display: inline-block; font-size: .65rem; font-weight: 600;
  padding: 1px 8px; border-radius: 8px; margin-top: 2px;
}
.role-admin { background: #fff3e0; color: #e65100; }
.role-user { background: var(--primary-light); color: var(--primary); }
.user-actions { display: flex; gap: 6px; }
.user-edit-btn, .user-delete-btn {
  background: none; border: none; cursor: pointer; padding: 6px;
  border-radius: 6px; transition: background .15s;
}
.user-edit-btn:hover { background: var(--bg); }
.user-delete-btn:hover { background: #fde8e8; }
.user-edit-btn svg { stroke: var(--text-light); }
.user-delete-btn svg { stroke: var(--danger); }

/* 管理画面タブ */
.admin-tabs {
  display: flex; gap: 0; margin: 0 12px 12px;
  border-radius: 10px; overflow: hidden;
  border: 1.5px solid var(--primary);
}
.admin-tab {
  flex: 1; padding: 10px; border: none;
  background: var(--card-bg); color: var(--primary);
  font-size: .85rem; font-weight: 600; cursor: pointer;
  transition: all .2s;
}
.admin-tab.active { background: var(--primary); color: #fff; }
.admin-view { display: none; }
.admin-view.active { display: block; }

/* ログイン履歴 */
.log-item {
  background: var(--card-bg); border-radius: 10px;
  padding: 12px 14px; margin-bottom: 6px;
  box-shadow: var(--shadow);
  display: flex; align-items: center; gap: 10px;
}
.log-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: .8rem; font-weight: 700; flex-shrink: 0;
}
.log-info { flex: 1; min-width: 0; }
.log-name { font-weight: 600; font-size: .88rem; }
.log-email { font-size: .72rem; color: var(--text-light); }
.log-meta {
  text-align: right; flex-shrink: 0;
}
.log-date { font-size: .75rem; color: var(--text); font-weight: 500; }
.log-time { font-size: .68rem; color: var(--text-light); }
.log-device { font-size: .6rem; color: var(--text-light); margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 120px; }

/* ===== ボトムナビ (モバイル) ===== */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  height: var(--nav-h);
  background: var(--card-bg);
  border-top: 1px solid var(--border);
  display: flex; justify-content: space-around; align-items: center;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.nav-item {
  display: flex; flex-direction: column; align-items: center;
  gap: 2px; background: none; border: none;
  color: var(--text-light); font-size: .65rem; cursor: pointer;
  padding: 6px 12px; border-radius: 8px; transition: all .2s;
}
.nav-item .nav-icon { font-size: 1.4rem; }
.nav-item.active { color: var(--primary); font-weight: 600; }

/* ===== メインコンテンツ ===== */
.main {
  padding-top: calc(var(--header-h) + 4px);
  padding-bottom: calc(var(--nav-h) + var(--bottom-bar-h) + 8px);
  padding-left: 0; padding-right: 0;
  max-width: 960px; margin: 0 auto;
}

/* ===== ページ表示制御 ===== */
.page { display: none; }
.page.active { display: block; animation: fadeIn .25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ===== リストコンテナ (カード一覧 + あいうえおインデックス) ===== */
.list-container {
  display: flex;
  position: relative;
}
.list-container .card-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0;
  min-width: 0;
}

/* ===== 名刺カード一覧 (Power Apps風) ===== */
.card-item {
  background: var(--card-bg);
  padding: 14px 16px;
  cursor: pointer;
  display: flex; align-items: flex-start; gap: 10px;
  border-bottom: 1px solid var(--border);
  transition: background .15s;
  position: relative;
}
.card-item:first-child { border-top: 1px solid var(--border); }
.card-item:hover { background: #f8f8fa; }
.card-item:active { background: #eef1f5; }

.card-info { flex: 1; min-width: 0; }
.card-info .card-name {
  font-weight: 500; font-size: 1.15rem; color: var(--primary);
  line-height: 1.3; margin-bottom: 2px;
}
.card-info .card-company {
  font-size: .88rem; color: var(--text); font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.card-info .card-dept {
  font-size: .8rem; color: var(--text-light); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.card-right {
  display: flex; flex-direction: column; align-items: flex-end;
  gap: 8px; flex-shrink: 0;
}
.card-date { font-size: .75rem; color: var(--text-light); white-space: nowrap; }

/* 電話・メール・住所アクションボタン */
.card-actions {
  display: flex; gap: 6px; align-items: center;
}
.action-btn {
  width: 38px; height: 38px; border-radius: 50%;
  border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: transform .15s, background .15s;
  text-decoration: none;
}
.action-btn:active { transform: scale(.9); }

.action-btn-phone {
  background: #e8f5e9; color: #2e7d32;
}
.action-btn-phone:hover { background: #c8e6c9; }
.action-btn-phone svg { stroke: #2e7d32; }

.action-btn-mail {
  background: #e3f2fd; color: #1565c0;
}
.action-btn-mail:hover { background: #bbdefb; }
.action-btn-mail svg { stroke: #1565c0; }

.action-btn-map {
  background: #fff3e0; color: #e65100;
}
.action-btn-map:hover { background: #ffe0b2; }
.action-btn-map svg { stroke: #e65100; }

/* ===== かな行フィルター (横スクロール) ===== */
.kana-row-bar {
  display: flex;
  gap: 6px;
  padding: 8px 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  position: sticky;
  top: var(--header-h);
  z-index: 40;
  background: var(--bg);
}
.kana-row-bar::-webkit-scrollbar { display: none; }

.kana-row-btn {
  flex-shrink: 0;
  padding: 8px 16px;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  background: var(--card-bg);
  color: var(--text);
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
  white-space: nowrap;
}
.kana-row-btn:active { transform: scale(.95); }
.kana-row-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.kana-row-btn:not(.active):hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* ===== ボトム固定: ソートタブ + キーワード検索 ===== */
.list-bottom-bar {
  position: fixed;
  bottom: var(--nav-h);
  left: 0; right: 0;
  background: var(--card-bg);
  border-top: 1px solid var(--border);
  z-index: 90;
  padding: 8px 12px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom, 0));
}

.sort-tabs {
  display: flex; gap: 6px; margin-bottom: 8px;
}
.sort-tab {
  flex: 1;
  padding: 8px 6px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--card-bg);
  color: var(--text-light);
  font-size: .78rem; font-weight: 600;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 4px;
  transition: all .2s;
  white-space: nowrap;
}
.sort-tab.active {
  background: var(--primary); color: #fff; border-color: var(--primary);
}
.sort-tab.active svg { stroke: #fff; }
.sort-tab:not(.active):hover { background: var(--bg); }

.keyword-search {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 6px 14px;
}
.keyword-icon { flex-shrink: 0; }
.keyword-search input {
  flex: 1; border: none; background: transparent;
  font-size: .92rem; outline: none; font-family: inherit;
  min-width: 0;
}
.keyword-search input::placeholder { color: #aaa; }
.keyword-clear {
  background: #999; color: #fff; border: none; border-radius: 50%;
  width: 22px; height: 22px; font-size: .7rem;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.keyword-go {
  background: var(--primary); color: #fff; border: none; border-radius: 16px;
  padding: 4px 14px; font-size: .8rem; font-weight: 600;
  cursor: pointer; flex-shrink: 0; white-space: nowrap;
}

/* ===== 音声入力ボタン ===== */
.voice-btn {
  padding: 8px 14px; border-radius: 10px;
  background: rgba(255,255,255,.25); border: 1.5px solid rgba(255,255,255,.5);
  cursor: pointer;
  display: flex; align-items: center; gap: 4px;
  flex-shrink: 0; transition: all .2s;
  font-size: 1rem; line-height: 1;
  color: #fff;
}
.voice-btn:hover { background: rgba(255,255,255,.4); border-color: #fff; }
.voice-btn:active { transform: scale(.95); }
.voice-label {
  font-size: .7rem; font-weight: 600; color: #fff;
}
.voice-btn.recording {
  background: #e53935; animation: pulse 1s infinite;
}
.voice-btn.recording svg { stroke: #fff; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(229,57,53,.4); }
  50% { box-shadow: 0 0 0 10px rgba(229,57,53,0); }
}

/* ===== 検索候補チップ ===== */
.search-suggestions {
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 12px 12px 4px;
}
.suggestion-chip {
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: 20px; padding: 8px 16px;
  font-size: .82rem; color: var(--text); cursor: pointer;
  transition: all .2s; white-space: nowrap;
}
.suggestion-chip:hover {
  background: var(--primary-light); border-color: var(--primary); color: var(--primary);
}
.suggestion-chip:active { transform: scale(.95); }

/* ===== グループヘッダー ===== */
.card-group-header {
  position: sticky;
  top: calc(var(--header-h) + 56px); /* ヘッダー + かな行バーの高さ */
  z-index: 20;
  background: var(--primary);
  color: #fff;
  font-size: .78rem;
  font-weight: 700;
  padding: 6px 16px;
  letter-spacing: .03em;
  margin: 0 -1px; /* 隙間防止 */
}

/* ===== Empty state ===== */
.empty-state {
  text-align: center; padding: 48px 16px; color: var(--text-light);
}
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 12px; }
.empty-state p { font-size: .9rem; }

/* ===== AI検索セクション ===== */
.ai-search {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: var(--radius); padding: 16px;
  margin: 0 12px 16px; color: #fff;
}
.ai-search h3 { font-size: .9rem; margin-bottom: 8px; display: flex; align-items: center; gap: 6px; }

.search-bar { display: flex; gap: 8px; }
.search-bar input {
  flex: 1; padding: 12px 16px; border: 1px solid rgba(255,255,255,.3);
  border-radius: var(--radius); font-size: .95rem;
  background: rgba(255,255,255,.15); color: #fff; transition: border-color .2s;
}
.search-bar input::placeholder { color: rgba(255,255,255,.6); }
.search-bar input:focus { outline: none; border-color: rgba(255,255,255,.6); }
.search-bar button {
  padding: 0 20px; background: rgba(255,255,255,.25); color: #fff;
  border: none; border-radius: var(--radius); font-size: .9rem;
  cursor: pointer; font-weight: 600; white-space: nowrap;
  transition: background .2s;
}
.search-bar button:hover { background: rgba(255,255,255,.35); }

.ai-answer {
  margin-top: 12px; padding: 12px; background: rgba(255,255,255,.12);
  border-radius: 8px; font-size: .9rem; line-height: 1.5;
  display: none;
}
.ai-answer.visible { display: block; }

.ai-result-list { padding: 0 12px; }

.search-examples {
  margin: 16px 12px; padding: 12px; background: var(--card-bg);
  border-radius: var(--radius); font-size: .82rem; color: var(--text-light);
}
.search-examples ul { margin-top: 6px; padding-left: 18px; line-height: 1.8; }

/* ===== 名刺詳細 (Power Apps風) ===== */
#page-detail {
  padding-bottom: 64px;
}
.detail-body {
  background: var(--card-bg);
  border-radius: var(--radius);
  margin: 8px;
  padding: 20px 18px;
  box-shadow: var(--shadow);
}

/* 名前行 */
.d-name-row {
  display: flex; align-items: baseline; gap: 16px;
  margin-bottom: 2px;
}
.d-name {
  font-size: 1.4rem; font-weight: 800; color: var(--text);
  letter-spacing: .02em;
}
.d-reading {
  font-size: .85rem; color: #4caf50; font-weight: 600;
}

/* 会社名 */
.d-company {
  font-size: 1rem; color: #555; font-weight: 600;
  margin-bottom: 16px;
}

/* 住所セクション */
.d-address-section {
  margin-bottom: 16px;
}
.d-postal {
  font-size: .9rem; color: var(--primary); font-weight: 600;
  margin-bottom: 2px;
}
.d-address-row {
  display: flex; align-items: center; gap: 8px;
}
.d-address-text {
  font-size: .95rem; color: var(--text); flex: 1;
}
.d-map-btn {
  width: 36px; height: 36px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; background: none; border: none; padding: 0;
  text-decoration: none;
}
.d-map-btn svg { stroke: var(--primary); }

/* キーマン */
.d-keyman-btn {
  margin-left: auto;
  display: inline-flex; align-items: center; gap: 4px;
  padding: 5px 14px; border-radius: 20px;
  border: 1.5px solid #ddd; background: var(--card-bg);
  color: var(--text-light); font-size: .78rem; font-weight: 600;
  cursor: pointer; transition: all .2s;
}
.d-keyman-btn:active { transform: scale(.95); }
.d-keyman-btn.active {
  border-color: #f0d060; background: #fef9e7; color: #b8860b;
}
.d-keyman-star { font-size: 1rem; }

/* 会社名 */
.d-company {
  font-size: 1rem; color: #555; font-weight: 600;
  margin-bottom: 4px;
}

/* 組織リンク */
.d-org-link {
  display: inline-block;
  font-size: .8rem; color: var(--primary); font-weight: 600;
  cursor: pointer; padding: 2px 0;
  margin-bottom: 14px;
  transition: opacity .15s;
}
.d-org-link:hover { opacity: .7; }
.d-org-link:active { opacity: .5; }

/* 区切り線 */
.d-divider {
  border: none; border-top: 1px solid var(--border);
  margin: 14px 0;
}

/* ラベル: 値 行 */
.d-field {
  display: flex; align-items: baseline; gap: 12px;
  padding: 5px 0; font-size: .92rem;
}
.d-label {
  color: var(--primary); font-weight: 700;
  font-size: .82rem; min-width: 56px; flex-shrink: 0;
}
.d-value {
  color: var(--text); font-size: .95rem; word-break: break-all;
}
.d-value a {
  color: var(--text); text-decoration: none;
}

/* TEL / 携帯 ボックス */
.d-phone-row {
  display: flex; gap: 16px; margin-top: 10px;
}
.d-phone-box {
  flex: 1;
}
.d-phone-label {
  display: inline-block;
  padding: 3px 14px;
  border: 1.5px solid var(--primary);
  border-radius: 4px;
  color: var(--primary);
  font-size: .78rem; font-weight: 700;
  margin-bottom: 4px;
}
.d-phone-number {
  font-size: 1rem; font-weight: 600; color: var(--text);
}
.d-phone-number a {
  color: var(--text); text-decoration: none;
}

/* FAXラベル（枠なし、TELの枠左端と揃え） */
.d-phone-label-plain {
  display: inline-block;
  color: var(--primary);
  font-size: .78rem; font-weight: 700;
  margin-bottom: 4px;
  /* TELの border(1.5px) + padding(14px) = 15.5px 分ずらしてテキスト位置を揃える */
  margin-left: 0;
  padding-left: 0;
}

/* 名刺画像 */
.d-photo-section {
  margin-top: 18px;
}
.d-photo {
  width: 100%; border-radius: 10px;
  border: 3px solid var(--primary-light);
  box-shadow: var(--shadow);
}

/* 自社担当カード */
.d-owners-card {
  margin-top: 16px; padding: 12px 14px;
  background: #e8f5e9; border-radius: 10px;
  border: 1px solid #c8e6c9;
}
.d-owners-title {
  font-size: .78rem; font-weight: 700; color: #2e7d32;
  display: flex; align-items: center; gap: 6px;
  margin-bottom: 8px;
}
.d-owners-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.d-owner-chip {
  display: flex; align-items: center; gap: 8px;
  background: #fff; border-radius: 12px;
  padding: 8px 12px 8px 8px;
  font-size: .85rem; font-weight: 500;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.d-owner-info {
  display: flex; flex-direction: column;
}
.d-owner-name { font-weight: 600; font-size: .85rem; }
.d-owner-date { font-size: .68rem; color: var(--text-light); margin-top: 1px; }
.d-owner-avatar {
  width: 26px; height: 26px; border-radius: 50%;
  background: #2e7d32; color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: .7rem; font-weight: 700; flex-shrink: 0;
}

/* 交換情報・メモ */
.d-notes-section {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.d-notes-section .d-field {
  align-items: flex-start;
}

/* 詳細ボトムバー */
.detail-bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0; right: 0;
  height: 54px;
  background: var(--card-bg);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 90;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.detail-bar-btn {
  background: none; border: none;
  color: var(--primary); cursor: pointer;
  padding: 8px 16px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
  text-decoration: none;
}
.detail-bar-btn:hover { background: var(--primary-light); }
.detail-bar-btn:active { transform: scale(.92); }
.detail-bar-btn svg { stroke: var(--primary); }

/* 非表示制御 */
#detailBottomBar { display: none; }
#page-detail.active ~ .bottom-nav { display: none; }

/* フォーム用ヘッダー */
.detail-header {
  display: flex; align-items: center; gap: 12px; margin-bottom: 20px;
  padding: 0 16px;
}
.back-btn {
  background: none; border: none; font-size: 1.5rem; cursor: pointer;
  color: var(--primary); padding: 4px;
}
.detail-actions { margin-left: auto; display: flex; gap: 8px; }

.detail-card {
  background: var(--card-bg); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow); margin: 0 12px;
}

.photo-preview {
  max-width: 100%; border-radius: 8px; margin-top: 12px;
  box-shadow: var(--shadow);
}

/* ===== フォーム ===== */
.camera-section {
  background: var(--card-bg); border-radius: var(--radius);
  padding: 16px; margin: 0 12px 16px; box-shadow: var(--shadow);
  text-align: center;
}
.camera-section h3 { font-size: .95rem; margin-bottom: 12px; }

/* 表面・裏面アップロード */
.photo-upload-row {
  display: flex; gap: 10px; margin-bottom: 8px;
}
.photo-upload-box {
  flex: 1; position: relative;
  border: 2px dashed var(--border); border-radius: 10px;
  overflow: hidden; cursor: pointer;
  min-height: 120px; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  transition: border-color .2s;
  background: var(--bg);
}
.photo-upload-box:hover { border-color: var(--primary); }
.photo-upload-box.has-photo { border-style: solid; border-color: var(--primary); }

.photo-upload-label {
  position: absolute; top: 6px; left: 8px;
  font-size: .7rem; font-weight: 700; color: var(--primary);
  background: var(--primary-light); padding: 2px 8px; border-radius: 4px;
  z-index: 2;
}
.photo-upload-preview {
  width: 100%; height: 100%; object-fit: cover;
  border-radius: 8px;
}
.photo-upload-placeholder {
  display: flex; flex-direction: column; align-items: center;
  gap: 6px; color: #aaa; font-size: .75rem; padding: 16px;
}

.ocr-status {
  margin-top: 8px; font-size: .85rem; color: var(--primary);
  display: none;
}

.form-group { margin-bottom: 14px; }
.form-group label {
  display: block; font-size: .82rem; font-weight: 600;
  color: var(--text-light); margin-bottom: 4px;
}
.form-group select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 8px; font-size: .95rem; font-family: inherit;
  background: var(--card-bg); color: var(--text);
  transition: border-color .2s; appearance: auto;
}
.form-group select:focus { outline: none; border-color: var(--primary); }
.form-group input, .form-group textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 8px; font-size: .95rem; font-family: inherit;
  transition: border-color .2s;
}
.form-group input:focus, .form-group textarea:focus {
  outline: none; border-color: var(--primary);
}
.form-group textarea { resize: vertical; min-height: 80px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ===== ボタン ===== */
.btn {
  padding: 10px 24px; border: none; border-radius: var(--radius);
  font-size: .9rem; font-weight: 600; cursor: pointer; transition: all .2s;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #a4262c; }
.btn-outline {
  background: transparent; border: 1px solid var(--border); color: var(--text);
}
.btn-outline:hover { background: var(--bg); }
.btn-block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ===== FAB ===== */
.fab {
  position: fixed; bottom: calc(var(--nav-h) + var(--bottom-bar-h) + 12px); right: 28px;
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--primary); color: #fff; border: none;
  font-size: 1.6rem; cursor: pointer; box-shadow: var(--shadow-lg);
  display: flex; align-items: center; justify-content: center;
  transition: transform .2s, background .2s; z-index: 50;
}
.fab:hover { background: var(--primary-dark); transform: scale(1.05); }

/* ===== ローディング ===== */
.spinner {
  display: inline-block; width: 20px; height: 20px;
  border: 3px solid rgba(255,255,255,.3); border-top-color: #fff;
  border-radius: 50%; animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; display: none;
}
.loading-overlay.visible { display: flex; }
.loading-box {
  background: var(--card-bg); padding: 24px 32px; border-radius: var(--radius);
  text-align: center; box-shadow: var(--shadow-lg);
}
.loading-box .spinner { border-color: var(--primary-light); border-top-color: var(--primary); width: 36px; height: 36px; }
.loading-box p { margin-top: 12px; font-size: .9rem; }

/* ===== モーダル ===== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.5);
  display: none; align-items: center; justify-content: center;
  z-index: 300; padding: 16px;
}
.modal-overlay.visible { display: flex; }
.modal {
  background: var(--card-bg); border-radius: var(--radius);
  padding: 24px; max-width: 400px; width: 100%;
  box-shadow: var(--shadow-lg);
}
.modal h3 { margin-bottom: 12px; }
.modal p { font-size: .9rem; color: var(--text-light); margin-bottom: 20px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* ===== PC (768px+) ===== */
@media (min-width: 768px) {
  :root { --nav-h: 0px; --bottom-bar-h: 0px; --header-h: 52px; }
  .bottom-nav { display: none; }
  .list-bottom-bar { display: none; }

  .header { padding: 0 24px; }
  .header h1 { font-size: 1.2rem; }
  .header-user-name { font-size: .85rem; max-width: 200px; }
  .header-logout-btn { width: 32px; height: 32px; }
  .pc-nav { display: flex !important; gap: 4px; margin-left: 24px; }
  .pc-nav .nav-link {
    color: rgba(255,255,255,.8); text-decoration: none;
    padding: 8px 16px; border-radius: 8px; font-size: .85rem;
    transition: all .2s;
  }
  .pc-nav .nav-link:hover, .pc-nav .nav-link.active {
    background: rgba(255,255,255,.15); color: #fff;
  }

  .main {
    padding: calc(var(--header-h) + 24px) 24px 24px;
    max-width: 1100px;
  }

  .list-container .card-list {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 8px;
  }
  .card-item {
    border-radius: var(--radius); border: 1px solid var(--border);
    border-bottom: 1px solid var(--border); box-shadow: var(--shadow);
  }

  .form-row { grid-template-columns: 1fr 1fr 1fr; }
  .fab { bottom: 24px; right: 24px; }
  .detail-card, .camera-section, .ai-search, .detail-header { margin: 0; }
}

/* PC ナビ非表示 (モバイル) */
.pc-nav { display: none; }

/* ===== 人脈管理 ===== */
#netTree { padding: 0 12px 12px; }

/* 組織ツリー: 会社カード */
.org-company {
  background: var(--card-bg); border-radius: var(--radius);
  margin-bottom: 10px; box-shadow: var(--shadow);
  overflow: hidden;
}
.org-company-header {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; cursor: pointer;
  transition: background .15s;
}
.org-company-header:active { background: #f5f5f5; }
.org-company-icon {
  width: 40px; height: 40px; border-radius: 10px;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; font-weight: 700; flex-shrink: 0;
}
.org-company-info { flex: 1; min-width: 0; }
.org-company-name {
  font-weight: 600; font-size: .95rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.org-company-meta {
  font-size: .75rem; color: var(--text-light); margin-top: 2px;
  display: flex; gap: 8px;
}
.org-company-meta .key-badge {
  color: #e6a700; font-weight: 700;
}
.org-chevron {
  font-size: 1rem; color: var(--text-light);
  transition: transform .2s; flex-shrink: 0;
}
.org-company.open .org-chevron { transform: rotate(90deg); }

/* 部署・人 */
.org-body { display: none; padding: 0 16px 12px 16px; }
.org-company.open .org-body { display: block; }

.org-dept {
  margin-top: 8px;
}
.org-dept-name {
  font-size: .78rem; font-weight: 700; color: var(--primary);
  padding: 4px 0; border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}
.org-person {
  display: flex; flex-direction: column;
  padding: 8px 8px 8px 12px;
  border-bottom: 1px solid #f0f0f0;
  cursor: pointer; transition: background .15s;
  gap: 3px;
}
.org-person:last-child { border-bottom: none; }
.org-person:active { background: #f5f5f5; }

.org-person-top {
  display: flex; align-items: center; gap: 8px;
  flex-wrap: wrap;
}
.org-person-owners {
  display: flex; gap: 3px; margin-left: auto;
}
.org-person-name {
  font-size: .9rem; font-weight: 500;
}
.org-person-key {
  font-size: .65rem; color: #e6a700; font-weight: 700;
  background: #fef9e7; border: 1px solid #f0d060;
  border-radius: 4px; padding: 1px 6px;
  white-space: nowrap;
}

.org-person-bottom {
  display: flex; align-items: center; gap: 6px;
}
.org-person-position {
  font-size: .72rem; color: var(--text-light);
  white-space: nowrap;
}
.org-person-owner {
  font-size: .6rem; color: var(--card-bg);
  background: var(--text-light); border-radius: 8px;
  padding: 1px 5px; white-space: nowrap;
}

/* 会社詳細ヘッダー */
.org-detail-header {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px 12px;
  position: sticky; top: var(--header-h); z-index: 30;
  background: var(--bg);
}
.org-detail-title { flex: 1; min-width: 0; }
.org-detail-title .odt-name {
  font-size: 1.05rem; font-weight: 700;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.org-detail-title .odt-meta {
  font-size: .75rem; color: var(--text-light);
  display: flex; gap: 8px; margin-top: 2px;
}
.odt-meta .key-badge { color: #e6a700; font-weight: 700; }

#orgDetailBody { padding: 0 12px 12px; }
#orgDetailBody .org-dept {
  background: var(--card-bg); border-radius: var(--radius);
  margin-bottom: 10px; box-shadow: var(--shadow); overflow: hidden;
}
#orgDetailBody .org-dept-name {
  padding: 10px 14px 6px; border-bottom: none; font-size: .85rem;
}
#orgDetailBody .org-person { padding: 8px 14px; }

/* ネットワークグラフ */
#graphContainer {
  width: 100%;
  height: 420px;
  background: #1a1a2e;
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
}
#graphContainer svg {
  width: 100%; display: block;
}
.graph-tooltip {
  position: absolute; pointer-events: none;
  background: rgba(0,0,0,.85); color: #fff;
  padding: 6px 10px; border-radius: 6px;
  font-size: .75rem; line-height: 1.4;
  display: none; z-index: 10;
  max-width: 200px;
}
.graph-legend {
  position: absolute; bottom: 10px; left: 10px;
  background: rgba(0,0,0,.6); border-radius: 8px;
  padding: 8px 12px; font-size: .65rem; color: #ccc;
  display: flex; flex-direction: column; gap: 4px;
}
.graph-legend-item {
  display: flex; align-items: center; gap: 6px;
}
.graph-legend-dot {
  width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
}

/* グラフフィルター */
.graph-filters {
  padding: 0 12px 16px;
}
.graph-filter-section {
  margin-bottom: 8px;
}
.graph-filter-label {
  font-size: .72rem; font-weight: 700;
  color: var(--text-light); margin-bottom: 5px;
}
.graph-filter-chips {
  display: flex; flex-wrap: wrap; gap: 6px;
}
.graph-chip-all, .graph-chip {
  padding: 6px 14px;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  background: var(--card-bg);
  color: var(--text);
  font-size: .78rem; font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  user-select: none; -webkit-user-select: none;
}
.graph-chip-all {
  border-color: var(--primary); color: var(--primary); font-weight: 600;
}
.graph-chip:active { transform: scale(.95); }
.chip-check {
  display: inline-flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; border-radius: 3px;
  border: 1.5px solid rgba(255,255,255,.6);
  background: rgba(255,255,255,.2);
  font-size: .7rem; line-height: 1;
  margin-right: 2px; vertical-align: -2px;
}
.graph-chip:not(.active-owner):not(.active-dept) .chip-check {
  border-color: #bbb;
  background: #fff;
  color: transparent;
}
.graph-chip.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.graph-chip.active-owner {
  background: #0288d1;
  color: #fff;
  border-color: #0288d1;
}
.graph-chip.active-dept {
  background: #2e7d32;
  color: #fff;
  border-color: #2e7d32;
}

/* コネクション */
.conn-company {
  background: var(--card-bg); border-radius: var(--radius);
  margin-bottom: 10px; box-shadow: var(--shadow); overflow: hidden;
}
.conn-company-header {
  padding: 14px 16px; cursor: pointer;
  display: flex; align-items: center; gap: 10px;
  transition: background .15s;
}
.conn-company-header:active { background: #f5f5f5; }
.conn-company-name { font-weight: 600; font-size: .95rem; flex: 1; }
.conn-badges {
  display: flex; gap: 4px;
}
.conn-badge {
  font-size: .7rem; padding: 2px 8px; border-radius: 10px;
  font-weight: 600;
}
.conn-badge-people { background: var(--primary-light); color: var(--primary); }
.conn-badge-owners { background: #e8f5e9; color: #2e7d32; }

.conn-body { display: none; padding: 0 16px 12px; }
.conn-company.open .conn-body { display: block; }
.conn-company.open .org-chevron { transform: rotate(90deg); }

.conn-owner-group { margin-top: 8px; }
.conn-owner-name {
  font-size: .8rem; font-weight: 700; color: #2e7d32;
  padding: 4px 0; display: flex; align-items: center; gap: 6px;
}
.conn-owner-name::before {
  content: ''; width: 8px; height: 8px; border-radius: 50%;
  background: #2e7d32; flex-shrink: 0;
}
.conn-person {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 0 5px 16px; font-size: .85rem;
  border-bottom: 1px solid #f5f5f5;
}
.conn-person:last-child { border-bottom: none; }
.conn-person-name { flex: 1; }
.conn-person-dept { font-size: .72rem; color: var(--text-light); }
.conn-person-key { font-size: .75rem; color: #e6a700; }

/* ===== ユーティリティ ===== */
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.text-center { text-align: center; }
.text-danger { color: var(--danger); }
.hidden { display: none !important; }
