/* Retention cohorts — Lucian element #161, scoped entirely to .u161.
   Used three times: weekly, monthly, yearly. Full-year tables are wide, so
   each grid scrolls horizontally inside its wrap and the signup label column
   sticks to the left while scrolling. */
.u161 {
  width: 100%;
  padding: 16px 0;
  position: relative;
  font-size: 13px;
  line-height: 1.45;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  min-height: 0;
}

.u161 button {
  border: 1px solid var(--ux-line-2);
  background: var(--ux-surface);
  padding: 8px 12px;
  border-radius: 10px;
  min-height: 44px;
  font-size: 12px;
  transition: background .2s, transform .3s var(--ux-ease);
}

.u161 button[aria-pressed="true"] {
  background: var(--ux-accent-soft);
  border-color: var(--ux-accent);
}

.u161 button:active { transform: scale(.97); }

.u161 .cohort-wrap {
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--ux-line-2) transparent;
}

.u161 .cohort-wrap::-webkit-scrollbar { height: 8px; }
.u161 .cohort-wrap::-webkit-scrollbar-thumb { background: var(--ux-line-2); border-radius: 8px; }
.u161 .cohort-wrap::-webkit-scrollbar-track { background: transparent; }

.u161 .cohort {
  display: grid;
  gap: 5px;
  margin-top: 0;
  width: max-content;
}

.u161[data-period="weekly"] .cohort { grid-template-columns: 68px repeat(52, 56px); }
.u161[data-period="monthly"] .cohort { grid-template-columns: 64px repeat(12, 64px); }
.u161[data-period="yearly"] .cohort { grid-template-columns: 52px repeat(5, 64px); }

.u161 .cohort .label {
  align-self: center;
  color: var(--ux-ink-2);
  font-size: 12px;
  position: sticky;
  left: 0;
  background: var(--ux-page);
  z-index: 2;
  padding: 4px 2px;
}

.u161 .cohort .week {
  text-align: center;
  min-height: 20px;
  font-size: 12px;
  color: var(--ux-ink-2);
}

.u161 .cohort button {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 4px 2px;
  min-height: 54px;
  border: 0;
  border-radius: 4px;
  background: color-mix(in srgb, var(--ux-heat) calc(var(--v) * .45%), var(--ux-surface));
  color: var(--ux-ink);
  font-variant-numeric: tabular-nums;
  transition: transform .35s;
}

.u161 .cohort button .n { font-size: 11px; font-weight: 600; line-height: 1.2; }
.u161 .cohort button .p { font-size: 10px; line-height: 1.2; opacity: .85; }

/* 85% and above: solid corporate navy in light, solid steel blue in dark.
   Text is accent-ink in both, so white on navy and dark ink on steel. */
.u161 .cohort button.high {
  background: var(--ux-heat);
  color: var(--ux-accent-ink);
}

/* Selected cell keeps its heat shading — only the outline and lift mark it.
   (The generic pressed rule above would otherwise wash it out to accent-soft.) */
.u161 .cohort button[aria-pressed="true"] {
  background: color-mix(in srgb, var(--ux-heat) calc(var(--v) * .45%), var(--ux-surface));
  outline: 2px solid var(--ux-ink);
  outline-offset: 1px;
  transform: translateY(-2px);
}

.u161 .cohort button.high[aria-pressed="true"] {
  background: var(--ux-heat);
}

/* Result panel below each table — the selected cohort's result, not just a line. */
.u161 .status {
  margin-top: 16px;
  padding: 12px 0 0;
  border-top: 1px solid var(--ux-line-2);
  background: transparent;
  min-height: 0;
  height: auto;
  color: var(--ux-ink-2);
  font-size: 12px;
  line-height: 1.5;
}

.u161 .status b { color: var(--ux-ink); }

.u161 .result-head {
  font-size: 13px;
  font-weight: 600;
  color: var(--ux-ink);
}

.u161 .result-note { margin-top: 2px; }

.u161 .result-metrics {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 28px;
  margin-top: 10px;
}

.u161 .result-metric {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 92px;
}

.u161 .result-metric span { font-size: 11px; color: var(--ux-ink-2); }

.u161 .result-metric b {
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.result-footer-action {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-drilldown-trigger {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  padding: 0 14px;
  border-radius: 6px;
  background: var(--ux-surface-2);
  color: var(--ux-ink);
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--ux-line-2);
  cursor: pointer;
  transition: all 0.18s var(--ux-ease);
  box-shadow: 0 1px 3px var(--ux-shadow);
}

.btn-drilldown-trigger svg {
  color: var(--ux-accent);
  transition: transform 0.18s ease;
}

.btn-drilldown-trigger:hover {
  background: var(--ux-surface-3);
  border-color: var(--ux-accent);
  color: var(--ux-accent);
  transform: translateY(-1px);
}

.btn-drilldown-trigger:hover svg {
  transform: scale(1.1);
}

/* Drill-down Modal Dialog */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: modalFadeIn 0.2s var(--ux-ease);
}

.modal-backdrop[hidden] {
  display: none;
}

@keyframes modalFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.drilldown-modal-card {
  width: 100%;
  max-width: 880px;
  max-height: 85vh;
  background: var(--ux-surface);
  border: 1px solid var(--ux-line-2);
  border-radius: 12px;
  box-shadow: 0 20px 48px -10px var(--ux-shadow-strong);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modalSlideUp 0.25s var(--ux-ease);
}

@keyframes modalSlideUp {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.drilldown-modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--ux-line);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.drilldown-modal-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--ux-ink);
  margin: 0;
}

.drilldown-modal-subtitle {
  font-size: 12px;
  color: var(--ux-ink-3);
  margin: 3px 0 0;
}

.drilldown-modal-close {
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--ux-ink-3);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.drilldown-modal-close:hover {
  background: var(--ux-surface-2);
  color: var(--ux-ink);
}

.drilldown-modal-toolbar {
  padding: 10px 20px;
  border-bottom: 1px solid var(--ux-line);
  background: var(--ux-surface-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.drilldown-search-wrap {
  position: relative;
  flex: 1;
  min-width: 180px;
  display: flex;
  align-items: center;
}

.drilldown-search-wrap .search-icon {
  position: absolute;
  left: 10px;
  color: var(--ux-ink-3);
  pointer-events: none;
}

.drilldown-search-input {
  width: 100%;
  height: 32px;
  padding: 0 10px 0 30px;
  border: 1px solid var(--ux-line-2);
  border-radius: 6px;
  background: var(--ux-surface);
  color: var(--ux-ink);
  font: inherit;
  font-size: 12px;
  outline: none;
  transition: border-color 0.15s ease;
}

.drilldown-search-input:focus {
  border-color: var(--ux-accent);
}

.drilldown-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border-radius: 6px;
  background: var(--ux-surface);
  color: var(--ux-ink);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--ux-line-2);
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.18s var(--ux-ease);
  box-shadow: 0 1px 2px var(--ux-shadow);
  user-select: none;
}

.modal-action-btn svg {
  color: var(--ux-ink-2);
  flex-shrink: 0;
  transition: transform 0.15s ease;
}

.modal-action-btn:hover {
  background: var(--ux-surface-2);
  border-color: var(--ux-accent-2);
  color: var(--ux-accent);
  transform: translateY(-1px);
}

.modal-action-btn:hover svg {
  color: var(--ux-accent);
}

.modal-action-btn.primary {
  background: var(--ux-accent);
  color: var(--ux-accent-ink);
  border-color: var(--ux-accent);
  box-shadow: 0 1px 4px var(--ux-shadow);
}

.modal-action-btn.primary svg {
  color: var(--ux-accent-ink);
}

.modal-action-btn.primary:hover {
  background: var(--ux-accent-2);
  border-color: var(--ux-accent-2);
  color: #FFFFFF;
}

.drilldown-table-container {
  flex: 1;
  overflow-y: auto;
  max-height: 400px;
  scrollbar-width: thin;
}

.drilldown-data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  text-align: left;
}

.drilldown-data-table th {
  position: sticky;
  top: 0;
  background: var(--ux-surface-2);
  padding: 8px 16px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ux-ink-3);
  border-bottom: 1px solid var(--ux-line);
  z-index: 2;
}

.drilldown-data-table td {
  padding: 9px 16px;
  border-bottom: 1px solid var(--ux-line);
  color: var(--ux-ink);
}

.drilldown-data-table tr:hover td {
  background: var(--ux-surface-2);
}

.drilldown-modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--ux-line);
  background: var(--ux-surface-2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--ux-ink-2);
}

@media print {
  .u161 .cohort-wrap { overflow: visible; }
}
