:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #1c2330;
  --muted: #6b7686;
  --line: #e6e9ee;
  --accent: #c8102e;        /* BNI レッド */
  --accent-ink: #ffffff;
  --ok: #1a8f5a;
  --warn: #c47d00;
  --danger: #c8102e;
  --chip: #eef1f5;
  --shadow: 0 1px 2px rgba(20,30,50,.06), 0 4px 16px rgba(20,30,50,.05);
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.6;
}
button { font-family: inherit; cursor: pointer; }
a { color: inherit; }

/* ---- Header ---- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 10px 20px;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; }
.brand .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--accent); }
.demo-badge {
  font-size: 12px; font-weight: 700; color: var(--warn);
  background: #fff6e5; border: 1px solid #ffe1a8; padding: 2px 8px; border-radius: 999px;
}
.nav { display: flex; gap: 4px; margin-left: 8px; }
.nav button {
  border: none; background: transparent; color: var(--muted);
  padding: 7px 12px; border-radius: 8px; font-size: 14px; font-weight: 600;
}
.nav button.active { background: var(--chip); color: var(--ink); }
.nav button:hover { background: var(--chip); }
.spacer { flex: 1; }
.actions { display: flex; gap: 8px; }

.btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  padding: 8px 14px; border-radius: 9px; font-weight: 600; font-size: 14px;
}
.btn:hover { background: #f0f2f5; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-primary:hover { filter: brightness(1.05); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--chip); }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-danger { color: var(--danger); border-color: #f0c4cb; background: #fff5f6; }

/* ---- Layout ---- */
.wrap { max-width: 1040px; margin: 0 auto; padding: 22px 20px 80px; }
.view { display: none; }
.view.active { display: block; }

h1.page { font-size: 20px; margin: 4px 0 18px; }
h2.section { font-size: 15px; color: var(--muted); margin: 26px 0 10px; letter-spacing: .02em; }
.section-row { display: flex; align-items: baseline; justify-content: space-between; }

.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: 1fr 1fr 1fr; }
@media (max-width: 720px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px;
}
.card.clickable { cursor: pointer; transition: transform .06s ease, box-shadow .12s ease; }
.card.clickable:hover { transform: translateY(-1px); box-shadow: 0 2px 4px rgba(20,30,50,.08), 0 8px 24px rgba(20,30,50,.08); }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.chip {
  display: inline-block; background: var(--chip); color: #45505f;
  padding: 2px 9px; border-radius: 999px; font-size: 12px; margin: 2px 4px 2px 0;
}
.chip.accent { background: #fdeaed; color: var(--accent); }
.pill-days { font-weight: 700; padding: 2px 10px; border-radius: 999px; font-size: 12px; }
.days-ok { background: #e7f6ee; color: var(--ok); }
.days-warn { background: #fff3df; color: var(--warn); }
.days-late { background: #fdeaed; color: var(--danger); }
.days-none { background: var(--chip); color: var(--muted); }

/* ---- List rows ---- */
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--panel); margin-bottom: 8px;
}
.row .grow { flex: 1; min-width: 0; }
.row .name { font-weight: 700; }
.row .sub { color: var(--muted); font-size: 13px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.avatar {
  width: 38px; height: 38px; border-radius: 50%; flex: none;
  background: linear-gradient(135deg, #d94a5f, var(--accent));
  color: #fff; font-weight: 700; display: flex; align-items: center; justify-content: center;
}

.empty { text-align: center; color: var(--muted); padding: 30px 10px; }

/* ---- Action (todo) ---- */
.todo { display: flex; align-items: flex-start; gap: 10px; padding: 9px 12px; border-bottom: 1px solid var(--line); }
.todo:last-child { border-bottom: none; }
.todo input { margin-top: 4px; width: 17px; height: 17px; accent-color: var(--accent); }
.todo.done .txt { text-decoration: line-through; color: var(--muted); }
.todo .act-ic { border: none; background: transparent; color: var(--muted); font-size: 14px; padding: 2px 6px; border-radius: 6px; opacity: .5; cursor: pointer; flex: none; }
.todo .act-ic:hover { opacity: 1; background: var(--chip); }
.due { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px; margin-left: 6px; white-space: nowrap; }
.due-over { background: #fdeaed; color: var(--danger); }
.due-today { background: #fff3df; color: var(--warn); }
.due-ok { background: var(--chip); color: var(--muted); }

/* 未完了アクションの人物グループ */
.avatar.sm { width: 27px; height: 27px; font-size: 12px; }
.avatar.sm.none { background: var(--chip); color: var(--muted); }
.act-group + .act-group { border-top: 1px solid var(--line); }
.act-group-head { display: flex; align-items: center; gap: 9px; padding: 10px 12px 6px; }
.act-group-head[data-person] { cursor: pointer; }
.act-group-head[data-person]:hover .agh-name { color: var(--accent); }
.agh-name { font-weight: 700; font-size: 14px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agh-count { margin-left: auto; flex: none; font-size: 11px; font-weight: 700; color: var(--muted); background: var(--chip); padding: 1px 9px; border-radius: 999px; }
.act-group-body { padding-left: 36px; }
.act-group-body .todo { border-bottom: 1px dashed var(--line); }
.act-group-body .todo:last-child { border-bottom: none; }

/* ---- リファーラル ---- */
.stat { font-size: 24px; font-weight: 700; margin-top: 2px; }
.ref-row { display: flex; align-items: flex-start; gap: 10px; padding: 11px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); margin-bottom: 8px; }
.ref-dir { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 8px; border-radius: 999px; margin-right: 6px; }
.ref-given { background: #e7f0ff; color: #2b5cad; }
.ref-received { background: #e7f6ee; color: var(--ok); }
.ref-st { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px; }
.st-open { background: var(--chip); color: var(--muted); }
.st-in_progress { background: #fff3df; color: var(--warn); }
.st-closed { background: #e7f6ee; color: var(--ok); }
.st-lost { background: #fdeaed; color: var(--danger); }
.ref-filters { display: flex; gap: 6px; margin-bottom: 12px; }
.ref-filters button { border: 1px solid var(--line); background: var(--panel); color: var(--muted); padding: 5px 12px; border-radius: 999px; font-weight: 600; font-size: 13px; cursor: pointer; }
.ref-filters button.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.ai-pre { white-space: pre-wrap; word-break: break-word; background: #fafbfc; border: 1px solid var(--line); border-radius: 8px; padding: 12px; font-size: 13px; line-height: 1.7; max-height: 55vh; overflow: auto; font-family: inherit; margin: 0; }

/* ---- Person detail ---- */
.person-head { display: flex; gap: 16px; align-items: flex-start; }
.person-head .avatar { width: 56px; height: 56px; font-size: 20px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin-top: 8px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.timeline { margin-top: 8px; }
.meeting {
  border: 1px solid var(--line); border-radius: 12px; background: var(--panel);
  box-shadow: var(--shadow); padding: 14px 16px; margin-bottom: 12px;
}
.meeting .m-head { display: flex; align-items: center; gap: 10px; }
.meeting .m-date { font-weight: 700; }
.meeting .distilled { margin: 8px 0 6px; font-size: 15px; }
.meeting details { margin-top: 8px; }
.meeting summary { cursor: pointer; color: var(--muted); font-size: 13px; font-weight: 600; }
.meeting pre {
  white-space: pre-wrap; word-break: break-word; background: #fafbfc;
  border: 1px solid var(--line); border-radius: 8px; padding: 10px; font-size: 13px;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; margin: 8px 0 0;
}

/* ---- Modal ---- */
.modal-back {
  position: fixed; inset: 0; background: rgba(20,26,38,.45);
  display: none; align-items: flex-start; justify-content: center; z-index: 40; padding: 40px 16px;
  overflow-y: auto;
}
.modal-back.open { display: flex; }
.modal {
  background: var(--panel); border-radius: 14px; width: 100%; max-width: 640px;
  box-shadow: 0 20px 60px rgba(10,15,30,.3); padding: 20px 22px; margin: auto 0;
}
.modal h3 { margin: 0 0 14px; font-size: 17px; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.field input, .field textarea, .field select {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px;
  font-family: inherit; font-size: 14px; background: #fff; color: var(--ink);
}
.field textarea { resize: vertical; min-height: 90px; }
.dropwrap { position: relative; border-radius: 9px; }
.dropwrap textarea { display: block; }
.drop-hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.linkbtn { border: none; background: none; padding: 0; font: inherit; font-size: 12px; color: var(--accent); cursor: pointer; text-decoration: underline; }
.dropwrap.dragover { outline: 2px dashed var(--accent); outline-offset: 2px; }
.dropwrap.dragover::after {
  content: "ファイルを離してアップロード"; position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center; text-align: center;
  background: #fdeaedcc; color: var(--accent); font-weight: 700; font-size: 14px;
  border-radius: 9px; pointer-events: none;
}
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }
.inp { padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; font-family: inherit; font-size: 14px; background: #fff; color: var(--ink); }

.bar { height: 8px; background: var(--chip); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, #e0607a, var(--accent)); border-radius: 999px; transition: width .3s ease; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.modal-foot .spacer { flex: 1; }

.distill-box { border: 1px dashed var(--line); border-radius: 10px; padding: 12px; background: #fbfcfd; }
.distill-box .lbl { font-size: 12px; font-weight: 700; color: var(--accent); }
.taglist { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.tag-edit {
  display: inline-flex; align-items: center; gap: 6px; background: var(--chip);
  border-radius: 999px; padding: 3px 6px 3px 10px; font-size: 13px;
}
.tag-edit button { border: none; background: transparent; color: var(--muted); font-size: 15px; line-height: 1; padding: 0 2px; }

/* ---- 面談相手ピッカー ---- */
.picker-controls { display: flex; gap: 8px; margin-bottom: 8px; }
.picker-controls > select { width: auto; max-width: 48%; flex: 0 0 auto; }
.picker-controls > input { flex: 1 1 auto; min-width: 0; width: auto; }
.picker-list { max-height: 210px; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.pick-group { position: sticky; top: 0; background: var(--bg); color: var(--muted); font-size: 12px; font-weight: 700; padding: 5px 12px; border-bottom: 1px solid var(--line); }
.pick-row { display: flex; align-items: baseline; gap: 8px; padding: 8px 12px; cursor: pointer; border-bottom: 1px solid var(--line); }
.pick-row:last-child { border-bottom: none; }
.pick-row:hover { background: var(--chip); }
.pick-row.sel { background: #fdeaed; box-shadow: inset 3px 0 0 var(--accent); }
.pick-name { font-weight: 700; }
.pick-sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pick-empty { padding: 18px 12px; text-align: center; color: var(--muted); font-size: 13px; }
.picker-fixed { padding: 9px 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--bg); font-weight: 700; }
.picker-fixed .pick-sub { font-weight: 400; margin-left: 2px; }

/* ---- 面談カレンダー ---- */
.cal-nav { display: flex; align-items: center; gap: 6px; }
.cal-label { font-weight: 700; font-size: 15px; min-width: 104px; text-align: center; }
.calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-wd { text-align: center; font-size: 12px; font-weight: 700; color: var(--muted); padding: 2px 0; }
.cal-wd.sun { color: var(--accent); }
.cal-wd.sat { color: #2b5cad; }
.cal-cell { min-height: 78px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel); padding: 5px 6px; overflow: hidden; }
.cal-cell.empty { border: none; background: transparent; }
.cal-cell.today { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.cal-day { font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 3px; }
.cal-cell.sun .cal-day { color: var(--accent); }
.cal-cell.sat .cal-day { color: #2b5cad; }
.cal-cell.today .cal-day { color: var(--accent); }
.cal-chip { display: block; background: #e7f6ee; color: var(--ok); font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 6px; margin-bottom: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-cell[data-cal-day] { cursor: pointer; }
.cal-cell[data-cal-day]:hover { border-color: var(--muted); }
.cal-cell.today[data-cal-day]:hover { border-color: var(--accent); }

/* その日の面談ポップアップ */
.cal-pop { position: fixed; z-index: 50; width: 232px; max-width: calc(100vw - 24px); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 14px 34px rgba(10,15,30,.28); padding: 12px 14px; }
.cal-pop[hidden] { display: none; }
.cal-pop .cp-date { font-weight: 700; font-size: 14px; margin-bottom: 6px; }
.cal-pop .cp-row { display: flex; align-items: center; gap: 8px; padding: 7px 0; border-top: 1px solid var(--line); cursor: pointer; }
.cal-pop .cp-main { flex: 1; min-width: 0; }
.cal-pop .cp-name { font-weight: 700; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-pop .cp-row:hover .cp-name { color: var(--accent); }
.cal-pop .cp-sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-pop .cp-open { color: var(--muted); font-size: 12px; white-space: nowrap; }
.cal-pop .cp-empty { font-size: 13px; color: var(--muted); margin: 2px 0 10px; }
.cal-pop .cp-rec { width: 100%; border: 1px dashed var(--accent); color: var(--accent); background: transparent; border-radius: 9px; padding: 7px; font-weight: 700; font-size: 13px; cursor: pointer; margin-top: 4px; }
.cal-pop .cp-rec:hover { background: #fdeaed; }

/* ---- Toast ---- */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: #1c2330; color: #fff; padding: 10px 18px; border-radius: 10px;
  font-size: 14px; box-shadow: 0 8px 30px rgba(0,0,0,.25); opacity: 0; pointer-events: none;
  transition: opacity .2s ease, transform .2s ease; z-index: 60;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }
.toast.err { background: var(--danger); }

.spin { display: inline-block; width: 14px; height: 14px; border: 2px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: sp .7s linear infinite; vertical-align: -2px; }
.btn .spin { border-color: rgba(0,0,0,.25); border-top-color: var(--ink); }
@keyframes sp { to { transform: rotate(360deg); } }

/* ---- モバイル最適化 ---- */
@media (max-width: 600px) {
  .wrap { padding: 16px 12px 84px; }
  .topbar { padding: 8px 12px; gap: 10px; }
  .brand { font-size: 15px; }
  .nav button { padding: 6px 9px; font-size: 13px; }
  h1.page { font-size: 18px; }
  .modal { padding: 16px; }
  .modal-back { padding: 14px 10px; }
  .field-row { flex-direction: column; gap: 0; }
  .field-row .field { max-width: none !important; }
  /* iOSでフォーカス時に自動ズームしないよう16px */
  .field input, .field textarea, .field select, .inp { font-size: 16px; }
  .person-head .avatar { width: 46px; height: 46px; font-size: 17px; }
  .calendar { gap: 3px; }
  .cal-cell { min-height: 56px; padding: 3px 4px; border-radius: 6px; }
  .cal-day { font-size: 11px; margin-bottom: 2px; }
  .cal-chip { font-size: 10px; padding: 1px 4px; }
  .picker-controls { flex-direction: column; }
  .picker-controls > select { max-width: none; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b; --panel: #1a1e26; --ink: #e8ecf2; --muted: #9aa5b3;
    --line: #2a303a; --chip: #262c36; --shadow: 0 1px 2px rgba(0,0,0,.3);
  }
  .field input, .field textarea, .field select, .inp { background: #12151b; }
  .meeting pre, .distill-box, .ai-pre { background: #141821; }
  .dropwrap.dragover::after { background: #3a1116cc; }
  .pick-row.sel { background: #3a1116; }
  .cal-chip { background: #14321f; }
  .cal-wd.sat, .cal-cell.sat .cal-day { color: #6f9be0; }
  .cal-pop .cp-rec:hover { background: #3a1116; }
}
