/* ============================================================
   app.css — map.kamiichi.app 共通スタイル
   スマホファースト設計
   ============================================================ */

/* --- Reset & Base ------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #1f2937;
  --accent: #2563eb;
  --accent-light: #3b82f6;
  --bg: #f9fafb;
  --card-bg: #ffffff;
  --text: #1f2937;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -2px rgba(0,0,0,.05);
  --header-h: 48px;
  --bottom-sheet-handle: 32px;
}

html { font-size: 16px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  overflow-x: hidden;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- Header ------------------------------------------------ */
.header {
  position: fixed; top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: var(--primary);
  color: #fff;
  display: flex; align-items: center;
  padding: 0 12px;
  z-index: 1100;
  box-shadow: var(--shadow);
}
.header__back {
  color: #fff; font-size: 1.3rem; margin-right: 8px;
  background: none; border: none; cursor: pointer;
  display: flex; align-items: center;
}
.header__title {
  font-size: .95rem; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  flex: 1;
}

/* --- Map Container ----------------------------------------- */
#map {
  position: fixed;
  top: var(--header-h);
  left: 0; right: 0;
  bottom: 0;
  z-index: 1;
}

/* --- Map Controls ------------------------------------------ */
.map-btn {
  position: fixed;
  z-index: 1000;
  width: 40px; height: 40px;
  border-radius: 8px;
  border: none;
  background: var(--card-bg);
  box-shadow: var(--shadow);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem;
}
.map-btn:active { background: var(--border); }

.btn-geolocate { right: 12px; bottom: 160px; }
.btn-zoom-extent { right: 12px; bottom: 110px; }

/* --- Layer Control Panel ----------------------------------- */
.layer-control-toggle {
  position: fixed;
  top: calc(var(--header-h) + 8px);
  right: 12px;
  z-index: 1050;
}
.layer-panel {
  display: none;
  position: fixed;
  top: calc(var(--header-h) + 48px);
  right: 12px;
  width: 260px;
  max-height: 60vh;
  overflow-y: auto;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 12px;
  z-index: 1050;
}
.layer-panel.is-open { display: block; }
.layer-panel h4 {
  font-size: .8rem; color: var(--text-muted);
  margin: 8px 0 4px; text-transform: uppercase; letter-spacing: .5px;
}
.layer-panel label {
  display: flex; align-items: center; gap: 6px;
  font-size: .85rem; padding: 4px 0; cursor: pointer;
}

/* --- Bottom Sheet ------------------------------------------ */
.bottom-sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: var(--card-bg);
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: 0 -2px 10px rgba(0,0,0,.12);
  z-index: 1050;
  transition: transform .3s ease;
  max-height: 70vh;
  display: flex; flex-direction: column;
}
.bottom-sheet.is-collapsed {
  transform: translateY(calc(100% - var(--bottom-sheet-handle) - 44px));
}
.bottom-sheet__handle {
  height: var(--bottom-sheet-handle);
  display: flex; align-items: center; justify-content: center;
  cursor: grab;
  flex-shrink: 0;
}
.bottom-sheet__handle::after {
  content: '';
  width: 36px; height: 4px;
  background: var(--border); border-radius: 2px;
}
.bottom-sheet__search {
  padding: 0 12px 8px;
  flex-shrink: 0;
}
.bottom-sheet__search input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: .9rem;
  outline: none;
}
.bottom-sheet__search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(37,99,235,.15);
}

/* --- Category Filter Chips --------------------------------- */
.category-chips {
  display: flex; gap: 6px;
  padding: 0 12px 8px;
  overflow-x: auto;
  flex-shrink: 0;
  -webkit-overflow-scrolling: touch;
}
.category-chips::-webkit-scrollbar { display: none; }
.chip {
  flex-shrink: 0;
  padding: 4px 12px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--card-bg);
  font-size: .78rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, color .15s;
}
.chip.is-active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* --- List -------------------------------------------------- */
.bottom-sheet__list {
  flex: 1; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.list-item {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .1s;
}
.list-item:active { background: #f3f4f6; }
.list-item__name { font-size: .9rem; font-weight: 600; }
.list-item__sub { font-size: .78rem; color: var(--text-muted); margin-top: 2px; }

/* --- Popup ------------------------------------------------- */
.leaflet-popup-content { font-size: .85rem; line-height: 1.5; }
.popup-table { width: 100%; border-collapse: collapse; }
.popup-table td {
  padding: 3px 6px;
  border-bottom: 1px solid var(--border);
  font-size: .82rem;
  vertical-align: top;
}
.popup-table td:first-child {
  color: var(--text-muted);
  white-space: nowrap;
  width: 30%;
}

/* --- Footer / Attribution ---------------------------------- */
.attribution-bar {
  background: var(--primary);
  color: rgba(255,255,255,.7);
  font-size: .7rem;
  padding: 8px 12px;
  line-height: 1.5;
}
.attribution-bar a { color: rgba(255,255,255,.9); }

/* --- Top Page ---------------------------------------------- */
.top-container {
  padding: calc(var(--header-h) + 16px) 12px 24px;
  max-width: 600px;
  margin: 0 auto;
}
.top-container h1 { font-size: 1.2rem; margin-bottom: 4px; }
.top-container .desc {
  font-size: .85rem; color: var(--text-muted); margin-bottom: 16px;
}
.card-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.card {
  display: flex; flex-direction: column;
  justify-content: center; align-items: center;
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 8px;
  text-align: center;
  color: var(--text);
  transition: box-shadow .15s, transform .15s;
  text-decoration: none;
}
.card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
  text-decoration: none;
}
.card__icon { font-size: 1.6rem; margin-bottom: 6px; }
.card__title { font-size: .85rem; font-weight: 600; }

/* --- Desktop --------------------------------------------- */
@media (min-width: 768px) {
  .top-container { max-width: 700px; }
  .card-grid { grid-template-columns: repeat(3, 1fr); gap: 14px; }
  .bottom-sheet {
    left: auto; right: 0;
    width: 360px;
    max-height: calc(100vh - var(--header-h));
    border-radius: 0;
    top: var(--header-h);
    bottom: 0;
  }
  .bottom-sheet.is-collapsed {
    transform: translateX(calc(100% - 32px));
  }
  .bottom-sheet__handle { display: none; }
}
