:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #eef1f6;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #dde2ea;
  --primary: #2563eb;
  --primary-text: #ffffff;
  --danger: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 2px 8px rgba(0, 0, 0, .05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141b;
    --surface: #171d26;
    --surface-2: #1f2732;
    --text: #e5e7eb;
    --muted: #9aa3af;
    --border: #2b3441;
    --primary: #3b82f6;
    --danger: #f87171;
    --success: #4ade80;
    --warning: #fbbf24;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
a { color: var(--primary); text-decoration: none; }
h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.3; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.15rem; }
.muted { color: var(--muted); }
.center { text-align: center; }
.small { font-size: .85rem; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .6rem 1rem; padding-top: max(.6rem, env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; color: var(--text); display: inline-flex; align-items: center; gap: .5rem; font-size: 1.1rem; white-space: nowrap; }
.brand img { width: 32px; height: 32px; border-radius: 8px; display: block; }
.brand small { font-size: .75rem; font-weight: 500; color: var(--muted); }
.nav { display: flex; align-items: center; gap: .9rem; flex-wrap: wrap; }
.nav a { color: var(--muted); }
.nav a.active { color: var(--primary); font-weight: 600; }

.app { max-width: 1200px; margin: 0 auto; padding: 1rem; padding-bottom: max(1rem, env(safe-area-inset-bottom)); }

button, .btn {
  font: inherit; cursor: pointer;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text);
  padding: .45rem .9rem; min-height: 38px;
}
button:hover { border-color: var(--primary); }
button.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
button.danger { color: var(--danger); }
button.link { border: 0; background: none; color: var(--muted); padding: 0; min-height: 0; }
button.small { padding: .2rem .55rem; min-height: 30px; font-size: .85rem; }
button:disabled { opacity: .6; cursor: default; }

input, select, textarea {
  font: inherit; width: 100%;
  padding: .5rem .65rem; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text);
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
label { display: block; font-size: .9rem; color: var(--muted); margin-bottom: .2rem; }
.field { margin-bottom: .85rem; }
.row { display: flex; gap: .75rem; }
.row > * { flex: 1; min-width: 0; }
.actions { display: flex; gap: .5rem; justify-content: flex-end; flex-wrap: wrap; margin-top: 1rem; }
.error { color: var(--danger); font-size: .9rem; min-height: 1.2em; margin: .25rem 0; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; }
.auth { max-width: 380px; margin: 8vh auto 0; }
.auth h1 { text-align: center; margin-bottom: .2rem; }
.auth-logo { text-align: center; margin-bottom: .5rem; }
.auth-logo img { width: 72px; height: 72px; border-radius: 18px; box-shadow: 0 6px 18px rgba(79, 70, 229, .3); }
.auth-sub { text-align: center; color: var(--muted); font-size: .9rem; margin: 0 0 1.25rem; }
.notice { background: var(--surface-2); border-radius: 8px; padding: .6rem .8rem; margin-bottom: 1rem; font-size: .9rem; }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; margin-bottom: 1rem; }
.toolbar h1 { margin: 0; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.segmented button { border: 0; border-radius: 0; min-height: 34px; }
.segmented button.on { background: var(--primary); color: var(--primary-text); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.project-card { display: block; color: inherit; }
.project-card:hover { border-color: var(--primary); }
.project-card p { margin: .25rem 0 .75rem; color: var(--muted); font-size: .9rem; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

.progress { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress > span { display: block; height: 100%; width: 0; background: var(--success); }
.progress-label { display: flex; justify-content: space-between; font-size: .85rem; color: var(--muted); margin-top: .3rem; }

.badge { display: inline-block; font-size: .75rem; padding: .05rem .5rem; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.high { background: rgba(220, 38, 38, .12); color: var(--danger); }
.badge.medium { background: rgba(217, 119, 6, .12); color: var(--warning); }
.badge.low { background: rgba(22, 163, 74, .12); color: var(--success); }
.overdue { color: var(--danger); font-weight: 600; }

.project-head { margin-bottom: 1rem; }
.project-head .desc { white-space: pre-wrap; color: var(--muted); margin: .25rem 0 .5rem; }
.project-head .meta { display: flex; gap: 1rem; flex-wrap: wrap; font-size: .85rem; color: var(--muted); margin-bottom: .5rem; }

.board { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; align-items: start; }
.column { background: var(--surface-2); border-radius: var(--radius); padding: .6rem; min-height: 140px; }
.column.drop { outline: 2px dashed var(--primary); }
.column-head { display: flex; justify-content: space-between; align-items: center; padding: .1rem .3rem .5rem; font-weight: 600; }
.column-head .count { color: var(--muted); font-weight: 400; font-size: .85rem; }
.task-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: .6rem .7rem; margin-bottom: .5rem; cursor: pointer; box-shadow: var(--shadow);
}
.task-card.dragging { opacity: .5; }
.task-card .title { font-weight: 500; word-break: break-word; }
.task-card .info { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; margin-top: .35rem; font-size: .8rem; color: var(--muted); }
.task-card .move { margin-left: auto; display: flex; gap: .25rem; }
.task-card .move button { min-height: 26px; padding: 0 .45rem; font-size: .8rem; }
.add-task { width: 100%; border-style: dashed; background: transparent; color: var(--muted); }

.list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.list-row { display: flex; align-items: center; gap: .75rem; padding: .6rem .8rem; border-top: 1px solid var(--border); cursor: pointer; }
.list-row:first-child { border-top: 0; }
.list-row input[type=checkbox] { width: 20px; height: 20px; flex: none; }
.list-row .title { flex: 1; min-width: 0; word-break: break-word; }
.list-row.done .title { text-decoration: line-through; color: var(--muted); }
.list-row .info { display: flex; gap: .4rem; align-items: center; font-size: .8rem; color: var(--muted); flex-wrap: wrap; justify-content: flex-end; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .55rem .6rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .85rem; color: var(--muted); font-weight: 500; }
.table-wrap { overflow-x: auto; }
td .actions { justify-content: flex-start; margin: 0; }

dialog {
  border: 1px solid var(--border); border-radius: 14px; padding: 1.2rem;
  width: min(520px, calc(100vw - 2rem)); max-height: calc(100vh - 2rem);
  background: var(--surface); color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, .4); }
.secret { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1.2rem; background: var(--surface-2); padding: .5rem .75rem; border-radius: 8px; user-select: all; text-align: center; }

.toast {
  position: fixed; left: 50%; bottom: max(1.5rem, env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: #111827; color: #fff; padding: .55rem 1rem; border-radius: 8px; font-size: .9rem;
  opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 100; max-width: calc(100vw - 2rem);
}
.toast.show { opacity: 1; }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }

@media (max-width: 720px) {
  .app { padding: .75rem; }
  .board {
    display: flex; overflow-x: auto; scroll-snap-type: x mandatory; gap: .75rem;
    margin: 0 -.75rem; padding: 0 .75rem .5rem;
  }
  .column { flex: 0 0 85%; scroll-snap-align: start; }
  .row { flex-direction: column; gap: 0; }
  .nav { gap: .7rem; font-size: .9rem; }
  .hide-mobile { display: none; }
}
button.full { width: 100%; }

/* ---------- 第二版：進度、預算、里程碑、總覽 ---------- */
.progress { position: relative; }
.progress.thin { height: 5px; margin-top: .3rem; }
.progress .expected {
  position: absolute; top: -3px; bottom: -3px; width: 2px; margin-left: -1px;
  background: var(--text); opacity: .55; border-radius: 1px;
}
.progress.budget.ok > span { background: var(--primary); }
.progress.budget.warn > span { background: var(--warning); }
.progress.budget.bad > span { background: var(--danger); }

.pill { display: inline-block; font-size: .75rem; font-weight: 500; padding: .05rem .5rem; border-radius: 99px; white-space: nowrap; vertical-align: middle; }
.pill.ok { background: rgba(22, 163, 74, .12); color: var(--success); }
.pill.warn { background: rgba(217, 119, 6, .14); color: var(--warning); }
.pill.bad { background: rgba(220, 38, 38, .12); color: var(--danger); }
.card-pills { display: flex; gap: .35rem; flex-wrap: wrap; margin: .5rem 0 .25rem; min-height: 1px; }

.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .75rem; margin-bottom: .75rem; }
.stat { padding: .75rem .9rem; }
.stat .label { font-size: .85rem; color: var(--muted); }
.stat .value { font-size: 1.6rem; font-weight: 700; line-height: 1.3; }
.stat .value.small-value { font-size: 1.15rem; }
.stat .value .muted { font-size: .85rem; font-weight: 400; }
.value.bad { color: var(--danger); }
.value.warn { color: var(--warning); }

.summary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .75rem; }
.summary-item { padding: .75rem .9rem; }
.summary-item .label { font-size: .85rem; color: var(--muted); margin-bottom: .45rem; display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; }

.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin: 1rem 0; overflow-x: auto; }
.tabs a { padding: .55rem .9rem; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a.on { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

.section-title { margin: 1.25rem 0 .6rem; font-size: 1.05rem; }
.section-gap { margin-top: 1.5rem; }
.toolbar h2 { margin: 0; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
.empty.small { padding: 1rem; font-size: .9rem; }

.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
tfoot th { color: var(--text); font-weight: 600; border-bottom: 0; }
.cell-progress { min-width: 90px; }
.amount { font-variant-numeric: tabular-nums; color: var(--text); font-size: .95rem; }
.list-row.static { cursor: default; }
a.link-row { color: inherit; }
a.link-row:hover { background: var(--surface-2); }
.dash-table td { font-size: .92rem; }
output { color: var(--text); font-weight: 600; }
input[type=range] { padding: 0; border: 0; accent-color: var(--primary); }

@media (max-width: 720px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .summary, .two-col { grid-template-columns: 1fr; }
}
.edit-link { color: var(--primary); font-size: .85rem; }

@media (max-width: 520px) {
  .brand small { display: none; }
  .brand img { width: 28px; height: 28px; }
}
