:root {
  --bg: #f2f5f8;
  --surface: #ffffff;
  --ink: #12263a;
  --muted: #5a6e82;
  --line: #d5dee7;
  --navy: #062c4a;
  --brand: #0b4a73;
  --brand-dark: #062c4a;
  --accent: #2b8fc7;
  --brand-soft: #e3eef6;
  --warn-bg: #fff4d6;
  --warn-ink: #6b4b00;
  --err: #b3261e;
  --err-bg: #fdeceb;
  --ok: #1f7a3d;
  --ok-bg: #e4f4e8;
  --radius: 4px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; scroll-padding-top: 64px; }

/* 底層背景：氣泡花紋＋固定在畫面底部的海草／珊瑚剪影 */
body::before {
  content: ""; position: fixed; left: 0; right: 0; bottom: 0; height: 240px;
  background: url("images/seabed.svg") center bottom / cover no-repeat;
  opacity: .16; z-index: -1; pointer-events: none;
}

body {
  margin: 0;
  background: var(--bg) url("images/bubbles.svg") repeat;
  color: var(--ink);
  font-family: "Noto Sans TC", "Microsoft JhengHei", "PingFang TC", system-ui, sans-serif;
  line-height: 1.65;
  font-size: 16px;
}
a { color: var(--brand); }

/* 頂端列 */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 20px;
  padding: 10px clamp(16px, 5vw, 56px);
  background: rgba(6, 44, 74, .96);
  backdrop-filter: blur(6px);
  color: #fff;
}
.brand { color: #fff; font-weight: 800; text-decoration: none; font-size: 1.05rem; letter-spacing: .04em; }
.nav { display: flex; gap: 6px; overflow-x: auto; }
.nav a {
  color: #fff; text-decoration: none; padding: 5px 14px; font-size: .86rem; white-space: nowrap;
  background: #0b4a73; border: 1px solid rgba(255,255,255,.18); border-radius: 3px;
}
.nav a:hover, .nav a:focus-visible { background: var(--accent); }

.mock-banner {
  background: var(--warn-bg); color: var(--warn-ink);
  padding: 10px clamp(16px, 5vw, 56px); font-size: .9rem; border-bottom: 1px solid #ecd9a0;
}

/* 首屏 */
.hero {
  position: relative; overflow: hidden; color: #fff;
  background:
    url("images/waves.svg") center bottom / 100% 90px no-repeat,
    url("images/fish.svg") right 24% bottom 70px / 460px auto no-repeat,
    radial-gradient(ellipse at 20% 110%, rgba(43,143,199,.55), transparent 60%),
    linear-gradient(160deg, #04243d 0%, #0b4a73 55%, #1c6f9c 100%);
  padding: clamp(36px, 7vw, 84px) clamp(16px, 5vw, 56px) clamp(90px, 10vw, 130px);
}
.hero::before, .hero::after {
  content: ""; position: absolute; border-radius: 50%;
  border: 1px solid rgba(255,255,255,.14); pointer-events: none;
}
.hero::before { width: 520px; height: 520px; right: 8%; top: 50%; transform: translateY(-50%); box-shadow: 0 0 0 60px rgba(255,255,255,.03), 0 0 0 130px rgba(255,255,255,.025); }
.hero::after { width: 260px; height: 260px; right: calc(8% + 130px); top: 50%; transform: translateY(-50%); background: rgba(255,255,255,.04); }
.hero-inner { position: relative; z-index: 1; max-width: 1180px; margin: 0 auto; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 32px; }
.hero-text { flex: 1 1 420px; max-width: 640px; }
.eyebrow { margin: 0 0 12px; font-size: .78rem; letter-spacing: .22em; color: #9fd3ee; font-weight: 700; }
.hero h1 { margin: 0 0 14px; font-size: clamp(1.9rem, 4.6vw, 3rem); line-height: 1.25; font-weight: 800; }
.hero p { margin: 0 0 22px; color: #d3e6f2; max-width: 56ch; }
.hero-link {
  display: inline-block; padding: 9px 22px; background: #fff; color: var(--navy); font-weight: 700;
  text-decoration: none; border-radius: 3px; font-size: .92rem;
}
.hero-link:hover { background: #cfe8f6; }

.steps { list-style: none; margin: 0; padding: 0 0 0 22px; border-left: 1px solid rgba(255,255,255,.35); display: flex; flex-direction: column; gap: 14px; }
.steps li { display: flex; align-items: baseline; gap: 12px; font-size: .95rem; color: #bcd9ea; }
.steps b { font-size: 1.5rem; font-weight: 300; letter-spacing: .04em; color: #fff; min-width: 2ch; }
.steps li:first-child b { color: #6ec1ea; }

/* 統計列 */
.stat-strip {
  background: #fff; border-bottom: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  padding: 0 clamp(16px, 5vw, 56px);
}
.stat-strip .s { padding: 22px 12px; text-align: center; border-right: 1px solid var(--line); }
.stat-strip .s:last-child { border-right: 0; }
.stat-strip b { display: block; font-size: 2rem; font-weight: 800; color: var(--brand); line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat-strip span { font-size: .84rem; color: var(--muted); }

main { max-width: 1120px; margin: 0 auto; padding: 8px 16px 16px; }

.panel {
  background: rgba(255, 255, 255, .94); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 24px; margin: 22px 0; box-shadow: 0 1px 2px rgba(6,44,74,.05);
}
.panel h2 {
  margin: 0 0 12px; font-size: 1.35rem; color: var(--navy); font-weight: 800;
  padding-left: 12px; border-left: 4px solid var(--accent); line-height: 1.3;
}
.panel h3 { margin: 22px 0 8px; font-size: 1.05rem; color: var(--brand); }
.hint, .tiny { color: var(--muted); font-size: .86rem; margin: 4px 0 10px; }

/* 表單 */
label { display: flex; flex-direction: column; gap: 4px; font-size: .88rem; font-weight: 700; color: var(--navy); }
input[type="text"], input[type="number"], input[type="search"], select, textarea {
  font: inherit; font-weight: 400; color: var(--ink);
  padding: 8px 10px; border: 1px solid #b4c4d2; border-radius: 3px; background: #fff; width: 100%;
}
textarea { font-family: ui-monospace, Consolas, "Courier New", monospace; font-size: .86rem; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible, summary:focus-visible, a:focus-visible {
  outline: 3px solid #79bfe6; outline-offset: 1px;
}
.invalid { border-color: var(--err) !important; background: var(--err-bg) !important; }

.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; margin-bottom: 12px; }
.inputs { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 12px; }
.inputs .grow { flex: 1 1 380px; }
.inputs .side { flex: 0 1 260px; display: flex; flex-direction: column; gap: 8px; }
.filters { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 12px; }
.filters label { flex: 1 1 180px; }
.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; margin: 8px 0; }
.row-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 10px 0; }

/* 按鈕 */
.btn {
  font: inherit; font-size: .9rem; cursor: pointer; text-align: center;
  padding: 8px 16px; border-radius: 3px; border: 1px solid #9db4c6;
  background: #fff; color: var(--navy); font-weight: 700;
}
.btn:hover { background: var(--brand-soft); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--navy); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--err); border-color: #e2aaa6; }
.btn.danger:hover { background: var(--err-bg); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 12px; margin: 12px 0 4px; }
.pager-info { color: var(--muted); font-size: .92rem; min-width: 9em; text-align: center; }
.filebtn { position: relative; overflow: hidden; display: block; }
.filebtn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }

/* 訊息 */
.msg { margin: 8px 0 0; padding: 0; font-size: .92rem; }
.msg:empty { display: none; }
.msg.error, .msg.success, .msg.info { padding: 10px 12px; border-radius: 3px; }
.msg.error { background: var(--err-bg); color: var(--err); border: 1px solid #f0bcb8; }
.msg.success { background: var(--ok-bg); color: var(--ok); border: 1px solid #b6dec2; }
.msg.info { background: #e8f1f9; color: #164a80; border: 1px solid #bfd5ea; }

/* 橫幅內的資料庫連線狀態：獨立一行的小字，不使用提示框樣式 */
.mock-banner #dbStatus { display: block; margin: 4px 0 0; padding: 0; background: none; border: 0; font-size: .82rem; }
.mock-banner #dbStatus.success { color: var(--ok); }
.mock-banner #dbStatus.info { color: var(--warn-ink); }
.mock-banner #dbStatus.error { color: var(--err); font-weight: 700; }

.empty { text-align: center; padding: 28px 16px; border: 2px dashed var(--line); border-radius: var(--radius); color: var(--muted); }
.empty p { margin: 0 0 12px; }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  max-width: min(92vw, 520px); padding: 12px 18px; border-radius: 3px;
  background: var(--navy); color: #fff; box-shadow: 0 6px 20px rgba(0,0,0,.28); z-index: 50; font-size: .94rem;
}
.toast.error { background: var(--err); }

/* 計畫卡片 */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; margin-bottom: 12px; }
.card {
  border: 1px solid var(--line); border-top: 3px solid var(--accent); border-radius: var(--radius);
  padding: 16px; background: #fbfdff; display: flex; flex-direction: column; gap: 4px;
}
.card h3 { margin: 0; font-size: 1.05rem; color: var(--navy); }
.card .meta { color: var(--muted); font-size: .86rem; }
.card .btn { margin-top: 8px; align-self: flex-start; }
.badge { display: inline-block; font-size: .72rem; padding: 1px 8px; border-radius: 2px; background: var(--warn-bg); color: var(--warn-ink); margin-left: 6px; vertical-align: middle; font-weight: 700; }
.badge.user { background: var(--brand-soft); color: var(--brand); }

.addbox { margin-top: 14px; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; background: #fbfdff; }
.addbox summary { cursor: pointer; font-weight: 700; color: var(--brand); }
.addbox form, .addbox .tablewrap { margin-top: 12px; }

/* 檢查結果 */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 10px; }
.chip { padding: 4px 12px; border-radius: 2px; font-size: .88rem; background: #e9eef3; font-weight: 700; }
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.bad { background: var(--err-bg); color: var(--err); }
.chip.fix { background: #e8f1f9; color: #164a80; }
.notes .msg { margin: 6px 0; }

/* 表格 */
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
.tbl { border-collapse: collapse; width: 100%; font-size: .88rem; min-width: 560px; }
.tbl th, .tbl td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.tbl th { background: var(--navy); color: #fff; position: sticky; top: 0; white-space: nowrap; font-weight: 700; }
.tbl tbody tr:nth-child(even) td { background: #f7fafc; }
.tbl tr.bad td { background: var(--err-bg) !important; }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.st { font-weight: 700; white-space: nowrap; }
.st.ok { color: var(--ok); }
.st.bad { color: var(--err); }
.tag { display: inline-block; margin: 0 4px 2px 0; padding: 0 7px; border-radius: 2px; font-size: .78rem; background: #e8f1f9; color: #164a80; }
.tag.err { background: #f8cfcc; color: var(--err); }

/* 概況 */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 0; margin-bottom: 12px; border: 1px solid var(--line); }
.stat { padding: 16px 14px; background: #fbfdff; border-right: 1px solid var(--line); }
.stat:last-child { border-right: 0; }
.stat b { display: block; font-size: 1.8rem; line-height: 1.2; color: var(--brand); font-weight: 800; font-variant-numeric: tabular-nums; }
.stat span { font-size: .84rem; color: var(--muted); }

.charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.chart { border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 16px 16px; background: #fbfdff; }
.bars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.bars li { display: grid; grid-template-columns: minmax(70px, 28%) 1fr auto; gap: 8px; align-items: center; font-size: .86rem; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { background: #e3ebf2; border-radius: 2px; height: 14px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: linear-gradient(90deg, var(--brand), var(--accent)); }
.bar-val { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 2.2em; text-align: right; }

.cols { display: flex; align-items: flex-end; gap: 10px; height: 200px; padding-top: 8px; overflow-x: auto; }
.col { flex: 1 0 54px; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; font-size: .8rem; }
.col-bar { width: 70%; max-width: 44px; background: linear-gradient(180deg, var(--accent), var(--brand)); border-radius: 2px 2px 0 0; }
.col-val { font-weight: 700; font-variant-numeric: tabular-nums; margin-bottom: 2px; }
.col-lab { margin-top: 4px; color: var(--muted); white-space: nowrap; }

/* 頁尾 */
.footer {
  margin-top: 32px; color: #bcd3e4; text-align: center;
  background: url("images/seabed.svg") center bottom / cover no-repeat, var(--navy);
  font-size: .86rem; padding: 28px 16px 40px; border-top: 4px solid var(--accent);
}
.footer p { margin: 4px 0; }
.footer strong { color: #fff; letter-spacing: .08em; }

@media (max-width: 700px) {
  .hero::before { right: -200px; opacity: .6; }
  .hero::after { display: none; }
  .steps { padding-left: 16px; gap: 8px; }
  .stat-strip .s { border-right: 0; border-bottom: 1px solid var(--line); }
  .panel { padding: 16px; }
  main { padding: 4px 10px 10px; }
}

/* 台灣分布圖 */
.mapgrid { display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start; }
.mapbox { flex: 1 1 340px; max-width: 480px; }
.mapbox svg { width: 100%; height: auto; display: block; border: 1px solid var(--line); border-radius: var(--radius); background: #dcecf6; }
.mapside { flex: 1 1 280px; min-width: 0; }
#mpSvg .grat { stroke: #fff; stroke-width: 1; opacity: .7; }
#mpSvg .gl { font-size: 10px; fill: #6b8aa0; }
#mpSvg .cl { font-size: 10px; fill: #4c6678; }
#mpSvg .city { fill: #4c6678; }
#mpSvg .land { fill: #f4efe2; stroke: #7f9bb0; stroke-width: 1.4; stroke-linejoin: round; }
#mpSvg .site { fill-opacity: .72; stroke: #fff; stroke-width: 1.5; cursor: pointer; }
#mpSvg .site:hover, #mpSvg .site:focus-visible { fill-opacity: .95; stroke: var(--navy); outline: none; }
#mpSvg .site.sel { fill-opacity: .95; stroke: var(--navy); stroke-width: 3; }
#mpSvg .sel-label { font-size: 12px; font-weight: 700; fill: var(--navy); paint-order: stroke; stroke: #fff; stroke-width: 3px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 8px; font-size: .84rem; }
.legend i, .rk i { display: inline-block; width: 11px; height: 11px; border-radius: 50%; margin-right: 6px; flex: none; }
.legend .lg-note { color: var(--muted); }
.detail { border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: var(--radius); padding: 12px 14px; background: #fbfdff; }
.detail h3 { margin: 0 0 2px; }
.dstats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 8px 0; }
.dstats b { display: block; font-size: 1.4rem; color: var(--brand); line-height: 1.2; }
.dstats span { font-size: .8rem; color: var(--muted); }
.rank { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; max-height: 340px; overflow-y: auto; }
.rk { width: 100%; display: flex; align-items: center; text-align: left; font: inherit; font-size: .88rem; padding: 6px 10px; border: 1px solid var(--line); border-radius: 3px; background: #fff; cursor: pointer; color: var(--ink); }
.rk:hover { background: var(--brand-soft); }
.rk.on { border-color: var(--navy); background: var(--brand-soft); }
.rk-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rk b { margin-left: 8px; font-variant-numeric: tabular-nums; color: var(--brand); }
