:root {
  color-scheme: light;
  --ink: #132521;
  --muted: #687773;
  --line: #dce4e1;
  --panel: #ffffff;
  --soft: #f2f6f4;
  --accent: #087f6a;
  --accent-dark: #075f51;
  --danger: #bd3e2b;
  --shadow: 0 18px 48px rgba(21, 43, 36, .10);
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  width: 100%;
  max-width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  color: var(--ink);
  background: #edf2f0;
}
button, input, select, textarea { font: inherit; }
button { border: 1px solid #c9d6d2; border-radius: 8px; background: #fff; color: var(--ink); padding: 8px 12px; cursor: pointer; }
button:hover { border-color: var(--accent); }
button:disabled { opacity: .55; cursor: wait; }
button.primary { background: var(--accent); color: white; border-color: var(--accent); }
button.primary:hover { background: var(--accent-dark); }
button.secondary { background: #eaf5f1; color: var(--accent-dark); border-color: #aed2c8; }
button.danger { background: #fff3f1; color: var(--danger); border-color: #e6b5ad; }
button.ghost { background: transparent; border-color: transparent; }
button.small { padding: 5px 8px; font-size: 12px; }
.wide { width: 100%; }
.hidden { display: none !important; }
.error-text { color: var(--danger); min-height: 1.4em; }

.topbar {
  min-height: 76px;
  padding: 12px 18px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #f9fbfa;
  border-bottom: 1px solid var(--line);
}
.topbar h1 { margin: 0; font-size: 24px; letter-spacing: .02em; }
.eyebrow { margin: 0 0 2px; color: var(--accent); text-transform: uppercase; font-size: 11px; letter-spacing: .13em; font-weight: 800; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.current-user { color: var(--accent-dark); font-size: 12px; font-weight: 700; white-space: nowrap; }
.freshness { max-width: 360px; color: var(--muted); font-size: 12px; text-align: right; }

.shell {
  height: calc(100vh - 76px);
  height: calc(100dvh - 76px);
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(360px, 1fr) minmax(300px, 350px);
  gap: 1px;
  background: var(--line);
}
.shell.event-mode {
  grid-template-columns: minmax(350px, 420px) minmax(360px, 1fr) minmax(440px, 520px);
}
.sidebar, .detail {
  background: #f8faf9;
  overflow: auto;
  overscroll-behavior: contain;
  min-width: 0;
  min-height: 0;
}
.sidebar { padding: 12px; display: flex; flex-direction: column; gap: 10px; overflow-x: hidden; }
.detail { padding: 16px; }
.detail-sticky-header {
  position: sticky;
  z-index: 8;
  top: -16px;
  margin: -16px -16px 0;
  padding: 16px 16px 8px;
  border-bottom: 1px solid var(--line);
  background: rgba(248, 250, 249, .97);
  backdrop-filter: blur(8px);
}
.detail-heading-copy { min-width: 0; }
.detail-meta { margin: 5px 0 0; color: var(--muted); font-size: 11px; line-height: 1.45; }
.event-overall-status {
  display: inline-block;
  margin-top: 7px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
}
.event-overall-status.critical { color: #a3271b; background: #fbe4e1; }
.event-overall-status.warning { color: #8b5700; background: #fdf0dc; }
.event-overall-status.info { color: #315e86; background: #e7f1fa; }
.event-overall-status.normal { color: #08725e; background: #e5f5ef; }
.event-overall-status.unknown { color: #596762; background: #e9eeec; }
.event-result-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
}
.event-result-tabs button {
  min-width: 0;
  padding: 7px 3px;
  border-color: transparent;
  background: transparent;
  font-size: 11px;
  line-height: 1.25;
}
.event-result-tabs button.active {
  border-color: #c6d9d2;
  background: #e7f3ef;
  color: var(--accent-dark);
}
.event-result-tabs button:disabled { opacity: .45; }
.tab-count {
  display: inline-block;
  min-width: 18px;
  padding: 1px 4px;
  border-radius: 999px;
  background: #d7e7e2;
  font-size: 10px;
}
.source-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; }
.source-tabs button { padding: 7px 4px; font-size: 12px; }
.source-tabs button.active { background: #183d35; color: white; border-color: #183d35; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 12px; box-shadow: 0 5px 16px rgba(18, 46, 38, .035); }
.panel.grow { flex: 1; min-height: 280px; }
.panel h2, .detail h2 { margin: 0; font-size: 16px; }
.panel h3 { margin: 12px 0 4px; }
.panel-heading { display: flex; justify-content: space-between; align-items: start; gap: 10px; margin-bottom: 10px; }
.heading-actions, .event-management { display: flex; flex-wrap: wrap; gap: 6px; }
.count { min-width: 28px; padding: 3px 7px; border-radius: 999px; background: #e6f3ef; color: var(--accent-dark); text-align: center; font-size: 12px; font-weight: 700; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0; }
.field-grid > *, .two-cols > *, .workflow-actions > * { min-width: 0; }
#query-panel .field-grid > label:nth-child(n + 3) { grid-column: 1 / -1; }
.query-mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  margin-top: 10px;
  padding: 4px;
  border-radius: 9px;
  background: #edf2f0;
}
.query-mode-switch button { border-color: transparent; background: transparent; }
.query-mode-switch button.active {
  border-color: #bfd2cc;
  background: #fff;
  color: var(--accent-dark);
  box-shadow: 0 2px 7px rgba(18, 46, 38, .08);
}
.history-time-fields {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}
.realtime-query-status {
  display: grid;
  gap: 5px;
  margin: 8px 0;
  padding: 8px;
  border: 1px solid #d7e5e0;
  border-radius: 8px;
  background: #f3f9f7;
  font-size: 11px;
}
.realtime-query-status span { color: var(--muted); line-height: 1.45; }
label { display: grid; gap: 4px; font-size: 12px; color: #44544f; }
input, select, textarea { width: 100%; max-width: 100%; min-width: 0; border: 1px solid #cfdad6; border-radius: 7px; padding: 7px 8px; background: white; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(8, 127, 106, .18); border-color: var(--accent); }
.help { color: var(--muted); font-size: 12px; line-height: 1.5; }
.filter-input { margin-bottom: 8px; }
.station-filters {
  display: grid;
  grid-template-columns: 1fr;
  gap: 7px;
  margin-bottom: 8px;
}

.station-list, .event-list { display: grid; gap: 6px; max-height: 42vh; overflow: auto; }
.station-row, .event-row { width: 100%; text-align: left; display: grid; gap: 3px; padding: 9px; border-color: #e0e7e4; }
.station-row strong, .event-row strong { font-size: 13px; }
.station-row span, .event-row span { color: var(--muted); font-size: 11px; }
.station-row.active { border-color: var(--accent); background: #edf8f4; }
.risk-badge { justify-self: start; width: fit-content; padding: 2px 6px; border-radius: 999px; background: #eef2f1; }
.risk-badge.critical { color: #a51e15; background: #fde9e7; }
.risk-badge.warning { color: #965900; background: #fff1d7; }
.risk-badge.normal { color: #08725e; background: #e7f5f1; }
.reading { display: flex; justify-content: space-between; align-items: baseline; }
.reading b { color: var(--accent-dark); font-size: 15px; }

.map-workspace {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: #d8e2de;
  min-width: 0;
  min-height: 0;
}
#map { position: relative; width: 100%; min-width: 0; min-height: 0; }
.map-toolbar {
  min-height: 45px;
  position: relative;
  z-index: 4;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px 12px;
  padding: 7px 10px;
  background: rgba(255,255,255,.94);
  border-bottom: 1px solid var(--line);
}
.layer-panel {
  flex: 1 1 auto;
  width: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
}
.layer-panel > summary { display: none; }
.layer-controls { display: flex; gap: 9px; align-items: center; flex-wrap: wrap; }
.layer-controls label { display: flex; gap: 4px; align-items: center; white-space: nowrap; font-size: 11px; }
.layer-controls input { width: auto; }
.persistent-layer-controls { display: contents; }
.overlay-help {
  flex: 1 0 100%;
  margin: 0;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.45;
}
#map-status {
  color: var(--muted);
  flex: 1 1 180px;
  font-size: 11px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.map-legend {
  position: absolute;
  z-index: 4;
  bottom: 22px;
  left: 12px;
  width: min(720px, calc(100% - 24px));
  max-height: min(310px, calc(100% - 44px));
  margin: 0;
  overflow: auto;
  padding: 8px 10px 10px;
  border: 1px solid rgba(191, 204, 199, .9);
  border-radius: 10px;
  background: rgba(255,255,255,.94);
  box-shadow: 0 10px 28px rgba(18, 46, 38, .16);
  backdrop-filter: blur(5px);
  font-size: 11px;
}
.map-legend summary { color: #23443b; font-size: 12px; }
.legend-groups { display: grid; gap: 7px; margin-top: 8px; }
.legend-group { display: grid; grid-template-columns: 96px minmax(0, 1fr); align-items: center; gap: 7px; }
.legend-group > strong { color: #334f47; font-size: 11px; }
.legend-items { display: flex; flex-wrap: wrap; gap: 5px 10px; }
.legend-item { display: inline-flex; align-items: center; gap: 4px; color: #40554f; white-space: nowrap; }
.legend-symbol {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  flex: 0 0 28px;
  border: 2px solid #fff;
  border-radius: 50%;
  color: #fff;
  box-shadow: 0 0 0 1px rgba(40, 63, 56, .22), 0 2px 5px rgba(22, 47, 39, .15);
}
.legend-symbol::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 13px;
  height: 13px;
  transform: translate(-50%, -50%);
  background: #fff;
}
.legend-symbol[data-shape="circle"]::after { border-radius: 50%; }
.legend-symbol[data-shape="ring"]::after {
  width: 14px;
  height: 14px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: transparent;
}
.legend-symbol[data-shape="half"]::after {
  width: 15px;
  height: 15px;
  border: 2px solid #fff;
  border-radius: 50%;
  background: linear-gradient(90deg, #fff 0 50%, transparent 50% 100%);
}
.legend-symbol[data-shape="square"]::after {
  width: 13px;
  height: 13px;
  border-radius: 2px;
}
.legend-symbol[data-shape="triangle"]::after {
  width: 15px;
  height: 14px;
  clip-path: polygon(50% 3%, 97% 94%, 3% 94%);
}
.legend-symbol[data-shape="diamond"]::after {
  width: 13px;
  height: 13px;
  border-radius: 2px;
  transform: translate(-50%, -50%) rotate(45deg);
}
.legend-symbol[data-shape="diamond-outline"]::after {
  width: 12px;
  height: 12px;
  border: 3px solid #fff;
  border-radius: 2px;
  background: transparent;
  transform: translate(-50%, -50%) rotate(45deg);
}
.legend-symbol.normal { background: #249bd0; }
.legend-symbol.warning { background: #f08c19; }
.legend-symbol.critical { background: #e23a2e; }
.legend-symbol.overflow { background: #b20d28; }
.legend-symbol.unknown { background: #899894; color: #fff; }
.legend-sewer .legend-symbol.normal { background: #137c6d; }
.legend-sewer .legend-symbol.warning { background: #f39c12; }
.legend-sewer .legend-symbol.critical,
.legend-sewer .legend-symbol.overflow { background: #d52b1e; }
.legend-surface .legend-symbol.normal { background: #249bd0; }
.legend-surface .legend-symbol.warning { background: #f39c12; }
.legend-surface .legend-symbol.critical { background: #d52b1e; }
.legend-rain .legend-symbol.normal { background: #1769aa; }
.legend-rain .legend-symbol.critical { background: #d52b1e; }
.legend-layers { display: flex; flex-wrap: wrap; gap: 7px 14px; padding-top: 6px; border-top: 1px solid #e3eae7; color: var(--muted); }
.dot { display: inline-block; width: 9px; height: 9px; margin-right: 3px; border-radius: 50%; }
.dot.rain { background: #1769aa; }.dot.sewer { background: #137c6d; }.dot.regional { background: #7048b8; }.dot.surface { background: #249bd0; }.dot.emic { background: #d44230; }
.selection-ring {
  display: inline-block;
  width: 14px;
  height: 14px;
  margin-right: 3px;
  vertical-align: -2px;
  border: 3px solid #ffe000;
  border-radius: 50%;
  background: transparent;
  box-shadow: 0 0 0 1px rgba(80, 70, 0, .25);
}

.detail-content { margin-top: 12px; color: #354640; font-size: 13px; line-height: 1.65; }
.detail-grid { display: grid; grid-template-columns: 100px 1fr; gap: 7px 8px; }
.detail-grid dt { color: var(--muted); }.detail-grid dd { margin: 0; word-break: break-word; }
.chart { margin-top: 18px; min-height: 250px; border-top: 1px solid var(--line); padding-top: 12px; overflow: hidden; }
.chart svg { width: 100%; height: 240px; overflow: visible; }
.chart .axis { stroke: #91a09b; stroke-width: 1; }.chart .grid { stroke: #e6ece9; }.chart .series { fill: none; stroke: var(--accent); stroke-width: 2; }.chart .area { fill: rgba(8,127,106,.10); }
.chart text { fill: #667772; font-size: 10px; }
.thresholds { font-size: 12px; color: var(--muted); }

.event-form { display: grid; gap: 8px; margin-bottom: 12px; padding: 10px; border-radius: 9px; background: var(--soft); }
.two-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.event-workspace { border-top: 1px solid var(--line); margin-top: 12px; padding-top: 10px; }
.event-management { margin: 8px 0; }
.workflow-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin: 10px 0; }
details { margin: 10px 0; border: 1px solid var(--line); border-radius: 8px; padding: 8px; }
summary { cursor: pointer; font-weight: 700; font-size: 13px; }
.review-form { display: grid; gap: 7px; margin-top: 10px; }
.review-form h4 { margin: 9px 0 0; }
.field-help { margin: -3px 0 4px 26px; color: var(--muted); font-size: 11px; line-height: 1.5; }
.field-help.report-position { margin-left: 0; padding: 6px 8px; border-left: 3px solid var(--accent); background: color-mix(in srgb, var(--accent) 7%, transparent); }
label.check { display: flex; align-items: center; gap: 7px; }
label.check input { width: auto; }
.district-review { display: grid; gap: 8px; }
.district-card {
  display: grid;
  gap: 6px;
  min-width: 0;
  margin: 0;
  padding: 8px 10px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--soft);
}
.district-card.pending { border-color: #e0b483; background: #fdf6ee; }
.district-card legend { padding: 0 4px; font-weight: 700; font-size: 13px; }
.district-status { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
.district-card.pending .district-status { color: #a1651b; }
.emic-cause-review {
  display: grid;
  gap: 9px;
  margin-top: 12px;
  padding-top: 11px;
  border-top: 1px solid var(--line);
}
.emic-confirmed-cause {
  display: grid;
  gap: 3px;
  padding: 8px 9px;
  border: 1px solid #dfc087;
  border-radius: 8px;
  background: #fff8eb;
}
.emic-confirmed-cause strong { color: #936018; }
.emic-confirmed-cause.confirmed {
  border-color: #94c6b5;
  background: #e9f6f0;
}
.emic-confirmed-cause.confirmed strong { color: var(--accent-dark); }
.emic-confirmed-cause.unable {
  border-color: #c8cfcc;
  background: #f3f5f4;
}
.emic-confirmed-cause.unable strong { color: #596763; }
.site-cause-card {
  display: grid;
  gap: 7px;
  min-width: 0;
  margin: 0;
  padding: 9px 10px 10px;
  border: 1px solid #c8dad4;
  border-radius: 9px;
  background: #f7fbf9;
}
.site-cause-card legend {
  max-width: 100%;
  padding: 0 4px;
  overflow-wrap: anywhere;
  font-weight: 700;
  font-size: 12px;
}
.site-cause-auto {
  display: grid;
  gap: 3px;
  padding: 7px 8px;
  border-radius: 7px;
  background: #eaf4f0;
  font-size: 11px;
}
.site-cause-auto span { overflow-wrap: anywhere; }
.site-cause-auto b { display: inline-block; min-width: 66px; color: var(--accent-dark); }
.site-cause-auto small { color: var(--muted); line-height: 1.45; }
.site-cause-auto .quality-warning { color: #9b5e14; }
.cause-evidence-help { margin-left: 0; }
.cause-code-field { display: grid; gap: 5px; }
.cause-code-options {
  display: grid;
  gap: 4px;
  max-height: 205px;
  padding: 7px;
  overflow-y: auto;
  border: 1px solid #cfdad6;
  border-radius: 7px;
  background: white;
}
.cause-code-option {
  align-items: flex-start !important;
  padding: 3px 4px;
  border-radius: 5px;
  font-size: 11px;
  line-height: 1.4;
}
.cause-code-option.candidate { background: #edf7f3; }
.cause-code-option span { display: flex; flex-wrap: wrap; gap: 0 4px; }
.cause-code-option small {
  padding: 0 4px;
  border-radius: 8px;
  background: #d8eee5;
  color: var(--accent-dark);
  font-size: 9px;
}

.field-block { display: grid; gap: 5px; }
.field-block-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; }
.field-block-actions { display: flex; gap: 6px; }
.field-block-actions button { width: auto; }
.field-note { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
.checkbox-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  gap: 2px 8px;
  max-height: 188px;
  padding: 7px 8px;
  overflow-y: auto;
  border: 1px solid #cfdad6;
  border-radius: 7px;
  background: white;
}
.checkbox-list label.check { font-size: 12px; }
.collect-steps .checkbox-list { grid-template-columns: 1fr; max-height: 232px; margin-top: 6px; }

.alert-station-panel { margin: 10px 0; }
.alert-filters { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.alert-filters button { width: auto; }
.alert-filters button.active { border-color: var(--accent); background: var(--accent); color: white; }
.alert-station-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.alert-station-table th, .alert-station-table td { padding: 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.alert-station-table tbody tr[data-alert-station] { cursor: pointer; }
.alert-station-table tbody tr[data-alert-station]:hover { background: var(--soft); }
.alert-station-table tbody tr.active { background: #e6f4f0; box-shadow: inset 3px 0 0 var(--accent); }
.alert-station-table td small { display: block; color: var(--muted); }
.alert-tag { display: inline-block; padding: 1px 6px; border-radius: 999px; font-size: 11px; white-space: nowrap; }
.alert-tag.critical { background: #fbe4e1; color: #a3271b; }
.alert-tag.warning { background: #fdf0dc; color: #92600f; }
.alert-tag.info { background: #e2eef8; color: #1c5a86; }

.event-station-view { margin: 12px 0; padding: 10px; border: 1px solid #cbdcd6; border-radius: 10px; background: #f8fbfa; }
.event-station-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.event-station-heading h3 { margin: 0; font-size: 15px; }
.event-station-view .detail-content { margin-top: 8px; }
.event-station-view .chart { margin-top: 12px; }
.map-station-output {
  margin: 12px 0;
  padding: 10px;
  border: 1px solid #cbdcd6;
  border-radius: 10px;
  background: #f6fbf9;
}
.map-station-output-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.map-station-output-heading span {
  color: var(--accent);
  font-size: 12px;
}
.selected-map-stations { display: grid; gap: 6px; margin-top: 8px; }
.selected-map-station {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 8px;
  border: 1px solid #dce7e3;
  border-radius: 8px;
  background: #fff;
}
.selected-map-station span { display: grid; min-width: 0; }
.selected-map-station strong { overflow-wrap: anywhere; }
.selected-map-station small { color: var(--muted); }
.selected-map-station button {
  width: auto;
  flex: 0 0 auto;
  padding: 5px 8px;
  color: #9d2b24;
  border-color: #efc8c3;
  background: #fff7f6;
}
.job-progress-wrap {
  display: grid;
  gap: 5px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}
.job-progress-wrap[hidden] { display: none; }
.job-progress-wrap progress {
  width: 100%;
  height: 11px;
  accent-color: var(--accent);
}
.job-progress-wrap.failed progress { accent-color: var(--danger); }
.job-progress-wrap.success { color: var(--accent-dark); }
.job-progress-wrap.failed { color: var(--danger); }
.job-status { margin-top: 10px; padding: 8px; border-radius: 7px; background: var(--soft); font-size: 12px; white-space: pre-wrap; }
.event-downloads { display: grid; gap: 5px; margin-top: 8px; font-size: 11px; }
.event-downloads:empty { display: none; }
.event-downloads a { color: var(--accent-dark); text-decoration: underline; }

.event-results { display: grid; gap: 10px; }
.event-result-pane { display: grid; gap: 12px; min-width: 0; }
.event-result-pane.hidden { display: none; }
.result-card-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
.result-card { display: grid; gap: 2px; padding: 8px; border: 1px solid var(--line); border-radius: 8px; background: var(--soft); }
.result-card strong { color: var(--accent-dark); font-size: 15px; }
.result-card span { color: var(--muted); font-size: 10px; }
.event-overall-banner {
  display: grid;
  gap: 3px;
  padding: 11px;
  border: 1px solid var(--line);
  border-left: 6px solid #84948f;
  border-radius: 9px;
  background: #fff;
}
.event-overall-banner strong { font-size: 15px; }
.event-overall-banner span { color: var(--muted); font-size: 11px; }
.event-overall-banner.critical { border-left-color: #d52b1e; background: #fff6f5; }
.event-overall-banner.warning { border-left-color: #f39c12; background: #fffaf0; }
.event-overall-banner.info { border-left-color: #4688bd; background: #f3f8fc; }
.event-overall-banner.normal { border-left-color: var(--accent); background: #f4fbf8; }
.event-overall-banner.unknown { border-left-color: #7b8b85; background: #f4f6f5; }
.event-coverage-note {
  display: grid;
  gap: 3px;
  padding: 9px;
  border-radius: 8px;
  background: #f1f5f3;
  font-size: 11px;
}
.event-coverage-note span, .event-coverage-note small { color: var(--muted); }
.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}
.section-heading > div { display: grid; gap: 2px; }
.section-heading small { color: var(--muted); font-weight: 400; line-height: 1.4; }
.summary-alerts { display: grid; gap: 6px; }
.cause-summary { display: grid; gap: 7px; }
.cause-district-result {
  margin: 0;
  padding: 7px 8px;
  background: #f8fbfa;
}
.cause-district-result > p {
  margin: 7px 2px;
  color: #40534c;
  font-size: 11px;
  line-height: 1.55;
}
.cause-district-result > .cause-counts {
  color: var(--accent-dark);
}
.cause-site-results { display: grid; gap: 5px; }
.cause-site-result {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 7px;
  padding: 7px;
  border: 1px solid #dbe6e2;
  border-radius: 7px;
  background: #fff;
  font-size: 11px;
}
.cause-site-result > span { display: grid; gap: 2px; min-width: 0; overflow-wrap: anywhere; }
.cause-site-result small { color: var(--muted); font-size: 10px; }
.cause-site-conclusion { color: var(--accent-dark); }
.cause-site-conclusion.pending { color: #956015; }
.cause-site-conclusion.unable { color: #64716d; }
.summary-alert-row {
  width: 100%;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px;
  align-items: start;
  text-align: left;
}
.summary-alert-row > span:last-child { display: grid; gap: 2px; min-width: 0; }
.summary-alert-row small { color: var(--muted); overflow-wrap: anywhere; }
.event-stale-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 9px;
  border: 1px solid #cfe1db;
  border-radius: 8px;
  background: #f3faf7;
}
.event-stale-bar.stale { border-color: #e5bf8c; background: #fff8ee; }
.event-stale-bar > span { display: grid; gap: 2px; min-width: 0; }
.event-stale-bar small { color: var(--muted); overflow-wrap: anywhere; }
.event-stale-bar button { flex: 0 0 auto; width: auto; }
.alert-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.alert-card { display: grid; gap: 3px; padding: 9px; border: 1px solid var(--line); border-left: 5px solid #84948f; border-radius: 8px; background: #fff; }
.alert-card span { font-size: 11px; color: var(--muted); }
.alert-card.critical { border-left-color: #d52b1e; background: #fff6f5; }
.alert-card.warning { border-left-color: #f39c12; background: #fffaf0; }
.alert-card.normal { border-left-color: var(--accent); }
.alert-card.reference { border-left-color: #7048b8; }
.alert-station-list { display: grid; gap: 7px; min-width: 0; }
.alert-station-card {
  width: 100%;
  min-width: 0;
  display: grid;
  gap: 4px;
  padding: 9px;
  text-align: left;
  overflow-wrap: anywhere;
}
.alert-station-card.aggregate { border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.alert-station-card-heading {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}
.alert-station-card > span:not(.alert-station-card-heading),
.alert-station-card small { color: var(--muted); font-size: 11px; }
.alert-station-card b { color: var(--ink); font-size: 12px; }
.alert-open-hint { color: var(--accent) !important; }
.alert-tag.unknown { background: #e9eeec; color: #596762; }
.alert-tag.normal { background: #e5f5ef; color: #08725e; }
.compact-filter { max-width: 220px; }
.event-station-filters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}
.event-station-filters .station-search { grid-column: 1 / -1; }
.event-alert-only { grid-column: 1 / -1; }
.event-station-results { display: grid; gap: 6px; min-width: 0; }
.event-station-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px;
  align-items: stretch;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
}
.event-station-row.active { border-color: var(--accent); background: #eef8f5; }
.event-station-main {
  min-width: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 7px;
  border-color: transparent;
  background: transparent;
  text-align: left;
}
.event-station-main > span { display: grid; gap: 2px; min-width: 0; }
.event-station-main small { color: var(--muted); overflow-wrap: anywhere; }
.event-station-reading { text-align: right; }
.event-station-reading b { color: var(--accent-dark); }
.map-select-button { align-self: center; width: auto; }
.map-select-button.selected { border-color: #e1b6ad; background: #fff1ef; color: #a3271b; }
.event-period-label { margin: 4px 0 0; color: var(--muted); font-size: 11px; }
.table-scroll { max-width: 100%; overflow: auto; }
.event-results table { width: 100%; border-collapse: collapse; font-size: 11px; }
.event-results th, .event-results td { padding: 6px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.status-chip { display: inline-block; padding: 2px 5px; border-radius: 999px; background: #edf2f0; white-space: nowrap; }
.status-chip.成功 { color: var(--accent-dark); background: #e5f5ef; }
.status-chip.失敗 { color: var(--danger); background: #fde9e7; }
.status-chip.略過 { color: #805c00; background: #fff2cd; }
.result-stations { display: grid; gap: 5px; margin-top: 7px; max-height: 260px; overflow: auto; }
.result-stations button { display: grid; gap: 2px; text-align: left; }
.result-stations small { color: var(--muted); }
.empty-results { padding: 14px; border-radius: 10px; background: var(--soft); }

.modal-screen { position: fixed; inset: 0; z-index: 100; background: rgba(10, 29, 24, .78); display: grid; place-items: center; }
.login-card { width: min(420px, calc(100vw - 30px)); background: white; border-radius: 16px; padding: 26px; box-shadow: var(--shadow); display: grid; gap: 13px; }
.login-card h1 { margin: 0; }
.login-card p { margin: 0; color: var(--muted); line-height: 1.5; }
.login-card .error-text:not(:empty) {
  padding: 10px 12px;
  border: 1px solid #e4aaa1;
  border-radius: 8px;
  background: #fff3f1;
  color: var(--danger);
  font-weight: 700;
}
.login-card label small { color: var(--muted); font-size: 11px; line-height: 1.4; }
.login-card .login-help { padding: 9px 10px; border-radius: 8px; background: var(--soft); font-size: 12px; }
.auth-link { border: 0; background: transparent; color: var(--accent-dark); text-decoration: underline; box-shadow: none; }
.auth-link:hover { background: var(--soft); }
.admin-card { width: min(1040px, calc(100vw - 30px)); max-height: calc(100dvh - 30px); overflow: auto; padding: 22px; border-radius: 16px; background: #fff; box-shadow: var(--shadow); }
.admin-card h2, .admin-card h3 { margin-top: 0; }
.admin-form { display: grid; gap: 8px; margin: 10px 0 18px; padding: 12px; border-radius: 10px; background: var(--soft); }
.admin-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.user-list { display: grid; gap: 8px; }
.user-card { display: grid; grid-template-columns: 1.2fr 1fr 130px 110px; gap: 7px; align-items: end; padding: 10px; border: 1px solid var(--line); border-radius: 10px; }
.user-card > div { display: grid; align-self: center; }
.user-card small { color: var(--muted); }
.persistent-layer-list { display: grid; gap: 7px; margin: 8px 0; }
.persistent-layer-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
}
.persistent-layer-card > span { display: grid; gap: 2px; min-width: 0; }
.persistent-layer-card small { color: var(--muted); }
.persistent-layer-card .layer-card-actions {
  display: flex;
  flex-flow: row wrap;
  justify-content: flex-end;
}
.layer-source-badge {
  display: inline-block;
  margin-right: 5px;
  padding: 2px 6px;
  border-radius: 999px;
  background: #e8f1ee;
  color: #31564c;
  font-size: 10px;
}
.layer-source-badge.overridden {
  background: #fff0ce;
  color: #7a5300;
}
.persistent-layer-swatch {
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 5px;
  border: 1px solid rgba(0,0,0,.2);
  border-radius: 3px;
  vertical-align: -1px;
}
.audit-list { display: grid; gap: 5px; max-height: 300px; overflow: auto; margin-top: 8px; }
.audit-row { display: grid; grid-template-columns: 160px 1fr auto; gap: 8px; padding: 7px; border-bottom: 1px solid var(--line); font-size: 11px; }
.secret-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 9px 0;
  padding: 8px;
  border-radius: 8px;
  background: var(--soft);
  font-size: 12px;
}
.secret-status span { color: var(--muted); }
.secret-ready { color: var(--accent-dark); }
.secret-missing { color: #9b4a1c; }
.secret-form { display: grid; gap: 8px; }
.secret-actions { display: flex; flex-wrap: wrap; gap: 7px; }
.secret-actions button { width: auto; }
.location-badge {
  display: inline-block;
  width: fit-content;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}
.location-badge.unlocated { color: #9b4a1c; background: #fff0df; }
.location-badge.located { color: var(--accent-dark); background: #e5f5ef; }
.emic-location-action { display: flex; align-items: center; gap: 7px; margin-top: 10px; }
.emic-location-action button { width: auto; }
.emic-location-card {
  width: min(980px, calc(100vw - 28px));
  max-height: calc(100dvh - 28px);
  overflow: auto;
  padding: 18px;
  border-radius: 15px;
  background: #fff;
  box-shadow: var(--shadow);
}
.emic-location-layout {
  display: grid;
  grid-template-columns: minmax(300px, 1.15fr) minmax(280px, .85fr);
  gap: 12px;
}
.emic-candidate-map {
  position: relative;
  min-height: 420px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #d8e2de;
}
.emic-candidate-map > p {
  position: absolute;
  z-index: 1;
  inset: 50% auto auto 50%;
  width: 80%;
  margin: 0;
  color: var(--muted);
  text-align: center;
  transform: translate(-50%, -50%);
}
.emic-location-query-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}
.emic-location-query-heading .help { flex: 1; }
.emic-location-query-heading button { width: auto; flex: 0 0 auto; }
.emic-location-candidates { display: grid; gap: 7px; margin-top: 8px; }
.emic-candidate-card {
  width: 100%;
  display: grid;
  gap: 3px;
  padding: 9px;
  text-align: left;
}
.emic-candidate-card.active { border-color: var(--accent); background: #edf8f4; }
.emic-candidate-card span,
.emic-candidate-card small { color: var(--muted); overflow-wrap: anywhere; }
.emic-location-actions {
  position: sticky;
  bottom: -18px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin: 14px -18px -18px;
  padding: 10px 18px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255,255,255,.97);
}
.emic-location-actions button { width: auto; }
.toast { position: fixed; z-index: 90; right: 18px; bottom: 18px; max-width: 520px; padding: 11px 14px; border-radius: 9px; background: #153c33; color: white; box-shadow: var(--shadow); white-space: pre-wrap; }

@media (max-width: 1180px) {
  .shell { grid-template-columns: minmax(260px, 300px) minmax(320px, 1fr) minmax(270px, 310px); }
  .shell.event-mode { grid-template-columns: minmax(300px, 340px) minmax(320px, 1fr) minmax(380px, 440px); }
  .map-toolbar { align-items: flex-start; flex-direction: column; }
  #map-status { white-space: normal; }
  .admin-grid { grid-template-columns: 1fr 1fr; }
  .user-card { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 1050px) {
  html, body { height: auto; min-height: 100%; overflow-x: hidden; overflow-y: auto; }
  .topbar { height: auto; }
  .shell {
    height: auto;
    min-height: calc(100vh - 76px);
    min-height: calc(100dvh - 76px);
    grid-template-columns: minmax(0, 1fr);
  }
  .shell.event-mode { grid-template-columns: minmax(0, 1fr); }
  .sidebar, .detail { overflow: visible; }
  .detail-sticky-header { top: 0; }
  .detail.event-results-mode { width: 100%; }
  .map-workspace { height: 62vh; height: 62dvh; min-height: 460px; max-height: 720px; }
  .station-list { max-height: 300px; }
}
@media (max-width: 640px) {
  .core-layer-card { grid-template-columns: minmax(0, 1fr); }
  .persistent-layer-card .layer-card-actions { justify-content: stretch; }
  .persistent-layer-card .layer-card-actions button { flex: 1; }
}
@media (max-width: 640px) {
  button { min-height: 40px; }
  input, select, textarea { min-height: 42px; font-size: 16px; }
  textarea { min-height: 76px; }
  .topbar { align-items: stretch; flex-direction: column; gap: 9px; padding: 10px 12px; }
  .topbar h1 { font-size: 21px; }
  .top-actions { width: 100%; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 7px; }
  .current-user { grid-column: 1 / -1; }
  .freshness { grid-column: 1 / -1; max-width: none; text-align: left; line-height: 1.45; }
  .sidebar { padding: 8px; }
  .detail { padding: 12px; }
  .detail-sticky-header {
    margin: -12px -12px 0;
    padding: 12px 12px 7px;
  }
  .event-result-tabs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .event-result-tabs button { min-height: 42px; }
  .source-tabs { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .source-tabs button { min-height: 44px; padding: 6px 3px; font-size: 11px; line-height: 1.25; }
  .panel { padding: 10px; border-radius: 10px; }
  .panel.grow { min-height: 0; }
  .field-grid, .two-cols, .workflow-actions { grid-template-columns: minmax(0, 1fr); }
  .station-list, .event-list { max-height: 260px; }
  .map-workspace { height: 68vh; height: 68dvh; min-height: 520px; max-height: 760px; }
  .map-toolbar { padding: 5px 8px; gap: 4px; }
  .layer-panel > summary {
    display: list-item;
    width: fit-content;
    min-height: 34px;
    padding: 7px 10px;
    border: 1px solid #c9d6d2;
    border-radius: 8px;
    background: #fff;
    color: var(--accent-dark);
    font-size: 12px;
  }
  .layer-panel[open] > summary { margin-bottom: 6px; }
  .layer-controls {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 3px 8px;
  }
  .layer-controls label { min-height: 32px; white-space: normal; font-size: 11px; }
  .layer-controls button { grid-column: 1 / -1; width: 100%; min-height: 36px; }
  .overlay-help { grid-column: 1 / -1; }
  #map-status { width: 100%; min-height: 17px; white-space: nowrap; }
  .map-legend {
    right: 8px;
    bottom: 8px;
    left: 8px;
    width: auto;
    max-width: calc(100% - 16px);
    max-height: 65%;
  }
  .map-legend:not([open]) {
    right: auto;
    width: auto;
    max-width: calc(100% - 16px);
    max-height: none;
    padding: 6px 9px;
  }
  .legend-group { grid-template-columns: minmax(0, 1fr); gap: 4px; }
  .legend-items { gap: 5px 8px; }
  .detail-grid { grid-template-columns: 88px minmax(0, 1fr); }
  .alert-grid, .result-card-grid, .admin-grid, .user-card { grid-template-columns: minmax(0, 1fr); }
  .cause-site-result { grid-template-columns: minmax(0, 1fr); }
  .event-stale-bar { align-items: stretch; flex-direction: column; }
  .event-stale-bar button { width: 100%; }
  .event-station-filters { grid-template-columns: minmax(0, 1fr); }
  .event-station-filters .station-search,
  .event-alert-only { grid-column: auto; }
  .event-station-row { grid-template-columns: minmax(0, 1fr); }
  .event-station-main { grid-template-columns: minmax(0, 1fr); }
  .event-station-reading { text-align: left; }
  .map-select-button { width: 100%; }
  .emic-location-card {
    width: calc(100vw - 12px);
    max-height: calc(100dvh - 12px);
    padding: 12px;
  }
  .emic-location-layout { grid-template-columns: minmax(0, 1fr); }
  .emic-candidate-map { min-height: 280px; }
  .emic-location-actions {
    bottom: -12px;
    margin: 12px -12px -12px;
    padding: 9px 12px calc(9px + env(safe-area-inset-bottom));
  }
  .emic-location-actions button { flex: 1; min-width: 0; }
  .admin-card { width: calc(100vw - 16px); max-height: calc(100dvh - 16px); padding: 12px; }
  .audit-row { grid-template-columns: 1fr; }
  .chart { min-height: 230px; }
  .chart svg { height: 220px; }
  .job-status { position: sticky; top: 6px; z-index: 3; border: 1px solid #d5e4df; }
  .login-card { padding: 20px; }
  .toast {
    right: 10px;
    bottom: calc(10px + env(safe-area-inset-bottom));
    left: 10px;
    max-width: none;
  }
}
