:root {
  --blue: #0053a0;
  --blue-dark: #003b73;
  --blue-soft: #e8f0f9;
  --ink: #1d2733;
  --muted: #5d6b7a;
  --line: #d9e0e7;
  --bg: #f5f7fa;
  --card: #ffffff;
  --ok: #1f7a3d;
  --ok-soft: #e6f4ea;
  --warn: #9a5b00;
  --warn-soft: #fff4e0;
  --bad: #b3261e;
  --bad-soft: #fdecea;
  --radius: 10px;
  --cat-1: #0053a0;
  --cat-2: #2a8c82;
  --cat-3: #c46b00;
  --cat-4: #6b4fa0;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
a { color: var(--blue); }
h1 { font-size: 1.6rem; margin: 1.5rem 0 .25rem; line-height: 1.25; }
h2 { font-size: 1.2rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0 0 .5rem; }
.lede { color: var(--muted); margin: 0 0 1.25rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }

.wrap { max-width: 1100px; margin: 0 auto; padding: 0 16px; }
.narrow { max-width: 460px; margin: 0 auto; }

/* Top bar */
.topbar { background: var(--blue); color: #fff; }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 1rem; min-height: 56px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: .6rem; color: #fff; text-decoration: none; font-weight: 600; }
.brand-mark { background: #fff; color: var(--blue); border-radius: 6px; padding: .1rem .45rem; font-size: .85rem; letter-spacing: .05em; }
.nav { display: flex; align-items: center; gap: .25rem; flex-wrap: wrap; }
.nav > a { color: #fff; text-decoration: none; padding: .4rem .6rem; border-radius: 6px; font-size: .95rem; }
.nav > a:hover, .nav > a[aria-current] { background: rgba(255,255,255,.16); }
.usermenu { position: relative; }
.usermenu summary { cursor: pointer; padding: .4rem .6rem; list-style: none; border-radius: 6px; }
.usermenu summary::-webkit-details-marker { display: none; }
.usermenu summary::after { content: " ▾"; font-size: .75rem; }
.usermenu-panel { position: absolute; right: 0; top: 2.4rem; background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: .5rem; min-width: 180px; z-index: 10; box-shadow: 0 6px 20px rgba(0,0,0,.12); }
.usermenu-panel a, .usermenu-panel .linklike { display: block; padding: .45rem .6rem; color: var(--ink); text-decoration: none; width: 100%; text-align: left; }
.linklike { background: none; border: 0; font: inherit; cursor: pointer; color: var(--blue); padding: 0; }

.footer { color: var(--muted); font-size: .8rem; padding: 2rem 16px; }

/* Cards and layout */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1rem; }
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }

.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.25rem; }
.stat-value { font-size: 1.9rem; font-weight: 700; line-height: 1.1; }
.stat-label { color: var(--muted); font-size: .875rem; }

/* Buttons and forms */
.btn { display: inline-block; background: var(--blue); color: #fff; border: 0; border-radius: 8px; padding: .65rem 1.1rem; font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; text-align: center; }
.btn:hover { background: var(--blue-dark); }
.btn-lg { padding: .9rem 1.4rem; font-size: 1.05rem; }
.btn-secondary { background: #fff; color: var(--blue); border: 1px solid var(--blue); }
.btn-secondary:hover { background: var(--blue-soft); }
.btn-danger { background: #fff; color: var(--bad); border: 1px solid var(--bad); }
.btn-block { display: block; width: 100%; }

label { font-weight: 600; display: block; margin-bottom: .3rem; }
input[type=text], input[type=email], input[type=password], input[type=date], select, textarea {
  width: 100%; padding: .6rem .7rem; border: 1px solid var(--line); border-radius: 8px; font: inherit; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue); outline-offset: 1px; border-color: var(--blue); }
.field { margin-bottom: 1rem; }
.helptext { color: var(--muted); font-size: .85rem; }
.errorlist { color: var(--bad); margin: .25rem 0; padding: 0; list-style: none; font-size: .9rem; }
.errorlist.nonfield { background: var(--bad-soft); border-radius: 8px; padding: .6rem .8rem; margin-bottom: 1rem; }
.divider { display: flex; align-items: center; gap: .75rem; color: var(--muted); font-size: .85rem; margin: 1.25rem 0; }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--line); }

.flash { border-radius: 8px; padding: .75rem 1rem; margin: 1rem 0; background: var(--blue-soft); }
.flash-success { background: var(--ok-soft); color: var(--ok); }
.flash-error { background: var(--bad-soft); color: var(--bad); }

/* Activity picker */
.picker-category { border-left: 4px solid var(--cat-1); }
.picker-category:nth-of-type(4n+2) { border-left-color: var(--cat-2); }
.picker-category:nth-of-type(4n+3) { border-left-color: var(--cat-3); }
.picker-category:nth-of-type(4n+4) { border-left-color: var(--cat-4); }
.choices { display: grid; gap: .5rem; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); margin-bottom: .75rem; }
.choice { position: relative; }
.choice input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.choice label { font-weight: 500; border: 1px solid var(--line); border-radius: 8px; padding: .65rem .75rem .65rem 2.4rem; cursor: pointer; margin: 0; height: 100%; background: #fff; position: relative; }
.choice label::before { content: ""; position: absolute; left: .75rem; top: .8rem; width: 1.1rem; height: 1.1rem; border: 2px solid var(--muted); border-radius: 4px; background: #fff; }
.choice input:checked + label { border-color: var(--blue); background: var(--blue-soft); }
.choice input:checked + label::before { background: var(--blue); border-color: var(--blue); box-shadow: inset 0 0 0 2px #fff; }
.choice input:focus-visible + label { outline: 2px solid var(--blue); outline-offset: 2px; }
.choice .help { display: block; font-weight: 400; color: var(--muted); font-size: .8rem; margin-top: .15rem; }
.sticky-actions { position: sticky; bottom: 0; background: var(--bg); padding: .75rem 0; border-top: 1px solid var(--line); }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { padding: .55rem .6rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:hover td { background: #fafbfd; }

/* Member × category grid */
.heat td.cell { text-align: center; font-variant-numeric: tabular-nums; font-weight: 600; }
.heat .h0 { color: #b8c2cc; font-weight: 400; }
.heat .h1 { background: #dbe8f5; }
.heat .h2 { background: #a9c7e6; }
.heat .h3 { background: #5f97cf; color: #fff; }
.heat .h4 { background: var(--blue); color: #fff; }

/* Bars */
.bars { display: grid; gap: .6rem; }
.bar-row { display: grid; grid-template-columns: minmax(120px, 34%) 1fr 3rem; gap: .6rem; align-items: center; font-size: .92rem; }
.bar-track { background: #edf1f5; border-radius: 4px; height: 14px; overflow: hidden; }
.bar-fill { background: var(--blue); height: 100%; border-radius: 4px; }
.bar-value { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

.columns { display: flex; align-items: flex-end; gap: 4px; height: 140px; padding-top: 1rem; }
.col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 0; }
.col-bar { width: 100%; max-width: 36px; background: var(--blue); border-radius: 3px 3px 0 0; min-height: 2px; }
.col-label { font-size: .7rem; color: var(--muted); margin-top: .25rem; white-space: nowrap; }
.col-value { font-size: .75rem; font-weight: 600; }

/* Badges and lists */
.badge { display: inline-block; font-size: .75rem; font-weight: 600; border-radius: 999px; padding: .1rem .55rem; background: #edf1f5; color: var(--muted); white-space: nowrap; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-blue { background: var(--blue-soft); color: var(--blue); }
.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: .6rem 0; border-bottom: 1px solid var(--line); }
.list li:last-child { border-bottom: 0; }
.check { display: inline-block; width: 1.25rem; text-align: center; font-weight: 700; }
.check-yes { color: var(--ok); }
.check-no { color: #b8c2cc; }

.filters { display: grid; gap: .75rem; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); align-items: end; }
.filters .field { margin: 0; }
.filters label { font-size: .85rem; }
.inline-check { display: flex; gap: .4rem; align-items: center; font-weight: 500; }
.inline-check input { width: auto; }

.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin: 1rem 0; overflow-x: auto; }
.tabs a { padding: .55rem .9rem; text-decoration: none; color: var(--muted); border-bottom: 3px solid transparent; white-space: nowrap; }
.tabs a[aria-current] { color: var(--blue); border-bottom-color: var(--blue); font-weight: 600; }

.quote { border-left: 3px solid var(--line); padding-left: .8rem; margin: .4rem 0; color: var(--ink); white-space: pre-line; }
.pagination { display: flex; gap: .75rem; align-items: center; margin-top: 1rem; }

@media (max-width: 640px) {
  h1 { font-size: 1.35rem; }
  .bar-row { grid-template-columns: 1fr 2.5rem; }
  .bar-row .bar-label { grid-column: 1 / -1; }
  .hide-sm { display: none; }
}
