:root {
  --bg: #f4f5f7; --panel: #ffffff; --ink: #1f2933; --muted: #6b7684; --line: #e2e5ea; --accent: #1d4ed8; --accent-soft: #e8eefc;
  --gatch: #1d4ed8; --hot: #e8590c; --visited: #2f9e44; --absent: #d9a400; --called: #7c4dff; --untouched: #0c8599; --ng: #9aa3ad;
  --gold: #c99a06; --danger: #d6336c; --shadow: 0 6px 24px rgba(15, 23, 42, .14);
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", system-ui, sans-serif; font-size: 13px; color: var(--ink); background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.spacer { flex: 1; }

/* ---------- top bar */
.topbar { height: 52px; display: flex; align-items: center; gap: 12px; padding: 0 12px; background: #13213a; color: #fff; position: relative; z-index: 1000; }
.brand { font-weight: 700; font-size: 15px; white-space: nowrap; }
.brand .sub { font-weight: 400; font-size: 11px; opacity: .65; margin-left: 8px; }
.search { flex: 1; max-width: 460px; }
.search input { width: 100%; height: 34px; border-radius: 8px; border: 0; padding: 0 12px; background: #24344f; color: #fff; }
.search input::placeholder { color: #9fb0c8; }
.tabs { display: flex; background: #24344f; border-radius: 8px; padding: 3px; }
.tabs button { border: 0; background: transparent; color: #c9d4e5; padding: 5px 14px; border-radius: 6px; cursor: pointer; }
.tabs button.on { background: #fff; color: #13213a; font-weight: 700; }
.actions { display: flex; gap: 6px; align-items: center; }
.btn { height: 32px; padding: 0 12px; border-radius: 7px; border: 1px solid var(--line); background: #fff; color: var(--ink); cursor: pointer; white-space: nowrap; }
.topbar .btn { background: #24344f; border-color: #33476a; color: #fff; }
.btn:hover { filter: brightness(.97); }
.btn.primary, .topbar .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.sm { height: 26px; padding: 0 8px; font-size: 12px; }
.icon-btn { width: 34px; height: 34px; border-radius: 8px; border: 0; background: transparent; color: inherit; font-size: 18px; cursor: pointer; }
.topbar .icon-btn:hover { background: #24344f; }
.link { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 0; }

/* ---------- layout */
.layout { display: flex; height: calc(100% - 52px); position: relative; }
.filters { width: 290px; flex: none; background: var(--panel); border-right: 1px solid var(--line); overflow-y: auto; padding: 10px 14px 20px; transition: margin .2s; }
.filters.hide { margin-left: -290px; }
.f-head { display: flex; justify-content: space-between; align-items: baseline; padding: 4px 0 8px; border-bottom: 1px solid var(--line); }
.f-head b { font-size: 20px; }
.filters section { padding: 10px 0; border-bottom: 1px solid var(--line); }
.filters h4 { margin: 0 0 6px; font-size: 12px; color: var(--muted); font-weight: 600; }
.chk-list label { display: flex; align-items: center; gap: 6px; padding: 2px 0; cursor: pointer; }
.chk-list label .n { margin-left: auto; color: var(--muted); font-size: 11px; }
.chk-list.inline { display: flex; flex-wrap: wrap; gap: 2px 10px; }
.chk-list.inline label .n { margin-left: 2px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid2 label { display: flex; flex-direction: column; gap: 2px; font-size: 11px; color: var(--muted); min-width: 0; }
.grid2 select { width: 100%; }
.filters { overflow-x: hidden; }
.f-head button { white-space: nowrap; }
select, input[type=text], input[type=date], input[type=number], input[type=tel], textarea { border: 1px solid var(--line); border-radius: 6px; padding: 5px 6px; background: #fff; min-width: 0; }
.opts label { display: flex; gap: 6px; align-items: center; padding: 3px 0; cursor: pointer; }
.meta { font-size: 11px; padding-top: 10px; line-height: 1.6; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }

.main { flex: 1; position: relative; min-width: 0; }
.view { position: absolute; inset: 0; display: none; }
.view.on { display: block; }
#map { position: absolute; inset: 0; }

/* ---------- markers */
.pin { width: 14px; height: 14px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0,0,0,.45); }
.pin.pm { box-shadow: 0 0 0 2.5px var(--gold), 0 1px 4px rgba(0,0,0,.5); }
.pin.star { width: 20px; height: 20px; border-radius: 4px; transform: rotate(45deg); display: flex; align-items: center; justify-content: center; }
.pin.star span { transform: rotate(-45deg); color: #fff; font-size: 11px; line-height: 1; font-weight: 700; }
.pin.sel { outline: 3px solid #ff2d55; outline-offset: 2px; }
.pin.inroute::after { content: ""; position: absolute; right: -6px; top: -6px; width: 8px; height: 8px; background: #ff2d55; border-radius: 50%; border: 1px solid #fff; }
.pin { position: relative; }
.s-gatch { background: var(--gatch); } .s-hot { background: var(--hot); } .s-visited { background: var(--visited); }
.s-absent { background: var(--absent); } .s-called { background: var(--called); } .s-untouched { background: var(--untouched); } .s-ng { background: var(--ng); }
.marker-cluster-custom { background: rgba(19, 33, 58, .82); color: #fff; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 700; border: 3px solid rgba(255,255,255,.85); box-shadow: 0 1px 5px rgba(0,0,0,.35); }
.marker-cluster-custom.has-gatch { border-color: #7aa2ff; }
.leaflet-tooltip.lbl { background: rgba(255,255,255,.9); border: 0; box-shadow: none; padding: 0 3px; font-size: 11px; color: #111; }
.leaflet-tooltip.lbl::before { display: none; }

.legend { position: absolute; left: 10px; bottom: 22px; z-index: 500; background: rgba(255,255,255,.95); border-radius: 8px; box-shadow: var(--shadow); padding: 8px 10px; font-size: 11px; line-height: 1.8; }
.legend .row { display: flex; align-items: center; gap: 6px; }
.legend .pin { width: 11px; height: 11px; border-width: 1.5px; }
.map-btns { position: absolute; right: 10px; bottom: 30px; z-index: 500; display: flex; gap: 8px; align-items: center; }
.map-btn { min-width: 40px; height: 40px; border-radius: 10px; border: 0; background: #fff; box-shadow: var(--shadow); cursor: pointer; font-size: 15px; color: var(--ink); }
.map-btn.wide { padding: 0 14px; font-weight: 700; background: var(--accent); color: #fff; }
.legend.hide { display: none; }
.mobile-only { display: none; }
.near-list { list-style: none; margin: 0; padding: 0; }
.near-list li { display: flex; align-items: center; gap: 8px; padding: 9px 0; border-bottom: 1px solid #eef0f3; cursor: pointer; }
.near-list .nm { flex: 1; min-width: 0; }
.near-list .sub { color: var(--muted); font-size: 11px; }
.near-list .dist { white-space: nowrap; font-weight: 700; font-size: 12px; }
.near-list a.btn { display: inline-flex; align-items: center; text-decoration: none; }

/* ---------- list */
#viewList { display: none; flex-direction: column; background: var(--panel); }
#viewList.on { display: flex; }
.list-tools { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.table-wrap { flex: 1; overflow: auto; }
table { border-collapse: collapse; width: 100%; }
thead th { position: sticky; top: 0; background: #f0f2f5; text-align: left; font-weight: 600; font-size: 12px; padding: 7px 8px; border-bottom: 1px solid var(--line); cursor: pointer; white-space: nowrap; z-index: 1; }
thead th.sorted::after { content: " ▾"; } thead th.sorted.asc::after { content: " ▴"; }
tbody td { padding: 6px 8px; border-bottom: 1px solid #eef0f3; vertical-align: top; }
tbody tr { cursor: pointer; } tbody tr:hover { background: #f7f9fc; } tbody tr.sel { background: var(--accent-soft); }
td.name { font-weight: 600; min-width: 200px; } td.num { text-align: right; white-space: nowrap; } td.nowrap { white-space: nowrap; }
.more { padding: 8px; text-align: center; border-top: 1px solid var(--line); }

/* ---------- badges */
.badge { display: inline-flex; align-items: center; gap: 3px; padding: 1px 7px; border-radius: 10px; font-size: 11px; font-weight: 600; white-space: nowrap; border: 1px solid transparent; }
.b-st { color: #fff; }
.b-gatch { background: var(--gatch); color: #fff; }
.b-pm { background: #fff6d6; color: #7a5b00; border-color: #f0d36b; }
.b-pm2 { background: #fffbea; color: #8a6d12; border-color: #f3e3a3; }
.b-pri { background: #eef1f5; color: #384250; }
.b-pri.S { background: #ffe3e3; color: #c92a2a; } .b-pri.A { background: #fff0e0; color: #d9480f; }
.b-warn { background: #fff0f6; color: var(--danger); border-color: #ffc9de; }
.b-lite { background: #f1f3f5; color: #495057; }

/* ---------- detail */
.detail { width: 440px; flex: none; background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; display: none; box-shadow: -4px 0 18px rgba(15,23,42,.08); z-index: 600; }
.detail.on { display: block; }
.d-head { position: sticky; top: 0; background: #fff; z-index: 2; padding: 12px 14px 10px; border-bottom: 1px solid var(--line); }
.d-head h2 { margin: 0 0 6px; font-size: 17px; line-height: 1.35; padding-right: 30px; }
.d-head .close { position: absolute; right: 8px; top: 8px; }
.d-head .badges { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.d-head .btns { display: flex; flex-wrap: wrap; gap: 6px; }
.d-sec { padding: 10px 14px; border-bottom: 1px solid var(--line); }
.d-sec h3 { margin: 0 0 8px; font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.d-sec h3 .spacer { flex: 1; }
dl.kv { display: grid; grid-template-columns: 92px 1fr; gap: 4px 10px; margin: 0; }
dl.kv dt { color: var(--muted); font-size: 12px; }
dl.kv dd { margin: 0; word-break: break-all; }
dl.kv .src { color: var(--muted); font-size: 10px; margin-left: 4px; }
.box { border-radius: 8px; padding: 8px 10px; margin-top: 6px; }
.box.gatch { background: #eef3ff; border: 1px solid #c8d6fb; }
.box.pm { background: #fffbea; border: 1px solid #f3e3a3; }
.summary { white-space: pre-wrap; line-height: 1.6; background: #f7f8fa; border-radius: 8px; padding: 8px 10px; font-size: 12px; }
.mysum textarea { width: 100%; min-height: 70px; resize: vertical; }
.lease-chip { font-weight: 700; } .lease-chip.soon { color: #d9480f; } .lease-chip.past { color: var(--muted); text-decoration: line-through; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { border-left: 2px solid var(--line); padding: 0 0 10px 12px; position: relative; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 3px; width: 10px; height: 10px; border-radius: 50%; background: #c5cbd3; }
.timeline li.k-visit::before { background: var(--visited); } .timeline li.k-call::before { background: var(--called); }
.timeline li.k-deal::before { background: var(--hot); } .timeline li.k-user::before { background: #ff2d55; }
.timeline .t-h { font-size: 11px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.timeline .t-b { white-space: pre-wrap; line-height: 1.55; margin-top: 2px; }
.timeline .t-b.clip { max-height: 7.8em; overflow: hidden; position: relative; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 12px; padding: 1px 9px; font-size: 11px; cursor: pointer; }
.chip.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.act-form { display: grid; grid-template-columns: 120px 1fr 1fr; gap: 6px; }
.act-form textarea { grid-column: 1 / -1; min-height: 60px; }
.act-form .row-end { grid-column: 1 / -1; display: flex; justify-content: flex-end; }
.near li { display: flex; align-items: center; gap: 6px; padding: 3px 0; cursor: pointer; }
.near li:hover { color: var(--accent); }
.near ul { list-style: none; margin: 0; padding: 0; }
.near .dist { margin-left: auto; color: var(--muted); font-size: 11px; white-space: nowrap; }
.next-row { display: grid; grid-template-columns: 130px 1fr auto; gap: 6px; }

/* ---------- dashboard */
.dash { position: absolute; inset: 0; overflow: auto; padding: 16px; display: grid; grid-template-columns: repeat(auto-fill, minmax(360px, 1fr)); gap: 14px; align-content: start; }
.card { background: var(--panel); border-radius: 10px; border: 1px solid var(--line); padding: 12px 14px; }
.card.wide { grid-column: 1 / -1; }
.card h3 { margin: 0 0 10px; font-size: 13px; }
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; cursor: pointer; }
.kpi .v { font-size: 24px; font-weight: 700; }
.kpi .l { color: var(--muted); font-size: 12px; }
.kpi .s { color: var(--muted); font-size: 11px; }
.bars .bar-row { display: grid; grid-template-columns: 130px 1fr 60px; align-items: center; gap: 8px; padding: 2px 0; font-size: 12px; }
.bars .track { height: 12px; background: #eef0f3; border-radius: 3px; overflow: hidden; display: flex; }
.bars .seg { height: 100%; }
.bars .v { text-align: right; color: var(--muted); }
.mini td, .mini th { padding: 4px 6px; font-size: 12px; border-bottom: 1px solid #eef0f3; }
.mini th { position: static; background: none; cursor: default; }
.mini td.num, .mini th.num { text-align: right; }
.mini td, .mini th { white-space: nowrap; }
.mini td:nth-child(2) { white-space: normal; }
.mini tr.click { cursor: pointer; } .mini tr.click:hover { background: #f7f9fc; }

/* ---------- modal & toast */
.modal { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: none; align-items: center; justify-content: center; z-index: 3000; padding: 16px; }
.modal.on { display: flex; }
.modal-box { background: #fff; border-radius: 12px; width: 720px; max-width: 100%; max-height: 92vh; overflow: auto; box-shadow: var(--shadow); }
.modal-box .m-head { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.modal-box .m-head h3 { margin: 0; font-size: 15px; flex: 1; }
.modal-box .m-body { padding: 14px 18px; }
.modal-box .m-foot { padding: 12px 18px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.form { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.form label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.form label.full { grid-column: 1 / -1; }
.form .chkrow { display: flex; gap: 12px; flex-wrap: wrap; color: var(--ink); }
.form .chkrow label { flex-direction: row; align-items: center; gap: 4px; color: var(--ink); }
.route-list { list-style: none; margin: 0; padding: 0; counter-reset: r; }
.route-list li { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid #eef0f3; }
.route-list li::before { counter-increment: r; content: counter(r); width: 22px; height: 22px; border-radius: 50%; background: var(--ink); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 11px; flex: none; }
.route-list .nm { flex: 1; } .route-list .ad { color: var(--muted); font-size: 11px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #13213a; color: #fff; padding: 9px 16px; border-radius: 8px; display: none; z-index: 4000; box-shadow: var(--shadow); }
.toast.on { display: block; }
.loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font-size: 15px; color: var(--muted); }

@media (max-width: 1100px) {
  .filters { position: absolute; left: 0; top: 0; bottom: 0; z-index: 700; box-shadow: var(--shadow); }
  .detail { position: absolute; right: 0; top: 0; bottom: 0; width: min(440px, 100%); }
  .brand .sub { display: none; }
}
@media (max-width: 760px) {
  html, body { overflow-x: hidden; }
  body { font-size: 14px; }
  .topbar { flex-wrap: wrap; height: auto; padding: 6px 8px; gap: 6px; max-width: 100vw; }
  .brand { display: none; }
  .tabs { flex: 1; min-width: 0; }
  .tabs button { padding: 5px 0; flex: 1; }
  .icon-btn { width: 32px; flex: none; }
  .layout { height: calc(100% - 92px); height: calc(100dvh - 92px); }
  .search { order: 5; max-width: none; flex-basis: 100%; }
  .actions { gap: 4px; }
  #btnExport { display: none; }
  .actions .btn { padding: 0 9px; }
  .mobile-only { display: inline-flex; align-items: center; }
  .main, .detail, .filters, .view { max-width: 100vw; }
  .summary, .timeline .t-b { overflow-wrap: anywhere; }
  .d-head .btns { gap: 4px; }
  .filters { width: 100%; padding-bottom: 80px; }
  .filters.hide { margin-left: -100%; }
  .f-head { position: sticky; top: -10px; background: #fff; z-index: 2; gap: 10px; align-items: center; }
  .chk-list label { padding: 5px 0; }
  .detail { position: fixed; inset: 0; width: 100%; z-index: 2000; }
  .d-head h2 { font-size: 18px; }
  .d-head .btns .btn { height: 34px; }
  dl.kv { grid-template-columns: 84px 1fr; }
  .act-form { grid-template-columns: 1fr 1fr; }
  .act-form input[type=date] { grid-column: 1 / -1; }
  .next-row { grid-template-columns: 1fr 1fr; }
  .next-row input[type=text] { grid-column: 1 / -1; order: 3; }
  input, select, textarea { font-size: 16px !important; } /* iOSの自動ズーム防止 */
  .legend { bottom: 80px; }
  .map-btns { bottom: 24px; }
  /* 一覧：主要列だけ */
  #tbl th:nth-child(n+4), #tbl td:nth-child(n+4) { display: none; }
  #tbl th:nth-child(13), #tbl td:nth-child(13) { display: table-cell; }
  td.name { min-width: 0; }
  .list-tools .muted { display: none; }
  .dash { padding: 10px; grid-template-columns: 1fr; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .bars .bar-row { grid-template-columns: 90px 1fr 48px; }
  .modal { padding: 0; align-items: flex-end; }
  .modal-box { border-radius: 14px 14px 0 0; max-height: 88vh; }
  .form { grid-template-columns: 1fr; }
  .toast { bottom: 84px; max-width: 92%; }
}
