/* Action Items extends the operational admin vocabulary from admin-ops.css.
   Everything remains scoped so the checklist can be mounted more than once. */
.cpg-action-items {
  --ai-done: var(--green);
  --ai-todo: var(--purple-l);
  --ai-blocked: var(--red, var(--danger));
  --ai-progress: var(--blue, #5da8ff);
}

.cpg-action-items .cpg-ai-toolbar { align-items: flex-end; }
.cpg-action-items .cpg-ai-toolbar .cpg-ops-field { flex-basis: 132px; }
.cpg-action-items .cpg-ai-primary {
  color: #fff;
  border-color: color-mix(in srgb, var(--ops-accent-deep) 72%, var(--ops-line));
  background: var(--ops-accent-deep);
}
.cpg-action-items .cpg-ai-primary:hover {
  color: #fff;
  border-color: var(--ops-accent);
  background: color-mix(in srgb, var(--ops-accent-deep) 84%, #fff);
}
.cpg-action-items .cpg-ai-danger {
  color: #fff;
  border-color: var(--ops-danger);
  background: var(--ops-danger);
}
.cpg-action-items .cpg-ai-danger:hover { color: #fff; background: color-mix(in srgb, var(--ops-danger) 82%, #fff); }

.cpg-ai-progress {
  flex: none;
  display: flex;
  align-items: baseline;
  gap: 7px;
  padding: 8px 10px;
  border: 1px solid var(--ops-line);
  border-radius: 9px;
  color: var(--ops-text-faint);
  background: var(--ops-bg);
  font: 9px var(--mono);
  letter-spacing: .07em;
  text-transform: uppercase;
}
.cpg-ai-progress strong { color: var(--ops-text); font-size: 14px; letter-spacing: 0; }

/* Group view: recap sections with their own progress and nested checklists. */
.cpg-ai-groups { display: grid; gap: 12px; }
.cpg-ai-group {
  overflow: hidden;
  border: 1px solid var(--ops-line);
  border-radius: 12px;
  background: var(--ops-bg);
}
.cpg-ai-group > summary {
  min-height: 58px;
  display: grid;
  grid-template-columns: minmax(180px, auto) minmax(100px, 240px);
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 10px 14px;
  list-style: none;
  color: var(--ops-text);
  cursor: pointer;
  user-select: none;
}
.cpg-ai-group > summary::-webkit-details-marker { display: none; }
.cpg-ai-group > summary::before {
  content: '';
  width: 7px;
  height: 7px;
  position: absolute;
  margin-left: -4px;
  border-right: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg);
  transition: transform var(--dur-quick, .15s) ease;
}
.cpg-ai-group[open] > summary::before { transform: rotate(45deg) translate(-2px, -2px); }
.cpg-ai-group > summary > span { min-width: 0; display: flex; flex-direction: column; gap: 4px; padding-left: 12px; }
.cpg-ai-group > summary strong {
  overflow: hidden;
  color: var(--ops-text);
  font: 700 11px var(--mono);
  letter-spacing: .1em;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}
.cpg-ai-group > summary small { color: var(--ops-text-faint); font-size: 10px; }
.cpg-ai-group > summary > i {
  height: 5px;
  overflow: hidden;
  border-radius: 999px;
  background: color-mix(in srgb, var(--ops-text) 8%, transparent);
}
.cpg-ai-group > summary > i > b { display: block; height: 100%; border-radius: inherit; background: var(--ai-done); }
.cpg-ai-group-body { border-top: 1px solid var(--ops-line); }

.cpg-ai-row { border-bottom: 1px solid var(--ops-line); }
.cpg-ai-row:last-child { border-bottom: 0; }
.cpg-ai-row:hover { background: color-mix(in srgb, var(--ops-text) 3%, transparent); }
.cpg-ai-row-main {
  min-height: 62px;
  display: grid;
  grid-template-columns: 28px minmax(220px, 1.25fr) minmax(280px, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px 8px 14px;
}
.cpg-ai-check {
  appearance: none;
  width: 20px;
  height: 20px;
  flex: none;
  display: inline-grid;
  place-items: center;
  margin: 0;
  border: 1.5px solid color-mix(in srgb, var(--ops-text) 30%, transparent);
  border-radius: 50%;
  color: var(--ops-bg);
  background: transparent;
  cursor: pointer;
}
.cpg-ai-check::before {
  content: '';
  width: 8px;
  height: 4px;
  border-left: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  opacity: 0;
  transform: translateY(-1px) rotate(-45deg);
}
.cpg-ai-check:hover { border-color: var(--ai-done); }
.cpg-ai-check:checked { color: var(--ops-bg); border-color: var(--ai-done); background: var(--ai-done); }
.cpg-ai-check:checked::before { opacity: 1; }
.cpg-ai-check:focus-visible { outline: 2px solid var(--ops-accent); outline-offset: 3px; }

.cpg-ai-title, .cpg-ai-list-title {
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 4px;
  overflow: hidden;
  border: 0;
  border-radius: 7px;
  color: var(--ops-text);
  background: transparent;
  text-align: left;
}
.cpg-ai-title:hover, .cpg-ai-list-title:hover { background: color-mix(in srgb, var(--ops-accent) 8%, transparent); }
.cpg-ai-title strong, .cpg-ai-list-title strong { max-width: 100%; overflow: hidden; color: var(--ops-text); font-size: 13px; line-height: 1.35; text-overflow: ellipsis; white-space: nowrap; }
.cpg-ai-title span, .cpg-ai-list-title small { max-width: 100%; overflow: hidden; color: var(--ops-text-faint); font-size: 11px; line-height: 1.35; text-overflow: ellipsis; white-space: nowrap; }
.cpg-ai-row.is-done .cpg-ai-title strong,
.cpg-ai-list-row.is-done .cpg-ai-list-title strong { color: var(--ops-text-faint); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--ai-done) 65%, transparent); }

.cpg-ai-row-meta { min-width: 0; display: flex; align-items: center; gap: 7px; overflow: hidden; }
.cpg-ai-row-meta > * { flex: none; }
.cpg-ai-row-meta .cpg-ai-owner { min-width: 50px; max-width: 150px; overflow: hidden; color: var(--ops-text-muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.cpg-ai-row-meta time { color: var(--ops-text-faint); font-size: 10px; white-space: nowrap; }
.cpg-ai-row-actions { display: flex; align-items: center; justify-content: flex-end; gap: 3px; }
.cpg-ai-row-actions .cpg-ops-btn, .cpg-ai-flat .gv-flat-cell-actions .cpg-ops-btn { width: 30px; min-height: 30px; padding: 0; }

.cpg-ai-subtasks { display: grid; gap: 1px; margin: 0 10px 10px 52px; overflow: hidden; border: 1px solid var(--ops-line); border-radius: 8px; background: var(--ops-line); }
.cpg-ai-subtask { min-width: 0; display: grid; grid-template-columns: 20px minmax(0, 1fr); align-items: start; gap: 9px; padding: 8px 10px; background: var(--ops-surface); cursor: pointer; }
.cpg-ai-subtask:hover { background: color-mix(in srgb, var(--ops-text) 5%, var(--ops-surface)); }
.cpg-ai-subtask .cpg-ai-check { width: 17px; height: 17px; margin-top: 1px; }
.cpg-ai-subtask > span { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.cpg-ai-subtask b { overflow: hidden; color: var(--ops-text-soft); font-size: 11px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.cpg-ai-subtask small { overflow: hidden; color: var(--ops-text-faint); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.cpg-ai-subtask.is-done b { color: var(--ops-text-faint); text-decoration: line-through; }

.cpg-action-items .cpg-ops-chip { flex: none; }
.cpg-action-items .cpg-ai-status-todo { color: var(--ai-todo); background: color-mix(in srgb, var(--ai-todo) 11%, transparent); }
.cpg-action-items .cpg-ai-status-in_progress { color: var(--ai-progress); background: color-mix(in srgb, var(--ai-progress) 11%, transparent); }
.cpg-action-items .cpg-ai-status-blocked { color: var(--ai-blocked); background: color-mix(in srgb, var(--ai-blocked) 11%, transparent); }
.cpg-action-items .cpg-ai-status-done { color: var(--ai-done); background: color-mix(in srgb, var(--ai-done) 11%, transparent); }
.cpg-action-items .cpg-ai-status-cancelled { color: var(--ops-text-faint); }
.cpg-action-items .cpg-ai-priority-urgent { color: var(--ops-danger); background: color-mix(in srgb, var(--ops-danger) 12%, transparent); }
.cpg-action-items .cpg-ai-priority-high { color: var(--ops-warning); background: color-mix(in srgb, var(--ops-warning) 11%, transparent); }
.cpg-action-items .cpg-ai-priority-medium { color: var(--ops-accent); background: color-mix(in srgb, var(--ops-accent) 10%, transparent); }

/* Flat Henshu-style list. The shared rules provide the shell and row behavior. */
.cpg-action-items .cpg-ai-flat .gv-flat-header,
.cpg-action-items .cpg-ai-flat .gv-flat-row {
  grid-template-columns: 52px minmax(270px, 1.7fr) minmax(150px, .75fr) 126px minmax(140px, .7fr) 126px 110px 154px;
}
.cpg-action-items .cpg-ai-flat .gv-flat-cell-mark { justify-content: center; }
.cpg-action-items .cpg-ai-flat .cpg-ai-list-title { width: 100%; }

/* Structured editor — no browser prompts. */
.cpg-ai-dialog { width: min(820px, calc(100vw - 32px)); max-height: min(860px, calc(100vh - 32px)); }
.cpg-ai-dialog form { margin: 0; }
.cpg-ai-form-body { padding: 18px; }
.cpg-ai-form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.cpg-ai-form-grid label, .cpg-ai-repeat-row label { min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.cpg-ai-form-grid label > span, .cpg-ai-repeat-row label > span {
  color: var(--ops-text-faint);
  font: 700 9px var(--mono);
  letter-spacing: .09em;
  text-transform: uppercase;
}
.cpg-ai-form-grid input, .cpg-ai-form-grid select, .cpg-ai-form-grid textarea,
.cpg-ai-repeat-row input, .cpg-ai-repeat-row textarea {
  width: 100%;
  min-height: 38px;
  padding: 9px 10px;
  border: 1px solid var(--ops-line);
  border-radius: 8px;
  color: var(--ops-text);
  background: var(--ops-surface);
  font: 12px var(--sans);
}
.cpg-ai-form-grid textarea, .cpg-ai-repeat-row textarea { resize: vertical; line-height: 1.5; }
.cpg-ai-form-grid input::placeholder, .cpg-ai-form-grid textarea::placeholder,
.cpg-ai-repeat-row input::placeholder, .cpg-ai-repeat-row textarea::placeholder { color: var(--ops-text-faint); }
.cpg-ai-span-2 { grid-column: 1 / -1; }

.cpg-ai-form-section { margin-top: 18px; padding-top: 17px; border-top: 1px solid var(--ops-line); }
.cpg-ai-form-section-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 10px; }
.cpg-ai-form-section-head h4 { margin: 0; color: var(--ops-text); font-size: 13px; }
.cpg-ai-form-section-head p { margin: 4px 0 0; color: var(--ops-text-faint); font-size: 11px; line-height: 1.45; }
.cpg-ai-repeat-row {
  position: relative;
  display: grid;
  align-items: end;
  gap: 8px;
  margin-top: 8px;
  padding: 10px;
  border: 1px solid var(--ops-line);
  border-radius: 10px;
  background: color-mix(in srgb, var(--ops-text) 2%, transparent);
}
.cpg-ai-subtask-editor { grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) auto 36px; }
.cpg-ai-link-editor { grid-template-columns: minmax(150px, .7fr) minmax(240px, 1.3fr) 36px; }
.cpg-ai-attachment-editor { grid-template-columns: minmax(150px, 1fr) minmax(220px, 1.3fr) minmax(130px, .8fr) minmax(110px, .55fr) 36px; }
.cpg-ai-attachment-editor .cpg-ai-metadata { grid-column: 1 / -2; }
.cpg-ai-inline-check { min-height: 38px; flex-direction: row !important; align-items: center; gap: 7px !important; padding: 0 8px; }
.cpg-ai-inline-check input { width: 16px; min-height: 16px; }
.cpg-ai-inline-check span { color: var(--ops-text-muted) !important; font: 600 11px var(--sans) !important; letter-spacing: 0 !important; text-transform: none !important; }

.cpg-ai-form-actions {
  position: sticky;
  bottom: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 18px;
  border-top: 1px solid var(--ops-line);
  background: var(--ops-bg);
}
.cpg-ai-form-actions > div { display: flex; gap: 7px; }
.cpg-ai-delete-confirm {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-top: 18px;
  padding: 12px;
  border: 1px solid color-mix(in srgb, var(--ops-danger) 45%, var(--ops-line));
  border-radius: 10px;
  color: var(--ops-danger);
  background: color-mix(in srgb, var(--ops-danger) 9%, transparent);
}
.cpg-ai-delete-confirm > span { display: flex; flex-direction: column; gap: 3px; font-size: 11px; }
.cpg-ai-delete-confirm strong { font-size: 13px; }
.cpg-ai-delete-confirm > div { display: flex; gap: 7px; flex: none; }

@media (max-width: 1080px) {
  .cpg-ai-row-main { grid-template-columns: 28px minmax(220px, 1fr) auto; }
  .cpg-ai-row-meta { grid-column: 2 / 3; grid-row: 2; padding: 0 4px 4px; }
  .cpg-ai-row-actions { grid-column: 3; grid-row: 1 / span 2; }
}

@media (max-width: 820px) {
  .cpg-ai-progress { align-self: flex-start; }
  .cpg-ai-group > summary { grid-template-columns: minmax(150px, 1fr) minmax(90px, 180px); }
  .cpg-ai-attachment-editor { grid-template-columns: 1fr 1fr 36px; }
  .cpg-ai-attachment-editor > label:nth-of-type(1), .cpg-ai-attachment-editor > label:nth-of-type(2) { grid-column: span 1; }
  .cpg-ai-attachment-editor > label:nth-of-type(3), .cpg-ai-attachment-editor > label:nth-of-type(4) { grid-column: span 1; }
  .cpg-ai-attachment-editor .cpg-ai-metadata { grid-column: 1 / -2; }
  .cpg-ai-subtask-editor { grid-template-columns: 1fr 1fr; }
  .cpg-ai-subtask-editor .cpg-ai-inline-check { grid-column: 1; }
  .cpg-ai-subtask-editor > button { grid-column: 2; justify-self: end; }
}

@media (max-width: 620px) {
  .cpg-action-items .cpg-ai-toolbar .cpg-ops-field { flex: 1 1 118px; }
  .cpg-action-items .cpg-ai-toolbar > .cpg-ai-primary { flex: 1 1 auto; }
  .cpg-ai-group > summary { grid-template-columns: 1fr; gap: 8px; }
  .cpg-ai-row-main { grid-template-columns: 24px minmax(0, 1fr) auto; align-items: start; }
  .cpg-ai-row-meta { grid-column: 2 / -1; flex-wrap: wrap; overflow: visible; }
  .cpg-ai-row-actions { grid-column: 3; grid-row: 1; }
  .cpg-ai-row-actions [data-ai-move] { display: none; }
  .cpg-ai-row-actions .cpg-ops-btn-danger { display: none; }
  .cpg-ai-subtasks { margin-left: 46px; }
  .cpg-ai-form-grid { grid-template-columns: 1fr; }
  .cpg-ai-span-2 { grid-column: 1; }
  .cpg-ai-form-section-head { align-items: stretch; flex-direction: column; }
  .cpg-ai-repeat-row, .cpg-ai-subtask-editor, .cpg-ai-link-editor, .cpg-ai-attachment-editor { grid-template-columns: 1fr 36px; }
  .cpg-ai-repeat-row > label, .cpg-ai-attachment-editor > label:nth-of-type(1),
  .cpg-ai-attachment-editor > label:nth-of-type(2), .cpg-ai-attachment-editor > label:nth-of-type(3),
  .cpg-ai-attachment-editor > label:nth-of-type(4), .cpg-ai-attachment-editor .cpg-ai-metadata { grid-column: 1 / -1; }
  .cpg-ai-repeat-row > button { grid-column: 2; justify-self: end; }
  .cpg-ai-subtask-editor .cpg-ai-inline-check { grid-column: 1; grid-row: auto; }
  .cpg-ai-delete-confirm, .cpg-ai-form-actions { align-items: stretch; flex-direction: column; }
  .cpg-ai-delete-confirm > div, .cpg-ai-form-actions > div { width: 100%; }
  .cpg-ai-delete-confirm button, .cpg-ai-form-actions > div button { flex: 1; }
  .cpg-ai-dialog { width: calc(100vw - 16px); max-height: calc(100vh - 16px); }
}

@media (prefers-reduced-motion: reduce) {
  .cpg-ai-group > summary::before { transition: none; }
}
