/* ============================================================
   社内名刺管理システム — モバイルファースト
   展示会や外出先で片手で使うことを前提にした設計。
     - 基本レイアウトはスマホ。768px 以上で PC 向けに拡張する
     - 入力欄は 16px 未満にしない（iOS Safari が勝手にズームするため）
     - 主要操作は親指の届く画面下部に置く
     - タップ領域は最低 48px
   ============================================================ */

:root {
  --bg: #f2f4f7;
  --panel: #ffffff;
  --line: #dde2e9;
  --line-soft: #eef1f5;
  --ink: #131a24;
  --muted: #616d7e;
  --accent: #1358a8;
  --accent-soft: #e9f1fb;
  --warn: #8a4b00;
  --warn-soft: #fdf3e3;
  --danger: #a01c1c;
  --danger-soft: #fceded;
  --ok: #10633a;
  --ok-soft: #e6f3ec;
  --r: 14px;
  --tap: 48px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --nav-h: calc(58px + var(--safe-b));
}

* { box-sizing: border-box; }

/* display を指定したクラスが UA の [hidden] を上書きしてしまうため明示する */
[hidden] { display: none !important; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  font-size: 16px;
  line-height: 1.65;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

a { color: var(--accent); text-decoration: none; }
a:active { opacity: 0.6; }

button, input, select, textarea { font-family: inherit; }
button { touch-action: manipulation; }

/* ---------- ヘッダー（スマホでは細く） ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: max(8px, env(safe-area-inset-top)) 16px 8px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand {
  font-weight: 700;
  font-size: 15px;
  color: var(--ink);
  margin-right: auto;
  letter-spacing: 0.02em;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar nav { display: none; }
.logout { display: flex; align-items: center; gap: 10px; margin: 0; }
/* 氏名はマイページへのリンク。押せることが分かるよう下線を残す */
a.who { color: var(--muted); font-size: 13px; max-width: 7em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  text-decoration: underline; text-underline-offset: 3px; text-decoration-color: currentColor;
  padding: 8px 0; }
.logout { flex: 0 0 auto; }
.linkish {
  background: none; border: none; color: var(--accent);
  font-size: 13px; padding: 8px 0; cursor: pointer;
}

/* ---------- 本文 ---------- */
.wrap {
  padding: 14px 14px calc(var(--nav-h) + 16px);
  max-width: 720px;
  margin: 0 auto;
}
.foot {
  display: none;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  padding: 16px 14px;
  margin-bottom: 14px;
}
.panel.flush { padding: 0; overflow: hidden; }

h1 { font-size: 19px; margin: 0 0 12px; letter-spacing: 0.01em; }
h2 { font-size: 16px; margin: 0 0 10px; }
h3 { font-size: 13px; margin: 16px 0 6px; color: var(--muted); font-weight: 600; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.kana { color: var(--muted); font-size: 13px; display: block; }

/* ---------- 下部タブ（スマホの主動線） ---------- */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: flex;
  background: rgba(255, 255, 255, 0.94);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  backdrop-filter: saturate(180%) blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tabbar a {
  flex: 1;
  min-height: 58px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}
.tabbar a.on { color: var(--accent); }
.tabbar svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 1.8; }

/* ---------- フォーム ---------- */
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; font-weight: 600; }
input[type=text], input[type=password], input[type=date], input[type=email],
input[type=search], input[type=tel], select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 16px;            /* 16px 未満にすると iOS が自動ズームする */
  background: #fff;
  color: var(--ink);
  appearance: none;
  -webkit-appearance: none;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}
select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'><path d='M1 1l5 5 5-5' stroke='%23616d7e' stroke-width='1.6' fill='none' stroke-linecap='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 12px;
  padding-right: 34px;
}
select[multiple] { background-image: none; padding-right: 12px; min-height: 120px; }
textarea { min-height: 84px; resize: vertical; line-height: 1.6; }
.field { margin-bottom: 12px; }
.grid { display: grid; gap: 12px; grid-template-columns: 1fr; }

/* ---------- ボタン ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: var(--tap);
  padding: 12px 20px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
.btn:active { transform: scale(0.985); filter: brightness(0.94); }
.btn:disabled { background: #b6c0cd; cursor: not-allowed; transform: none; filter: none; }
.btn.block { width: 100%; }
.btn.ghost { background: #fff; color: var(--accent); border: 1.5px solid #c4d6ec; }
.btn.danger { background: #fff; color: var(--danger); border: 1.5px solid #e9c6c6; }
.btn.small { min-height: 40px; padding: 8px 14px; font-size: 14px; border-radius: 10px; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.actions .btn { flex: 1 1 auto; white-space: nowrap; }
.actions form { flex: 1 1 auto; margin: 0; }

/* 画面下部に貼り付く主要操作（親指ゾーン） */
.sticky-action {
  position: sticky;
  bottom: calc(var(--nav-h) + 8px);
  z-index: 10;
  margin-top: 14px;
}

/* ---------- 撮影画面 ---------- */
/* 画面の縦を使い切り、撮影エリアを最大化する（カメラアプリ的な操作感） */
.panel.capture {
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - var(--nav-h) - 118px);
  min-height: calc(100dvh - var(--nav-h) - 118px);
}
.panel.capture > .grow { flex: 1 1 auto; }
.panel.capture .shoot { flex: 1 1 auto; display: flex; flex-direction: column;
  align-items: center; justify-content: center; }

.shoot {
  display: block;
  border: 2px dashed #c3cddb;
  border-radius: var(--r);
  background: linear-gradient(180deg, #fff, #fafcff);
  padding: 30px 16px;
  text-align: center;
  cursor: pointer;
}
.shoot:active { background: var(--accent-soft); }
.shoot .icon { width: 46px; height: 46px; stroke: var(--accent); fill: none; stroke-width: 1.6; }
.shoot .label { display: block; margin-top: 8px; font-size: 17px; font-weight: 700; color: var(--accent); }
.shoot .hint { display: block; margin-top: 2px; font-size: 13px; color: var(--muted); }

.shots { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.shot {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #fff;
  aspect-ratio: 3 / 2;
  display: flex;
  align-items: center;
  justify-content: center;
}
.shot img { width: 100%; height: 100%; object-fit: cover; display: block; }
.shot .tag {
  position: absolute; left: 6px; top: 6px;
  background: rgba(0, 0, 0, 0.62); color: #fff;
  font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px;
}
.shot.add {
  border-style: dashed; color: var(--accent); font-weight: 600; font-size: 14px;
  flex-direction: column; gap: 4px; cursor: pointer;
}
.shot.add svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 1.8; }
.shot.empty { color: var(--muted); font-size: 13px; border-style: dashed; }

/* もらった社員・日付（既定で畳んでおく） */
.meta { border: 1px solid var(--line); border-radius: 12px; background: #fff; margin-top: 12px; }
.meta > summary {
  list-style: none; cursor: pointer;
  min-height: var(--tap); display: flex; align-items: center; gap: 8px;
  padding: 10px 14px; font-size: 14px;
}
.meta > summary::-webkit-details-marker { display: none; }
.meta > summary::after {
  content: ""; margin-left: auto;
  width: 9px; height: 9px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted);
  transform: rotate(45deg); transition: transform 0.15s;
}
.meta[open] > summary::after { transform: rotate(-135deg); }
.meta .body { padding: 0 14px 14px; border-top: 1px solid var(--line-soft); }
.meta .sum-val { font-weight: 600; }

/* ---------- 一覧（スマホはカード） ---------- */
.cardlist { list-style: none; margin: 0; padding: 0; }
.cardlist li { border-bottom: 1px solid var(--line-soft); }
.cardlist li:last-child { border-bottom: none; }
.cardlist a.row {
  display: grid;
  grid-template-columns: 68px 1fr;
  gap: 12px;
  padding: 12px 14px;
  align-items: center;
  color: inherit;
  min-height: 76px;
}
.cardlist a.row:active { background: var(--accent-soft); }
.cardlist .thumb {
  width: 68px; height: 44px; border-radius: 8px; object-fit: cover;
  border: 1px solid var(--line); background: #f6f8fa;
}
.cardlist .thumb.none {
  display: flex; align-items: center; justify-content: center;
  color: #b6c0cd; font-size: 11px;
}
.cardlist .co, .cardlist .nm, .cardlist .sub { display: block; min-width: 0; }
.cardlist .co {
  font-size: 12.5px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.cardlist .nm { font-weight: 700; font-size: 16px; line-height: 1.35; }
.cardlist .nm .small { font-weight: 500; }
.cardlist .sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

/* ---------- バッジ・通知 ---------- */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; border: 1px solid var(--line); background: #fff;
}
.badge.pending { background: var(--warn-soft); border-color: #e9d6b4; color: var(--warn); }
.badge.retry   { background: var(--warn-soft); border-color: #e9d6b4; color: var(--warn); }
.badge.failed, .badge.timeout { background: var(--danger-soft); border-color: #e9c6c6; color: var(--danger); }
.badge.done   { background: var(--ok-soft); border-color: #bfdfcc; color: var(--ok); }
.badge.manual { background: var(--accent-soft); border-color: #c3d7ee; color: var(--accent); }

.notice { padding: 12px 14px; border-radius: 12px; margin-bottom: 12px; font-size: 14.5px; }
.notice.warn { background: var(--warn-soft); border: 1px solid #e9d6b4; color: var(--warn); }
.notice.err  { background: var(--danger-soft); border: 1px solid #e9c6c6; color: var(--danger); }
.notice.info { background: var(--accent-soft); border: 1px solid #c3d7ee; color: var(--accent); }
.notice a { color: inherit; text-decoration: underline; }

/* ---------- 登録キュー ---------- */
.queue { list-style: none; padding: 0; margin: 12px 0 0; }
.queue li {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px;
  background: #fff; margin-bottom: 8px; font-size: 14.5px;
}
.queue li > span:first-child { flex: 1 1 60%; min-width: 0; }

/* ---------- 名刺画像 ---------- */
.card-images { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.card-images img {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; display: block;
}

/* 名刺1枚ぶんの塊 */
.cardblock { border: 1px solid var(--line); border-radius: var(--r); background: var(--panel); margin-bottom: 14px; overflow: hidden; }
.cardblock > .head {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 12px 14px; border-bottom: 1px solid var(--line-soft); background: #fbfcfe;
}
.cardblock > .head .t { font-weight: 700; }
.cardblock > .body { padding: 14px; }
.cardblock details > summary {
  list-style: none; cursor: pointer; min-height: var(--tap);
  display: flex; align-items: center; font-size: 14px; font-weight: 600; color: var(--accent);
}
.cardblock details > summary::-webkit-details-marker { display: none; }

/* 定義リスト（読み取り表示） */
/* 件数表示と書き出しボタンを1行に並べる */
.listhead { display: flex; align-items: center; gap: 10px; margin: 0 4px 8px; }
.listhead > p { flex: 1 1 auto; min-width: 0; }
.listhead > .btn { flex: 0 0 auto; }

.kv { margin: 0; font-size: 15px; }
.kv > div { display: grid; grid-template-columns: 6.5em 1fr; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line-soft); }
.kv > div:last-child { border-bottom: none; }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd { margin: 0; word-break: break-word; }

/* ---------- ログイン ---------- */
.login-wrap { max-width: 400px; margin: 8vh auto 0; padding: 0 4px; }

/* ============================================================
   768px 以上：PC 向けに拡張
   ============================================================ */
@media (min-width: 768px) {
  :root { --nav-h: 0px; }

  .topbar { padding: 12px 24px; gap: 22px; }
  .brand { font-size: 16px; margin-right: 0; }
  .topbar nav { display: flex; gap: 20px; margin-right: auto; }
  .topbar nav a { color: var(--muted); font-weight: 600; padding: 6px 0; border-bottom: 2px solid transparent; }
  .topbar nav a.on { color: var(--accent); border-bottom-color: var(--accent); }
  .who { max-width: none; }

  .tabbar { display: none; }
  .wrap { max-width: 1000px; padding: 24px; }
  .foot { display: block; max-width: 1000px; margin: 0 auto; padding: 0 24px 32px; color: var(--muted); font-size: 12px; }

  .panel { padding: 20px; }
  h1 { font-size: 22px; }

  .grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

  .actions .btn { flex: 0 0 auto; }
  .sticky-action { position: static; }

  .shots { grid-template-columns: repeat(3, 1fr); }
  .card-images { grid-template-columns: repeat(2, minmax(0, 260px)); }
  .cardlist a.row { grid-template-columns: 92px 1fr 200px; }
  .cardlist .thumb { width: 92px; height: 58px; }
  .kv > div { grid-template-columns: 8em 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
  .btn:active { transform: none; }
}

/* ---------- 名寄せ候補のペア表示 ---------- */
.pair { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: center; }
.pair-side { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.pair-side a { font-weight: 600; word-break: break-word; }
.pair-vs { color: var(--muted); font-size: 13px; }

/* ---------- 未送信バッジ（設計書 8） ---------- */
.tabbar a { position: relative; }
.tab-badge {
  position: absolute; top: 6px; left: 50%; margin-left: 6px;
  min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 999px; background: var(--danger); color: #fff;
  font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
}
.offline-bar {
  position: sticky; top: 0; z-index: 25;
  background: var(--warn-soft); color: var(--warn);
  border-bottom: 1px solid #e9d6b4;
  padding: 8px 14px; font-size: 13.5px; font-weight: 600; text-align: center;
}

/* ---------- モード切替（1枚ずつ / 一斉登録） ---------- */
.segmented {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  background: #e6eaf0; border-radius: 12px; padding: 4px; margin-bottom: 12px;
}
.segmented button {
  min-height: 42px; border: none; background: transparent; border-radius: 9px;
  font-size: 14px; font-weight: 700; color: var(--muted); cursor: pointer;
}
.segmented button.on { background: #fff; color: var(--accent); box-shadow: 0 1px 3px rgba(0,0,0,.1); }

/* ---------- 一斉登録 ---------- */
.batch-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 2px 8px; font-size: 15px;
}
.batch-shots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.batch-shots .shot { aspect-ratio: 3 / 2; }
.batch-shots .tag.back { left: auto; right: 6px; background: rgba(19,88,168,.85); }
.shot-back-btn {
  position: absolute; right: 4px; bottom: 4px;
  background: rgba(255,255,255,.94); border: 1px solid var(--line);
  border-radius: 8px; font-size: 11px; font-weight: 700; color: var(--accent);
  padding: 4px 7px; cursor: pointer;
}
