:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --header-h: 58px;
  --sidebar-w: 300px;
  --panel-w: 380px;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.08);
  --shadow-lg: 0 10px 25px rgba(0,0,0,.15);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Hiragino Kaku Gothic Pro', 'ヒラギノ角ゴ Pro', 'Yu Gothic UI', 'Meiryo', sans-serif; font-size: 14px; color: var(--gray-800); background: var(--gray-100); overflow: hidden; }

/* ===== HEADER ===== */
.header {
  position: fixed; top: 0; left: 0; right: 0; z-index: 1000;
  height: var(--header-h);
  background: #fff;
  border-bottom: 1px solid var(--gray-200);
  display: flex; align-items: center;
  padding: 0 16px;
  gap: 12px;
  box-shadow: var(--shadow);
}
.header-left { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.logo { font-size: 24px; }
.header-title { font-size: 16px; font-weight: 700; color: var(--gray-900); line-height: 1.2; }
.header-sub { font-size: 11px; color: var(--gray-500); }
.header-right { display: flex; align-items: center; gap: 8px; margin-left: auto; flex-shrink: 0; }

/* Filter buttons */
.filter-group { display: flex; gap: 4px; }
.filter-btn {
  padding: 5px 10px; border-radius: 20px;
  border: 1.5px solid var(--gray-300);
  background: #fff; color: var(--gray-600);
  font-size: 12px; cursor: pointer;
  display: flex; align-items: center; gap: 4px;
  transition: all .15s;
  font-family: inherit;
}
.filter-btn:hover { border-color: var(--primary); color: var(--primary); }
.filter-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* Buttons */
.btn {
  padding: 7px 14px; border-radius: var(--radius);
  border: none; cursor: pointer; font-size: 13px; font-weight: 600;
  transition: all .15s; white-space: nowrap; font-family: inherit;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--gray-100); color: var(--gray-700); border: 1.5px solid var(--gray-300); }
.btn-secondary:hover { background: var(--gray-200); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2020; }
.btn-ghost { background: transparent; color: var(--gray-600); }
.btn-ghost:hover { background: var(--gray-100); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn.active { background: var(--danger); color: #fff; border-color: var(--danger); }

/* ===== BODY ===== */
.body-container {
  position: fixed;
  top: var(--header-h); left: 0; right: 0; bottom: 0;
  display: flex;
}

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: #fff;
  border-right: 1px solid var(--gray-200);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.sidebar-top { padding: 12px; border-bottom: 1px solid var(--gray-200); }
.search-input {
  width: 100%; padding: 8px 12px;
  border: 1.5px solid var(--gray-300); border-radius: var(--radius);
  font-size: 13px; font-family: inherit;
  outline: none; transition: border-color .15s;
}
.search-input:focus { border-color: var(--primary); }
.stats-row { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.stat-chip {
  font-size: 11px; padding: 3px 8px; border-radius: 20px;
  background: var(--gray-100); color: var(--gray-600);
  font-weight: 600;
}
.stat-chip.vacant { background: #fef2f2; color: #dc2626; }
.stat-chip.negotiating { background: #fffbeb; color: #d97706; }

.store-list { flex: 1; overflow-y: auto; }
.store-list::-webkit-scrollbar { width: 4px; }
.store-list::-webkit-scrollbar-track { background: transparent; }
.store-list::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 2px; }

.store-card {
  padding: 12px 14px;
  border-bottom: 1px solid var(--gray-100);
  cursor: pointer; transition: background .1s;
}
.store-card:hover { background: var(--gray-50); }
.store-card.active { background: #eff6ff; border-left: 3px solid var(--primary); }
.store-card-header { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; }
.status-badge {
  font-size: 10px; font-weight: 700; padding: 2px 7px;
  border-radius: 20px; color: #fff; flex-shrink: 0;
}
.hearing-badge {
  font-size: 10px; color: var(--gray-500);
  background: var(--gray-100); padding: 2px 6px; border-radius: 20px;
}
.store-card-name { font-weight: 700; font-size: 14px; color: var(--gray-900); margin-bottom: 4px; }
.store-card-info { display: flex; flex-direction: column; gap: 2px; }
.store-card-info span { font-size: 11px; color: var(--gray-500); }

.empty-state { padding: 40px 16px; text-align: center; color: var(--gray-400); font-size: 13px; }
.loading-state { padding: 40px 16px; text-align: center; color: var(--gray-400); }

/* ===== MAP ===== */
#map { flex: 1; position: relative; }
.placement-hint {
  display: none;
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%);
  z-index: 500;
  background: var(--primary); color: #fff;
  padding: 10px 20px; border-radius: 30px;
  font-size: 14px; font-weight: 600;
  box-shadow: var(--shadow-lg);
  pointer-events: none;
  white-space: nowrap;
}

/* Custom map markers */
.custom-marker-wrap { position: relative; width: 36px; height: 46px; }
.custom-marker-pin {
  width: 36px; height: 36px; border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 6px rgba(0,0,0,.3);
  transition: transform .2s;
}
.custom-marker-pin:hover { transform: rotate(-45deg) scale(1.1); }
.custom-marker-char {
  transform: rotate(45deg);
  font-size: 13px; font-weight: 900; color: #fff;
  line-height: 1;
}
.custom-marker-badge {
  position: absolute; top: -4px; right: -4px;
  width: 16px; height: 16px; border-radius: 50%;
  background: #fff; color: var(--primary);
  font-size: 9px; font-weight: 900;
  display: flex; align-items: center; justify-content: center;
  transform: rotate(45deg);
  border: 1.5px solid currentColor;
}
.custom-marker-tail {
  width: 0; height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 10px solid;
  margin: 0 auto;
}
.leaflet-marker-icon.selected .custom-marker-pin {
  box-shadow: 0 0 0 4px rgba(37,99,235,.4), 0 2px 6px rgba(0,0,0,.3);
}

/* Map legend */
.map-legend {
  background: #fff; padding: 10px 12px;
  border-radius: var(--radius); box-shadow: var(--shadow);
  font-size: 12px;
}
.legend-title { font-weight: 700; margin-bottom: 6px; color: var(--gray-700); }
.legend-item { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

/* ===== DETAIL PANEL ===== */
.detail-panel {
  position: absolute; right: 0; top: 0; bottom: 0;
  width: var(--panel-w);
  background: #fff;
  border-left: 1px solid var(--gray-200);
  box-shadow: -4px 0 20px rgba(0,0,0,.08);
  transform: translateX(100%);
  transition: transform .25s ease;
  display: flex; flex-direction: column;
  z-index: 600;
  overflow: hidden;
}
.detail-panel.open { transform: translateX(0); }
.panel-close-btn {
  position: absolute; top: 12px; right: 12px; z-index: 1;
  width: 28px; height: 28px; border-radius: 50%;
  border: none; background: var(--gray-100);
  cursor: pointer; font-size: 14px; color: var(--gray-600);
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.panel-close-btn:hover { background: var(--gray-200); }
.detail-scroll { flex: 1; overflow-y: auto; padding: 20px; padding-top: 48px; }
.detail-scroll::-webkit-scrollbar { width: 4px; }
.detail-scroll::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 2px; }

.detail-header { margin-bottom: 16px; }
.detail-title { font-size: 20px; font-weight: 800; color: var(--gray-900); margin: 8px 0 4px; }
.detail-address { font-size: 13px; color: var(--gray-500); }
.status-badge.large { font-size: 12px; padding: 4px 10px; }

.detail-actions { display: flex; gap: 6px; margin-bottom: 20px; flex-wrap: wrap; }

.detail-section { margin-bottom: 20px; }
.detail-section h3 {
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; color: var(--gray-400);
  border-bottom: 1px solid var(--gray-100);
  padding-bottom: 6px; margin-bottom: 10px;
}
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.detail-item { display: flex; flex-direction: column; gap: 2px; }
.detail-label { font-size: 11px; color: var(--gray-400); font-weight: 600; }
.detail-item span:last-child { font-size: 13px; color: var(--gray-800); font-weight: 500; }
.detail-notes { font-size: 13px; color: var(--gray-700); line-height: 1.6; white-space: pre-wrap; }

/* Hearing cards */
.hearing-card {
  background: var(--gray-50); border-radius: var(--radius);
  padding: 12px; margin-bottom: 10px;
  border-left: 3px solid var(--gray-300);
}
.hearing-card.entrepreneur { border-left-color: var(--primary); }
.hearing-card.real_estate { border-left-color: var(--warning); }
.hearing-card.owner { border-left-color: var(--success); }

.hearing-head { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.hearing-type-badge {
  font-size: 11px; font-weight: 700; padding: 2px 7px;
  border-radius: 20px; background: var(--gray-200); color: var(--gray-700);
}
.hearing-date { font-size: 11px; color: var(--gray-500); margin-left: auto; }
.hearing-delete-btn {
  width: 20px; height: 20px; border-radius: 50%;
  border: none; background: transparent; color: var(--gray-400);
  cursor: pointer; font-size: 12px;
  display: flex; align-items: center; justify-content: center;
  transition: all .15s;
}
.hearing-delete-btn:hover { background: #fef2f2; color: var(--danger); }
.hearing-row { font-size: 12px; margin-bottom: 4px; color: var(--gray-700); }
.hearing-row strong { color: var(--gray-500); }
.hearing-content { font-size: 13px; line-height: 1.6; color: var(--gray-800); white-space: pre-wrap; margin-top: 6px; }
.interest-high { color: #16a34a; font-weight: 700; }
.interest-medium { color: #d97706; font-weight: 700; }
.interest-low { color: var(--gray-500); font-weight: 700; }

/* ===== MODAL ===== */
.modal-overlay {
  display: none;
  position: fixed; inset: 0; z-index: 2000;
  background: rgba(0,0,0,.5);
  align-items: center; justify-content: center;
  padding: 20px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: #fff; border-radius: 12px;
  width: 100%; max-width: 600px;
  max-height: 90vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: modal-in .2s ease;
}
@keyframes modal-in {
  from { opacity: 0; transform: scale(.96) translateY(-10px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-header {
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--gray-200);
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.modal-header h2 { font-size: 18px; font-weight: 800; }
.modal-close {
  width: 30px; height: 30px; border-radius: 50%;
  border: none; background: var(--gray-100);
  cursor: pointer; font-size: 16px; color: var(--gray-600);
  display: flex; align-items: center; justify-content: center;
}
.modal-close:hover { background: var(--gray-200); }
.modal-body { flex: 1; overflow-y: auto; padding: 0 20px; }
.modal-body::-webkit-scrollbar { width: 4px; }
.modal-body::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 2px; }
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--gray-200);
  display: flex; justify-content: flex-end; gap: 8px;
  flex-shrink: 0;
}

/* Form elements */
.form-section { padding: 16px 0; border-bottom: 1px solid var(--gray-100); }
.form-section:last-child { border-bottom: none; }
.form-section-title {
  font-size: 12px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .05em; color: var(--primary);
  margin-bottom: 12px;
}
.form-row { display: flex; gap: 12px; margin-bottom: 10px; }
.form-row:last-child { margin-bottom: 0; }
.form-group { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.form-group.full { flex: 1 0 100%; }
.form-group label { font-size: 12px; font-weight: 600; color: var(--gray-600); }
.required { color: var(--danger); }
.form-group input,
.form-group select,
.form-group textarea {
  padding: 8px 10px;
  border: 1.5px solid var(--gray-300); border-radius: var(--radius);
  font-size: 13px; font-family: inherit; color: var(--gray-800);
  outline: none; transition: border-color .15s;
  background: #fff;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { border-color: var(--primary); }
.form-group textarea { resize: vertical; min-height: 80px; }
.checkbox-group { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.checkbox-label { display: flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
.checkbox-label input { width: 15px; height: 15px; cursor: pointer; }

/* ===== TOAST ===== */
.toast-container {
  position: fixed; bottom: 20px; right: 20px; z-index: 9999;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 12px 18px; border-radius: var(--radius);
  font-size: 13px; font-weight: 600; color: #fff;
  box-shadow: var(--shadow-lg);
  animation: toast-in .25s ease;
  pointer-events: auto;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: var(--primary); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ===== ATTACHMENT LIST ===== */
.attachment-list { display: flex; flex-direction: column; gap: 5px; margin-bottom: 10px; }
.attachment-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  min-width: 0;
}
.att-icon { font-size: 18px; flex-shrink: 0; line-height: 1; }
.att-name {
  flex: 1; font-size: 12px; font-weight: 600;
  color: var(--gray-800);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  min-width: 0;
}
.att-meta { font-size: 11px; color: var(--gray-400); flex-shrink: 0; white-space: nowrap; }
.att-btn {
  width: 26px; height: 26px; border-radius: 6px; border: none;
  cursor: pointer; font-size: 13px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: all .15s;
}
.att-dl-btn { background: var(--gray-100); color: var(--gray-600); }
.att-dl-btn:hover { background: var(--primary); color: #fff; }
.att-del-btn { background: transparent; color: var(--gray-300); }
.att-del-btn:hover { background: #fef2f2; color: var(--danger); }

/* ===== PHOTO GALLERY ===== */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 10px;
}
.photo-thumb {
  position: relative;
  aspect-ratio: 1;
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  background: var(--gray-100);
}
.photo-thumb img {
  width: 100%; height: 100%;
  object-fit: cover;
  transition: transform .2s;
  display: block;
}
.photo-thumb:hover img { transform: scale(1.05); }
.photo-delete-btn {
  position: absolute; top: 4px; right: 4px;
  width: 22px; height: 22px; border-radius: 50%;
  border: none; background: rgba(0,0,0,.6);
  color: #fff; font-size: 11px; cursor: pointer;
  display: none; align-items: center; justify-content: center;
  transition: background .15s;
}
.photo-thumb:hover .photo-delete-btn { display: flex; }
.photo-delete-btn:hover { background: var(--danger); }

.photo-upload-label {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  border: 1.5px dashed var(--gray-300);
  border-radius: var(--radius);
  font-size: 13px; color: var(--gray-500);
  cursor: pointer; transition: all .15s;
  font-family: inherit;
}
.photo-upload-label:hover { border-color: var(--primary); color: var(--primary); }
.photo-upload-label input { display: none; }

/* ===== PHOTO LIGHTBOX ===== */
.photo-lightbox {
  display: none;
  position: fixed; inset: 0; z-index: 3000;
  background: rgba(0,0,0,.92);
  align-items: center; justify-content: center;
}
.photo-lightbox.open { display: flex; }
.photo-lightbox img {
  max-width: 92vw; max-height: 88vh;
  object-fit: contain; border-radius: 4px;
  box-shadow: 0 8px 40px rgba(0,0,0,.5);
}
.lightbox-close {
  position: absolute; top: 16px; right: 16px;
  width: 40px; height: 40px; border-radius: 50%;
  border: none; background: rgba(255,255,255,.15);
  color: #fff; font-size: 18px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.lightbox-close:hover { background: rgba(255,255,255,.3); }

/* ===== MOBILE-ONLY ELEMENTS (hidden on desktop) ===== */
.mobile-fab { display: none; }
.mobile-backdrop { display: none; }

/* ===== MOBILE RESPONSIVE (max 767px) ===== */
@media (max-width: 767px) {

  /* --- Root variables --- */
  :root {
    --header-h: 92px; /* 52px 上段 + 40px フィルター段 */
  }

  /* --- Header: 2段組み --- */
  .header {
    flex-wrap: wrap;
    height: auto;
    min-height: var(--header-h);
    padding: 0 12px;
    gap: 0;
    align-content: flex-start;
  }
  .header-left {
    flex: 1;
    height: 52px;
    min-width: 0;
  }
  .logo { font-size: 20px; flex-shrink: 0; }
  .header-title { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .header-sub { display: none; }
  .header-right {
    height: 52px;
    margin-left: 0;
    gap: 6px;
  }
  #exportBtn { display: none; }
  #addStoreBtn { font-size: 12px; padding: 6px 10px; }

  /* フィルターグループ: 2段目 (全幅・横スクロール) */
  #filterGroup {
    order: 10;
    width: calc(100% + 24px);
    margin: 0 -12px;
    padding: 6px 12px;
    height: 40px;
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 6px;
    border-top: 1px solid var(--gray-100);
    flex-shrink: 0;
  }
  #filterGroup::-webkit-scrollbar { display: none; }
  .filter-btn { white-space: nowrap; flex-shrink: 0; }

  /* --- Body container --- */
  .body-container {
    position: fixed;
    top: var(--header-h);
    left: 0; right: 0; bottom: 0;
  }

  /* --- Sidebar: ボトムシート --- */
  .sidebar {
    position: fixed;
    left: 0; right: 0; bottom: 0; top: auto;
    width: 100%;
    height: 70vh;
    border-right: none;
    border-top: 1px solid var(--gray-200);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -6px 30px rgba(0,0,0,.18);
    transform: translateY(100%);
    transition: transform .3s cubic-bezier(.32,.72,0,1);
    z-index: 900;
  }
  .sidebar.mobile-open { transform: translateY(0); }

  /* ドラッグハンドル */
  .sidebar-top::before {
    content: '';
    display: block;
    width: 36px; height: 4px;
    background: var(--gray-300);
    border-radius: 2px;
    margin: 0 auto 10px;
  }

  /* --- Map: 全幅 --- */
  #map { width: 100%; }

  /* --- Detail panel: 全画面ボトムシート --- */
  .detail-panel {
    position: fixed;
    left: 0; right: 0;
    top: var(--header-h); bottom: 0;
    width: 100%;
    transform: translateY(100%);
    border-left: none;
    border-radius: 0;
    z-index: 850;
  }
  .detail-panel.open { transform: translateY(0); }

  /* --- Mobile FAB (一覧ボタン) --- */
  .mobile-fab {
    display: flex;
    align-items: center;
    gap: 6px;
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 820;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 30px;
    padding: 13px 26px;
    font-size: 15px;
    font-weight: 700;
    font-family: inherit;
    box-shadow: 0 4px 20px rgba(37,99,235,.45);
    cursor: pointer;
    white-space: nowrap;
    transition: transform .15s, box-shadow .15s;
  }
  .mobile-fab:active {
    transform: translateX(-50%) scale(.95);
    box-shadow: 0 2px 10px rgba(37,99,235,.35);
  }
  .mobile-fab.open {
    background: var(--gray-700);
    box-shadow: 0 4px 20px rgba(0,0,0,.3);
  }

  /* --- Mobile backdrop --- */
  .mobile-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 880;
    opacity: 0;
    pointer-events: none;
    transition: opacity .3s;
  }
  .mobile-backdrop.active {
    opacity: 1;
    pointer-events: auto;
  }

  /* --- Modals: ボトムシート --- */
  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }
  .modal {
    border-radius: 16px 16px 0 0;
    max-height: 95vh;
    max-width: 100%;
    width: 100%;
  }

  /* --- Forms: 縦並び --- */
  .form-row { flex-direction: column; gap: 8px; }

  /* --- Photo grid: 2列 --- */
  .photo-grid { grid-template-columns: repeat(2, 1fr); }
  .photo-delete-btn { display: flex; } /* スマホは常に表示 */

  /* --- Toast: FABの上に表示 --- */
  .toast-container {
    bottom: 90px;
    right: 50%;
    left: auto;
    transform: translateX(50%);
    align-items: center;
  }
  .toast { text-align: center; }
}
