:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --text: #1d2229;
  --muted: #5d6673;
  --line: #dde1e6;
  --accent: #c8102e;
  --accent-ink: #ffffff;
  --header-h: 52px;
  --side-w: 360px;
  font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "BIZ UDPGothic", Meiryo, system-ui, sans-serif;
  color: var(--text);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); }
body { display: flex; flex-direction: column; }
button { font: inherit; }

/* ---------- ヘッダー ---------- */
.app-header {
  height: var(--header-h); flex: none;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 0 14px; background: var(--accent); color: var(--accent-ink);
}
.brand { display: flex; align-items: baseline; gap: 12px; min-width: 0; }
.brand h1 { margin: 0; font-size: 18px; letter-spacing: .04em; white-space: nowrap; }
.publisher { font-size: 12px; opacity: .9; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.last-loaded { font-size: 12px; opacity: .92; }
.last-loaded.error { background: #fff3; padding: 2px 6px; border-radius: 4px; }
.btn {
  border: 1px solid #ffffff99; background: transparent; color: inherit;
  padding: 6px 12px; border-radius: 6px; cursor: pointer; font-size: 14px;
}
.btn:hover { background: #ffffff22; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: #fff; color: var(--accent); border-color: #fff; font-weight: 700; }
.btn-primary:hover { background: #fff; opacity: .9; }
.list-toggle { display: none; }

.notice {
  flex: none; background: #fff4d6; color: #5a4300; border-bottom: 1px solid #f0d98c;
  padding: 7px 14px; font-size: 13px;
}

/* ---------- レイアウト ---------- */
.layout { flex: 1; display: flex; min-height: 0; }
.sidebar {
  width: var(--side-w); flex: none; display: flex; flex-direction: column;
  background: var(--panel); border-right: 1px solid var(--line); min-height: 0;
}
.map { flex: 1; min-width: 0; }

.filters { padding: 12px; border-bottom: 1px solid var(--line); display: grid; gap: 10px; }
.search input {
  width: 100%; padding: 9px 11px; font-size: 15px;
  border: 1px solid var(--line); border-radius: 8px; background: #fafbfc;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  --c: #666;
  display: inline-flex; align-items: center; gap: 6px;
  border: 1.5px solid var(--c); color: var(--c); background: #fff;
  padding: 5px 10px; border-radius: 999px; font-size: 13px; cursor: pointer;
}
.chip.on { background: var(--c); color: #fff; }
.chip .count { font-size: 11px; background: #0000001a; border-radius: 999px; padding: 0 6px; min-width: 20px; text-align: center; }
.toggle { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); cursor: pointer; }
.sort { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.sort select { flex: 1; padding: 5px; border: 1px solid var(--line); border-radius: 6px; font: inherit; }

.summary { padding: 8px 12px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--line); }
.item-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.item-list .empty { padding: 24px 12px; text-align: center; color: var(--muted); font-size: 14px; }
.item {
  display: flex; width: 100%; text-align: left; gap: 10px;
  padding: 10px 12px; border: 0; border-bottom: 1px solid var(--line); background: #fff; cursor: pointer;
}
.item:hover { background: #f6f8fb; }
.item.selected { background: #eef4ff; }
.item.ended { opacity: .65; }
.item-body { display: grid; gap: 3px; min-width: 0; }
.item-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.item-cat { font-weight: 700; color: var(--text); }
.item-title { font-size: 14px; font-weight: 700; line-height: 1.4; }
.item-addr { font-size: 12px; color: var(--muted); }
.status {
  font-size: 11px; padding: 1px 6px; border-radius: 4px;
  background: #fde8e8; color: #a3122a; font-weight: 700;
}
.status.ended { background: #eceef1; color: #5d6673; }

.side-footer { padding: 8px 12px; font-size: 12px; border-top: 1px solid var(--line); color: var(--muted); }
.side-footer a { color: var(--muted); }

/* ---------- アイコン ---------- */
.ico {
  --c: #666;
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  border-radius: 50%; background: var(--c);
}
.ico svg { display: block; }
.chip .ico { margin-left: -4px; box-shadow: 0 0 0 1.5px #fff; }

/* ---------- 地図上の要素 ---------- */
.pin {
  --c: #666;
  width: 34px; height: 34px; border-radius: 50% 50% 50% 0;
  background: var(--c); transform: rotate(-45deg);
  display: flex; align-items: center; justify-content: center;
  border: 2px solid #fff; box-shadow: 0 2px 6px #0007;
}
.pin span { transform: rotate(45deg); display: flex; }
.pin.ended { opacity: .8; }
.pin.selected { box-shadow: 0 0 0 4px #ffd400, 0 2px 6px #0007; }
.refdot {
  --c: #666;
  border-radius: 50%; background: var(--c);
  border: 2px solid #fff; box-shadow: 0 1px 3px #0006;
  display: flex; align-items: center; justify-content: center;
}
.legend {
  background: #fffffff2; padding: 6px 10px; border-radius: 8px; box-shadow: 0 1px 5px #0003;
  font-size: 12px; line-height: 1.6;
}
.legend-toggle { border: 0; background: none; font-weight: 700; padding: 0; cursor: pointer; font-size: 12px; }
.legend-toggle::after { content: " ▾"; }
.legend.closed .legend-toggle::after { content: " ▸"; }
.legend.closed .legend-body { display: none; }
.legend-row { display: flex; align-items: center; gap: 6px; margin-top: 3px; }

/* サイドバーのタブ */
.side-tabs { display: flex; flex: none; border-bottom: 1px solid var(--line); }
.side-tab {
  flex: 1; padding: 10px 6px; border: 0; background: #f3f5f8; cursor: pointer;
  font-size: 13px; font-weight: 700; color: var(--muted); border-bottom: 3px solid transparent;
}
.side-tab.on { background: #fff; color: var(--text); border-bottom-color: var(--accent); }
.side-panel { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.side-panel[hidden] { display: none; }
#panel-layers { overflow-y: auto; }

/* レイヤーパネル */
.lp-tools { display: flex; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); flex: none; }
.lp-btn { flex: 1; padding: 7px 8px; border: 1px solid #c3c9d1; border-radius: 6px; background: #fff; cursor: pointer; font-size: 13px; }
.lp-btn:hover { background: #f3f5f8; }
.lp-group { border-bottom: 1px solid var(--line); }
.lp-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px; background: #f7f8fa; }
.lp-fold { border: 0; background: none; font-weight: 700; font-size: 14px; cursor: pointer; padding: 2px 0; text-align: left; color: var(--text); }
.lp-fold::before { content: "▾ "; color: var(--muted); }
.lp-group.closed .lp-fold::before { content: "▸ "; }
.lp-group.closed .lp-body { display: none; }
.lp-all { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 4px; cursor: pointer; white-space: nowrap; }
.lp-body { padding: 4px 0; }
.lp-row { display: flex; align-items: center; gap: 8px; padding: 6px 12px; font-size: 14px; cursor: pointer; }
.lp-row:hover { background: #f6f8fb; }
.lp-row input[type=checkbox], .lp-row input[type=radio] { width: 17px; height: 17px; flex: none; margin: 0; }
.lp-row.sub { font-size: 13px; color: var(--muted); padding-left: 16px; }
.lp-row.solo { padding: 10px 12px; border-bottom: 1px solid var(--line); }
.lp-name { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.lp-hint { font-size: 11px; color: var(--muted); }
.lp-count { font-size: 11px; color: var(--muted); background: #eef0f3; border-radius: 999px; padding: 0 7px; min-width: 22px; text-align: center; }
.lp-row.ov { flex-direction: column; align-items: stretch; gap: 4px; cursor: default; }
.lp-ovlabel { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.lp-opacity { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); padding-left: 25px; }
.lp-opacity[hidden] { display: none; }
.lp-opacity input { flex: 1; }
.lp-note { font-size: 11px; color: var(--muted); padding: 8px 12px; margin: 0; }
.line-swatch { --c: #666; width: 24px; height: 24px; flex: none; display: inline-block; position: relative; }
.line-swatch::after { content: ""; position: absolute; left: 1px; right: 1px; top: 10px; height: 4px; border-radius: 2px; background: var(--c); }

/* 地図のボタン・クラスタ・名称ラベル */
.map-btns { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.map-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 10px;
  background: #fff; border: 2px solid #0003; border-radius: 6px; cursor: pointer; font-size: 13px; font-weight: 700; color: #333;
  background-clip: padding-box;
}
.map-btn:hover { background: #f3f5f8; }
.map-btns .locate-btn { width: 36px; justify-content: center; padding: 0; font-size: 18px; }
.cluster {
  --c: #666;
  display: flex; align-items: center; justify-content: center; border-radius: 50%;
  background: var(--c); color: #fff; font-weight: 700; font-size: 13px;
  border: 3px solid #fff; box-shadow: 0 0 0 4px color-mix(in srgb, var(--c) 35%, transparent), 0 2px 6px #0005;
}
.leaflet-tooltip.ref-label {
  background: #ffffffe6; border: 0; box-shadow: 0 1px 3px #0004; padding: 1px 6px;
  font-size: 12px; font-weight: 700; color: #1d2229;
}
.leaflet-tooltip.ref-label::before { display: none; }
.legend-sep { border-top: 1px solid var(--line); margin: 5px 0 2px; }
.legend-row.muted { color: var(--muted); }
.legend-body { max-height: 46vh; overflow-y: auto; }

/* アイコン選択 */
.icon-picker { position: relative; }
.ip-current {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 4px 8px; min-height: 40px;
  border: 1px solid #c3c9d1; border-radius: 6px; background: #fff; cursor: pointer; font-size: 14px; text-align: left; color: var(--text);
}
.ip-current span:nth-child(2) { flex: 1; }
.ip-caret { color: var(--muted); }
.ip-pop {
  position: absolute; z-index: 3000; top: calc(100% + 4px); left: 0; width: min(400px, 86vw); max-height: 360px; overflow-y: auto;
  background: #fff; border: 1px solid #c3c9d1; border-radius: 8px; box-shadow: 0 6px 20px #0003; padding: 8px;
}
.ip-group { font-size: 12px; font-weight: 700; color: var(--muted); margin: 6px 2px 4px; }
.ip-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; }
.ip-item {
  display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 2px; border: 1px solid transparent;
  border-radius: 6px; background: none; cursor: pointer; font-size: 10.5px; line-height: 1.25; color: var(--text); text-align: center;
}
.ip-item:hover { background: #f3f5f8; }
.ip-item.on { border-color: var(--c, #1f6fd1); background: #eef4ff; }
.ip-default { flex-direction: row; width: 100%; justify-content: flex-start; padding: 6px; font-size: 13px; gap: 8px; }

.popup h3 { margin: 6px 0; font-size: 15px; line-height: 1.4; }
.popup-head { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.badge { color: #fff; font-size: 11px; padding: 2px 8px; border-radius: 999px; font-weight: 700; }
.popup .detail { margin: 6px 0; font-size: 13px; line-height: 1.6; }
.popup dl { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; margin: 6px 0; font-size: 12px; }
.popup dt { color: var(--muted); }
.popup dd { margin: 0; }
.popup-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.popup-actions a, .popup-actions button {
  font-size: 12px; padding: 4px 10px; border: 1px solid var(--line); border-radius: 6px;
  background: #fff; color: var(--text); text-decoration: none; cursor: pointer;
}

/* ---------- スマートフォン ---------- */
@media (max-width: 800px) {
  .publisher, .last-loaded { display: none; }
  .brand h1 { font-size: 16px; }
  .list-toggle { display: inline-block; }
  .layout { position: relative; overflow: hidden; }   /* 隠れている一覧が下（広告など）にはみ出さないように */
  .sidebar {
    position: absolute; inset: 0; width: 100%; z-index: 1100;
    transform: translateY(100%); transition: transform .22s ease; border-right: 0;
  }
  body.sidebar-open .sidebar { transform: none; }
  .legend { display: none; }
}

/* ---------- 印刷 ---------- */
@media print {
  .sidebar, .header-actions, .leaflet-control-zoom, .leaflet-control-layers, .locate-btn { display: none !important; }
  .app-header { background: none; color: #000; border-bottom: 2px solid #000; }
  html, body { height: auto; }
  .map { height: 180mm; }
}

/* アイコンなし・面と線の見本 */
.ico.none i { width: 38%; height: 38%; border-radius: 50%; background: #fff; display: block; }
.pin-dot { display: block; width: 10px; height: 10px; border-radius: 50%; background: #fff; }
.refdot.plain { border-width: 2px; }
.area-swatch { --c: #666; --fo: .2; flex: none; display: inline-block; box-sizing: border-box; border: 2.5px solid var(--c); border-radius: 4px;
  background: color-mix(in srgb, var(--c) calc(var(--fo) * 100%), transparent); }
.line-swatch.dash::after { background: repeating-linear-gradient(90deg, var(--c) 0 5px, transparent 5px 8px); }
.leaflet-tooltip.area-label {
  background: none; border: 0; box-shadow: none; padding: 0; font-size: 12px; font-weight: 700; color: #1d2229;
  text-shadow: 0 0 3px #fff, 0 0 3px #fff, 0 0 2px #fff;
}
.leaflet-tooltip.area-label::before { display: none; }

/* 書き出し画面 */
.link-btn { border: 0; background: none; color: var(--muted); text-decoration: underline; cursor: pointer; font: inherit; font-size: 12px; padding: 0; }
.dm-modal { position: fixed; inset: 0; z-index: 6000; background: #1d2229b3; display: flex; align-items: flex-start; justify-content: center; overflow-y: auto; padding: 32px 12px; }
.dm-modal-card { background: #fff; border-radius: 12px; padding: 18px; width: min(620px, 100%); display: grid; gap: 12px; }
.dm-modal-card h2 { margin: 0; font-size: 18px; }
.dm-modal-card fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px 10px; margin: 0; }
.dm-modal-card legend { font-size: 13px; font-weight: 700; padding: 0 4px; }
.exp-actions { display: flex; gap: 12px; justify-content: flex-end; }
.exp-targets { display: grid; gap: 2px; max-height: 240px; overflow-y: auto; }
.exp-targets.disabled { opacity: .4; pointer-events: none; }
.exp-row { display: flex; align-items: center; gap: 8px; padding: 4px 2px; font-size: 14px; cursor: pointer; }
.exp-row .exp-name { flex: 1; }
.exp-row.sub { font-size: 13px; color: var(--muted); border-top: 1px dashed var(--line); margin-top: 4px; padding-top: 8px; }
.exp-count { font-size: 12px; color: var(--muted); }
.exp-formats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.exp-fmt { display: flex; gap: 8px; align-items: flex-start; padding: 8px; border: 1.5px solid var(--line); border-radius: 8px; cursor: pointer; font-size: 13px; }
.exp-fmt small { color: var(--muted); }
.exp-fmt:has(input:checked) { border-color: #1f6fd1; background: #f2f7ff; }
.exp-fmt.backup { grid-column: 1 / -1; }
.exp-note { font-size: 12px; color: var(--muted); margin: 8px 0 0; line-height: 1.6; }
.exp-btns { display: flex; gap: 8px; }
.exp-btns .primary { flex: 1; }
.dm-modal .big-btn { display: inline-flex; align-items: center; justify-content: center; min-height: 42px; padding: 8px 16px; border-radius: 8px; cursor: pointer;
  border: 1.5px solid #c3c9d1; background: #fff; font-size: 15px; font-weight: 700; color: var(--text); }
.dm-modal .big-btn.primary { background: #1f6fd1; border-color: #1f6fd1; color: #fff; }
.dm-modal .msg { font-size: 13px; margin: 0; min-height: 1em; }
.dm-modal .msg.err { color: #c8102e; font-weight: 700; }
.dm-modal .msg.ok { color: #16804a; }
@media (max-width: 600px) { .exp-formats { grid-template-columns: 1fr; } }

/* インポートデータの状態（開設中・停電・運休など） */
.spill { --c: #666; display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 4px; margin-right: 3px;
  color: #fff; background: var(--c); white-space: nowrap; }
.spill.normal { background: #eef0f3; color: var(--muted); }
.spill.closed { background: #eceef1; color: #5d6673; }
.popup-status { margin: 4px 0; }
.popup .hint-line { font-size: 12px; color: var(--muted); margin: 4px 0; }
.leaflet-tooltip.area-label.active { font-size: 13px; color: #111; }
.leaflet-tooltip.ref-label.status { background: #fff; border: 1.5px solid #0003; font-size: 11.5px; }
.ref-label.status::before { display: none; }

/* 災害情報の写真 */
.popup-photos { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0; }
.popup-photos a { display: block; flex: 1 1 30%; max-width: 100%; }
.popup-photos img { display: block; width: 100%; height: 90px; object-fit: cover; border-radius: 6px; border: 1px solid #0002; background: #eee; }
.popup-photos a:only-child img { height: 150px; }
.has-photo { font-size: 12px; }
/* 画面下のリンク（報告・編集）。表示されているもの同士の間に「・」 */
.side-footer > span:not([hidden]) ~ span:not([hidden])::before { content: " ・ "; color: var(--muted); }

/* 広告の表示位置（画面の一番下。中身がなければ表示しない） */
.ad-slot { flex: none; text-align: center; background: #fff; border-top: 1px solid var(--line); overflow: hidden; max-height: 120px; }
.ad-slot:empty { display: none; }
@media print { .ad-slot { display: none; } }
