:root {
  --navy: #1a365d;
  --navy-2: #163154;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --bg: #f3f5f8;
  --card: #fff;
  --ok: #166534;
  --err: #9b1c1c;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 8px 24px rgba(16, 24, 40, 0.04);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Noto Sans CJK TC", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.55;
  min-height: 100vh;
}
a { color: var(--navy); }
.keep-space { white-space: pre-wrap; }
.wrap { width: min(960px, calc(100% - 32px)); margin: 0 auto; }
.top {
  background: var(--navy);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 10;
}
.top-inner { display: flex; align-items: center; justify-content: space-between; min-height: 52px; }
.brand { color: #fff; text-decoration: none; font-weight: 700; letter-spacing: 0.04em; }
.top-nav { display: flex; gap: 12px; align-items: center; font-size: 13px; }
.who { opacity: 0.85; max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.linkish {
  background: none; border: 0; color: inherit; cursor: pointer;
  font: inherit; text-decoration: underline; padding: 0;
}
.top .linkish { color: #dbeafe; }
.linkish.danger { color: #9b1c1c; }
.inline { display: inline; }
main.wrap { padding: 20px 0 40px; }
.foot { color: var(--muted); font-size: 12px; padding: 8px 0 28px; }
h1, h2 { line-height: 1.3; }
.page-title { margin: 0 0 4px; font-size: 1.5rem; }
.sub, .lead, .hint, .muted { color: var(--muted); }
.lead { margin-top: 0; }
.hint { font-size: 13px; margin: 6px 0 0; }
.crumb { font-size: 13px; color: var(--muted); }
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 18px 16px;
  margin: 16px 0;
}
.card h2 { margin: 0 0 12px; font-size: 1.05rem; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.card-head h2 { margin: 0; }
.login-card { margin-top: 32px; padding: 28px 24px; }
.banner {
  border-radius: 10px;
  padding: 10px 14px;
  margin: 0 0 16px;
  white-space: pre-wrap;
  font-size: 14px;
}
.banner.ok { background: #ecfdf3; color: var(--ok); }
.banner.err { background: #fef2f2; color: var(--err); }
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--navy); color: #fff; border: 0;
  border-radius: 10px; padding: 8px 14px; font: inherit;
  cursor: pointer; text-decoration: none; font-weight: 600;
}
.btn:hover { background: var(--navy-2); }
.btn.small { padding: 6px 10px; font-size: 13px; font-weight: 600; }
.btn.ghost {
  background: #fff; color: var(--navy);
  border: 1px solid var(--line);
}
.btn.ghost:hover { background: #f8fafc; }
.btn.line { background: #06c755; color: #fff; width: 100%; margin: 8px 0; padding: 12px; }
.btn.line:hover { background: #05b34c; }
.btn.danger, .btn.ghost.danger { color: #9b1c1c; }
.dev-box { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); }
code { font-size: 0.92em; background: #eef2f7; padding: 1px 5px; border-radius: 4px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 12px 0; }
.filters input[type="search"],
input[type="text"], input:not([type]), textarea {
  border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 10px; font: inherit; width: 100%; background: #fff;
}
.filters input[type="search"] { flex: 1; min-width: 160px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 16px; }
.chip {
  text-decoration: none; color: var(--text);
  background: #fff; border: 1px solid var(--line);
  border-radius: 999px; padding: 4px 12px; font-size: 13px;
}
.chip.on { background: var(--navy); color: #fff; border-color: var(--navy); }
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.item {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border-left: 6px solid var(--dir, var(--status, var(--navy)));
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px;
  padding: 12px 14px;
}
.item-main { text-decoration: none; color: inherit; flex: 1; min-width: 200px; }
.item-top { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.key { font-size: 1.05rem; }
.item-sum { margin-top: 4px; }
.item-meta { color: var(--muted); font-size: 12px; margin-top: 4px; }
.item-del { align-self: flex-end; }
.pill {
  display: inline-block; color: #fff; border-radius: 999px;
  padding: 2px 9px; font-size: 12px; font-weight: 600; white-space: nowrap;
}
.pill.lg { font-size: 13px; padding: 4px 12px; }
.empty { color: var(--muted); padding: 12px 0; }
.add-card label { display: block; font-weight: 600; margin: 0 0 6px; font-size: 14px; }
.detail-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; }
.meta-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px 16px; margin: 16px 0;
}
.meta-grid dt { font-size: 12px; color: var(--muted); }
.meta-grid dd { margin: 0; font-weight: 600; }
.actions { display: flex; gap: 8px; margin: 8px 0 16px; }
.timeline { list-style: none; margin: 0; padding: 0 0 0 8px; }
.timeline li {
  position: relative; padding: 0 0 16px 18px;
  border-left: 2px solid var(--line);
}
.timeline li:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline .dot {
  position: absolute; left: -6px; top: 6px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--navy);
}
.t-when, .t-extra { color: var(--muted); font-size: 13px; }
.plain { list-style: none; margin: 0; padding: 0; }
.plain li { padding: 8px 0; border-bottom: 1px solid var(--line); }
.plain li:last-child { border-bottom: 0; }
.plain li.ok { color: #166534; }
.plain li.warn { color: #b45309; }
.notice {
  white-space: pre-wrap; background: #f8fafc; border: 1px solid var(--line);
  border-radius: 10px; padding: 12px; font: inherit; font-size: 14px;
  margin: 0; overflow: auto;
}
@media (max-width: 600px) {
  .page-title { font-size: 1.28rem; }
  .item-top { flex-direction: column; align-items: flex-start; }
  .detail-head { flex-direction: column; }
}
.t-extra .phone { color: #E11D48; font-weight: 700; font-size: 14px; background: #FFE4E6; padding: 0 4px; border-radius: 4px; }

/* ---- 追蹤清單（行動版優先，390px） ---- */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
main.wrap { padding-top: 14px; }
.card { padding: 14px 14px 12px; margin: 12px 0; }
.add-card h2, .search-card h2 { margin-bottom: 8px; }
.add-card textarea { min-height: 76px; resize: vertical; font-size: 16px; line-height: 1.45; }
.add-foot { display: flex; gap: 10px; align-items: flex-end; justify-content: space-between; margin-top: 8px; }
.add-foot .hint { margin: 0; font-size: 12px; flex: 1; }
.add-foot .btn { min-width: 76px; padding: 10px 16px; }
.search-row { display: flex; gap: 8px; align-items: center; }
.search-row input[type="search"] {
  flex: 1; min-width: 0; border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 10px; font: inherit; font-size: 16px; background: #fff;
}
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 10px; }
.chip { flex: 0 0 auto; padding: 4px 10px; font-size: 13px; white-space: nowrap; }
.chip .n { opacity: 0.6; font-size: 12px; margin-left: 2px; }
.chip.on .n { opacity: 0.85; }
.export-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.export-alt { font-size: 12px; color: var(--muted); }
.export-alt a { color: var(--navy); }
.hint.small { font-size: 12px; margin-top: 8px; }
.hint .linkish { color: var(--navy); font-size: 12px; }
.list-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 18px 0 8px; }
.list-head .page-title { margin: 0; font-size: 1.2rem; }
.list-head .count { font-size: 0.85rem; color: var(--muted); font-weight: 600; }
.btn[disabled] { opacity: 0.6; cursor: default; }
.group-label {
  font-size: 12px; font-weight: 700; color: var(--navy); letter-spacing: 0.08em;
  margin: 8px 2px -2px; list-style: none;
}
.item { padding: 10px 12px; gap: 4px; align-items: flex-end; }
.item-main { min-width: 0; width: 100%; }
.item-top { flex-direction: row !important; align-items: center !important; justify-content: space-between; }
.item-top .key { font-size: 1rem; word-break: break-all; }
.item-latest { margin-top: 4px; font-weight: 600; font-size: 14px; }
.item-latest .at { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: 4px; white-space: nowrap; }
.item-fields { display: flex; flex-wrap: wrap; gap: 2px 14px; margin: 4px 0 0; font-size: 12px; color: var(--muted); }
.item-fields div { display: flex; gap: 4px; }
.item-fields dt { margin: 0; }
.item-fields dd { margin: 0; color: var(--text); font-weight: 600; }
.item-del { margin-left: auto; }
.item-del .linkish { font-size: 12px; }
.item-del.armed .linkish { color: #fff; background: #b91c1c; border-radius: 6px; padding: 2px 8px; text-decoration: none; }
.tz { font-size: 11px; margin-top: 8px; }
.danger-zone { margin: 22px 0 4px; text-align: center; }
.job-banner {
  display: flex; align-items: center; gap: 8px; border-radius: 10px;
  padding: 9px 12px; margin: 0 0 10px; font-size: 13px;
}
.job-banner.running { background: #eef4fb; color: #1e3a5f; }
.job-banner.done { background: #f1f5f9; color: var(--muted); }
.job-cur { color: var(--muted); margin-left: 4px; font-size: 12px; }
.spinner {
  width: 14px; height: 14px; border-radius: 50%; flex: 0 0 auto;
  border: 2px solid #bfd3ea; border-top-color: var(--navy); animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.confirm-card label { display: block; font-weight: 600; margin: 12px 0 6px; }
.confirm-card input { font-size: 16px; }
.confirm-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 14px; }
.btn.danger-solid { background: #b91c1c; }
.btn.danger-solid:hover { background: #991b1b; }

/* ---- 自動同步（就地更新卡片） ---- */
[hidden] { display: none !important; }
.job-banner.done .spinner { display: none; }
.job-banner a { color: inherit; text-decoration: underline; }
.item-badges { display: inline-flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.updating {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; color: #1e3a5f; background: #eef4fb; border-radius: 999px; padding: 2px 8px; white-space: nowrap;
}
.spinner.sm { display: inline-block; width: 10px; height: 10px; border-width: 2px; margin-right: 4px; vertical-align: -1px; }
.updating .spinner.sm { margin-right: 0; }
.item.is-new .item-latest { color: var(--muted); }
#list-synced { color: var(--muted); }

/* 進出口方向色：進口藍、出口紫（狀態仍以右側色塊區分） */
.dir-chip { display: inline-block; margin-left: 8px; padding: 0 7px; border: 1px solid var(--dir, #9CA3AF);
  color: var(--dir, #6B7280); border-radius: 999px; font-size: 12px; font-weight: 700; line-height: 18px; vertical-align: middle; }
.dir-legend { font-size: 12px; color: #6B7280; margin: 4px 0; }
.dir-legend span { display: inline-block; margin-right: 12px; }
.dir-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 4px; vertical-align: -1px; }
.notice-tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.notice-tbl th, .notice-tbl td { border-bottom: 1px solid var(--line, #E5E7EB); padding: 6px 4px; text-align: left; vertical-align: top; }
