:root {
  --bg: #f6f7f8;
  --card: #ffffff;
  --text: #16202a;
  --muted: #64707d;
  --line: #e3e6ea;
  --accent: #0f766e;
  --accent-text: #ffffff;
  --danger: #b42318;
  --danger-bg: #fdecea;
  --warn: #9a6700;
  --warn-bg: #fff4d6;
  --chip: #eef1f4;
  --wa: #128c7e;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101418;
    --card: #1a2027;
    --text: #e8ecf0;
    --muted: #97a3b0;
    --line: #2a323b;
    --accent: #2dd4bf;
    --accent-text: #06201d;
    --danger: #ff8a7a;
    --danger-bg: #3a1c19;
    --warn: #f2c94c;
    --warn-bg: #3a3014;
    --chip: #252d36;
    --wa: #25d366;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }

main {
  max-width: 560px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 96px);
}

h1 { font-size: 26px; margin: 4px 0 2px; letter-spacing: -0.02em; }
.sub { color: var(--muted); margin: 0 0 16px; font-size: 14px; }
h2 {
  font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); margin: 22px 4px 8px; display: flex; gap: 8px; align-items: center;
}
h2 .count { background: var(--chip); border-radius: 999px; padding: 1px 8px; font-size: 12px; }
h2.overdue { color: var(--danger); }
h2.overdue .count { background: var(--danger-bg); }

/* cards and rows */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.row { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-top: 1px solid var(--line); }
.row:first-child { border-top: 0; }
.row-main { flex: 1; min-width: 0; }
.row-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-meta { color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-meta .late { color: var(--danger); font-weight: 600; }
.row-actions { display: flex; gap: 6px; flex-shrink: 0; }

.icon-btn {
  width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); display: grid; place-items: center; cursor: pointer; font-size: 17px; padding: 0;
}
.icon-btn.done { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 700; }
.icon-btn.wa { color: var(--wa); font-weight: 700; font-size: 13px; }

.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.empty strong { display: block; color: var(--text); font-size: 18px; margin-bottom: 4px; }

/* forms */
label { display: block; font-size: 13px; color: var(--muted); margin: 14px 2px 6px; }
input[type=text], input[type=tel], input[type=date], input[type=password], input[type=search], select, textarea {
  width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--card); outline: none; -webkit-appearance: none; appearance: none; min-height: 46px;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 84px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line); background: var(--chip); border-radius: 999px;
  padding: 8px 14px; font-size: 14px; cursor: pointer; white-space: nowrap;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.chips.scroll { gap: 6px; margin: 0 0 12px; }
.chips.scroll .chip { padding: 7px 11px; font-size: 13px; }

.btn {
  display: block; width: 100%; padding: 14px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--card); font-weight: 600; cursor: pointer; text-align: center; margin-top: 12px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); }
.btn.link { border: 0; background: none; color: var(--muted); font-weight: 500; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { flex: 1; }
.error { color: var(--danger); font-size: 14px; margin: 10px 2px 0; min-height: 1em; }

/* person page */
.back { color: var(--muted); font-size: 15px; display: inline-block; padding: 6px 0; }
.stage-pill { display: inline-block; background: var(--chip); border-radius: 999px; padding: 3px 10px; font-size: 13px; color: var(--muted); }
.next { padding: 14px; }
.next-label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.next-action { font-size: 18px; font-weight: 600; margin: 2px 0; }
.next-date.late { color: var(--danger); font-weight: 600; }
.contact-row { display: flex; gap: 10px; margin: 12px 0 0; }
.contact-row .btn { margin-top: 0; }
.timeline-item { padding: 12px 14px; border-top: 1px solid var(--line); }
.timeline-item:first-child { border-top: 0; }
.timeline-when { font-size: 13px; color: var(--muted); }
.timeline-action { font-weight: 600; }
.timeline-note { white-space: pre-wrap; overflow-wrap: anywhere; }

/* tab bar */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: center; gap: 4px;
  background: var(--card); border-top: 1px solid var(--line);
  padding: 6px 12px calc(env(safe-area-inset-bottom) + 6px);
}
.tabs a {
  flex: 1; max-width: 180px; text-align: center; font-size: 12px; color: var(--muted);
  padding: 6px 0; border-radius: 12px; position: relative;
}
.tabs a.active { color: var(--accent); font-weight: 600; }
.tab-icon { display: block; font-size: 20px; line-height: 1.2; }
.badge {
  position: absolute; top: 2px; left: calc(50% + 8px); background: var(--danger); color: #fff;
  border-radius: 999px; font-size: 11px; font-weight: 700; padding: 0 6px; min-width: 18px;
}

/* bottom sheet */
.sheet {
  border: 0; padding: 0; margin: auto auto 0; width: 100%; max-width: 560px; max-height: 92vh;
  background: var(--bg); color: var(--text); border-radius: 20px 20px 0 0; overflow-y: auto;
}
.sheet::backdrop { background: rgba(0, 0, 0, 0.45); }
.sheet-body { padding: 18px 16px calc(env(safe-area-inset-bottom) + 18px); }
.sheet h3 { margin: 0 0 2px; font-size: 20px; }
.sheet .sub { margin-bottom: 4px; }

.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 86px); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px;
  max-width: 90vw; z-index: 10;
}

/* v2: templates, key dates, scorecard, pipeline, import, calendar */
.center { text-align: center; margin-top: 22px; }
.muted { color: var(--muted); font-weight: 400; }
.none { color: var(--muted); font-size: 14px; margin: 4px 4px 0; }
.hint { color: var(--muted); font-size: 14px; margin: 8px 0 0; }
.pad { padding: 14px; margin-top: 14px; }
.pad input[type=file] { margin-top: 12px; width: 100%; }
.chev { color: var(--muted); font-size: 20px; }
textarea.tall { min-height: 160px; }
a.row { color: inherit; }

.segment { display: flex; background: var(--chip); border-radius: 12px; padding: 3px; margin-bottom: 12px; }
.segment button {
  flex: 1; border: 0; background: none; padding: 8px; border-radius: 10px; cursor: pointer; color: var(--muted); font-weight: 600;
}
.segment button.on { background: var(--card); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12); }
#search { margin-bottom: 12px; }

.tpl {
  display: block; width: 100%; text-align: left; padding: 12px 14px; border: 0; border-top: 1px solid var(--line);
  background: none; cursor: pointer;
}
.tpl:first-child { border-top: 0; }
.tpl-body {
  color: var(--muted); font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; }
.tile-num { font-size: 30px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.tile-label { font-weight: 600; font-size: 14px; }
.tile-prev { color: var(--muted); font-size: 13px; margin-top: 2px; }

.checklist { max-height: 46vh; overflow-y: auto; margin-top: 12px; }
.check { display: flex; align-items: center; gap: 12px; padding: 10px 14px; margin: 0; border-top: 1px solid var(--line); color: var(--text); font-size: 16px; cursor: pointer; }
.check:first-child { border-top: 0; }
.check input { width: 22px; height: 22px; flex-shrink: 0; accent-color: var(--accent); }
.check span span { display: block; }

.tabs a { max-width: 110px; }
