:root {
  color-scheme: light;
  --ink: #17202a;
  --muted: #5d6a76;
  --line: #d9e0e6;
  --surface: #ffffff;
  --surface-soft: #f5f8fa;
  --teal: #0f766e;
  --blue: #2563eb;
  --red: #c2410c;
  --green: #168a4a;
  --amber: #b7791f;
  --shadow: 0 16px 48px rgba(23, 32, 42, 0.11);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Noto Sans TC", "PingFang TC", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: #eef3f6;
  color: var(--ink);
  letter-spacing: 0;
}

a {
  color: var(--blue);
}

button,
input {
  font: inherit;
}

.app-header {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-end;
  padding: 32px clamp(18px, 4vw, 48px) 20px;
  background: #f9fbfc;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--teal);
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 10px;
  font-size: clamp(1.85rem, 4vw, 3rem);
  line-height: 1.08;
}

h2 {
  margin-bottom: 6px;
  font-size: 1rem;
}

.subtitle {
  max-width: 760px;
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.7;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: max-content;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.88rem;
}

.header-tools {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-end;
}

.language-switcher {
  display: inline-grid;
  grid-template-columns: repeat(3, auto);
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
}

.language-button {
  min-height: 30px;
  padding: 0 10px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 700;
}

.language-button.active {
  background: #edf6f4;
  color: var(--teal);
}

.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--amber);
}

main {
  padding: 18px clamp(14px, 3vw, 32px) 32px;
}

.kpi-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.kpi-strip article,
.control-panel,
.case-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.kpi-strip article {
  padding: 16px;
}

.kpi-strip span,
.mini-summary span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
}

.kpi-strip strong {
  display: block;
  margin: 4px 0;
  font-size: clamp(1.55rem, 3vw, 2.25rem);
  line-height: 1;
}

.kpi-strip small {
  color: var(--muted);
}

.workspace {
  display: grid;
  grid-template-columns: 284px minmax(0, 1fr) 360px;
  gap: 14px;
  align-items: stretch;
}

.control-panel,
.case-panel {
  padding: 14px;
}

.segmented,
.filter-group {
  display: grid;
  gap: 8px;
}

.segmented {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.view-tab,
.filter-chip,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}

.view-tab svg,
.icon-button svg,
.search-box svg {
  width: 17px;
  height: 17px;
}

.view-tab.active,
.filter-chip.active,
.icon-button:hover {
  border-color: #b9c7d2;
  background: #ffffff;
  box-shadow: 0 4px 14px rgba(23, 32, 42, 0.07);
}

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 14px 0;
  padding: 0 12px;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-soft);
  color: var(--muted);
}

.search-box input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
}

.filter-group {
  margin-bottom: 14px;
}

.filter-chip {
  justify-content: flex-start;
  padding: 0 12px;
  border-color: var(--line);
  background: var(--surface);
}

.date-filter {
  display: grid;
  gap: 9px;
  margin: 14px 0 16px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.section-label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.date-preset-group {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.date-preset {
  min-height: 34px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 700;
}

.date-preset.active {
  border-color: #9db4c4;
  background: #edf6f4;
  color: var(--teal);
  box-shadow: 0 4px 14px rgba(23, 32, 42, 0.06);
}

.year-preset-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.year-preset {
  display: grid;
  gap: 1px;
  min-height: 42px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.year-preset strong {
  font-size: 0.86rem;
  line-height: 1.1;
}

.year-preset span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}

.year-preset.active {
  border-color: #9db4c4;
  background: #edf6f4;
  color: var(--teal);
  box-shadow: 0 4px 14px rgba(23, 32, 42, 0.06);
}

.date-input-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.date-input-grid label {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.date-input-grid span,
.date-filter small {
  color: var(--muted);
  font-size: 0.76rem;
}

.date-input-grid input {
  min-width: 0;
  width: 100%;
  min-height: 36px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
  color: var(--ink);
}

.chip-dot,
.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  display: inline-block;
}

.chip-dot.all {
  background: linear-gradient(90deg, var(--red) 0 33%, var(--amber) 33% 66%, var(--blue) 66% 100%);
}

.chip-dot.detained,
.legend-dot.detained {
  background: var(--red);
}

.chip-dot.outside,
.legend-dot.outside {
  background: var(--amber);
}

.chip-dot.sentenced,
.legend-dot.sentenced {
  background: var(--blue);
}

.case-marker {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 2px solid #ffffff;
  border-radius: 999px;
  color: #ffffff;
  font-size: 0.78rem;
  font-weight: 800;
  box-shadow: 0 8px 20px rgba(23, 32, 42, 0.28);
}

.case-marker.detained {
  background: var(--red);
}

.case-marker.released {
  background: var(--green);
}

.case-marker.prosecuted {
  background: var(--blue);
}

.case-marker.sentenced {
  background: var(--blue);
}

.case-marker.outside,
.case-marker.bailed,
.case-marker.transferred,
.case-marker.lead,
.case-marker.pending,
.case-marker.policy {
  background: var(--amber);
}

.toggle-row {
  display: grid;
  grid-template-columns: 38px 1fr;
  gap: 8px;
  align-items: center;
  margin: 16px 0;
  color: var(--ink);
  cursor: pointer;
}

.toggle-row b,
.map-legend b {
  font-weight: 600;
}

.toggle-row input {
  position: absolute;
  opacity: 0;
}

.toggle-row span {
  grid-column: 1;
  position: relative;
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: #c7d2da;
  transition: 180ms ease;
}

.toggle-row span::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 999px;
  background: #fff;
  box-shadow: 0 2px 5px rgba(23, 32, 42, 0.2);
  transition: 180ms ease;
}

.toggle-row input:checked + span {
  background: var(--teal);
}

.toggle-row input:checked + span::after {
  transform: translateX(16px);
}

.mini-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 12px 0;
}

.mini-summary div {
  padding: 12px;
  border-radius: 7px;
  background: #edf6f4;
}

.mini-summary strong {
  display: block;
  margin-top: 4px;
  font-size: 1.25rem;
}

.official-stats-panel {
  display: grid;
  gap: 10px;
  margin: 14px 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.official-stats-panel p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.45;
}

.official-stats-list {
  display: grid;
  gap: 10px;
}

.official-stat-group {
  display: grid;
  gap: 7px;
}

.official-stat-group h3 {
  margin: 0;
  color: var(--ink);
  font-size: 0.78rem;
}

.official-stat-rows {
  display: grid;
  gap: 6px;
}

.official-stat-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-height: 50px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-soft);
  color: var(--ink);
  text-decoration: none;
}

.official-stat-row:hover {
  border-color: #9db4c4;
  box-shadow: 0 6px 14px rgba(23, 32, 42, 0.07);
}

.official-stat-row span {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.official-stat-row b {
  overflow: hidden;
  font-size: 0.78rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.official-stat-row em {
  color: var(--muted);
  font-size: 0.68rem;
  font-style: normal;
  line-height: 1.25;
}

.official-stat-row strong {
  color: var(--teal);
  font-size: 1.05rem;
}

.region-overview {
  display: grid;
  gap: 9px;
  margin: 14px 0 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.region-list {
  display: grid;
  gap: 8px;
}

.region-sort {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.region-sort-button {
  min-width: 0;
  min-height: 32px;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 800;
}

.region-sort-button.active {
  border-color: #9db4c4;
  background: #edf6f4;
  color: var(--teal);
}

.region-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 6px 10px;
  width: 100%;
  min-height: 74px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
  color: var(--ink);
  cursor: pointer;
  text-align: left;
}

.region-row:hover {
  border-color: #9db4c4;
  box-shadow: 0 6px 14px rgba(23, 32, 42, 0.07);
}

.region-name {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  overflow: hidden;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.region-sample-flag {
  flex: 0 0 auto;
  padding: 2px 5px;
  border: 1px solid #d6c79b;
  border-radius: 999px;
  background: #fff7d8;
  color: #7a5a08;
  font-size: 0.62rem;
  font-weight: 800;
  line-height: 1;
}

.region-row.small-sample {
  border-style: dashed;
}

.region-row strong {
  font-size: 1.05rem;
  line-height: 1.1;
}

.region-row small {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 0.75rem;
}

.region-row .region-official {
  color: #315b66;
  font-weight: 750;
}

.region-row .region-coverage {
  color: #647075;
  font-weight: 750;
}

.region-breakdown {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.region-breakdown span {
  display: grid;
  gap: 1px;
  min-width: 0;
  padding: 5px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f7f9fb;
}

.region-breakdown b {
  font-size: 0.82rem;
  line-height: 1;
}

.region-breakdown em {
  overflow: hidden;
  color: var(--muted);
  font-size: 0.66rem;
  font-style: normal;
  font-weight: 700;
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.region-breakdown .outside b {
  color: var(--amber);
}

.region-breakdown .detained b {
  color: var(--red);
}

.region-breakdown .sentenced b {
  color: var(--blue);
}

.region-bar {
  grid-column: 1 / -1;
  height: 7px;
  border-radius: 999px;
  background: #e2e9ee;
  overflow: hidden;
}

.region-bar i {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--teal);
}

.region-toggle {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
  color: var(--teal);
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 800;
}

.region-toggle:hover {
  border-color: #9db4c4;
  background: #edf6f4;
}

.method-note {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.65;
}

.view-panel {
  min-height: 670px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.view {
  display: none;
  height: 100%;
}

.view.active {
  display: block;
}

#map {
  height: 670px;
  min-height: 58vh;
}

.map-legend {
  position: absolute;
  z-index: 500;
  right: calc(360px + 38px);
  bottom: 56px;
  display: flex;
  gap: 12px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--muted);
  font-size: 0.84rem;
  box-shadow: 0 8px 30px rgba(23, 32, 42, 0.12);
}

.map-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.date-head,
.case-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.date-head {
  padding: 18px 18px 8px;
}

.date-head p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.icon-button {
  min-width: 0;
  padding: 0 10px;
  border-color: var(--line);
  background: var(--surface);
}

.date-bars {
  display: grid;
  gap: 8px;
  padding: 10px 18px 16px;
}

.sync-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 8px 18px 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #edf6f4;
  color: var(--muted);
}

.sync-strip strong {
  color: var(--ink);
  white-space: nowrap;
}

.latest-list {
  display: grid;
  gap: 10px;
  max-height: 560px;
  overflow: auto;
  padding: 0 18px 18px;
}

.latest-card {
  display: grid;
  gap: 8px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.latest-card h3 {
  margin: 0;
  font-size: 0.98rem;
  line-height: 1.4;
}

.latest-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.55;
}

.latest-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.latest-meta span,
.latest-meta a {
  padding: 4px 7px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font-size: 0.74rem;
  text-decoration: none;
}

.latest-meta a {
  color: var(--blue);
}

.latest-badge {
  width: max-content;
  padding: 4px 8px;
  border-radius: 999px;
  color: #ffffff;
  font-size: 0.74rem;
  font-weight: 800;
}

.latest-badge.detained {
  background: var(--red);
}

.latest-badge.released,
.latest-badge.outside {
  background: var(--green);
}

.latest-badge.prosecuted,
.latest-badge.sentenced,
.badge.prosecuted,
.badge.sentenced {
  background: var(--blue);
}

.latest-badge.pending,
.latest-badge.policy,
.latest-badge.lead,
.latest-badge.transferred,
.latest-badge.bailed,
.badge.pending,
.badge.policy,
.badge.lead,
.badge.transferred,
.badge.bailed {
  background: var(--amber);
}

.date-bar-row {
  display: grid;
  grid-template-columns: 104px 1fr 48px;
  gap: 10px;
  align-items: center;
  color: var(--muted);
  font-size: 0.88rem;
}

.date-bar-track {
  position: relative;
  height: 26px;
  border-radius: 6px;
  background: var(--surface-soft);
  overflow: hidden;
}

.date-bar-fill {
  height: 100%;
  border-radius: 6px;
  background: var(--teal);
}

.timeline {
  list-style: none;
  margin: 0;
  padding: 0 18px 18px;
  max-height: 470px;
  overflow: auto;
}

.timeline li {
  position: relative;
  padding: 14px 0 14px 20px;
  border-top: 1px solid var(--line);
}

.timeline li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 21px;
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--teal);
}

.timeline time {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
}

.timeline strong {
  display: block;
  margin: 3px 0;
}

.timeline p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.55;
}

.case-panel {
  min-height: 670px;
}

.case-panel-head {
  margin-bottom: 12px;
}

.case-panel h2,
.date-head h2 {
  margin: 0;
  font-size: 1.05rem;
}

.case-list {
  display: grid;
  gap: 10px;
  max-height: 606px;
  overflow: auto;
  padding-right: 3px;
}

.case-card {
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  cursor: pointer;
  transition:
    transform 150ms ease,
    border-color 150ms ease,
    box-shadow 150ms ease;
}

.case-card:hover,
.case-card.active {
  transform: translateY(-1px);
  border-color: #9db4c4;
  box-shadow: 0 8px 20px rgba(23, 32, 42, 0.08);
}

.case-card-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: flex-start;
}

.case-card h3 {
  margin: 0;
  font-size: 0.98rem;
  line-height: 1.35;
}

.badge {
  flex: 0 0 auto;
  padding: 4px 7px;
  border-radius: 999px;
  color: #fff;
  font-size: 0.74rem;
  font-weight: 700;
}

.badge.detained {
  background: var(--red);
}

.badge.released,
.badge.outside {
  background: var(--green);
}

.case-card p {
  margin: 8px 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.55;
}

.case-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.case-meta span,
.case-meta a {
  padding: 4px 7px;
  border-radius: 999px;
  background: #ffffff;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.74rem;
}

.case-meta a {
  color: var(--blue);
  font-weight: 700;
  text-decoration: none;
}

.case-meta a:hover {
  border-color: #9db4c4;
  background: #f7fbff;
}

.leaflet-popup-content {
  margin: 12px;
  line-height: 1.55;
}

.popup-title {
  display: block;
  margin-bottom: 5px;
  font-weight: 800;
}

.popup-link {
  display: inline-block;
  margin-top: 7px;
}

.source-band {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 430px);
  gap: 24px;
  margin-top: 18px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.source-band p,
.source-band li {
  color: var(--muted);
  line-height: 1.65;
}

.source-band ul {
  margin: 0;
  padding-left: 18px;
}

.empty-state {
  padding: 16px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: var(--surface-soft);
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 280px minmax(0, 1fr);
  }

  .case-panel {
    grid-column: 1 / -1;
    min-height: 0;
  }

  .case-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-height: none;
  }

  .map-legend {
    right: 36px;
  }
}

@media (max-width: 820px) {
  .app-header,
  .source-band {
    display: block;
  }

  .status-pill {
    margin-top: 16px;
    min-width: 0;
  }

  .header-tools {
    align-items: flex-start;
    margin-top: 16px;
  }

  .kpi-strip,
  .workspace,
  .case-list {
    grid-template-columns: 1fr;
  }

  .view-panel,
  .case-panel {
    min-height: 0;
  }

  #map {
    height: 560px;
  }

  .map-legend {
    position: static;
    margin: 10px;
    flex-wrap: wrap;
  }

  .date-bar-row {
    grid-template-columns: 88px 1fr 34px;
  }
}

@media (max-width: 520px) {
  main {
    padding-inline: 10px;
  }

  .app-header {
    padding-inline: 16px;
  }

  .kpi-strip article {
    padding: 14px;
  }

  .date-head,
  .case-panel-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .icon-button {
    width: 100%;
  }

  .language-switcher {
    width: 100%;
  }

  .language-button {
    width: 100%;
  }

  .sync-strip {
    align-items: flex-start;
    flex-direction: column;
  }
}
