/* Statistics. */
/* ==========================================================================
   Statistics — ported from ui_kits/webapp/styles.css (kw-stats-*). Tasks and
   Goals section rules land with those views (#964, #965).
   ========================================================================== */
.kw-stats {
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  container-type: inline-size;
  min-width: 0;
}
.kw-stats .kw-page-head {
  flex-wrap: wrap;
  align-items: flex-end;
}
.kw-stats-period {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-wrap: wrap;
}
.kw-stats-seg {
  display: inline-flex;
  gap: var(--space-xxxs);
  padding: var(--space-xxxs);
  background: var(--bg-subtle);
  border: 1px solid var(--divider);
  border-radius: var(--radius-sm);
}
.kw-stats-seg > * {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  height: 28px;
  padding: 0 var(--space-sm);
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  font-family: inherit;
  font-size: var(--text-label-md);
  font-weight: 600;
  color: var(--fg-muted);
  cursor: pointer;
}
.kw-stats-seg > *:hover {
  color: var(--fg);
}
.kw-stats-seg > .on {
  background: var(--surface);
  color: var(--fg);
  box-shadow: var(--shadow-sm);
}
.kw-stats-nav {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-xxxs);
  height: 36px;
  padding: 0 var(--space-xxxs);
  border: 1px solid var(--divider);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.kw-stats-nav .kw-iconbtn {
  width: 30px;
  height: 30px;
}
.kw-stats-nav .kw-iconbtn:disabled {
  opacity: .3;
  cursor: default;
  background: transparent;
}
.kw-stats-label {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 150px;
  padding: 0 var(--space-xs);
  border: none;
  background: transparent;
  font-family: inherit;
  cursor: pointer;
  border-radius: var(--radius-sm);
}
.kw-stats-label:hover {
  background: var(--bg-subtle);
}
.kw-stats-label .t {
  display: flex;
  align-items: center;
  gap: var(--space-xxxs);
  font-size: var(--text-title-sm);
  font-weight: 600;
  color: var(--fg);
  line-height: 17px;
}
.kw-stats-label .r {
  font-family: var(--font-mono);
  font-size: var(--text-label-sm);
  color: var(--fg-subtle);
  letter-spacing: .02em;
  line-height: 13px;
}
.kw-stats-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 30;
  width: 320px;
  max-height: 380px;
  overflow: auto;
  padding: var(--space-xs);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
}
.kw-stats-menu-head {
  padding: var(--space-xs) var(--space-sm) var(--space-xs);
  font-size: var(--text-eyebrow);
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--fg-muted);
}
.kw-stats-menu-row {
  display: grid;
  grid-template-columns: minmax(0,1fr) 64px 56px 18px;
  align-items: center;
  gap: var(--space-sm);
  width: 100%;
  padding: var(--space-xs) var(--space-sm);
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  color: var(--fg);
  text-decoration: none;
}
.kw-stats-menu-row:hover {
  background: var(--bg-subtle);
}
.kw-stats-menu-row .t {
  display: block;
  font-size: var(--text-label-lg);
  font-weight: 500;
}
.kw-stats-menu-row.on .t {
  font-weight: 700;
  color: var(--orange-text);
}
.kw-stats-menu-row .r {
  display: block;
  font-family: var(--font-mono);
  font-size: var(--text-label-sm);
  color: var(--fg-subtle);
}
.kw-stats-menu-row .bar {
  height: 4px;
  border-radius: var(--radius-xs);
  background: var(--divider);
  overflow: hidden;
}
.kw-stats-menu-row .bar i {
  display: block;
  height: 100%;
  background: var(--fg-muted);
}
.kw-stats-menu-row .v {
  font-size: var(--text-label-md);
  font-weight: 600;
  text-align: right;
  font-variant-numeric: tabular-nums;
}
.kw-stats-tab kbd {
  font-family: var(--font-mono);
  font-size: var(--text-eyebrow);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 1px var(--space-xxs);
  color: var(--fg);
  line-height: 14px;
}
.kw-stats-kpis {
  display: grid;
  grid-template-columns: repeat(3,minmax(0,1fr));
  gap: var(--space-sm);
}
.kw-stats-kpis .kw-kpi-value small {
  font-size: var(--text-title-md);
  font-weight: 600;
  color: var(--fg-muted);
  letter-spacing: 0;
}
.kw-stats-kpis .kw-kpi-sub {
  display: flex;
  flex-direction: column;
  gap: var(--space-xxs);
  margin-top: var(--space-xxxs);
}
.kw-stats-delta {
  font-size: var(--text-label-md);
  font-weight: 600;
  color: var(--fg-muted);
  font-variant-numeric: tabular-nums;
}
.kw-stats-delta span {
  font-weight: 500;
}
.kw-stats-cmp {
  font-family: var(--font-mono);
  font-size: var(--text-label-sm);
  color: var(--fg-subtle);
  letter-spacing: .02em;
}
.kw-stats-tabs {
  display: flex;
  align-items: flex-end;
  gap: var(--space-xxs);
  border-bottom: 1px solid var(--divider);
}
.kw-stats-tab {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  height: 40px;
  padding: 0 var(--space-md);
  font-size: var(--text-title-sm);
  font-weight: 600;
  color: var(--fg-muted);
  text-decoration: none;
  box-shadow: inset 0 -2px 0 transparent;
}
.kw-stats-tab:hover {
  color: var(--fg);
}
.kw-stats-tab.on {
  color: var(--fg);
  box-shadow: inset 0 -2px 0 var(--orange);
}
.kw-stats-tab kbd {
  opacity: .7;
}
.kw-stats-grid {
  display: grid;
  grid-template-columns: repeat(12,minmax(0,1fr));
  gap: var(--space-md);
  align-items: stretch;
}
.kw-stats-span-12 {
  grid-column: span 12;
}
.kw-stats-span-8 {
  grid-column: span 8;
}
.kw-stats-span-7 {
  grid-column: span 7;
}
.kw-stats-span-6 {
  grid-column: span 6;
}
.kw-stats-span-5 {
  grid-column: span 5;
}
.kw-stats-span-4 {
  grid-column: span 4;
}
@container (max-width: 760px) {
  .kw-stats-grid > * {
    grid-column: span 12;
  }
  .kw-stats-kpis {
    grid-template-columns: 1fr;
  }
}
.kw-stats-card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--divider);
  border-radius: var(--radius-md);
}
.kw-stats-card-head {
  display: flex;
  align-items: baseline;
  gap: var(--space-sm);
  padding: var(--space-md) var(--space-md) 0;
}
.kw-stats-card-title {
  flex: 1;
  min-width: 0;
  font-size: var(--text-title-sm);
  font-weight: 600;
  color: var(--fg);
}
.kw-stats-card-meta {
  font-size: var(--text-label-md);
  font-weight: 600;
  color: var(--fg-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.kw-stats-card-body {
  flex: 1;
  padding: var(--space-md) var(--space-md) var(--space-md);
  min-width: 0;
}
.kw-stats-card-foot {
  border-top: 1px solid var(--divider);
  padding: var(--space-sm) var(--space-md);
  font-size: var(--text-body-sm);
  color: var(--fg-muted);
  display: flex;
  justify-content: space-between;
  gap: var(--space-sm);
}
.kw-stats-empty {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--space-xxs);
  font-size: var(--text-body-md);
  line-height: 19px;
  color: var(--fg-muted);
  text-wrap: pretty;
}
.kw-stats-link {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xxxs);
  padding: var(--space-xxxs) 0;
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: var(--text-label-md);
  font-weight: 600;
  color: var(--orange-text);
  text-decoration: none;
  cursor: pointer;
}
.kw-stats-link:hover {
  text-decoration: underline;
}
.kw-stats-hint {
  display: flex;
  align-items: center;
  gap: var(--space-md);
  flex-wrap: wrap;
  margin-top: var(--space-sm);
  font-size: var(--text-body-sm);
  color: var(--fg-muted);
}
.kw-stats-hint .sw {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xxs);
  white-space: nowrap;
}
.kw-stats-hint .sw i {
  width: 9px;
  height: 9px;
  border-radius: var(--radius-xs);
}
.kw-stats-hint .sub {
  color: var(--fg-subtle);
}
/* charts */
.kw-stats-chart {
  padding-left: var(--space-2xl);
  min-width: 0;
}
.kw-stats-plot {
  position: relative;
}
.kw-stats-plot .ax {
  position: absolute;
  left: -40px;
  width: 32px;
  text-align: right;
  font-family: var(--font-mono);
  font-size: var(--text-eyebrow);
  line-height: 12px;
  color: var(--fg-subtle);
  transform: translateY(-6px);
}
.kw-stats-plot .gl {
  position: absolute;
  left: 0;
  right: 0;
  border-top: 1px dashed var(--divider);
}
.kw-stats-plot .base {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  border-top: 1px solid var(--border);
}
.kw-stats-cols {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: stretch;
}
.kw-stats-col {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column-reverse;
  padding: 0;
  border: none;
  background: transparent;
  font-family: inherit;
  text-decoration: none;
  cursor: pointer;
  transition: opacity 120ms var(--ease-standard);
}
.kw-stats-col.still {
  cursor: default;
}
.kw-stats-cols:hover .kw-stats-col {
  opacity: .5;
}
.kw-stats-cols .kw-stats-col:hover, .kw-stats-cols .kw-stats-col:focus-visible {
  opacity: 1;
}
.kw-stats-col .seg {
  flex-shrink: 0;
  display: block;
}
.kw-stats-col .stub {
  height: 6px;
  border: 1px dashed var(--border-strong);
  border-bottom: none;
  border-radius: var(--radius-xs) var(--radius-xs) 0 0;
}
.kw-stats-col .zero {
  height: 2px;
  border-radius: 1px;
  background: var(--border-strong);
}
.kw-stats-labels {
  display: flex;
  margin-top: var(--space-xs);
}
.kw-stats-labels span {
  flex: 1;
  min-width: 0;
  text-align: center;
  white-space: nowrap;
  font-size: var(--text-label-sm);
  line-height: 13px;
  color: var(--fg-subtle);
  font-weight: 500;
}
.kw-stats-labels.mono span {
  font-family: var(--font-mono);
  font-size: var(--text-eyebrow);
}
.kw-stats-labels span.today {
  color: var(--orange-text);
  font-weight: 700;
}
/* hover tooltips — replace the phone's tap-to-inspect */
.kw-stats-hit {
  position: relative;
}
.kw-stats-tip {
  display: none;
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 25;
  min-width: 140px;
  padding: var(--space-xs) var(--space-sm);
  background: var(--fg);
  color: var(--bg);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  font-size: var(--text-body-sm);
  line-height: 17px;
  text-align: left;
  white-space: nowrap;
  pointer-events: none;
  font-weight: 400;
}
.kw-stats-tip.l {
  left: 0;
  transform: none;
}
.kw-stats-tip.r {
  left: auto;
  right: 0;
  transform: none;
}
.kw-stats-tip.below {
  bottom: auto;
  top: calc(100% + 8px);
}
.kw-stats-hit:hover > .kw-stats-tip, .kw-stats-hit:focus-visible > .kw-stats-tip {
  display: block;
}
.kw-stats-tip b {
  display: block;
  font-weight: 600;
  margin-bottom: var(--space-xxs);
}
.kw-stats-tip .ln {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  font-variant-numeric: tabular-nums;
}
.kw-stats-tip .ln i {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-xs);
  flex-shrink: 0;
}
.kw-stats-tip .ln em {
  flex: 1;
  font-style: normal;
  opacity: .8;
  padding-right: var(--space-sm);
}
.kw-stats-tip .ln.tot {
  margin-top: var(--space-xxs);
  padding-top: var(--space-xxs);
  border-top: 1px solid color-mix(in oklab, var(--bg) 25%, transparent);
  font-weight: 600;
}
.kw-stats-tip .ft {
  display: block;
  margin-top: var(--space-xxs);
  font-family: var(--font-mono);
  font-size: var(--text-eyebrow);
  opacity: .7;
}
/* horizontal rows */
/* goals view (#965) */
.kw-stats-htable {
  display: grid;
  grid-template-columns: minmax(0,1fr) 72px 72px 84px;
  column-gap: var(--space-xs);
  align-items: center;
}
.kw-stats-htable .hd {
  font-size: var(--text-eyebrow);
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--fg-subtle);
  text-align: right;
  padding-bottom: var(--space-xs);
  border-bottom: 1px solid var(--divider);
}
.kw-stats-htable .hd:first-child {
  text-align: left;
}
.kw-stats-hrow {
  display: contents;
}
.kw-stats-hrow > * {
  padding: var(--space-sm) 0;
  border-bottom: 1px solid var(--divider);
}
.kw-stats-hrow:last-child > * {
  border-bottom: none;
}
.kw-stats-hrow:hover > * {
  background: var(--bg-subtle);
}
.kw-stats-hrow .c {
  font-size: var(--text-title-md);
  font-weight: 600;
  color: var(--fg);
  text-align: right;
  font-variant-numeric: tabular-nums;
  padding-right: var(--space-xxs);
}
.kw-stats-hrow .c.nil {
  color: var(--fg-subtle);
}
.kw-stats-hrow .hn {
  font-size: var(--text-title-sm);
  font-weight: 600;
  color: var(--fg);
  padding-left: var(--space-xxs);
}
.kw-stats-hrow .hn div {
  font-family: var(--font-mono);
  font-size: var(--text-label-sm);
  font-weight: 400;
  color: var(--fg-subtle);
  margin-top: 1px;
}
.kw-stats-list {
  display: flex;
  flex-direction: column;
}
.kw-stats-li {
  display: grid;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-sm) var(--space-xs);
  margin: 0 calc(var(--space-xs) * -1);
  border-radius: var(--radius-sm);
  border-top: 1px solid var(--divider);
}
.kw-stats-li:first-child {
  border-top: none;
}
.kw-stats-li:hover {
  background: var(--bg-subtle);
}
.kw-stats-li .tx {
  font-size: var(--text-body-md);
  line-height: 19px;
  color: var(--fg);
  min-width: 0;
  text-wrap: pretty;
}
.kw-stats-li .mono {
  font-family: var(--font-mono);
  font-size: var(--text-label-sm);
  color: var(--fg-subtle);
  letter-spacing: .02em;
}
.kw-stats-li .hz {
  font-size: var(--text-eyebrow);
  letter-spacing: .08em;
  text-transform: uppercase;
}
.kw-stats-li .v {
  font-size: var(--text-title-sm);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.kw-stats-hops {
  display: flex;
  align-items: center;
  gap: var(--space-xxxs);
  flex-wrap: wrap;
}
.kw-stats-state {
  display: inline-flex;
  align-items: center;
  gap: var(--space-xxs);
  font-size: var(--text-label-md);
  font-weight: 600;
  color: var(--fg-subtle);
  white-space: nowrap;
  justify-self: end;
}
.kw-stats-state.done {
  color: var(--success);
}
.kw-stats-rows {
  display: flex;
  flex-direction: column;
  gap: var(--space-xxs);
}
.kw-stats-row {
  display: grid;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-xxs) var(--space-xs);
  margin: 0 calc(var(--space-xs) * -1);
  border-radius: var(--radius-sm);
}
.kw-stats-row:hover {
  background: var(--bg-subtle);
}
.kw-stats-row .n {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  min-width: 0;
  font-size: var(--text-body-md);
  color: var(--fg);
}
.kw-stats-row .n span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.kw-stats-row .n.muted {
  color: var(--fg-muted);
}
.kw-stats-row .n i {
  width: 10px;
  height: 10px;
  border-radius: var(--radius-xs);
  flex-shrink: 0;
}
.kw-stats-row .track {
  height: 8px;
  border-radius: var(--radius-xs);
  background: var(--divider);
  overflow: hidden;
}
.kw-stats-row .track i {
  display: block;
  height: 100%;
  border-radius: var(--radius-xs);
}
.kw-stats-row .v {
  text-align: right;
  font-size: var(--text-title-sm);
  font-weight: 600;
  color: var(--fg);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.kw-stats-row .p {
  text-align: right;
  font-size: var(--text-body-sm);
  color: var(--fg-muted);
  font-variant-numeric: tabular-nums;
}
.kw-stats-split {
  display: flex;
  gap: var(--space-xxxs);
  height: 10px;
  border-radius: var(--radius-xs);
  overflow: hidden;
  margin-bottom: var(--space-sm);
}
.kw-stats-row .i {
  font-family: var(--font-mono);
  font-size: var(--text-label-sm);
  color: var(--fg-subtle);
}
/* tasks view */
.kw-stats-nums {
  display: flex;
  gap: var(--space-xl);
  margin-bottom: var(--space-md);
  flex-wrap: wrap;
}
.kw-stats-num {
  display: flex;
  flex-direction: column;
  gap: var(--space-xxxs);
}
.kw-stats-num .l {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  font-size: var(--text-body-sm);
  color: var(--fg-muted);
}
.kw-stats-num .l i {
  width: 10px;
  height: 10px;
  border-radius: var(--radius-xs);
}
.kw-stats-num .v {
  font-size: var(--text-title-lg);
  font-weight: 700;
  color: var(--fg);
  font-variant-numeric: tabular-nums;
  letter-spacing: -.01em;
}
.kw-stats-pairs {
  position: relative;
  height: 72px;
  align-items: flex-end;
  border-bottom: 1px solid var(--border);
}
.kw-stats-pairs .kw-stats-col {
  flex-direction: row;
  align-items: flex-end;
  height: 100%;
}
.kw-stats-pairs .kw-stats-col > .c, .kw-stats-pairs .kw-stats-col > .d {
  flex: 1;
  border-radius: var(--radius-xs) var(--radius-xs) 0 0;
}
.kw-stats-pairs .kw-stats-col > .c {
  background: var(--border-strong);
}
.kw-stats-pairs .kw-stats-col > .d {
  background: var(--success);
}
.kw-stats-pairs .kw-stats-col > .stub {
  flex: 1;
}
.kw-stats-caption {
  margin-top: var(--space-sm);
  font-size: var(--text-body-md);
  color: var(--fg-muted);
}
/* year grid */
.kw-stats-year {
  display: grid;
  grid-template-columns: 28px minmax(0,1fr);
  column-gap: var(--space-xs);
}
.kw-stats-year-months {
  display: grid;
  height: 14px;
  margin-bottom: var(--space-xxs);
}
.kw-stats-year-months span {
  grid-row: 1;
  font-family: var(--font-mono);
  font-size: var(--text-eyebrow);
  line-height: 14px;
  color: var(--fg-subtle);
  white-space: nowrap;
}
.kw-stats-year-dow {
  display: grid;
  grid-template-rows: repeat(7,minmax(0,1fr));
  row-gap: var(--space-xxs);
  font-family: var(--font-mono);
  font-size: var(--text-eyebrow);
  color: var(--fg-subtle);
  align-items: center;
}
.kw-stats-year-cells {
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(7,auto);
  gap: var(--space-xxs);
}
.kw-stats-cell {
  display: block;
  aspect-ratio: 1;
  padding: 0;
  border: none;
  border-radius: var(--radius-xs);
  cursor: pointer;
}
.kw-stats-cell.off {
  background: transparent;
  box-shadow: inset 0 0 0 1px var(--divider);
  cursor: default;
}
.kw-stats-cell:hover {
  box-shadow: 0 0 0 1.5px var(--fg);
}
.kw-stats-cell.off:hover {
  box-shadow: inset 0 0 0 1px var(--divider);
}
.kw-stats-legend {
  display: flex;
  align-items: center;
  gap: var(--space-xxs);
  font-size: var(--text-label-sm);
  color: var(--fg-subtle);
}
.kw-stats-legend i {
  width: 11px;
  height: 11px;
  border-radius: var(--radius-xs);
}
.kw-stats-streak {
  display: flex;
  gap: var(--space-sm);
  align-items: flex-start;
}
.kw-stats-streak .big {
  font-size: var(--text-title-lg);
  font-weight: 700;
  color: var(--fg);
  font-variant-numeric: tabular-nums;
  letter-spacing: -.01em;
  line-height: 28px;
}
.kw-stats-streak .line {
  font-size: var(--text-body-md);
  line-height: 19px;
  color: var(--fg-muted);
  text-wrap: pretty;
}
.kw-stats-streak .line b {
  color: var(--fg);
  font-weight: 600;
}

/* Page-level classes (#1231): one class per element, replacing the Tailwind
   utilities the templates used to carry. Kept after this sheet's component
   rules so they win equal-specificity ties on the same element. */
/* ---------- pages/stats.templ ---------- */
.kw-stats-plot .top { top: 0; }
/* Notes and legends under a bar chart line up with its plot, past the axis labels. */
.kw-stats-plot-note { margin-top: 14px; padding-left: 40px; }
.kw-stats-plot-hint { padding-left: 40px; }
.kw-stats-year-hint { padding-left: 34px; }
.kw-stats-seg-spaced { margin-bottom: 14px; }
.kw-stats-row-activity { grid-template-columns: 112px minmax(0,1fr) 60px 40px; }
.kw-stats-row-top-task { grid-template-columns: 16px minmax(0,1.2fr) minmax(0,1fr) 64px; }
.kw-stats-row-count { grid-template-columns: 110px minmax(0,1fr) 36px; }
.kw-stats-li-linked { grid-template-columns: minmax(0,1fr) auto; }
.kw-stats-li-chain { grid-template-columns: minmax(0,1.4fr) 64px minmax(0,1fr) 90px; }
.kw-stats-li-meta { margin-top: var(--space-xxxs); }
.kw-stats-page-menu-icon { color: var(--fg-muted); }
.kw-stats-page-check-icon { color: var(--orange-text); }
.kw-stats-page-streak-fire-on { color: var(--orange); }
.kw-stats-page-streak-fire-off { color: var(--fg-subtle); }
