:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --line: #e0e0e0;
  --text: #1c1c1e;
  --muted: #6b7280;
  --accent: #0a84ff;
  --danger: #e53935;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Hiragino Sans', 'Segoe UI', sans-serif;
  color: var(--text); background: var(--bg);
  font-size: 16px;
}

/* ── ヘッダー / タブ ── */
.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 17px; margin: 0; font-weight: 700; flex: 1; }
.tabs { display: flex; gap: 4px; }
.tabs a {
  text-decoration: none; color: var(--muted);
  padding: 7px 12px; border-radius: 8px; font-size: 14px; font-weight: 600;
}
.tabs a.active { background: var(--accent); color: #fff; }

/* ── 集計バー ── */
.stats {
  display: flex; gap: 6px; overflow-x: auto; padding: 8px 12px;
  background: var(--card); border-bottom: 1px solid var(--line);
  -webkit-overflow-scrolling: touch;
}
.stat {
  flex: 0 0 auto; min-width: 62px; text-align: center;
  padding: 4px 8px; border-radius: 8px; background: var(--bg);
  border-left: 4px solid var(--line);
}
.stat b { display: block; font-size: 18px; line-height: 1.1; }
.stat span { font-size: 11px; color: var(--muted); }

/* ── 地図 ── */
#map { position: absolute; inset: 0; }
.map-wrap { position: relative; flex: 1; min-height: 0; }
.page-map { display: flex; flex-direction: column; height: 100%; }

.map-controls {
  position: absolute; top: 10px; left: 10px; right: 10px; z-index: 10;
  display: flex; gap: 6px; flex-wrap: wrap;
}
.map-controls input[type="search"] {
  flex: 1; min-width: 140px;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 15px; background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.12);
}
.filter-chips { display: flex; gap: 6px; overflow-x: auto; padding: 8px 10px 0; }
.chip {
  flex: 0 0 auto; padding: 7px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: #fff; font-size: 13px; font-weight: 600;
  color: var(--muted); box-shadow: 0 1px 3px rgba(0,0,0,.1);
}
.chip.active { background: var(--text); color: #fff; border-color: var(--text); }

.locate-btn {
  position: absolute; right: 14px; bottom: calc(24px + var(--safe-b)); z-index: 10;
  width: 52px; height: 52px; border-radius: 50%; border: none;
  background: #fff; box-shadow: 0 2px 8px rgba(0,0,0,.25);
  font-size: 24px; cursor: pointer;
}

/* ── ボトムシート ── */
.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.35);
  opacity: 0; pointer-events: none; transition: opacity .18s; z-index: 30;
}
.sheet-backdrop.open { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31;
  background: var(--card); border-radius: 18px 18px 0 0;
  box-shadow: 0 -4px 24px rgba(0,0,0,.2);
  transform: translateY(100%); transition: transform .22s ease;
  max-height: 88vh; overflow-y: auto;
  padding: 8px 16px calc(20px + var(--safe-b));
}
.sheet.open { transform: translateY(0); }
.sheet .grabber { width: 40px; height: 5px; background: #d1d5db; border-radius: 3px; margin: 6px auto 12px; }

.sheet h2 { font-size: 20px; margin: 0 0 4px; }
.sheet .addr { color: var(--muted); font-size: 14px; margin: 0 0 10px; }
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  color: #fff; font-size: 12px; font-weight: 700;
}
.meta { font-size: 14px; color: var(--muted); margin: 10px 0; line-height: 1.6; }
.meta b { color: var(--text); }

textarea, input[type="text"], input[type="password"] {
  width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 16px; font-family: inherit; background: #fff;
}
textarea { min-height: 74px; resize: vertical; }
label.fld { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 5px; font-weight: 600; }

.status-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 6px 0; }
.status-grid button {
  padding: 13px 8px; border-radius: 10px; border: 2px solid var(--line);
  background: #fff; font-size: 15px; font-weight: 700; color: var(--text);
}
.status-grid button.sel { color: #fff; border-color: transparent; }

.btn {
  display: block; width: 100%; padding: 15px; border: none; border-radius: 12px;
  background: var(--accent); color: #fff; font-size: 17px; font-weight: 700;
  margin-top: 12px; cursor: pointer;
}
.btn.secondary { background: #eceef1; color: var(--text); }
.btn:active { opacity: .85; }
.btn-row { display: flex; gap: 8px; }
.btn-row .btn { margin-top: 12px; }

.history-list { margin: 6px 0 0; padding: 0; list-style: none; }
.history-list li {
  border-top: 1px solid var(--line); padding: 10px 0; font-size: 14px;
}
.history-list .when { color: var(--muted); font-size: 13px; }
.history-list .note { margin-top: 3px; white-space: pre-wrap; }

/* ── リスト / 履歴ページ ── */
.page { padding: 12px; max-width: 760px; margin: 0 auto; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.toolbar input, .toolbar select {
  padding: 10px; border: 1px solid var(--line); border-radius: 10px; font-size: 15px; background:#fff;
}
.toolbar input[type="search"] { flex: 1; min-width: 150px; }
.rcard {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px; margin-bottom: 10px;
}
.rcard .row1 { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.rcard h3 { margin: 0 0 3px; font-size: 16px; }
.rcard .sub { color: var(--muted); font-size: 13px; }
.rcard .acts { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.rcard .acts a, .rcard .acts button {
  font-size: 13px; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: #fff; color: var(--accent); text-decoration: none; font-weight: 600; cursor: pointer;
}
.empty { text-align: center; color: var(--muted); padding: 40px 12px; }

/* ── ログイン ── */
.login-wrap {
  min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 24px;
}
.login-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 28px 22px; width: 100%; max-width: 360px; box-shadow: 0 4px 20px rgba(0,0,0,.06);
}
.login-card h1 { font-size: 20px; margin: 0 0 4px; }
.login-card p { color: var(--muted); font-size: 14px; margin: 0 0 18px; }

/* ── トースト ── */
.toast {
  position: fixed; left: 50%; bottom: calc(28px + var(--safe-b)); transform: translate(-50%, 20px);
  background: #1c1c1e; color: #fff; padding: 12px 20px; border-radius: 12px;
  font-size: 15px; font-weight: 600; opacity: 0; pointer-events: none; z-index: 60;
  transition: opacity .2s, transform .2s; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--danger); }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 40;
  display: none; align-items: center; justify-content: center; padding: 20px;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: #fff; border-radius: 16px; padding: 20px; width: 100%; max-width: 420px;
  max-height: 88vh; overflow-y: auto;
}
.modal h2 { margin: 0 0 12px; font-size: 18px; }
