:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #1f2933;
  --muted: #6b7280;
  --line: #e3e8ee;
  --brand: #1f6feb;
  --brand-dark: #1659c4;
  --danger: #d64545;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 4px 16px rgba(0, 0, 0, 0.06);
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.6;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---- ヘッダ ---- */
.app-header {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 12px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 500;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}
.brand .logo {
  background: var(--brand);
  color: #fff;
  font-weight: 800;
  letter-spacing: -0.5px;
  padding: 4px 8px;
  border-radius: 8px;
  font-size: 15px;
}
.brand .title { font-weight: 700; font-size: 16px; }
.crumbs { color: var(--muted); font-size: 13px; }
.crumbs a { color: var(--brand); text-decoration: none; cursor: pointer; }
.crumbs a:hover { text-decoration: underline; }

/* ---- 共通 ---- */
main { padding: 24px; max-width: 1400px; margin: 0 auto; }
.view-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
}
.view-head h1 { font-size: 22px; margin: 0; }
.head-actions { display: flex; gap: 8px; flex-shrink: 0; }

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn:hover { background: #f0f3f7; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-danger-outline { color: var(--danger); border-color: #f0c4c4; }
.btn-danger-outline:hover { background: #fdeded; }
.btn-sm { padding: 5px 10px; font-size: 13px; }

/* ---- 案件一覧 ---- */
.projects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.project-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.1s;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.project-card:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,0,0,0.1); }
.project-card h3 { margin: 0; font-size: 17px; }
.project-card .desc { color: var(--muted); font-size: 13px; min-height: 20px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.project-card .stats { display: flex; gap: 14px; font-size: 13px; color: var(--muted); margin-top: auto; }
.project-card .stats b { color: var(--ink); }
.project-card .card-foot { display: flex; justify-content: space-between; align-items: center; font-size: 12px; }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 60px 20px;
  background: var(--panel);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

/* ---- アップローダ ---- */
.uploader {
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  padding: 18px 20px;
  margin-bottom: 18px;
  transition: border-color 0.15s, background 0.15s;
}
.uploader.dragover { border-color: var(--brand); background: #eef4ff; }
.uploader-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.uploader-text { display: flex; flex-direction: column; }
.uploader-text strong { font-size: 15px; }
.uploader-text span { color: var(--muted); font-size: 13px; }
.progress {
  margin-top: 14px;
  height: 22px;
  background: #eef1f5;
  border-radius: 11px;
  position: relative;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--brand), #4d92ff);
  transition: width 0.2s;
}
.progress-label {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink);
}

/* ---- ワークスペース（地図＋一覧） ---- */
.workspace {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 16px;
  height: calc(100vh - 280px);
  min-height: 480px;
}
.map-wrap { position: relative; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
#map { width: 100%; height: 100%; background: #dfe6ee; }
.map-hint {
  position: absolute;
  top: 12px; left: 50%; transform: translateX(-50%);
  background: rgba(31,111,235,0.95);
  color: #fff;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
  z-index: 600;
  box-shadow: var(--shadow);
}

.sidebar {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar-head { padding: 12px 14px; border-bottom: 1px solid var(--line); }
.photo-list { overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 8px; }
.sidebar > .photo-list { flex: 1; }

.photo-item {
  display: flex;
  gap: 10px;
  padding: 8px;
  border-radius: 10px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.12s, border-color 0.12s;
}
.photo-item:hover { background: #f3f6fb; }
.photo-item.active { border-color: var(--brand); background: #eef4ff; }
.photo-item img {
  width: 84px;
  height: 48px;
  object-fit: cover;
  border-radius: 6px;
  background: #e6ebf1;
  flex-shrink: 0;
}
.photo-item .pi-body { min-width: 0; flex: 1; display: flex; flex-direction: column; }
.photo-item .pi-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.photo-item .pi-meta { font-size: 11px; color: var(--muted); }
.photo-item .pi-actions { display: flex; gap: 6px; margin-top: 4px; }
.link-btn {
  background: none; border: none; color: var(--brand); cursor: pointer;
  font-size: 12px; padding: 0; font-weight: 600;
}
.link-btn:hover { text-decoration: underline; }
.link-btn.danger { color: var(--danger); }

.nogeo { border-top: 1px solid var(--line); padding: 10px 14px; }
.nogeo h3 { margin: 0 0 4px; font-size: 14px; }

/* ---- 地図ピン（divIcon） ---- */
.photo-pin .pin-inner {
  width: 30px; height: 30px;
  background: var(--brand);
  color: #fff;
  border: 2px solid #fff;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 800;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}
.leaflet-popup-content { margin: 10px 12px; }
.popup-card { width: 200px; }
.popup-card img { width: 100%; height: 110px; object-fit: cover; border-radius: 6px; }
.popup-card .pc-name { font-weight: 700; font-size: 13px; margin: 6px 0 2px; word-break: break-all; }
.popup-card .pc-meta { font-size: 11px; color: var(--muted); margin-bottom: 8px; }

/* ---- モーダル ---- */
.modal {
  position: fixed; inset: 0;
  background: rgba(15, 23, 32, 0.6);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.dialog {
  background: var(--panel);
  border-radius: var(--radius);
  padding: 22px;
  width: min(440px, 92vw);
  box-shadow: var(--shadow);
}
.dialog h2 { margin: 0 0 16px; font-size: 18px; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field span { font-size: 13px; font-weight: 600; }
.field em { color: var(--danger); font-style: normal; }
.field input, .field textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
}
.field input:focus, .field textarea:focus { outline: 2px solid var(--brand); border-color: var(--brand); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

/* ---- 360ビューア ---- */
#viewer-modal { flex-direction: column; background: #0b0f14; padding: 0; }
.viewer-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: #11161d; color: #fff; flex-shrink: 0;
}
.viewer-meta { display: flex; flex-direction: column; min-width: 0; }
.viewer-meta strong { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viewer-meta .muted { color: #9aa6b2 !important; }
.viewer-actions { display: flex; gap: 8px; flex-shrink: 0; }
.viewer-actions .btn { background: #1c2530; border-color: #2b3744; color: #fff; }
.viewer-actions .btn:hover { background: #25313f; }
#pano { flex: 1; width: 100%; }

/* ---- トースト ---- */
.toast {
  position: fixed;
  bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #1f2933; color: #fff;
  padding: 12px 20px; border-radius: 8px;
  font-size: 14px; z-index: 2000;
  box-shadow: var(--shadow);
  max-width: 90vw;
}
.toast.error { background: var(--danger); }

/* ---- レスポンシブ ---- */
@media (max-width: 860px) {
  .workspace { grid-template-columns: 1fr; height: auto; }
  .map-wrap { height: 60vh; }
  .sidebar { height: 50vh; }
  .uploader-inner { flex-direction: column; align-items: stretch; text-align: center; }
}
