:root {
  --bg: #fbfbfa;
  --surface: #ffffff;
  --ink: #1c1c1a;
  --muted: #6b6b66;
  --line: #e4e4df;
  --accent: #0f6b4f;
  --accent-ink: #ffffff;
  --bar: #d8d8d2;
  --today: #eef5f1;
  --good: #0f6b4f;
  --warn: #8a5a00;
  --radius: 10px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #16161a;
  --surface: #1e1e23;
  --ink: #ececea;
  --muted: #9a9a95;
  --line: #2e2e34;
  --accent: #4fbf94;
  --accent-ink: #10231b;
  --bar: #34343b;
  --today: #1b2a24;
  --good: #4fbf94;
  --warn: #d7a54a;
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

a { color: var(--accent); text-underline-offset: 2px; }

.topbar {
  display: flex;
  gap: 1rem;
  align-items: center;
  max-width: 900px;
  margin: 0 auto;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
}
.nav-links { display: flex; gap: 1rem; align-items: center; flex: 1; }
.topbar form { margin-left: 0; }
.brand { display: none; }

nav a, nav button {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
}

.tabbar { display: none; }

main {
  max-width: 900px;
  margin: 0 auto;
  padding: 1.5rem 1rem 4rem;
}

h1 { font-size: 1.7rem; line-height: 1.2; letter-spacing: -0.02em; margin: 0.4rem 0 1rem; }
h2 { font-size: 1.1rem; letter-spacing: -0.01em; margin: 1.6rem 0 0.6rem; }
h3 { font-size: 0.95rem; color: var(--muted); margin: 1rem 0 0.4rem; }

p, li { color: var(--ink); }
.muted, .meta { color: var(--muted); font-size: 0.88rem; }

section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  margin: 0 0 1rem;
}

ul { padding-left: 1.1rem; }
li { margin: 0.25rem 0; }

/* week grid */
.grid-wrap { overflow-x: auto; }
.week-grid {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}
.week-grid th, .week-grid td {
  padding: 0.4rem 0.35rem;
  text-align: left;
  border-bottom: 1px solid var(--line);
}
.week-grid thead th {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 600;
}
.week-grid .goal-row th {
  padding-top: 1rem;
  border-bottom: 0;
  font-size: 0.95rem;
}
.week-grid td.name { min-width: 9rem; overflow-wrap: anywhere; }
.week-grid input {
  width: 3.2rem;
  padding: 0.3rem 0.35rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  text-align: center;
}
.week-grid td.score { text-align: right; min-width: 3.2rem; }
.week-grid td.target, .week-grid td.actual { text-align: right; }
.week-grid th:nth-last-child(-n+3) { text-align: right; }
.week-grid tfoot th, .week-grid tfoot td {
  border-bottom: 0;
  border-top: 2px solid var(--line);
  padding-top: 0.6rem;
  font-weight: 600;
}
.week-grid tfoot th { color: var(--muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; }

.score {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}
.score.is-good { color: var(--good); }
.score.is-low { color: var(--warn); }

/* forms */
form { margin: 0.6rem 0; }
label { display: block; font-size: 0.85rem; color: var(--muted); margin: 0.35rem 0; }
input, select, textarea, button {
  font: inherit;
}
input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="date"], input[type="url"], select, textarea {
  width: 100%;
  max-width: 28rem;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
}
button {
  padding: 0.45rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease;
}
button:hover { background: var(--bg); }
button:active { transform: translateY(1px); }
button[type="submit"] {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: transparent;
}
button[type="submit"]:hover { filter: brightness(1.08); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* score bar */
.bar {
  position: relative;
  height: 6px;
  background: var(--bar);
  border-radius: 999px;
  overflow: hidden;
  margin: 0.35rem 0 0.6rem;
}
.bar > span {
  display: block;
  height: 100%;
  background: var(--accent);
}
.bar .mark {
  position: absolute;
  top: -3px;
  bottom: -3px;
  left: 85%;
  width: 2px;
  background: var(--ink);
  opacity: 0.55;
}

/* htmx swap fade */
.htmx-swapping { opacity: 0.4; transition: opacity 120ms ease; }

@media (max-width: 640px) {
  .week-grid { font-size: 0.85rem; }
}

/* phone: a bottom tab bar instead of a wrapping link row */
@media (max-width: 700px) {
  .topbar .nav-links,
  .topbar .nav-context { display: none; }
  .brand {
    display: block;
    margin-right: auto;
    font-weight: 600;
    color: var(--ink);
    text-decoration: none;
  }
  .tabbar {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    background: var(--surface);
    border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .tabbar a {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
    align-items: center;
    justify-content: center;
    min-height: 56px;
    font-size: 0.72rem;
    color: var(--muted);
    text-decoration: none;
  }
  .tabbar svg { display: block; }
  .tabbar a.active { color: var(--accent); font-weight: 600; }
  .member-head .spark,
  .member > summary .spark { flex-basis: 100%; order: 3; margin-top: 0.35rem; }
  .member > summary { flex-wrap: wrap; }
  main { padding-bottom: 6rem; }
  input, select, textarea { font-size: 16px; }
  .week-grid input { min-height: 40px; }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 5.5rem;
  transform: translateX(-50%);
  z-index: 30;
  max-width: 90vw;
  padding: 0.6rem 0.9rem;
  border-radius: 8px;
  background: var(--ink);
  color: var(--bg);
  font-size: 0.9rem;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* goals page */
.page-head { margin-bottom: 1.5rem; }
.page-head h1 { margin-bottom: 0.15rem; }

/* one hue per quarter, used on the quarter card headings */
.quarter { --q: var(--line); border-top: 4px solid var(--q); padding: 1.1rem 1.2rem 1.3rem; }
.quarter.q1, .week-quarter.q1 { --q: #0f6b4f; }
.quarter.q2, .week-quarter.q2 { --q: #2563a8; }
.quarter.q3, .week-quarter.q3 { --q: #6b4ea8; }
.quarter.q4, .week-quarter.q4 { --q: #a33a5c; }
:root[data-theme="dark"] .quarter.q1, :root[data-theme="dark"] .week-quarter.q1 { --q: #4fbf94; }
:root[data-theme="dark"] .quarter.q2, :root[data-theme="dark"] .week-quarter.q2 { --q: #7fb2ea; }
:root[data-theme="dark"] .quarter.q3, :root[data-theme="dark"] .week-quarter.q3 { --q: #b39ae0; }
:root[data-theme="dark"] .quarter.q4, :root[data-theme="dark"] .week-quarter.q4 { --q: #e28aa4; }
.quarter .quarter-head h2 { color: color-mix(in srgb, var(--q) 80%, var(--ink)); }
.quarter-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--line);
}
.quarter-head h2 { margin: 0; font-size: 1.2rem; }
.quarter-head .meta { margin: 0.15rem 0 0; }

.chip {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: var(--muted);
  white-space: nowrap;
}
.chip-current { color: var(--good); border-color: currentColor; }
.chip-past { opacity: 0.6; }

.goal { padding-top: 0.9rem; }
.goal h3 { margin: 0 0 0.35rem; font-size: 1.15rem; font-weight: 600; letter-spacing: -0.01em; color: var(--ink); }
.tactic-list { list-style: none; padding: 0; margin: 0 0 0.5rem; }
.tactic-list li {
  display: block;
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--line);
}
.tactic-line { display: flex; align-items: baseline; gap: 0.6rem; }
.goal-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.35rem;
}
.goal-head h3 { margin: 0; color: var(--ink); }
button.mini {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 6px;
  color: var(--muted);
}
/* keep the visual button small but the tap area phone-sized */
button.mini::after {
  content: "";
  position: absolute;
  inset: -12px;
}
.tactic-list li:last-child { border-bottom: 0; }
.tactic-name { flex: 1; min-width: 6rem; overflow-wrap: anywhere; }
.tactic-meta { color: var(--muted); font-size: 0.82rem; font-variant-numeric: tabular-nums; }
.tag {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 0.05rem 0.3rem;
}
.actions { display: flex; gap: 0.5rem; align-items: baseline; font-size: 0.82rem; }
.actions form { margin: 0; }
button.link {
  background: none;
  border: 0;
  padding: 0;
  color: var(--muted);
  font-size: 0.82rem;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
button.link:hover { color: var(--ink); background: none; }

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
  margin: 0.5rem 0 0;
}
.inline-form input[type="text"] { flex: 1 1 12rem; max-width: none; }
.inline-form .target-input { width: 4.5rem; flex: 0 0 auto; }
.inline-form .check {
  display: inline-flex;
  gap: 0.3rem;
  align-items: center;
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
}
.inline-form .check input { width: auto; }
.inline-form select { width: auto; max-width: none; padding: 0.35rem 0.3rem; }
.add-goal { margin-top: 1rem; padding-top: 0.9rem; border-top: 1px solid var(--line); }
.page-foot { margin-top: 1.5rem; }

/* avatars */
.avatar {
  display: inline-block;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  object-fit: cover;
  vertical-align: middle;
  background: var(--line);
}
.avatar-empty {
  display: inline-grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
}
.avatar-large { width: 5rem; height: 5rem; }
.member-head { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }

/* week strip */
.week-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.9rem;
  margin: 0.6rem 0 0.2rem;
}
.week-quarter { display: flex; flex-direction: column; align-items: flex-start; gap: 0.25rem; }
.week-quarter-label {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-weight: 600;
  color: var(--q);
}
.week-quarter-weeks { display: flex; gap: 0.25rem; }
.week-quarter-weeks a, .week-quarter-weeks > span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  min-height: 40px;
  border: 1px solid color-mix(in srgb, var(--q) 32%, var(--line));
  border-radius: 8px;
  background: color-mix(in srgb, var(--q) 8%, var(--surface));
  font-size: 0.85rem;
  text-decoration: none;
  color: color-mix(in srgb, var(--q) 85%, var(--ink));
}
.week-quarter-weeks a.active {
  border-color: var(--accent);
  background: var(--surface);
  color: var(--accent);
  font-weight: 600;
}
.week-quarter-weeks > span { opacity: 0.45; }

/* week navigation and grid extras */
.week-nav { display: flex; gap: 1rem; flex-wrap: wrap; font-size: 0.9rem; margin-bottom: 0.4rem; }
.week-grid th.today, .week-grid td.today { background: var(--today); }
.week-grid td .cell-value {
  display: inline-block;
  min-width: 2rem;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
@media (min-width: 701px) {
  .grid-wrap .week-grid th:first-child, .grid-wrap .week-grid td:first-child {
    position: sticky;
    left: 0;
    background: var(--surface);
  }
  .grid-wrap .week-grid th:last-child, .grid-wrap .week-grid td:last-child {
    position: sticky;
    right: 0;
    background: var(--surface);
  }
}

/* member rows */
.member {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin: 0 0 0.6rem;
}
.member > summary {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.8rem;
  cursor: pointer;
  list-style: none;
}
.member > summary::-webkit-details-marker { display: none; }
.member-name { flex: 1; min-width: 5rem; overflow-wrap: anywhere; }
.member-detail { padding: 0 0.9rem 0.9rem; border-top: 1px solid var(--line); }
.member-detail .goal-head { margin-top: 1rem; }

/* recent activity */
.activity ul { list-style: none; margin: 0; padding: 0; }
.activity li {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-height: 2.75rem;
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--line);
}
.activity li:last-child { border-bottom: 0; }
.activity-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.activity .meta { white-space: nowrap; }

/* sparkline */
.spark { display: inline-flex; align-items: flex-end; gap: 2px; height: 1.5rem; flex: none; }
.spark-bar {
  flex: 0 0 5px;
  width: 5px;
  min-height: 2px;
  background: var(--bar);
  border-radius: 2px 2px 0 0;
}
.spark-bar.is-good { background: var(--good); }
.spark-bar.is-low { background: var(--warn); }

/* WAM agenda on the review page */
.wam {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.7rem 1rem;
  margin: 0 0 1rem;
}
.wam > summary { cursor: pointer; font-weight: 600; font-size: 0.9rem; }
.wam ol { margin: 0.6rem 0 0.2rem; padding-left: 1.2rem; }
.wam li { margin: 0.35rem 0; }
.wam .min {
  float: right;
  margin-left: 0.6rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

/* group chart */
.team-chart svg { display: block; width: 100%; height: auto; }
.team-chart .grid { stroke: var(--line); stroke-width: 1; }
.team-chart .axis { fill: var(--muted); font-size: 9px; }
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1rem;
  margin: 0.4rem 0 1.2rem;
  padding: 0;
  list-style: none;
  font-size: 0.85rem;
}
.chart-legend .swatch {
  display: inline-block;
  width: 0.7rem;
  height: 0.7rem;
  margin-right: 0.3rem;
  border-radius: 50%;
}

/* navigation state */
.topbar a.active { color: var(--ink); font-weight: 600; text-decoration: none; }
.nav-context { margin-left: auto; color: var(--muted); font-size: 0.8rem; }

/* empty states and buttons */
.empty { text-align: left; }
.empty h2 { margin-top: 0; }
a.button {
  display: inline-block;
  padding: 0.45rem 0.8rem;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-ink);
  text-decoration: none;
}
a.button:hover { filter: brightness(1.08); }
button.copy { margin-left: 0.4rem; padding: 0.2rem 0.5rem; font-size: 0.8rem; }
code { font-size: 0.82rem; overflow-wrap: anywhere; }

/* form errors and edit details */
.errorlist { color: var(--warn); font-size: 0.85rem; margin: 0.2rem 0; padding-left: 1rem; }
.goal-edit { margin: 0.2rem 0 0.6rem; }
.goal-edit > summary { font-size: 0.8rem; color: var(--muted); cursor: pointer; }
.goal-edit .inline-form { margin-top: 0.4rem; }

/* phone layout: one card per tactic */
@media (max-width: 700px) {
  .week-grid thead { display: none; }
  .week-grid, .week-grid tbody, .week-grid tfoot { display: block; }
  .week-grid tr {
    display: grid;
    grid-template-columns: repeat(21, minmax(0, 1fr));
    gap: 0.3rem;
    padding: 0.7rem 0;
    border-bottom: 1px solid var(--line);
  }
  .week-grid td { display: block; padding: 0; border: 0; }
  .week-grid td.name { grid-column: 1 / -1; font-weight: 600; padding-bottom: 0.2rem; }
  .week-grid td.day::before,
  .week-grid td.target::before,
  .week-grid td.actual::before,
  .week-grid td.score::before {
    display: block;
    font-size: 0.62rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
    text-align: center;
    padding-bottom: 0.15rem;
  }
  .week-grid td.day::before { content: attr(data-day); }
  .week-grid td.target::before { content: "Target"; }
  .week-grid td.actual::before { content: "Actual"; }
  .week-grid td.score::before { content: "Score"; }
  .week-grid td.day { grid-column: span 3; }
  .week-grid td.day input { width: 100%; }
  .week-grid td.target, .week-grid td.actual, .week-grid td.score {
    grid-column: span 7;
    text-align: center;
  }
  .week-grid tfoot tr {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    border-bottom: 0;
    border-top: 2px solid var(--line);
  }
  .week-grid tfoot th, .week-grid tfoot td { border: 0; padding: 0.5rem 0 0; }
  .week-grid td.today { background: var(--today); border-radius: 6px; }
}

/* first-run checklist */
.checklist ul { list-style: none; padding: 0; margin: 0.4rem 0 0; }
.checklist li { padding: 0.25rem 0; color: var(--muted); }
.checklist li.done { color: var(--muted); text-decoration: line-through; }

.tactic-list li form + form { margin-top: 0.3rem; }

.topbar form button {
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 0.9rem;
  padding: 0 0.2rem;
}
.topbar form button:hover { color: var(--ink); background: none; }

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: 8px;
  color: var(--muted);
}

/* vision */
.vision textarea { width: 100%; max-width: 40rem; }
.vision-statement { margin-bottom: 0.6rem; }
.vision-list { list-style: none; padding: 0; margin: 0 0 0.5rem; }
.vision-list li {
  display: flex;
  align-items: baseline;
  gap: 0.6rem;
  padding: 0.3rem 0;
  border-bottom: 1px solid var(--line);
}
.vision-list li:last-child { border-bottom: 0; }
.member-vision { padding-top: 0.7rem; }
.member-vision h4 { margin: 0 0 0.3rem; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.member-vision p { margin: 0 0 0.4rem; }
.member-vision ul { padding-left: 1.1rem; margin: 0; }

/* weekly plan */
.plan-panel { border-color: var(--accent); }
.plan-panel h2 { margin-top: 0; }
.plan-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  padding: 0.25rem 0;
  margin: 0;
}
.plan-row input { width: 5rem; text-align: center; }
