/* =====================================================
   三重県 栽培漁業 放流量マップ — style.css（共通）
   ===================================================== */

:root {
  --bg:          #f4f6f8;
  --surface:     #ffffff;
  --surface2:    #f9fafb;
  --border:      #e2e6ea;
  --border-dark: #cdd3da;
  --text:        #1a2332;
  --text-muted:  #6b7c93;
  --text-light:  #9aa8b8;
  --primary:     #1a6fa8;
  --primary-lt:  #e8f3fa;
  --primary-bd:  #c2ddf0;
  --accent:      #e8703a;
  --green:       #2e9e6b;
  --shadow-sm:   0 1px 4px rgba(0,0,0,.07);
  --shadow:      0 2px 12px rgba(0,0,0,.10);
  --shadow-lg:   0 4px 24px rgba(0,0,0,.14);
  --sidebar-w:   272px;
  --header-h:    52px;
  --transition:  0.25s ease;
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
button { cursor: pointer; font-family: inherit; }
a { text-decoration: none; }

body {
  font-family: 'Noto Sans JP', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ===== HEADER ===== */
header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 14px 0 20px;
  display: flex; align-items: center; gap: 12px;
  flex-shrink: 0; box-shadow: var(--shadow-sm); z-index: 200;
}
.header-logo { display: flex; align-items: center; gap: 10px; }
.logo-icon {
  width: 32px; height: 32px; background: var(--primary);
  border-radius: 8px; display: flex; align-items: center;
  justify-content: center; font-size: 17px; flex-shrink: 0;
}
.logo-text h1   { font-size: 15px; font-weight: 700; line-height: 1.2; }
.logo-text span { font-size: 10px; color: var(--text-muted); letter-spacing: .06em; }
.header-sep { width: 1px; height: 28px; background: var(--border); flex-shrink: 0; }
.data-status { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--text-muted); }
.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--border-dark); flex-shrink: 0; transition: background .3s;
}
.status-dot.loading { background: var(--accent); animation: blink 1s ease-in-out infinite; }
.status-dot.ok      { background: var(--green); box-shadow: 0 0 0 2px rgba(46,158,107,.2); }
.status-dot.error   { background: #e53e3e; }
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:.35} }

.header-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.btn-extract {
  display: flex; align-items: center; gap: 5px;
  background: var(--primary); color: #fff;
  border: none; border-radius: 7px; padding: 7px 12px;
  font-size: 12px; font-weight: 500;
  transition: background .15s; box-shadow: 0 1px 4px rgba(26,111,168,.3);
  cursor: pointer;
}
.btn-extract:hover { background: #155e8f; }
.sidebar-toggle {
  width: 30px; height: 30px; border-radius: 7px;
  border: 1px solid var(--border); background: var(--surface2);
  color: var(--text-muted); font-size: 11px;
  display: flex; align-items: center; justify-content: center;
  transition: all .15s;
}
.sidebar-toggle:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-lt); }

/* ===== LAYOUT ===== */
.layout { display: flex; flex: 1; overflow: hidden; }

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--surface); border-right: 1px solid var(--border);
  overflow-y: auto; display: flex; flex-direction: column;
  box-shadow: 2px 0 8px rgba(0,0,0,.04); z-index: 100;
  transition: width var(--transition), opacity var(--transition);
}
.sidebar.collapsed { width: 0; opacity: 0; overflow: hidden; border-right: none; }
.sidebar::-webkit-scrollbar { width: 3px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border-dark); border-radius: 2px; }

.sidebar-section { padding: 13px 14px; border-bottom: 1px solid var(--border); }
.sidebar-section:last-child { border-bottom: none; }

.section-label-row {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 9px;
}
.section-label {
  font-size: 10px; font-weight: 700; letter-spacing: .15em;
  text-transform: uppercase; color: var(--text-light);
}
.select-actions { display: flex; align-items: center; gap: 4px; }
.link-btn {
  background: none; border: none; font-size: 10px;
  color: var(--primary); padding: 0; text-decoration: underline; cursor: pointer;
}
.link-btn:hover { color: #155e8f; }
.sep { font-size: 10px; color: var(--border-dark); }

/* 魚種チェックリスト */
.fish-check-list { display: flex; flex-direction: column; gap: 3px; }
.fish-check-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; border-radius: 6px;
  border: 1.5px solid transparent;
  cursor: pointer; user-select: none; transition: background .1s;
}
.fish-check-item:hover { background: var(--surface2); }
.fish-check-item.checked { background: var(--primary-lt); border-color: var(--primary-bd); }
.fish-check-box {
  width: 16px; height: 16px; border-radius: 4px;
  border: 1.5px solid var(--border-dark); background: var(--surface);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; font-size: 10px; color: transparent; transition: all .12s;
}
.fish-check-item.checked .fish-check-box { border-color: var(--primary); background: var(--primary); color: #fff; }
.fish-color-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.fish-check-label { font-size: 12px; font-weight: 500; flex: 1; }
.fish-check-unit {
  font-size: 10px; color: var(--text-light);
  background: var(--surface2); padding: 1px 5px; border-radius: 3px;
}
.fish-check-item.checked .fish-check-unit { background: #d4eaf8; color: var(--primary); }

/* 地区チェックリスト */
.city-check-list { display: flex; flex-direction: column; gap: 2px; }
.city-check-item {
  display: flex; align-items: center; gap: 7px;
  padding: 5px 8px; border-radius: 6px;
  cursor: pointer; user-select: none;
  font-size: 12px; color: var(--text-muted); transition: background .1s;
}
.city-check-item:hover { background: var(--surface2); color: var(--text); }
.city-check-item.checked { background: var(--primary-lt); color: var(--primary); }
.city-check-box {
  width: 14px; height: 14px; border-radius: 3px;
  border: 1.5px solid var(--border-dark); background: var(--surface);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; font-size: 9px; color: transparent; transition: all .12s;
}
.city-check-item.checked .city-check-box { border-color: var(--primary); background: var(--primary); color: #fff; }

/* 統計 */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.stat-card { background: var(--surface2); border: 1px solid var(--border); border-radius: 8px; padding: 9px 10px; }
.stat-full { grid-column: 1 / -1; }
.stat-label { font-size: 10px; color: var(--text-muted); margin-bottom: 3px; }
.stat-value { font-family: 'DM Mono', monospace; font-size: 18px; font-weight: 500; color: var(--primary); line-height: 1; }
.stat-unit-row { font-size: 10px; color: var(--text-muted); margin-top: 2px; }
.stat-sub { font-size: 11px; color: var(--text); line-height: 1.4; margin-top: 2px; }

/* 凡例 */
.legend { display: flex; flex-direction: column; gap: 5px; }
.legend-row { display: flex; align-items: center; gap: 9px; font-size: 11px; color: var(--text-muted); }
.legend-circle { border-radius: 50%; flex-shrink: 0; opacity: .7; }

/* CSV ガイド */
.csv-guide { font-size: 11px; }
.csv-filename { color: var(--text-muted); margin-bottom: 6px; }
.csv-filename code { font-family: 'DM Mono', monospace; font-size: 11px; background: var(--surface2); padding: 1px 5px; border-radius: 3px; }
.csv-cols { display: block; font-family: 'DM Mono', monospace; font-size: 11px; background: var(--surface2); border: 1px solid var(--border); border-radius: 5px; padding: 6px 8px; margin-bottom: 6px; }
.csv-table { width: 100%; font-size: 10px; border-collapse: collapse; }
.csv-table th { text-align: left; padding: 3px 6px; background: var(--surface2); border: 1px solid var(--border); color: var(--text-muted); font-weight: 600; white-space: nowrap; }
.csv-table td { padding: 3px 6px; border: 1px solid var(--border); color: var(--text-muted); }

/* ===== MAP ===== */
.map-wrapper { flex: 1; display: flex; flex-direction: column; position: relative; overflow: hidden; }
#map { flex: 1; background: #e8eef4; }

.loading-overlay {
  display: none; position: absolute; inset: 0;
  background: rgba(244,246,248,.75); z-index: 400;
  align-items: center; justify-content: center; flex-direction: column;
  gap: 12px; backdrop-filter: blur(2px);
}
.loading-overlay.show { display: flex; }
.spinner { width: 34px; height: 34px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-msg { font-size: 12px; color: var(--text-muted); }

.error-banner {
  display: none; position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  background: #fff5f5; border: 1px solid #feb2b2; color: #c53030;
  border-radius: 8px; padding: 10px 16px; font-size: 12px; line-height: 1.5;
  z-index: 500; box-shadow: var(--shadow); max-width: 400px; text-align: center;
}
.error-banner.show { display: block; }

/* ===== TIME BAR ===== */
.time-bar {
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 10px 20px 13px; flex-shrink: 0;
  box-shadow: 0 -2px 8px rgba(0,0,0,.05); z-index: 100;
}
.time-row { display: flex; align-items: center; gap: 10px; margin-bottom: 9px; }
.year-display { font-family: 'DM Mono', monospace; font-size: 22px; font-weight: 500; color: var(--primary); min-width: 56px; line-height: 1; }
.play-btn {
  width: 30px; height: 30px; border-radius: 50%;
  border: 1.5px solid var(--border-dark); background: var(--surface);
  color: var(--text-muted); font-size: 11px;
  display: flex; align-items: center; justify-content: center;
  transition: all .15s; flex-shrink: 0;
}
.play-btn:hover   { border-color: var(--primary); color: var(--primary); background: var(--primary-lt); }
.play-btn.playing { border-color: var(--accent); color: var(--accent); background: #fff3ec; }
.time-label { font-size: 11px; color: var(--text-muted); }
.slider-wrap { position: relative; }
.year-ticks  { display: flex; justify-content: space-between; margin-bottom: 3px; }
.year-tick {
  font-family: 'DM Mono', monospace; font-size: 10px; color: var(--text-light);
  min-width: 36px; text-align: center; cursor: pointer; user-select: none; transition: color .12s;
}
.year-tick:hover  { color: var(--primary); }
.year-tick.active { color: var(--primary); font-weight: 600; }
input[type=range] {
  -webkit-appearance: none; width: 100%; height: 4px; border-radius: 2px;
  background: linear-gradient(to right, var(--primary) 0%, var(--primary) var(--pct,0%), var(--border) var(--pct,0%), var(--border) 100%);
  outline: none; cursor: pointer;
}
input[type=range]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; border: 2.5px solid var(--primary);
  box-shadow: 0 1px 6px rgba(26,111,168,.25); margin-top: -7px; cursor: pointer;
}
input[type=range]::-webkit-slider-thumb:hover { box-shadow: 0 2px 10px rgba(26,111,168,.4); }

/* ===== POPUP ===== */
.leaflet-popup-content-wrapper {
  border-radius: 10px !important; border: 1px solid var(--border) !important;
  box-shadow: var(--shadow-lg) !important; padding: 0 !important;
}
.leaflet-popup-content { margin: 0 !important; }
.leaflet-popup-tip { background: #fff !important; }
.leaflet-popup-close-button { top: 7px !important; right: 9px !important; font-size: 16px !important; }
.popup-inner { padding: 13px 15px; min-width: 210px; max-width: 280px; }
.popup-title { font-size: 13px; font-weight: 700; padding-bottom: 8px; margin-bottom: 8px; border-bottom: 1px solid var(--border); }
.popup-row { display: flex; justify-content: space-between; gap: 12px; font-size: 11px; color: var(--text-muted); margin-bottom: 4px; }
.popup-row:last-child { margin-bottom: 0; }
.popup-val { font-family: 'DM Mono', monospace; font-weight: 500; color: var(--primary); }
.popup-val.up   { color: #e53e3e; }
.popup-val.down { color: var(--green); }
.popup-history { margin-top: 9px; padding-top: 8px; border-top: 1px solid var(--border); }
.popup-history-title { font-size: 10px; color: var(--text-light); margin-bottom: 5px; font-weight: 600; letter-spacing: .08em; }
.popup-history-table { width: 100%; border-collapse: collapse; font-size: 11px; }
.popup-history-table th { font-size: 10px; color: var(--text-light); font-weight: 600; text-align: right; padding: 2px 4px; border-bottom: 1px solid var(--border); }
.popup-history-table th:first-child { text-align: left; }
.popup-history-table td { padding: 3px 4px; text-align: right; color: var(--text-muted); font-family: 'DM Mono', monospace; font-size: 11px; }
.popup-history-table td:first-child { text-align: left; color: var(--text); }
.popup-history-table tr.current td { background: var(--primary-lt); color: var(--primary); font-weight: 600; }

/* ===== LEAFLET CONTROLS ===== */
.leaflet-control-zoom a { background: var(--surface) !important; color: var(--text) !important; border-color: var(--border-dark) !important; box-shadow: var(--shadow-sm) !important; }
.leaflet-control-zoom a:hover { background: var(--primary-lt) !important; color: var(--primary) !important; }

/* ===== PC折りたたみボタン ===== */
.sidebar-toggle {
  width: 30px; height: 30px; border-radius: 7px;
  border: 1px solid var(--border-dark); background: var(--surface);
  color: var(--text-muted); font-size: 11px;
  display: flex; align-items: center; justify-content: center;
  transition: all .15s; flex-shrink: 0; cursor: pointer;
}
.sidebar-toggle:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-lt); }

/* ===== スマホ用ハンバーガーボタン（PCでは非表示） ===== */
.hamburger-btn {
  display: none;
  flex-direction: column; justify-content: center; align-items: center;
  gap: 5px; width: 36px; height: 36px;
  border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface2); cursor: pointer; padding: 0;
}
.hamburger-btn span {
  display: block; width: 18px; height: 2px;
  background: var(--text-muted); border-radius: 2px;
}

/* ===== パイチャートマーカー ===== */
.pie-marker { background: none !important; border: none !important; }

/* ===== 事業所マーカー ===== */
.office-marker { background: none !important; border: none !important; }
.office-label {
  background: rgba(255,255,255,0.92);
  border: 1px solid var(--border); border-radius: 4px;
  padding: 2px 7px; font-size: 11px;
  font-family: 'Noto Sans JP', sans-serif; font-weight: 600;
  color: #c0400a; white-space: nowrap; box-shadow: var(--shadow-sm);
}

/* ===== PC: サイドバー collapsed ===== */
@media (min-width: 769px) {
  .sidebar.collapsed {
    width: 0; opacity: 0; overflow: hidden; border-right: none;
  }
}

/* ===== スマホ（≤768px）===== */
@media (max-width: 768px) {
  .sidebar-toggle { display: none; }
  .hamburger-btn  { display: flex; }
  .logo-text span { display: none; }
  .data-status    { display: none; }
  .logo-text h1   { font-size: 13px; }
  .sidebar        { display: none; }   /* PC用サイドバーはスマホで非表示 */
  .time-bar       { padding: 8px 12px 10px; }
  .year-display   { font-size: 18px; }
  .time-label     { display: none; }
  .year-ticks     { display: none; }
  .btn-extract    { font-size: 11px; padding: 6px 10px; }
}
