:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #1c2430;
  --muted: #6b7684;
  --line: #e2e7ec;
  --brand: #1573ff;
  --brand-dark: #0f5ad6;
  --green: #1faa59;
  --amber: #f2a007;
  --red: #e0453e;
  --gray: #98a2b0;
  --shadow: 0 2px 10px rgba(20, 30, 45, 0.12);
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN",
    "Noto Sans JP", "Segoe UI", Meiryo, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
}

#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

/* ---- top bar ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 10px 14px; background: var(--panel);
  border-bottom: 1px solid var(--line); box-shadow: var(--shadow); z-index: 500;
}
.brand { font-size: 17px; margin: 0; white-space: nowrap; }
.topbar-actions { display: flex; gap: 8px; }

button { font-family: inherit; cursor: pointer; }
.primary-btn {
  background: var(--brand); color: #fff; border: none; border-radius: 999px;
  padding: 9px 16px; font-size: 14px; font-weight: 600; box-shadow: var(--shadow);
}
.primary-btn:hover { background: var(--brand-dark); }
.ghost-btn {
  background: #eef1f5; color: var(--ink); border: none; border-radius: 999px;
  padding: 9px 16px; font-size: 14px; font-weight: 600;
}
.icon-btn {
  background: #eef1f5; color: var(--ink); border: none; border-radius: 999px;
  padding: 9px 12px; font-size: 14px; font-weight: 600;
}
.link-btn { background: none; border: none; color: var(--brand); font-weight: 600; padding: 0 6px; }
.rank-chip {
  background: linear-gradient(135deg, #fff6e0, #ffe9c2); color: #8a5a00; border: 1px solid #f2d79a;
  border-radius: 999px; padding: 7px 12px; font-size: 13px; font-weight: 700;
  display: inline-flex; align-items: center; gap: 6px;
}
.rank-chip .rank-pts { background: rgba(255,255,255,.7); border-radius: 999px; padding: 1px 7px; font-size: 11px; }

/* ---- profile panel ---- */
.profile-rank { display: flex; align-items: baseline; justify-content: space-between; margin: 6px 0 10px; }
.profile-rank-label { font-size: 22px; font-weight: 800; }
.profile-points { font-size: 18px; font-weight: 800; color: var(--brand); }
.progress { height: 10px; background: #eef1f5; border-radius: 999px; overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--brand), #46a0ff); border-radius: 999px; transition: width .5s; }
.profile-next { font-size: 13px; color: var(--muted); margin: 8px 0 4px; }
.profile-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 14px 0; }
.stat-box { background: #f8fafc; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.stat-box .stat-num { font-size: 20px; font-weight: 800; }
.stat-box .stat-label { font-size: 12px; color: var(--muted); }
.profile-h3 { font-size: 14px; margin: 12px 0 8px; }
.badge-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.badge-item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); font-size: 13px; font-weight: 600; }
.badge-item.earned { background: #e5f6ec; border-color: #bfe6cd; color: #1a7a44; }
.badge-item.locked { background: #f6f7f9; color: var(--gray); }
.profile-note { font-size: 12px; color: var(--muted); margin-top: 14px; line-height: 1.6; }

/* ---- controls ---- */
.controls {
  display: flex; gap: 18px; flex-wrap: wrap; align-items: center;
  padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--line); z-index: 400;
}
.control-group { display: flex; align-items: center; gap: 8px; }
.control-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.segmented { display: inline-flex; background: #eef1f5; border-radius: 999px; padding: 3px; }
.segmented button {
  border: none; background: transparent; padding: 6px 11px; font-size: 13px;
  border-radius: 999px; color: var(--muted); font-weight: 600;
}
.segmented button.active { background: #fff; color: var(--brand); box-shadow: var(--shadow); }

/* ---- layout ---- */
.layout { flex: 1; display: flex; min-height: 0; }
#map { flex: 1; min-height: 0; z-index: 1; }
.list-panel {
  width: 340px; background: var(--panel); border-left: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
}
.list-header { padding: 10px 14px; border-bottom: 1px solid var(--line); font-size: 13px; color: var(--muted); font-weight: 600; }
.lot-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; }

/* ---- lot card ---- */
.lot-card { display: flex; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.lot-card:hover { background: #f8fafc; }
.lot-thumb {
  width: 60px; height: 60px; flex: none; border-radius: 8px; object-fit: cover;
  background: #eef1f5; display: flex; align-items: center; justify-content: center; color: var(--gray); font-size: 22px;
}
.lot-body { flex: 1; min-width: 0; }
.lot-name { font-weight: 700; font-size: 15px; margin: 0 0 3px; display: flex; align-items: center; gap: 6px; }
.lot-price { font-size: 13px; color: var(--ink); }
.lot-price strong { color: var(--brand); font-size: 15px; }
.lot-meta { font-size: 11.5px; color: var(--muted); margin-top: 4px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.badge { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 999px; }
.badge-fresh { background: #e5f6ec; color: var(--green); }
.badge-mid { background: #fdf1dc; color: var(--amber); }
.badge-old { background: #f0f2f5; color: var(--gray); }
.badge-warn { background: #fde7e6; color: var(--red); }
.badge-photo { background: #fdf1dc; color: var(--amber); }
.badge-sample { background: #e7effe; color: var(--brand); }

/* ---- add hint ---- */
.add-hint {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 22px;
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 999px;
  font-size: 14px; font-weight: 600; box-shadow: var(--shadow); z-index: 1200;
  display: flex; align-items: center; gap: 6px;
}
.add-hint .link-btn { color: #7fb4ff; }

/* ---- modal ---- */
.modal { position: fixed; inset: 0; background: rgba(20, 28, 40, 0.55); display: flex; align-items: flex-end; justify-content: center; z-index: 2000; }
.modal-card {
  background: var(--panel); width: 100%; max-width: 520px; border-radius: 16px 16px 0 0;
  max-height: 92vh; overflow-y: auto; padding: 16px 18px 22px;
}
@media (min-width: 640px) { .modal { align-items: center; } .modal-card { border-radius: 16px; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.modal-head h2 { font-size: 18px; margin: 0; }

.field { display: flex; flex-direction: column; gap: 5px; margin: 12px 0; font-size: 13px; font-weight: 600; color: var(--muted); }
.field input[type=text], .field input[type=number] {
  font: inherit; font-weight: 500; color: var(--ink); padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: #fbfcfd;
}
.field input:focus { outline: none; border-color: var(--brand); background: #fff; }
.field input[type=file] { font-weight: 500; }
.req { color: var(--red); font-style: normal; font-size: 11px; }
.hint-inline { color: var(--amber); font-style: normal; font-size: 11px; font-weight: 600; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---- rate rows (可変料金) ---- */
.rate-rows { display: flex; flex-direction: column; gap: 8px; }
.rate-row { display: flex; align-items: center; gap: 6px; }
.rate-row input[type=number] { width: 68px; font: inherit; font-weight: 500; color: var(--ink); padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: #fbfcfd; }
.rate-row input[type=time] { width: 92px; font: inherit; font-weight: 500; color: var(--ink); padding: 7px 8px; border: 1px solid var(--line); border-radius: 8px; background: #fbfcfd; }
.add-rate-btns { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.rate-row select { font: inherit; font-weight: 500; color: var(--ink); padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: #fbfcfd; }
.rate-row .yen-suffix { color: var(--muted); font-size: 13px; }
.rate-row .rate-max { display: inline-flex; align-items: center; gap: 3px; font-size: 12px; color: var(--muted); white-space: nowrap; font-weight: 600; }
.rate-row .rate-del { background: #f0f2f5; border: none; color: var(--muted); border-radius: 8px; width: 30px; height: 32px; font-size: 16px; flex: none; }
.add-rate-btn { align-self: flex-start; margin-top: 8px; background: #eef4ff; color: var(--brand); border: 1px dashed #b9d3ff; border-radius: 10px; padding: 8px 14px; font-size: 13px; font-weight: 700; }
.photo-preview { margin-top: 8px; }
.photo-preview img { max-width: 100%; max-height: 200px; border-radius: 10px; }
.pos-note { font-size: 12px; color: var(--muted); margin: 6px 0 0; }
.form-error { background: #fde7e6; color: var(--red); padding: 8px 12px; border-radius: 8px; font-size: 13px; margin: 8px 0 0; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

/* ---- popup ---- */
.popup-photo { width: 100%; max-height: 200px; object-fit: cover; border-radius: 8px; margin-bottom: 2px; cursor: zoom-in; }
.popup-photo-cap { font-size: 11px; color: var(--brand); font-weight: 600; margin-bottom: 6px; }
.est-note { font-size: 10.5px; color: var(--gray); font-weight: 600; }
.popup-name { font-weight: 700; font-size: 15px; margin: 0 0 4px; }
.popup-price { font-size: 13px; margin: 2px 0; }
.popup-price strong { color: var(--brand); }
.popup-note { font-size: 12px; color: var(--muted); margin: 4px 0; }
.popup-meta { font-size: 11.5px; color: var(--muted); margin: 6px 0; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.popup-actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.popup-actions button { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 6px 9px; font-size: 12px; font-weight: 600; }
.popup-actions .act-confirm { color: var(--green); }
.popup-actions .act-report { color: var(--red); }
.popup-actions .act-edit { color: var(--brand); }

/* ---- lightbox ---- */
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,0.85); display: flex; align-items: center; justify-content: center; z-index: 3000; cursor: zoom-out; }
.lightbox img { max-width: 94vw; max-height: 94vh; border-radius: 8px; }

/* ---- toast ---- */
.toast {
  position: fixed; left: 50%; bottom: 80px; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 999px;
  font-size: 14px; font-weight: 600; z-index: 4000; box-shadow: var(--shadow);
}

/* ---- marker pin ---- */
.pin { width: 30px; height: 30px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); border: 2px solid #fff; box-shadow: 0 2px 5px rgba(0,0,0,.35); display: flex; align-items: center; justify-content: center; }
.pin span { transform: rotate(45deg); color: #fff; font-size: 11px; font-weight: 800; }
.pin-green { background: var(--green); }
.pin-amber { background: var(--amber); }
.pin-red { background: var(--red); }
.pin-gray { background: var(--gray); }
.pin-gold { background: #e0a400; }
.pin-gold span, .pin-cert span { color: #fff; }
.pin-osm { background: var(--gray); opacity: 0.9; border-style: dashed; } /* 地図上のP（未登録） */

/* 信頼度バッジ */
.badge-cert { background: #fdf0cf; color: #8a5a00; }
.badge-confirmed { background: #e5f6ec; color: var(--green); }
.badge-info { background: #e7effe; color: var(--brand); }

.osm-loading {
  position: fixed; right: 12px; bottom: 16px; z-index: 1100;
  background: rgba(28,36,48,.9); color: #fff; padding: 7px 12px; border-radius: 999px;
  font-size: 12px; font-weight: 600; box-shadow: var(--shadow); pointer-events: none;
}

/* 著作権表記は小さく控えめに（© OpenStreetMap はライセンス上必須） */
.leaflet-control-attribution {
  font-size: 9px; background: rgba(255,255,255,.6); padding: 0 4px; color: #888;
}
.leaflet-control-attribution a { color: #888; }

.hidden { display: none !important; }

/* ---- responsive ---- */
@media (max-width: 720px) {
  .layout { flex-direction: column; }
  .list-panel { width: auto; border-left: none; border-top: 1px solid var(--line); max-height: 42vh; }
  #map { min-height: 40vh; }
  .brand { font-size: 15px; }
  .controls { gap: 10px; }
}
