:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #1c2530;
  --muted: #6b7785;
  --line: #dfe4ea;
  --accent: #2f6f8f;
  --green: #2e9e5b;
  --yellow: #d9a300;
  --red: #d24b4b;
  --overdue: #fdecec;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
  --radius: 10px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
}

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 8px; font-size: 16px; }
.health-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--muted); display: inline-block; }
.health-dot.green { background: var(--green); }
.health-dot.yellow { background: var(--yellow); }
.health-dot.red { background: var(--red); }

.proj-sel { max-width: 170px; padding: 5px 8px; font-size: 13px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); }
.nav-sel { display: none; padding: 6px 8px; font-size: 14px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); }
.proj-card { cursor: pointer; transition: border-color .15s; margin-bottom: 0; }
.proj-card:hover { border-color: var(--accent); }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.tabs button {
  border: 1px solid transparent; background: transparent; color: var(--muted);
  padding: 6px 10px; border-radius: 8px; cursor: pointer; font-size: 14px;
}
.tabs button:hover { background: var(--bg); }
.tabs button.active { background: var(--accent); color: #fff; }

.sync { font-size: 12px; color: var(--muted); white-space: nowrap; }
.sync.ok { color: var(--green); }
.sync.warn { color: var(--yellow); }
.sync.err { color: var(--red); }

main { max-width: 1040px; margin: 0 auto; padding: 16px 14px 60px; }

.footnote { text-align: center; color: var(--muted); font-size: 12px; padding: 0 14px 24px; }

/* Panels and cards */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; margin-bottom: 16px; }
.panel h2 { margin: 0 0 4px; font-size: 17px; }
.panel h3 { margin: 14px 0 6px; font-size: 15px; }
.panel .hint { color: var(--muted); font-size: 13px; margin: 0 0 10px; }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.section-head .actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* Buttons */
button.btn { border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 6px 12px; border-radius: 8px; cursor: pointer; font-size: 13px; }
button.btn:hover { border-color: var(--accent); color: var(--accent); }
button.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.btn.danger:hover { border-color: var(--red); color: var(--red); }
button.btn.small { padding: 3px 8px; font-size: 12px; }

/* Forms */
.field { display: flex; flex-direction: column; gap: 3px; margin-bottom: 8px; }
.field label { font-size: 12px; color: var(--muted); }
input, select, textarea {
  font: inherit; padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); width: 100%;
}
textarea { min-height: 90px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }

/* Tables -> cards on narrow */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
tr.overdue td { background: var(--overdue); }

.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; border: 1px solid var(--line); }
.badge.red { background: #fdecec; color: var(--red); border-color: #f3c5c5; }
.badge.yellow { background: #fff5d9; color: #9a7400; border-color: #ecd58a; }
.badge.green { background: #e6f6ec; color: var(--green); border-color: #b8e3c6; }
.badge.gray { background: var(--bg); color: var(--muted); }

/* Dashboard grid */
.dash-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.metric { display: flex; flex-direction: column; gap: 2px; }
.metric .big { font-size: 26px; font-weight: 700; }
.progress { height: 8px; background: var(--bg); border-radius: 999px; overflow: hidden; margin-top: 4px; }
.progress > span { display: block; height: 100%; background: var(--accent); }
.gap-item { padding: 7px 0; border-bottom: 1px dashed var(--line); font-size: 13px; }
.gap-item:last-child { border-bottom: none; }
.gap-item .tag { font-size: 11px; color: #fff; background: var(--red); border-radius: 6px; padding: 1px 6px; margin-right: 6px; }
.gap-item .tag.warn { background: var(--yellow); }
.empty { color: var(--muted); font-style: normal; padding: 8px 0; }

/* Chart */
.chart-wrap { text-align: center; }
.chart-wrap svg { width: 100%; max-width: 460px; height: auto; }

.row-actions { display: flex; gap: 4px; }

/* Toast */
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 13px; opacity: 0; pointer-events: none; transition: .25s; z-index: 50; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.draft-box { background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 10px; white-space: pre-wrap; font-size: 13px; margin-top: 8px; }

/* Responsive: iPhone 13 mini 375px */
@media (max-width: 720px) {
  .form-grid, .dash-grid { grid-template-columns: 1fr; }
  .tabs { display: none; }
  .nav-sel { display: block; order: 3; width: 100%; max-width: none; }
  .proj-sel { order: 2; flex: 1; max-width: none; }
  table thead { display: none; }
  table, tbody, tr, td { display: block; width: 100%; }
  tr { border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; padding: 4px; }
  td { border-bottom: 1px dashed var(--line); padding: 6px 8px; }
  td:last-child { border-bottom: none; }
  td::before { content: attr(data-label); display: block; font-size: 11px; color: var(--muted); }
}

/* Print */
@media print {
  .no-print, .topbar, .footnote, .row-actions, .section-head .actions, button { display: none !important; }
  body { background: #fff; }
  main { max-width: none; padding: 0; }
  .panel { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
  tr.overdue td { background: #fff; }
  table { font-size: 11px; }
  .module:not(.printing) { display: none; }
}
